Add disk usage snapshot reports
This commit is contained in:
@@ -3,6 +3,7 @@ import time
|
||||
import psutil
|
||||
from system_checks import list_disks, smart_health, disk_temperature
|
||||
from services.system import worst_disk_usage
|
||||
from services.disk_report import build_disk_report
|
||||
|
||||
|
||||
async def monitor_resources(cfg, notify, bot, chat_id):
|
||||
@@ -12,10 +13,12 @@ async def monitor_resources(cfg, notify, bot, chat_id):
|
||||
notify_recovery = bool(alerts_cfg.get("notify_recovery", True))
|
||||
|
||||
disk_warn = int(cfg.get("thresholds", {}).get("disk_warn", 80))
|
||||
snapshot_warn = int(cfg.get("disk_report", {}).get("threshold", disk_warn))
|
||||
snapshot_cooldown = int(cfg.get("disk_report", {}).get("cooldown_sec", 21600))
|
||||
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, "disk_report": 0.0}
|
||||
state = {"disk_high": False, "disk_na": False, "load_level": 0}
|
||||
|
||||
while True:
|
||||
@@ -42,6 +45,11 @@ async def monitor_resources(cfg, notify, bot, chat_id):
|
||||
await notify(bot, chat_id, f"🟢 Disk usage OK ({usage}% {mount})")
|
||||
state["disk_high"] = False
|
||||
|
||||
if usage >= snapshot_warn and now - last_sent["disk_report"] >= snapshot_cooldown:
|
||||
report = await build_disk_report(cfg, mount or "/", usage)
|
||||
await notify(bot, chat_id, f"📦 Disk snapshot\n\n{report}")
|
||||
last_sent["disk_report"] = now
|
||||
|
||||
load = psutil.getloadavg()[0]
|
||||
if load >= high_warn:
|
||||
level = 2
|
||||
|
||||
Reference in New Issue
Block a user