From b0d3d85fb9a38557b9d070d05dd9ddd2c4a5cca1 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Tue, 14 Oct 2025 18:21:45 +0200 Subject: [PATCH] Improve services widget column headers and value formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update column headers to be more concise: RAM (GB) → RAM, CPU (%) → CPU, Disk (GB) → Disk - Change sandbox column "no(ok)" to "-" for excluded services - Implement smart unit formatting for memory and disk values (kB/MB/GB) - Display quotas as (XG) format without decimals when limits exist - Add format_bytes() helper for consistent unit display across metrics --- dashboard/src/ui/services.rs | 40 ++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/dashboard/src/ui/services.rs b/dashboard/src/ui/services.rs index 50aaf43..d2a7ce1 100644 --- a/dashboard/src/ui/services.rs +++ b/dashboard/src/ui/services.rs @@ -50,7 +50,7 @@ fn render_metrics( let mut data = WidgetData::new( title, Some(WidgetStatus::new(widget_status)), - vec!["Service".to_string(), "RAM (GB)".to_string(), "CPU (%)".to_string(), "Disk (GB)".to_string(), "SB".to_string()] + vec!["Service".to_string(), "RAM".to_string(), "CPU".to_string(), "Disk".to_string(), "SB".to_string()] ); @@ -140,17 +140,26 @@ fn render_metrics( -fn format_memory_value(used: f32, quota: f32) -> String { - let used_gb = used / 1000.0; - let quota_gb = quota / 1000.0; - - // Show usage/quota format only if quota exists, otherwise just usage - if quota > 0.05 { - format!("{:.1}/{:.1}", used_gb, quota_gb) - } else if used > 0.05 { - format!("{:.1}", used_gb) +fn format_bytes(mb: f32) -> String { + if mb < 0.1 { + "0".to_string() + } else if mb < 1.0 { + format!("{:.0} kB", mb * 1000.0) + } else if mb < 1000.0 { + format!("{:.0} MB", mb) } else { - "0.0".to_string() + format!("{:.1} GB", mb / 1000.0) + } +} + +fn format_memory_value(used: f32, quota: f32) -> String { + let used_value = format_bytes(used); + + if quota > 0.05 { + let quota_gb = quota / 1000.0; + format!("{} ({}G)", used_value, quota_gb as u32) + } else { + used_value } } @@ -163,11 +172,12 @@ fn format_cpu_value(cpu_percent: f32) -> String { } fn format_disk_value(used: f32, quota: f32) -> String { - // Show usage/quota format only if quota exists, otherwise just usage + let used_value = format_bytes(used * 1000.0); // Convert GB to MB for format_bytes + if quota > 0.05 { - format!("{:.1}/{:.1}", used, quota) + format!("{} ({}G)", used_value, quota as u32) } else { - format!("{:.1}", used) + used_value } } @@ -175,7 +185,7 @@ fn format_sandbox_value(is_sandboxed: bool, is_excluded: bool) -> String { if is_sandboxed { "yes".to_string() } else if is_excluded { - "no(ok)".to_string() // Excluded services don't need sandboxing + "-".to_string() // Excluded services don't need sandboxing } else { "no".to_string() // Services that should be sandboxed but aren't }