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(account): per-user live refresh interval in Display

karloks2005aa7fd68da9cb
diff --git a/src/backend/main.py b/src/backend/main.py
index d496563..a1c0960 100644
--- a/src/backend/main.py
+++ b/src/backend/main.py
@@ -2795,8 +2795,10 @@ def unmute_incident(incident_id: PathId, session_id: Annotated[str | None, Cooki
_USERNAME = re.compile(r"[a-z0-9][a-z0-9._-]{1,31}")
_COLOR = re.compile(r"#[0-9a-fA-F]{6}")
_CLOCK = re.compile(r"([01]\d|2[0-3]):[0-5]\d")
-DISPLAY_CHOICES = {"time_format": ("24h", "12h"), "sizes": ("GB", "GiB"), "theme": ("dark", "light", "system"), "density": ("comfortable", "compact"), "open_on": ("overview", "statistics", "agent")}
-DISPLAY_DEFAULTS = {"time_format": "24h", "sizes": "GB", "theme": "dark", "density": "comfortable", "open_on": "overview", "timezone": ""}
+# live_refresh: how often the Overview asks for new data, in seconds (null: the default built into the frontend).
+DISPLAY_CHOICES = {"time_format": ("24h", "12h"), "sizes": ("GB", "GiB"), "theme": ("dark", "light", "system"), "density": ("comfortable", "compact"), "open_on": ("overview", "statistics", "agent"),
+ "live_refresh": (2, 3, 5, 10, 30, 60)}
+DISPLAY_DEFAULTS = {"time_format": "24h", "sizes": "GB", "theme": "dark", "density": "comfortable", "open_on": "overview", "timezone": "", "live_refresh": None}
class ProfileRequest(BaseModel):
@@ -2891,7 +2893,8 @@ def update_preferences(payload: PreferencesRequest, session_id: Annotated[str |
current = _preferences(user)
if payload.display is not None:
for key, choices in DISPLAY_CHOICES.items():
- if payload.display.get(key) in choices:
+ value = payload.display.get(key)
+ if value in choices and not isinstance(value, bool):
current["display"][key] = payload.display[key]
zone = payload.display.get("timezone")
if isinstance(zone, str) and len(zone) <= 64:
diff --git a/src/frontend/src/account/AccountPage.jsx b/src/frontend/src/account/AccountPage.jsx
index 37ab098..878bfa5 100644
--- a/src/frontend/src/account/AccountPage.jsx
+++ b/src/frontend/src/account/AccountPage.jsx
@@ -1,7 +1,7 @@
// Your account: who you are, how you sign in, where alerts reach you and how Infradeck looks for you.
import { useEffect, useRef, useState } from 'react'
import { useNavigate } from 'react-router-dom'
-import { apiRequest } from '../api.js'
+import { LIVE_REFRESH_SECONDS, apiRequest } from '../api.js'
import { MIN_PASSWORD_LENGTH } from '../auth/AuthPages.jsx'
import { Icon } from '../icons.jsx'
import { applyDisplay } from '../prefs.js'
@@ -374,6 +374,9 @@ function Display({ account, onPreferences }) {
<div className="card divide-y divide-line">
<Row title="Theme" detail="Dark is what Infradeck was designed in."><Choice label="Theme" value={display.theme} options={[['dark', 'Dark'], ['light', 'Light'], ['system', 'System']]} onChange={(value) => set('theme', value)} /></Row>
<Row title="Density" detail="Compact fits more rows on a screen."><Choice label="Density" value={display.density} options={[['comfortable', 'Comfortable'], ['compact', 'Compact']]} onChange={(value) => set('density', value)} /></Row>
+ <Row title="Live refresh" detail={`How often the Overview asks for new data. Slower uses less of this device's battery and data; the charts never get new points faster than a server checks in. Default ${LIVE_REFRESH_SECONDS} s.`}>
+ <Choice label="Live refresh" value={display.live_refresh ?? LIVE_REFRESH_SECONDS} options={[[2, '2 s'], [3, '3 s'], [5, '5 s'], [10, '10 s'], [30, '30 s'], [60, '1 min']]} onChange={(value) => set('live_refresh', value)} />
+ </Row>
<Row title="Open on" detail="The page you land on after signing in."><select className="select" aria-label="Open on" value={display.open_on} onChange={(event) => set('open_on', event.target.value)}><option value="overview">Overview</option><option value="statistics">Statistics</option><option value="agent">Agent</option></select></Row>
<Row title="Time zone" detail={`Used for your quiet hours. Charts and incident times follow this browser (${browserZone}).`}><select className="select max-w-[240px]" aria-label="Time zone" value={display.timezone} onChange={(event) => set('timezone', event.target.value)}><option value="">This browser ({browserZone})</option>{zones.map((zone) => <option key={zone} value={zone}>{zone}</option>)}</select></Row>
<Row title="Time format" detail="Saved with your account. Times are shown in 24 h everywhere for now."><Choice label="Time format" value={display.time_format} options={[['24h', '24 h'], ['12h', '12 h']]} onChange={(value) => set('time_format', value)} /></Row>
diff --git a/src/frontend/src/dashboard/DashboardPage.jsx b/src/frontend/src/dashboard/DashboardPage.jsx
index 6d606cb..7f52d4f 100644
--- a/src/frontend/src/dashboard/DashboardPage.jsx
+++ b/src/frontend/src/dashboard/DashboardPage.jsx
@@ -2,6 +2,7 @@
import { useEffect, useMemo, useRef, useState } from 'react'
import { useNavigate, useSearchParams } from 'react-router-dom'
import { LIVE_REFRESH_SECONDS, apiRequest } from '../api.js'
+import { liveRefreshSeconds } from '../prefs.js'
import { Icon } from '../icons.jsx'
import { refreshOverview, useOverview } from '../overviewStore.js'
import { AppShell } from '../shell.jsx'
@@ -36,7 +37,9 @@ const headline = (servers) => headlineParts(servers, ', ').join(' ')
export default function DashboardPage({ user, onLogout }) {
const navigate = useNavigate()
const [params, setParams] = useSearchParams()
- const { data: overview, error } = useOverview(Boolean(user), LIVE_REFRESH_SECONDS, onLogout)
+ // Account › Display › Live refresh; read when the page opens.
+ const [refresh] = useState(() => liveRefreshSeconds(LIVE_REFRESH_SECONDS))
+ const { data: overview, error } = useOverview(Boolean(user), refresh, onLogout)
// A phone shows the fleet and one server as separate screens; the desktop shows both, with one server picked.
const phone = usePhone()
const [minutes, setMinutes] = useState(rememberedRange)
@@ -65,7 +68,8 @@ export default function DashboardPage({ user, onLogout }) {
try { window.localStorage.setItem(RANGE_KEY, String(minutes)) } catch { /* private windows: keep it for this visit only */ }
}, [minutes])
- const pace = Math.max(5, Math.min(selected?.check_interval_seconds || 15, 30))
+ // The live chart follows the server's check-ins (new points come no faster), but never refreshes more often than chosen.
+ const pace = Math.max(refresh, 5, Math.min(selected?.check_interval_seconds || 15, 30))
const { data: fleetLines } = usePolled(servers.length ? `/monitoring/sparklines?minutes=${minutes}` : null, 15)
const { data: live } = usePolled(selectedId ? `/monitoring/servers/${selectedId}/live?minutes=${minutes}` : null, pace)
const showsContainers = selected?.containers?.length > 0 && (tab === 'overview' || tab === 'containers')
diff --git a/src/frontend/src/prefs.js b/src/frontend/src/prefs.js
index 944c2a7..72b0d90 100644
--- a/src/frontend/src/prefs.js
+++ b/src/frontend/src/prefs.js
@@ -15,6 +15,12 @@ export function applyDisplay(display) {
return choice
}
+// How often the Overview refreshes for this person, in seconds: their choice, or the default built into the frontend.
+export function liveRefreshSeconds(fallback) {
+ const chosen = Number(storedDisplay().live_refresh)
+ return [2, 3, 5, 10, 30, 60].includes(chosen) ? chosen : fallback
+}
+
// Where "/" should lead for this person: the page they chose to open on.
export function landingPath() {
return { statistics: '/statistics', agent: '/agent' }[storedDisplay().open_on] || '/'
diff --git a/src/frontend/src/shell.jsx b/src/frontend/src/shell.jsx
index 05cadb6..06b4d5c 100644
--- a/src/frontend/src/shell.jsx
+++ b/src/frontend/src/shell.jsx
@@ -3,13 +3,16 @@
// (Overview, Statistics, Agent, More), with Account, Admin and the fleet under More.
import { createContext, useContext, useEffect, useMemo, useRef, useState } from 'react'
import { Link, NavLink, useLocation, useNavigate } from 'react-router-dom'
-import { apiRequest } from './api.js'
+import { LIVE_REFRESH_SECONDS, apiRequest } from './api.js'
+import { liveRefreshSeconds } from './prefs.js'
import { isOnline } from './fleetLogic.js'
import { Icon } from './icons.jsx'
import { formatQuiet, listenerRows, serverState, serverStateLabel, sortServers } from './dashboard/logic.js'
import { useOverview } from './overviewStore.js'
const SIDEBAR_REFRESH_SECONDS = 15
+// "Stale" only once a few refreshes in a row were missed, however slow the chosen refresh is.
+const staleAfter = () => Math.max(30, liveRefreshSeconds(LIVE_REFRESH_SECONDS) * 2 + 5)
const primaryNav = [
{ label: 'Overview', to: '/', icon: 'overview', keys: 'O' },
@@ -176,7 +179,7 @@ function LiveStatus({ overview, loadedAt, error }) {
if (!overview) return <span className="flex items-center gap-2 text-xs text-muted"><span className="dot" />{error ? 'Not connected' : 'Connecting…'}</span>
if (!overview.servers.length) return <span className="flex items-center gap-2 text-xs text-muted"><span className="dot" />No collectors reporting</span>
const seconds = Math.max(0, Math.round((Date.now() - loadedAt) / 1000))
- const stale = Boolean(error) || seconds > 30
+ const stale = Boolean(error) || seconds > staleAfter()
return <span className="flex items-center gap-2 whitespace-nowrap text-xs text-soft" title={error || undefined}><span className={`dot ${stale ? 'dot-warn' : 'dot-ok'}`} />{stale ? 'Stale' : 'Live'} · checked {seconds}s ago</span>
}
@@ -279,7 +282,7 @@ function ShortLive() {
}, [])
if (!overview?.servers?.length) return null
const seconds = Math.max(0, Math.round((Date.now() - loadedAt) / 1000))
- const stale = Boolean(error) || seconds > 30
+ const stale = Boolean(error) || seconds > staleAfter()
return <span className="flex items-center gap-1.5 whitespace-nowrap text-xs text-soft" title={error || undefined}><span className={`dot ${stale ? 'dot-warn' : 'dot-ok'}`} style={{ width: 7, height: 7 }} />{stale ? 'stale' : `${seconds}s ago`}</span>
}
diff --git a/tests/accounts/test_new_pages.py b/tests/accounts/test_new_pages.py
index 6cc5c4a..0dba1f9 100644
--- a/tests/accounts/test_new_pages.py
+++ b/tests/accounts/test_new_pages.py
@@ -576,3 +576,12 @@ def test_chat_is_for_admins_unless_allowed_per_user(app, monkeypatch):
owner.put("/admin/settings", json={"agent_chat_access": "admins_only"})
assert ask().status_code == 403 # admins only wins over the per-user switch
assert owner.put("/admin/settings", json={"agent_chat_access": "everyone"}).status_code == 422
+
+
+def test_live_refresh_is_a_display_choice_from_a_fixed_list(app):
+ viewer = signed_in(app, 3)
+ assert viewer.get("/account").json()["preferences"]["display"]["live_refresh"] is None # the frontend's default
+
+ assert viewer.put("/account/preferences", json={"display": {"live_refresh": 10}}).json()["display"]["live_refresh"] == 10
+ for wrong in (7, 0, "10", True):
+ assert viewer.put("/account/preferences", json={"display": {"live_refresh": wrong}}).json()["display"]["live_refresh"] == 10 # ignored