Skip to content

Commit cc9cfc7

Browse files
committed
Fix browser crashing; closes pterodactyl#38
1 parent 35de668 commit cc9cfc7

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

resources/views/server/index.blade.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,28 +298,47 @@
298298
});
299299
300300
// Socket Recieves New Server Stats
301+
var activeChartArrays = [];
301302
socket.on('proc', function (proc) {
302303
var MemoryChart = $('#chart_memory').highcharts();
303304
MemoryChart.series[0].addPoint(parseInt(proc.data.memory.total / (1024 * 1024)), true, true);
304305
305306
var CPUChart = $('#chart_cpu').highcharts();
306307
307-
// if({{ $server->cpu }} > 0) {
308-
// CPUChart.series[0].addPoint(parseFloat(((proc.data.cpu.total / {{ $server->cpu }}) * 100).toFixed(3).toString()), true, true);
309-
// } else {
310-
// CPUChart.series[0].addPoint(proc.data.cpu.total, true, true);
311-
// }
308+
// Remove blank values from listing
309+
var activeCores = [];
312310
for (i = 0, length = proc.data.cpu.cores.length; i < length; i++) {
311+
if (proc.data.cpu.cores[i] > 0) {
312+
activeCores.push(proc.data.cpu.cores[i]);
313+
}
314+
}
315+
316+
var modifedActiveCores = { '0': 0 };
317+
for (i = 0, length = activeCores.length; i < length; i++) {
318+
if (i > 7) {
319+
modifedActiveCores['0'] = modifedActiveCores['0'] + activeCores[i];
320+
} else {
321+
if (activeChartArrays.indexOf(i) < 0) {
322+
activeChartArrays.push(i);
323+
}
324+
modifedActiveCores[i] = activeCores[i];
325+
}
326+
}
327+
328+
console.log(activeChartArrays);
329+
console.log(modifedActiveCores);
330+
331+
for (i = 0, length = activeChartArrays.length; i < length; i++) {
313332
if (typeof CPUChart.series[i] === 'undefined') {
314333
CPUChart.addSeries({
315334
name: 'Core ' + i,
316335
data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
317336
});
318337
}
319338
if({{ $server->cpu }} > 0) {
320-
CPUChart.series[i].addPoint(parseFloat(((proc.data.cpu.cores[i] / {{ $server->cpu }}) * 100).toFixed(3).toString()), true, true);
339+
CPUChart.series[i].addPoint(parseFloat((((modifedActiveCores[i] || 0)/ {{ $server->cpu }}) * 100).toFixed(3).toString()), true, true);
321340
} else {
322-
CPUChart.series[i].addPoint(proc.data.cpu.cores[i], true, true);
341+
CPUChart.series[i].addPoint(modifedActiveCores[i] || 0, true, true);
323342
}
324343
}
325344
});

0 commit comments

Comments
 (0)