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
fix(memory): skip meminfo-derived when balloon lacks cache metrics (#1302)
rcourtman60bdc9a10106
diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.goindex 53065a65cf..19a393ac45 100644--- a/internal/monitoring/monitor.go+++ b/internal/monitoring/monitor.go@@ -6906,18 +6906,29 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNamguestRaw.MemInfoCached = detailedStatus.MemInfo.CachedguestRaw.MemInfoShared = detailedStatus.MemInfo.Shared+ // Derive memAvailable from balloon MemInfo. Prefer Available (most+ // accurate), then Free+Buffers+Cached when cache metrics are present.+ // When Buffers=0 AND Cached=0, the balloon isn't reporting cache+ // breakdown — using Free alone gives wildly inflated usage because+ // reclaimable page cache is counted as used. In that case, skip and+ // fall through to RRD/guest-agent fallbacks. Refs: #1302, #1270switch {case detailedStatus.MemInfo.Available > 0:memAvailable = detailedStatus.MemInfo.AvailablememorySource = "meminfo-available"- case detailedStatus.MemInfo.Free > 0 ||- detailedStatus.MemInfo.Buffers > 0 ||- detailedStatus.MemInfo.Cached > 0:+ case detailedStatus.MemInfo.Buffers > 0 || detailedStatus.MemInfo.Cached > 0:memAvailable = detailedStatus.MemInfo.Free +detailedStatus.MemInfo.Buffers +detailedStatus.MemInfo.CachedmemorySource = "meminfo-derived"}++ // Record Total-Used for diagnostics even when not used as the source+ if detailedStatus.MemInfo.Total > 0 &&+ detailedStatus.MemInfo.Used > 0 &&+ detailedStatus.MemInfo.Total >= detailedStatus.MemInfo.Used {+ guestRaw.MemInfoTotalMinusUsed = detailedStatus.MemInfo.Total - detailedStatus.MemInfo.Used+ }}// Use actual disk I/O values from detailed status@@ -7004,6 +7015,19 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam}}+ // Last-chance MemInfo fallback: when balloon reports Used/Total but no+ // cache breakdown (Buffers=Cached=0), use Total-Used. This may equal+ // Free (if Used=Total-Free) but is still better than status-mem which+ // can be even more inflated. Placed after RRD/agent so those get+ // priority. Refs: #1302, #1270+ if memAvailable == 0 && detailedStatus.MemInfo != nil &&+ detailedStatus.MemInfo.Total > 0 &&+ detailedStatus.MemInfo.Used > 0 &&+ detailedStatus.MemInfo.Total >= detailedStatus.MemInfo.Used {+ memAvailable = detailedStatus.MemInfo.Total - detailedStatus.MemInfo.Used+ memorySource = "meminfo-total-minus-used"+ }+switch {case memAvailable > 0:if memAvailable > memTotal {diff --git a/internal/monitoring/monitor_polling.go b/internal/monitoring/monitor_polling.goindex cb26f9c173..cb0d0e7a58 100644--- a/internal/monitoring/monitor_polling.go+++ b/internal/monitoring/monitor_polling.go@@ -311,57 +311,29 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, cluguestRaw.MemInfoBuffers = status.MemInfo.BuffersguestRaw.MemInfoCached = status.MemInfo.CachedguestRaw.MemInfoShared = status.MemInfo.Shared- componentAvailable := status.MemInfo.Free- if status.MemInfo.Buffers > 0 {- if math.MaxUint64-componentAvailable < status.MemInfo.Buffers {- componentAvailable = math.MaxUint64- } else {- componentAvailable += status.MemInfo.Buffers- }- }- if status.MemInfo.Cached > 0 {- if math.MaxUint64-componentAvailable < status.MemInfo.Cached {- componentAvailable = math.MaxUint64- } else {- componentAvailable += status.MemInfo.Cached- }- }- if status.MemInfo.Total > 0 && componentAvailable > status.MemInfo.Total {- componentAvailable = status.MemInfo.Total- }-- availableFromUsed := uint64(0)- if status.MemInfo.Total > 0 && status.MemInfo.Used > 0 && status.MemInfo.Total >= status.MemInfo.Used {- availableFromUsed = status.MemInfo.Total - status.MemInfo.Used- guestRaw.MemInfoTotalMinusUsed = availableFromUsed- }-- missingCacheMetrics := status.MemInfo.Available == 0 &&- status.MemInfo.Buffers == 0 &&- status.MemInfo.Cached == 0+ // Derive memAvailable from balloon MemInfo. Prefer Available (most+ // accurate), then Free+Buffers+Cached when cache metrics are present.+ // When Buffers=0 AND Cached=0, the balloon isn't reporting cache+ // breakdown — using Free alone gives wildly inflated usage because+ // reclaimable page cache is counted as used. In that case, skip and+ // fall through to RRD/guest-agent fallbacks. Refs: #1302, #1270switch {case status.MemInfo.Available > 0:memAvailable = status.MemInfo.AvailablememorySource = "meminfo-available"- case status.MemInfo.Free > 0 ||- status.MemInfo.Buffers > 0 ||- status.MemInfo.Cached > 0:+ case status.MemInfo.Buffers > 0 || status.MemInfo.Cached > 0:memAvailable = status.MemInfo.Free +status.MemInfo.Buffers +status.MemInfo.CachedmemorySource = "meminfo-derived"}- if memAvailable == 0 && availableFromUsed > 0 && missingCacheMetrics {- const vmTotalMinusUsedGapTolerance uint64 = 4 * 1024 * 1024- if availableFromUsed > componentAvailable {- gap := availableFromUsed - componentAvailable- if componentAvailable == 0 || gap >= vmTotalMinusUsedGapTolerance {- memAvailable = availableFromUsed- memorySource = "meminfo-total-minus-used"- }- }+ // Record Total-Used for diagnostics even when not used as the source+ if status.MemInfo.Total > 0 &&+ status.MemInfo.Used > 0 &&+ status.MemInfo.Total >= status.MemInfo.Used {+ guestRaw.MemInfoTotalMinusUsed = status.MemInfo.Total - status.MemInfo.Used}}// Note: We intentionally do NOT override memTotal with balloon.@@ -428,6 +400,19 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, clu}}+ // Last-chance MemInfo fallback: when balloon reports Used/Total but no+ // cache breakdown (Buffers=Cached=0), use Total-Used. This may equal+ // Free (if Used=Total-Free) but is still better than status-mem which+ // can be even more inflated. Placed after RRD/agent so those get+ // priority. Refs: #1302, #1270+ if memAvailable == 0 && status.MemInfo != nil &&+ status.MemInfo.Total > 0 &&+ status.MemInfo.Used > 0 &&+ status.MemInfo.Total >= status.MemInfo.Used {+ memAvailable = status.MemInfo.Total - status.MemInfo.Used+ memorySource = "meminfo-total-minus-used"+ }+switch {case memAvailable > 0:if memAvailable > memTotal {