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:
1 parent
01fd7b9922
commit
2f2f1bb518
16 files changed
+204
-10
No files matched your search
@@ -92,6 +92,7 @@ describe("sysinfo", () => {
|
||||
// `/test` does not exist: the probe must land on the root filesystem
|
||||
// instead of blanking the tile (the shipped bug).
|
||||
stat: fakeStat(oneFs),
|
||||
uptime: () => 4321.6,
|
||||
readFile: async (path) => { reads++; return path === "/proc/stat" ? "cpu 10 0 0 10 0 0 0" : mem(); },
|
||||
statfs: async () => { stats++; return { bsize: 100, blocks: 10, bfree: 4, type: 0xef53 }; },
|
||||
cpus: () => cpus(10, 10),
|
||||
@@ -103,6 +104,7 @@ describe("sysinfo", () => {
|
||||
const first = await sampler.sample();
|
||||
expect(first).toEqual({
|
||||
sampledAt: 1000,
|
||||
hostUptimeSec: 4322,
|
||||
cpuPercent: null,
|
||||
cpuCores: 1,
|
||||
loadAvg: [1.23, 2.35, 3.46],
|
||||
@@ -139,6 +141,39 @@ describe("sysinfo", () => {
|
||||
await expect(sampler.sample()).resolves.toMatchObject({ memTotalBytes: 0, memUsedBytes: 0, memPercent: 0 });
|
||||
});
|
||||
|
||||
it("reports a host uptime independently of the daemon's own age", async () => {
|
||||
const result = await createSysinfo({
|
||||
platform: "linux",
|
||||
diskPath: "/",
|
||||
sessionsPath: "/pi/sessions",
|
||||
stat: fakeStat(oneFs),
|
||||
statfs: async () => ({ bsize: 100, blocks: 10, bfree: 4 }),
|
||||
uptime: () => 5 * 86_400 + 3 * 3_600,
|
||||
cpus: () => cpus(1, 1),
|
||||
totalmem: () => 1,
|
||||
freemem: () => 0,
|
||||
loadavg: () => [0, 0, 0],
|
||||
}).sample();
|
||||
expect(result.hostUptimeSec).toBe(442_800);
|
||||
});
|
||||
|
||||
it("nulls a host uptime the OS cannot report", async () => {
|
||||
const base = {
|
||||
platform: "linux" as const,
|
||||
diskPath: "/",
|
||||
sessionsPath: "/pi/sessions",
|
||||
stat: fakeStat(oneFs),
|
||||
statfs: async () => ({ bsize: 100, blocks: 10, bfree: 4 }),
|
||||
cpus: () => cpus(1, 1),
|
||||
totalmem: () => 1,
|
||||
freemem: () => 0,
|
||||
loadavg: () => [0, 0, 0],
|
||||
};
|
||||
for (const uptime of [() => Number.NaN, () => -1, () => Number.POSITIVE_INFINITY, () => { throw new Error("no uptime"); }]) {
|
||||
await expect(createSysinfo({ ...base, uptime }).sample()).resolves.toMatchObject({ hostUptimeSec: null });
|
||||
}
|
||||
});
|
||||
|
||||
it("reports a diskError instead of silent nulls when nothing can be sampled", async () => {
|
||||
const result = await createSysinfo({
|
||||
now: () => 1,
|
||||
|
||||
Reference in new issue
Block a user