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.

feat(monitoring): auto-detect Docker inside LXC containers

rcourtman103eb9c3e053
diff --git a/internal/models/models.go b/internal/models/models.go
index e735808bf5..84cb54f648 100644
--- a/internal/models/models.go
+++ b/internal/models/models.go
@@ -155,6 +155,10 @@ type Container struct {
// OCI container support (Proxmox VE 9.1+)
IsOCI bool `json:"isOci,omitempty"` // True if this is an OCI container
OSTemplate string `json:"osTemplate,omitempty"` // Template or OCI image used (e.g., "docker:alpine:latest")
+
+ // Docker detection - automatically detected by checking for Docker socket inside the container
+ HasDocker bool `json:"hasDocker,omitempty"` // True if Docker is installed inside this LXC
+ DockerCheckedAt time.Time `json:"dockerCheckedAt,omitempty"` // When Docker presence was last checked
}
// Host represents a generic infrastructure host reporting via external agents.
@@ -2750,3 +2754,28 @@ func (s *State) UpdatePMGBackups(instanceName string, backups []PMGBackup) {
s.syncBackupsLocked()
s.LastUpdate = time.Now()
}
+
+// GetContainers returns a copy of all LXC containers.
+func (s *State) GetContainers() []Container {
+ s.mu.RLock()
+ defer s.mu.RUnlock()
+
+ containers := make([]Container, len(s.Containers))
+ copy(containers, s.Containers)
+ return containers
+}
+
+// UpdateContainerDockerStatus updates the Docker detection status for a specific container.
+func (s *State) UpdateContainerDockerStatus(containerID string, hasDocker bool, checkedAt time.Time) bool {
+ s.mu.Lock()
+ defer s.mu.Unlock()
+
+ for i := range s.Containers {
+ if s.Containers[i].ID == containerID {
+ s.Containers[i].HasDocker = hasDocker
+ s.Containers[i].DockerCheckedAt = checkedAt
+ return true
+ }
+ }
+ return false
+}
diff --git a/internal/monitoring/docker_detection.go b/internal/monitoring/docker_detection.go
new file mode 100644
index 0000000000..e08a7ac61c
--- /dev/null
+++ b/internal/monitoring/docker_detection.go
@@ -0,0 +1,281 @@
+package monitoring
+
+import (
+ "context"
+ "fmt"
+ "strings"
+ "sync"
+ "time"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/models"
+ "github.com/rs/zerolog/log"
+)
+
+// DockerChecker provides the ability to check for Docker inside LXC containers.
+// This is typically implemented by wrapping the agentexec.Server.
+type DockerChecker interface {
+ // CheckDockerInContainer checks if Docker is installed inside an LXC container.
+ // Returns true if Docker socket exists, false otherwise.
+ // The node parameter is the Proxmox node hostname where the container runs.
+ CheckDockerInContainer(ctx context.Context, node string, vmid int) (bool, error)
+}
+
+// containerDockerCheck represents a container that needs Docker checking
+type containerDockerCheck struct {
+ index int
+ container models.Container
+ reason string // "new", "restarted", "first_check"
+}
+
+// containerDockerResult holds the result of a Docker check
+type containerDockerResult struct {
+ index int
+ hasDocker bool
+ checked bool
+ err error
+}
+
+// CheckContainersForDocker checks Docker presence for containers that need it.
+// This is called during container polling to detect Docker in:
+// - New containers that are running (first time seen)
+// - Containers that have restarted (uptime reset)
+// - Running containers that have never been checked
+//
+// Checks are performed in parallel for efficiency.
+// Returns the containers with updated Docker status.
+func (m *Monitor) CheckContainersForDocker(ctx context.Context, containers []models.Container) []models.Container {
+ m.mu.RLock()
+ checker := m.dockerChecker
+ m.mu.RUnlock()
+
+ if checker == nil {
+ return containers
+ }
+
+ // Get previous container state for comparison
+ previousContainers := make(map[string]models.Container)
+ for _, ct := range m.state.GetContainers() {
+ previousContainers[ct.ID] = ct
+ }
+
+ // Identify containers that need Docker checking
+ var needsCheck []containerDockerCheck
+ for i, ct := range containers {
+ if ct.Status != "running" {
+ // Not running - preserve previous Docker status if any
+ if prev, ok := previousContainers[ct.ID]; ok {
+ containers[i].HasDocker = prev.HasDocker
+ containers[i].DockerCheckedAt = prev.DockerCheckedAt
+ }
+ continue
+ }
+
+ // Check if this container needs Docker detection
+ reason := m.containerNeedsDockerCheck(ct, previousContainers)
+ if reason != "" {
+ needsCheck = append(needsCheck, containerDockerCheck{
+ index: i,
+ container: ct,
+ reason: reason,
+ })
+ } else {
+ // Preserve previous Docker status
+ if prev, ok := previousContainers[ct.ID]; ok {
+ containers[i].HasDocker = prev.HasDocker
+ containers[i].DockerCheckedAt = prev.DockerCheckedAt
+ }
+ }
+ }
+
+ if len(needsCheck) == 0 {
+ return containers
+ }
+
+ // Check Docker in parallel
+ results := m.checkDockerParallel(ctx, checker, needsCheck)
+
+ // Apply results
+ checkedCount := 0
+ dockerCount := 0
+ for _, result := range results {
+ if result.checked {
+ containers[result.index].HasDocker = result.hasDocker
+ containers[result.index].DockerCheckedAt = time.Now()
+ checkedCount++
+ if result.hasDocker {
+ dockerCount++
+ }
+ } else if result.err != nil {
+ // Check failed - preserve previous status if available
+ ct := containers[result.index]
+ if prev, ok := previousContainers[ct.ID]; ok {
+ containers[result.index].HasDocker = prev.HasDocker
+ containers[result.index].DockerCheckedAt = prev.DockerCheckedAt
+ }
+ }
+ }
+
+ if checkedCount > 0 {
+ log.Info().
+ Int("checked", checkedCount).
+ Int("with_docker", dockerCount).
+ Int("total_candidates", len(needsCheck)).
+ Msg("Docker detection completed for containers")
+ }
+
+ return containers
+}
+
+// containerNeedsDockerCheck determines if a running container needs Docker checking.
+// Returns the reason for checking, or empty string if no check is needed.
+func (m *Monitor) containerNeedsDockerCheck(ct models.Container, previousContainers map[string]models.Container) string {
+ prev, existed := previousContainers[ct.ID]
+
+ // New container - never seen before
+ if !existed {
+ return "new"
+ }
+
+ // Never been checked
+ if prev.DockerCheckedAt.IsZero() {
+ return "first_check"
+ }
+
+ // Container restarted - uptime is less than before
+ // (This catches containers that were stopped and started again)
+ if ct.Uptime < prev.Uptime && prev.Uptime > 0 {
+ return "restarted"
+ }
+
+ // Container was previously stopped and is now running
+ if prev.Status != "running" {
+ return "started"
+ }
+
+ // No check needed - use cached value
+ return ""
+}
+
+// checkDockerParallel checks Docker for multiple containers in parallel
+func (m *Monitor) checkDockerParallel(ctx context.Context, checker DockerChecker, checks []containerDockerCheck) []containerDockerResult {
+ results := make([]containerDockerResult, len(checks))
+
+ // Use a semaphore to limit concurrent checks (avoid overwhelming the system)
+ const maxConcurrent = 5
+ sem := make(chan struct{}, maxConcurrent)
+ var wg sync.WaitGroup
+
+ for i, check := range checks {
+ wg.Add(1)
+ go func(idx int, chk containerDockerCheck) {
+ defer wg.Done()
+
+ // Acquire semaphore
+ select {
+ case sem <- struct{}{}:
+ defer func() { <-sem }()
+ case <-ctx.Done():
+ results[idx] = containerDockerResult{index: chk.index, err: ctx.Err()}
+ return
+ }
+
+ // Perform the check
+ hasDocker, err := checker.CheckDockerInContainer(ctx, chk.container.Node, chk.container.VMID)
+ if err != nil {
+ log.Debug().
+ Str("container", chk.container.Name).
+ Int("vmid", chk.container.VMID).
+ Str("reason", chk.reason).
+ Err(err).
+ Msg("Failed to check Docker in container")
+ results[idx] = containerDockerResult{index: chk.index, err: err}
+ return
+ }
+
+ log.Debug().
+ Str("container", chk.container.Name).
+ Int("vmid", chk.container.VMID).
+ Str("reason", chk.reason).
+ Bool("has_docker", hasDocker).
+ Msg("Docker check completed")
+
+ results[idx] = containerDockerResult{
+ index: chk.index,
+ hasDocker: hasDocker,
+ checked: true,
+ }
+ }(i, check)
+ }
+
+ wg.Wait()
+ return results
+}
+
+// AgentDockerChecker implements DockerChecker using the agent execution system.
+// This wraps command execution to check for Docker inside LXC containers.
+type AgentDockerChecker struct {
+ executeCommand func(ctx context.Context, hostname string, command string, timeout int) (string, int, error)
+}
+
+// NewAgentDockerChecker creates a new checker that uses agent command execution.
+// The executeCommand function should execute a command on the given hostname and return
+// (stdout, exitCode, error).
+func NewAgentDockerChecker(executeCommand func(ctx context.Context, hostname string, command string, timeout int) (string, int, error)) *AgentDockerChecker {
+ return &AgentDockerChecker{
+ executeCommand: executeCommand,
+ }
+}
+
+// CheckDockerInContainer checks if Docker is installed inside an LXC container
+// by running `pct exec <vmid> -- test -S /var/run/docker.sock` on the Proxmox node.
+func (c *AgentDockerChecker) CheckDockerInContainer(ctx context.Context, node string, vmid int) (bool, error) {
+ if c.executeCommand == nil {
+ return false, fmt.Errorf("no command executor configured")
+ }
+
+ // Check for Docker socket - this is the most reliable indicator
+ // We use test -S which checks if the file exists and is a socket
+ cmd := fmt.Sprintf("pct exec %d -- test -S /var/run/docker.sock && echo yes || echo no", vmid)
+
+ stdout, exitCode, err := c.executeCommand(ctx, node, cmd, 10) // 10 second timeout
+ if err != nil {
+ return false, fmt.Errorf("command execution failed: %w", err)
+ }
+
+ // The test command itself might fail if container is not accessible
+ // but our echo fallback should always give us output
+ stdout = strings.TrimSpace(stdout)
+
+ // If we got "yes", Docker socket exists
+ if strings.Contains(stdout, "yes") {
+ return true, nil
+ }
+
+ // If exit code is non-zero and we didn't get "no", the container might not be accessible
+ if exitCode != 0 && !strings.Contains(stdout, "no") {
+ return false, fmt.Errorf("container not accessible (exit code %d): %s", exitCode, stdout)
+ }
+
+ return false, nil
+}
+
+// SetDockerChecker configures Docker detection for LXC containers.
+// When set, Docker presence will be automatically detected during container polling
+// for new containers and containers that have restarted.
+func (m *Monitor) SetDockerChecker(checker DockerChecker) {
+ m.mu.Lock()
+ defer m.mu.Unlock()
+ m.dockerChecker = checker
+ if checker != nil {
+ log.Info().Msg("Docker detection enabled for LXC containers")
+ } else {
+ log.Info().Msg("Docker detection disabled for LXC containers")
+ }
+}
+
+// GetDockerChecker returns the current Docker checker, if configured.
+func (m *Monitor) GetDockerChecker() DockerChecker {
+ m.mu.RLock()
+ defer m.mu.RUnlock()
+ return m.dockerChecker
+}
diff --git a/internal/monitoring/docker_detection_test.go b/internal/monitoring/docker_detection_test.go
new file mode 100644
index 0000000000..72cba2cbd6
--- /dev/null
+++ b/internal/monitoring/docker_detection_test.go
@@ -0,0 +1,424 @@
+package monitoring
+
+import (
+ "context"
+ "testing"
+ "time"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/models"
+)
+
+// mockDockerChecker is a test implementation of DockerChecker
+type mockDockerChecker struct {
+ results map[int]bool // vmid -> hasDocker
+ calls []int // records vmids that were checked
+}
+
+func (m *mockDockerChecker) CheckDockerInContainer(ctx context.Context, node string, vmid int) (bool, error) {
+ m.calls = append(m.calls, vmid)
+ if hasDocker, ok := m.results[vmid]; ok {
+ return hasDocker, nil
+ }
+ return false, nil
+}
+
+func TestCheckContainersForDocker_NewContainers(t *testing.T) {
+ // Create a monitor with state
+ state := models.NewState()
+ monitor := &Monitor{
+ state: state,
+ }
+
+ // Create a mock checker
+ checker := &mockDockerChecker{
+ results: map[int]bool{
+ 101: true,
+ 102: false,
+ 103: true, // This one is stopped, so it shouldn't be checked
+ },
+ }
+ monitor.SetDockerChecker(checker)
+
+ // Input containers - all new (not in state yet)
+ containers := []models.Container{
+ {ID: "ct-1", VMID: 101, Name: "container-with-docker", Node: "node1", Status: "running"},
+ {ID: "ct-2", VMID: 102, Name: "container-without-docker", Node: "node1", Status: "running"},
+ {ID: "ct-3", VMID: 103, Name: "stopped-container", Node: "node1", Status: "stopped"},
+ }
+
+ // Run the check
+ result := monitor.CheckContainersForDocker(context.Background(), containers)
+
+ // Verify results
+ var ct1, ct2, ct3 *models.Container
+ for i := range result {
+ switch result[i].ID {
+ case "ct-1":
+ ct1 = &result[i]
+ case "ct-2":
+ ct2 = &result[i]
+ case "ct-3":
+ ct3 = &result[i]
+ }
+ }
+
+ if ct1 == nil || !ct1.HasDocker {
+ t.Errorf("Container 101 should have HasDocker=true")
+ }
+ if ct1 != nil && ct1.DockerCheckedAt.IsZero() {
+ t.Errorf("Container 101 should have DockerCheckedAt set")
+ }
+
+ if ct2 == nil || ct2.HasDocker {
+ t.Errorf("Container 102 should have HasDocker=false")
+ }
+ if ct2 != nil && ct2.DockerCheckedAt.IsZero() {
+ t.Errorf("Container 102 should have DockerCheckedAt set")
+ }
+
+ // Stopped container should not be checked
+ if ct3 != nil && !ct3.DockerCheckedAt.IsZero() {
+ t.Errorf("Stopped container 103 should not have been checked")
+ }
+
+ // Verify only running containers were checked
+ if len(checker.calls) != 2 {
+ t.Errorf("Expected 2 Docker checks (running containers only), got %d", len(checker.calls))
+ }
+}
+
+func TestCheckContainersForDocker_PreservesExistingStatus(t *testing.T) {
+ // Create a monitor with state containing previously checked containers
+ state := models.NewState()
+ checkedTime := time.Now().Add(-30 * time.Minute)
+ state.UpdateContainers([]models.Container{
+ {
+ ID: "ct-1",
+ VMID: 101,
+ Name: "already-checked",
+ Node: "node1",
+ Status: "running",
+ HasDocker: true,
+ DockerCheckedAt: checkedTime,
+ Uptime: 3600, // 1 hour uptime
+ },
+ })
+
+ monitor := &Monitor{
+ state: state,
+ }
+
+ checker := &mockDockerChecker{
+ results: map[int]bool{101: false}, // Would return false if checked
+ }
+ monitor.SetDockerChecker(checker)
+
+ // Same container, still running with same/higher uptime
+ containers := []models.Container{
+ {
+ ID: "ct-1",
+ VMID: 101,
+ Name: "already-checked",
+ Node: "node1",
+ Status: "running",
+ Uptime: 7200, // 2 hours uptime (no restart)
+ },
+ }
+
+ result := monitor.CheckContainersForDocker(context.Background(), containers)
+
+ // Should not have been re-checked
+ if len(checker.calls) != 0 {
+ t.Errorf("Expected 0 checks (should preserve existing status), got %d", len(checker.calls))
+ }
+
+ // Should preserve the previous Docker status
+ if !result[0].HasDocker {
+ t.Errorf("Container should still have cached HasDocker=true")
+ }
+ if result[0].DockerCheckedAt.IsZero() {
+ t.Errorf("Container should have preserved DockerCheckedAt")
+ }
+}
+
+func TestCheckContainersForDocker_RechecksOnRestart(t *testing.T) {
+ // Create a monitor with state containing previously checked container
+ state := models.NewState()
+ state.UpdateContainers([]models.Container{
+ {
+ ID: "ct-1",
+ VMID: 101,
+ Name: "restarted-container",
+ Node: "node1",
+ Status: "running",
+ HasDocker: false,
+ DockerCheckedAt: time.Now().Add(-1 * time.Hour),
+ Uptime: 3600, // 1 hour uptime
+ },
+ })
+
+ monitor := &Monitor{
+ state: state,
+ }
+
+ checker := &mockDockerChecker{
+ results: map[int]bool{101: true}, // Now has Docker after restart
+ }
+ monitor.SetDockerChecker(checker)
+
+ // Same container but with reset uptime (restarted)
+ containers := []models.Container{
+ {
+ ID: "ct-1",
+ VMID: 101,
+ Name: "restarted-container",
+ Node: "node1",
+ Status: "running",
+ Uptime: 60, // Only 1 minute uptime - it restarted
+ },
+ }
+
+ result := monitor.CheckContainersForDocker(context.Background(), containers)
+
+ // Should have been re-checked because uptime reset
+ if len(checker.calls) != 1 {
+ t.Errorf("Expected 1 check (container restarted), got %d", len(checker.calls))
+ }
+
+ // Should have updated Docker status
+ if !result[0].HasDocker {
+ t.Errorf("Container should now have HasDocker=true after restart")
+ }
+}
+
+func TestCheckContainersForDocker_RechecksWhenStarted(t *testing.T) {
+ // Create a monitor with state containing previously stopped container
+ state := models.NewState()
+ state.UpdateContainers([]models.Container{
+ {
+ ID: "ct-1",
+ VMID: 101,
+ Name: "was-stopped",
+ Node: "node1",
+ Status: "stopped",
+ HasDocker: false,
+ DockerCheckedAt: time.Now().Add(-1 * time.Hour),
+ },
+ })
+
+ monitor := &Monitor{
+ state: state,
+ }
+
+ checker := &mockDockerChecker{
+ results: map[int]bool{101: true},
+ }
+ monitor.SetDockerChecker(checker)
+
+ // Container is now running
+ containers := []models.Container{
+ {
+ ID: "ct-1",
+ VMID: 101,
+ Name: "was-stopped",
+ Node: "node1",
+ Status: "running",
+ Uptime: 60,
+ },
+ }
+
+ result := monitor.CheckContainersForDocker(context.Background(), containers)
+
+ // Should have been checked because it just started
+ if len(checker.calls) != 1 {
+ t.Errorf("Expected 1 check (container started), got %d", len(checker.calls))
+ }
+
+ if !result[0].HasDocker {
+ t.Errorf("Container should have HasDocker=true after starting")
+ }
+}
+
+func TestCheckContainersForDocker_NoCheckerConfigured(t *testing.T) {
+ state := models.NewState()
+ monitor := &Monitor{
+ state: state,
+ }
+ // No checker configured
+
+ containers := []models.Container{
+ {ID: "ct-1", VMID: 101, Name: "test", Node: "node1", Status: "running"},
+ }
+
+ result := monitor.CheckContainersForDocker(context.Background(), containers)
+
+ // Should return containers unchanged
+ if len(result) != 1 {
+ t.Errorf("Expected 1 container, got %d", len(result))
+ }
+ if result[0].HasDocker {
+ t.Errorf("Container should not have HasDocker set without checker")
+ }
+}
+
+func TestAgentDockerChecker_ParsesOutput(t *testing.T) {
+ tests := []struct {
+ name string
+ stdout string
+ exitCode int
+ wantDocker bool
+ wantErr bool
+ }{
+ {
+ name: "docker socket exists",
+ stdout: "yes\n",
+ exitCode: 0,
+ wantDocker: true,
+ wantErr: false,
+ },
+ {
+ name: "docker socket does not exist",
+ stdout: "no\n",
+ exitCode: 1,
+ wantDocker: false,
+ wantErr: false,
+ },
+ {
+ name: "container not accessible",
+ stdout: "error: CT 101 is locked",
+ exitCode: 1,
+ wantDocker: false,
+ wantErr: true,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ checker := NewAgentDockerChecker(func(ctx context.Context, hostname string, command string, timeout int) (string, int, error) {
+ return tt.stdout, tt.exitCode, nil
+ })
+
+ hasDocker, err := checker.CheckDockerInContainer(context.Background(), "node1", 101)
+
+ if tt.wantErr && err == nil {
+ t.Errorf("Expected error but got none")
+ }
+ if !tt.wantErr && err != nil {
+ t.Errorf("Unexpected error: %v", err)
+ }
+ if hasDocker != tt.wantDocker {
+ t.Errorf("Expected hasDocker=%v, got %v", tt.wantDocker, hasDocker)
+ }
+ })
+ }
+}
+
+func TestState_GetContainers(t *testing.T) {
+ state := models.NewState()
+ state.UpdateContainers([]models.Container{
+ {ID: "ct-1", VMID: 101, Name: "test1"},
+ {ID: "ct-2", VMID: 102, Name: "test2"},
+ })
+
+ containers := state.GetContainers()
+
+ if len(containers) != 2 {
+ t.Errorf("Expected 2 containers, got %d", len(containers))
+ }
+
+ // Verify it's a copy (modifying shouldn't affect original)
+ containers[0].Name = "modified"
+ originalContainers := state.GetContainers()
+ if originalContainers[0].Name == "modified" {
+ t.Error("GetContainers should return a copy, not the original slice")
+ }
+}
+
+func TestState_UpdateContainerDockerStatus(t *testing.T) {
+ state := models.NewState()
+ state.UpdateContainers([]models.Container{
+ {ID: "ct-1", VMID: 101, Name: "test1"},
+ })
+
+ now := time.Now()
+ updated := state.UpdateContainerDockerStatus("ct-1", true, now)
+
+ if !updated {
+ t.Error("UpdateContainerDockerStatus should return true for existing container")
+ }
+
+ containers := state.GetContainers()
+ if !containers[0].HasDocker {
+ t.Error("Container should have HasDocker=true")
+ }
+ if containers[0].DockerCheckedAt.IsZero() {
+ t.Error("Container should have DockerCheckedAt set")
+ }
+
+ // Test non-existent container
+ updated = state.UpdateContainerDockerStatus("non-existent", true, now)
+ if updated {
+ t.Error("UpdateContainerDockerStatus should return false for non-existent container")
+ }
+}
+
+func TestContainerNeedsDockerCheck(t *testing.T) {
+ monitor := &Monitor{
+ state: models.NewState(),
+ }
+
+ tests := []struct {
+ name string
+ container models.Container
+ previous map[string]models.Container
+ wantReason string
+ }{
+ {
+ name: "new container",
+ container: models.Container{ID: "ct-1", Status: "running"},
+ previous: map[string]models.Container{},
+ wantReason: "new",
+ },
+ {
+ name: "first check - never checked before",
+ container: models.Container{ID: "ct-1", Status: "running", Uptime: 3600},
+ previous: map[string]models.Container{
+ "ct-1": {ID: "ct-1", Status: "running", Uptime: 3600},
+ },
+ wantReason: "first_check",
+ },
+ {
+ name: "restarted - uptime lower",
+ container: models.Container{ID: "ct-1", Status: "running", Uptime: 60},
+ previous: map[string]models.Container{
+ "ct-1": {ID: "ct-1", Status: "running", Uptime: 3600, DockerCheckedAt: time.Now()},
+ },
+ wantReason: "restarted",
+ },
+ {
+ name: "started - was stopped",
+ container: models.Container{ID: "ct-1", Status: "running", Uptime: 60},
+ previous: map[string]models.Container{
+ "ct-1": {ID: "ct-1", Status: "stopped", DockerCheckedAt: time.Now()},
+ },
+ wantReason: "started",
+ },
+ {
+ name: "no check needed - same state",
+ container: models.Container{ID: "ct-1", Status: "running", Uptime: 7200},
+ previous: map[string]models.Container{
+ "ct-1": {ID: "ct-1", Status: "running", Uptime: 3600, DockerCheckedAt: time.Now()},
+ },
+ wantReason: "",
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ reason := monitor.containerNeedsDockerCheck(tt.container, tt.previous)
+ if reason != tt.wantReason {
+ t.Errorf("Expected reason %q, got %q", tt.wantReason, reason)
+ }
+ })
+ }
+}
diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go
index 98ae5a840c..3014441e43 100644
--- a/internal/monitoring/monitor.go
+++ b/internal/monitoring/monitor.go
@@ -774,6 +774,7 @@ type Monitor struct {
resourceStore ResourceStoreInterface // Optional unified resource store for polling optimization
mockMetricsCancel context.CancelFunc
mockMetricsWg sync.WaitGroup
+ dockerChecker DockerChecker // Optional Docker checker for LXC containers
}
type rrdMemCacheEntry struct {
@@ -7120,6 +7121,10 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam
// Always update state when using efficient polling path
// Even if arrays are empty, we need to update to clear out VMs from genuinely offline nodes
m.state.UpdateVMsForInstance(instanceName, allVMs)
+
+ // Check Docker presence for containers that need it (new, restarted, started)
+ allContainers = m.CheckContainersForDocker(ctx, allContainers)
+
m.state.UpdateContainersForInstance(instanceName, allContainers)
// Record guest metrics history for running guests (enables sparkline/trends view)
diff --git a/internal/monitoring/monitor_polling.go b/internal/monitoring/monitor_polling.go
index d2ef9b3c0a..9d97f9591b 100644
--- a/internal/monitoring/monitor_polling.go
+++ b/internal/monitoring/monitor_polling.go
@@ -1151,6 +1151,9 @@ func (m *Monitor) pollContainersWithNodes(ctx context.Context, instanceName stri
}
}
+ // Check Docker presence for containers that need it (new, restarted, started)
+ allContainers = m.CheckContainersForDocker(ctx, allContainers)
+
// Update state with all containers
m.state.UpdateContainersForInstance(instanceName, allContainers)