mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-07-21 06:02:04 -04:00
Feat: Use UptimeCalculator
for PingChart (#4264)
Co-authored-by: Frank Elsinga <frank@elsinga.de>
This commit is contained in:
parent
a3ac954140
commit
a581a85633
6 changed files with 426 additions and 76 deletions
38
server/socket-handlers/chart-socket-handler.js
Normal file
38
server/socket-handlers/chart-socket-handler.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
const { checkLogin } = require("../util-server");
|
||||
const { UptimeCalculator } = require("../uptime-calculator");
|
||||
const { log } = require("../../src/util");
|
||||
|
||||
module.exports.chartSocketHandler = (socket) => {
|
||||
socket.on("getMonitorChartData", async (monitorID, period, callback) => {
|
||||
try {
|
||||
checkLogin(socket);
|
||||
|
||||
log.debug("monitor", `Get Monitor Chart Data: ${monitorID} User ID: ${socket.userID}`);
|
||||
|
||||
if (period == null) {
|
||||
throw new Error("Invalid period.");
|
||||
}
|
||||
|
||||
let uptimeCalculator = await UptimeCalculator.getUptimeCalculator(monitorID);
|
||||
|
||||
let data;
|
||||
if (period <= 24) {
|
||||
data = uptimeCalculator.getDataArray(period * 60, "minute");
|
||||
} else if (period <= 720) {
|
||||
data = uptimeCalculator.getDataArray(period, "hour");
|
||||
} else {
|
||||
data = uptimeCalculator.getDataArray(period / 24, "day");
|
||||
}
|
||||
|
||||
callback({
|
||||
ok: true,
|
||||
data,
|
||||
});
|
||||
} catch (e) {
|
||||
callback({
|
||||
ok: false,
|
||||
msg: e.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue