Skip to content

Commit 28a97fe

Browse files
committed
Polished it up
1 parent 93a7d11 commit 28a97fe

File tree

3 files changed

+84
-6
lines changed

3 files changed

+84
-6
lines changed

app/Http/Controllers/Admin/StatisticsController.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,22 @@
1212
use Pterodactyl\Models\User;
1313
use JavaScript;
1414
use Illuminate\Support\Facades\DB;
15+
use Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService;
1516

1617
class StatisticsController extends Controller
1718
{
1819

20+
private $keyProviderService;
21+
22+
function __construct(DaemonKeyProviderService $keyProviderService)
23+
{
24+
$this->keyProviderService = $keyProviderService;
25+
}
26+
1927
public function index(Request $request)
2028
{
2129
$servers = Server::all();
30+
$nodes = Node::all();
2231
$serversCount = count($servers);
2332
$nodesCount = Node::count();
2433
$usersCount = User::count();
@@ -29,17 +38,26 @@ public function index(Request $request)
2938
$totalServerDisk = DB::table('servers')->sum('disk');
3039
$totalNodeDisk = DB::table('nodes')->sum('disk');
3140
$totalAllocations = Allocation::count();
41+
$totalUsersCount = User::count();
42+
$totalDBCount = Database::count();
3243

3344
$suspendedServersCount = Server::where('suspended', true)->count();
3445

46+
$tokens = [];
47+
foreach ($nodes as $node) {
48+
$tokens[$node->id] = $this->keyProviderService->handle($node->servers->get(0), $request->user());
49+
}
50+
3551
Javascript::put([
36-
'servers' => Server::all(),
52+
'servers' => $servers,
3753
'serverCount' => $serversCount,
3854
'suspendedServers' => $suspendedServersCount,
3955
'totalServerRam' => $totalServerRam,
4056
'totalNodeRam' => $totalNodeRam,
4157
'totalServerDisk' => $totalServerDisk,
4258
'totalNodeDisk' => $totalNodeDisk,
59+
'nodes' => $nodes,
60+
'tokens' => $tokens,
4361
]);
4462

4563
return view('admin.statistics', [
@@ -53,6 +71,8 @@ public function index(Request $request)
5371
'totalNodeDisk' => $totalNodeDisk,
5472
'totalServerDisk' => $totalServerDisk,
5573
'totalAllocations' => $totalAllocations,
74+
'totalUsersCount' => $totalUsersCount,
75+
'totalDBCount' => $totalDBCount,
5676
]);
5777
}
5878

public/themes/pterodactyl/js/admin/statistics.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,25 @@ let statusChart = new Chart($('#status_chart'), {
5858
});
5959

6060
var servers = Pterodactyl.servers;
61-
servers.forEach(function (server) {
61+
var nodes = Pterodactyl.nodes;
62+
63+
for (let i = 0; i < servers.length; i++) {
64+
setTimeout(getStatus, 200 * i);
65+
}
66+
67+
var index = 0;
68+
function getStatus() {
69+
var server = servers[index];
70+
var uuid = server.uuid;
71+
var node = getNodeByID(server.node_id);
72+
6273
$.ajax({
6374
type: 'GET',
64-
url: Router.route('index.status', { server: server.uuidShort}),
75+
url: node.scheme + '://' + node.fqdn + ':'+node.daemonListen+'/v1/server',
6576
timeout: 5000,
6677
headers: {
67-
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content'),
78+
'X-Access-Server': uuid,
79+
'X-Access-Token': Pterodactyl.tokens[node.id],
6880
}
6981
}).done(function (data) {
7082

@@ -84,7 +96,6 @@ servers.forEach(function (server) {
8496
case 1:
8597
case 2:
8698
// Online
87-
console.log('online');
8899
statusChart.data.datasets[0].data[0]++;
89100
break;
90101
case 20:
@@ -98,4 +109,13 @@ servers.forEach(function (server) {
98109
statusChart.data.datasets[0].data[3]++;
99110
statusChart.update();
100111
});
101-
});
112+
113+
index++;
114+
}
115+
116+
function getNodeByID(id) {
117+
for (var i = 0; i < nodes.length; i++) {
118+
if (nodes[i].id === id)
119+
return nodes[i];
120+
}
121+
}

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,44 @@
9494
</div>
9595
</div>
9696
</div>
97+
<div class="row">
98+
<div class="col-xs-12 col-md-3">
99+
<div class="info-box bg-blue">
100+
<span class="info-box-icon"><i class="fa fa-gamepad"></i></span>
101+
<div class="info-box-content number-info-box-content">
102+
<span class="info-box-text">Total Eggs</span>
103+
<span class="info-box-number">{{ $eggsCount }}</span>
104+
</div>
105+
</div>
106+
</div>
107+
<div class="col-xs-12 col-md-3">
108+
<div class="info-box bg-blue">
109+
<span class="info-box-icon"><i class="fa fa-users"></i></span>
110+
<div class="info-box-content number-info-box-content">
111+
<span class="info-box-text">Total Users</span>
112+
<span class="info-box-number">{{ $totalUsersCount }}</span>
113+
</div>
114+
</div>
115+
</div>
116+
<div class="col-xs-12 col-md-3">
117+
<div class="info-box bg-blue">
118+
<span class="info-box-icon"><i class="fa fa-server"></i></span>
119+
<div class="info-box-content number-info-box-content">
120+
<span class="info-box-text">Total Nodes</span>
121+
<span class="info-box-number">{{ $nodesCount }}</span>
122+
</div>
123+
</div>
124+
</div>
125+
<div class="col-xs-12 col-md-3">
126+
<div class="info-box bg-blue">
127+
<span class="info-box-icon"><i class="fa fa-database"></i></span>
128+
<div class="info-box-content number-info-box-content">
129+
<span class="info-box-text">Total Databases</span>
130+
<span class="info-box-number">{{ $totalDBCount }}</span>
131+
</div>
132+
</div>
133+
</div>
134+
</div>
97135
@endsection
98136

99137
@section('footer-scripts')

0 commit comments

Comments
 (0)