Implement nginx site status monitoring with unreachable detection

- Show 'unreachable' status for nginx sites that fail connection tests
- Set service status to error (red) for unreachable sites
- Display latency in milliseconds for responsive sites
- Properly count failed sites in service summary statistics
- Improve nginx site monitoring reliability and visibility
This commit is contained in:
Christoffer Martinsson 2025-10-14 20:19:39 +02:00
parent f10a4e25e6
commit 77795c44d3
2 changed files with 21 additions and 5 deletions

View File

@ -1358,9 +1358,15 @@ impl Collector for ServiceCollector {
// Measure latency for this site
let latency = self.measure_site_latency(site).await;
// Determine status and description based on latency measurement
let (site_status, site_description) = match latency {
Some(ms) => (ServiceStatus::Running, None),
None => (ServiceStatus::Stopped, Some(vec!["unreachable".to_string()])),
};
services.push(ServiceData {
name: site.clone(),
status: ServiceStatus::Running, // Assume sites are running if nginx is running
status: site_status,
memory_used_mb: 0.0,
memory_quota_mb: 0.0,
cpu_percent: 0.0,
@ -1369,11 +1375,17 @@ impl Collector for ServiceCollector {
disk_quota_gb: 0.0,
is_sandboxed: false, // Sub-services inherit parent sandbox status
is_sandbox_excluded: false,
description: None,
description: site_description,
sub_service: Some("nginx".to_string()),
latency_ms: latency,
});
healthy += 1;
// Update counters based on site status
match site_status {
ServiceStatus::Running => healthy += 1,
ServiceStatus::Stopped => failed += 1,
_ => degraded += 1,
}
}
}
}

View File

@ -108,8 +108,12 @@ fn render_metrics(
// Sub-services (nginx sites) only show name and status, no memory/CPU/disk data
// Add latency information for nginx sites if available
let service_name_with_latency = if let Some(parent) = &svc.sub_service {
if parent == "nginx" && svc.latency_ms.is_some() {
format!("{} {:.0}ms", svc.name, svc.latency_ms.unwrap())
if parent == "nginx" {
match (&svc.latency_ms, &svc.description) {
(Some(latency), _) => format!("{} {:.0}ms", svc.name, latency),
(None, Some(desc)) if !desc.is_empty() => format!("{} {}", svc.name, desc[0]),
_ => svc.name.clone(),
}
} else {
svc.name.clone()
}