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 JavaScript;
use Illuminate\Support\Facades\DB;
use Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService;
class StatisticsController extends Controller
{
private $keyProviderService;
function __construct(DaemonKeyProviderService $keyProviderService)
{
$this->keyProviderService = $keyProviderService;
}
public function index(Request $request)
{
$servers = Server::all();
$nodes = Node::all();
$serversCount = count($servers);
$nodesCount = Node::count();
$usersCount = User::count();
@ -29,17 +38,26 @@ class StatisticsController extends Controller
$totalServerDisk = DB::table('servers')->sum('disk');
$totalNodeDisk = DB::table('nodes')->sum('disk');
$totalAllocations = Allocation::count();
$totalUsersCount = User::count();
$totalDBCount = Database::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([
'servers' => Server::all(),
'servers' => $servers,
'serverCount' => $serversCount,
'suspendedServers' => $suspendedServersCount,
'totalServerRam' => $totalServerRam,
'totalNodeRam' => $totalNodeRam,
'totalServerDisk' => $totalServerDisk,
'totalNodeDisk' => $totalNodeDisk,
'nodes' => $nodes,
'tokens' => $tokens,
]);
return view('admin.statistics', [
@ -53,6 +71,8 @@ class StatisticsController extends Controller
'totalNodeDisk' => $totalNodeDisk,
'totalServerDisk' => $totalServerDisk,
'totalAllocations' => $totalAllocations,
'totalUsersCount' => $totalUsersCount,
'totalDBCount' => $totalDBCount,
]);
}

View File

@ -58,13 +58,25 @@ let statusChart = new Chart($('#status_chart'), {
});
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({
type: 'GET',
url: Router.route('index.status', { server: server.uuidShort}),
url: node.scheme + '://' + node.fqdn + ':'+node.daemonListen+'/v1/server',
timeout: 5000,
headers: {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content'),
'X-Access-Server': uuid,
'X-Access-Token': Pterodactyl.tokens[node.id],
}
}).done(function (data) {
@ -84,7 +96,6 @@ servers.forEach(function (server) {
case 1:
case 2:
// Online
console.log('online');
statusChart.data.datasets[0].data[0]++;
break;
case 20:
@ -98,4 +109,13 @@ servers.forEach(function (server) {
statusChart.data.datasets[0].data[3]++;
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 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
@section('footer-scripts')