fix(daemon): sample disk usage on the filesystems pi2d uses

The status tile read `—` on a fresh machine: the sampler ran `statfs` on the
daemon's state dir, which is created lazily on the first instance log, so the
call failed with ENOENT and `diskUsedBytes`/`diskTotalBytes`/`diskPercent` all
came back null — `/info` then dropped `disk` altogether and the failure was
indistinguishable from a full disk.

`probeMount()` now walks up to the nearest existing ancestor and then to the
filesystem boundary (`st_dev` change), so a sample describes a volume, not a
directory. Candidates are pi2d's own write targets — `/` (the home volume on
macOS, where `/` is the sealed read-only system volume), the pi session store
and the visible workspace roots — never a mount-table dump: an unrelated or
hung network mount must not stall the sampler. Rows are deduped by `st_dev`,
sorted most-constrained first, capped at four, and reported as `system.disks[]`
with the legacy scalars aliasing the worst row. A sample that yields nothing
now carries `diskError` instead of silent nulls.

The status tile shows the worst filesystem and, when several are in play, one
quiet row per mount instead of a single percentage that hides the full volume.
This commit is contained in:
yuez committed 2026-10-30 16:17:43 +08:00
1 parent 1d907c08fa
commit 01fd7b9922
9 files changed
+474 -31

No files matched your search

+60 -4
View File
@@ -2,7 +2,7 @@ import { useTranslation } from "react-i18next";
import { Icon } from "@/components/icons";
import { RelativeTime } from "@/components/shared/relative-time";
import type { ResourcesResponse } from "@/lib/api";
import type { DiskUsage, ResourcesResponse } from "@/lib/api";
import { formatBytes, formatUptime, type ServerIdentity } from "@/features/status/server";
import { ErrorBlock } from "./card-parts";
@@ -34,6 +34,53 @@ function readable(pct: number | null): string {
return pct == null ? "—" : `${Math.round(pct)}%`;
}
function diskTone(pct: number): string {
return pct > 90 ? "is-err" : pct > 80 ? "is-warn" : "";
}
/**
* Disk tile meta line. One filesystem reads `mountPoint · used / total`; several
* become a compact worst-first stack (the daemon caps the list at 4), because a
* single headline percent would hide the volume that is actually full.
*/
function DiskMeta({ disks, diskError, diskPath }: { disks: DiskUsage[]; diskError?: string; diskPath?: string }) {
if (disks.length === 0) {
const reason = diskError ?? diskPath ?? "—";
return (
<span className="faint truncate" title={reason}>
{reason}
</span>
);
}
const detail = (disk: DiskUsage) =>
[disk.mountPoint, disk.fsType, `${formatBytes(disk.usedBytes)} / ${formatBytes(disk.totalBytes)}`]
.filter(Boolean)
.join(" · ");
if (disks.length === 1) {
const disk = disks[0]!;
return (
<span className="faint truncate" title={detail(disk)}>
{disk.mountPoint} · {formatBytes(disk.usedBytes)} / {formatBytes(disk.totalBytes)}
</span>
);
}
return (
<div className="disk-rows">
{disks.map((disk) => (
<div className="disk-row" key={disk.mountPoint}>
<span className="disk-row__label truncate" title={detail(disk)}>
{disk.mountPoint}
</span>
<b className={`disk-row__pct ${diskTone(disk.percent)}`}>{readable(percent(disk.percent))}</b>
</div>
))}
</div>
);
}
export interface MetricsBlockProps {
server: ServerIdentity;
resources: ResourcesResponse | undefined;
@@ -62,17 +109,26 @@ export function MetricsBlock({
}: MetricsBlockProps) {
const { t } = useTranslation();
const system = resources?.system;
const disks = system?.disks ?? [];
const cpu = percent(system?.cpuPercent ?? server.cpu);
const mem = percent(system?.memPercent ?? server.mem);
const disk = percent(system?.diskPercent ?? server.disk);
// `disks` is worst-first, so `[0]` is the number worth showing; the scalars are
// the same row on new daemons and the only source on old ones.
const disk = percent(disks[0]?.percent ?? system?.diskPercent ?? server.disk);
const live = t("status.live", { defaultValue: "Live" });
const cpuMeta = system
? `${system.cpuCores} ${t("status.cores")}${system.loadAvg ? ` · ${t("status.load")} ${system.loadAvg[0].toFixed(2)}` : ""}`
: live;
const memMeta = system ? `${formatBytes(system.memUsedBytes)} / ${formatBytes(system.memTotalBytes)}` : live;
const diskMeta = system ? (
<span className="faint truncate" title={system.diskPath}>{system.diskPath}</span>
) : live;
<DiskMeta
disks={disks}
{...(system.diskError === undefined ? {} : { diskError: system.diskError })}
{...(system.diskPath === undefined ? {} : { diskPath: system.diskPath })}
/>
) : (
live
);
const counts: Array<[string, string]> = [
[t("status.workspaces"), String(workspaceCount)],
+15
View File
@@ -302,6 +302,17 @@ export interface ModelsResponse {
pendingReason?: "fetching" | "no-instance" | "no-live-session";
}
/** One sampled filesystem (daemon ≥ 0.1.8; older daemons only send the scalars). */
export interface DiskUsage {
/** Filesystem boundary, e.g. `/`, `/home`, `/mnt/data`. */
mountPoint: string;
/** Best-effort type label (`ext4`, `btrfs`, …); absent when unknown. */
fsType?: string;
totalBytes: number;
usedBytes: number;
percent: number;
}
export interface SystemStats {
sampledAt: number;
cpuPercent: number | null;
@@ -314,6 +325,10 @@ export interface SystemStats {
diskUsedBytes: number | null;
diskTotalBytes: number | null;
diskPercent: number | null;
/** Most constrained first, at most 4 rows; absent on daemons < 0.1.8. */
disks?: DiskUsage[];
/** Present only when `disks` is empty — the sample failed, distinct from a full disk. */
diskError?: string;
}
export interface ResourcesResponse {
+19
View File
@@ -104,6 +104,25 @@
gap: 4px;
min-width: 0;
}
/* Multi-filesystem disk tile: one quiet row per mount, worst first. */
.status-tile .disk-rows {
display: flex;
flex-direction: column;
gap: 2px;
width: 100%;
min-width: 0;
}
.status-tile .disk-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 6px;
min-width: 0;
}
.status-tile .disk-row__label { min-width: 0; }
.status-tile .disk-row__pct { flex: none; font-weight: 600; font-variant-numeric: tabular-nums; }
.status-tile .disk-row__pct.is-warn { color: var(--warn); }
.status-tile .disk-row__pct.is-err { color: var(--err); }
/* 3px meter: a quiet hairline rather than a progress bar */
.meter {