Skip to content

Commit 93a7d11

Browse files
committed
Made a base
1 parent 7cf79a1 commit 93a7d11

File tree

6 files changed

+273
-0
lines changed

6 files changed

+273
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\Controllers\Admin;
4+
5+
use Illuminate\Http\Request;
6+
use Pterodactyl\Http\Controllers\Controller;
7+
use Pterodactyl\Models\Allocation;
8+
use Pterodactyl\Models\Database;
9+
use Pterodactyl\Models\Egg;
10+
use Pterodactyl\Models\Node;
11+
use Pterodactyl\Models\Server;
12+
use Pterodactyl\Models\User;
13+
use JavaScript;
14+
use Illuminate\Support\Facades\DB;
15+
16+
class StatisticsController extends Controller
17+
{
18+
19+
public function index(Request $request)
20+
{
21+
$servers = Server::all();
22+
$serversCount = count($servers);
23+
$nodesCount = Node::count();
24+
$usersCount = User::count();
25+
$eggsCount = Egg::count();
26+
$databasesCount = Database::count();
27+
$totalServerRam = DB::table('servers')->sum('memory');
28+
$totalNodeRam = DB::table('nodes')->sum('memory');
29+
$totalServerDisk = DB::table('servers')->sum('disk');
30+
$totalNodeDisk = DB::table('nodes')->sum('disk');
31+
$totalAllocations = Allocation::count();
32+
33+
$suspendedServersCount = Server::where('suspended', true)->count();
34+
35+
Javascript::put([
36+
'servers' => Server::all(),
37+
'serverCount' => $serversCount,
38+
'suspendedServers' => $suspendedServersCount,
39+
'totalServerRam' => $totalServerRam,
40+
'totalNodeRam' => $totalNodeRam,
41+
'totalServerDisk' => $totalServerDisk,
42+
'totalNodeDisk' => $totalNodeDisk,
43+
]);
44+
45+
return view('admin.statistics', [
46+
'serversCount' => $serversCount,
47+
'nodesCount' => $nodesCount,
48+
'usersCount' => $usersCount,
49+
'eggsCount' => $eggsCount,
50+
'totalServerRam' => $totalServerRam,
51+
'databasesCount' => $databasesCount,
52+
'totalNodeRam' => $totalNodeRam,
53+
'totalNodeDisk' => $totalNodeDisk,
54+
'totalServerDisk' => $totalServerDisk,
55+
'totalAllocations' => $totalAllocations,
56+
]);
57+
}
58+
59+
}

public/themes/pterodactyl/css/pterodactyl.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,3 +473,7 @@ label.control-label > span.field-optional:before {
473473
height: 42px;
474474
width: auto;
475475
}
476+
477+
.number-info-box-content {
478+
padding: 15px 10px 0;
479+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
var freeDisk = Pterodactyl.totalNodeDisk - Pterodactyl.totalServerDisk;
2+
let diskChart = new Chart($('#disk_chart'), {
3+
type: 'pie',
4+
data: {
5+
labels: ['Free Disk', 'Used Disk'],
6+
datasets: [
7+
{
8+
label: 'Disk in MBs',
9+
backgroundColor: ['#51B060', '#ff0000'],
10+
data: [freeDisk, Pterodactyl.totalServerDisk]
11+
}
12+
]
13+
}
14+
});
15+
16+
var freeRam = Pterodactyl.totalNodeRam - Pterodactyl.totalServerRam;
17+
let ramChart = new Chart($('#ram_chart'), {
18+
type: 'pie',
19+
data: {
20+
labels: ['Free RAM', 'Used RAM'],
21+
datasets: [
22+
{
23+
label: 'RAM in MBs',
24+
backgroundColor: ['#51B060', '#ff0000'],
25+
data: [freeRam, Pterodactyl.totalServerRam]
26+
}
27+
]
28+
}
29+
});
30+
31+
var activeServers = Pterodactyl.serverCount - Pterodactyl.suspendedServers;
32+
let serversChart = new Chart($('#servers_chart'), {
33+
type: 'pie',
34+
data: {
35+
labels: ['Active', 'Suspended'],
36+
datasets: [
37+
{
38+
label: 'Servers',
39+
backgroundColor: ['#51B060', '#E08E0B'],
40+
data: [activeServers, Pterodactyl.suspendedServers]
41+
}
42+
]
43+
}
44+
});
45+
46+
let statusChart = new Chart($('#status_chart'), {
47+
type: 'pie',
48+
data: {
49+
labels: ['Online', 'Offline', 'Installing', 'Error'],
50+
datasets: [
51+
{
52+
label: '',
53+
backgroundColor: ['#51B060', '#b7b7b7', '#E08E0B', '#ff0000'],
54+
data: [0,0,0,0]
55+
}
56+
]
57+
}
58+
});
59+
60+
var servers = Pterodactyl.servers;
61+
servers.forEach(function (server) {
62+
$.ajax({
63+
type: 'GET',
64+
url: Router.route('index.status', { server: server.uuidShort}),
65+
timeout: 5000,
66+
headers: {
67+
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content'),
68+
}
69+
}).done(function (data) {
70+
71+
if (typeof data.status === 'undefined') {
72+
// Error
73+
statusChart.data.datasets[0].data[3]++;
74+
return;
75+
}
76+
77+
switch (data.status) {
78+
case 0:
79+
case 3:
80+
case 30:
81+
// Offline
82+
statusChart.data.datasets[0].data[1]++;
83+
break;
84+
case 1:
85+
case 2:
86+
// Online
87+
console.log('online');
88+
statusChart.data.datasets[0].data[0]++;
89+
break;
90+
case 20:
91+
// Installing
92+
statusChart.data.datasets[0].data[2]++;
93+
break;
94+
}
95+
statusChart.update();
96+
}).fail(function (jqXHR) {
97+
// Error
98+
statusChart.data.datasets[0].data[3]++;
99+
statusChart.update();
100+
});
101+
});
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
@extends('layouts.admin')
2+
@include('partials/admin.settings.nav', ['activeTab' => 'basic'])
3+
4+
@section('title')
5+
Statistics Overview
6+
@endsection
7+
8+
@section('content-header')
9+
<h1>Statistics Overview<small>Monitor your panel usage.</small></h1>
10+
<ol class="breadcrumb">
11+
<li><a href="{{ route('admin.index') }}">Admin</a></li>
12+
<li class="active">Statistics</li>
13+
</ol>
14+
@endsection
15+
16+
@section('content')
17+
<div class="row">
18+
<div class="col-xs-12 col-md-8">
19+
<div class="box box-primary">
20+
<div class="box-header with-border">
21+
Servers
22+
</div>
23+
<div class="box-body">
24+
<div class="col-xs-12 col-md-6">
25+
<canvas id="servers_chart" width="100%" height="50"></canvas>
26+
</div>
27+
<div class="col-xs-12 col-md-6">
28+
<canvas id="status_chart" width="100%" height="50"></canvas>
29+
</div>
30+
</div>
31+
</div>
32+
</div>
33+
<div class="col-xs-12 col-md-4">
34+
<div class="info-box bg-blue">
35+
<span class="info-box-icon"><i class="fa fa-server"></i></span>
36+
<div class="info-box-content number-info-box-content">
37+
<span class="info-box-text">Servers</span>
38+
<span class="info-box-number">{{ $serversCount }}</span>
39+
</div>
40+
</div>
41+
<div class="info-box bg-blue">
42+
<span class="info-box-icon"><i class="ion ion-ios-barcode-outline"></i></span>
43+
<div class="info-box-content number-info-box-content">
44+
<span class="info-box-text">Total used RAM</span>
45+
<span class="info-box-number">{{ $totalServerRam }}MB</span>
46+
</div>
47+
</div>
48+
<div class="info-box bg-blue">
49+
<span class="info-box-icon"><i class="ion ion-stats-bars"></i></span>
50+
<div class="info-box-content number-info-box-content">
51+
<span class="info-box-text">Total used disk space</span>
52+
<span class="info-box-number">{{ $totalServerDisk }}MB</span>
53+
</div>
54+
</div>
55+
</div>
56+
</div>
57+
<div class="row">
58+
<div class="col-xs-12 col-md-8">
59+
<div class="box box-primary">
60+
<div class="box-header with-border">
61+
Nodes
62+
</div>
63+
<dib class="box-body">
64+
<div class="col-xs-12 col-md-6">
65+
<canvas id="ram_chart" width="100%" height="50"></canvas>
66+
</div>
67+
<div class="col-xs-12 col-md-6">
68+
<canvas id="disk_chart" width="100%" height="50"></canvas>
69+
</div>
70+
</dib>
71+
</div>
72+
</div>
73+
<div class="col-xs-12 col-md-4">
74+
<div class="info-box bg-blue">
75+
<span class="info-box-icon"><i class="ion ion-ios-barcode-outline"></i></span>
76+
<div class="info-box-content number-info-box-content">
77+
<span class="info-box-text">Total RAM</span>
78+
<span class="info-box-number">{{ $totalNodeRam }}MB</span>
79+
</div>
80+
</div>
81+
<div class="info-box bg-blue">
82+
<span class="info-box-icon"><i class="ion ion-stats-bars"></i></span>
83+
<div class="info-box-content number-info-box-content">
84+
<span class="info-box-text">Total Disk Space</span>
85+
<span class="info-box-number">{{ $totalNodeDisk }}MB</span>
86+
</div>
87+
</div>
88+
<div class="info-box bg-blue">
89+
<span class="info-box-icon"><i class="fa fa-location-arrow"></i></span>
90+
<div class="info-box-content number-info-box-content">
91+
<span class="info-box-text">Total Allocations</span>
92+
<span class="info-box-number">{{ $totalAllocations }}</span>
93+
</div>
94+
</div>
95+
</div>
96+
</div>
97+
@endsection
98+
99+
@section('footer-scripts')
100+
@parent
101+
{!! Theme::js('vendor/chartjs/chart.min.js') !!}
102+
{!! Theme::js('js/admin/statistics.js') !!}
103+
@endsection

resources/themes/pterodactyl/layouts/admin.blade.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@
8080
<i class="fa fa-home"></i> <span>Overview</span>
8181
</a>
8282
</li>
83+
<li class="{{ Route::currentRouteName() !== 'admin.statistics' ?: 'active' }}">
84+
<a href="{{ route('admin.statistics') }}">
85+
<i class="fa fa-tachometer"></i> <span>Statistics</span>
86+
</a>
87+
</li>
8388
<li class="{{ ! starts_with(Route::currentRouteName(), 'admin.settings') ?: 'active' }}">
8489
<a href="{{ route('admin.settings')}}">
8590
<i class="fa fa-wrench"></i> <span>Settings</span>

routes/admin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
Route::get('/', 'BaseController@index')->name('admin.index');
4+
Route::get('/statistics', 'StatisticsController@index')->name('admin.statistics');
45

56
/*
67
|--------------------------------------------------------------------------

0 commit comments

Comments
 (0)