Skip to content

Commit f560020

Browse files
committed
Fix CPU usage display for server
Previously was stacked and would show 2x normal usage.
1 parent edf0939 commit f560020

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

resources/views/server/index.blade.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@
201201
width: $('#col11_setter').width()
202202
},
203203
colors: [
204-
'#113F8C',
205204
'#00A1CB',
206205
'#01A4A4',
207206
'#61AE24',
@@ -223,13 +222,22 @@
223222
crosshairs: true,
224223
formatter: function () {
225224
var s = '<b>CPU Usage</b>';
226-
225+
var i = 0;
226+
var t = 0;
227227
$.each(this.points, function () {
228+
t = t + this.y;
229+
i++;
228230
s += '<br/>' + this.series.name + ': ' +
229231
this.y + '%';
230232
});
231233
232-
return s;
234+
t = parseFloat(t).toFixed(3).toString();
235+
236+
if (i > 1) {
237+
return s + '<br />Combined: ' + t;
238+
} else {
239+
return s;
240+
}
233241
},
234242
},
235243
xAxis: {
@@ -258,7 +266,7 @@
258266
enabled: true
259267
},
260268
series: [{
261-
name: 'Total CPU',
269+
name: 'Core 0',
262270
data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
263271
}]
264272
});
@@ -270,22 +278,22 @@
270278
271279
var CPUChart = $('#chart_cpu').highcharts();
272280
273-
if({{ $server->cpu }} > 0) {
274-
CPUChart.series[0].addPoint(parseFloat(((proc.data.cpu.total / {{ $server->cpu }}) * 100).toFixed(3).toString()), true, true);
275-
} else {
276-
CPUChart.series[0].addPoint(proc.data.cpu.total, true, true);
277-
}
281+
// if({{ $server->cpu }} > 0) {
282+
// CPUChart.series[0].addPoint(parseFloat(((proc.data.cpu.total / {{ $server->cpu }}) * 100).toFixed(3).toString()), true, true);
283+
// } else {
284+
// CPUChart.series[0].addPoint(proc.data.cpu.total, true, true);
285+
// }
278286
for (i = 0, length = proc.data.cpu.cores.length; i < length; i++) {
279-
if (typeof CPUChart.series[ i + 1 ] === 'undefined') {
287+
if (typeof CPUChart.series[i] === 'undefined') {
280288
CPUChart.addSeries({
281289
name: 'Core ' + i,
282290
data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
283291
});
284292
}
285293
if({{ $server->cpu }} > 0) {
286-
CPUChart.series[ i + 1 ].addPoint(parseFloat(((proc.data.cpu.cores[i] / {{ $server->cpu }}) * 100).toFixed(3).toString()), true, true);
294+
CPUChart.series[i].addPoint(parseFloat(((proc.data.cpu.cores[i] / {{ $server->cpu }}) * 100).toFixed(3).toString()), true, true);
287295
} else {
288-
CPUChart.series[ i + 1 ].addPoint(proc.data.cpu.cores[i], true, true);
296+
CPUChart.series[i].addPoint(proc.data.cpu.cores[i], true, true);
289297
}
290298
}
291299
});

0 commit comments

Comments
 (0)