feat: memory alerts with top-memory process, top offender in alerts, scheduled status reports

This commit is contained in:
snowy-yang committed 2026-09-12 20:06:31 +08:00
1 parent e61142399a
commit f26f34cb87
8 files changed
+169 -37

No files matched your search

+19
View File
@@ -229,6 +229,25 @@ def get_top_processes(n: int = 10) -> list:
return procs[:n]
def get_top_memory(n: int = 10) -> list:
"""按内存占用排序的 TOP N 进程(无需 CPU 基准采样)。"""
procs = []
for p in psutil.process_iter(["pid", "name"]):
try:
if p.info["pid"] in (0, 4):
continue
procs.append({
"pid": p.info["pid"],
"name": (p.info["name"] or "?")[:24],
"cpu": 0.0,
"mem_mb": round(p.memory_info().rss / 1024**2, 1),
})
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
continue
procs.sort(key=lambda x: x["mem_mb"], reverse=True)
return procs[:n]
def get_uptime() -> float:
try:
with open("/proc/uptime") as f: