From f23a1b5cec9238e1b15b49ec88657aa03ce207c4 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Thu, 27 Nov 2025 12:04:51 +0100 Subject: [PATCH] Add debug logging for Docker container and image collection Agent changes: - Added debug logging to Docker images collection function - Log when Docker sub-services are being collected for a service - Log count of containers and images found - Log total sub-services added - Show command failure details instead of silently returning empty vec This will help diagnose why Docker images aren't showing up as sub-services on some hosts. The logs will show if the docker commands are failing or if the collection is working but data isn't being transmitted properly. Updated to version 0.1.175 --- Cargo.lock | 6 +++--- agent/Cargo.toml | 2 +- agent/src/collectors/systemd.rs | 17 ++++++++++++++++- dashboard/Cargo.toml | 2 +- shared/Cargo.toml | 2 +- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8983893..87b2374 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" [[package]] name = "cm-dashboard" -version = "0.1.174" +version = "0.1.175" dependencies = [ "anyhow", "chrono", @@ -301,7 +301,7 @@ dependencies = [ [[package]] name = "cm-dashboard-agent" -version = "0.1.174" +version = "0.1.175" dependencies = [ "anyhow", "async-trait", @@ -324,7 +324,7 @@ dependencies = [ [[package]] name = "cm-dashboard-shared" -version = "0.1.174" +version = "0.1.175" dependencies = [ "chrono", "serde", diff --git a/agent/Cargo.toml b/agent/Cargo.toml index 77ff163..7d31801 100644 --- a/agent/Cargo.toml +++ b/agent/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-agent" -version = "0.1.174" +version = "0.1.175" edition = "2021" [dependencies] diff --git a/agent/src/collectors/systemd.rs b/agent/src/collectors/systemd.rs index 94ae7f3..2146eb9 100644 --- a/agent/src/collectors/systemd.rs +++ b/agent/src/collectors/systemd.rs @@ -118,7 +118,10 @@ impl SystemdCollector { } if service_name.contains("docker") && active_status == "active" { + debug!("Collecting Docker sub-services for service: {}", service_name); + let docker_containers = self.get_docker_containers(); + debug!("Found {} Docker containers", docker_containers.len()); for (container_name, container_status) in docker_containers { // For now, docker containers have no additional metrics // Future: could add memory_mb, cpu_percent, restart_count, etc. @@ -133,6 +136,7 @@ impl SystemdCollector { // Add Docker images let docker_images = self.get_docker_images(); + debug!("Found {} Docker images", docker_images.len()); for (image_name, image_status, image_size) in docker_images { let mut metrics = Vec::new(); metrics.push(SubServiceMetric { @@ -147,6 +151,8 @@ impl SystemdCollector { metrics, }); } + + debug!("Total Docker sub-services added: {}", sub_services.len()); } // Create complete service data @@ -818,6 +824,8 @@ impl SystemdCollector { fn get_docker_images(&self) -> Vec<(String, String, String)> { let mut images = Vec::new(); + debug!("Collecting Docker images"); + // Check if docker is available (use sudo for permissions) let output = Command::new("sudo") .args(&["docker", "images", "--format", "{{.Repository}}:{{.Tag}},{{.Size}}"]) @@ -825,7 +833,14 @@ impl SystemdCollector { let output = match output { Ok(out) if out.status.success() => out, - _ => return images, // Docker not available or failed + Ok(out) => { + debug!("Docker images command failed with status: {}", out.status); + return images; + } + Err(e) => { + debug!("Docker images command error: {}", e); + return images; + } }; let output_str = match String::from_utf8(output.stdout) { diff --git a/dashboard/Cargo.toml b/dashboard/Cargo.toml index 6d33f50..f0ecc1f 100644 --- a/dashboard/Cargo.toml +++ b/dashboard/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard" -version = "0.1.174" +version = "0.1.175" edition = "2021" [dependencies] diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 045f2f9..af75780 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-shared" -version = "0.1.174" +version = "0.1.175" edition = "2021" [dependencies]