Skip to content

Commit cd7ec73

Browse files
Martin GafertDaneEveritt
authored andcommitted
Change Console Chart yAxes to start at 0 and calculate maximum depending on server config (pterodactyl#1535)
* Change Console Chart to start yAxes at 0 * Add calculation for Console Chart yAxes maximum if data is recieved * Fix problem with calculating memory maximum
1 parent 3290d39 commit cd7ec73

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

public/themes/pterodactyl/js/frontend/console.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,31 @@ $(document).ready(function () {
255255

256256
TimeLabels.push($.format.date(new Date(), 'HH:mm:ss'));
257257

258+
259+
// memory.cmax is the maximum given by the container
260+
// memory.amax is given by the json config
261+
// use the maximum of both
262+
// with no limit memory.cmax will always be higher
263+
// but with limit memory.amax is sometimes still smaller than memory.total
264+
MemoryChart.config.options.scales.yAxes[0].ticks.max = Math.max(proc.data.memory.cmax, proc.data.memory.amax) / (1000 * 1000);
265+
266+
if (Pterodactyl.server.cpu > 0) {
267+
// if there is a cpu limit defined use 100% as maximum
268+
CPUChart.config.options.scales.yAxes[0].ticks.max = 100;
269+
} else {
270+
// if there is no cpu limit defined use linux percentage
271+
// and find maximum in all values
272+
var maxCpu = 1;
273+
for(var i = 0; i < CPUData.length; i++) {
274+
maxCpu = Math.max(maxCpu, parseFloat(CPUData[i]))
275+
}
276+
277+
maxCpu = Math.ceil(maxCpu / 100) * 100;
278+
CPUChart.config.options.scales.yAxes[0].ticks.max = maxCpu;
279+
}
280+
281+
282+
258283
CPUChart.update();
259284
MemoryChart.update();
260285
});
@@ -301,6 +326,13 @@ $(document).ready(function () {
301326
},
302327
animation: {
303328
duration: 1,
329+
},
330+
scales: {
331+
yAxes: [{
332+
ticks: {
333+
beginAtZero: true
334+
}
335+
}]
304336
}
305337
}
306338
});
@@ -346,6 +378,13 @@ $(document).ready(function () {
346378
},
347379
animation: {
348380
duration: 1,
381+
},
382+
scales: {
383+
yAxes: [{
384+
ticks: {
385+
beginAtZero: true
386+
}
387+
}]
349388
}
350389
}
351390
});

0 commit comments

Comments
 (0)