From 87e07b220990499182977610ad88bbad567eb93d Mon Sep 17 00:00:00 2001 From: Bobban Rydh Date: Fri, 6 Nov 2026 23:21:57 +0100 Subject: [PATCH] Add a status strip to the server page: status, maintenance, alerts, updates, disk, load and uptime at a glance Co-Authored-By: Claude Sonnet 5.5 --- README.md | 2 + server/test/serverStrip.test.ts | 159 +++++++++++++++++++++++ web/src/components/ServerStatusStrip.tsx | 45 +++++++ web/src/pages/ServerDetail.tsx | 24 ++++ web/src/utils/serverStrip.ts | 139 ++++++++++++++++++++ 5 files changed, 369 insertions(+) create mode 100644 server/test/serverStrip.test.ts create mode 100644 web/src/components/ServerStatusStrip.tsx create mode 100644 web/src/utils/serverStrip.ts diff --git a/README.md b/README.md index 20f3d2a..68d058a 100644 --- a/README.md +++ b/README.md @@ -941,6 +941,8 @@ hours (maintenance), is handed to you or is still going is counted in the badge **A server's page in sections.** Overview (links, hardware, identity, runbooks — fold a card by clicking its header, and *Arrange cards* puts them in the order you like, for every server), Health, Network (what it is connected through, ports), History (trends, activity), Tasks (scheduled tasks, run a playbook) and Settings (Proxmox link, its own alert limits), switched by `?view=`, so a section can be linked to: an alert about a failing service opens the Health section, a new-port alert the Network section. +**The status strip.** Under a server's name, on every section of its page, a row of figures says how it is at a glance: **Status** (online, with when it last reported — or *offline*, with when it did, and a note when Proxmox says the guest is still running, so a stopped agent is not read as a dead machine; for a server with no agent report, what Proxmox says, or that nothing has reported), **Maintenance** (only while a window on this server is on, with when it ends and why), **Alerts** (how many are open about this server and how bad — what a maintenance window, a snooze or a closing has put aside is not counted, but said — and a link to the Alerts page), **Updates** (what is waiting, how many of them security fixes, whether a reboot is needed), **Disk** (the fullest, against its own limit: green, yellow within ten points of it, red at it; a mount with its own limit is judged by that, and an ignored mount is left out), **CPU · memory** and, for a guest Proxmox reads, **how long it has run**. A figure nothing is known for is left out or says so — it is never filled in. It uses what the page already has plus the alerts and the maintenance windows, read again whenever the page is (the *Refresh* button). Everyone signed in sees it. + **Away mode, and critical alerts through the night.** For a one-person homelab, "on call" is about *when you can be reached*. **Settings → Notifications → When → Away** is a one-off "I'm away until Sunday evening": notifications are held while it lasts (a banner on every page says so and counts them) and sent as **one digest** when it ends — at the time you gave, or when you press *I'm back* — so a week away is one message to read, not a buzzing phone. **Critical** alerts (a server down, a disk full, mains power lost) can still come through at once, which is the default; untick it for true silence. You can plan one ahead (start later) and add a note. **Quiet hours** got the same option, *Still send critical alerts*, off by default: a full disk at 03:00 is diff --git a/server/test/serverStrip.test.ts b/server/test/serverStrip.test.ts new file mode 100644 index 0000000..1e2a807 --- /dev/null +++ b/server/test/serverStrip.test.ts @@ -0,0 +1,159 @@ +/** + * The strip under a server's name: whether it reports, maintenance, what is open about it, what is waiting to be installed, its disk, how busy it is and how long it has run — worked out from what the page + * already has (and the alerts and maintenance windows), never made up where nothing is known. + * + * Run with: npm test --workspace server + */ +import { test, describe } from "node:test"; +import assert from "node:assert/strict"; + +const { serverStrip, worstDisk, uptimeText } = await import("../../web/src/utils/serverStrip.js"); + +type Input = Parameters[0]; +type Server = Input["server"]; +type Hardware = Input["hardware"]; +type Alert = NonNullable[number]; +type Window = NonNullable[number]; + +const NOW = Date.parse("2026-06-10T12:00:00Z"); +const MIN = 60_000; +const HOUR = 60 * MIN; +const iso = (ms: number) => new Date(ms).toISOString(); + +const defaults = { serverOfflineMinutes: 15, diskUsagePercent: 90 } as Input["defaults"]; +const server = (extra: Partial = {}): Server => ({ id: 7, name: "web-1", lastSeenAt: iso(NOW - 2 * MIN), pendingUpdates: null, thresholds: null, ...extra }) as Server; +const hardware = (extra: Partial = {}): Hardware => ({ source: "agent", ...extra }) as Hardware; +const alert = (extra: Partial = {}): Alert => ({ id: "a", kind: "disk", type: "server", severity: "warning", category: "disk", source: "Servers", message: "m", link: null, silenced: false, target: { type: "server", id: 7, name: "web-1" }, ...extra }) as Alert; +const win = (extra: Partial = {}): Window => ({ id: 1, targetType: "server", targetId: 7, targetName: "web-1", targetKind: "server", reason: null, startedAt: iso(NOW - HOUR), endsAt: iso(NOW + 45 * MIN), createdBy: null, source: null, ...extra }) as Window; + +const strip = (extra: Partial = {}) => serverStrip({ server: server(), hardware: hardware(), defaults, alerts: [], windows: [], now: NOW, ...extra }); +const tile = (tiles: ReturnType, id: string) => tiles.find((t) => t.id === id); + +describe("whether it reports", () => { + test("a recent report is Online, with when; a report older than the limit is Offline, with when it was", () => { + const on = tile(strip(), "status")!; + assert.deepEqual([on.value, on.tone, on.sub], ["Online", "ok", "reported 2 min ago"]); + const off = tile(strip({ server: server({ lastSeenAt: iso(NOW - 3 * HOUR) }) }), "status")!; + assert.deepEqual([off.value, off.tone, off.sub], ["Offline", "bad", "last report 3 h ago"]); + }); + + test("the server's own limit decides, not the default", () => { + const s = server({ lastSeenAt: iso(NOW - 20 * MIN), thresholds: { serverOfflineMinutes: 60 } }); + assert.equal(tile(strip({ server: s }), "status")!.value, "Online"); + assert.equal(tile(strip({ server: server({ lastSeenAt: iso(NOW - 20 * MIN) }) }), "status")!.value, "Offline", "the default is 15 minutes"); + }); + + test("an offline agent whose guest Proxmox says is running is said to be that, so it is not read as the machine being down", () => { + const t = tile(strip({ server: server({ lastSeenAt: iso(NOW - 2 * HOUR) }), hardware: hardware({ source: "proxmox", status: "running" }) }), "status")!; + assert.match(t.sub ?? "", /last report 2 h ago — Proxmox says it is running/); + }); + + test("no report at all: what Proxmox says if it says, else that nothing has reported — never Online", () => { + const viaProxmox = tile(strip({ server: server({ lastSeenAt: null }), hardware: hardware({ source: "proxmox", status: "stopped" }) }), "status")!; + assert.deepEqual([viaProxmox.value, viaProxmox.tone, viaProxmox.sub], ["Stopped", "warn", "from Proxmox — no agent report"]); + const running = tile(strip({ server: server({ lastSeenAt: null }), hardware: hardware({ source: "proxmox", status: "running" }) }), "status")!; + assert.deepEqual([running.value, running.tone], ["Running", "ok"]); + const none = tile(strip({ server: server({ lastSeenAt: null }) }), "status")!; + assert.deepEqual([none.value, none.tone], ["No report yet", "muted"]); + }); +}); + +describe("maintenance", () => { + test("a window on this server that is on now is a tile, saying when it ends and why; the nearest end if there are two", () => { + const t = tile(strip({ windows: [win({ endsAt: iso(NOW + 3 * HOUR) }), win({ id: 2, endsAt: iso(NOW + 45 * MIN), reason: "kernel update" })] }), "maintenance")!; + assert.deepEqual([t.value, t.tone, t.sub, t.to], ["On now", "info", "ends in 45 min — kernel update", "/maintenance"]); + }); + + test("another server's window, one that has ended, one that has not begun and a window on something else are not this server's", () => { + const windows = [win({ targetId: 8 }), win({ endsAt: iso(NOW - MIN) }), win({ startedAt: iso(NOW + HOUR), endsAt: iso(NOW + 2 * HOUR) }), win({ targetType: "integration" })]; + assert.equal(tile(strip({ windows }), "maintenance"), undefined); + assert.equal(tile(strip({ windows: null }), "maintenance"), undefined, "not loaded: nothing is said"); + }); +}); + +describe("what is open about it", () => { + test("only this server's alerts, by how bad: critical first in the tone, both counted", () => { + const alerts = [alert({ id: "1", severity: "critical" }), alert({ id: "2" }), alert({ id: "3" }), alert({ id: "x", target: { type: "server", id: 8, name: "other" } }), alert({ id: "y", target: { type: "integration", id: 7, name: "int" } }), alert({ id: "i", severity: "info" })]; + const t = tile(strip({ alerts }), "alerts")!; + assert.deepEqual([t.value, t.tone, t.sub, t.to], ["3", "bad", "1 critical · 2 warnings", "/alerts"]); + assert.equal(tile(strip({ alerts: [alert()] }), "alerts")!.tone, "warn"); + }); + + test("what a maintenance window, a snooze or somebody has put aside is not counted, but is said", () => { + const alerts = [alert({ id: "1", silenced: true }), alert({ id: "2", snoozed: { until: iso(NOW + HOUR), by: "x" } }), alert({ id: "3", closed: { by: "x", at: iso(NOW), note: null } }), alert({ id: "4" })]; + const t = tile(strip({ alerts }), "alerts")!; + assert.deepEqual([t.value, t.sub], ["1", "1 warning · 3 set aside"]); + const onlyAside = tile(strip({ alerts: [alerts[0]] }), "alerts")!; + assert.deepEqual([onlyAside.value, onlyAside.tone, onlyAside.sub], ["None", "ok", "1 set aside"]); + }); + + test("none is None and fine; alerts that could not be loaded say so, not None", () => { + const none = tile(strip({ alerts: [] }), "alerts")!; + assert.deepEqual([none.value, none.tone, none.sub], ["None", "ok", "nothing open"]); + const unknown = tile(strip({ alerts: null }), "alerts")!; + assert.deepEqual([unknown.value, unknown.tone, unknown.sub], ["—", "muted", "not loaded"]); + }); +}); + +describe("what is waiting to be installed", () => { + const pending = (extra: Partial>) => server({ pendingUpdates: { manager: "apt", count: 0, security: 0, rebootRequired: false, reportedAt: iso(NOW), ...extra } }); + test("not reported, up to date, some, security ones, and a reboot", () => { + assert.deepEqual(((t) => [t.value, t.tone])(tile(strip(), "updates")!), ["Not reported", "muted"]); + assert.deepEqual(((t) => [t.value, t.tone, t.sub])(tile(strip({ server: pending({}) }), "updates")!), ["Up to date", "ok", null]); + assert.deepEqual(((t) => [t.value, t.tone, t.sub])(tile(strip({ server: pending({ count: 12, security: 0 }) }), "updates")!), ["12 waiting", "info", "0 security"]); + assert.deepEqual(((t) => [t.value, t.tone, t.sub])(tile(strip({ server: pending({ count: 12, security: 3 }) }), "updates")!), ["12 waiting", "warn", "3 security"]); + assert.deepEqual(((t) => [t.value, t.tone, t.sub])(tile(strip({ server: pending({ count: 2, security: null, rebootRequired: true }) }), "updates")!), ["2 waiting", "warn", "reboot needed"]); + assert.equal(tile(strip({ server: pending({ count: 0, rebootRequired: true }) }), "updates")!.sub, "reboot needed", "a reboot is needed even with nothing waiting"); + }); +}); + +describe("the disk", () => { + const disks = (...d: [string, number, number][]): Hardware => hardware({ disks: d.map(([mount, used, size]) => ({ mount, usedBytes: used, sizeBytes: size })) }); + test("the fullest, against the limit: fine, to be watched within ten points, wrong at the limit", () => { + const t = (used: number) => tile(strip({ hardware: disks(["/", used, 100]) }), "disk")!; + assert.deepEqual([t(50).value, t(50).tone, t(50).sub], ["50%", "ok", "/"]); + assert.equal(t(80).tone, "warn"); + assert.equal(t(89).tone, "warn"); + assert.equal(t(90).tone, "bad"); + }); + + test("with several, the one closest to its own limit is shown, and the others are counted", () => { + const t = tile(strip({ hardware: disks(["/", 60, 100], ["/data", 85, 100], ["/boot", 10, 100]) }), "disk")!; + assert.deepEqual([t.value, t.sub], ["85%", "/data — fullest of 3"]); + }); + + test("a mount's own limit decides for it, and an ignored mount is left out (so is one with no size)", () => { + const s = server({ thresholds: { diskUsagePercent: 95, mounts: { "/data": { percent: 70 }, "/scratch": { ignore: true } } } }); + const t = tile(strip({ server: s, hardware: disks(["/", 80, 100], ["/data", 75, 100], ["/scratch", 99, 100], ["/zero", 0, 0]) }), "disk")!; + assert.deepEqual([t.value, t.tone, t.sub], ["75%", "bad", "/data — fullest of 2"], "75% is over /data's 70, though / at 80% is under the 95 of the server"); + assert.deepEqual(worstDisk(disks(["/zero", 0, 0]), { thresholds: null }, { diskUsagePercent: 90 }), null); + }); + + test("no disks reported, no tile", () => { + assert.equal(tile(strip(), "disk"), undefined); + assert.equal(tile(strip({ hardware: hardware({ disks: [] }) }), "disk"), undefined); + }); +}); + +describe("how busy it is, and how long it has run", () => { + test("processor and memory as percentages, to be watched at 90; either alone; neither, no tile", () => { + const both = tile(strip({ hardware: hardware({ cpuUsagePercent: 12.4, memTotalBytes: 1000, memUsedBytes: 610 }) }), "load")!; + assert.deepEqual([both.value, both.tone], ["12% · 61%", "muted"]); + assert.equal(tile(strip({ hardware: hardware({ cpuLoadPercent: 95, memTotalBytes: 1000, memUsedBytes: 10 }) }), "load")!.tone, "warn", "the load figure stands in for the usage one"); + assert.equal(tile(strip({ hardware: hardware({ memTotalBytes: 1000, memUsedBytes: 950 }) }), "load")!.value, "— · 95%"); + assert.equal(tile(strip(), "load"), undefined); + }); + + test("uptime, in days and hours or hours and minutes; none, no tile", () => { + assert.equal(uptimeText(12 * 86400 + 4 * 3600 + 59), "12d 4h"); + assert.equal(uptimeText(3 * 3600 + 20 * 60), "3h 20m"); + assert.equal(tile(strip({ hardware: hardware({ uptime: 90_000 }) }), "uptime")!.value, "1d 1h"); + assert.equal(tile(strip({ hardware: hardware({ uptime: null }) }), "uptime"), undefined); + assert.equal(tile(strip({ hardware: hardware({ uptime: 0 }) }), "uptime"), undefined); + }); + + test("the tiles come in a fixed order: status, maintenance, alerts, updates, disk, load, uptime", () => { + const tiles = strip({ windows: [win()], hardware: hardware({ disks: [{ mount: "/", usedBytes: 1, sizeBytes: 10 }], cpuUsagePercent: 5, memTotalBytes: 10, memUsedBytes: 1, uptime: 5000 }) }); + assert.deepEqual(tiles.map((t) => t.id), ["status", "maintenance", "alerts", "updates", "disk", "load", "uptime"]); + }); +}); diff --git a/web/src/components/ServerStatusStrip.tsx b/web/src/components/ServerStatusStrip.tsx new file mode 100644 index 0000000..6184db5 --- /dev/null +++ b/web/src/components/ServerStatusStrip.tsx @@ -0,0 +1,45 @@ +import { Link } from "react-router-dom"; +import type { AlertItem, HealthCheckSettings, MaintenanceWindow, ServerHardware, ServerRecord } from "../api/client"; +import { serverStrip, type StripTile, type StripTone } from "../utils/serverStrip"; + +const TEXT: Record = { ok: "text-green", warn: "text-yellow", bad: "text-red", info: "text-blue", muted: "" }; + +function Tile({ t }: { t: StripTile }) { + const body = ( +
+
+
{t.label}
+
+ {t.value} +
+ {t.sub &&
{t.sub}
} +
+
+ ); + return ( +
+ {t.to ? ( + + {body} + + ) : ( + body + )} +
+ ); +} + +/** + * How the server is, in a row under its name — on every section of its page: whether it reports (or is offline), whether it is in maintenance, what is open about it, what is waiting to be + * installed, how full its disk is, how busy it is and how long it has run. What it is built from is in utils/serverStrip.ts. + */ +export default function ServerStatusStrip({ server, hardware, defaults, alerts, windows }: { server: ServerRecord; hardware: ServerHardware; defaults: HealthCheckSettings; alerts: AlertItem[] | null; windows: MaintenanceWindow[] | null }) { + const tiles = serverStrip({ server, hardware, defaults, alerts, windows }); + return ( +
+ {tiles.map((t) => ( + + ))} +
+ ); +} diff --git a/web/src/pages/ServerDetail.tsx b/web/src/pages/ServerDetail.tsx index 12abe7e..eb8db35 100644 --- a/web/src/pages/ServerDetail.tsx +++ b/web/src/pages/ServerDetail.tsx @@ -9,6 +9,8 @@ import { type ProxmoxGuest, type ScheduleType, type ServerDetail as ServerDetailResponse, + type AlertItem, + type MaintenanceWindow, type ServerLink, type TaskRecord, } from "../api/client"; @@ -44,6 +46,7 @@ import ViewTabs from "../components/ViewTabs"; import ConnectedThrough from "../components/ConnectedThrough"; import HetznerServerCard from "../components/HetznerServerCard"; import ServerBlock, { ArrangeBar } from "../components/ServerBlock"; +import ServerStatusStrip from "../components/ServerStatusStrip"; const SCHEDULE_TYPE_OPTIONS: { value: ScheduleType; label: string }[] = Object.entries(SCHEDULE_TYPE_LABELS).map( ([value, label]) => ({ value: value as ScheduleType, label }), @@ -173,6 +176,25 @@ export default function ServerDetail({ user }: { user: CurrentUser }) { }); }, [serverId]); + // What the strip under the name says that is not in the server's own record: the alerts about it and the maintenance windows. Read again whenever the page is (the Refresh button). + const [stripAlerts, setStripAlerts] = useState(null); + const [stripWindows, setStripWindows] = useState(null); + useEffect(() => { + if (!detail) return; + let live = true; + api.alerts + .list() + .then((r) => live && setStripAlerts(r.alerts)) + .catch(() => live && setStripAlerts(null)); + api.maintenance + .list() + .then((r) => live && setStripWindows(r.windows)) + .catch(() => live && setStripWindows(null)); + return () => { + live = false; + }; + }, [detail]); + const loadTasks = useCallback(() => { api.tasks .list({ serverId, includeStale: true }) @@ -434,6 +456,8 @@ export default function ServerDetail({ user }: { user: CurrentUser }) { + + `${n} ${n === 1 ? one : many}`; + +/** "12d 4h", "3h 20m". */ +export function uptimeText(seconds: number): string { + const days = Math.floor(seconds / 86400); + const hours = Math.floor((seconds % 86400) / 3600); + if (days > 0) return `${days}d ${hours}h`; + return `${hours}h ${Math.floor((seconds % 3600) / 60)}m`; +} + +/** Pure: what is wrong with a disk's fullness, against its own limit (a mount may have its own, or be ignored): the worst of them, as "87% on /". */ +export function worstDisk(hardware: ServerHardware, server: Pick, defaults: Pick): { mount: string; percent: number; limit: number; of: number } | null { + const base = server.thresholds?.diskUsagePercent ?? defaults.diskUsagePercent; + let worst: { mount: string; percent: number; limit: number; margin: number } | null = null; + let counted = 0; + for (const d of hardware.disks ?? []) { + if (!(d.sizeBytes > 0)) continue; + const rule = server.thresholds?.mounts?.[d.mount]; + if (rule?.ignore) continue; + counted++; + const percent = Math.round((d.usedBytes / d.sizeBytes) * 100); + const limit = rule?.percent ?? base; + const margin = percent - limit; + if (worst === null || margin > worst.margin) worst = { mount: d.mount, percent, limit, margin }; + } + return worst && { mount: worst.mount, percent: worst.percent, limit: worst.limit, of: counted }; +} + +/** + * Pure: the figures that say at a glance how a server is — whether it reports, whether it is in maintenance, what is open about it, what is waiting to be installed, how full its disk is, how busy it is + * and how long it has run — each with a tone and, where there is one, the page to go to. A figure that cannot be told (nothing reported, nothing loaded) is left out or says so, never made up. + */ +export function serverStrip(i: StripInput): StripTile[] { + const now = i.now ?? Date.now(); + const { server, hardware, defaults } = i; + const tiles: StripTile[] = []; + + // Whether it reports. + const offlineMinutes = server.thresholds?.serverOfflineMinutes ?? defaults.serverOfflineMinutes; + const viaProxmox = hardware.source === "proxmox" && hardware.status ? hardware.status : null; + if (server.lastSeenAt) { + const age = (now - Date.parse(server.lastSeenAt)) / 60_000; + if (age > offlineMinutes) { + tiles.push({ id: "status", label: "Status", value: "Offline", sub: `last report ${formatAgo(server.lastSeenAt, now)}${viaProxmox === "running" ? " — Proxmox says it is running" : ""}`, tone: "bad" }); + } else { + tiles.push({ id: "status", label: "Status", value: "Online", sub: `reported ${formatAgo(server.lastSeenAt, now)}`, tone: "ok" }); + } + } else if (viaProxmox) { + tiles.push({ id: "status", label: "Status", value: viaProxmox.charAt(0).toUpperCase() + viaProxmox.slice(1), sub: "from Proxmox — no agent report", tone: viaProxmox === "running" ? "ok" : "warn" }); + } else { + tiles.push({ id: "status", label: "Status", value: "No report yet", sub: "its agent has not reported", tone: "muted" }); + } + + // A maintenance window that is on now. + const active = (i.windows ?? []) + .filter((w) => w.targetType === "server" && w.targetId === server.id && Date.parse(w.startedAt) <= now && Date.parse(w.endsAt) > now) + .sort((a, b) => Date.parse(a.endsAt) - Date.parse(b.endsAt))[0]; + if (active) tiles.push({ id: "maintenance", label: "Maintenance", value: "On now", sub: `ends in ${formatRemaining(active.endsAt, now)}${active.reason ? ` — ${active.reason}` : ""}`, tone: "info", to: "/maintenance" }); + + // What is open about it (what a window or a snooze has put aside is not counted, but said). + if (i.alerts === null) { + tiles.push({ id: "alerts", label: "Alerts", value: "—", sub: "not loaded", tone: "muted", to: "/alerts" }); + } else { + const mine = i.alerts.filter((a) => a.target?.type === "server" && a.target.id === server.id); + const open = mine.filter((a) => !a.silenced && !a.snoozed && !a.closed); + const critical = open.filter((a) => a.severity === "critical").length; + const warning = open.filter((a) => a.severity === "warning").length; + const aside = mine.length - open.length; + const parts = [critical > 0 ? plural(critical, "critical", "critical") : null, warning > 0 ? plural(warning, "warning") : null].filter(Boolean) as string[]; + tiles.push({ + id: "alerts", + label: "Alerts", + value: critical + warning === 0 ? "None" : String(critical + warning), + sub: [parts.join(" · "), aside > 0 ? `${aside} set aside` : ""].filter(Boolean).join(" · ") || "nothing open", + tone: critical > 0 ? "bad" : warning > 0 ? "warn" : "ok", + to: "/alerts", + }); + } + + // What is waiting to be installed. + const u = server.pendingUpdates; + if (u === null) { + tiles.push({ id: "updates", label: "Updates", value: "Not reported", sub: "the agent has not said", tone: "muted", to: "/updates" }); + } else { + const security = u.security !== null && u.security > 0; + tiles.push({ + id: "updates", + label: "Updates", + value: u.count === 0 ? "Up to date" : `${u.count} waiting`, + sub: [u.count > 0 && u.security !== null ? `${u.security} security` : "", u.rebootRequired ? "reboot needed" : ""].filter(Boolean).join(" · ") || null, + tone: security || u.rebootRequired ? "warn" : u.count > 0 ? "info" : "ok", + to: "/updates", + }); + } + + // The fullest disk, against its own limit. + const disk = worstDisk(hardware, server, defaults); + if (disk) { + tiles.push({ id: "disk", label: "Disk", value: `${disk.percent}%`, sub: `${disk.mount}${disk.of > 1 ? ` — fullest of ${disk.of}` : ""}`, tone: disk.percent >= disk.limit ? "bad" : disk.percent >= disk.limit - 10 ? "warn" : "ok" }); + } + + // How busy it is. + const cpu = hardware.cpuUsagePercent ?? hardware.cpuLoadPercent ?? null; + const mem = hardware.memTotalBytes ? Math.round(((hardware.memUsedBytes ?? 0) / hardware.memTotalBytes) * 100) : null; + if (cpu !== null || mem !== null) { + const busy = (cpu ?? 0) >= 90 || (mem ?? 0) >= 90; + tiles.push({ id: "load", label: "CPU · memory", value: [cpu !== null ? `${Math.round(cpu)}%` : "—", mem !== null ? `${mem}%` : "—"].join(" · "), sub: null, tone: busy ? "warn" : "muted" }); + } + + if (typeof hardware.uptime === "number" && hardware.uptime > 0) tiles.push({ id: "uptime", label: "Up for", value: uptimeText(hardware.uptime), sub: null, tone: "muted" }); + return tiles; +}