Skip to content

Commit

Permalink
Update ApexCharts | Display last 1 hour of Performance Data
Browse files Browse the repository at this point in the history
  • Loading branch information
ToBiDi0410 committed Feb 7, 2022
1 parent a905f5a commit 159bf41
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/main/java/de/tobias/spigotdash/utils/taskManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static void startTasks() {
}

if(lastClearUpdate + 1000*120 <= System.currentTimeMillis()) {
dataFetcher.clearWithTime(main.cacheFile.jsonTree.get("PERFORMANCE_DATA").getAsJsonArray(), (1000 * 60 * 10));
dataFetcher.clearWithTime(main.cacheFile.jsonTree.get("PERFORMANCE_DATA").getAsJsonArray(), (1000 * 60 * 60));
lastClearUpdate = System.currentTimeMillis();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public static boolean unusedJARFiles() {
// ** PERFORMANCE GENERAL **
public static Object getPerformanceDataForWeb() {
JsonArray entrys = main.cacheFile.jsonTree.get("PERFORMANCE_DATA").getAsJsonArray();
clearWithTime(entrys, (1000 * 60 * 10));
clearWithTime(entrys, (1000 * 60 * 60));
return entrys;

}
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/www/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
10 changes: 5 additions & 5 deletions src/main/resources/www/global/other-license/apexcharts.js

Large diffs are not rendered by default.

23 changes: 17 additions & 6 deletions src/main/resources/www/pages/performance/graphs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var ramchart;
var enginechart;
var cpuchart;

var GLOBAL_CHART_OPTIONS = {}

function initCPUChart() {
var options = {
series: [],
Expand All @@ -29,8 +31,9 @@ function initCPUChart() {
return value.toFixed(2) + "%";
}
}
},
}
};
options = {...options, ...GLOBAL_CHART_OPTIONS }

cpuchart = new ApexCharts(document.querySelector("#cpuchart"), options);
cpuchart.render();
Expand Down Expand Up @@ -65,6 +68,7 @@ function initRAMChart() {
show: false,
}]
};
options = {...options, ...GLOBAL_CHART_OPTIONS }

ramchart = new ApexCharts(document.querySelector("#ramchart"), options);
ramchart.render();
Expand Down Expand Up @@ -96,6 +100,7 @@ function initTPSChart() {
show: false,
}]
};
options = {...options, ...GLOBAL_CHART_OPTIONS }

tpschart = new ApexCharts(document.querySelector("#tpschart"), options);
tpschart.render();
Expand Down Expand Up @@ -129,6 +134,7 @@ function initEngineChart() {
show: false,
}]
};
options = {...options, ...GLOBAL_CHART_OPTIONS }

enginechart = new ApexCharts(document.querySelector("#enginechart"), options);
enginechart.render();
Expand Down Expand Up @@ -203,7 +209,7 @@ async function updateData() {
},
min: MIN_STOR,
max: MAX_STOR,
}]
}],
},
series: [{
name: "%T%RAM_ALLOCATED%T%",
Expand Down Expand Up @@ -256,7 +262,7 @@ async function updateData() {
}

data.forEach((elem) => {
var elem_date = transformDate(new Date(elem.DATETIME));
var elem_date = dateFormatter(new Date(elem.DATETIME));
RAM_GRAPH.series[0].data.push({ x: elem_date, y: elem.MEMORY_ALLOCATED });
RAM_GRAPH.series[1].data.push({ x: elem_date, y: elem.MEMORY_USED });
RAM_GRAPH.series[2].data.push({ x: elem_date, y: bytesToGB(elem.TOTAL_SPACE) });
Expand All @@ -272,7 +278,6 @@ async function updateData() {
ENGINE_GRAPH.series[0].data.push({ x: elem_date, y: elem.WORLD_CHUNKS });
ENGINE_GRAPH.series[1].data.push({ x: elem_date, y: elem.WORLD_ENTITIES });
ENGINE_GRAPH.series[2].data.push({ x: elem_date, y: elem.WORLD_PLAYERS });

});

ramchart.updateOptions(RAM_GRAPH.options);
Expand All @@ -289,8 +294,14 @@ async function updateData() {

}

function transformDate(date) {
return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
function dateFormatter(value) {
try {
var date = new Date(value);
return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
} catch (err) {
return "ERR";
}

}

function bytesToGB(bytes) {
Expand Down

0 comments on commit 159bf41

Please sign in to comment.