feat(web): read host stats and the bare models endpoint on the status page

The metrics tiles now prefer the daemon's own sample (`resources.system`, then
`info.cpu/mem/disk`) over the old RSS-over-physical-memory guess, and each tile
gained the detail that makes the number actionable: cores and 1-minute load,
used/total bytes, the filesystem the disk figure describes.

The models card stops asking for a workspace it does not have. It calls the bare
endpoint (no spawn), polls every 1.5 s while the plugin's cache is still filling
(bounded to 12 rounds), and tells the three empty states apart instead of showing
one generic "no models": still fetching, no live instance, no live session. With
no workspace to key on, `fetchModels` also tolerates a legacy daemon that
requires the parameter, retrying with the first visible workspace.

Smaller fixes that fell out of the same read: `formatBytes` printed "4.00 GiB"
for a whole number of GiB, and the workspaces query now polls every 5 s only
while the socket is down, so a dropped connection still refreshes the page.
This commit is contained in:
yuez committed 2026-10-28 08:14:17 +08:00
1 parent b577e15f6d
commit 604fec5ea0
10 files changed
+560 -105

No files matched your search

+43 -4
View File
@@ -62,6 +62,19 @@ const resourcesBody = {
],
totalRssBytes: 512 * 1024 * 1024,
physicalMemoryBytes: 2048 * 1024 * 1024,
system: {
sampledAt: Date.now(),
cpuPercent: 37,
cpuCores: 8,
loadAvg: [1.23, 0.98, 0.75],
memUsedBytes: 4 * 1024 * 1024 * 1024,
memTotalBytes: 16 * 1024 * 1024 * 1024,
memPercent: 61,
diskPath: "/var/lib/pi2",
diskUsedBytes: 82 * 1024 * 1024 * 1024,
diskTotalBytes: 100 * 1024 * 1024 * 1024,
diskPercent: 82,
},
warn: true,
reason: "rss > soft limit",
};
@@ -242,10 +255,15 @@ describe("StatusPage", () => {
}
// cpu / mem / disk carry the 3px meter, uptime does not.
expect(document.querySelectorAll(".meter")).toHaveLength(3);
// 512 MiB of 2 GiB RSS → the memory ratio the daemon does not send directly.
await waitFor(() =>
expect(document.querySelector('.status-tile[data-res="mem"] .tile__value')).toHaveTextContent("25%"),
);
await waitFor(() => {
expect(document.querySelector('.status-tile[data-res="cpu"] .tile__value')).toHaveTextContent("37%");
expect(document.querySelector('.status-tile[data-res="mem"] .tile__value')).toHaveTextContent("61%");
expect(document.querySelector('.status-tile[data-res="disk"] .tile__value')).toHaveTextContent("82%");
});
expect(document.querySelector('.status-tile[data-res="mem"] .tile__meta')).toHaveTextContent("4 GiB / 16 GiB");
expect(document.querySelector('.status-tile[data-res="disk"] .tile__meta')).toHaveTextContent("/var/lib/pi2");
expect(document.querySelector('.status-tile[data-res="cpu"] .tile__meta')).toHaveTextContent("8");
expect(document.querySelector('.status-tile[data-res="cpu"] .tile__meta')).toHaveTextContent("1.23");
expect(document.querySelector('.status-tile[data-res="uptime"] .tile__value')).toHaveTextContent("2h 5m");
const counts = document.querySelector(".status-counts");
@@ -257,6 +275,27 @@ describe("StatusPage", () => {
expect(primaries()).toHaveLength(0);
});
it("does not derive memory percent from RSS on old daemons", async () => {
mockApi(
apiRoutes([
{
path: "/api/v1/resources",
handler: () => ({
body: {
...resourcesBody,
system: undefined,
},
}),
},
]),
);
await renderPage(routes(), "/status", { paired: true });
await screen.findByText("Server info");
await waitFor(() =>
expect(document.querySelector('.status-tile[data-res="mem"] .tile__value')).toHaveTextContent("—"),
);
});
it("puts info + health and models + tasks into two columns, with devices and connection full width", async () => {
mockApi(apiRoutes());
await renderPage(routes(), "/status", { paired: true });