2018-03-17 19:01:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Server;
|
2019-08-17 23:03:10 +00:00
|
|
|
use Pterodactyl\Repositories\Wings\WingsServerRepository;
|
2018-03-17 19:01:53 +00:00
|
|
|
use Pterodactyl\Transformers\Api\Client\StatsTransformer;
|
|
|
|
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
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Repositories\Wings\WingsServerRepository
|
|
|
|
*/
|
|
|
|
private $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ResourceUtilizationController constructor.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Repositories\Wings\WingsServerRepository $repository
|
|
|
|
*/
|
|
|
|
public function __construct(WingsServerRepository $repository)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
* @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-08-17 23:03:10 +00:00
|
|
|
public function __invoke(GetServerRequest $request): array
|
2018-03-17 19:01:53 +00:00
|
|
|
{
|
2019-08-17 23:03:10 +00:00
|
|
|
$stats = $this->repository
|
|
|
|
->setServer($request->getModel(Server::class))
|
|
|
|
->getDetails();
|
|
|
|
|
|
|
|
return $this->fractal->item($stats)
|
2018-03-17 19:01:53 +00:00
|
|
|
->transformWith($this->getTransformer(StatsTransformer::class))
|
|
|
|
->toArray();
|
|
|
|
}
|
|
|
|
}
|