diff --git a/docs/CONSOLE.md b/docs/CONSOLE.md index 90f660d56..e3cf328c5 100644 --- a/docs/CONSOLE.md +++ b/docs/CONSOLE.md @@ -138,6 +138,7 @@ Each worker shows: | Devices | How many devices are running, and how many are leased | | Capacity | Devices running out of the limit, per platform | | Capabilities | Each optional module the worker knows of, such as agent-device: `available`, `off`, or `unavailable` with its reason | +| Load | The machine's CPU, memory and disk use, such as `CPU 34% · memory 9.8 of 32.0 GiB · disk 112.4 GiB free`. A figure the worker limits itself to, such as a container's, is marked `(limit)`, and one it could not read says `unavailable`. A disconnected worker says "No reading while disconnected" | A worker the gateway could not read from yet says "Not reported" where it has nothing to show. A worker that is still starting shows its health as @@ -167,6 +168,13 @@ Select a worker to open its page. It adds: each platform tool, such as Xcode or the Android emulator. - **Catalog**: the models and runtimes the worker can lease. It is read again straight after a component is installed, and otherwise every 30 seconds. +- **Load**: how busy the machine is right now: CPU busy share and cores, + memory available of total, swap used, memory pressure (`normal`, `warn` or + `critical`, left out where the system does not report it), and disk free of + total. A part the worker could not read says `Unavailable`. **Read** says how + long ago the reading was taken, and it ticks up until the next one. A + worker that sent no load says "Not reported.", and a disconnected one "No + reading while disconnected." - **Warm pool**: whether the worker keeps devices warm, the running slots it holds back per platform, and a row for each kind of device the targets name (targets that resolve to the same device are one row, their counts added) diff --git a/e2e/console/workers.spec.ts b/e2e/console/workers.spec.ts index 134197053..2b68758a1 100644 --- a/e2e/console/workers.spec.ts +++ b/e2e/console/workers.spec.ts @@ -425,6 +425,50 @@ test.describe("the workers views", () => { } }); + test("on a single host, a card shows its Load row and the detail shows the Load panel with an age that ticks", async ({ + daemon, + page, + }) => { + const [host] = await workerList(daemon); + await openConsole(page, daemon); + + const shown = card(page, host?.id ?? ""); + await expect(fact(shown, "Load")).toHaveText(/^CPU .*memory .*disk /); + await shown.getByRole("link", { name: host?.id ?? "" }).click(); + + const panel = page.getByRole("region", { name: "Load", exact: true }); + const read = fact(panel, "Read"); + await expect(read).toHaveText(/^\d+ s ago$/); + const first = await read.textContent(); + await expect(read).not.toHaveText(first ?? "", { timeout: 10_000 }); + await expect(fact(panel, "Memory")).toContainText("available"); + }); + + test("a disconnected worker's Load row says No reading while disconnected within a second", async ({ + page, + }) => { + const fleet = await startFleet([ + { driverScript: { ios: IOS }, label: "worker-a" }, + { driverScript: { ios: IOS }, label: "worker-b" }, + ]); + try { + await openConsole(page, fleet.gateway); + const load = fact(card(page, "worker-b"), "Load"); + // why: the gateway shows a worker's first reading after its refresh, so allow twice the default 5 s wait. + await expect(load).toHaveText(/^CPU /, { timeout: 10_000 }); + + await (fleet.workers[1] as RunningDaemon).stop(); + await untilTheGatewaySays( + fleet.gateway, + (views) => views.find((view) => view.label === "worker-b")?.connection === "disconnected", + ); + + await expect(load).toHaveText("No reading while disconnected", { timeout: 1_000 }); + } finally { + await disposeFleet(fleet); + } + }); + test("a disconnected worker shows as disconnected within a second", async ({ page }) => { const fleet = await startFleet([ { driverScript: { ios: IOS }, label: "worker-a" }, diff --git a/src/daemon/main.test.ts b/src/daemon/main.test.ts index 2c873a7b9..8eca03c1f 100644 --- a/src/daemon/main.test.ts +++ b/src/daemon/main.test.ts @@ -2756,6 +2756,31 @@ describe("startDaemon host load", () => { }); }); + it("dials its gateway only after the first host load reading, so the gateway's first status.get carries load", async () => { + const dials: number[] = []; + const listener = createServer((socket) => { + dials.push(Date.now()); + socket.destroy(); + }); + await new Promise((resolve) => listener.listen(0, "127.0.0.1", resolve)); + const { port } = listener.address() as { readonly port: number }; + try { + const probe = new FakeHostLoadProbe(); + await startOnClock({ + configOverrides: { gateway: { token: "join-token-load", url: `ws://127.0.0.1:${port}` } }, + hostLoadProbe: probe, + }); + await new Promise((resolve) => setTimeout(resolve, 100)); + expect(dials).toEqual([]); + + probe.answer(COUNTERS); + + await expect.poll(() => dials.length).toBeGreaterThan(0); + } finally { + await new Promise((resolve) => listener.close(() => resolve())); + } + }); + it("fits the load it answers with to the status.get bounds: an age over a day is capped at one day", async () => { const probe = new FakeHostLoadProbe(COUNTERS); const { clock, daemon } = await startOnClock({ hostLoadProbe: probe }); diff --git a/src/daemon/main.ts b/src/daemon/main.ts index d0922a379..dd8c3bc73 100644 --- a/src/daemon/main.ts +++ b/src/daemon/main.ts @@ -592,14 +592,17 @@ export async function startDaemon(options: StartDaemonOptions = {}): Promise gatewayUplink.start()); + } if (!config.http.enabled) return; void startHttpGateway().then( () => resolveGatewayStarted?.(), diff --git a/src/host-load/sampler.test.ts b/src/host-load/sampler.test.ts index f6361caf1..cda05db50 100644 --- a/src/host-load/sampler.test.ts +++ b/src/host-load/sampler.test.ts @@ -301,6 +301,38 @@ describe("HostLoadSampler", () => { sampler.dispose(); }); + it("settles firstReading when the first read is recorded, not before, and whether it succeeded or failed", async () => { + const answered = harness(); + let settled = false; + void answered.sampler.firstReading().then(() => (settled = true)); + answered.sampler.start(); + await flush(); + expect(settled).toBe(false); + await answered.settle(counters(10, 100)); + expect(settled).toBe(true); + + const failed = harness(); + let failedSettled = false; + void failed.sampler.firstReading().then(() => (failedSettled = true)); + failed.sampler.start(); + await failed.settle(new Error("no proc")); + expect(failedSettled).toBe(true); + }); + + it("settles firstReading at dispose when no read was ever recorded", async () => { + const { sampler } = harness(); + let settled = false; + void sampler.firstReading().then(() => (settled = true)); + sampler.start(); + await flush(); + expect(settled).toBe(false); + + sampler.dispose(); + await flush(); + + expect(settled).toBe(true); + }); + it("holds no timer after dispose(), and a read in flight changes nothing and logs nothing", async () => { const { clock, probe, sampler, settle, warnings } = harness(); sampler.start(); diff --git a/src/host-load/sampler.ts b/src/host-load/sampler.ts index 27a3f356b..839929c32 100644 --- a/src/host-load/sampler.ts +++ b/src/host-load/sampler.ts @@ -42,11 +42,21 @@ export class HostLoadSampler { #reading: { readonly at: number; readonly parts: Omit } | undefined; #inFlight = false; #disposed = false; + #firstReading: Promise; + #markFirstReading: () => void = () => undefined; #tickTimer: TimerHandle | undefined; #boundTimer: TimerHandle | undefined; constructor(private readonly options: HostLoadSamplerOptions) { this.#logger = (options.logger ?? new NoopLogger()).child("host-load"); + this.#firstReading = new Promise((resolve) => { + this.#markFirstReading = resolve; + }); + } + + /** why: settles once the first read has been recorded, whatever it found, or at dispose; the read's own bound keeps it from waiting longer than that. */ + firstReading(): Promise { + return this.#firstReading; } start(): void { @@ -65,6 +75,7 @@ export class HostLoadSampler { dispose(): void { this.#disposed = true; + this.#markFirstReading(); if (this.#tickTimer !== undefined) this.options.clock.cancel(this.#tickTimer); this.#tickTimer = undefined; if (this.#boundTimer !== undefined) this.options.clock.cancel(this.#boundTimer); @@ -132,6 +143,7 @@ export class HostLoadSampler { if (this.#states[part] === "read") this.#states[part] = "failed"; } this.#reading = { at: now, parts: {} }; + this.#markFirstReading(); return; } for (const part of ["cpu", "memory", "disk"] as const) { @@ -146,6 +158,7 @@ export class HostLoadSampler { if (counters.memory !== undefined) parts.memory = counters.memory; if (counters.disk !== undefined) parts.disk = counters.disk; this.#reading = { at: now, parts }; + this.#markFirstReading(); } #note(part: Part, present: boolean): void { diff --git a/ui/src/status.tsx b/ui/src/status.tsx index 6279042e2..bcf762391 100644 --- a/ui/src/status.tsx +++ b/ui/src/status.tsx @@ -29,6 +29,8 @@ const CONNECTIONS: Tones = { connected: "ok", disconnected: "error", incompatibl const HEALTH: Tones = { running: "ok", starting: "warn", failed: "error" }; +const PRESSURE: Tones = { normal: "ok", warn: "warn", critical: "error" }; + const INSTALL_STATES: Tones = { downloading: "ok", waiting: "idle" }; const WAITING_STAGES: Tones = { queued: "idle", starting: "ok" }; @@ -46,3 +48,4 @@ export const connectionStatus = (connection: string) => statusOf(CONNECTIONS, co export const healthStatus = (health: string) => statusOf(HEALTH, health); export const installStatus = (state: string) => statusOf(INSTALL_STATES, state); export const waitingStageStatus = (stage: string) => statusOf(WAITING_STAGES, stage); +export const pressureStatus = (pressure: string) => statusOf(PRESSURE, pressure); diff --git a/ui/src/views/load-model.test.ts b/ui/src/views/load-model.test.ts new file mode 100644 index 000000000..9c1f7e4bd --- /dev/null +++ b/ui/src/views/load-model.test.ts @@ -0,0 +1,66 @@ +import { describe, expect, it } from "vitest"; + +import { formatBusyPercent, formatBytes, formatCores, loadSummary } from "./load-model"; + +const MIB = 1024 ** 2; +const GIB = 1024 ** 3; + +describe("the load figures", () => { + it("formats bytes, busy % and cores as the CLI's Load line does, including 0, 1023.6 MiB, 0.5 cores, 1 core and 0.001 cores", () => { + expect(formatBytes(0)).toBe("0 B"); + expect(formatBytes(300 * MIB)).toBe("300 MiB"); + expect(formatBytes(1023.6 * MIB)).toBe("1.0 GiB"); + expect(formatBytes(9.8 * GIB)).toBe("9.8 GiB"); + expect(formatBusyPercent(33.5)).toBe("34%"); + expect(formatBusyPercent(33.4)).toBe("33%"); + expect(formatCores(10)).toBe("10 cores"); + expect(formatCores(0.5)).toBe("0.5 cores"); + expect(formatCores(1)).toBe("1 core"); + expect(formatCores(0.01)).toBe("0.01 cores"); + expect(formatCores(0.001)).toBe("<0.01 cores"); + }); +}); + +const FULL = { + cpu: { busyPercent: 34, cores: 10, limited: false }, + disk: { freeBytes: 112.4 * GIB, totalBytes: 494.4 * GIB }, + memory: { + availableBytes: 9.8 * GIB, + limited: false, + swapUsedBytes: 0, + totalBytes: 32 * GIB, + }, + readAt: 0, +}; + +describe("the card summary", () => { + it("lists CPU, memory and disk as the table shows, with (limit) on a limited part, including memory under 1 GiB", () => { + expect(loadSummary(FULL)).toBe("CPU 34% · memory 9.8 of 32.0 GiB · disk 112.4 GiB free"); + expect( + loadSummary({ + ...FULL, + cpu: { busyPercent: 61, cores: 2, limited: true }, + disk: { freeBytes: 40.2 * GIB, totalBytes: 100 * GIB }, + memory: { ...FULL.memory, availableBytes: 3.1 * GIB, limited: true, totalBytes: 8 * GIB }, + }), + ).toBe("CPU 61% (limit) · memory 3.1 of 8.0 GiB (limit) · disk 40.2 GiB free"); + expect( + loadSummary({ + ...FULL, + memory: { ...FULL.memory, availableBytes: 300 * MIB, totalBytes: 8 * GIB }, + }), + ).toContain("memory 300 MiB of 8.0 GiB"); + }); + + it("says CPU unavailable, memory unavailable or disk unavailable for an absent part", () => { + const { cpu: _cpu, ...noCpu } = FULL; + const { memory: _memory, ...noMemory } = FULL; + const { disk: _disk, ...noDisk } = FULL; + + expect(loadSummary(noCpu)).toBe( + "CPU unavailable · memory 9.8 of 32.0 GiB · disk 112.4 GiB free", + ); + expect(loadSummary(noMemory)).toBe("CPU 34% · memory unavailable · disk 112.4 GiB free"); + expect(loadSummary(noDisk)).toBe("CPU 34% · memory 9.8 of 32.0 GiB · disk unavailable"); + }); +}); diff --git a/ui/src/views/load-model.ts b/ui/src/views/load-model.ts new file mode 100644 index 000000000..c3910b95e --- /dev/null +++ b/ui/src/views/load-model.ts @@ -0,0 +1,52 @@ +import type { WorkerView } from "./workers-model"; + +export type WorkerLoad = NonNullable; + +const MIB = 2 ** 20; +const GIB = 2 ** 30; + +function roundHalfUp(value: number, decimals: number): number { + const scale = 10 ** decimals; + return Math.floor(value * scale + 0.5) / scale; +} + +function isGib(bytes: number): boolean { + return bytes > 0 && Math.floor(bytes / MIB + 0.5) >= 1024; +} + +export function formatBytes(bytes: number): string { + if (bytes <= 0) return "0 B"; + const mebibytes = Math.floor(bytes / MIB + 0.5); + if (mebibytes < 1024) return `${mebibytes} MiB`; + return `${roundHalfUp(bytes / GIB, 1).toFixed(1)} GiB`; +} + +export function formatBusyPercent(percent: number): string { + return `${roundHalfUp(percent, 0)}%`; +} + +export function formatCores(cores: number): string { + const figure = cores < 0.005 ? "<0.01" : String(roundHalfUp(cores, cores < 0.1 ? 2 : 1)); + return `${figure} ${cores === 1 ? "core" : "cores"}`; +} + +export function loadSummary(load: WorkerLoad): string { + const { cpu, disk, memory } = load; + const cpuPart = + cpu === undefined + ? "CPU unavailable" + : `CPU ${formatBusyPercent(cpu.busyPercent)}${cpu.limited ? " (limit)" : ""}`; + let memoryPart = "memory unavailable"; + if (memory !== undefined) { + const bothGib = isGib(memory.availableBytes) && isGib(memory.totalBytes); + const available = bothGib + ? roundHalfUp(memory.availableBytes / GIB, 1).toFixed(1) + : formatBytes(memory.availableBytes); + memoryPart = `memory ${available} of ${formatBytes(memory.totalBytes)}${ + memory.limited ? " (limit)" : "" + }`; + } + const diskPart = + disk === undefined ? "disk unavailable" : `disk ${formatBytes(disk.freeBytes)} free`; + return [cpuPart, memoryPart, diskPart].join(" · "); +} diff --git a/ui/src/views/worker-detail.test.tsx b/ui/src/views/worker-detail.test.tsx index 1052c10f6..5ed3bc051 100644 --- a/ui/src/views/worker-detail.test.tsx +++ b/ui/src/views/worker-detail.test.tsx @@ -74,6 +74,7 @@ const RUNNING: WorkerView = { function text(html: string): string { return html .replace(/<[^>]+>/g, " ") + .replace(/'/g, "'") .replace(/\s+/g, " ") .trim(); } @@ -267,11 +268,13 @@ describe("the warm pool section of a worker's page", () => { expect(shown).toContain("Reserved running slots iOS 1, Android 0"); }); - it("says Not reported for a worker whose status never carried the block", () => { + it("the warm pool's Not reported test checks the Warm pool panel alone", () => { const shown = detail(RUNNING); + const start = shown.indexOf("The devices the worker keeps booted ahead of demand"); + const panel = shown.slice(start, shown.indexOf("Installs in progress", start)); - expect(shown).toContain("Warm pool"); - expect(shown).toContain("Not reported."); + expect(start).toBeGreaterThan(-1); + expect(panel).toContain("Not reported."); }); it("shows none for a worker that is still starting", () => { @@ -356,3 +359,201 @@ describe("the Capabilities row of a worker's page", () => { expect(card).toContain("Capabilities agent-device available"); }); }); + +const GIB = 1024 ** 3; + +const LOAD = { + cpu: { busyPercent: 34, cores: 10, limited: false }, + disk: { freeBytes: 112.4 * GIB, totalBytes: 494.4 * GIB }, + memory: { + availableBytes: 9.8 * GIB, + limited: false, + pressure: "normal" as const, + swapUsedBytes: 1.2 * GIB, + totalBytes: 32 * GIB, + }, + readAt: NOW - 12_000, +}; + +const STARTING: WorkerView = { + connection: "connected", + drained: false, + health: "starting", + host: RUNNING.host, + id: "wrk_1", + lastSeenAt: NOW, +}; + +const LOAD_DESCRIPTION = "How busy the machine is right now"; + +function detailAt(worker: WorkerView, now: number): string { + return text(renderToStaticMarkup()); +} + +function loadPanel(shown: string): string { + const start = shown.indexOf(LOAD_DESCRIPTION); + if (start === -1) return ""; + const ends = ["Warm pool", "Devices, leases and capacity appear"] + .map((marker) => shown.indexOf(marker, start)) + .filter((index) => index !== -1); + return shown.slice(start, ends.length === 0 ? undefined : Math.min(...ends)); +} + +describe("a worker's card shows its load", () => { + const card = (worker: WorkerView) => text(renderToStaticMarkup()); + + it("a running worker's card shows the Load row right after Capabilities, and a starting worker's right after Version", () => { + const running = card({ ...RUNNING, load: LOAD }); + expect(running).toContain("Load CPU 34% · memory 9.8 of 32.0 GiB · disk 112.4 GiB free"); + expect(running.indexOf("Capabilities")).toBeGreaterThan(running.indexOf("Capacity")); + expect(running.indexOf("Load")).toBeGreaterThan(running.indexOf("Capabilities")); + + const starting = card({ ...STARTING, load: LOAD, version: "1.2.3" }); + expect(starting).toContain("Version 1.2.3 Load CPU 34% · memory 9.8 of 32.0 GiB"); + expect(starting).not.toContain("Devices"); + }); + + it("a worker card says Not reported for a connected worker with no load, and No reading while disconnected for a disconnected one", () => { + expect(card(RUNNING)).toContain("Load Not reported"); + expect(card({ ...RUNNING, connection: "disconnected", load: LOAD })).toContain( + "Load No reading while disconnected", + ); + }); + + it("an incompatible worker's card and page have no Load row or panel", () => { + const incompatible: WorkerView = { + connection: "incompatible", + drained: false, + id: "wrk_1", + lastSeenAt: NOW, + load: LOAD, + protocol: { gateway: { max: 35, min: 35 }, worker: { max: 30, min: 30 } }, + }; + + expect(card(incompatible)).not.toContain("Load"); + const page = detailAt(incompatible, NOW); + expect(page).not.toContain("Load "); + expect(page).not.toContain(LOAD_DESCRIPTION); + }); +}); + +describe("a worker's page shows its load", () => { + it("a running worker's detail shows the Load panel after Host and Catalog, with CPU, memory, swap, pressure, disk and the reading's age", () => { + const shown = detailAt({ ...RUNNING, load: LOAD }, NOW); + + expect(shown.indexOf(LOAD_DESCRIPTION)).toBeGreaterThan( + shown.indexOf("The models and runtimes it can lease."), + ); + expect(shown.indexOf("The models and runtimes it can lease.")).toBeGreaterThan( + shown.indexOf("The machine the worker runs on."), + ); + const panel = loadPanel(shown); + expect(panel).toContain("CPU 34% busy, 10 cores"); + expect(panel).toContain("Memory 9.8 GiB of 32.0 GiB available"); + expect(panel).toContain("Swap 1.2 GiB used"); + expect(panel).toContain("Pressure normal"); + expect(panel).toContain("Disk 112.4 GiB of 494.4 GiB free"); + expect(panel).toContain("Read 12 s ago"); + }); + + it("a starting worker's detail shows the Load panel after Host and before the startup line", () => { + const shown = detailAt({ ...STARTING, load: LOAD }, NOW); + const at = shown.indexOf(LOAD_DESCRIPTION); + + expect(at).toBeGreaterThan(shown.indexOf("The machine the worker runs on.")); + expect(at).toBeGreaterThan(-1); + expect(at).toBeLessThan(shown.indexOf("Devices, leases and capacity appear once startup")); + }); + + it("a worker's detail leaves out Pressure when the view has none, and leaves out Swap and Pressure when memory is absent", () => { + const { pressure: _pressure, ...noPressure } = LOAD.memory; + const withoutPressure = loadPanel( + detailAt({ ...RUNNING, load: { ...LOAD, memory: noPressure } }, NOW), + ); + expect(withoutPressure).toContain("Swap 1.2 GiB used"); + expect(withoutPressure).not.toContain("Pressure"); + + const { memory: _memory, ...noMemory } = LOAD; + const withoutMemory = loadPanel(detailAt({ ...RUNNING, load: noMemory }, NOW)); + expect(withoutMemory).toContain("CPU 34% busy"); + expect(withoutMemory).not.toContain("Swap"); + expect(withoutMemory).not.toContain("Pressure"); + }); + + it("a worker's detail shows pressure normal, warn and critical in the ok, warn and error tones", () => { + const tone = (pressure: "normal" | "warn" | "critical") => + renderToStaticMarkup( + , + ); + const status = (kind: string, word: string) => + `${word}`; + + expect(tone("normal")).toContain(status("ok", "normal")); + expect(tone("warn")).toContain(status("warn", "warn")); + expect(tone("critical")).toContain(status("error", "critical")); + }); + + it("a worker's detail says Unavailable in the row of an absent CPU, memory or disk", () => { + const { cpu: _cpu, ...noCpu } = LOAD; + const { memory: _memory, ...noMemory } = LOAD; + const { disk: _disk, ...noDisk } = LOAD; + + expect(loadPanel(detailAt({ ...RUNNING, load: noCpu }, NOW))).toContain("CPU Unavailable"); + expect(loadPanel(detailAt({ ...RUNNING, load: noMemory }, NOW))).toContain( + "Memory Unavailable", + ); + expect(loadPanel(detailAt({ ...RUNNING, load: noDisk }, NOW))).toContain("Disk Unavailable"); + }); + + it("a worker's detail says Not reported. in the Load panel with no load, and No reading while disconnected. for a disconnected worker", () => { + expect(loadPanel(detailAt(RUNNING, NOW))).toContain("Not reported."); + expect( + loadPanel(detailAt({ ...RUNNING, connection: "disconnected", load: LOAD }, NOW)), + ).toContain("No reading while disconnected."); + }); + + it("a worker's detail ages the reading as now minus readAt rounded up to a whole second, and shows a larger age for a later now", () => { + const worker = { ...RUNNING, load: { ...LOAD, readAt: NOW - 4_100 } }; + + expect(loadPanel(detailAt(worker, NOW))).toContain("Read 5 s ago"); + expect(loadPanel(detailAt(worker, NOW + 10_000))).toContain("Read 15 s ago"); + expect( + loadPanel(detailAt({ ...worker, load: { ...LOAD, readAt: NOW + 3_000 } }, NOW)), + ).toContain("Read 0 s ago"); + }); + + it("the Status panel's description reads the worker's connection, health, capacity and load, and the Load panel's How busy the machine is right now", () => { + const shown = detailAt({ ...RUNNING, load: LOAD }, NOW); + + expect(shown).toContain("The worker's connection, health, capacity and load."); + expect(shown).toContain("How busy the machine is right now"); + }); + + it("a worker's detail writes (limit) as muted text after a limited CPU or memory figure", () => { + const html = renderToStaticMarkup( + , + ); + const panel = loadPanel(text(html)); + + expect(panel).toContain("CPU 61% busy, 2 cores (limit)"); + expect(panel).toContain("Memory 9.8 GiB of 32.0 GiB available (limit)"); + expect(html.match(/\(limit\)<\/span>/g)).toHaveLength(2); + }); +}); diff --git a/ui/src/views/worker-detail.tsx b/ui/src/views/worker-detail.tsx index dd425badb..851742d94 100644 --- a/ui/src/views/worker-detail.tsx +++ b/ui/src/views/worker-detail.tsx @@ -1,9 +1,10 @@ import { Id, PageHeader, Panel } from "../layout"; import { formatDuration } from "../live/time"; import { Link } from "../router"; -import { deviceStateStatus, installStatus, Status } from "../status"; +import { deviceStateStatus, installStatus, pressureStatus, Status } from "../status"; import { type Column, DataTable } from "../table"; import { WorkerLeases } from "./leases"; +import { formatBusyPercent, formatBytes, formatCores } from "./load-model"; import { WorkerFacts } from "./worker-facts"; import { platformName, @@ -51,7 +52,7 @@ export function WorkerDetail(props: { } actions={} /> - + {worker.health === "starting" ? ( @@ -59,6 +60,7 @@ export function WorkerDetail(props: { +

Devices, leases and capacity appear once startup finishes.

) : ( @@ -70,7 +72,6 @@ export function WorkerDetail(props: { ); } -/** What a worker that has finished starting reports: its devices, leases, host, catalog and installs. */ function WorkerReads(props: { readonly worker: WorkerView; readonly workers: readonly WorkerView[]; @@ -93,6 +94,7 @@ function WorkerReads(props: {
+ ); } + +function LoadPanel({ now, worker }: { readonly worker: WorkerView; readonly now: number }) { + if (worker.connection === "incompatible") return null; + return ( + + + + ); +} + +function Limit({ limited }: { readonly limited: boolean }) { + return limited ? ( + <> + {" "} + (limit) + + ) : null; +} + +function LoadFacts({ now, worker }: { readonly worker: WorkerView; readonly now: number }) { + if (worker.connection === "disconnected") { + return

No reading while disconnected.

; + } + const { load } = worker; + if (load === undefined) return

Not reported.

; + const { cpu, disk, memory } = load; + const age = formatDuration(Math.ceil((now - load.readAt) / 1000) * 1000); + return ( +
+
+
CPU
+
+ {cpu === undefined ? ( + "Unavailable" + ) : ( + <> + {formatBusyPercent(cpu.busyPercent)} busy, {formatCores(cpu.cores)} + + + )} +
+
+
+
Memory
+
+ {memory === undefined ? ( + "Unavailable" + ) : ( + <> + {formatBytes(memory.availableBytes)} of {formatBytes(memory.totalBytes)} available + + + )} +
+
+ {memory === undefined ? null : ( +
+
Swap
+
{formatBytes(memory.swapUsedBytes)} used
+
+ )} + {memory?.pressure === undefined ? null : ( +
+
Pressure
+
+ {memory.pressure} +
+
+ )} +
+
Disk
+
+ {disk === undefined + ? "Unavailable" + : `${formatBytes(disk.freeBytes)} of ${formatBytes(disk.totalBytes)} free`} +
+
+
+
Read
+
{age} ago
+
+
+ ); +} diff --git a/ui/src/views/worker-facts.tsx b/ui/src/views/worker-facts.tsx index a3e2e7a39..9286f65b0 100644 --- a/ui/src/views/worker-facts.tsx +++ b/ui/src/views/worker-facts.tsx @@ -1,4 +1,5 @@ import { connectionStatus, healthStatus, Status } from "../status"; +import { loadSummary } from "./load-model"; import { capacityByPlatform, deviceCounts, platformName, type WorkerView } from "./workers-model"; const capabilityTone = { available: "ok", off: "idle", unavailable: "warn" } as const; @@ -39,6 +40,7 @@ export function WorkerFacts({ worker }: { readonly worker: WorkerView }) {
Version
{worker.version ?? "Not reported"}
+ {starting ? : null} {starting ? null : ( <>
@@ -76,12 +78,26 @@ export function WorkerFacts({ worker }: { readonly worker: WorkerView }) { ))}
+ )} ); } +function LoadRow({ worker }: { readonly worker: WorkerView }) { + if (worker.connection === "incompatible") return null; + let shown = "Not reported"; + if (worker.connection === "disconnected") shown = "No reading while disconnected"; + else if (worker.load !== undefined) shown = loadSummary(worker.load); + return ( +
+
Load
+
{shown}
+
+ ); +} + function Health({ health }: { readonly health: string }) { const status = healthStatus(health); return {status.word};