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.

Promote guest-agent /proc/meminfo fallback for accurate VM memory (#1270)

rcourtman572520ebc677
diff --git a/install.sh b/install.sh
index 2e04a65209..f80001965d 100755
--- a/install.sh
+++ b/install.sh
@@ -1690,14 +1690,28 @@ PY
pveum role delete PulseGuestAuditProbe >/dev/null 2>&1 || true
fi
+ # VM.GuestAgent.FileRead (PVE 9+): needed for reading /proc/meminfo
+ # via the guest agent for accurate memory reporting
+ local has_guest_file_read=false
+ if pveum role list 2>/dev/null | grep -q "VM.GuestAgent.FileRead"; then
+ has_guest_file_read=true
+ elif pveum role add PulseGuestFileReadProbe -privs VM.GuestAgent.FileRead >/dev/null 2>&1; then
+ has_guest_file_read=true
+ pveum role delete PulseGuestFileReadProbe >/dev/null 2>&1 || true
+ fi
+
if [[ "$has_vm_monitor" == true ]]; then
extra_privs+=("VM.Monitor")
elif [[ "$has_guest_audit" == true ]]; then
extra_privs+=("VM.GuestAgent.Audit")
+ if [[ "$has_guest_file_read" == true ]]; then
+ extra_privs+=("VM.GuestAgent.FileRead")
+ fi
fi
if [[ ${#extra_privs[@]} -gt 0 ]]; then
- local priv_string="${extra_privs[*]}"
+ local priv_string
+ priv_string="$(IFS=,; echo "${extra_privs[*]}")"
pveum role delete PulseMonitor >/dev/null 2>&1 || true
if pveum role add PulseMonitor -privs "$priv_string" >/dev/null 2>&1; then
pveum aclmod / -user pulse-monitor@pam -role PulseMonitor >/dev/null 2>&1 || true
diff --git a/internal/api/config_handlers.go b/internal/api/config_handlers.go
index f7c8871bac..6a30af193d 100644
--- a/internal/api/config_handlers.go
+++ b/internal/api/config_handlers.go
@@ -4464,6 +4464,18 @@ else
fi
fi
+# VM.GuestAgent.FileRead (PVE 9+): needed for reading /proc/meminfo
+# via the guest agent for accurate memory reporting
+HAS_VM_GUEST_AGENT_FILE_READ=false
+if pveum role list 2>/dev/null | grep -q "VM.GuestAgent.FileRead"; then
+ HAS_VM_GUEST_AGENT_FILE_READ=true
+else
+ if pveum role add TestGuestAgentFileRead -privs VM.GuestAgent.FileRead 2>/dev/null; then
+ HAS_VM_GUEST_AGENT_FILE_READ=true
+ pveum role delete TestGuestAgentFileRead 2>/dev/null || true
+ fi
+fi
+
# Detect availability of Sys.Audit (needed for Ceph metrics)
HAS_SYS_AUDIT=false
if pveum role list 2>/dev/null | grep -q "Sys.Audit"; then
@@ -4494,6 +4506,9 @@ if [ "$HAS_VM_MONITOR" = true ]; then
elif [ "$HAS_VM_GUEST_AGENT_AUDIT" = true ]; then
# PVE 9+ - VM.Monitor removed, prefer VM.GuestAgent.Audit for guest data
EXTRA_PRIVS+=("VM.GuestAgent.Audit")
+ if [ "$HAS_VM_GUEST_AGENT_FILE_READ" = true ]; then
+ EXTRA_PRIVS+=("VM.GuestAgent.FileRead")
+ fi
fi
if [ ${#EXTRA_PRIVS[@]} -gt 0 ]; then
diff --git a/internal/api/diagnostics.go b/internal/api/diagnostics.go
index 4faf65a88e..f577de49b0 100644
--- a/internal/api/diagnostics.go
+++ b/internal/api/diagnostics.go
@@ -1317,7 +1317,7 @@ func (r *Router) checkVMDiskMonitoring(ctx context.Context, client *proxmox.Clie
} else if strings.Contains(errStr, "403") || strings.Contains(errStr, "401") {
result.Recommendations = append(result.Recommendations,
"Ensure API token has PVEAuditor role for baseline access",
- "Add VM.GuestAgent.Audit (PVE 9) or VM.Monitor (PVE 8) privileges; Pulse setup adds these via the PulseMonitor role",
+ "Add VM.GuestAgent.Audit+VM.GuestAgent.FileRead (PVE 9) or VM.Monitor (PVE 8) privileges; Pulse setup adds these via the PulseMonitor role",
"Include Sys.Audit when available for Ceph metrics",
)
} else {
@@ -1347,7 +1347,7 @@ func (r *Router) checkVMDiskMonitoring(ctx context.Context, client *proxmox.Clie
result.TestResult = "Permission denied accessing guest agent"
result.Recommendations = append(result.Recommendations,
"Ensure API token has PVEAuditor role for baseline access",
- "Add VM.GuestAgent.Audit (PVE 9) or VM.Monitor (PVE 8) privileges; Pulse setup adds these via the PulseMonitor role",
+ "Add VM.GuestAgent.Audit+VM.GuestAgent.FileRead (PVE 9) or VM.Monitor (PVE 8) privileges; Pulse setup adds these via the PulseMonitor role",
"Include Sys.Audit when available for Ceph metrics")
} else if errors.Is(err, context.DeadlineExceeded) || strings.Contains(errStr, "context deadline exceeded") {
result.TestResult = "Guest agent request timed out"
diff --git a/internal/hostagent/proxmox_setup.go b/internal/hostagent/proxmox_setup.go
index cca1b31884..81264935bc 100644
--- a/internal/hostagent/proxmox_setup.go
+++ b/internal/hostagent/proxmox_setup.go
@@ -179,7 +179,7 @@ func (p *ProxmoxSetup) configurePVEPermissions(ctx context.Context) {
// Extra privileges are optional, but enable additional features:
// - Sys.Audit: required for pending apt updates + some cluster/ceph visibility
- // - VM.Monitor (PVE 8) or VM.GuestAgent.Audit (PVE 9+): guest agent data
+ // - VM.Monitor (PVE 8) or VM.GuestAgent.Audit+VM.GuestAgent.FileRead (PVE 9+): guest agent data
// - Datastore.Audit: improved storage visibility
var extraPrivs []string
@@ -191,6 +191,11 @@ func (p *ProxmoxSetup) configurePVEPermissions(ctx context.Context) {
extraPrivs = append(extraPrivs, "VM.Monitor")
} else if p.probePVEPrivilege(ctx, "VM.GuestAgent.Audit") {
extraPrivs = append(extraPrivs, "VM.GuestAgent.Audit")
+ // VM.GuestAgent.FileRead is needed for reading /proc/meminfo via the
+ // guest agent file-read endpoint (accurate memory excluding buff/cache).
+ if p.probePVEPrivilege(ctx, "VM.GuestAgent.FileRead") {
+ extraPrivs = append(extraPrivs, "VM.GuestAgent.FileRead")
+ }
}
if p.probePVEPrivilege(ctx, "Datastore.Audit") {
diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go
index b8df159feb..06ce234713 100644
--- a/internal/monitoring/monitor.go
+++ b/internal/monitoring/monitor.go
@@ -7240,8 +7240,30 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam
}
}
- // Fallback for Linux VMs when the guest agent doesn't provide MemInfo.Available:
- // try Proxmox RRD memory first, even if detailed status was unavailable.
+ // Preferred fallback: read /proc/meminfo directly via the QEMU guest
+ // agent's file-read endpoint. This gives real-time MemAvailable which
+ // correctly excludes reclaimable buff/cache. Results are cached (60s
+ // positive, 5min negative) so this is cheap after the first call.
+ // Refs: #1270
+ if res.Status == "running" && agentEnabled && memAvailable == 0 {
+ m.runGuestAgentVMWork(ctx, instanceName, res.Node, res.Name, res.VMID, func(agentCtx context.Context) {
+ if agentAvail, agentErr := m.getVMAgentMemAvailable(agentCtx, client, instanceName, res.Node, res.VMID); agentErr == nil && agentAvail > 0 {
+ memAvailable = agentAvail
+ memorySource = "guest-agent-meminfo"
+ guestRaw.MemInfoAvailable = memAvailable
+ log.Debug().
+ Str("vm", res.Name).
+ Str("node", res.Node).
+ Int("vmid", res.VMID).
+ Uint64("total", memTotal).
+ Uint64("available", memAvailable).
+ Msg("QEMU memory: using guest agent /proc/meminfo (excludes reclaimable cache)")
+ }
+ })
+ }
+
+ // Fallback for Linux VMs when the guest agent doesn't provide MemInfo.Available
+ // and the direct file-read didn't work: try Proxmox RRD memory.
if res.Status == "running" && memAvailable == 0 {
if rrdEntry, rrdErr := m.getVMRRDMetrics(ctx, client, instanceName, res.Node, res.VMID); rrdErr == nil {
if rrdEntry.total > 0 {
@@ -7356,7 +7378,7 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam
log.Info().
Str("instance", instanceName).
Str("vm", res.Name).
- Msg("• Proxmox 9: Ensure token/user has VM.GuestAgent.Audit privilege (Pulse setup adds this via PulseMonitor role)")
+ Msg("• Proxmox 9: Ensure token/user has VM.GuestAgent.Audit+VM.GuestAgent.FileRead privileges (Pulse setup adds these via PulseMonitor role)")
log.Info().
Str("instance", instanceName).
Str("vm", res.Name).
@@ -7596,25 +7618,6 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam
}
}
- // Last-resort fallback before status-mem: read /proc/meminfo via the
- // QEMU guest agent's file-read endpoint. This works for Linux VMs with
- // the guest agent running even when the balloon driver doesn't populate
- // the meminfo fields. Results are cached with negative backoff. Refs: #1270
- if memAvailable == 0 {
- if agentAvail, agentErr := m.getVMAgentMemAvailable(agentCtx, client, instanceName, res.Node, res.VMID); agentErr == nil && agentAvail > 0 {
- memAvailable = agentAvail
- memorySource = "guest-agent-meminfo"
- guestRaw.MemInfoAvailable = memAvailable
- log.Debug().
- Str("vm", res.Name).
- Str("node", res.Node).
- Int("vmid", res.VMID).
- Uint64("total", memTotal).
- Uint64("available", memAvailable).
- Msg("QEMU memory: using guest agent /proc/meminfo fallback (excludes reclaimable cache)")
- }
- }
-
guestIPs, guestIfaces, guestOSName, guestOSVersion, guestAgentVersion := m.fetchGuestAgentMetadata(agentCtx, client, instanceName, res.Node, res.Name, res.VMID, detailedStatus)
if len(guestIPs) > 0 {
ipAddresses = guestIPs
diff --git a/internal/monitoring/monitor_polling.go b/internal/monitoring/monitor_polling.go
index 65b770b99c..1a540c0bc0 100644
--- a/internal/monitoring/monitor_polling.go
+++ b/internal/monitoring/monitor_polling.go
@@ -340,6 +340,30 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, clu
cancel()
}
+ // Preferred fallback: read /proc/meminfo directly via the QEMU guest
+ // agent's file-read endpoint. This gives real-time MemAvailable which
+ // correctly excludes reclaimable buff/cache. Results are cached (60s
+ // positive, 5min negative) so this is cheap after the first call.
+ // Refs: #1270
+ if vm.Status == "running" && agentEnabled && memAvailable == 0 {
+ m.runGuestAgentVMWork(ctx, instanceName, n.Node, vm.Name, vm.VMID, func(agentCtx context.Context) {
+ if agentAvail, agentErr := m.getVMAgentMemAvailable(agentCtx, client, instanceName, n.Node, vm.VMID); agentErr == nil && agentAvail > 0 {
+ memAvailable = agentAvail
+ memorySource = "guest-agent-meminfo"
+ guestRaw.MemInfoAvailable = memAvailable
+ log.Debug().
+ Str("vm", vm.Name).
+ Str("node", n.Node).
+ Int("vmid", vm.VMID).
+ Uint64("total", memTotal).
+ Uint64("available", memAvailable).
+ Msg("QEMU memory: using guest agent /proc/meminfo (excludes reclaimable cache)")
+ }
+ })
+ }
+
+ // Fallback: try Proxmox RRD memory when guest agent file-read
+ // didn't work or isn't available.
if vm.Status == "running" && memAvailable == 0 {
if rrdEntry, rrdErr := m.getVMRRDMetrics(ctx, client, instanceName, n.Node, vm.VMID); rrdErr == nil {
if rrdEntry.total > 0 {
@@ -393,23 +417,6 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, clu
}
}
- if vm.Status == "running" && memAvailable == 0 && agentEnabled {
- m.runGuestAgentVMWork(ctx, instanceName, n.Node, vm.Name, vm.VMID, func(agentCtx context.Context) {
- if agentAvail, agentErr := m.getVMAgentMemAvailable(agentCtx, client, instanceName, n.Node, vm.VMID); agentErr == nil && agentAvail > 0 {
- memAvailable = agentAvail
- memorySource = "guest-agent-meminfo"
- guestRaw.MemInfoAvailable = memAvailable
- log.Debug().
- Str("vm", vm.Name).
- Str("node", n.Node).
- Int("vmid", vm.VMID).
- Uint64("total", memTotal).
- Uint64("available", memAvailable).
- Msg("QEMU memory: using guest agent /proc/meminfo fallback (excludes reclaimable cache)")
- }
- })
- }
-
if vm.Status == "running" && memAvailable == 0 && memInfoTotalMinusUsed > 0 {
memAvailable = memInfoTotalMinusUsed
memorySource = "meminfo-total-minus-used"
@@ -595,7 +602,7 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, clu
Str("instance", instanceName).
Str("vm", vm.Name).
Int("vmid", vm.VMID).
- Msg("Permission denied accessing guest agent. Verify Pulse user has VM.Monitor (PVE 8) or VM.Audit+VM.GuestAgent.Audit (PVE 9) permissions")
+ Msg("Permission denied accessing guest agent. Verify Pulse user has VM.Monitor (PVE 8) or VM.GuestAgent.Audit+VM.GuestAgent.FileRead (PVE 9) permissions")
} else if strings.Contains(errStr, "500") {
// Generic 500 error without clear indicators - likely agent unavailable
// Refs #596: Proxmox returns 500 errors when guest agent isn't installed/running