From 8f5068c6e056a47dae13cd048e88a66cd482df75 Mon Sep 17 00:00:00 2001 From: Bobban Rydh Date: Sun, 8 Nov 2026 21:59:59 +0100 Subject: [PATCH] Add an Up for panel to the generated Grafana dashboard One tile per server, time() - homelab_server_boot_time_seconds, in the Servers row and following the Server picker. Co-Authored-By: Claude Sonnet 5.5 --- docs/PROMETHEUS-GRAFANA.md | 2 +- server/src/services/grafanaDashboard.ts | 1 + server/test/grafanaDashboard.test.ts | 11 ++++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/PROMETHEUS-GRAFANA.md b/docs/PROMETHEUS-GRAFANA.md index 4ff3535..df75f38 100644 --- a/docs/PROMETHEUS-GRAFANA.md +++ b/docs/PROMETHEUS-GRAFANA.md @@ -117,7 +117,7 @@ The dashboard has a **Server** picker (filled from `homelab_server_up`) and five | Row | What it has | |---|---| | **Needs attention** | Critical alerts, warnings, acknowledged, open incidents, servers down and up, integrations failing, maintenance, stale and failed backups, failed services, updates waiting, restarts needed; alerts over time; each integration's state. | -| **Servers** | One table (up, CPU, memory, updates, security updates, failed services, agent behind), CPU and memory over time, 30-day uptime, time since each agent last reported. | +| **Servers** | One table (up, CPU, memory, updates, security updates, failed services, agent behind), a tile per server for how long it has been up since it last started (for servers whose agent reports it), CPU and memory over time, 30-day uptime, time since each agent last reported. | | **Disks** | Usage with a 90% line, disks filling up (days to full), SMART health, SSD life used, disk temperature, ZFS pools. | | **Backups** | Guests by backup state, the age of each newest backup, and the age, last result and count of Homelab Manager's own backups. | | **Secrets, power and the app itself** | Secrets and certificates by days left, the inventory's power draw, how long `/metrics` takes to build. | diff --git a/server/src/services/grafanaDashboard.ts b/server/src/services/grafanaDashboard.ts index 1282b20..19e5551 100644 --- a/server/src/services/grafanaDashboard.ts +++ b/server/src/services/grafanaDashboard.ts @@ -200,6 +200,7 @@ export function buildGrafanaDashboard(): Record { 24, 9, ); + l.add(stat("Up for", `time() - homelab_server_boot_time_seconds${srv}`, { unit: "s", legend: "{{server}}", description: "How long each server has run since it last started, from the uptime its agent reports. A tile that has just reset is a server that has just rebooted." }), 24, 4); l.add(timeseries("CPU load", [{ expr: `homelab_server_cpu_load_percent${srv}`, legend: "{{server}}" }], { unit: "percent", min: 0 }), 12, 8); l.add(timeseries("Memory in use", [{ expr: `homelab_server_memory_used_percent${srv}`, legend: "{{server}}" }], { unit: "percent", min: 0, max: 100 }), 12, 8); l.add(bargauge("Uptime, last 30 days", `homelab_server_uptime_ratio_30d${srv}`, "{{server}}", { unit: "percentunit", min: 0, max: 1, thresholds: { steps: [[RED, null], [YELLOW, 0.95], [GREEN, 0.99]] } }), 12, 8); diff --git a/server/test/grafanaDashboard.test.ts b/server/test/grafanaDashboard.test.ts index 5912e1c..b920346 100644 --- a/server/test/grafanaDashboard.test.ts +++ b/server/test/grafanaDashboard.test.ts @@ -95,10 +95,19 @@ describe("what it asks for", () => { for (const m of [ "homelab_alerts", "homelab_incidents_open", "homelab_server_up", "homelab_server_disk_used_percent", "homelab_server_disk_days_to_full", "homelab_server_disk_healthy", "homelab_server_zfs_pool_online", "homelab_backup_guests", "homelab_backup_last_age_seconds", "homelab_selfbackup_last_success_timestamp_seconds", "homelab_secret_expiry_days", - "homelab_integration_up", "homelab_server_uptime_ratio_30d", "homelab_server_pending_updates", + "homelab_integration_up", "homelab_server_uptime_ratio_30d", "homelab_server_pending_updates", "homelab_server_boot_time_seconds", ]) assert.ok(asked.has(m), `${m} has no panel`); }); + test("a server's time since it last started is shown, per server, in seconds, and follows the Server picker", () => { + const p = panels.find((x) => x.title === "Up for")!; + assert.ok(p, "there is an Up for panel"); + assert.equal(p.type, "stat"); + assert.equal(p.targets![0].expr, 'time() - homelab_server_boot_time_seconds{server=~"$server"}'); + assert.equal(p.targets![0].legendFormat, "{{server}}"); + assert.equal((p as unknown as { fieldConfig: { defaults: { unit: string } } }).fieldConfig.defaults.unit, "s"); + }); + test("each query is well-formed: not empty, brackets and quotes balanced, no stray template text", () => { for (const p of withQueries) { for (const t of p.targets!) {