Tune load thresholds for status and alerts

This commit is contained in:
2026-02-08 01:21:25 +03:00
parent 4b895748d1
commit 4989314e2b
3 changed files with 23 additions and 10 deletions

View File

@@ -13,9 +13,10 @@ async def monitor_resources(cfg, notify, bot, chat_id):
disk_warn = int(cfg.get("thresholds", {}).get("disk_warn", 80))
load_warn = float(cfg.get("thresholds", {}).get("load_warn", 2.0))
high_warn = float(cfg.get("thresholds", {}).get("high_load_warn", load_warn * 1.5))
last_sent = {"disk": 0.0, "load": 0.0, "disk_na": 0.0}
state = {"disk_high": False, "load_high": False, "disk_na": False}
state = {"disk_high": False, "disk_na": False, "load_level": 0}
while True:
now = time.time()
@@ -42,15 +43,23 @@ async def monitor_resources(cfg, notify, bot, chat_id):
state["disk_high"] = False
load = psutil.getloadavg()[0]
if load >= load_warn:
if not state["load_high"] or now - last_sent["load"] >= cooldown:
await notify(bot, chat_id, f"🟡 Load high: {load:.2f}")
state["load_high"] = True
last_sent["load"] = now
if load >= high_warn:
level = 2
elif load >= load_warn:
level = 1
else:
if state["load_high"] and notify_recovery:
level = 0
if level == 0:
if state["load_level"] > 0 and notify_recovery:
await notify(bot, chat_id, f"🟢 Load OK: {load:.2f}")
state["load_high"] = False
state["load_level"] = 0
else:
if level != state["load_level"] or now - last_sent["load"] >= cooldown:
icon = "🔴" if level == 2 else "🟡"
await notify(bot, chat_id, f"{icon} Load high: {load:.2f}")
last_sent["load"] = now
state["load_level"] = level
await asyncio.sleep(interval)