Uptime Kuma 是一个开源的 WEB 监控项目,除了常规的 HTTP 请求,还支持了 MySQL Redis 等监控,支持飞书、钉钉等 70 种异常通知方式。
在初期的使用中,发现我设置 5 秒的监控时间,但每一次请求的间隔是不连续的,经过查阅代码后,才发现下一次请求发出是要等当前请求结束,这个是没错的,但是下一次的时间是写死的我们配置的时间(5 秒),相当于我当前请求耗时 1 秒,那下一次请求和当前请求他们发出的时间是相差 6 秒,和我想要的有些差距。
server/model/monitor.js
1 2 3 4 5 6 7 8 9 10 11
| if (! this.isStop) { log.debug("monitor", `[${this.name}] SetTimeout for next check.`);
+ let timestamp = (new Date()).getTime(); // 获取当前时间戳 + let value = beatInterval * 1000 - (timestamp % (beatInterval * 1000)); // 计算出下一次时间
- this.heartbeatInterval = setTimeout(safeBeat, beatInterval * 1000); + this.heartbeatInterval = setTimeout(safeBeat, value); } else { log.info("monitor", `[${this.name}] isStop = true, no next check.`); }
|
