feat(daemon): report host uptime, not only the daemon's process age

The status tile labelled "uptime" showed the age of the daemon *process*
(`/info.uptimeMs`), and `/info` was fetched once with a 30 s staleTime and no
refetch interval, so the figure also froze: on a box five days up, a
`pi2 update` restart made the tile read "3m" and it never moved again.

`os.uptime()` is now sampled with the other host figures and served as
`system.hostUptimeSec` — which the 3 s `/resources` poll already refreshes —
plus an additive `/info.hostUptimeMs`. The tile renders it through a
`LiveUptime` label that anchors the reported snapshot once and ticks locally,
so the counter advances without a refetch and cannot rewind on a re-render.
The daemon's own process age stays in the server card, relabelled
`status.daemonUptime`, next to the `pid`/`daemonId` that give it meaning.
This commit is contained in:
yuez committed 2026-10-30 16:18:48 +08:00
1 parent 01fd7b9922
commit 2f2f1bb518
16 files changed
+204 -10

No files matched your search

+16
View File
@@ -46,6 +46,8 @@ export interface DiskUsage {
export interface SystemStats {
sampledAt: number;
/** Host uptime in whole seconds (`os.uptime()`), `null` when the OS has none. */
hostUptimeSec: number | null;
cpuPercent: number | null;
cpuCores: number;
loadAvg: [number, number, number] | null;
@@ -74,6 +76,7 @@ export interface SysinfoDeps {
cpus?: () => Array<{ times: { user: number; nice: number; sys: number; idle: number; irq: number } }>;
totalmem?: () => number;
freemem?: () => number;
uptime?: () => number;
loadavg?: () => number[];
platform?: NodeJS.Platform;
/** Primary disk candidate; defaults to `/` (the home volume on macOS). */
@@ -279,6 +282,7 @@ export function createSysinfo(deps: SysinfoDeps = {}): SysinfoSampler {
const cpus = deps.cpus ?? (() => nodeOs.cpus());
const totalmem = deps.totalmem ?? (() => nodeOs.totalmem());
const freemem = deps.freemem ?? (() => nodeOs.freemem());
const uptime = deps.uptime ?? (() => nodeOs.uptime());
const loadavg = deps.loadavg ?? (() => nodeOs.loadavg());
/**
@@ -394,6 +398,17 @@ export function createSysinfo(deps: SysinfoDeps = {}): SysinfoSampler {
}
}
// ── Host uptime ──────────────────────────────────────────────
// The daemon's own process age lives on `/info.uptimeMs`; this is the
// figure a user reads as "how long has this box been up".
let hostUptimeSec: number | null = null;
try {
const raw = uptime();
if (Number.isFinite(raw) && raw >= 0) hostUptimeSec = Math.round(raw);
} catch {
hostUptimeSec = null;
}
// ── Memory ───────────────────────────────────────────────────
let memTotalBytes: number;
let memUsedBytes: number;
@@ -442,6 +457,7 @@ export function createSysinfo(deps: SysinfoDeps = {}): SysinfoSampler {
return {
sampledAt,
hostUptimeSec,
cpuPercent,
cpuCores,
loadAvg: loadAvgResult,
+3
View File
@@ -205,7 +205,10 @@ export function createApp(deps: AppDeps): Hono<Env> {
hostname: osHostname(),
os: `${osPlatform()} ${osRelease()}`,
version: daemonVersion(),
// Process age of the daemon itself (`uptimeMs`), distinct from the host
// figure (`hostUptimeMs`) the status page shows as "uptime".
uptimeMs: Math.max(0, now() - startedAt),
...(typeof system?.hostUptimeSec === "number" ? { hostUptimeMs: system.hostUptimeSec * 1000 } : {}),
pid: process.pid,
port: config.port,
capabilities: ["ws", "sse", "devices", "attention"],