Skip to content

Self-hosted monitoring for homelabs: host and container metrics and uptime checks from all your machines in one dashboard, with an optional AI agent that diagnoses incidents and suggests fixes.

feat(dashboard): collapse repeated kernel errors into one row with a count

karloks2005931413e9b56a
diff --git a/TESTS.md b/TESTS.md
index 02efaaa..2b2de9f 100644
--- a/TESTS.md
+++ b/TESTS.md
@@ -4,7 +4,7 @@ Vexion ships with an automated test suite. This page explains how to run it, wha
covers (and what it doesn't), and what every single test is for, so you can decide
whether a failure matters before you upgrade or change your setup.
-- **297 test cases** from 174 test functions (some functions run once per input).
+- **302 test cases** from 179 test functions (some functions run once per input).
- **About 15 seconds** to run. No Docker, PostgreSQL, Redis, network or root access needed.
- **Safe to run next to a live install.** The tests use a throwaway in-memory database
and fakes; they never touch your running containers or your data. (Two collector
@@ -35,7 +35,7 @@ pytest
A healthy run ends with a line like:
```text
-297 passed, 3 warnings in 14.1s
+302 passed, 3 warnings in 14.1s
```
The warnings are harmless notices from the libraries (FastAPI deprecating the
@@ -132,7 +132,7 @@ docker compose logs --tail 20 collector # "Sent host metrics and N contai
| [`test_health_checks.py`](#test_health_checkspy) | 4 | The assistant's fixed health checks and the critical-only webhook. |
| [`test_pending_collectors.py`](#test_pending_collectorspy) | 28 | Adding servers: approval, join tokens, strict mode, re-pairing safety. |
| [`test_rules.py`](#test_rulespy) | 20 | Alert thresholds: sustained breaches, per-mount disks, settings validation. |
-| [`test_system_checks.py`](#test_system_checkspy) | 12 | Reboot, OOM, kernel-fault, clock and pending-reboot detection. |
+| [`test_system_checks.py`](#test_system_checkspy) | 17 | Reboot, OOM, kernel-fault, clock and pending-reboot detection, and the System row's event list. |
| [`test_system_helper.py`](#test_system_helperpy) | 35 | The optional system helper: kernel-log parsing, `wtmp`, crash detection, hostile input. |
## Every test, explained
@@ -382,6 +382,11 @@ kernel exposes (no helper needed).
| `test_reboot_required_raises_info_alert` | A pending-reboot flag raises an informational incident and clears when gone. |
| `test_collector_reads_kernel_state_from_proc` | The collector reads boot ID, OOM counter, kernel flags and the reboot-required file from the right places. |
| `test_collector_reports_unknown_when_files_are_missing` | Missing files give *unknown*, never a false "OK". |
+| `test_repeated_kernel_errors_collapse_into_one_row_with_a_count` | The same kernel message seen on several boots is shown once with a count (the row's time is the latest occurrence; the first is kept for the tooltip), while different messages stay separate. |
+| `test_reboots_and_oom_kills_are_never_collapsed` | Reboots and OOM kills stay one row per occurrence, so the timeline is never merged. |
+| `test_noisy_kernel_errors_cannot_crowd_out_real_events` | Even with dozens of different kernel messages, an older OOM kill is still listed and kernel messages are capped at 10 rows. |
+| `test_events_are_listed_newest_first_across_kinds` | Reboots, OOM kills and kernel messages are interleaved newest first. |
+| `test_events_older_than_seven_days_are_not_shown` | Events older than 7 days are left out of the System row. |
### test_system_helper.py
diff --git a/src/backend/main.py b/src/backend/main.py
index d78656e..a969647 100644
--- a/src/backend/main.py
+++ b/src/backend/main.py
@@ -538,6 +538,34 @@ OVERVIEW_ALERT_LIMIT = 50
SYSTEM_EVENTS_SHOWN = 10
+def recent_system_events(db, since: datetime) -> dict[int, list[dict]]:
+ """Each server's recent events, newest first, for the dashboard's System row.
+
+ Kernel errors repeat on every boot, so identical messages are collapsed into one row with a count
+ (and the first and last time seen) and capped separately; otherwise they would push reboots and
+ OOM kills out of the list. Every other kind stays one row per occurrence.
+ """
+ result: dict[int, list[dict]] = {}
+ for event in db.query(SystemEvent).filter(SystemEvent.time >= since, SystemEvent.kind != "kernel_error").order_by(SystemEvent.time.desc()):
+ rows = result.setdefault(event.server_id, [])
+ if len(rows) < SYSTEM_EVENTS_SHOWN:
+ rows.append({"time": event.time.isoformat(), "first_time": event.time.isoformat(), "kind": event.kind, "detail": event.detail, "count": 1})
+ shown: dict[int, int] = {}
+ grouped = (
+ db.query(SystemEvent.server_id, SystemEvent.detail, func.count(), func.min(SystemEvent.time), func.max(SystemEvent.time))
+ .filter(SystemEvent.time >= since, SystemEvent.kind == "kernel_error")
+ .group_by(SystemEvent.server_id, SystemEvent.detail)
+ .order_by(func.max(SystemEvent.time).desc())
+ )
+ for server_id, detail, count, first, last in grouped:
+ if shown.get(server_id, 0) < SYSTEM_EVENTS_SHOWN:
+ shown[server_id] = shown.get(server_id, 0) + 1
+ result.setdefault(server_id, []).append({"time": last.isoformat(), "first_time": first.isoformat(), "kind": "kernel_error", "detail": detail, "count": count})
+ for rows in result.values():
+ rows.sort(key=lambda row: row["time"], reverse=True)
+ return result
+
+
@app.get("/monitoring/overview")
def monitoring_overview(session_id: Annotated[str | None, Cookie(alias=SESSION_COOKIE_NAME)] = None, db=Depends(get_db)):
# Servers belong to the install: everyone signed in can view them, only admins manage them.
@@ -546,10 +574,7 @@ def monitoring_overview(session_id: Annotated[str | None, Cookie(alias=SESSION_C
servers = db.query(Server).order_by(Server.is_dashboard_host.desc(), Server.created_at.desc()).all()
alert_counts = dict(db.query(IncidentAlert.server_id, func.count()).filter(IncidentAlert.status == "active").group_by(IncidentAlert.server_id).all())
since = datetime.now(timezone.utc) - timedelta(days=7)
- events: dict[int, list[SystemEvent]] = {}
- for event in db.query(SystemEvent).filter(SystemEvent.time >= since).order_by(SystemEvent.time.desc()):
- if len(events.setdefault(event.server_id, [])) < SYSTEM_EVENTS_SHOWN:
- events[event.server_id].append(event)
+ events = recent_system_events(db, since)
result = []
for server in servers:
metric = db.query(HostMetric).filter(HostMetric.server_id == server.id).order_by(HostMetric.time.desc()).first()
@@ -562,7 +587,7 @@ def monitoring_overview(session_id: Annotated[str | None, Cookie(alias=SESSION_C
"active_alert_count": alert_counts.get(server.id, 0),
"last_seen_at": server.last_seen_at.isoformat() if server.last_seen_at else None,
"host": ({key: getattr(metric, key) for key in ("time", "cpu_utilization_pct", "load_1m", "load_5m", "load_15m", "ram_used_gb", "ram_available_gb", "ram_pct", "swap_pct", "disk_usage_pct", "disk_inodes_pct", "net_bytes_sent_mb", "net_bytes_recv_mb", "system_uptime_seconds", "oom_kill_total", "kernel_tainted", "ntp_synced", "reboot_required", "last_shutdown")} if metric else None),
- "system_events": [{"time": e.time.isoformat(), "kind": e.kind, "detail": e.detail} for e in events.get(server.id, [])],
+ "system_events": events.get(server.id, []),
"mounts": [{key: getattr(m, key) for key in ("mount", "fs_type", "total_gb", "used_gb", "used_pct", "inodes_pct")} for m in mounts],
"containers": [{"container_id": c.container_id, "name": c.name, "image": c.image, "status": c.status, "restart_count": c.restart_count, "cpu_pct": c.cpu_pct, "memory_used_mb": c.memory_used_mb, "memory_pct": c.memory_pct, "healthcheck_status": c.healthcheck_status, "time": c.time.isoformat()} for c in latest.values()],
})
diff --git a/src/frontend/src/App.jsx b/src/frontend/src/App.jsx
index f7c1bd1..d6ebdbe 100644
--- a/src/frontend/src/App.jsx
+++ b/src/frontend/src/App.jsx
@@ -704,11 +704,12 @@ function SystemSection({ server, open, onToggle }) {
<div className="mb-2 text-xs uppercase tracking-[0.2em] text-[#7f8589]">Recent events · 7 days</div>
{events.length ? <ul className="space-y-1.5 text-sm">{events.map((event, index) => (
<li key={`${event.time}-${event.kind}-${index}`} className="flex flex-wrap items-baseline gap-x-3 gap-y-0.5">
- <span className="w-24 shrink-0 text-xs text-[#7f8589]" title={new Date(event.time).toLocaleString()}>{formatAgo(event.time)}</span>
+ <span className="w-24 shrink-0 text-xs text-[#7f8589]" title={event.count > 1 ? `Last seen ${new Date(event.time).toLocaleString()}` : new Date(event.time).toLocaleString()}>{formatAgo(event.time)}</span>
<span className={`w-24 shrink-0 text-xs font-medium ${SYSTEM_EVENT_CLASSES[event.kind] || 'text-[#cfcfcf]'}`}>{SYSTEM_EVENT_LABELS[event.kind] || event.kind}</span>
- <span className="min-w-0 flex-1 basis-60 break-words text-[#bcbcbc]">{event.detail}</span>
+ <span className="min-w-0 flex-1 basis-60 break-words text-[#bcbcbc]">{event.detail}{event.count > 1 && <span className="ml-2 whitespace-nowrap rounded-full bg-white/10 px-2 py-0.5 text-[10px] font-medium text-[#cfcfcf]" title={`Seen ${event.count} times · first ${formatAgo(event.first_time)}, last ${formatAgo(event.time)}`}>×{event.count}</span>}</span>
</li>
))}</ul> : <p className="text-sm text-[#9aa0a6]">No reboots, OOM kills or kernel faults in the last 7 days.</p>}
+ {events.some((event) => event.count > 1) && <p className="mt-2 text-xs text-[#7f8589]">Repeated kernel messages are shown once with a count; the time is when each was last seen.</p>}
{host.last_shutdown == null && <p className="mt-3 text-xs text-[#7f8589]">“Unknown” means the collector couldn't read that value on this host, not that anything is wrong. Last shutdown, OOM process names and kernel errors need the optional system helper (see SECURITY.md).</p>}
</div>
)}
diff --git a/tests/test_system_checks.py b/tests/test_system_checks.py
index 2bcee91..325d8a9 100644
--- a/tests/test_system_checks.py
+++ b/tests/test_system_checks.py
@@ -1,4 +1,5 @@
import os
+from datetime import datetime, timedelta, timezone
os.environ.setdefault("DATABASE_URL", "sqlite://")
os.environ.setdefault("REDIS_URL", "redis://localhost:6379/0")
@@ -148,3 +149,66 @@ def test_collector_reports_unknown_when_files_are_missing(tmp_path, monkeypatch)
state = collector.collect_system()
assert (state["boot_id"], state["kernel_tainted"], state["oom_kill_total"], state["reboot_required"]) == (None, None, None, None)
+
+
+# --- the System row's event list ---------------------------------------------------------------
+
+def _event(db, kind, detail, minutes_ago):
+ db.add(SystemEvent(server_id=5, time=datetime.now(timezone.utc) - timedelta(minutes=minutes_ago), kind=kind, detail=detail))
+ db.commit()
+
+
+def _shown(db, monkeypatch):
+ monkeypatch.setattr(main, "_current_user", lambda session_id, db: {"id": 1})
+ return main.monitoring_overview(session_id="s", db=db)["servers"][0]["system_events"]
+
+
+def test_repeated_kernel_errors_collapse_into_one_row_with_a_count(db, monkeypatch):
+ for minutes_ago in (3000, 2000, 100):
+ _event(db, "kernel_error", "ACPI BIOS Error (bug): Could not resolve symbol", minutes_ago)
+ _event(db, "kernel_error", "i915: Unclaimed access detected", 50)
+
+ rows = {row["detail"]: row for row in _shown(db, monkeypatch)}
+
+ assert len(rows) == 2
+ acpi = rows["ACPI BIOS Error (bug): Could not resolve symbol"]
+ assert acpi["count"] == 3
+ # The row's time is the latest occurrence; the first one is kept for the tooltip.
+ assert datetime.fromisoformat(acpi["time"]) > datetime.fromisoformat(acpi["first_time"])
+ assert rows["i915: Unclaimed access detected"]["count"] == 1
+
+
+def test_reboots_and_oom_kills_are_never_collapsed(db, monkeypatch):
+ for minutes_ago in (500, 100):
+ _event(db, "reboot", "The host rebooted after a clean shutdown", minutes_ago)
+ _event(db, "oom_kill", "The kernel OOM killer stopped java (pid 1)", minutes_ago + 1)
+
+ rows = _shown(db, monkeypatch)
+
+ assert sorted((row["kind"], row["count"]) for row in rows) == [("oom_kill", 1), ("oom_kill", 1), ("reboot", 1), ("reboot", 1)]
+
+
+def test_noisy_kernel_errors_cannot_crowd_out_real_events(db, monkeypatch):
+ _event(db, "oom_kill", "The kernel OOM killer stopped java (pid 1)", 60 * 24 * 6)
+ for number in range(40):
+ _event(db, "kernel_error", f"driver message {number}", number + 1)
+
+ rows = _shown(db, monkeypatch)
+
+ assert [row["kind"] for row in rows].count("oom_kill") == 1
+ assert [row["kind"] for row in rows].count("kernel_error") == main.SYSTEM_EVENTS_SHOWN
+
+
+def test_events_are_listed_newest_first_across_kinds(db, monkeypatch):
+ _event(db, "reboot", "The host rebooted", 300)
+ _event(db, "kernel_error", "late message", 10)
+ _event(db, "oom_kill", "The kernel OOM killer stopped x (pid 2)", 100)
+
+ assert [row["kind"] for row in _shown(db, monkeypatch)] == ["kernel_error", "oom_kill", "reboot"]
+
+
+def test_events_older_than_seven_days_are_not_shown(db, monkeypatch):
+ _event(db, "reboot", "The host rebooted", 60 * 24 * 8)
+ _event(db, "kernel_error", "old message", 60 * 24 * 8)
+
+ assert _shown(db, monkeypatch) == []