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
memory(cache): hold the used+cache+free invariant as mock metrics drift
rcourtman7d1ff3674a7d
diff --git a/frontend-modern/src/components/Workloads/stackedMemoryBarModel.ts b/frontend-modern/src/components/Workloads/stackedMemoryBarModel.tsindex 43ac5c2bc6..30ffa42949 100644--- a/frontend-modern/src/components/Workloads/stackedMemoryBarModel.ts+++ b/frontend-modern/src/components/Workloads/stackedMemoryBarModel.ts@@ -60,6 +60,15 @@ const MEMORY_COLORS = {swap: 'rgba(168, 85, 247, 0.6)',};+// Cache can never exceed the non-used pages; clamp so a momentarily+// inconsistent snapshot (used drifting past total - cache) cannot push the+// segments or the reconciliation row past 100%.+function getEffectiveCache(props: StackedMemoryBarProps): number {+ const cache = props.cache || 0;+ if (cache <= 0 || props.total <= 0) return 0;+ return Math.min(cache, Math.max(0, props.total - props.used));+}+function getUtilizationPercent(props: StackedMemoryBarProps): number {if (props.total > 0) {return (props.used / props.total) * 100;@@ -91,7 +100,7 @@ function getSegments(const balloon = props.balloon || 0;const hasActiveBallooning = balloon > 0 && balloon < props.total;const usedPercent = (props.used / props.total) * 100;- const cache = props.cache || 0;+ const cache = getEffectiveCache(props);const cachePercent = (cache / props.total) * 100;const segments: StackedMemorySegment[] = [];@@ -139,7 +148,7 @@ function getTooltipRows(): StackedMemoryTooltipRow[] {const rows: StackedMemoryTooltipRow[] = [];const balloon = props.balloon || 0;- const cache = props.cache || 0;+ const cache = getEffectiveCache(props);const hasActiveBallooning = props.total > 0 && balloon > 0 && balloon < props.total;const hasSwap = (props.swapTotal || 0) > 0;diff --git a/internal/mock/generator.go b/internal/mock/generator.goindex 56a7d4f78f..7c71076ef8 100644--- a/internal/mock/generator.go+++ b/internal/mock/generator.go@@ -4072,6 +4072,12 @@ func applyMemoryUsage(memory *models.Memory, usage float64) {if memory.Free < 0 {memory.Free = 0}+ // Keep the reclaimable-cache invariant (used + cache + free == total) as+ // the sampled usage drifts: cache can never exceed the non-used pages.+ if memory.Cache > memory.Free {+ memory.Cache = memory.Free+ }+ memory.Free -= memory.Cache}func applyDiskUsage(disk *models.Disk, usage float64) {