1
0
mirror of https://github.com/louislam/uptime-kuma.git synced 2024-11-24 08:32:23 +02:00

fix first beat's uptime is 0%

This commit is contained in:
LouisLam 2021-07-11 20:07:03 +08:00
parent eeb904b1ea
commit d357dcb334
2 changed files with 32 additions and 19 deletions

View File

@ -7,7 +7,7 @@
"update": "",
"build": "vite build",
"vite-preview-dist": "vite preview --host",
"build-docker": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma . --push",
"build-docker": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma -t louislam/uptime-kuma:1 . --push",
"setup": "git checkout 1.0.0 && npm install && npm run build"
},
"dependencies": {

View File

@ -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);
}