diff --git a/server/server.js b/server/server.js index 3084cad21..49e867da0 100644 --- a/server/server.js +++ b/server/server.js @@ -644,6 +644,38 @@ exports.entryPage = "dashboard"; } }); + socket.on("getMonitorBeats", async (monitorID, period, callback) => { + try { + checkLogin(socket); + + console.log(`Get Monitor Beats: ${monitorID} User ID: ${socket.userID}`); + + if (period == null) { + throw new Error("Invalid period."); + } + + let list = await R.getAll(` + SELECT * FROM heartbeat + WHERE monitor_id = ? AND + time > DATETIME('now', '-' || ? || ' hours') + ORDER BY time ASC + `, [ + monitorID, + period, + ]); + + callback({ + ok: true, + data: list, + }); + } catch (e) { + callback({ + ok: false, + msg: e.message, + }); + } + }); + // Start or Resume the monitor socket.on("resumeMonitor", async (monitorID, callback) => { try { diff --git a/src/components/PingChart.vue b/src/components/PingChart.vue index 0baa9881d..aa209fabe 100644 --- a/src/components/PingChart.vue +++ b/src/components/PingChart.vue @@ -1,16 +1,34 @@ - + + diff --git a/src/mixins/socket.js b/src/mixins/socket.js index d7ac8bcb9..679794496 100644 --- a/src/mixins/socket.js +++ b/src/mixins/socket.js @@ -328,6 +328,10 @@ export default { clearStatistics(callback) { socket.emit("clearStatistics", callback); }, + + getMonitorBeats(monitorID, period, callback) { + socket.emit("getMonitorBeats", monitorID, period, callback); + } }, computed: {