diff --git a/server/model/monitor.js b/server/model/monitor.js index 97b00e280..a96633598 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -20,7 +20,7 @@ class Monitor extends BeanModel { id: this.id, name: this.name, url: this.url, - upRate: this.upRate, + weight: this.weight, active: this.active, type: this.type, interval: this.interval, @@ -91,15 +91,20 @@ class Monitor extends BeanModel { static async sendStats(io, monitorID, userID) { Monitor.sendAvgPing(24, io, monitorID, userID); - //Monitor.sendUptime(24, io, this.id); - //Monitor.sendUptime(24 * 30, io, this.id); + Monitor.sendUptime(24, io, monitorID, userID); + Monitor.sendUptime(24 * 30, io, monitorID, userID); } + /** + * + * @param duration : int Hours + */ static async sendAvgPing(duration, io, monitorID, userID) { let avgPing = parseInt(await R.getCell(` SELECT AVG(ping) FROM heartbeat WHERE time > DATE('now', ? || ' hours') + AND ping IS NOT NULL AND monitor_id = ? `, [ -duration, monitorID @@ -108,8 +113,25 @@ class Monitor extends BeanModel { io.to(userID).emit("avgPing", monitorID, avgPing); } - sendUptime(duration) { + /** + * + * @param duration : int Hours + */ + static async sendUptime(duration, io, monitorID, userID) { + let downtime = parseInt(await R.getCell(` + SELECT SUM(duration) + FROM heartbeat + WHERE time > DATE('now', ? || ' hours') + AND status = 0 + AND monitor_id = ? `, [ + -duration, + monitorID + ])); + let sec = duration * 3600; + let uptime = (sec - downtime) / sec; + + io.to(userID).emit("uptime", monitorID, duration, uptime); } } diff --git a/server/server.js b/server/server.js index 87bad452b..7775e646c 100644 --- a/server/server.js +++ b/server/server.js @@ -340,7 +340,7 @@ async function afterLogin(socket, user) { async function getMonitorJSONList(userID) { let result = {}; - let monitorList = await R.find("monitor", " user_id = ? ORDER BY active DESC, name ASC ", [ + let monitorList = await R.find("monitor", " user_id = ? ", [ userID ]) diff --git a/src/components/Datetime.vue b/src/components/Datetime.vue index 454697ba5..b362ea23e 100644 --- a/src/components/Datetime.vue +++ b/src/components/Datetime.vue @@ -18,9 +18,6 @@ export default { computed: { displayText() { - - console.log(dayjs.tz.guess()) - return this.value }, } diff --git a/src/components/Uptime.vue b/src/components/Uptime.vue new file mode 100644 index 000000000..f752b8f31 --- /dev/null +++ b/src/components/Uptime.vue @@ -0,0 +1,61 @@ + + {{ uptime }} + + + + + diff --git a/src/mixins/socket.js b/src/mixins/socket.js index 132a5d10d..af725d416 100644 --- a/src/mixins/socket.js +++ b/src/mixins/socket.js @@ -17,18 +17,11 @@ export default { }, allowLoginDialog: false, // Allowed to show login dialog, but "loggedIn" have to be true too. This exists because prevent the login dialog show 0.1s in first before the socket server auth-ed. loggedIn: false, - monitorList: [ - - ], - heartbeatList: { - - }, - importantHeartbeatList: { - - }, - avgPingList: { - - } + monitorList: { }, + heartbeatList: { }, + importantHeartbeatList: { }, + avgPingList: { }, + uptimeList: { } } }, @@ -85,6 +78,10 @@ export default { this.avgPingList[monitorID] = data }); + socket.on('uptime', (monitorID, type, data) => { + this.uptimeList[`${monitorID}_${type}`] = data + }); + socket.on('importantHeartbeatList', (monitorID, data) => { if (! (monitorID in this.importantHeartbeatList)) { this.importantHeartbeatList[monitorID] = data; diff --git a/src/pages/Dashboard.vue b/src/pages/Dashboard.vue index d274bed05..9814e2561 100644 --- a/src/pages/Dashboard.vue +++ b/src/pages/Dashboard.vue @@ -11,18 +11,18 @@ No Monitors, please add one. - + - + - {{ item.upRate }}% + {{ item.name }} - + @@ -42,15 +42,49 @@