Polished it up

This commit is contained in:
stanjg 2018-05-04 22:48:43 +02:00
parent 93a7d11c28
commit 28a97fea54
No known key found for this signature in database
GPG key ID: 27D9DF9D28935303
3 changed files with 84 additions and 6 deletions

View file

@ -12,13 +12,22 @@ use Pterodactyl\Models\Server;
use Pterodactyl\Models\User; use Pterodactyl\Models\User;
use JavaScript; use JavaScript;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService;
class StatisticsController extends Controller class StatisticsController extends Controller
{ {
private $keyProviderService;
function __construct(DaemonKeyProviderService $keyProviderService)
{
$this->keyProviderService = $keyProviderService;
}
public function index(Request $request) public function index(Request $request)
{ {
$servers = Server::all(); $servers = Server::all();
$nodes = Node::all();
$serversCount = count($servers); $serversCount = count($servers);
$nodesCount = Node::count(); $nodesCount = Node::count();
$usersCount = User::count(); $usersCount = User::count();
@ -29,17 +38,26 @@ class StatisticsController extends Controller
$totalServerDisk = DB::table('servers')->sum('disk'); $totalServerDisk = DB::table('servers')->sum('disk');
$totalNodeDisk = DB::table('nodes')->sum('disk'); $totalNodeDisk = DB::table('nodes')->sum('disk');
$totalAllocations = Allocation::count(); $totalAllocations = Allocation::count();
$totalUsersCount = User::count();
$totalDBCount = Database::count();
$suspendedServersCount = Server::where('suspended', true)->count(); $suspendedServersCount = Server::where('suspended', true)->count();
$tokens = [];
foreach ($nodes as $node) {
$tokens[$node->id] = $this->keyProviderService->handle($node->servers->get(0), $request->user());
}
Javascript::put([ Javascript::put([
'servers' => Server::all(), 'servers' => $servers,
'serverCount' => $serversCount, 'serverCount' => $serversCount,
'suspendedServers' => $suspendedServersCount, 'suspendedServers' => $suspendedServersCount,
'totalServerRam' => $totalServerRam, 'totalServerRam' => $totalServerRam,
'totalNodeRam' => $totalNodeRam, 'totalNodeRam' => $totalNodeRam,
'totalServerDisk' => $totalServerDisk, 'totalServerDisk' => $totalServerDisk,
'totalNodeDisk' => $totalNodeDisk, 'totalNodeDisk' => $totalNodeDisk,
'nodes' => $nodes,
'tokens' => $tokens,
]); ]);
return view('admin.statistics', [ return view('admin.statistics', [
@ -53,6 +71,8 @@ class StatisticsController extends Controller
'totalNodeDisk' => $totalNodeDisk, 'totalNodeDisk' => $totalNodeDisk,
'totalServerDisk' => $totalServerDisk, 'totalServerDisk' => $totalServerDisk,
'totalAllocations' => $totalAllocations, 'totalAllocations' => $totalAllocations,
'totalUsersCount' => $totalUsersCount,
'totalDBCount' => $totalDBCount,
]); ]);
} }

View file

@ -58,13 +58,25 @@ let statusChart = new Chart($('#status_chart'), {
}); });
var servers = Pterodactyl.servers; var servers = Pterodactyl.servers;
servers.forEach(function (server) { var nodes = Pterodactyl.nodes;
for (let i = 0; i < servers.length; i++) {
setTimeout(getStatus, 200 * i);
}
var index = 0;
function getStatus() {
var server = servers[index];
var uuid = server.uuid;
var node = getNodeByID(server.node_id);
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: Router.route('index.status', { server: server.uuidShort}), url: node.scheme + '://' + node.fqdn + ':'+node.daemonListen+'/v1/server',
timeout: 5000, timeout: 5000,
headers: { headers: {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content'), 'X-Access-Server': uuid,
'X-Access-Token': Pterodactyl.tokens[node.id],
} }
}).done(function (data) { }).done(function (data) {
@ -84,7 +96,6 @@ servers.forEach(function (server) {
case 1: case 1:
case 2: case 2:
// Online // Online
console.log('online');
statusChart.data.datasets[0].data[0]++; statusChart.data.datasets[0].data[0]++;
break; break;
case 20: case 20:
@ -98,4 +109,13 @@ servers.forEach(function (server) {
statusChart.data.datasets[0].data[3]++; statusChart.data.datasets[0].data[3]++;
statusChart.update(); statusChart.update();
}); });
});
index++;
}
function getNodeByID(id) {
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].id === id)
return nodes[i];
}
}

View file

@ -94,6 +94,44 @@
</div> </div>
</div> </div>
</div> </div>
<div class="row">
<div class="col-xs-12 col-md-3">
<div class="info-box bg-blue">
<span class="info-box-icon"><i class="fa fa-gamepad"></i></span>
<div class="info-box-content number-info-box-content">
<span class="info-box-text">Total Eggs</span>
<span class="info-box-number">{{ $eggsCount }}</span>
</div>
</div>
</div>
<div class="col-xs-12 col-md-3">
<div class="info-box bg-blue">
<span class="info-box-icon"><i class="fa fa-users"></i></span>
<div class="info-box-content number-info-box-content">
<span class="info-box-text">Total Users</span>
<span class="info-box-number">{{ $totalUsersCount }}</span>
</div>
</div>
</div>
<div class="col-xs-12 col-md-3">
<div class="info-box bg-blue">
<span class="info-box-icon"><i class="fa fa-server"></i></span>
<div class="info-box-content number-info-box-content">
<span class="info-box-text">Total Nodes</span>
<span class="info-box-number">{{ $nodesCount }}</span>
</div>
</div>
</div>
<div class="col-xs-12 col-md-3">
<div class="info-box bg-blue">
<span class="info-box-icon"><i class="fa fa-database"></i></span>
<div class="info-box-content number-info-box-content">
<span class="info-box-text">Total Databases</span>
<span class="info-box-number">{{ $totalDBCount }}</span>
</div>
</div>
</div>
</div>
@endsection @endsection
@section('footer-scripts') @section('footer-scripts')