Add service_type field to separate data from presentation
Changes: - Add service_type field to SubServiceData: 'nginx_site', 'container', 'image' - Agent sends pure data without display formatting - Dashboard checks service_type to decide presentation - Docker images now display without status icon (service_type='image') - Remove unused image_size_str from docker images tuple Clean separation: agent provides data, dashboard handles display logic.
This commit is contained in:
@@ -113,6 +113,7 @@ impl SystemdCollector {
|
||||
name: site_name.clone(),
|
||||
service_status: self.calculate_service_status(&site_name, &site_status),
|
||||
metrics,
|
||||
service_type: "nginx_site".to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -128,12 +129,13 @@ impl SystemdCollector {
|
||||
name: container_name.clone(),
|
||||
service_status: self.calculate_service_status(&container_name, &container_status),
|
||||
metrics,
|
||||
service_type: "container".to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
// Add Docker images
|
||||
let docker_images = self.get_docker_images();
|
||||
for (image_name, image_status, image_size_str, image_size_mb) in docker_images {
|
||||
for (image_name, image_status, image_size_mb) in docker_images {
|
||||
let mut metrics = Vec::new();
|
||||
metrics.push(SubServiceMetric {
|
||||
label: "size".to_string(),
|
||||
@@ -142,9 +144,10 @@ impl SystemdCollector {
|
||||
});
|
||||
|
||||
sub_services.push(SubServiceData {
|
||||
name: format!("{} ({})", image_name, image_size_str),
|
||||
name: image_name.to_string(),
|
||||
service_status: self.calculate_service_status(&image_name, &image_status),
|
||||
metrics,
|
||||
service_type: "image".to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -824,7 +827,7 @@ impl SystemdCollector {
|
||||
}
|
||||
|
||||
/// Get docker images as sub-services
|
||||
fn get_docker_images(&self) -> Vec<(String, String, String, f32)> {
|
||||
fn get_docker_images(&self) -> Vec<(String, String, f32)> {
|
||||
let mut images = Vec::new();
|
||||
// Check if docker is available (cm-agent user is in docker group) with 3 second timeout
|
||||
let output = Command::new("timeout")
|
||||
@@ -865,9 +868,8 @@ impl SystemdCollector {
|
||||
let size_mb = self.parse_docker_size(size_str);
|
||||
|
||||
images.push((
|
||||
format!("I {}", image_name),
|
||||
image_name.to_string(),
|
||||
"inactive".to_string(), // Images are informational - use inactive for neutral display
|
||||
size_str.to_string(),
|
||||
size_mb
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user