2018-03-17 19:01:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
use Pterodactyl\Transformers\Api\Client\StatsTransformer;
|
2019-09-06 03:33:27 +00:00
|
|
|
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
2018-03-17 19:01:53 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
|
|
|
use Pterodactyl\Http\Requests\Api\Client\Servers\GetServerRequest;
|
|
|
|
|
|
|
|
class ResourceUtilizationController extends ClientApiController
|
|
|
|
{
|
2019-08-17 23:03:10 +00:00
|
|
|
/**
|
2019-09-06 03:33:27 +00:00
|
|
|
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
|
2019-08-17 23:03:10 +00:00
|
|
|
*/
|
|
|
|
private $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ResourceUtilizationController constructor.
|
|
|
|
*
|
2019-09-06 03:33:27 +00:00
|
|
|
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $repository
|
2019-08-17 23:03:10 +00:00
|
|
|
*/
|
2019-09-06 03:33:27 +00:00
|
|
|
public function __construct(DaemonServerRepository $repository)
|
2019-08-17 23:03:10 +00:00
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
2018-03-17 19:01:53 +00:00
|
|
|
/**
|
|
|
|
* Return the current resource utilization for a server.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\GetServerRequest $request
|
2019-09-06 04:41:20 +00:00
|
|
|
* @param \Pterodactyl\Models\Server $server
|
2018-03-17 19:01:53 +00:00
|
|
|
* @return array
|
2019-08-17 23:03:10 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
2018-03-17 19:01:53 +00:00
|
|
|
*/
|
2019-09-06 04:41:20 +00:00
|
|
|
public function __invoke(GetServerRequest $request, Server $server): array
|
2018-03-17 19:01:53 +00:00
|
|
|
{
|
2019-09-06 04:41:20 +00:00
|
|
|
$stats = $this->repository->setServer($server)->getDetails();
|
2019-08-17 23:03:10 +00:00
|
|
|
|
|
|
|
return $this->fractal->item($stats)
|
2018-03-17 19:01:53 +00:00
|
|
|
->transformWith($this->getTransformer(StatsTransformer::class))
|
|
|
|
->toArray();
|
|
|
|
}
|
|
|
|
}
|