Files
tg-admin-bot/health.py
2026-02-07 21:34:24 +03:00

32 lines
977 B
Python

import subprocess, psutil
def health(cfg):
lines = ["🩺 Health check\n"]
try:
subprocess.check_output(["restic", "snapshots"], timeout=10)
lines.append("🟢 Backup repo reachable")
except Exception:
lines.append("🔴 Backup repo unreachable")
for alias, real in cfg["docker"]["containers"].items():
out = subprocess.getoutput(
f"docker inspect -f '{{{{.State.Status}}}}' {real}"
)
if out.strip() != "running":
lines.append(f"🔴 {alias} down")
else:
lines.append(f"🟢 {alias} OK")
disk = psutil.disk_usage("/mnt/data")
usage = disk.percent
if usage > cfg["thresholds"]["disk_warn"]:
lines.append(f"🟡 Disk usage {usage}%")
else:
lines.append(f"🟢 Disk {usage}%")
load = psutil.getloadavg()[0]
lines.append(f"{'🟢' if load < cfg['thresholds']['load_warn'] else '🟡'} Load {load}")
return "\n".join(lines)