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

76 lines
2.4 KiB
PHP
Raw Normal View History

2018-05-04 16:45:37 +00:00
<?php
namespace Pterodactyl\Http\Controllers\Admin;
use Illuminate\Http\Request;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Models\Allocation;
use Pterodactyl\Models\Database;
use Pterodactyl\Models\Egg;
use Pterodactyl\Models\Node;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\User;
use JavaScript;
use Illuminate\Support\Facades\DB;
2018-05-04 20:48:43 +00:00
use Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService;
2018-05-04 16:45:37 +00:00
class StatisticsController extends Controller
{
2018-05-04 20:48:43 +00:00
private $keyProviderService;
function __construct(DaemonKeyProviderService $keyProviderService)
{
$this->keyProviderService = $keyProviderService;
}
2018-05-04 16:45:37 +00:00
public function index(Request $request)
{
$servers = Server::all();
2018-05-04 20:48:43 +00:00
$nodes = Node::all();
2018-05-04 16:45:37 +00:00
$serversCount = count($servers);
$nodesCount = Node::count();
$usersCount = User::count();
$eggsCount = Egg::count();
$databasesCount = Database::count();
$totalServerRam = DB::table('servers')->sum('memory');
$totalNodeRam = DB::table('nodes')->sum('memory');
$totalServerDisk = DB::table('servers')->sum('disk');
$totalNodeDisk = DB::table('nodes')->sum('disk');
$totalAllocations = Allocation::count();
$suspendedServersCount = Server::where('suspended', true)->count();
2018-05-04 20:48:43 +00:00
$tokens = [];
foreach ($nodes as $node) {
$tokens[$node->id] = $this->keyProviderService->handle($node->servers->get(0), $request->user());
}
2018-05-04 16:45:37 +00:00
Javascript::put([
2018-05-04 20:48:43 +00:00
'servers' => $servers,
2018-05-04 16:45:37 +00:00
'serverCount' => $serversCount,
'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
]);
return view('admin.statistics', [
'serversCount' => $serversCount,
'nodesCount' => $nodesCount,
'usersCount' => $usersCount,
'eggsCount' => $eggsCount,
'totalServerRam' => $totalServerRam,
'databasesCount' => $databasesCount,
'totalNodeRam' => $totalNodeRam,
'totalNodeDisk' => $totalNodeDisk,
'totalServerDisk' => $totalServerDisk,
'totalAllocations' => $totalAllocations,
]);
}
}