misc_pterodactyl-panel/app/Http/Controllers/Admin/StatisticsController.php

100 lines
3.5 KiB
PHP
Raw Normal View History

2018-05-04 16:45:37 +00:00
<?php
namespace Pterodactyl\Http\Controllers\Admin;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Pterodactyl\Traits\Controllers\PlainJavascriptInjection;
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
2020-04-12 23:03:41 +00:00
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
2018-05-04 16:45:37 +00:00
class StatisticsController extends Controller
{
use PlainJavascriptInjection;
private $allocationRepository;
private $databaseRepository;
2018-05-04 16:45:37 +00:00
private $eggRepository;
private $nodeRepository;
private $serverRepository;
private $userRepository;
public function __construct(
AllocationRepositoryInterface $allocationRepository,
DatabaseRepositoryInterface $databaseRepository,
EggRepositoryInterface $eggRepository,
NodeRepositoryInterface $nodeRepository,
ServerRepositoryInterface $serverRepository,
UserRepositoryInterface $userRepository
) {
$this->allocationRepository = $allocationRepository;
$this->databaseRepository = $databaseRepository;
$this->eggRepository = $eggRepository;
$this->nodeRepository = $nodeRepository;
$this->serverRepository = $serverRepository;
$this->userRepository = $userRepository;
2018-05-04 20:48:43 +00:00
}
public function index()
2018-05-04 16:45:37 +00:00
{
2021-01-23 20:33:34 +00:00
throw new NotFoundHttpException();
$servers = $this->serverRepository->all();
$nodes = $this->nodeRepository->all();
$usersCount = $this->userRepository->count();
$eggsCount = $this->eggRepository->count();
$databasesCount = $this->databaseRepository->count();
$totalAllocations = $this->allocationRepository->count();
$suspendedServersCount = $this->serverRepository->getSuspendedServersCount();
$totalServerRam = 0;
$totalNodeRam = 0;
$totalServerDisk = 0;
$totalNodeDisk = 0;
foreach ($nodes as $node) {
$stats = $this->nodeRepository->getUsageStatsRaw($node);
$totalServerRam += $stats['memory']['value'];
$totalNodeRam += $stats['memory']['max'];
$totalServerDisk += $stats['disk']['value'];
$totalNodeDisk += $stats['disk']['max'];
}
2018-05-04 16:45:37 +00:00
2018-05-04 20:48:43 +00:00
$tokens = [];
foreach ($nodes as $node) {
$tokens[$node->id] = decrypt($node->daemon_token);
2018-05-04 20:48:43 +00:00
}
$this->injectJavascript([
2018-05-04 20:48:43 +00:00
'servers' => $servers,
2018-05-04 16:45:37 +00:00
'suspendedServers' => $suspendedServersCount,
'totalServerRam' => $totalServerRam,
'totalNodeRam' => $totalNodeRam,
'totalServerDisk' => $totalServerDisk,
'totalNodeDisk' => $totalNodeDisk,
2018-05-04 20:48:43 +00:00
'nodes' => $nodes,
'tokens' => $tokens,
2018-05-04 16:45:37 +00:00
]);
2018-05-04 16:45:37 +00:00
return view('admin.statistics', [
'servers' => $servers,
'nodes' => $nodes,
2018-05-04 16:45:37 +00:00
'usersCount' => $usersCount,
'eggsCount' => $eggsCount,
'totalServerRam' => $totalServerRam,
'databasesCount' => $databasesCount,
'totalNodeRam' => $totalNodeRam,
'totalNodeDisk' => $totalNodeDisk,
'totalServerDisk' => $totalServerDisk,
'totalAllocations' => $totalAllocations,
]);
}
}