Implement nginx site latency monitoring and improve disk usage display

Agent improvements:
- Add reqwest dependency for HTTP latency testing
- Implement measure_site_latency() function for nginx sites
- Add latency_ms field to ServiceData structure
- Measure response times for nginx sites using HEAD requests
- Handle connection failures gracefully with 5-second timeout
- Use HTTPS for external sites, HTTP for localhost

Dashboard improvements:
- Add latency_ms field to ServiceInfo structure
- Display latency for nginx sites: "docker.cmtec.se 134ms"
- Only show latency for nginx sub-services, not other services
- Change disk usage "0" to "<1MB" for better readability

The Services widget now shows:
- Nginx sites with response times when measurable
- Cleaner disk usage formatting for small values
- Improved user experience with meaningful latency data
This commit is contained in:
2025-10-14 19:38:36 +02:00
parent c6e8749ddd
commit fd8aa0678e
4 changed files with 61 additions and 4 deletions

View File

@@ -128,6 +128,8 @@ pub struct ServiceInfo {
pub description: Option<Vec<String>>,
#[serde(default)]
pub sub_service: Option<String>,
#[serde(default)]
pub latency_ms: Option<f32>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]

View File

@@ -105,12 +105,23 @@ fn render_metrics(
};
if svc.sub_service.is_some() {
// Sub-services only show name and status, no memory/CPU/disk/sandbox data
// 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())
} else {
svc.name.clone()
}
} else {
svc.name.clone()
};
data.add_row_with_sub_service(
Some(WidgetStatus::new(status_level)),
description,
vec![
svc.name.clone(),
service_name_with_latency,
"".to_string(),
"".to_string(),
"".to_string(),
@@ -139,7 +150,7 @@ fn render_metrics(
fn format_bytes(mb: f32) -> String {
if mb < 0.1 {
"0".to_string()
"<1MB".to_string()
} else if mb < 1.0 {
format!("{:.0}kB", mb * 1000.0)
} else if mb < 1000.0 {