feat: Umami/ntfy 可观测性栈与 WordPress AdSense 部署
This commit is contained in:
39
deploy/observability/healthcheck.sh
Normal file
39
deploy/observability/healthcheck.sh
Normal file
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
# Healthcheck key public services; notify ntfy on failure transitions.
|
||||
set -euo pipefail
|
||||
|
||||
STATE_DIR=/var/lib/nomadro-health
|
||||
NOTIFY=/usr/local/bin/notify-ntfy
|
||||
mkdir -p "$STATE_DIR"
|
||||
|
||||
check() {
|
||||
local name="$1"
|
||||
local cmd="$2"
|
||||
local ok=0
|
||||
if eval "$cmd" >/dev/null 2>&1; then
|
||||
ok=1
|
||||
fi
|
||||
local state_file="$STATE_DIR/${name}.ok"
|
||||
local prev=1
|
||||
[[ -f "$state_file" ]] && prev=$(cat "$state_file")
|
||||
echo "$ok" >"$state_file"
|
||||
if [[ "$ok" -eq 0 && "$prev" -eq 1 ]]; then
|
||||
"$NOTIFY" "Service down: $name" "Host $(hostname) — $name failed health check at $(date -u +%Y-%m-%dT%H:%M:%SZ)" high "rotating_light,server" || true
|
||||
elif [[ "$ok" -eq 1 && "$prev" -eq 0 ]]; then
|
||||
"$NOTIFY" "Service recovered: $name" "Host $(hostname) — $name is healthy again" default "white_check_mark,server" || true
|
||||
fi
|
||||
}
|
||||
|
||||
check caddy "systemctl is-active --quiet caddy"
|
||||
check docker "systemctl is-active --quiet docker"
|
||||
check nomadro "systemctl is-active --quiet nomadro"
|
||||
check nomadro-router "systemctl is-active --quiet nomadro-router"
|
||||
check wordpress "curl -fsS -o /dev/null http://127.0.0.1:8088/"
|
||||
check umami "curl -fsS -o /dev/null http://127.0.0.1:3010/api/heartbeat"
|
||||
check ntfy "curl -fsS http://127.0.0.1:2586/v1/health | grep -q healthy"
|
||||
check dylive "curl -fsS -o /dev/null -H 'Host: dylive.nomadro.com' http://127.0.0.1:4015/"
|
||||
check nomadro-live "curl -fsS -o /dev/null http://127.0.0.1:3015/"
|
||||
check wx "curl -fsS -o /dev/null http://127.0.0.1:3000/"
|
||||
check public-nomadro "curl -fsS -o /dev/null https://nomadro.com/"
|
||||
check public-umami "curl -fsS -o /dev/null https://umami.nomadro.com/api/heartbeat"
|
||||
check public-ntfy "curl -fsS https://ntfy.nomadro.com/v1/health | grep -q healthy"
|
||||
Reference in New Issue
Block a user