Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

fix(memory): use linked Pulse host agent memory to avoid VM inflation (#1270)

rcourtmanfb7582c7e4fe
diff --git a/internal/monitoring/diagnostic_snapshots.go b/internal/monitoring/diagnostic_snapshots.go
index db8a937073..1ed9a9279c 100644
--- a/internal/monitoring/diagnostic_snapshots.go
+++ b/internal/monitoring/diagnostic_snapshots.go
@@ -62,6 +62,8 @@ type VMMemoryRaw struct {
MemInfoTotalMinusUsed uint64 `json:"meminfoTotalMinusUsed,omitempty"`
Agent int `json:"agent,omitempty"`
DerivedFromBall bool `json:"derivedFromBalloon,omitempty"`
+ HostAgentTotal uint64 `json:"hostAgentTotal,omitempty"`
+ HostAgentUsed uint64 `json:"hostAgentUsed,omitempty"`
}
// GuestMemorySnapshot records the memory calculation for a guest (VM/LXC).
diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go
index cd90ff7ee6..e1b2b3a34b 100644
--- a/internal/monitoring/monitor.go
+++ b/internal/monitoring/monitor.go
@@ -6707,6 +6707,17 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam
}
}
+ // Build a lookup map from VM guest ID → linked host agent.
+ // When a Pulse agent runs inside a VM, it reads /proc/meminfo directly
+ // and gets accurate MemAvailable (excluding page cache). We use this as
+ // a memory fallback before the inflated status.Mem value. Refs: #1270
+ vmIDToHostAgent := make(map[string]models.Host)
+ for _, h := range prevState.Hosts {
+ if h.LinkedVMID != "" && h.Status == "online" && h.Memory.Total > 0 {
+ vmIDToHostAgent[h.LinkedVMID] = h
+ }
+ }
+
var allVMs []models.VM
var allContainers []models.Container
@@ -6845,6 +6856,30 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam
}
}
+ // Fallback: use linked Pulse host agent's memory data.
+ // gopsutil's Used = Total - Available (excludes page cache),
+ // so we can derive accurate available memory. Refs: #1270
+ if memAvailable == 0 {
+ if agentHost, ok := vmIDToHostAgent[guestID]; ok {
+ agentAvailable := agentHost.Memory.Total - agentHost.Memory.Used
+ if agentAvailable > 0 {
+ memAvailable = uint64(agentAvailable)
+ memorySource = "host-agent"
+ guestRaw.HostAgentTotal = uint64(agentHost.Memory.Total)
+ guestRaw.HostAgentUsed = uint64(agentHost.Memory.Used)
+ log.Debug().
+ Str("vm", res.Name).
+ Str("node", res.Node).
+ Int("vmid", res.VMID).
+ Uint64("total", memTotal).
+ Uint64("available", memAvailable).
+ Int64("agentTotal", agentHost.Memory.Total).
+ Int64("agentUsed", agentHost.Memory.Used).
+ Msg("QEMU memory: using linked Pulse host agent memory (excludes page cache)")
+ }
+ }
+ }
+
switch {
case memAvailable > 0:
if memAvailable > memTotal {
diff --git a/internal/monitoring/monitor_polling.go b/internal/monitoring/monitor_polling.go
index 8eac60ba2c..06bbf119fd 100644
--- a/internal/monitoring/monitor_polling.go
+++ b/internal/monitoring/monitor_polling.go
@@ -214,6 +214,18 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, clu
Int("onlineNodes", onlineNodes).
Msg("Starting parallel VM polling")
+ // Build a lookup map from VM guest ID → linked host agent.
+ // When a Pulse agent runs inside a VM, it reads /proc/meminfo directly
+ // and gets accurate MemAvailable (excluding page cache). We use this as
+ // a memory fallback before the inflated status.Mem value. Refs: #1270
+ prevState := m.GetState()
+ vmIDToHostAgent := make(map[string]models.Host)
+ for _, h := range prevState.Hosts {
+ if h.LinkedVMID != "" && h.Status == "online" && h.Memory.Total > 0 {
+ vmIDToHostAgent[h.LinkedVMID] = h
+ }
+ }
+
// Launch a goroutine for each online node
for _, node := range nodes {
// Skip offline nodes
@@ -358,6 +370,31 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, clu
// confusion (showing 1GB/1GB at 100% when VM is configured for 4GB)
// and makes the frontend's balloon marker logic ineffective.
// Refs: #1070
+
+ // Fallback: use linked Pulse host agent's memory data.
+ // gopsutil's Used = Total - Available (excludes page cache),
+ // so we can derive accurate available memory. Refs: #1270
+ if memAvailable == 0 {
+ if agentHost, ok := vmIDToHostAgent[guestID]; ok {
+ agentAvailable := agentHost.Memory.Total - agentHost.Memory.Used
+ if agentAvailable > 0 {
+ memAvailable = uint64(agentAvailable)
+ memorySource = "host-agent"
+ guestRaw.HostAgentTotal = uint64(agentHost.Memory.Total)
+ guestRaw.HostAgentUsed = uint64(agentHost.Memory.Used)
+ log.Debug().
+ Str("vm", vm.Name).
+ Str("node", n.Node).
+ Int("vmid", vm.VMID).
+ Uint64("total", memTotal).
+ Uint64("available", memAvailable).
+ Int64("agentTotal", agentHost.Memory.Total).
+ Int64("agentUsed", agentHost.Memory.Used).
+ Msg("QEMU memory: using linked Pulse host agent memory (excludes page cache)")
+ }
+ }
+ }
+
switch {
case memAvailable > 0:
if memAvailable > memTotal {