2018-05-04 16:45:37 +00:00
|
|
|
var freeDisk = Pterodactyl.totalNodeDisk - Pterodactyl.totalServerDisk;
|
|
|
|
let diskChart = new Chart($('#disk_chart'), {
|
|
|
|
type: 'pie',
|
|
|
|
data: {
|
|
|
|
labels: ['Free Disk', 'Used Disk'],
|
|
|
|
datasets: [
|
|
|
|
{
|
2018-05-26 19:02:47 +00:00
|
|
|
label: 'Disk (in MB)',
|
2018-05-04 16:45:37 +00:00
|
|
|
backgroundColor: ['#51B060', '#ff0000'],
|
|
|
|
data: [freeDisk, Pterodactyl.totalServerDisk]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var freeRam = Pterodactyl.totalNodeRam - Pterodactyl.totalServerRam;
|
|
|
|
let ramChart = new Chart($('#ram_chart'), {
|
|
|
|
type: 'pie',
|
|
|
|
data: {
|
|
|
|
labels: ['Free RAM', 'Used RAM'],
|
|
|
|
datasets: [
|
|
|
|
{
|
2018-05-26 19:02:47 +00:00
|
|
|
label: 'Memory (in MB)',
|
2018-05-04 16:45:37 +00:00
|
|
|
backgroundColor: ['#51B060', '#ff0000'],
|
|
|
|
data: [freeRam, Pterodactyl.totalServerRam]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-05-26 22:16:13 +00:00
|
|
|
var activeServers = Pterodactyl.servers.length - Pterodactyl.suspendedServers;
|
2018-05-04 16:45:37 +00:00
|
|
|
let serversChart = new Chart($('#servers_chart'), {
|
|
|
|
type: 'pie',
|
|
|
|
data: {
|
|
|
|
labels: ['Active', 'Suspended'],
|
|
|
|
datasets: [
|
|
|
|
{
|
|
|
|
label: 'Servers',
|
|
|
|
backgroundColor: ['#51B060', '#E08E0B'],
|
|
|
|
data: [activeServers, Pterodactyl.suspendedServers]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
let statusChart = new Chart($('#status_chart'), {
|
|
|
|
type: 'pie',
|
|
|
|
data: {
|
|
|
|
labels: ['Online', 'Offline', 'Installing', 'Error'],
|
|
|
|
datasets: [
|
|
|
|
{
|
|
|
|
label: '',
|
|
|
|
backgroundColor: ['#51B060', '#b7b7b7', '#E08E0B', '#ff0000'],
|
|
|
|
data: [0,0,0,0]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var servers = Pterodactyl.servers;
|
2018-05-04 20:48:43 +00:00
|
|
|
var nodes = Pterodactyl.nodes;
|
|
|
|
|
|
|
|
for (let i = 0; i < servers.length; i++) {
|
2018-05-06 15:59:11 +00:00
|
|
|
setTimeout(getStatus, 200 * i, servers[i]);
|
2018-05-04 20:48:43 +00:00
|
|
|
}
|
|
|
|
|
2018-05-06 15:59:11 +00:00
|
|
|
function getStatus(server) {
|
2018-05-04 20:48:43 +00:00
|
|
|
var uuid = server.uuid;
|
|
|
|
var node = getNodeByID(server.node_id);
|
|
|
|
|
2018-05-04 16:45:37 +00:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
2018-05-04 20:48:43 +00:00
|
|
|
url: node.scheme + '://' + node.fqdn + ':'+node.daemonListen+'/v1/server',
|
2018-05-04 16:45:37 +00:00
|
|
|
timeout: 5000,
|
|
|
|
headers: {
|
2018-05-04 20:48:43 +00:00
|
|
|
'X-Access-Server': uuid,
|
|
|
|
'X-Access-Token': Pterodactyl.tokens[node.id],
|
2018-05-04 16:45:37 +00:00
|
|
|
}
|
|
|
|
}).done(function (data) {
|
|
|
|
|
|
|
|
if (typeof data.status === 'undefined') {
|
|
|
|
// Error
|
|
|
|
statusChart.data.datasets[0].data[3]++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (data.status) {
|
|
|
|
case 0:
|
|
|
|
case 3:
|
|
|
|
case 30:
|
|
|
|
// Offline
|
|
|
|
statusChart.data.datasets[0].data[1]++;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
// Online
|
|
|
|
statusChart.data.datasets[0].data[0]++;
|
|
|
|
break;
|
|
|
|
case 20:
|
|
|
|
// Installing
|
|
|
|
statusChart.data.datasets[0].data[2]++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
statusChart.update();
|
|
|
|
}).fail(function (jqXHR) {
|
|
|
|
// Error
|
|
|
|
statusChart.data.datasets[0].data[3]++;
|
|
|
|
statusChart.update();
|
|
|
|
});
|
2018-05-04 20:48:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getNodeByID(id) {
|
|
|
|
for (var i = 0; i < nodes.length; i++) {
|
2018-05-06 15:59:11 +00:00
|
|
|
if (nodes[i].id === id) {
|
2018-05-04 20:48:43 +00:00
|
|
|
return nodes[i];
|
2018-05-06 15:59:11 +00:00
|
|
|
}
|
2018-05-04 20:48:43 +00:00
|
|
|
}
|
|
|
|
}
|