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.

Don't overwrite populated Docker hosts with empty inventory polls

rcourtman926906b134a1
diff --git a/internal/monitoring/docker_detection.go b/internal/monitoring/docker_detection.go
index 24a6bb1cd5..530e0376a9 100644
--- a/internal/monitoring/docker_detection.go
+++ b/internal/monitoring/docker_detection.go
@@ -302,6 +302,28 @@ func (m *Monitor) CollectProxmoxGuestDockerInventory(ctx context.Context, contai
enrichGuestDockerReportFromContainer(&report, container)
+ // Refuse to overwrite a known-populated host with an empty
+ // container list. docker ps -a inside an LXC occasionally
+ // returns zero containers for a single poll (during
+ // watchtower-driven container recreate cycles, or while the
+ // daemon is restarting), which would otherwise wipe every
+ // row for that host on every connected WebSocket client
+ // until the next successful poll restores it. A host that
+ // genuinely has no containers still applies on first sight,
+ // and a host transitioning to zero containers will catch
+ // up as soon as we hit the existing offline grace window.
+ if len(report.Containers) == 0 && m.dockerHostHasContainers(report.Agent.ID) {
+ log.Debug().
+ Str("container", container.Name).
+ Int("vmid", container.VMID).
+ Str("agentID", report.Agent.ID).
+ Msg("Skipping Proxmox LXC Docker inventory apply: report has zero containers but host previously had containers (transient docker ps state)")
+ mu.Lock()
+ skipped++
+ mu.Unlock()
+ return
+ }
+
if _, err := m.ApplyDockerReport(report, nil); err != nil {
log.Warn().
Err(err).
@@ -345,6 +367,25 @@ func (m *Monitor) hasOnlineHostAgentForContainer(containerID string) bool {
return false
}
+// dockerHostHasContainers reports whether the docker host identified by the
+// given agent ID (or canonical host ID alias) currently has at least one
+// container tracked in state. Used by CollectProxmoxGuestDockerInventory to
+// detect the "previously populated, now reporting zero" pattern that comes
+// from transient docker ps blips inside an LXC and would otherwise wipe
+// container rows for every WebSocket client.
+func (m *Monitor) dockerHostHasContainers(agentID string) bool {
+ agentID = strings.TrimSpace(agentID)
+ if m == nil || m.state == nil || agentID == "" {
+ return false
+ }
+ for _, host := range m.state.GetDockerHosts() {
+ if host.ID == agentID || strings.TrimSpace(host.AgentID) == agentID {
+ return len(host.Containers) > 0
+ }
+ }
+ return false
+}
+
// AgentDockerChecker implements DockerChecker using the agent execution system.
// This wraps command execution to check for Docker inside LXC containers.
type AgentDockerChecker struct {
diff --git a/internal/monitoring/docker_detection_test.go b/internal/monitoring/docker_detection_test.go
index 791dfa5af9..57dd1ffc34 100644
--- a/internal/monitoring/docker_detection_test.go
+++ b/internal/monitoring/docker_detection_test.go
@@ -596,6 +596,104 @@ func TestMonitorCollectProxmoxGuestDockerInventory_AppliesDockerReport(t *testin
}
}
+func TestMonitorCollectProxmoxGuestDockerInventory_RefusesEmptyOverwriteOfPopulatedHost(t *testing.T) {
+ monitor := newTestMonitor(t)
+
+ // First poll populates the docker host with one container.
+ collector := &mockDockerInventoryCollector{
+ reports: map[int]agentsdocker.Report{
+ 101: {
+ Agent: agentsdocker.AgentInfo{ID: "proxmox-lxc-docker:pve-a:node-a:101", Type: "unified", IntervalSeconds: 30},
+ Host: agentsdocker.HostInfo{
+ Hostname: "ct-web",
+ Name: "web-lxc",
+ Runtime: "docker",
+ DockerVersion: "26.1.4",
+ RuntimeVersion: "26.1.4",
+ },
+ Containers: []agentsdocker.Container{{
+ ID: "docker-1",
+ Name: "web",
+ Image: "nginx:latest",
+ State: "running",
+ Status: "Up 1 minute",
+ }},
+ Timestamp: time.Now().UTC(),
+ },
+ },
+ }
+ monitor.SetDockerInventoryCollector(collector)
+
+ monitor.CollectProxmoxGuestDockerInventory(context.Background(), []models.Container{
+ {ID: "pve-a:node-a:101", VMID: 101, Name: "web-lxc", Node: "node-a", Status: "running", HasDocker: true},
+ })
+
+ hosts := monitor.state.GetDockerHosts()
+ if len(hosts) != 1 || len(hosts[0].Containers) != 1 {
+ t.Fatalf("setup failed: expected 1 host with 1 container, got %d hosts", len(hosts))
+ }
+
+ // Second poll returns the same host but with zero containers — the
+ // transient `docker ps` blip we want to ignore so the UI does not
+ // flash empty until the next successful poll.
+ collector.reports[101] = agentsdocker.Report{
+ Agent: agentsdocker.AgentInfo{ID: "proxmox-lxc-docker:pve-a:node-a:101", Type: "unified", IntervalSeconds: 30},
+ Host: agentsdocker.HostInfo{
+ Hostname: "ct-web",
+ Name: "web-lxc",
+ Runtime: "docker",
+ DockerVersion: "26.1.4",
+ RuntimeVersion: "26.1.4",
+ },
+ Containers: nil,
+ Timestamp: time.Now().UTC(),
+ }
+
+ monitor.CollectProxmoxGuestDockerInventory(context.Background(), []models.Container{
+ {ID: "pve-a:node-a:101", VMID: 101, Name: "web-lxc", Node: "node-a", Status: "running", HasDocker: true},
+ })
+
+ hosts = monitor.state.GetDockerHosts()
+ if len(hosts) != 1 {
+ t.Fatalf("docker host disappeared after empty report")
+ }
+ if len(hosts[0].Containers) != 1 || hosts[0].Containers[0].Name != "web" {
+ t.Fatalf("empty inventory report wiped the previously-populated container list: %#v", hosts[0].Containers)
+ }
+}
+
+func TestMonitorCollectProxmoxGuestDockerInventory_AppliesFirstZeroContainerReport(t *testing.T) {
+ monitor := newTestMonitor(t)
+ collector := &mockDockerInventoryCollector{
+ reports: map[int]agentsdocker.Report{
+ 101: {
+ Agent: agentsdocker.AgentInfo{ID: "proxmox-lxc-docker:pve-a:node-a:101", Type: "unified", IntervalSeconds: 30},
+ Host: agentsdocker.HostInfo{
+ Hostname: "ct-web",
+ Name: "web-lxc",
+ Runtime: "docker",
+ DockerVersion: "26.1.4",
+ },
+ Containers: nil,
+ Timestamp: time.Now().UTC(),
+ },
+ },
+ }
+ monitor.SetDockerInventoryCollector(collector)
+
+ monitor.CollectProxmoxGuestDockerInventory(context.Background(), []models.Container{
+ {ID: "pve-a:node-a:101", VMID: 101, Name: "web-lxc", Node: "node-a", Status: "running", HasDocker: true},
+ })
+
+ hosts := monitor.state.GetDockerHosts()
+ if len(hosts) != 1 {
+ t.Fatalf("expected the host to be created from the first (empty) report, got %d hosts", len(hosts))
+ }
+ if len(hosts[0].Containers) != 0 {
+ t.Fatalf("expected zero containers on a freshly-seen empty host, got %d", len(hosts[0].Containers))
+ }
+}
+
func TestMonitorCollectProxmoxGuestDockerInventory_SkipsLinkedGuestLocalAgent(t *testing.T) {
monitor := newTestMonitor(t)
monitor.state.UpsertHost(models.Host{