Add homelab_server_boot_time_seconds to /metrics
When each agent-reported server last started (last report minus uptime), so uptime is time() - the metric and a reboot shows as it moving. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
41fbbf3467
commit
48aea747bc
3 files changed
+8
No files matched your search
@@ -61,6 +61,7 @@ describe("metrics and webhooks", () => {
|
||||
apiTokenPrefix: "a",
|
||||
lastSeenAt: now.toISOString(),
|
||||
cpuLoadPercent: 12.5,
|
||||
uptimeSeconds: 86_400,
|
||||
memTotalBytes: 1000,
|
||||
memUsedBytes: 250,
|
||||
disks: JSON.stringify([{ mount: "C:\\", sizeBytes: 100, usedBytes: 40 }]),
|
||||
@@ -161,6 +162,10 @@ describe("metrics and webhooks", () => {
|
||||
assert.ok(!text.includes('server="never"'), "a server that never reported has nothing to say");
|
||||
assert.match(text, /homelab_server_cpu_load_percent\{server="elsa \\"main\\""\} 12\.5/);
|
||||
assert.match(text, /homelab_server_memory_used_percent\{server="elsa \\"main\\""\} 25/);
|
||||
const boot = /homelab_server_boot_time_seconds\{server="elsa \\"main\\""\} (\d+)/.exec(text);
|
||||
assert.ok(boot, "a server that says how long it has been up gets a boot time");
|
||||
assert.ok(Math.abs(Number(boot[1]) - (Math.floor(Date.now() / 1000) - 86_400)) < 120, "the moment of its last report minus the uptime");
|
||||
assert.ok(!text.includes('homelab_server_boot_time_seconds{server="anna"}'), "one that does not say gets none");
|
||||
assert.match(text, /homelab_server_disk_used_percent\{server="elsa \\"main\\"",mount="C:\\\\"\} 40/, "a backslash in a mount is escaped");
|
||||
assert.match(text, /homelab_server_pending_updates\{server="elsa \\"main\\""\} 7/);
|
||||
assert.match(text, /homelab_server_pending_security_updates\{server="elsa \\"main\\""\} 2/);
|
||||
|
||||
Reference in new issue
Block a user