fix: active anomalies not disappear after resolve

This commit is contained in:
kilyabin
2026-05-29 17:52:30 +04:00
parent 1a2a0dfbb7
commit 85ebea7958
7 changed files with 4 additions and 2 deletions
+4 -2
View File
@@ -229,7 +229,8 @@ async def get_system_metrics(limit: int = 60) -> list[dict]:
@app.get("/api/active-anomalies", summary="Currently anomalous processes") @app.get("/api/active-anomalies", summary="Currently anomalous processes")
async def get_active_anomalies() -> list[dict]: async def get_active_anomalies() -> list[dict]:
"""Latest snapshot per PID — only rows where is_anomaly=1.""" """Latest snapshot per PID — only rows where is_anomaly=1 and seen within last 30 s."""
cutoff = (datetime.now(timezone.utc) - timedelta(seconds=30)).isoformat()
async with aiosqlite.connect(DB_PATH) as db: async with aiosqlite.connect(DB_PATH) as db:
db.row_factory = aiosqlite.Row db.row_factory = aiosqlite.Row
async with db.execute(""" async with db.execute("""
@@ -239,9 +240,10 @@ async def get_active_anomalies() -> list[dict]:
SELECT pid, MAX(id) AS max_id FROM metrics GROUP BY pid SELECT pid, MAX(id) AS max_id FROM metrics GROUP BY pid
) latest ON m.id = latest.max_id ) latest ON m.id = latest.max_id
WHERE m.is_anomaly = 1 WHERE m.is_anomaly = 1
AND m.timestamp >= ?
ORDER BY m.cpu_percent DESC ORDER BY m.cpu_percent DESC
LIMIT 20 LIMIT 20
""") as cur: """, (cutoff,)) as cur:
return [dict(r) for r in await cur.fetchall()] return [dict(r) for r in await cur.fetchall()]
Binary file not shown.

After

Width:  |  Height:  |  Size: 181 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB