diff --git a/README.md b/README.md index 46f8823..10dd3de 100644 --- a/README.md +++ b/README.md @@ -915,7 +915,7 @@ exists; it can be hidden, and brought back from the search box. **Proxmox snapshots.** Click a guest on Infrastructure → Proxmox and its drawer has a **Snapshots** section: what there is (oldest first, a branch indented, *with memory* marked), **Take a snapshot** for operators (a name or one from the time, a description, and for a running VM whether to keep its memory), and **Roll back…** and **Delete…** for administrators, each behind a confirmation that says what is lost. Proxmox does each as a task, followed for up to 20 seconds; each is in the audit log and the change log. The API token needs VM.Snapshot and VM.Snapshot.Rollback (the PVEVMAdmin role has them). The guest actions (start, shut down, restart, stop) were there already. -**Small trends in lists.** The rows of three lists carry a small line for which way things are going: each **server's card** (Infrastructure → Servers) has its load and memory over the last 24 hours (red or orange when it ends high), each **endpoint check** has how long it took to answer over the last day, with a red tick under each stretch in which a check failed, and each **integration** that keeps a history (Integrations, as cards or table, with a *Last week* column) has the figure it is known for over the last week — DNS queries for AdGuard, the queue for Sonarr, photos for Immich, the monthly cost for Hetzner. A gap in the data is a gap in the line, the newest reading is a dot, and each line is a picture with a sentence for a screen reader (*CPU load, last 24 hours: 12% now, between 3% and 40%*). They are drawn from the history the app already keeps (nothing new is stored), come from one request for the whole list, refresh every five minutes and are simply left out where there is no history. A line fitted to its own data makes a small change look steep — the sentence and the numbers beside it say how big it really is. The full charts are one click away on each page. +**Small trends in lists.** The rows of three lists carry a small line for which way things are going: each **server's card** (Infrastructure → Servers) has its load and memory over the last 24 hours and its **fullest disk over the last week** (a disk moves too slowly to show in a day; the line says which mount it is, and turns orange from 80% and red from 90%), and the admin table behind *Manage servers* has the same three lines side by side in a *Load and disk* column (load and memory turn orange from 75% and red from 90%), each **endpoint check** has how long it took to answer over the last day, with a red tick under each stretch in which a check failed, and each **integration** that keeps a history (Integrations, as cards or table, with a *Last week* column) has the figure it is known for over the last week — DNS queries for AdGuard, the queue for Sonarr, photos for Immich, the monthly cost for Hetzner. A gap in the data is a gap in the line, the newest reading is a dot, and each line is a picture with a sentence for a screen reader (*CPU load, last 24 hours: 12% now, between 3% and 40%*). They are drawn from the history the app already keeps (nothing new is stored), come from one request for the whole list, refresh every five minutes and are simply left out where there is no history. A line fitted to its own data makes a small change look steep — the sentence and the numbers beside it say how big it really is. The full charts are one click away on each page. **On a phone.** Below desktop width the top bar (logo and menu button) stays at the top of the screen so the menu is always within reach, with a menu button of at least 44 px; an open menu scrolls by itself (it no longer pushes the page down), its rows are finger-sized and the favourite stars are always visible; text is a little larger on a small screen, toasts run across the width and drawers fill it. The page asks for the whole screen (`viewport-fit=cover`) and keeps clear of the notch, the rounded corners and the home bar, which matters when it is installed to the home screen (the status bar then sits over the app). Tables turn into stacked cards, form fields are 16 px so a phone does not zoom in on them, and what is pressed does not wait for a second tap. Checked at 375 px: no page scrolls sideways. diff --git a/server/src/services/sparklines.ts b/server/src/services/sparklines.ts index d9cc304..91beb53 100644 Binary files a/server/src/services/sparklines.ts and b/server/src/services/sparklines.ts differ diff --git a/server/test/sparklines.test.ts b/server/test/sparklines.test.ts index bee6693..75a7c19 100644 --- a/server/test/sparklines.test.ts +++ b/server/test/sparklines.test.ts @@ -67,7 +67,12 @@ describe("servers", () => { rows.push({ serverId: a, metric: "cpu", value: 100 - h * 4, recordedAt: hoursAgo(h).toISOString() }); rows.push({ serverId: a, metric: "mem", value: 50, recordedAt: hoursAgo(h).toISOString() }); } - // b: a disk figure only (not one of the lines), and a reading from two days ago (out of the stretch) + // a: two disks over the week — "/" climbing from 50 to 62, "/data" steady at 85 (the fuller one) + for (const d of [6, 5, 4, 3, 2, 1, 0.2]) { + rows.push({ serverId: a, metric: "disk:/", value: 50 + (6 - d) * 2, recordedAt: hoursAgo(d * 24).toISOString() }); + rows.push({ serverId: a, metric: "disk:/data", value: 85, recordedAt: hoursAgo(d * 24).toISOString() }); + } + // b: a disk figure only (no load or memory), and a reading from two days ago (out of the stretch) rows.push({ serverId: b, metric: "disk:/", value: 80, recordedAt: hoursAgo(1).toISOString() }); rows.push({ serverId: b, metric: "cpu", value: 99, recordedAt: hoursAgo(48).toISOString() }); await db.insert(serverMetrics).values(rows); @@ -75,7 +80,9 @@ describe("servers", () => { test("load and memory over the last day, a slice an hour; a gap is null; others are left out", async () => { const out = await S.serverSparklines(NOW); - assert.deepEqual(Object.keys(out).map(Number), [a], "b has nothing in the last day that is drawn"); + assert.deepEqual(Object.keys(out).map(Number).sort(), [a, b].sort(), "b has only a disk, a has everything"); + assert.equal(out[b].cpu, undefined, "b's load was two days ago: not in the last day"); + assert.equal(out[b].mem, undefined); const cpu = out[a].cpu!; assert.equal(cpu.values.length, S.SLICES); assert.equal(cpu.values[0], 6, "23.5 hours ago is the first slice: 100 − 94"); @@ -87,6 +94,23 @@ describe("servers", () => { assert.ok(out[a].mem!.values.every((v) => v === null || v === 50)); }); + test("the fullest disk stands for the server, over a week, with its mount", async () => { + const out = await S.serverSparklines(NOW); + const disk = out[a].disk!; + assert.deepEqual([disk.mount, disk.days, disk.latest], ["/data", 7, 85], "/data (85) is fuller than / (62)"); + assert.equal(disk.values.length, S.SLICES); + assert.ok(disk.values.filter((v) => v !== null).length >= 6); + assert.deepEqual([out[b].disk!.mount, out[b].disk!.latest], ["/", 80]); + }); + + test("the fullest is the one that is fullest now; a tie goes to the shorter mount; none is none", () => { + assert.equal(S.fullestDisk([{ mount: "/", latest: 62 }, { mount: "/data", latest: 85 }])!.mount, "/data"); + assert.equal(S.fullestDisk([{ mount: "/data", latest: 70 }, { mount: "/", latest: 70 }])!.mount, "/"); + assert.equal(S.fullestDisk([{ mount: "/a", latest: null }, { mount: "/b", latest: 10 }])!.mount, "/b"); + assert.equal(S.fullestDisk([]), null); + assert.equal(S.fullestDisk([{ mount: "/", latest: null }]), null); + }); + test("readings in the same slice are averaged", async () => { await db.insert(serverMetrics).values([ { serverId: a, metric: "cpu", value: 10, recordedAt: hoursAgo(10.9).toISOString() }, diff --git a/web/src/api/client.ts b/web/src/api/client.ts index daceafe..300cd4b 100644 --- a/web/src/api/client.ts +++ b/web/src/api/client.ts @@ -4355,8 +4355,8 @@ export const api = { }, servers: { list: () => request<{ servers: ServerRecord[]; agentLatest: AgentLatest; agentAutoUpdate: boolean }>("/api/servers"), - /** The last day's load and memory of each server that reports them, for the lines in the list. */ - sparklines: () => request<{ hours: number; servers: Record }>("/api/servers/sparklines"), + /** The last day's load and memory of each server that reports them, and its fullest disk over the last week, for the lines in the list. */ + sparklines: () => request<{ hours: number; servers: Record }>("/api/servers/sparklines"), setAgentAutoUpdate: (autoUpdate: boolean) => request<{ autoUpdate: boolean }>("/api/servers/agent-update", { method: "PUT", body: JSON.stringify({ autoUpdate }) }), create: (data: { name: string; hostname?: string; description?: string; osType?: "linux" | "windows" }) => request<{ server: ServerRecord; token: string }>("/api/servers", { diff --git a/web/src/components/ServerSparks.tsx b/web/src/components/ServerSparks.tsx new file mode 100644 index 0000000..8d58cd7 --- /dev/null +++ b/web/src/components/ServerSparks.tsx @@ -0,0 +1,59 @@ +import type { SparkSeries } from "../api/client"; +import { t } from "../i18n"; +import { sparkWords } from "../utils/sparkline"; +import Sparkline from "./Sparkline"; + +export interface ServerLines { + cpu?: SparkSeries; + mem?: SparkSeries; + /** The fullest disk, over a week. */ + disk?: SparkSeries & { mount: string; days: number }; +} + +/** Orange from three quarters, red from nine tenths: how close a load, a memory or a disk is to the end of its room. */ +const toneOf = (latest: number | null, at: [number, number]): "primary" | "orange" | "red" => (latest !== null && latest >= at[1] ? "red" : latest !== null && latest >= at[0] ? "orange" : "primary"); + +/** + * A server's small lines: load and memory over the last day, and its fullest disk over the last week (a disk moves too slowly to show in a day). On a card each is a row of its own, in a list's + * table (`compact`) they sit side by side under short names. Nothing is drawn for a figure the server does not report. + */ +export default function ServerSparks({ lines, compact = false }: { lines: ServerLines | undefined; compact?: boolean }) { + if (!lines || (!lines.cpu && !lines.mem && !lines.disk)) return null; + const rows: { key: string; name: string; short: string; line: SparkSeries; period: string; tone: "primary" | "orange" | "red" }[] = []; + if (lines.cpu) rows.push({ key: "cpu", name: t("CPU load"), short: t("CPU"), line: lines.cpu, period: t("last 24 hours"), tone: toneOf(lines.cpu.latest, [75, 90]) }); + if (lines.mem) rows.push({ key: "mem", name: t("Memory"), short: t("Mem"), line: lines.mem, period: t("last 24 hours"), tone: toneOf(lines.mem.latest, [75, 90]) }); + if (lines.disk) rows.push({ key: "disk", name: t("Disk {mount}", { mount: lines.disk.mount }), short: t("Disk"), line: lines.disk, period: t("last week"), tone: toneOf(lines.disk.latest, [80, 90]) }); + const words = (r: (typeof rows)[number]) => sparkWords(r.name, r.period, r.line.latest, r.line.low, r.line.high, (v) => `${Math.round(v)}%`); + const value = (r: (typeof rows)[number]) => (r.line.latest === null ? "—" : `${Math.round(r.line.latest)}%`); + + if (compact) { + return ( +
+ {rows.map((r) => ( + + + {r.short} {value(r)} + + + + ))} +
+ ); + } + return ( +
+ {rows.map((r) => ( +
+
+ + {r.name} + {r.key === "disk" && · {t("a week")}} + + {value(r)} +
+ +
+ ))} +
+ ); +} diff --git a/web/src/i18n/sv.ts b/web/src/i18n/sv.ts index eb5340e..391ba0c 100644 --- a/web/src/i18n/sv.ts +++ b/web/src/i18n/sv.ts @@ -67,6 +67,7 @@ export const sv: Record = { "A playbook that only restarts the server. It runs once the updates are in and the server has reported again.": "En playbook som bara startar om servern. Den körs när uppdateringarna är installerade och servern har rapporterat igen.", "A port with a note counts as taken, even when nothing is listening.": "En port med en anteckning räknas som upptagen, även när inget lyssnar.", "A scan from this app connected to it": "En skanning från den här appen kopplade upp sig mot den", + "a week": "en vecka", "About": "Gäller", "Acknowledge…": "Kvittera…", "Acknowledged": "Kvitterad", @@ -196,6 +197,7 @@ export const sv: Record = { "Couldn't load the history.": "Kunde inte läsa in historiken.", "Couldn't load the integrations.": "Kunde inte läsa in integrationerna.", "Couldn't save that. Try again.": "Det gick inte att spara. Försök igen.", + "CPU": "CPU", "CPU load": "Processorbelastning", "Created": "Skapad", "Critical": "Kritisk", @@ -216,7 +218,9 @@ export const sv: Record = { "didn't finish": "blev inte klar", "Disable": "Stäng av", "Disabled": "Avstängd", + "Disk": "Disk", "Disk (allocated)": "Disk (tilldelad)", + "Disk {mount}": "Disk {mount}", "Dismiss": "Avfärda", "Display": "Display", "DNS answers": "DNS-svar", @@ -346,6 +350,7 @@ export const sv: Record = { "Linked to": "Kopplad till", "Linking…": "Kopplar…", "Listening": "Lyssnar", + "Load and disk": "Belastning och disk", "Load:": "Belastning:", "Loading…": "Läser in…", "Longest wait": "Längsta väntan", @@ -365,6 +370,7 @@ export const sv: Record = { "Matched to a server": "Kopplad till en server", "Matching settings": "Matchande inställningar", "Media managers": "Mediahanterare", + "Mem": "Minne", "Memory": "Minne", "Monitoring": "Övervakning", "Most in an hour": "Flest på en timme", diff --git a/web/src/pages/Servers.tsx b/web/src/pages/Servers.tsx index c045501..6b4fcb1 100644 --- a/web/src/pages/Servers.tsx +++ b/web/src/pages/Servers.tsx @@ -28,8 +28,8 @@ import { RunsOnBulkDrawer, SilenceBulkDrawer, TagBulkDrawer } from "../component import { doBulk, plural } from "../utils/bulk"; import { BrandTag } from "../components/BrandIcon"; import { t } from "../i18n"; -import Sparkline, { useSparklines } from "../components/Sparkline"; -import { sparkWords } from "../utils/sparkline"; +import { useSparklines } from "../components/Sparkline"; +import ServerSparks from "../components/ServerSparks"; export default function Servers({ user }: { user: CurrentUser }) { @@ -255,22 +255,7 @@ export default function Servers({ user }: { user: CurrentUser }) {
{s.lastSeenAt ? <>{t("Last seen")} : t("Never reported")}
- {(sparks?.servers[s.id]?.cpu || sparks?.servers[s.id]?.mem) && ( -
- {([["cpu", t("CPU load")], ["mem", t("Memory")]] as const).map(([metric, name]) => { - const line = sparks?.servers[s.id]?.[metric]; - return line ? ( -
-
- {name} - {line.latest === null ? "—" : `${Math.round(line.latest)}%`} -
- = 90 ? "red" : line.latest !== null && line.latest >= 75 ? "orange" : "primary"} label={sparkWords(name, t("last 24 hours"), line.latest, line.low, line.high, (v) => `${Math.round(v)}%`)} /> -
- ) : null; - })} -
- )} +
@@ -465,6 +450,7 @@ export default function Servers({ user }: { user: CurrentUser }) { direction={sortDir} onSort={requestSort} /> + {t("Load and disk")} {t("Last 30 days")} {t("Actions")} @@ -488,6 +474,9 @@ export default function Servers({ user }: { user: CurrentUser }) { {s.apiTokenPrefix}… {s.lastSeenAt ? : "never"} + + + @@ -506,9 +495,9 @@ export default function Servers({ user }: { user: CurrentUser }) { ))} - {!loaded && } + {!loaded && } {loaded && sortedServers?.length === 0 && ( - tableSearch.setQuery("") : undefined} /> + tableSearch.setQuery("") : undefined} /> )}