This commit is contained in:
Christoffer Martinsson 2025-10-13 08:38:57 +02:00
parent 5e8a0ce108
commit 859df2dec1
3 changed files with 22 additions and 47 deletions

View File

@ -114,7 +114,7 @@ impl ServiceCollector {
sandbox_limit: None, // TODO: Implement sandbox limit detection sandbox_limit: None, // TODO: Implement sandbox limit detection
disk_used_gb, disk_used_gb,
description, description,
sub_service: false, sub_service: None,
}) })
} }
@ -834,7 +834,7 @@ impl Collector for ServiceCollector {
sandbox_limit: None, sandbox_limit: None,
disk_used_gb: 0.0, disk_used_gb: 0.0,
description: None, description: None,
sub_service: true, sub_service: Some("nginx".to_string()),
}); });
healthy += 1; healthy += 1;
} }
@ -855,7 +855,7 @@ impl Collector for ServiceCollector {
sandbox_limit: None, sandbox_limit: None,
disk_used_gb: 0.0, disk_used_gb: 0.0,
description: None, description: None,
sub_service: false, sub_service: None,
}); });
tracing::warn!("Failed to collect metrics for service {}: {}", service, e); tracing::warn!("Failed to collect metrics for service {}: {}", service, e);
} }
@ -915,7 +915,7 @@ struct ServiceData {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
description: Option<Vec<String>>, description: Option<Vec<String>>,
#[serde(default)] #[serde(default)]
sub_service: bool, sub_service: Option<String>,
} }
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]

View File

@ -117,7 +117,7 @@ pub struct ServiceInfo {
#[serde(default)] #[serde(default)]
pub description: Option<Vec<String>>, pub description: Option<Vec<String>>,
#[serde(default)] #[serde(default)]
pub sub_service: bool, pub sub_service: Option<String>,
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]

View File

@ -69,42 +69,25 @@ fn render_metrics(
return; return;
} }
// Sort services but preserve nginx + sites grouping let mut services = metrics.services.clone();
let mut services = Vec::new(); services.sort_by(|a, b| {
let mut regular_services = Vec::new(); // First, determine the primary service name for grouping
let mut nginx_group = Vec::new(); let primary_a = a.sub_service.as_ref().unwrap_or(&a.name);
let mut in_nginx_group = false; let primary_b = b.sub_service.as_ref().unwrap_or(&b.name);
for svc in metrics.services.iter() { // Sort by primary service name first
if svc.name == "nginx" { match primary_a.cmp(primary_b) {
// Start nginx group std::cmp::Ordering::Equal => {
in_nginx_group = true; // Same primary service, put parent service first, then sub-services alphabetically
nginx_group.push(svc.clone()); match (a.sub_service.as_ref(), b.sub_service.as_ref()) {
} else if in_nginx_group && svc.sub_service { (None, Some(_)) => std::cmp::Ordering::Less, // Parent comes before sub-services
// Add nginx site to group (Some(_), None) => std::cmp::Ordering::Greater, // Sub-services come after parent
nginx_group.push(svc.clone()); _ => a.name.cmp(&b.name), // Both same type, sort by name
} else { }
// End nginx group if we were in one
if in_nginx_group {
in_nginx_group = false;
services.append(&mut nginx_group);
} }
regular_services.push(svc.clone()); other => other, // Different primary services, sort alphabetically
} }
}
// Add any remaining nginx group
if !nginx_group.is_empty() {
services.append(&mut nginx_group);
}
// Sort regular services and add them
regular_services.sort_by(|a, b| {
status_weight(&a.status)
.cmp(&status_weight(&b.status))
.then_with(|| a.name.cmp(&b.name))
}); });
services.append(&mut regular_services);
for svc in services { for svc in services {
let status_level = match svc.status { let status_level = match svc.status {
@ -121,7 +104,7 @@ fn render_metrics(
vec![] vec![]
}; };
if svc.sub_service { if svc.sub_service.is_some() {
// Sub-services only show name and status, no memory/CPU/disk data // Sub-services only show name and status, no memory/CPU/disk data
data.add_row( data.add_row(
Some(WidgetStatus::new(status_level)), Some(WidgetStatus::new(status_level)),
@ -151,14 +134,6 @@ fn render_metrics(
render_widget_data(frame, area, data); render_widget_data(frame, area, data);
} }
fn status_weight(status: &ServiceStatus) -> i32 {
match status {
ServiceStatus::Stopped => 0,
ServiceStatus::Degraded => 1,
ServiceStatus::Restarting => 2,
ServiceStatus::Running => 3,
}
}
fn format_memory_value(used: f32, quota: f32) -> String { fn format_memory_value(used: f32, quota: f32) -> String {