1
0
mirror of https://github.com/louislam/uptime-kuma.git synced 2025-11-23 22:37:10 +02:00

fix: Clear all statistics and clear heartbeats not resetting uptime statistics of monitors (#6398)
Some checks failed
Automatically close stale issues / stale (push) Has been cancelled
Merge Conflict Labeler / Labeling (push) Has been cancelled
validate / json-yaml-validate (push) Has been cancelled
validate / validate (push) Has been cancelled
Auto Test / armv7-simple-test (20, ARMv7) (push) Has been cancelled
Auto Test / armv7-simple-test (22, ARMv7) (push) Has been cancelled
Auto Test / check-linters (push) Has been cancelled
Auto Test / e2e-test (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Auto Test / auto-test (20, ARM64) (push) Has been cancelled
Auto Test / auto-test (20, macos-latest) (push) Has been cancelled
Auto Test / auto-test (20, ubuntu-22.04) (push) Has been cancelled
Auto Test / auto-test (20, windows-latest) (push) Has been cancelled
Auto Test / auto-test (25, ubuntu-22.04) (push) Has been cancelled
Auto Test / auto-test (24, ARM64) (push) Has been cancelled
Auto Test / auto-test (24, macos-latest) (push) Has been cancelled
Auto Test / auto-test (24, ubuntu-22.04) (push) Has been cancelled
Auto Test / auto-test (24, windows-latest) (push) Has been cancelled

This commit is contained in:
Sn0r1ax
2025-11-23 12:46:32 +08:00
committed by GitHub
parent 23498e4134
commit 082e4b9712
2 changed files with 51 additions and 7 deletions

View File

@@ -109,6 +109,7 @@ const { login } = require("./auth");
const passwordHash = require("./password-hash");
const { Prometheus } = require("./prometheus");
const { UptimeCalculator } = require("./uptime-calculator");
const hostname = config.hostname;
@@ -1592,9 +1593,11 @@ let needSetup = false;
log.info("manage", `Clear Heartbeats Monitor: ${monitorID} User ID: ${socket.userID}`);
await R.exec("DELETE FROM heartbeat WHERE monitor_id = ?", [
monitorID
]);
await UptimeCalculator.clearStatistics(monitorID);
if (monitorID in server.monitorList) {
await restartMonitor(socket.userID, monitorID);
}
await sendHeartbeatList(socket, monitorID, true, true);
@@ -1616,10 +1619,7 @@ let needSetup = false;
log.info("manage", `Clear Statistics User ID: ${socket.userID}`);
await R.exec("DELETE FROM heartbeat");
await R.exec("DELETE FROM stat_daily");
await R.exec("DELETE FROM stat_hourly");
await R.exec("DELETE FROM stat_minutely");
await UptimeCalculator.clearAllStatistics();
// Restart all monitors to reset the stats
for (let monitorID in server.monitorList) {

View File

@@ -90,6 +90,14 @@ class UptimeCalculator {
delete UptimeCalculator.list[monitorID];
}
/**
* Remove all monitors from the list
* @returns {Promise<void>}
*/
static async removeAll() {
UptimeCalculator.list = {};
}
/**
*
*/
@@ -845,6 +853,42 @@ class UptimeCalculator {
setMigrationMode(value) {
this.migrationMode = value;
}
/**
* Clear all statistics and heartbeats for a monitor
* @param {number} monitorID the id of the monitor
* @returns {Promise<void>}
*/
static async clearStatistics(monitorID) {
await R.exec("DELETE FROM heartbeat WHERE monitor_id = ?", [
monitorID
]);
await R.exec("DELETE FROM stat_minutely WHERE monitor_id = ?", [
monitorID
]);
await R.exec("DELETE FROM stat_hourly WHERE monitor_id = ?", [
monitorID
]);
await R.exec("DELETE FROM stat_daily WHERE monitor_id = ?", [
monitorID
]);
await UptimeCalculator.remove(monitorID);
}
/**
* Clear all statistics and heartbeats for all monitors
* @returns {Promise<void>}
*/
static async clearAllStatistics() {
await R.exec("DELETE FROM heartbeat");
await R.exec("DELETE FROM stat_minutely");
await R.exec("DELETE FROM stat_hourly");
await R.exec("DELETE FROM stat_daily");
await UptimeCalculator.removeAll();
}
}
class UptimeDataResult {