Initial version of Telegram admin bot
This commit is contained in:
31
health.py
Normal file
31
health.py
Normal file
@@ -0,0 +1,31 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user