Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/user/concepts/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions web/components/dashboard/node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
cpuCores,
cpuTop,
currentCores,
diskTopGib,
diskUsedBytes,
diskUsedPercent,
gib,
load,
Expand Down Expand Up @@ -292,10 +294,10 @@ export function Node({
/>
<Kpi
label="Disk used"
value={pct(diskUsedPercent(diskFree, diskTotal))}
value={gib(diskUsedBytes(diskFree, diskTotal))}
detail={
diskTotal && diskFree !== null
? `${gib(Math.max(0, diskTotal - diskFree))} of ${gib(diskTotal)} · ${cur.disk_path || "run volume"}`
? `of ${gib(diskTotal)} · ${pct(diskUsedPercent(diskFree, diskTotal))} · ${cur.disk_path || "run volume"}`
: `total unknown · ${cur.disk_path || "run volume"}`
}
/>
Expand Down Expand Up @@ -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"
/>
</Panel>
) : null}
Expand Down
19 changes: 19 additions & 0 deletions web/lib/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
cpuCores,
cpuTop,
currentCores,
diskTopGib,
diskUsedBytes,
diskUsedPercent,
gib,
niceMax,
Expand Down Expand Up @@ -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("–");
Expand Down
17 changes: 17 additions & 0 deletions web/lib/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, number> | undefined) =>
Object.values(by ?? {}).reduce((a, b) => a + b, 0);

Expand Down
11 changes: 7 additions & 4 deletions web/tests/node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Loading