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
|
|
|
|
{
|
2021-03-05 17:03:12 +00:00
|
|
|
private DaemonServerRepository $repository;
|
2019-08-17 23:03:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ResourceUtilizationController constructor.
|
|
|
|
*/
|
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.
|
|
|
|
*
|
2019-08-17 23:03:10 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
2021-03-05 17:03:12 +00:00
|
|
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
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();
|
|
|
|
}
|
|
|
|
}
|