diff --git a/docs/user/concepts/architecture.md b/docs/user/concepts/architecture.md index ebeac5a..1b1c937 100644 --- a/docs/user/concepts/architecture.md +++ b/docs/user/concepts/architecture.md @@ -81,7 +81,7 @@ volume's free disk and its running runs by kind (task runs per project, bot runs per bot, services and scheduled service runs per bot) and sends them with its admission report; the server keeps raw samples and 5-minute rollups, pruned hourly (`[node_metrics]`, `node_metrics.rs`). The web Node view -shows CPU in cores and memory in GiB and charts them in the viewer's local time (`GET /api/node/metrics`) and the Telegram owner command `/node` +shows CPU in cores and memory and disk used in GiB and charts them in the viewer's local time (`GET /api/node/metrics`) and the Telegram owner command `/node` shows the latest sample. **Rollouts.** SIGUSR1 starts a bounded drain: nothing new is admitted, and diff --git a/web/components/dashboard/node.tsx b/web/components/dashboard/node.tsx index ac110f2..43928c3 100644 --- a/web/components/dashboard/node.tsx +++ b/web/components/dashboard/node.tsx @@ -8,6 +8,8 @@ import { cpuCores, cpuTop, currentCores, + diskTopGib, + diskUsedBytes, diskUsedPercent, gib, load, @@ -292,10 +294,10 @@ export function Node({ /> @@ -351,17 +353,19 @@ export function Node({ step={s.step_seconds} from={s.from} to={s.to} - yMax={100} + reference={{ value: diskTotal, label: `total ${gib(diskTotal)}` }} + // Whole GiB ticks, like memory; percent stays in the readout. + yMax={diskTopGib(diskTotal) * GIB} series={[ { label: "Disk used", slot: 1, - values: s.points.map((p) => diskUsedPercent(p.disk_free_min, diskTotal)), + values: s.points.map((p) => diskUsedBytes(p.disk_free_min, diskTotal)), }, ]} - format={pct} - tick={(n) => `${n}%`} - yLabel="Used %" + format={(n) => `${gib(n)} (${pct((100 * n) / diskTotal)})`} + tick={(n) => `${Math.round(n / GIB)}`} + yLabel="GiB" /> ) : null} diff --git a/web/lib/node.test.ts b/web/lib/node.test.ts index dbc5c60..da035ce 100644 --- a/web/lib/node.test.ts +++ b/web/lib/node.test.ts @@ -6,6 +6,8 @@ import { cpuCores, cpuTop, currentCores, + diskTopGib, + diskUsedBytes, diskUsedPercent, gib, niceMax, @@ -87,6 +89,23 @@ describe("node view model", () => { expect(diskUsedPercent(120, 0)).toBeNull(); }); + it("disk used in bytes and its GiB axis top", () => { + expect(diskUsedBytes(120, 480)).toBe(360); + expect(diskUsedBytes(500, 480)).toBe(0); + expect(diskUsedBytes(null, 480)).toBeNull(); + expect(diskUsedBytes(120, 0)).toBeNull(); + const G = 2 ** 30; + expect(diskTopGib(500 * G)).toBe(600); + expect(diskTopGib(30 * G)).toBe(40); + expect(diskTopGib(100 * G)).toBe(120); + expect(diskTopGib(1 * G)).toBe(2); + for (const t of [8, 30, 64, 100, 250, 500, 1000, 2000]) { + const top = diskTopGib(t * G); + expect(top).toBeGreaterThanOrEqual(t * 1.05); + expect(Number.isInteger(top / 2)).toBe(true); + } + }); + it("formats values and ages", () => { expect(gib(1.5 * 2 ** 30)).toBe("1.5 GiB"); expect(gib(null)).toBe("–"); diff --git a/web/lib/node.ts b/web/lib/node.ts index 7692d57..c135d0f 100644 --- a/web/lib/node.ts +++ b/web/lib/node.ts @@ -86,6 +86,23 @@ export function diskUsedPercent(free: number | null | undefined, total: number | return (100 * Math.max(0, total - free)) / total; } +/** Disk used in bytes, `total - free`, against the current total like {@link diskUsedPercent}. */ +export function diskUsedBytes(free: number | null | undefined, total: number | null | undefined): number | null { + if (free === null || free === undefined || !total) return null; + return Math.max(0, total - free); +} + +/** + * The disk chart's axis top in whole GiB for a `total` of bytes with + * headroom: a multiple of two tenths of the next nice value, so the midline + * tick is a whole GiB count (500 GiB: 600, 300) without doubling the axis. + */ +export function diskTopGib(total: number): number { + const v = (total * 1.05) / GIB; + const step = (2 * niceMax(v)) / 10; + return Math.max(2, step * Math.ceil(v / step)); +} + export const runTotal = (by: Record | undefined) => Object.values(by ?? {}).reduce((a, b) => a + b, 0); diff --git a/web/tests/node.spec.ts b/web/tests/node.spec.ts index 7ad8de9..cb68e38 100644 --- a/web/tests/node.spec.ts +++ b/web/tests/node.spec.ts @@ -22,10 +22,10 @@ for (const theme of ["dark", "light"]) for (const width of [1440, 390]) { await expect(kpis).toContainText("6.2 GiB"); await expect(kpis).toContainText("of 16.0 GiB"); await expect(kpis).not.toContainText("39%"); - // Disk used, as /node's "disk N%": (500 - 120.4) / 500 GiB. + // Disk used as an amount too (owner #6909), percent as a detail: 500 - 120.4 GiB. await expect(kpis).toContainText("Disk used"); - await expect(kpis).toContainText("76%"); - await expect(kpis).toContainText("379.6 GiB of 500.0 GiB · /srv/axe/.runs"); + await expect(kpis).toContainText("379.6 GiB"); + await expect(kpis).toContainText("of 500.0 GiB · 76% · /srv/axe/.runs"); await expect(kpis).toContainText("3 task runs · 1 bot runs · 2 services · 0 scheduled runs"); for (const name of ["CPU", "Memory used", "Disk used", "Running runs by kind"]) await expect(page.getByRole("figure", { name })).toBeVisible(); @@ -65,10 +65,13 @@ for (const theme of ["dark", "light"]) for (const width of [1440, 390]) { // Disk history: each point's least free space against the current total. const disk = page.getByRole("figure", { name: "Disk used" }); await expect(disk).toContainText("of the current 500.0 GiB"); + await expect(disk).toContainText("total 500.0 GiB"); + await expect(disk).toContainText("GiB"); + await expect(disk).not.toContainText("Used %"); await disk.locator("svg[role=group]").scrollIntoViewIfNeeded(); const dbox = (await disk.locator("svg[role=group]").boundingBox())!; await page.mouse.move(dbox.x + dbox.width * 0.3, dbox.y + dbox.height / 2); - await expect(disk.locator("[aria-live=polite]")).toContainText("Disk used 76%"); + await expect(disk.locator("[aria-live=polite]")).toContainText(/Disk used \d+\.\d GiB \(\d+%\)/); // No horizontal overflow at any width. const overflow = await page.evaluate(() => document.documentElement.scrollWidth - window.innerWidth); expect(overflow).toBeLessThanOrEqual(0);