Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Unify dashboard storage trend loading
rcourtmanb643d6d25534
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.mdindex cf9df13238..fba942bd4d 100644--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md@@ -197,6 +197,7 @@ an add-only capacity posture.11. Keep shared `internal/api/router.go` workload-chart downsampling presentation-only: when that router caps mixed-cadence workload history into equal-time buckets for operator-facing cards, lifecycle-adjacent setup and fleet surfaces must not reuse the shaped chart samples as heartbeat, enrollment, or last-seen authority.That same presentation-only boundary must preserve canonical millisecond timestamps when it serializes chart points, so lifecycle-adjacent first-host and fleet surfaces do not misread rounded chart samples as duplicate or restarted heartbeat evidence.The same rule now applies to storage summary interaction. Shared sticky-card or row-hover focus behavior on infrastructure, workloads, and storage may reuse the canonical chart transport, but lifecycle-adjacent install, enrollment, and fleet surfaces must not treat highlighted summary series or sticky-shell state as agent freshness or setup progress.+ Dashboard storage trend consumers on that shared router boundary must now reuse the single `/api/storage-charts` summary response instead of fanning out per-pool `/api/metrics-store/history` reads, and lifecycle surfaces still must treat that batched storage summary transport as presentation context only rather than install, enrollment, or freshness truth.12. Keep lifecycle installer fallback pinned to published release lineage only.When `internal/api/unified_agent.go` has to proxy `/install.sh` or`/install.ps1` from GitHub, the shared lifecycle path may only treat stablediff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex 97f83f5d6f..94f03db09f 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -236,6 +236,14 @@ when the disabled candidate no longer counts toward monitored-system capacity.hidden. Upgrade prompts, trial nudges, monitored-system migration guidance,usage counts, billing identity, and plan metadata must therefore not dependon hidden commercial routes surviving the public demo boundary.+34. Keep the storage summary route in `internal/api/router.go` as the+ canonical storage summary contract across dashboard and storage consumers.+ `internal/api/router.go`,+ `internal/api/contract_test.go`, and shared frontend consumers must expose+ pooled storage history through one response keyed by canonical+ metrics-target IDs, preserve millisecond chart timestamps, and avoid+ reconstructing storage summary behavior from per-pool+ `/api/metrics-store/history` fan-out.## Forbidden Pathsdiff --git a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md b/docs/release-control/v6/internal/subsystems/performance-and-scalability.mdindex 75b10ef712..29f30e389b 100644--- a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md+++ b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md@@ -328,6 +328,13 @@ must include API-backed systems such as top-level TrueNAS appliances throughthe shared `isAgentFacetInfrastructureResource(...)` helper instead of a local`resource.type` branch, so the summary poll/cache path stays on one canonicalinfrastructure selector contract.+That same protected dashboard hot path now includes storage trend loading too.+`frontend-modern/src/hooks/useDashboardTrends.ts` and+`internal/api/router.go` must keep dashboard storage trends on one+`/api/storage-charts` request backed by+`GetStorageMetricsForChartBatch(...)`, so the dashboard does not reopen an+N+1 per-pool `/api/metrics-store/history` fan-out just to compute the shared+24-hour storage capacity delta.That same dashboard shell boundary also owns empty-state action routing in`frontend-modern/src/components/Dashboard/DashboardStateCards.tsx`. When thedashboard has no connected infrastructure, the CTA must hand operatorsdiff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.mdindex 0ec7c50778..a27aaf35b1 100644--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md@@ -290,6 +290,11 @@ querying, and the operator-facing storage health presentation layer.storage detail charts must all address history through the canonicalunified-resource metrics-target IDs, and the storage page must reuse theshared sticky summary primitive instead of a storage-local scroll wrapper.+ Dashboard storage trends belong to that same owned summary contract: the+ dashboard may derive a 24-hour storage capacity delta from+ `/api/storage-charts`, but it must not rebuild storage summary behavior by+ fanning out per-pool `/api/metrics-store/history` reads or by inventing a+ dashboard-only storage history transport.13. Keep storage summary interaction scoped through the same canonical IDs.14. Keep adjacent AI settings persistence vendor-neutral on the shared`internal/api/` boundary. When storage- or recovery-adjacent hosted flowsdiff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.mdindex 643fee69ff..015dd727cb 100644--- a/docs/release-control/v6/internal/subsystems/unified-resources.md+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md@@ -273,6 +273,12 @@ assembly branch.through the canonical frontend-to-`ResourceType` resolver before slicingthe snapshot, so compatibility values such as `disk` / `physical_disk`stay on one cache truth instead of falling back to ad hoc filter aliases.+18. Keep dashboard storage trend target selection on canonical unified-resource+ truth. `frontend-modern/src/hooks/useDashboardTrends.ts` may detect+ storage presence from canonical `isStorage(...)` resources and their+ shared metrics-target IDs, but once storage exists it must reuse the owned+ `/api/storage-charts` summary contract instead of rebuilding page-local+ per-resource storage history fetches or storage-type aliases.## Current Statediff --git a/frontend-modern/src/hooks/__tests__/useDashboardTrends.test.ts b/frontend-modern/src/hooks/__tests__/useDashboardTrends.test.tsindex 8ac4b60f51..4531f81693 100644--- a/frontend-modern/src/hooks/__tests__/useDashboardTrends.test.ts+++ b/frontend-modern/src/hooks/__tests__/useDashboardTrends.test.ts@@ -1,6 +1,11 @@import { describe, expect, it } from 'vitest';import useDashboardTrendsSource from '@/hooks/useDashboardTrends.ts?raw';-import { computeTrendDelta, extractTrendData, type TrendPoint } from '@/hooks/useDashboardTrends';+import {+ buildStorageCapacityTrendPoints,+ computeTrendDelta,+ extractTrendData,+ type TrendPoint,+} from '@/hooks/useDashboardTrends';function createPoints(values: number[]): TrendPoint[] {const start = 1_700_000_000_000;@@ -80,6 +85,43 @@ describe('extractTrendData', () => {});});+describe('buildStorageCapacityTrendPoints', () => {+ it('aggregates used and available bytes into total capacity percentages', () => {+ const points = buildStorageCapacityTrendPoints({+ 'pool-a': {+ name: 'Pool A',+ usage: [],+ used: createPoints([400, 600]),+ avail: createPoints([600, 400]),+ },+ 'pool-b': {+ name: 'Pool B',+ usage: [],+ used: createPoints([100, 300]),+ avail: createPoints([900, 700]),+ },+ });++ expect(points).toEqual([+ { timestamp: 1_700_000_000_000, value: 25 },+ { timestamp: 1_700_000_060_000, value: 45 },+ ]);+ });++ it('drops timestamps without both used and available capacity', () => {+ const points = buildStorageCapacityTrendPoints({+ 'pool-a': {+ name: 'Pool A',+ usage: [],+ used: createPoints([400, 600]),+ avail: [{ timestamp: 1_700_000_000_000, value: 600 }],+ },+ });++ expect(points).toEqual([{ timestamp: 1_700_000_000_000, value: 40 }]);+ });+});+describe('useDashboardTrends infrastructure routing', () => {it('routes dashboard infrastructure sparklines through the infrastructure summary chart cache', () => {expect(useDashboardTrendsSource).toContain('fetchInfrastructureSummaryAndCache');@@ -87,4 +129,11 @@ describe('useDashboardTrends infrastructure routing', () => {expect(useDashboardTrendsSource).not.toContain('request.cpu.map(async');expect(useDashboardTrendsSource).not.toContain('request.memory.map(async');});++ it('routes storage trends through the storage summary charts endpoint', () => {+ expect(useDashboardTrendsSource).toContain('ChartService.getStorageSummaryCharts(STORAGE_RANGE)');+ expect(useDashboardTrendsSource).toContain('buildStorageCapacityTrendPoints(storageSummary.pools)');+ expect(useDashboardTrendsSource).not.toContain('metrics-store/history');+ expect(useDashboardTrendsSource).not.toContain('request.storage.map(async');+ });});diff --git a/frontend-modern/src/hooks/useDashboardTrends.ts b/frontend-modern/src/hooks/useDashboardTrends.tsindex 0c355ec427..6ffa3fd794 100644--- a/frontend-modern/src/hooks/useDashboardTrends.ts+++ b/frontend-modern/src/hooks/useDashboardTrends.ts@@ -1,9 +1,8 @@import { createEffect, createMemo, createSignal, type Accessor } from 'solid-js';import {ChartsAPI as ChartService,- type AggregatedMetricPoint,type HistoryTimeRange,- type ResourceType as HistoryResourceType,+ type StorageSummaryChartsResponse,type TimeRange,} from '@/api/charts';import {@@ -51,9 +50,8 @@ interface DashboardTrendSnapshot {error: string | null;}-const SPARKLINE_POINTS = 30;const INFRASTRUCTURE_RANGE: HistoryTimeRange = '1h';-const STORAGE_RANGE: HistoryTimeRange = '24h';+const STORAGE_RANGE: TimeRange = '24h';function createEmptyTrendData(): TrendData {return {@@ -170,46 +168,62 @@ async function fetchInfrastructureTrendSnapshot(};}-export function aggregateStoragePoints(allSeries: TrendPoint[][]): TrendPoint[] {- const buckets = new Map<number, { sum: number; count: number }>();-- for (const series of allSeries) {- for (const point of series) {- const bucket = buckets.get(point.timestamp) ?? { sum: 0, count: 0 };- bucket.sum += point.value;- bucket.count += 1;+export function buildStorageCapacityTrendPoints(+ pools: StorageSummaryChartsResponse['pools'],+): TrendPoint[] {+ const buckets = new Map<+ number,+ { used: number; avail: number; hasUsed: boolean; hasAvail: boolean }+ >();++ for (const pool of Object.values(pools)) {+ for (const point of pool.used ?? []) {+ if (!Number.isFinite(point.timestamp) || !Number.isFinite(point.value)) {+ continue;+ }+ const bucket = buckets.get(point.timestamp) ?? {+ used: 0,+ avail: 0,+ hasUsed: false,+ hasAvail: false,+ };+ bucket.used += point.value;+ bucket.hasUsed = true;+ buckets.set(point.timestamp, bucket);+ }+ for (const point of pool.avail ?? []) {+ if (!Number.isFinite(point.timestamp) || !Number.isFinite(point.value)) {+ continue;+ }+ const bucket = buckets.get(point.timestamp) ?? {+ used: 0,+ avail: 0,+ hasUsed: false,+ hasAvail: false,+ };+ bucket.avail += point.value;+ bucket.hasAvail = true;buckets.set(point.timestamp, bucket);}}return Array.from(buckets.entries()).sort((a, b) => a[0] - b[0])- .map(([timestamp, bucket]) => ({- timestamp,- value: bucket.sum / bucket.count,- }));-}--async function fetchMetricPoints(- resourceType: HistoryResourceType,- resourceId: string,- metric: 'cpu' | 'memory' | 'disk',- range: HistoryTimeRange,- maxPoints: number,-): Promise<TrendPoint[]> {- const result = await ChartService.getMetricsHistory({- resourceType,- resourceId,- metric,- range,- maxPoints,- });-- if (!('points' in result) || !Array.isArray(result.points)) {- return [];- }-- return normalizeTrendPoints(result.points as AggregatedMetricPoint[]);+ .flatMap(([timestamp, bucket]) => {+ if (!bucket.hasUsed || !bucket.hasAvail) {+ return [];+ }+ const total = bucket.used + bucket.avail;+ if (!Number.isFinite(total) || total <= 0) {+ return [];+ }+ return [+ {+ timestamp,+ value: (bucket.used / total) * 100,+ },+ ];+ });}export function computeTrendDelta(points: TrendPoint[]): number | null {@@ -254,7 +268,7 @@ async function fetchDashboardTrendSnapshot(}};- const [infrastructure, storageSeries] = await Promise.all([+ const [infrastructure, storageCapacity] = await Promise.all([(async () => {try {return await fetchInfrastructureTrendSnapshot(resources, request.infrastructureRange);@@ -263,27 +277,20 @@ async function fetchDashboardTrendSnapshot(return createEmptyTrendSnapshot().infrastructure;}})(),- Promise.all(- request.storage.map(async (resourceId) => {- try {- return await fetchMetricPoints(- 'storage',- resourceId,- 'disk',- STORAGE_RANGE,- SPARKLINE_POINTS,- );- } catch (error) {- captureError(error);- return [];- }- }),- ),+ (async () => {+ if (request.storage.length === 0) {+ return null;+ }+ try {+ const storageSummary = await ChartService.getStorageSummaryCharts(STORAGE_RANGE);+ return extractTrendData(buildStorageCapacityTrendPoints(storageSummary.pools));+ } catch (error) {+ captureError(error);+ return null;+ }+ })(),]);- const storageCapacity =- request.storage.length > 0 ? extractTrendData(aggregateStoragePoints(storageSeries)) : null;-return {infrastructure,storage: {diff --git a/internal/api/contract_test.go b/internal/api/contract_test.goindex e8aad2d044..73735e9639 100644--- a/internal/api/contract_test.go+++ b/internal/api/contract_test.go@@ -559,7 +559,7 @@ func TestContract_ChartMetricPointsPreserveMillisecondPrecision(t *testing.T) {func TestContract_StorageChartsUseCanonicalMetricsTargetIDs(t *testing.T) {monitor, state, metricsHistory := newTestMonitor(t)- now := time.Date(2026, time.April, 1, 12, 0, 0, 0, time.UTC)+ now := time.Now().UTC().Add(-5 * time.Minute).Truncate(time.Millisecond)metricsHistory.AddStorageMetric("vc-1:datastore:datastore-202", "usage", 0.25, now)metricsHistory.AddStorageMetric("vc-1:datastore:datastore-202", "used", 3.57*1024*1024*1024*1024, now)@@ -640,6 +640,17 @@ func TestContract_StorageChartsUseCanonicalMetricsTargetIDs(t *testing.T) {if _, ok := decoded.Pools["storage-truenas-1"]; ok {t.Fatalf("expected raw TrueNAS resource id to stay out of chart payload, got %v", decoded.Pools)}+ vmwarePool := decoded.Pools["vc-1:datastore:datastore-202"]+ if len(vmwarePool.Used) != 1 || len(vmwarePool.Avail) != 1 {+ t.Fatalf("expected canonical storage summary payload to preserve used/avail series, got %+v", vmwarePool)+ }+ if vmwarePool.Used[0].Timestamp != now.UnixMilli() || vmwarePool.Avail[0].Timestamp != now.UnixMilli() {+ t.Fatalf(+ "expected storage summary series to preserve millisecond timestamps, got used=%v avail=%v",+ vmwarePool.Used,+ vmwarePool.Avail,+ )+ }}func TestContract_TrueNASConnectionsDisabledMessageIsExplicit(t *testing.T) {diff --git a/internal/api/router.go b/internal/api/router.goindex 635b02b217..8e4cc3f109 100644--- a/internal/api/router.go+++ b/internal/api/router.go@@ -7777,10 +7777,10 @@ func (r *Router) handleStorageCharts(w http.ResponseWriter, req *http.Request) {return true}- // Build pool chart data — convert monitoring MetricPoints (time.Time) to- // API MetricPoints (Unix milliseconds) matching the infrastructure/workloads- // chart endpoints.- pools := make(map[string]StoragePoolChartData, len(readState.StoragePools()))+ // Build pool chart data from the canonical storage summary batch path so+ // the dashboard and storage page share one efficient history retrieval model.+ poolNames := make(map[string]string, len(readState.StoragePools()))+ storageIDs := make([]string, 0, len(readState.StoragePools()))for _, sp := range readState.StoragePools() {if sp == nil {continue@@ -7792,9 +7792,16 @@ func (r *Router) handleStorageCharts(w http.ResponseWriter, req *http.Request) {if sid == "" {continue}- metrics := monitor.GetStorageMetricsForChart(sid, duration)+ poolNames[sid] = sp.Name()+ storageIDs = append(storageIDs, sid)+ }++ poolMetrics := monitor.GetStorageMetricsForChartBatch(storageIDs, duration)+ pools := make(map[string]StoragePoolChartData, len(storageIDs))+ for _, sid := range storageIDs {+ metrics := poolMetrics[sid]pools[sid] = StoragePoolChartData{- Name: sp.Name(),+ Name: poolNames[sid],Usage: monitorPointsToAPI(metrics["usage"]),Used: monitorPointsToAPI(metrics["used"]),Avail: monitorPointsToAPI(metrics["avail"]),