|
|
@ -185,7 +185,7 @@ class Monitor extends BeanModel { |
|
|
|
static async sendUptime(duration, io, monitorID, userID) { |
|
|
|
let sec = duration * 3600; |
|
|
|
|
|
|
|
let downtimeList = await R.getAll(` |
|
|
|
let heartbeatList = await R.getAll(` |
|
|
|
SELECT duration, time, status |
|
|
|
FROM heartbeat |
|
|
|
WHERE time > DATETIME('now', ? || ' hours') |
|
|
@ -198,7 +198,17 @@ class Monitor extends BeanModel { |
|
|
|
let total = 0; |
|
|
|
let uptime; |
|
|
|
|
|
|
|
for (let row of downtimeList) { |
|
|
|
// Special handle for the first heartbeat only
|
|
|
|
if (heartbeatList.length === 1) { |
|
|
|
|
|
|
|
if (heartbeatList[0].status === 1) { |
|
|
|
uptime = 1; |
|
|
|
} else { |
|
|
|
uptime = 0; |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
for (let row of heartbeatList) { |
|
|
|
let value = parseInt(row.duration) |
|
|
|
let time = row.time |
|
|
|
|
|
|
@ -224,6 +234,9 @@ class Monitor extends BeanModel { |
|
|
|
if (uptime < 0) { |
|
|
|
uptime = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
io.to(userID).emit("uptime", monitorID, duration, uptime); |
|
|
|
} |
|
|
|