Historical metrics + sparkline charts #10

Closed
opened 2026-07-12 20:11:04 -06:00 by jhodgkin · 2 comments
Owner

Retain a rolling window of metric snapshots (e.g. 24h at 1-5 min resolution) and render small sparkline charts per host card instead of just the current value.

Retain a rolling window of metric snapshots (e.g. 24h at 1-5 min resolution) and render small sparkline charts per host card instead of just the current value.
Author
Owner

Starting this one. SQLite already retains 24h of snapshots (metric_snapshots), just unused by the UI so far. Plan: a windowed query for the last ~40 samples per host, embedded in the existing /api/hosts response (avoids N+1 requests given the polling model already in place), rendered as small hand-rolled SVG sparklines in each host card — no charting library needed at this scale.

Starting this one. SQLite already retains 24h of snapshots (`metric_snapshots`), just unused by the UI so far. Plan: a windowed query for the last ~40 samples per host, embedded in the existing `/api/hosts` response (avoids N+1 requests given the polling model already in place), rendered as small hand-rolled SVG sparklines in each host card — no charting library needed at this scale.
Author
Owner

Done and deployed. /api/hosts now embeds the last ~40 samples per host (one windowed query via ROW_NUMBER() OVER (PARTITION BY host_id ...), not N+1), rendered as small hand-rolled SVG sparklines (cpu/mem/disk overlaid) in each host card.

Also found and fixed a real pre-existing bug while checking the sparkline data: the Proxmox host node's own mem/disk had been null this entire time. /nodes/{node}/status nests memory: {total, used} / rootfs: {total, used}, but the code assumed the same flat mem/maxmem/disk/maxdisk shape the LXC listing endpoint uses — produced NaN, which serializes as null over JSON instead of throwing, so it went unnoticed. LXC entries were never affected (different endpoint, correct shape). Fixed and verified against raw Proxmox API values (68% mem / 3.5% disk, matches).

Done and deployed. `/api/hosts` now embeds the last ~40 samples per host (one windowed query via `ROW_NUMBER() OVER (PARTITION BY host_id ...)`, not N+1), rendered as small hand-rolled SVG sparklines (cpu/mem/disk overlaid) in each host card. Also found and fixed a real pre-existing bug while checking the sparkline data: the Proxmox **host node's own** mem/disk had been `null` this entire time. `/nodes/{node}/status` nests `memory: {total, used}` / `rootfs: {total, used}`, but the code assumed the same flat `mem`/`maxmem`/`disk`/`maxdisk` shape the *LXC listing* endpoint uses — produced `NaN`, which serializes as `null` over JSON instead of throwing, so it went unnoticed. LXC entries were never affected (different endpoint, correct shape). Fixed and verified against raw Proxmox API values (68% mem / 3.5% disk, matches).
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: jhodgkin/homelab-monitor#10