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.

Use unavailable sentinel when VM guest agent disk query fails

rcourtmane1720ca219b3
diff --git a/internal/monitoring/guest_disk_stability_test.go b/internal/monitoring/guest_disk_stability_test.go
index c61818ee11..f449e9f538 100644
--- a/internal/monitoring/guest_disk_stability_test.go
+++ b/internal/monitoring/guest_disk_stability_test.go
@@ -1,10 +1,13 @@
package monitoring
import (
+ "context"
+ "errors"
"testing"
"time"
"github.com/rcourtman/pulse-go-rewrite/internal/models"
+ "github.com/rcourtman/pulse-go-rewrite/pkg/proxmox"
)
func TestStabilizeGuestLowTrustDiskCarriesForwardPreviousSnapshot(t *testing.T) {
@@ -133,3 +136,50 @@ func TestStabilizeGuestLowTrustDiskCarriesPreviouslyForwardedSnapshotWithAgentEv
t.Fatalf("reason = %q, want prev-no-filesystems", reason)
}
}
+
+type failingFSInfoClient struct {
+ PVEClientInterface
+ err error
+}
+
+func (c failingFSInfoClient) GetVMFSInfo(ctx context.Context, node string, vmid int) ([]proxmox.VMFileSystem, error) {
+ return nil, c.err
+}
+
+func TestUpdateVMDisksFromGuestAgentFSInfoErrorUsesUnavailableSentinel(t *testing.T) {
+ // Cluster/resources reports 0 used for QEMU, so a failed agent query must
+ // not pass those zeros through as a confident 0% (it renders as
+ // "0% (0 B/120 GB)" instead of unavailable + reason in the UI).
+ m := &Monitor{}
+ res := proxmox.ClusterResource{Node: "pve1", VMID: 100, Name: "vm100", MaxDisk: 128849018880}
+ client := failingFSInfoClient{err: errors.New("guest agent request timeout")}
+
+ total, used, free, usage, disks, fromAgent, reason := m.updateVMDisksFromGuestAgentFSInfo(
+ context.Background(),
+ "test-instance",
+ res,
+ client,
+ uint64(res.MaxDisk),
+ 0,
+ 0,
+ )
+
+ if usage != -1 {
+ t.Fatalf("usage = %v, want -1 sentinel", usage)
+ }
+ if reason != "agent-timeout" {
+ t.Fatalf("reason = %q, want agent-timeout", reason)
+ }
+ if fromAgent {
+ t.Fatal("fromAgent = true, want false")
+ }
+ if total != uint64(res.MaxDisk) {
+ t.Fatalf("total = %d, want allocated size %d", total, res.MaxDisk)
+ }
+ if used != 0 || free != total {
+ t.Fatalf("used/free = %d/%d, want 0/%d", used, free, total)
+ }
+ if disks != nil {
+ t.Fatalf("disks = %v, want nil", disks)
+ }
+}
diff --git a/internal/monitoring/monitor_pve_guest_builders.go b/internal/monitoring/monitor_pve_guest_builders.go
index cca26c69cc..8b2d052c5c 100644
--- a/internal/monitoring/monitor_pve_guest_builders.go
+++ b/internal/monitoring/monitor_pve_guest_builders.go
@@ -701,6 +701,14 @@ func (m *Monitor) updateVMDisksFromGuestAgentFSInfo(
fsInfo, diskStatusReason, ok := m.fetchVMFSInfo(ctx, instanceName, res, client)
if !ok {
+ // No trustworthy usage data: cluster/resources reports 0 used for
+ // QEMU, so passing it through renders a confident "0%" in the UI.
+ // Use the -1 sentinel (same as the agent-disabled path) so the
+ // frontend shows unavailable + diskStatusReason instead; the
+ // stabilizer may still replace this with the previous good sample.
+ if diskTotal > 0 {
+ diskUsage = -1
+ }
return diskTotal, diskUsed, diskTotal - diskUsed, diskUsage, nil, false, diskStatusReason
}