Show all Docker containers as top-level services with active/inactive status
All checks were successful
Build and Release / build-and-release (push) Successful in 1m20s

Agent changes:
- Changed docker ps to docker ps -a to show ALL containers (running and stopped)
- Map container status: Up -> active, Exited/Created -> inactive, other -> failed
- Display Docker containers as individual top-level services instead of sub-services
- Each container shown as "docker_{container_name}" in service list

This provides better visibility of all containers and their status directly in the
services panel, making it easier to see stopped containers at a glance.

Updated to version 0.1.172
This commit is contained in:
Christoffer Martinsson 2025-11-27 10:51:47 +01:00
parent 8f9e9eabca
commit b0ee0242bd
5 changed files with 29 additions and 25 deletions

6
Cargo.lock generated
View File

@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
[[package]] [[package]]
name = "cm-dashboard" name = "cm-dashboard"
version = "0.1.171" version = "0.1.172"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"chrono", "chrono",
@ -301,7 +301,7 @@ dependencies = [
[[package]] [[package]]
name = "cm-dashboard-agent" name = "cm-dashboard-agent"
version = "0.1.171" version = "0.1.172"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
@ -324,7 +324,7 @@ dependencies = [
[[package]] [[package]]
name = "cm-dashboard-shared" name = "cm-dashboard-shared"
version = "0.1.171" version = "0.1.172"
dependencies = [ dependencies = [
"chrono", "chrono",
"serde", "serde",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "cm-dashboard-agent" name = "cm-dashboard-agent"
version = "0.1.171" version = "0.1.172"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@ -117,20 +117,8 @@ impl SystemdCollector {
} }
} }
if service_name.contains("docker") && active_status == "active" { // Docker containers are now collected as top-level services below
let docker_containers = self.get_docker_containers(); // Keeping nginx as sub-services for now
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.
let metrics = Vec::new();
sub_services.push(SubServiceData {
name: container_name.clone(),
service_status: self.calculate_service_status(&container_name, &container_status),
metrics,
});
}
}
// Create complete service data // Create complete service data
let service_data = ServiceData { let service_data = ServiceData {
@ -151,7 +139,22 @@ impl SystemdCollector {
} }
} }
} }
// Collect Docker containers as top-level services
let docker_containers = self.get_docker_containers();
for (container_name, container_status) in docker_containers {
let service_data = ServiceData {
name: container_name.clone(),
memory_mb: 0.0, // TODO: Could add container memory via docker stats
disk_gb: 0.0, // TODO: Could add container disk usage
user_stopped: false,
service_status: self.calculate_service_status(&container_name, &container_status),
sub_services: Vec::new(),
};
agent_data.services.push(service_data.clone());
complete_service_data.push(service_data);
}
// Update cached state // Update cached state
{ {
let mut state = self.state.write().unwrap(); let mut state = self.state.write().unwrap();
@ -757,8 +760,9 @@ impl SystemdCollector {
let mut containers = Vec::new(); let mut containers = Vec::new();
// Check if docker is available (use sudo for permissions) // Check if docker is available (use sudo for permissions)
// Use -a to show ALL containers (running and stopped)
let output = Command::new("sudo") let output = Command::new("sudo")
.args(&["docker", "ps", "--format", "{{.Names}},{{.Status}}"]) .args(&["docker", "ps", "-a", "--format", "{{.Names}},{{.Status}}"])
.output(); .output();
let output = match output { let output = match output {
@ -783,10 +787,10 @@ impl SystemdCollector {
let container_status = if status_str.contains("Up") { let container_status = if status_str.contains("Up") {
"active" "active"
} else if status_str.contains("Exited") { } else if status_str.contains("Exited") || status_str.contains("Created") {
"warning" // Match original: Exited → Warning, not inactive "inactive" // Stopped/created containers are inactive
} else { } else {
"failed" // Other states → failed "failed" // Other states (restarting, paused, dead) → failed
}; };
containers.push((format!("docker_{}", container_name), container_status.to_string())); containers.push((format!("docker_{}", container_name), container_status.to_string()));

View File

@ -1,6 +1,6 @@
[package] [package]
name = "cm-dashboard" name = "cm-dashboard"
version = "0.1.171" version = "0.1.172"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@ -1,6 +1,6 @@
[package] [package]
name = "cm-dashboard-shared" name = "cm-dashboard-shared"
version = "0.1.171" version = "0.1.172"
edition = "2021" edition = "2021"
[dependencies] [dependencies]