Merge branch '1.23.X' into 1.23.X-merge-to-2.X.X-2

# Conflicts:
#	package-lock.json
#	package.json
#	server/model/monitor.js
#	server/monitor-types/tailscale-ping.js
#	server/socket-handlers/general-socket-handler.js
#	server/uptime-kuma-server.js
This commit is contained in:
Louis Lam
2023-11-25 03:25:03 +08:00
10 changed files with 119 additions and 151 deletions

View File

@@ -12,7 +12,6 @@ const { Settings } = require("./settings");
const dayjs = require("dayjs");
const childProcess = require("child_process");
const path = require("path");
const axios = require("axios");
// DO NOT IMPORT HERE IF THE MODULES USED `UptimeKumaServer.getInstance()`, put at the bottom of this file instead.
/**
@@ -62,8 +61,6 @@ class UptimeKumaServer {
*/
jwtSecret = null;
checkMonitorsInterval = null;
/**
* Get the current instance of the server if it exists, otherwise
* create a new instance.
@@ -376,10 +373,6 @@ class UptimeKumaServer {
if (enable || enable === null) {
this.startNSCDServices();
}
this.checkMonitorsInterval = setInterval(() => {
this.checkMonitors();
}, 60 * 1000);
}
/**
@@ -392,8 +385,6 @@ class UptimeKumaServer {
if (enable || enable === null) {
this.stopNSCDServices();
}
clearInterval(this.checkMonitorsInterval);
}
/**
@@ -427,83 +418,6 @@ class UptimeKumaServer {
}
}
/**
* Start the specified monitor
* @param {number} monitorID ID of monitor to start
* @returns {Promise<void>}
*/
async startMonitor(monitorID) {
log.info("manage", `Resume Monitor: ${monitorID} by server`);
await R.exec("UPDATE monitor SET active = 1 WHERE id = ?", [
monitorID,
]);
let monitor = await R.findOne("monitor", " id = ? ", [
monitorID,
]);
if (monitor.id in this.monitorList) {
this.monitorList[monitor.id].stop();
}
this.monitorList[monitor.id] = monitor;
monitor.start(this.io);
}
/**
* Restart a given monitor
* @param {number} monitorID ID of monitor to start
* @returns {Promise<void>}
*/
async restartMonitor(monitorID) {
return await this.startMonitor(monitorID);
}
/**
* Check if monitors are running properly
*/
async checkMonitors() {
log.debug("monitor_checker", "Checking monitors");
for (let monitorID in this.monitorList) {
let monitor = this.monitorList[monitorID];
// Not for push monitor
if (monitor.type === "push") {
continue;
}
if (!monitor.active) {
continue;
}
// Check the lastStartBeatTime, if it is too long, then restart
if (monitor.lastScheduleBeatTime ) {
let diff = dayjs().diff(monitor.lastStartBeatTime, "second");
if (diff > monitor.interval * 1.5) {
log.error("monitor_checker", `Monitor Interval: ${monitor.interval} Monitor ` + monitorID + " lastStartBeatTime diff: " + diff);
log.error("monitor_checker", "Unexpected error: Monitor " + monitorID + " is struck for unknown reason");
log.error("monitor_checker", "Last start beat time: " + R.isoDateTime(monitor.lastStartBeatTime));
log.error("monitor_checker", "Last end beat time: " + R.isoDateTime(monitor.lastEndBeatTime));
log.error("monitor_checker", "Last ScheduleBeatTime: " + R.isoDateTime(monitor.lastScheduleBeatTime));
// Restart
log.error("monitor_checker", `Restarting monitor ${monitorID} automatically now`);
this.restartMonitor(monitorID);
} else {
//log.debug("monitor_checker", "Monitor " + monitorID + " is running normally");
}
} else {
//log.debug("monitor_checker", "Monitor " + monitorID + " is not started yet, skipp");
}
}
log.debug("monitor_checker", "Checking monitors end");
}
/**
* Default User-Agent when making HTTP requests
* @returns {string} User-Agent