今年看RSS订阅中的年终总结时,频繁看到 uptime-kuma1 ,其实之前就耳闻过,这次刚好有动力折腾一下。在此之前我的监控需求主要由两个工具满足,其一是 uptimerobot2,主要监控网站是否正常,其二是 healthcheck3,主要监控定时任务是否正常。
从名字来看,我一直以为 uptime-kuma 只能替代 uptimerobot,没想到部署后发现对于定时任务 uptime-kuma 也可以使用 Push 的方式被动监控,因此完美替代了我此前的监控需求。删除 healthcheck 账户,uptimerobot 留着继续监控 uptime-kuma 本身。
另外在折腾的过程中,我的 Telegram Bot 频繁出问题,因此和大模型聊了一下 uptime-kuma 是否可以监控 Telegram Bot 的运行状况,Gemini 给了非常不错的回答,按照实现难度从低到高给了3种方案。
| 方案 | 监控粒度 | 复杂度 | 适用场景 |
|---|---|---|---|
| Push 心跳 | 进程级 | 低 | 最通用,适合大多数个人 Bot |
| HTTP 检查 | 服务级 | 中 | 适合使用 Webhook 部署的专业 Bot |
| 模拟用户 | 业务级 | 高 | 关键业务,需要确保指令响应完全正常 |
偷懒的个人用户当然选择 Push 心跳方式,在 uptime-kuma 中还是使用和定时任务一样的 Push 监控,需要在 Telegram Bot 的代码中实现心跳逻辑。
import requests
from apscheduler.schedulers.background import BackgroundScheduler
def send_heartbeat():
try:
requests.get("https://your-kuma-url/api/push/TOKEN?status=up&msg=OK")
except Exception as e:
print(f"Heartbeat failed: {e}")
scheduler = BackgroundScheduler()
scheduler.add_job(send_heartbeat, 'interval', minutes=1)
scheduler.start()
参考 #
-
A fancy self-hosted monitoring tool https://github.com/louislam/uptime-kuma ↩︎
-
Simple and Effective Cron Job Monitoring https://healthchecks.io/ ↩︎
-
The world’s leading uptime monitoring service https://uptimerobot.com/, ↩︎