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 LXC Docker container flicker from partial inventory polls
rcourtmanfc72e3d8d1ae
diff --git a/internal/monitoring/docker_detection.go b/internal/monitoring/docker_detection.goindex 93932fba1c..a02f6e525f 100644--- a/internal/monitoring/docker_detection.go+++ b/internal/monitoring/docker_detection.go@@ -472,7 +472,7 @@ func buildProxmoxGuestDockerInventoryCommand(vmid int) string {"if ! test -S /var/run/docker.sock; then printf 'NO_DOCKER\\n'; exit 0; fi","version=\"$(docker version --format '{{json .Server.Version}}' 2>/dev/null || true)\"","if [ -n \"$version\" ]; then printf 'VERSION\\t%s\\n' \"$version\"; fi",- "docker ps -a --no-trunc --format 'CONTAINER\\t{{json .ID}}\\t{{json .Names}}\\t{{json .Image}}\\t{{json .State}}\\t{{json .Status}}\\t{{json .Ports}}\\t{{json .RunningFor}}' 2>/dev/null || true",+ "if docker ps -a --no-trunc --format 'CONTAINER\\t{{json .ID}}\\t{{json .Names}}\\t{{json .Image}}\\t{{json .State}}\\t{{json .Status}}\\t{{json .Ports}}\\t{{json .RunningFor}}' 2>/dev/null; then printf 'PS_OK\\n'; fi","ids=\"$(docker ps -aq --no-trunc 2>/dev/null)\"","if [ -n \"$ids\" ]; then docker stats --no-stream --no-trunc --format 'STAT\\t{{json .ID}}\\t{{json .Name}}\\t{{json .CPUPerc}}\\t{{json .MemUsage}}\\t{{json .MemPerc}}\\t{{json .NetIO}}\\t{{json .BlockIO}}' $ids 2>/dev/null || true; fi",}, "\n")@@ -502,6 +502,7 @@ func parseProxmoxGuestDockerInventory(output string, container models.Container,containers := make([]agentsdocker.Container, 0)containerIndex := make(map[string]int)noDocker := false+ psOK := falsefor _, rawLine := range strings.Split(output, "\n") {line := strings.TrimRight(rawLine, "\r")@@ -512,6 +513,10 @@ func parseProxmoxGuestDockerInventory(output string, container models.Container,noDocker = truecontinue}+ if line == "PS_OK" {+ psOK = true+ continue+ }fields := strings.Split(line, "\t")if len(fields) == 1 && strings.HasPrefix(line, "VERSION\\t") {@@ -573,6 +578,9 @@ func parseProxmoxGuestDockerInventory(output string, container models.Container,if noDocker && len(containers) == 0 && hostInfo.DockerVersion == "" {return agentsdocker.Report{}, false, nil}+ if !noDocker && !psOK {+ return agentsdocker.Report{}, false, fmt.Errorf("docker ps did not complete (no PS_OK marker); refusing to apply partial inventory for %q", strings.TrimSpace(container.Name))+ }if timestamp.IsZero() {timestamp = time.Now().UTC()}diff --git a/internal/monitoring/docker_detection_test.go b/internal/monitoring/docker_detection_test.goindex fdca26a245..f69f0c305b 100644--- a/internal/monitoring/docker_detection_test.go+++ b/internal/monitoring/docker_detection_test.go@@ -331,6 +331,7 @@ func TestAgentDockerInventoryCollector_MinimalCommandAndReport(t *testing.T) {"MEMTOTAL\t1073741824","VERSION\t\"26.1.4\"","CONTAINER\t\"abcdef123456\"\t\"web\"\t\"nginx:latest\"\t\"running\"\t\"Up 2 hours\"\t\"0.0.0.0:8080->80/tcp, 443/tcp\"\t\"2 hours ago\"",+ "PS_OK","STAT\t\"abcdef123456\"\t\"web\"\t\"0.50%\"\t\"64MiB / 1GiB\"\t\"6.25%\"\t\"1.2kB / 3.4MB\"\t\"5MB / 6MB\"","",}, "\n"), 0, nil@@ -394,6 +395,66 @@ func TestAgentDockerInventoryCollector_MinimalCommandAndReport(t *testing.T) {}}+func TestAgentDockerInventoryCollector_PartialOutputRefusesApply(t *testing.T) {+ collector := NewAgentDockerInventoryCollector(func(ctx context.Context, hostname string, command string, timeout int) (string, int, error) {+ return strings.Join([]string{+ proxmoxGuestDockerInventoryMarker,+ "HOSTNAME\tct-web",+ "UNAME\tLinux 6.8.12-9-pve x86_64",+ "CPUS\t2",+ "MEMTOTAL\t1073741824",+ "VERSION\t\"26.1.4\"",+ "",+ }, "\n"), 0, nil+ }, AgentDockerInventoryCollectorOptions{})++ _, ok, err := collector.CollectDockerInventory(context.Background(), models.Container{+ ID: "pve-a:node-a:101",+ VMID: 101,+ Name: "web-lxc",+ Node: "node-a",+ Status: "running",+ })+ if err == nil {+ t.Fatal("expected an error when docker ps marker is missing")+ }+ if ok {+ t.Fatal("partial inventory output (no PS_OK) must not produce an applicable report")+ }+}++func TestAgentDockerInventoryCollector_PSOKWithZeroContainersApplies(t *testing.T) {+ collector := NewAgentDockerInventoryCollector(func(ctx context.Context, hostname string, command string, timeout int) (string, int, error) {+ return strings.Join([]string{+ proxmoxGuestDockerInventoryMarker,+ "HOSTNAME\tct-web",+ "UNAME\tLinux 6.8.12-9-pve x86_64",+ "CPUS\t2",+ "MEMTOTAL\t1073741824",+ "VERSION\t\"26.1.4\"",+ "PS_OK",+ "",+ }, "\n"), 0, nil+ }, AgentDockerInventoryCollectorOptions{})++ report, ok, err := collector.CollectDockerInventory(context.Background(), models.Container{+ ID: "pve-a:node-a:101",+ VMID: 101,+ Name: "web-lxc",+ Node: "node-a",+ Status: "running",+ })+ if err != nil {+ t.Fatalf("CollectDockerInventory returned error: %v", err)+ }+ if !ok {+ t.Fatal("zero-container result with PS_OK must be applied (host genuinely has no containers)")+ }+ if len(report.Containers) != 0 {+ t.Fatalf("expected zero containers, got %d", len(report.Containers))+ }+}+func TestAgentDockerInventoryCollector_AllowlistSkipsUnlistedVMID(t *testing.T) {called := falsecollector := NewAgentDockerInventoryCollector(func(ctx context.Context, hostname string, command string, timeout int) (string, int, error) {