fix: active anomalies not disappear after resolve
This commit is contained in:
+4
-2
@@ -229,7 +229,8 @@ async def get_system_metrics(limit: int = 60) -> list[dict]:
|
||||
|
||||
@app.get("/api/active-anomalies", summary="Currently anomalous processes")
|
||||
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:
|
||||
db.row_factory = aiosqlite.Row
|
||||
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
|
||||
) latest ON m.id = latest.max_id
|
||||
WHERE m.is_anomaly = 1
|
||||
AND m.timestamp >= ?
|
||||
ORDER BY m.cpu_percent DESC
|
||||
LIMIT 20
|
||||
""") as cur:
|
||||
""", (cutoff,)) as cur:
|
||||
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 |
Reference in New Issue
Block a user