mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-27 16:54:04 +00:00
improve uptime calculation
This commit is contained in:
parent
d4a651e211
commit
ea1556ef81
1 changed files with 40 additions and 17 deletions
|
@ -158,7 +158,9 @@ class Monitor extends BeanModel {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let downtime = 0;
|
let downtime = 0;
|
||||||
|
let uptime = 0;
|
||||||
|
|
||||||
|
if (downtimeList.length === 0) {
|
||||||
for (let row of downtimeList) {
|
for (let row of downtimeList) {
|
||||||
let value = parseInt(row.duration)
|
let value = parseInt(row.duration)
|
||||||
let time = row.time
|
let time = row.time
|
||||||
|
@ -179,11 +181,32 @@ class Monitor extends BeanModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let uptime = (sec - downtime) / sec;
|
uptime = (sec - downtime) / sec;
|
||||||
|
|
||||||
if (uptime < 0) {
|
if (uptime < 0) {
|
||||||
uptime = 0;
|
uptime = 0;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// This case for someone who are not running UptimeKuma 24x7.
|
||||||
|
// If there is no heartbeat in this time range, use last heartbeat as reference
|
||||||
|
// If is down, uptime = 0
|
||||||
|
// If is up, uptime = 1
|
||||||
|
|
||||||
|
let lastHeartbeat = await R.findOne("heartbeat", " monitor_id = ? ORDER BY time DESC", [
|
||||||
|
monitorID
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (lastHeartbeat) {
|
||||||
|
if (lastHeartbeat.status === 1) {
|
||||||
|
uptime = 1;
|
||||||
|
} else {
|
||||||
|
uptime = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// No heartbeat is found, assume 100%
|
||||||
|
uptime = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
io.to(userID).emit("uptime", monitorID, duration, uptime);
|
io.to(userID).emit("uptime", monitorID, duration, uptime);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue