Improve services widget column headers and value formatting

- 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
This commit is contained in:
Christoffer Martinsson 2025-10-14 18:21:45 +02:00
parent c6d5a3f2a5
commit b0d3d85fb9

View File

@ -50,7 +50,7 @@ fn render_metrics(
let mut data = WidgetData::new( let mut data = WidgetData::new(
title, title,
Some(WidgetStatus::new(widget_status)), 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 { fn format_bytes(mb: f32) -> String {
let used_gb = used / 1000.0; if mb < 0.1 {
let quota_gb = quota / 1000.0; "0".to_string()
} else if mb < 1.0 {
// Show usage/quota format only if quota exists, otherwise just usage format!("{:.0} kB", mb * 1000.0)
if quota > 0.05 { } else if mb < 1000.0 {
format!("{:.1}/{:.1}", used_gb, quota_gb) format!("{:.0} MB", mb)
} else if used > 0.05 {
format!("{:.1}", used_gb)
} else { } 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 { 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 { if quota > 0.05 {
format!("{:.1}/{:.1}", used, quota) format!("{} ({}G)", used_value, quota as u32)
} else { } else {
format!("{:.1}", used) used_value
} }
} }
@ -175,7 +185,7 @@ fn format_sandbox_value(is_sandboxed: bool, is_excluded: bool) -> String {
if is_sandboxed { if is_sandboxed {
"yes".to_string() "yes".to_string()
} else if is_excluded { } else if is_excluded {
"no(ok)".to_string() // Excluded services don't need sandboxing "-".to_string() // Excluded services don't need sandboxing
} else { } else {
"no".to_string() // Services that should be sandboxed but aren't "no".to_string() // Services that should be sandboxed but aren't
} }