'stats', 'attributes' => [ 'current_state' => 'running', 'is_suspended' => false, 'resources' => [ 'memory_bytes' => 536870912, 'cpu_absolute' => 12.5, 'disk_bytes' => 2147483648, 'network_rx_bytes' => 102400, 'network_tx_bytes' => 204800, 'uptime' => 3600000, ], ], ]; private const array DAEMON_ERROR = [ 'errors' => [ [ 'code' => 'DaemonConnectionException', 'status' => '502', 'detail' => 'There was an error while communicating with the machine running this server.', ], ], ]; /** * Return the current resource utilization for a server. This value is cached for up to * 20 seconds at a time to ensure that repeated requests to this endpoint do not cause * a flood of unnecessary API calls. * * * @return ApiPayload * * @throws DaemonConnectionException */ #[Endpoint('Get server resources', 'Returns the latest cached resource utilization reported by Wings for the server.')] #[ScribeResponse(self::STATS_EXAMPLE, description: 'Resource utilization returned.')] #[ScribeResponse(self::DAEMON_ERROR, status: 502, description: 'Wings could not be reached for resource utilization.')] #[ResponseField('attributes.current_state', 'string', example: 'running', enum: ['offline', 'stopped', 'starting', 'running', 'stopping'])] public function __invoke(GetServerRequest $request, ReadsServerState $state, Server $server): array { return Fractal::item($state->read($server)) ->transformWith($this->getTransformer(StatsTransformer::class)) ->toResponseArray(); } }