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

@@ -11,6 +11,7 @@ paths:
thresholds: thresholds:
disk_warn: 80 disk_warn: 80
load_warn: 2.0 load_warn: 2.0
high_load_warn: 3.0
alerts: alerts:
enabled: true enabled: true

View File

@@ -21,10 +21,13 @@ async def cmd_status(msg: Message):
minutes, _ = divmod(rem, 60) minutes, _ = divmod(rem, 60)
load1 = psutil.getloadavg()[0] load1 = psutil.getloadavg()[0]
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))
cpu_icon = "🟢" cpu_icon = "🟢"
if load1 > 2.0: if load1 > high_warn:
cpu_icon = "🔴" cpu_icon = "🔴"
elif load1 > 1.0: elif load1 > load_warn:
cpu_icon = "🟡" cpu_icon = "🟡"
mem = psutil.virtual_memory() mem = psutil.virtual_memory()

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)) disk_warn = int(cfg.get("thresholds", {}).get("disk_warn", 80))
load_warn = float(cfg.get("thresholds", {}).get("load_warn", 2.0)) 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} 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: while True:
now = time.time() now = time.time()
@@ -42,15 +43,23 @@ async def monitor_resources(cfg, notify, bot, chat_id):
state["disk_high"] = False state["disk_high"] = False
load = psutil.getloadavg()[0] load = psutil.getloadavg()[0]
if load >= load_warn: if load >= high_warn:
if not state["load_high"] or now - last_sent["load"] >= cooldown: level = 2
await notify(bot, chat_id, f"🟡 Load high: {load:.2f}") elif load >= load_warn:
state["load_high"] = True level = 1
last_sent["load"] = now
else: 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}") 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) await asyncio.sleep(interval)