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
Add storage growth planner runway
rcourtman8c7a01186ea3
diff --git a/frontend-modern/src/components/Storage/Storage.tsx b/frontend-modern/src/components/Storage/Storage.tsxindex bbfd5b6d9b..6aef783699 100644--- a/frontend-modern/src/components/Storage/Storage.tsx+++ b/frontend-modern/src/components/Storage/Storage.tsx@@ -1,6 +1,7 @@import { Component, Show } from 'solid-js';import StorageCephSection from '@/components/Storage/StorageCephSection';import StorageContentCard from '@/components/Storage/StorageContentCard';+import StorageGrowthPlanner from '@/components/Storage/StorageGrowthPlanner';import StoragePageBanners from '@/components/Storage/StoragePageBanners';import StoragePageControls from '@/components/Storage/StoragePageControls';import StoragePageSummary from '@/components/Storage/StoragePageSummary';@@ -19,6 +20,7 @@ const Storage: Component = () => {setStorageSummaryCollapsed,storageGrowthBySeriesId,storageGrowthColumnLabel,+ storageGrowthPlanner,storageSummaryData,storageSummaryLoaded,storageSummaryFetchFailed,@@ -72,6 +74,7 @@ const Storage: Component = () => {hoveredStorageResourceId,isLoadingPools,focusedStorageResourceId,+ focusStorageGrowthPool,jumpToActiveStorageRow,selectedDiskId,setChartHoverSync,@@ -93,38 +96,48 @@ const Storage: Component = () => {<Show when={!storageSummaryCollapsed()}><StickySummarySection desktopOnly={false} stickyDesktopOnly>- <StoragePageSummary- filteredRecords={filteredRecords}- search={search}- sourceFilter={sourceFilter}- healthFilter={healthFilter}- diskRoleFilter={diskRoleFilter}- diskGroupFilter={diskGroupFilter}- selectedNodeId={selectedNodeId}- nodeOptions={nodeOptions}- physicalDisks={physicalDisks}- summaryTimeRange={summaryTimeRange}- setSummaryTimeRange={setSummaryTimeRange}- storageSummaryData={storageSummaryData}- storageSummaryLoaded={storageSummaryLoaded}- storageSummaryFetchFailed={storageSummaryFetchFailed}- hoveredResourceId={hoveredStorageResourceId}- hoveredGroupScope={hoveredSummaryStorageGroupScope}- focusedResourceId={focusedStorageResourceId}- focusedGroupScope={focusedSummaryStorageGroupScope}- chartHoverSync={chartHoverSync}- onChartHoverSyncChange={setChartHoverSync}- showJumpToActiveRow={shouldShowJumpToActiveStorageRow}- onJumpToActiveRow={jumpToActiveStorageRow}- onScopeToDegradedPools={() => {- setView('pools');- setStorageFilterStatus('attention');- }}- onScopeToFailingDisks={() => {- setView('disks');- setStorageFilterStatus('attention');- }}- />+ <div class="space-y-2">+ <StoragePageSummary+ filteredRecords={filteredRecords}+ search={search}+ sourceFilter={sourceFilter}+ healthFilter={healthFilter}+ diskRoleFilter={diskRoleFilter}+ diskGroupFilter={diskGroupFilter}+ selectedNodeId={selectedNodeId}+ nodeOptions={nodeOptions}+ physicalDisks={physicalDisks}+ summaryTimeRange={summaryTimeRange}+ setSummaryTimeRange={setSummaryTimeRange}+ storageSummaryData={storageSummaryData}+ storageSummaryLoaded={storageSummaryLoaded}+ storageSummaryFetchFailed={storageSummaryFetchFailed}+ hoveredResourceId={hoveredStorageResourceId}+ hoveredGroupScope={hoveredSummaryStorageGroupScope}+ focusedResourceId={focusedStorageResourceId}+ focusedGroupScope={focusedSummaryStorageGroupScope}+ chartHoverSync={chartHoverSync}+ onChartHoverSyncChange={setChartHoverSync}+ showJumpToActiveRow={shouldShowJumpToActiveStorageRow}+ onJumpToActiveRow={jumpToActiveStorageRow}+ onScopeToDegradedPools={() => {+ setView('pools');+ setStorageFilterStatus('attention');+ }}+ onScopeToFailingDisks={() => {+ setView('disks');+ setStorageFilterStatus('attention');+ }}+ />+ <StorageGrowthPlanner+ planner={storageGrowthPlanner()}+ loaded={storageSummaryLoaded()}+ fetchFailed={storageSummaryFetchFailed()}+ activeSeriesId={activeSummaryStorageResourceId()}+ onFocusPool={focusStorageGrowthPool}+ onHoverPool={setHoveredStorageResourceId}+ />+ </div></StickySummarySection></Show>diff --git a/frontend-modern/src/components/Storage/StorageGrowthPlanner.tsx b/frontend-modern/src/components/Storage/StorageGrowthPlanner.tsxnew file mode 100644index 0000000000..677876f25d--- /dev/null+++ b/frontend-modern/src/components/Storage/StorageGrowthPlanner.tsx@@ -0,0 +1,151 @@+import { Component, For, Show } from 'solid-js';+import type {+ StorageGrowthPlannerPool,+ StorageGrowthPlannerPresentation,+} from '@/features/storageBackups/storageGrowthPlannerPresentation';++type StorageGrowthPlannerProps = {+ planner: StorageGrowthPlannerPresentation;+ loaded: boolean;+ fetchFailed: boolean;+ activeSeriesId?: string | null;+ onFocusPool?: (seriesId: string) => void;+ onHoverPool?: (seriesId: string | null) => void;+};++const STORAGE_GROWTH_PLANNER_FRAME_CLASS = 'rounded-md border border-border bg-surface shadow-sm';+const STORAGE_GROWTH_PLANNER_HEADER_CLASS =+ 'flex flex-wrap items-center justify-between gap-2 border-b border-border-subtle px-3 py-2';+const STORAGE_GROWTH_PLANNER_LIST_CLASS = 'grid gap-2 p-2 sm:grid-cols-2 xl:grid-cols-3';+const STORAGE_GROWTH_PLANNER_ITEM_CLASS =+ 'min-w-0 rounded border border-border bg-surface-alt px-2.5 py-2 text-left transition-colors hover:border-sky-300 hover:bg-surface focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/40';+const STORAGE_GROWTH_PLANNER_ACTIVE_ITEM_CLASS =+ 'border-sky-400 bg-sky-50 ring-2 ring-inset ring-sky-500/20 dark:bg-sky-950/30';+const STORAGE_GROWTH_PLANNER_EMPTY_CLASS = 'px-3 py-4 text-sm text-muted';+const STORAGE_GROWTH_PLANNER_SKELETON_CLASS =+ 'h-[74px] animate-pulse rounded border border-border bg-surface-alt';++const StorageGrowthPlannerItem: Component<{+ pool: StorageGrowthPlannerPool;+ active: boolean;+ onFocus?: (seriesId: string) => void;+ onHover?: (seriesId: string | null) => void;+}> = (props) => (+ <button+ type="button"+ class={`${STORAGE_GROWTH_PLANNER_ITEM_CLASS} ${+ props.active ? STORAGE_GROWTH_PLANNER_ACTIVE_ITEM_CLASS : ''+ }`.trim()}+ title={props.pool.runwayTitle}+ data-testid={`storage-growth-planner-pool-${props.pool.seriesId}`}+ data-summary-series-id={props.pool.seriesId}+ data-storage-growth-priority={props.pool.priority}+ onClick={() => props.onFocus?.(props.pool.seriesId)}+ onPointerEnter={(event) => {+ if (event.pointerType !== 'touch') {+ props.onHover?.(props.pool.seriesId);+ }+ }}+ onPointerLeave={(event) => {+ if (event.pointerType !== 'touch') {+ props.onHover?.(null);+ }+ }}+ onFocus={() => props.onHover?.(props.pool.seriesId)}+ onBlur={() => props.onHover?.(null)}+ >+ <div class="flex min-w-0 items-start justify-between gap-2">+ <div class="min-w-0">+ <div class="truncate text-[12px] font-semibold text-base-content">{props.pool.name}</div>+ <div class="truncate text-[11px] text-muted">{props.pool.hostLabel}</div>+ </div>+ <span+ class={`shrink-0 rounded-full border px-1.5 py-0.5 text-[10px] font-semibold ${props.pool.priorityToneClass}`}+ >+ {props.pool.priorityLabel}+ </span>+ </div>+ <div class="mt-2 grid grid-cols-3 gap-2 text-[11px]">+ <div class="min-w-0">+ <div class="text-muted">Growth</div>+ <div class={`truncate font-mono font-semibold ${props.pool.growthToneClass}`}>+ {props.pool.growthLabel}+ </div>+ </div>+ <div class="min-w-0">+ <div class="text-muted">Runway</div>+ <div class="truncate font-semibold text-base-content">{props.pool.runwayLabel}</div>+ </div>+ <div class="min-w-0">+ <div class="text-muted">{props.pool.usageLabel}</div>+ <div class="truncate text-base-content">{props.pool.freeLabel}</div>+ </div>+ </div>+ </button>+);++export const StorageGrowthPlanner: Component<StorageGrowthPlannerProps> = (props) => {+ const headerSummary = () => {+ if (props.fetchFailed) {+ return 'History unavailable';+ }+ return `${props.planner.growingPoolCount}/${props.planner.trackedPoolCount} growing`;+ };++ return (+ <section+ class={STORAGE_GROWTH_PLANNER_FRAME_CLASS}+ data-testid="storage-growth-planner"+ aria-label="Storage growth planner"+ >+ <div class={STORAGE_GROWTH_PLANNER_HEADER_CLASS}>+ <div class="min-w-0">+ <h2 class="text-sm font-semibold text-base-content">Growth Planner</h2>+ <p class="text-[11px] text-muted">+ {props.planner.rangeLabel} runway from storage history+ </p>+ </div>+ <div class="text-[11px] font-medium text-muted">{headerSummary()}</div>+ </div>+ <Show+ when={props.loaded}+ fallback={+ <div class={STORAGE_GROWTH_PLANNER_LIST_CLASS}>+ <div class={STORAGE_GROWTH_PLANNER_SKELETON_CLASS} />+ <div class={STORAGE_GROWTH_PLANNER_SKELETON_CLASS} />+ <div class={STORAGE_GROWTH_PLANNER_SKELETON_CLASS} />+ </div>+ }+ >+ <Show+ when={!props.fetchFailed && props.planner.topPools.length > 0}+ fallback={+ <div class={STORAGE_GROWTH_PLANNER_EMPTY_CLASS}>+ <div class="font-medium text-base-content">{props.planner.emptyTitle}</div>+ <div class="mt-0.5">+ {props.fetchFailed+ ? 'Trend history could not be loaded.'+ : props.planner.emptyMessage}+ </div>+ </div>+ }+ >+ <div class={STORAGE_GROWTH_PLANNER_LIST_CLASS}>+ <For each={props.planner.topPools}>+ {(pool) => (+ <StorageGrowthPlannerItem+ pool={pool}+ active={props.activeSeriesId === pool.seriesId}+ onFocus={props.onFocusPool}+ onHover={props.onHoverPool}+ />+ )}+ </For>+ </div>+ </Show>+ </Show>+ </section>+ );+};++export default StorageGrowthPlanner;diff --git a/frontend-modern/src/components/Storage/__tests__/Storage.test.tsx b/frontend-modern/src/components/Storage/__tests__/Storage.test.tsxindex b79c99f61b..d397111d03 100644--- a/frontend-modern/src/components/Storage/__tests__/Storage.test.tsx+++ b/frontend-modern/src/components/Storage/__tests__/Storage.test.tsx@@ -432,6 +432,7 @@ describe('Storage', () => {});it('renders per-pool growth from the shared storage summary history contract', async () => {+ const gib = 1024 * 1024 * 1024;const storageSummarySpy = vi.spyOn(ChartsAPI, 'getStorageSummaryCharts').mockResolvedValue({pools: {'pool:alpha': {@@ -441,12 +442,12 @@ describe('Storage', () => {{ timestamp: Date.now(), value: 44 },],used: [- { timestamp: Date.now() - 86_400_000, value: 100 * 1024 * 1024 * 1024 },- { timestamp: Date.now(), value: 140 * 1024 * 1024 * 1024 },+ { timestamp: Date.now() - 86_400_000, value: 100 * gib },+ { timestamp: Date.now(), value: 140 * gib },],avail: [- { timestamp: Date.now() - 86_400_000, value: 150 * 1024 * 1024 * 1024 },- { timestamp: Date.now(), value: 110 * 1024 * 1024 * 1024 },+ { timestamp: Date.now() - 86_400_000, value: 150 * gib },+ { timestamp: Date.now(), value: 110 * gib },],},'pool:beta': {@@ -456,12 +457,12 @@ describe('Storage', () => {{ timestamp: Date.now(), value: 68 },],used: [- { timestamp: Date.now() - 86_400_000, value: 220 * 1024 * 1024 * 1024 },- { timestamp: Date.now(), value: 200 * 1024 * 1024 * 1024 },+ { timestamp: Date.now() - 86_400_000, value: 220 * gib },+ { timestamp: Date.now(), value: 200 * gib },],avail: [- { timestamp: Date.now() - 86_400_000, value: 80 * 1024 * 1024 * 1024 },- { timestamp: Date.now(), value: 100 * 1024 * 1024 * 1024 },+ { timestamp: Date.now() - 86_400_000, value: 80 * gib },+ { timestamp: Date.now(), value: 100 * gib },],},},@@ -473,12 +474,20 @@ describe('Storage', () => {hookResources = [buildStorageResource('storage-display-alpha', 'Alpha-Store', 'pve1', {+ total: 250 * gib,+ used: 140 * gib,+ free: 110 * gib,+ current: 56,metricsTarget: {resourceType: 'storage',resourceId: 'pool:alpha',},}),buildStorageResource('storage-display-beta', 'Beta-Store', 'pve2', {+ total: 300 * gib,+ used: 200 * gib,+ free: 100 * gib,+ current: 67,metricsTarget: {resourceType: 'storage',resourceId: 'pool:beta',@@ -489,8 +498,20 @@ describe('Storage', () => {render(() => <Storage />);expect(await screen.findByText('Growth (24h)')).toBeInTheDocument();- expect(await screen.findByText(/\+40(?:\.0)? GB/)).toBeInTheDocument();- expect(screen.getByText(/-20(?:\.0)? GB/)).toBeInTheDocument();+ const storageContentSurface = screen.getByTestId('storage-content-surface');+ expect(await within(storageContentSurface).findByText(/\+40(?:\.0)? GB/)).toBeInTheDocument();+ expect(within(storageContentSurface).getByText(/-20(?:\.0)? GB/)).toBeInTheDocument();+ expect(screen.getByTestId('storage-growth-planner')).toHaveTextContent(+ '24h runway from storage history',+ );+ expect(screen.getByTestId('storage-growth-planner')).toHaveTextContent('1/2 growing');+ expect(screen.getByTestId('storage-growth-planner')).toHaveTextContent('3 days');++ fireEvent.click(screen.getByTestId('storage-growth-planner-pool-pool:alpha'));++ await waitFor(() => {+ expect(screen.getByRole('button', { name: 'Collapse Alpha-Store' })).toBeInTheDocument();+ });expect(storageSummarySpy).toHaveBeenCalledWith('24h', undefined, { nodeId: undefined });storageSummarySpy.mockRestore();@@ -561,7 +582,7 @@ describe('Storage', () => {expect(stickyWrapper?.className).toContain('lg:sticky');expect(stickyWrapper?.className).toContain('top-0');- const alphaRow = screen.getByText('Alpha-Store').closest('tr')!;+ const alphaRow = document.querySelector('tr[data-summary-series-id="pool:alpha"]')!;expect(alphaRow).toHaveAttribute('data-summary-series-id', 'pool:alpha');expect(alphaRow).toHaveAttribute('data-summary-row-active', 'false');@@ -1369,7 +1390,9 @@ describe('Storage', () => {render(() => <Storage />);await screen.findByTestId('storage-summary');- const alphaRow = screen.getByText('Alpha-Store').closest('tr') as HTMLTableRowElement;+ const alphaRow = document.querySelector(+ 'tr[data-summary-series-id="pool:alpha"]',+ ) as HTMLTableRowElement;expect(alphaRow).toBeTruthy();alphaRow.getBoundingClientRect = vi.fn(() => ({diff --git a/frontend-modern/src/components/Storage/useStoragePageModel.ts b/frontend-modern/src/components/Storage/useStoragePageModel.tsindex 6f731fc24f..7a02e84972 100644--- a/frontend-modern/src/components/Storage/useStoragePageModel.ts+++ b/frontend-modern/src/components/Storage/useStoragePageModel.ts@@ -6,6 +6,7 @@ import {type SummaryTimeRange,} from '@/components/shared/summaryTimeRange';import { buildStorageCapacityDeltaPresentation } from '@/features/storageBackups/storageCapacityDeltaPresentation';+import { buildStorageGrowthPlannerPresentation } from '@/features/storageBackups/storageGrowthPlannerPresentation';import {resolvePhysicalDiskMetricResourceId,resolveStorageRecordMetricResourceId,@@ -192,6 +193,13 @@ export const useStoragePageModel = () => {}return growth;});+ const storageGrowthPlanner = createMemo(() =>+ buildStorageGrowthPlannerPresentation({+ records: filteredRecords(),+ pools: storageSummaryCharts.data()?.pools,+ rangeLabel: storageGrowthRangeLabel(),+ }),+ );const hoveredStorageResourceId = createMemo(() => {const hoveredId = hoveredStorageRowId();if (!hoveredId) return null;@@ -219,6 +227,13 @@ export const useStoragePageModel = () => {}return keys;});+ const storageRecordIdByMetricSeriesId = createMemo(() => {+ const ids = new Map<string, string>();+ for (const record of records()) {+ ids.set(resolveStorageRecordMetricResourceId(record), record.id);+ }+ return ids;+ });const physicalDiskSeriesIds = createMemo(() => {const ids = new Set<string>();for (const disk of physicalDisks()) {@@ -442,6 +457,21 @@ export const useStoragePageModel = () => {},});+ const focusStorageGrowthPool = (seriesId: string) => {+ const recordId = storageRecordIdByMetricSeriesId().get(seriesId);+ if (!recordId) {+ return;+ }+ if (view() !== 'pools') {+ setView('pools');+ }+ const groupKey = storageGroupKeyByMetricSeriesId().get(seriesId);+ if (groupKey && !expandedGroups().has(groupKey)) {+ toggleGroup(groupKey);+ }+ setExpandedPoolId(recordId);+ };+onCleanup(() => {routeStateNavigate.cleanup();});@@ -459,6 +489,7 @@ export const useStoragePageModel = () => {setStorageSummaryCollapsed,storageGrowthBySeriesId,storageGrowthColumnLabel,+ storageGrowthPlanner,storageSummaryData: storageSummaryCharts.data,storageSummaryLoaded: storageSummaryCharts.loaded,storageSummaryFetchFailed: storageSummaryCharts.fetchFailed,@@ -509,6 +540,7 @@ export const useStoragePageModel = () => {hoveredStorageResourceId,isLoadingPools,jumpToActiveStorageRow: summaryInteraction.jumpToActiveRow,+ focusStorageGrowthPool,focusedSummaryStorageGroupScope: focusedStorageGroupScope,focusedSummaryStorageGroupId: selectedStorageGroupId,hoveredSummaryStorageGroupScope: hoveredStorageGroupScope,diff --git a/frontend-modern/src/features/storageBackups/__tests__/storageCapacityDeltaPresentation.test.ts b/frontend-modern/src/features/storageBackups/__tests__/storageCapacityDeltaPresentation.test.tsindex 44556f7ab8..5e24e1b5c2 100644--- a/frontend-modern/src/features/storageBackups/__tests__/storageCapacityDeltaPresentation.test.ts+++ b/frontend-modern/src/features/storageBackups/__tests__/storageCapacityDeltaPresentation.test.ts@@ -1,6 +1,7 @@import { describe, expect, it } from 'vitest';import {buildStorageCapacityDeltaPresentation,+ computeStorageCapacityDeltaAnalysis,computeStorageCapacityDelta,formatStorageCapacityDelta,getStorageCapacityDeltaToneClass,@@ -18,6 +19,22 @@ describe('storageCapacityDeltaPresentation', () => {expect(delta).toBe(40);});+ it('exposes the smoothed observation window for runway estimates', () => {+ expect(+ computeStorageCapacityDeltaAnalysis([+ { timestamp: 1_000, value: 100 },+ { timestamp: 2_000, value: 110 },+ { timestamp: 3_000, value: 140 },+ { timestamp: 4_000, value: 150 },+ ]),+ ).toEqual({+ deltaBytes: 40,+ durationMs: 2_000,+ startTimestamp: 1_500,+ endTimestamp: 3_500,+ });+ });+it('formats increase, decrease, and neutral deltas canonically', () => {expect(formatStorageCapacityDelta(2048)).toBe('+2.00 KB');expect(formatStorageCapacityDelta(-2048)).toBe('-2.00 KB');@@ -36,7 +53,15 @@ describe('storageCapacityDeltaPresentation', () => {title: 'No storage change history available for 24h.',toneClass: 'text-muted',});- expect(buildStorageCapacityDeltaPresentation([{ timestamp: 1, value: 100 }, { timestamp: 2, value: 100 }], '24h')).toEqual({+ expect(+ buildStorageCapacityDeltaPresentation(+ [+ { timestamp: 1, value: 100 },+ { timestamp: 2, value: 100 },+ ],+ '24h',+ ),+ ).toEqual({deltaBytes: 0,label: '0 B',title: 'No used-capacity change over 24h.',diff --git a/frontend-modern/src/features/storageBackups/__tests__/storageGrowthPlannerPresentation.test.ts b/frontend-modern/src/features/storageBackups/__tests__/storageGrowthPlannerPresentation.test.tsnew file mode 100644index 0000000000..d57ce60d83--- /dev/null+++ b/frontend-modern/src/features/storageBackups/__tests__/storageGrowthPlannerPresentation.test.ts@@ -0,0 +1,145 @@+import { describe, expect, it } from 'vitest';+import type { StorageRecord } from '@/features/storageBackups/models';+import { buildStorageGrowthPlannerPresentation } from '@/features/storageBackups/storageGrowthPlannerPresentation';++const GB = 1024 * 1024 * 1024;++const buildRecord = (+ id: string,+ name: string,+ capacity: StorageRecord['capacity'],+): StorageRecord => ({+ id,+ name,+ category: 'pool',+ health: 'healthy',+ hostLabel: 'pve1',+ location: { label: 'pve1', scope: 'node' },+ capacity,+ capabilities: ['capacity'],+ source: {+ platform: 'proxmox-pve',+ family: 'virtualization',+ origin: 'resource',+ adapterId: 'test',+ },+ observedAt: 0,+ metricsTarget: {+ resourceType: 'storage',+ resourceId: `pool:${id}`,+ },+ refs: {},+ details: {},+});++describe('storageGrowthPlannerPresentation', () => {+ it('ranks pools by runway using selected-range used history and current capacity', () => {+ const planner = buildStorageGrowthPlannerPresentation({+ rangeLabel: '24h',+ records: [+ buildRecord('alpha', 'Alpha Pool', {+ totalBytes: 250 * GB,+ usedBytes: 140 * GB,+ freeBytes: 110 * GB,+ usagePercent: 56,+ }),+ buildRecord('beta', 'Beta Pool', {+ totalBytes: 300 * GB,+ usedBytes: 276 * GB,+ freeBytes: 24 * GB,+ usagePercent: 92,+ }),+ buildRecord('gamma', 'Gamma Pool', {+ totalBytes: 200 * GB,+ usedBytes: 80 * GB,+ freeBytes: 120 * GB,+ usagePercent: 40,+ }),+ ],+ pools: {+ 'pool:alpha': {+ name: 'Alpha Pool',+ usage: [],+ used: [+ { timestamp: 1, value: 100 * GB },+ { timestamp: 86_400_001, value: 140 * GB },+ ],+ avail: [+ { timestamp: 1, value: 150 * GB },+ { timestamp: 86_400_001, value: 110 * GB },+ ],+ },+ 'pool:beta': {+ name: 'Beta Pool',+ usage: [],+ used: [+ { timestamp: 1, value: 276 * GB },+ { timestamp: 86_400_001, value: 276 * GB },+ ],+ avail: [+ { timestamp: 1, value: 24 * GB },+ { timestamp: 86_400_001, value: 24 * GB },+ ],+ },+ 'pool:gamma': {+ name: 'Gamma Pool',+ usage: [],+ used: [+ { timestamp: 1, value: 90 * GB },+ { timestamp: 86_400_001, value: 80 * GB },+ ],+ avail: [+ { timestamp: 1, value: 110 * GB },+ { timestamp: 86_400_001, value: 120 * GB },+ ],+ },+ },+ });++ expect(planner.rangeLabel).toBe('24h');+ expect(planner.trackedPoolCount).toBe(3);+ expect(planner.growingPoolCount).toBe(1);+ expect(planner.topPools.map((pool) => pool.name)).toEqual(['Alpha Pool', 'Beta Pool']);+ expect(planner.topPools[0]).toMatchObject({+ growthLabel: '+40.0 GB',+ runwayLabel: '3 days',+ priorityLabel: 'Plan now',+ });+ expect(planner.topPools[1]).toMatchObject({+ growthLabel: '0 B',+ runwayLabel: 'Unknown',+ priorityLabel: 'Plan now',+ });+ });++ it('returns an empty state when scoped pools are stable', () => {+ const planner = buildStorageGrowthPlannerPresentation({+ rangeLabel: '7d',+ records: [+ buildRecord('stable', 'Stable Pool', {+ totalBytes: 100 * GB,+ usedBytes: 20 * GB,+ freeBytes: 80 * GB,+ usagePercent: 20,+ }),+ ],+ pools: {+ 'pool:stable': {+ name: 'Stable Pool',+ usage: [],+ used: [+ { timestamp: 1, value: 30 * GB },+ { timestamp: 604_800_001, value: 20 * GB },+ ],+ avail: [+ { timestamp: 1, value: 70 * GB },+ { timestamp: 604_800_001, value: 80 * GB },+ ],+ },+ },+ });++ expect(planner.topPools).toEqual([]);+ expect(planner.emptyTitle).toBe('No capacity planning pressure over 7d');+ });+});diff --git a/frontend-modern/src/features/storageBackups/storageCapacityDeltaPresentation.ts b/frontend-modern/src/features/storageBackups/storageCapacityDeltaPresentation.tsindex 2a8c8e6f64..c5fed3ba44 100644--- a/frontend-modern/src/features/storageBackups/storageCapacityDeltaPresentation.ts+++ b/frontend-modern/src/features/storageBackups/storageCapacityDeltaPresentation.ts@@ -8,11 +8,16 @@ export interface StorageCapacityDeltaPresentation {toneClass: string;}+export interface StorageCapacityDeltaAnalysis {+ deltaBytes: number;+ durationMs: number;+ startTimestamp: number;+ endTimestamp: number;+}+function normalizeMetricPoints(points: MetricPoint[]): MetricPoint[] {return points- .filter(- (point) => Number.isFinite(point.timestamp) && Number.isFinite(point.value),- )+ .filter((point) => Number.isFinite(point.timestamp) && Number.isFinite(point.value)).sort((left, right) => left.timestamp - right.timestamp);}@@ -23,26 +28,44 @@ function averageMetricValues(points: MetricPoint[]): number {return points.reduce((sum, point) => sum + point.value, 0) / points.length;}-export function computeStorageCapacityDelta(points: MetricPoint[]): number | null {+function averageMetricTimestamps(points: MetricPoint[]): number {+ if (points.length === 0) {+ return 0;+ }+ return points.reduce((sum, point) => sum + point.timestamp, 0) / points.length;+}++export function computeStorageCapacityDeltaAnalysis(+ points: MetricPoint[],+): StorageCapacityDeltaAnalysis | null {const normalized = normalizeMetricPoints(points);if (normalized.length < 2) {return null;}const sampleWindowSize =- normalized.length >= 4- ? Math.max(2, Math.floor(normalized.length * 0.25))- : 1;- const startAverage = averageMetricValues(normalized.slice(0, sampleWindowSize));- const endAverage = averageMetricValues(normalized.slice(normalized.length - sampleWindowSize));+ normalized.length >= 4 ? Math.max(2, Math.floor(normalized.length * 0.25)) : 1;+ const startWindow = normalized.slice(0, sampleWindowSize);+ const endWindow = normalized.slice(normalized.length - sampleWindowSize);+ const startAverage = averageMetricValues(startWindow);+ const endAverage = averageMetricValues(endWindow);+ const startTimestamp = averageMetricTimestamps(startWindow);+ const endTimestamp = averageMetricTimestamps(endWindow);+ const durationMs = endTimestamp - startTimestamp;const delta = endAverage - startAverage;- if (!Number.isFinite(delta)) {+ if (!Number.isFinite(delta) || !Number.isFinite(durationMs) || durationMs <= 0) {return null;}- if (Math.abs(delta) < 1) {- return 0;- }- return delta;+ return {+ deltaBytes: Math.abs(delta) < 1 ? 0 : delta,+ durationMs,+ startTimestamp,+ endTimestamp,+ };+}++export function computeStorageCapacityDelta(points: MetricPoint[]): number | null {+ return computeStorageCapacityDeltaAnalysis(points)?.deltaBytes ?? null;}export function formatStorageCapacityDelta(deltaBytes: number | null): string {diff --git a/frontend-modern/src/features/storageBackups/storageGrowthPlannerPresentation.ts b/frontend-modern/src/features/storageBackups/storageGrowthPlannerPresentation.tsnew file mode 100644index 0000000000..86453bbe13--- /dev/null+++ b/frontend-modern/src/features/storageBackups/storageGrowthPlannerPresentation.ts@@ -0,0 +1,274 @@+import type { MetricPoint, StoragePoolChartData } from '@/api/charts';+import { formatBytes, formatPercent } from '@/utils/format';+import type { StorageRecord } from './models';+import {+ buildStorageCapacityDeltaPresentation,+ computeStorageCapacityDeltaAnalysis,+} from './storageCapacityDeltaPresentation';+import { getStorageRecordHostLabel } from './recordPresentation';+import { resolveStorageRecordMetricResourceId } from './storageMetricsIdentity';++const DAY_MS = 24 * 60 * 60 * 1000;+const TOP_POOL_LIMIT = 3;++export type StorageGrowthPlannerPriority = 'critical' | 'warning' | 'watch' | 'stable' | 'unknown';++export interface StorageGrowthPlannerPool {+ recordId: string;+ seriesId: string;+ name: string;+ hostLabel: string;+ usageLabel: string;+ freeLabel: string;+ growthDeltaBytes: number | null;+ growthLabel: string;+ growthTitle: string;+ growthToneClass: string;+ runwayDays: number | null;+ runwayLabel: string;+ runwayTitle: string;+ priority: StorageGrowthPlannerPriority;+ priorityLabel: string;+ priorityToneClass: string;+}++export interface StorageGrowthPlannerPresentation {+ rangeLabel: string;+ trackedPoolCount: number;+ growingPoolCount: number;+ planningPools: StorageGrowthPlannerPool[];+ topPools: StorageGrowthPlannerPool[];+ emptyTitle: string;+ emptyMessage: string;+}++function asFiniteNonNegative(value: number | null | undefined): number | null {+ if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {+ return null;+ }+ return value;+}++function getLatestMetricValue(points: MetricPoint[] | undefined): number | null {+ if (!points) {+ return null;+ }+ let latest: MetricPoint | null = null;+ for (const point of points) {+ if (!Number.isFinite(point.timestamp) || !Number.isFinite(point.value)) {+ continue;+ }+ if (!latest || point.timestamp > latest.timestamp) {+ latest = point;+ }+ }+ return asFiniteNonNegative(latest?.value);+}++function formatRunwayDays(runwayDays: number | null): string {+ if (runwayDays === null) {+ return 'Unknown';+ }+ if (runwayDays <= 0) {+ return 'Full now';+ }+ if (runwayDays < 1) {+ return '<1 day';+ }+ if (runwayDays < 90) {+ const days = Math.max(1, Math.round(runwayDays));+ return `${days} ${days === 1 ? 'day' : 'days'}`;+ }+ const months = Math.max(3, Math.round(runwayDays / 30));+ if (months < 24) {+ return `${months} mo`;+ }+ const years = Math.round(months / 12);+ return `${years} yr`;+}++function getPriority(+ usagePercent: number | null,+ growthDeltaBytes: number | null,+ runwayDays: number | null,+): StorageGrowthPlannerPriority {+ if (runwayDays !== null) {+ if (runwayDays <= 30) return 'critical';+ if (runwayDays <= 90) return 'warning';+ return 'watch';+ }+ if ((usagePercent ?? 0) >= 90) {+ return 'critical';+ }+ if ((usagePercent ?? 0) >= 80) {+ return 'warning';+ }+ if ((growthDeltaBytes ?? 0) > 0) {+ return 'unknown';+ }+ return 'stable';+}++function getPriorityLabel(priority: StorageGrowthPlannerPriority): string {+ switch (priority) {+ case 'critical':+ return 'Plan now';+ case 'warning':+ return 'Plan soon';+ case 'watch':+ return 'Watch';+ case 'unknown':+ return 'Needs trend';+ case 'stable':+ return 'Stable';+ }+}++function getPriorityToneClass(priority: StorageGrowthPlannerPriority): string {+ switch (priority) {+ case 'critical':+ return 'border-red-200 bg-red-50 text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300';+ case 'warning':+ return 'border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-900/60 dark:bg-amber-950/30 dark:text-amber-300';+ case 'watch':+ return 'border-sky-200 bg-sky-50 text-sky-700 dark:border-sky-900/60 dark:bg-sky-950/30 dark:text-sky-300';+ case 'unknown':+ return 'border-border bg-surface-alt text-muted';+ case 'stable':+ return 'border-emerald-200 bg-emerald-50 text-emerald-700 dark:border-emerald-900/60 dark:bg-emerald-950/30 dark:text-emerald-300';+ }+}++function buildRunwayTitle(+ poolName: string,+ runwayDays: number | null,+ growthDeltaBytes: number | null,+ rangeLabel: string,+): string {+ if ((growthDeltaBytes ?? 0) <= 0) {+ return `${poolName} is not growing over ${rangeLabel}.`;+ }+ if (runwayDays === null) {+ return `${poolName} needs more capacity data before runway can be estimated.`;+ }+ return `${poolName} reaches full capacity in about ${formatRunwayDays(runwayDays)} at the ${rangeLabel} growth rate.`;+}++function buildPoolPresentation(+ record: StorageRecord,+ chartData: StoragePoolChartData | undefined,+ rangeLabel: string,+): StorageGrowthPlannerPool {+ const seriesId = resolveStorageRecordMetricResourceId(record);+ const totalBytes = asFiniteNonNegative(record.capacity.totalBytes);+ const usedBytes = asFiniteNonNegative(record.capacity.usedBytes);+ const latestAvailBytes = getLatestMetricValue(chartData?.avail);+ const freeBytes =+ asFiniteNonNegative(record.capacity.freeBytes) ??+ (totalBytes !== null && usedBytes !== null ? Math.max(totalBytes - usedBytes, 0) : null) ??+ latestAvailBytes;+ const effectiveTotalBytes =+ totalBytes ??+ (usedBytes !== null && freeBytes !== null ? Math.max(usedBytes + freeBytes, 0) : null);+ const usagePercent =+ typeof record.capacity.usagePercent === 'number' &&+ Number.isFinite(record.capacity.usagePercent)+ ? record.capacity.usagePercent+ : effectiveTotalBytes && usedBytes !== null+ ? (usedBytes / effectiveTotalBytes) * 100+ : null;+ const deltaPresentation = buildStorageCapacityDeltaPresentation(+ chartData?.used ?? [],+ rangeLabel,+ );+ const deltaAnalysis = computeStorageCapacityDeltaAnalysis(chartData?.used ?? []);+ const growthRatePerMs =+ deltaAnalysis && deltaAnalysis.deltaBytes > 0+ ? deltaAnalysis.deltaBytes / deltaAnalysis.durationMs+ : null;+ const runwayDays =+ growthRatePerMs && freeBytes !== null+ ? Math.max(0, freeBytes / growthRatePerMs / DAY_MS)+ : null;+ const priority = getPriority(usagePercent, deltaPresentation.deltaBytes, runwayDays);++ return {+ recordId: record.id,+ seriesId,+ name: record.name,+ hostLabel: getStorageRecordHostLabel(record),+ usageLabel: usagePercent === null ? 'Usage n/a' : `${formatPercent(usagePercent)} used`,+ freeLabel: freeBytes === null ? 'Free n/a' : `${formatBytes(freeBytes)} free`,+ growthDeltaBytes: deltaPresentation.deltaBytes,+ growthLabel: deltaPresentation.label,+ growthTitle: deltaPresentation.title,+ growthToneClass: deltaPresentation.toneClass,+ runwayDays,+ runwayLabel: formatRunwayDays(runwayDays),+ runwayTitle: buildRunwayTitle(+ record.name,+ runwayDays,+ deltaPresentation.deltaBytes,+ rangeLabel,+ ),+ priority,+ priorityLabel: getPriorityLabel(priority),+ priorityToneClass: getPriorityToneClass(priority),+ };+}++function comparePlanningPools(+ left: StorageGrowthPlannerPool,+ right: StorageGrowthPlannerPool,+): number {+ const priorityRank: Record<StorageGrowthPlannerPriority, number> = {+ critical: 0,+ warning: 1,+ watch: 2,+ unknown: 3,+ stable: 4,+ };+ const priorityDelta = priorityRank[left.priority] - priorityRank[right.priority];+ if (priorityDelta !== 0) {+ return priorityDelta;+ }+ const leftRunway = left.runwayDays ?? Number.POSITIVE_INFINITY;+ const rightRunway = right.runwayDays ?? Number.POSITIVE_INFINITY;+ if (leftRunway !== rightRunway) {+ return leftRunway - rightRunway;+ }+ return (right.growthDeltaBytes ?? 0) - (left.growthDeltaBytes ?? 0);+}++export function buildStorageGrowthPlannerPresentation(params: {+ records: StorageRecord[];+ pools: Record<string, StoragePoolChartData> | undefined;+ rangeLabel: string;+}): StorageGrowthPlannerPresentation {+ const planningPools = params.records+ .map((record) => {+ const seriesId = resolveStorageRecordMetricResourceId(record);+ return buildPoolPresentation(record, params.pools?.[seriesId], params.rangeLabel);+ })+ .sort(comparePlanningPools);+ const topPools = planningPools+ .filter((pool) => pool.priority !== 'stable')+ .slice(0, TOP_POOL_LIMIT);+ const growingPoolCount = planningPools.filter((pool) => (pool.growthDeltaBytes ?? 0) > 0).length;++ return {+ rangeLabel: params.rangeLabel,+ trackedPoolCount: planningPools.length,+ growingPoolCount,+ planningPools,+ topPools,+ emptyTitle:+ planningPools.length === 0+ ? 'No pools in scope'+ : `No capacity planning pressure over ${params.rangeLabel}`,+ emptyMessage:+ planningPools.length === 0+ ? 'Storage filters have removed every pool from the planner.'+ : 'Tracked pools are stable or shrinking for the selected range.',+ };+}