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.

fix(admin): bring back the alert thresholds the old Admin page could change

karloks200543d15cc7bcbf
diff --git a/ODSTUPANJA.md b/ODSTUPANJA.md
index 78465f9..ee5c020 100644
--- a/ODSTUPANJA.md
+++ b/ODSTUPANJA.md
@@ -123,7 +123,7 @@ su anotacije dizajna i namjerno nisu ugrađeni.
| „Removing a server keeps its history" | Brisanje servera briše i njegove metrike i incidente | Tako radi postojeće brisanje | – |
| Users: „Invite pending · Resend" | Poveznica se prikaže jednom; „Cancel" i nova pozivnica | Infradeck ne šalje e-mail | – |
| Uloge Owner / Admin / Viewer | Owner je prvi admin i ne može se mijenjati; ostalo Admin ili Viewer | Nema zasebne uloge vlasnika | #106 |
-| Alert rules: „Disk forecast full in < 30 days", „CPU > 90%" | Ne postoje; popis ima 16 stvarnih pravila | Ta pravila nisu napravljena | – |
+| Alert rules: „Disk forecast full in < 30 days", „CPU > 90%" | Ne postoje; popis ima 18 stvarnih pravila | Ta pravila nisu napravljena | – |
| Alert rules: stupac Servers s izborom servera | Uvijek „All" | Pravila vrijede za sve servere | – |
| Alert rules: „New rule" | Gumb je onemogućen | Vlastita pravila ne postoje | – |
| Alert rules: bilješka zašto je pravilo isključeno | Samo broj isključenih pravila | Razlog se ne upisuje | – |
diff --git a/src/backend/main.py b/src/backend/main.py
index b58b36b..557db07 100644
--- a/src/backend/main.py
+++ b/src/backend/main.py
@@ -3085,18 +3085,20 @@ def admin_cancel_invite(invite_id: PathId, session_id: Annotated[str | None, Coo
RULE_ROWS = [
{"kind": "container:restart_loop", "when": "Container restarts ≥ {restart_loop_count}", "window": "{restart_loop_window_minutes} min", "severity": "CRITICAL", "edit": ["restart_loop_count", "restart_loop_window_minutes"]},
{"kind": SERVER_OFFLINE_RULE, "when": f"Server misses {OFFLINE_AFTER_MISSED_CHECKS} check-ins in a row", "window": None, "severity": "CRITICAL", "edit": []},
- {"kind": "host:disk", "when": "Disk used > {disk_critical_pct}% (warning from {disk_warning_pct}%)", "window": "{sustained_checks} check-ins", "severity": "CRITICAL", "edit": ["disk_warning_pct", "disk_critical_pct"]},
- {"kind": "host:inodes", "when": "Inodes used > {inodes_critical_pct}% (warning from {inodes_warning_pct}%)", "window": "{sustained_checks} check-ins", "severity": "CRITICAL", "edit": ["inodes_warning_pct", "inodes_critical_pct"]},
- {"kind": "host:memory", "when": "Memory used > {memory_warning_pct}% (critical from {memory_critical_pct}%)", "window": "{sustained_checks} check-ins", "severity": "WARNING", "edit": ["memory_warning_pct", "memory_critical_pct"]},
- {"kind": "host:swap", "when": "Swap used > {swap_warning_pct}%", "window": "{sustained_checks} check-ins", "severity": "WARNING", "edit": ["swap_warning_pct"]},
- {"kind": "host:load", "when": "Load > {load_warning_per_core}× the cores (critical from {load_critical_per_core}×)", "window": "{sustained_checks} check-ins", "severity": "WARNING", "edit": ["load_warning_per_core", "load_critical_per_core"]},
- {"kind": "trend:memory", "when": "A container's memory climbs steadily", "window": None, "severity": "WARNING", "edit": []},
+ {"kind": "host:disk", "when": "Disk used > {disk_critical_pct}% (warning from {disk_warning_pct}%)", "window": "{sustained_checks} check-ins", "severity": "CRITICAL", "edit": ["disk_warning_pct", "disk_critical_pct", "sustained_checks"]},
+ {"kind": "host:inodes", "when": "Inodes used > {inodes_critical_pct}% (warning from {inodes_warning_pct}%)", "window": "{sustained_checks} check-ins", "severity": "CRITICAL", "edit": ["inodes_warning_pct", "inodes_critical_pct", "sustained_checks"]},
+ {"kind": "host:memory", "when": "Memory used > {memory_warning_pct}% (critical from {memory_critical_pct}%)", "window": "{sustained_checks} check-ins", "severity": "WARNING", "edit": ["memory_warning_pct", "memory_critical_pct", "sustained_checks"]},
+ {"kind": "host:swap", "when": "Swap used > {swap_warning_pct}%", "window": "{sustained_checks} check-ins", "severity": "WARNING", "edit": ["swap_warning_pct", "sustained_checks"]},
+ {"kind": "host:load", "when": "Load > {load_warning_per_core}× the cores (critical from {load_critical_per_core}×)", "window": "{sustained_checks} check-ins", "severity": "WARNING", "edit": ["load_warning_per_core", "load_critical_per_core", "sustained_checks"]},
+ {"kind": "trend:memory", "when": "A container's memory climbs ≥ {leak_min_mb_per_hour} MB/h and {leak_min_growth_pct}% steadily", "window": "{leak_window_hours} h", "severity": "WARNING", "edit": ["leak_min_mb_per_hour", "leak_min_growth_pct", "leak_window_hours"]},
{"kind": "container:unhealthy", "when": "A container's healthcheck fails", "window": None, "severity": "WARNING", "edit": []},
{"kind": "container:exit", "when": "A container exits with an error or is killed for memory", "window": "{event_window_minutes} min", "severity": "WARNING", "edit": ["event_window_minutes"]},
{"kind": "network:port", "when": "New port reachable from other machines", "window": None, "severity": "WARNING", "edit": []},
{"kind": "network:firewall", "when": "The firewall configuration is weakened", "window": None, "severity": "WARNING", "edit": []},
{"kind": "system:oom", "when": "The kernel kills a process to free memory", "window": "{event_window_minutes} min", "severity": "WARNING", "edit": []},
{"kind": "system:docker_unreachable", "when": "Docker stops answering", "window": None, "severity": "CRITICAL", "edit": []},
+ {"kind": "system:docker_slow", "when": "Docker takes > {docker_slow_ms} ms to list containers", "window": "{sustained_checks} check-ins", "severity": "WARNING", "edit": ["docker_slow_ms", "sustained_checks"]},
+ {"kind": "system:collect_slow", "when": "Collecting data takes > {collect_slow_pct}% of the check interval", "window": "{sustained_checks} check-ins", "severity": "WARNING", "edit": ["collect_slow_pct", "sustained_checks"]},
{"kind": "system:ntp", "when": "The clock is not synchronized", "window": None, "severity": "WARNING", "edit": []},
{"kind": "system:reboot_required", "when": "Reboot required for updates", "window": None, "severity": "INFO", "edit": []},
]
diff --git a/src/frontend/src/admin/AdminPage.jsx b/src/frontend/src/admin/AdminPage.jsx
index 8a4876e..6c283b0 100644
--- a/src/frontend/src/admin/AdminPage.jsx
+++ b/src/frontend/src/admin/AdminPage.jsx
@@ -16,6 +16,7 @@ const SEVERITY = { CRITICAL: ['Critical', 'chip-signal'], WARNING: ['Warning', '
const THRESHOLD_LABELS = {
restart_loop_count: 'Restarts', restart_loop_window_minutes: 'Within (min)', disk_warning_pct: 'Warning from %', disk_critical_pct: 'Critical from %', inodes_warning_pct: 'Warning from %', inodes_critical_pct: 'Critical from %',
memory_warning_pct: 'Warning from %', memory_critical_pct: 'Critical from %', swap_warning_pct: 'Warning from %', load_warning_per_core: 'Warning × cores', load_critical_per_core: 'Critical × cores', event_window_minutes: 'Stays open (min)',
+ sustained_checks: 'Check-ins in a row', docker_slow_ms: 'Slower than (ms)', collect_slow_pct: 'Over % of interval', leak_min_mb_per_hour: 'Rises MB/h', leak_min_growth_pct: 'Grows by %', leak_window_hours: 'Over (h)',
}
const put = (body) => apiRequest('/admin/settings', { method: 'PUT', body: JSON.stringify(body) })
const post = (path, body) => apiRequest(path, { method: 'POST', body: JSON.stringify(body || {}) })
diff --git a/tests/accounts/test_new_pages.py b/tests/accounts/test_new_pages.py
index 2f376a0..26a8401 100644
--- a/tests/accounts/test_new_pages.py
+++ b/tests/accounts/test_new_pages.py
@@ -306,6 +306,19 @@ def test_a_rule_can_be_switched_off_and_the_table_shows_how_often_each_fired(app
assert signed_in(app, 3).get("/admin/rules").status_code == 403
+def test_every_threshold_the_old_admin_page_could_change_can_still_be_changed(app):
+ rules = signed_in(app, 1).get("/admin/rules").json()["rules"]
+ editable = {key for rule in rules for key in rule["edit"]}
+ assert editable == set(main.DEFAULT_THRESHOLDS)
+ by_kind = {rule["kind"]: rule for rule in rules}
+ assert by_kind["system:docker_slow"]["when"] == "Docker takes > 2000 ms to list containers"
+ assert by_kind["trend:memory"]["window"] == "12 h"
+ # Rules that exist in rules.py but were missing from the table could not be switched off.
+ firing = {"system:docker_slow": ("WARNING", "t", "d"), "system:collect_slow": ("WARNING", "t", "d")}
+ signed_in(app, 1).put("/admin/settings", json={"disabled_rules": ["system:docker_slow", "system:collect_slow"]})
+ assert main._enabled_rules(app.db, firing) == {}
+
+
def test_a_server_is_renamed_and_keeps_the_name_and_the_install_describes_itself(app):
owner = signed_in(app, 1)
assert owner.patch("/monitoring/servers/1", json={"hostname": "media-box", "check_interval_seconds": 15}).json() == {"id": 1, "hostname": "media-box", "check_interval_seconds": 15}