自己写一个够用的可用性探测
小项目上 Prometheus 加 Grafana 有点重,但完全不做监控又不行。一个够用的版本:
while true; do
code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 10 https://example.com/healthz)
if [ "$code" != "200" ]; then
echo "$(date -Is) fail $code" >> /var/log/probe.log
fi
sleep 60
done
要点:探测要打真正的健康检查端点,而不是首页——首页有缓存,挂了也可能是 200;超时要比间隔短;连续失败三次再告警,避免抖动。
告警渠道用已有的:Telegram bot、邮件、或者干脆 curl 一个 webhook。关键是有人能收到,而不是告警系统有多先进。