From 3f98f68b518d331f2e6ef7cae241e4d6a5147133 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Thu, 27 Nov 2025 11:43:35 +0100 Subject: [PATCH] Show Docker images as sub-services under docker service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent changes: - Added get_docker_images() function to list all Docker images - Use docker images to show stored images with repository:tag and size - Display images as sub-services under docker service with size in parentheses - Skip dangling images (:) - Images shown with active status (always present when listed) Example display: ● docker active 139M 1MB ├─ ● docker_gitea active ├─ ○ docker_old-app inactive ├─ ● image_nginx:latest (142MB) ├─ ● image_postgres:15 (379MB) └─ ● image_gitea:latest (256MB) Updated to version 0.1.174 --- Cargo.lock | 6 ++-- agent/Cargo.toml | 2 +- agent/src/collectors/systemd.rs | 62 +++++++++++++++++++++++++++++++++ dashboard/Cargo.toml | 2 +- shared/Cargo.toml | 2 +- 5 files changed, 68 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f8ac5a..8983893 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" [[package]] name = "cm-dashboard" -version = "0.1.173" +version = "0.1.174" dependencies = [ "anyhow", "chrono", @@ -301,7 +301,7 @@ dependencies = [ [[package]] name = "cm-dashboard-agent" -version = "0.1.173" +version = "0.1.174" dependencies = [ "anyhow", "async-trait", @@ -324,7 +324,7 @@ dependencies = [ [[package]] name = "cm-dashboard-shared" -version = "0.1.173" +version = "0.1.174" dependencies = [ "chrono", "serde", diff --git a/agent/Cargo.toml b/agent/Cargo.toml index db68843..77ff163 100644 --- a/agent/Cargo.toml +++ b/agent/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-agent" -version = "0.1.173" +version = "0.1.174" edition = "2021" [dependencies] diff --git a/agent/src/collectors/systemd.rs b/agent/src/collectors/systemd.rs index 2f76b7f..94ae7f3 100644 --- a/agent/src/collectors/systemd.rs +++ b/agent/src/collectors/systemd.rs @@ -130,6 +130,23 @@ impl SystemdCollector { metrics, }); } + + // Add Docker images + let docker_images = self.get_docker_images(); + for (image_name, image_status, image_size) in docker_images { + let mut metrics = Vec::new(); + metrics.push(SubServiceMetric { + label: "size".to_string(), + value: 0.0, // Size as string in name instead + unit: None, + }); + + sub_services.push(SubServiceData { + name: format!("{} ({})", image_name, image_size), + service_status: self.calculate_service_status(&image_name, &image_status), + metrics, + }); + } } // Create complete service data @@ -796,6 +813,51 @@ impl SystemdCollector { containers } + + /// Get docker images as sub-services + fn get_docker_images(&self) -> Vec<(String, String, String)> { + let mut images = Vec::new(); + + // Check if docker is available (use sudo for permissions) + let output = Command::new("sudo") + .args(&["docker", "images", "--format", "{{.Repository}}:{{.Tag}},{{.Size}}"]) + .output(); + + let output = match output { + Ok(out) if out.status.success() => out, + _ => return images, // Docker not available or failed + }; + + let output_str = match String::from_utf8(output.stdout) { + Ok(s) => s, + Err(_) => return images, + }; + + for line in output_str.lines() { + if line.trim().is_empty() { + continue; + } + + let parts: Vec<&str> = line.split(',').collect(); + if parts.len() >= 2 { + let image_name = parts[0].trim(); + let size = parts[1].trim(); + + // Skip : images (dangling images) + if image_name.contains("") { + continue; + } + + images.push(( + format!("image_{}", image_name), + "active".to_string(), // Images are always "active" (present) + size.to_string() + )); + } + } + + images + } } #[async_trait] diff --git a/dashboard/Cargo.toml b/dashboard/Cargo.toml index 8e7e57f..6d33f50 100644 --- a/dashboard/Cargo.toml +++ b/dashboard/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard" -version = "0.1.173" +version = "0.1.174" edition = "2021" [dependencies] diff --git a/shared/Cargo.toml b/shared/Cargo.toml index a78d2cf..045f2f9 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-shared" -version = "0.1.173" +version = "0.1.174" edition = "2021" [dependencies]