From 4be1223a8d4a7101a7cb974194ba6bbfd45cb7a2 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Tue, 14 Oct 2025 10:23:16 +0200 Subject: [PATCH] Update services widget memory display and formatting Improve services widget to show consistent usage/total format for both RAM and Disk columns, using system totals when no service quotas exist. Changes: - Change column header from "Memory (GB)" to "RAM (GB)" - Remove "GB" units from memory values (units now in header) - Add system memory total detection from /proc/meminfo - Use system memory total as default quota for services without limits - Services now show "5.2/32.0" format for both RAM and disk Both RAM and Disk columns now consistently display usage/quota format where quota is either service-specific limit or system total capacity. --- agent/src/collectors/service.rs | 32 +++++++++++++++++++++++++++++++- dashboard/src/ui/services.rs | 8 ++++---- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/agent/src/collectors/service.rs b/agent/src/collectors/service.rs index 2eb8fc6..2c68839 100644 --- a/agent/src/collectors/service.rs +++ b/agent/src/collectors/service.rs @@ -286,6 +286,30 @@ impl ServiceCollector { } + async fn get_system_memory_total(&self) -> Result { + // Read /proc/meminfo to get total system memory + let meminfo = fs::read_to_string("/proc/meminfo") + .await + .map_err(|e| CollectorError::IoError { + message: e.to_string(), + })?; + + for line in meminfo.lines() { + if let Some(mem_total_line) = line.strip_prefix("MemTotal:") { + let parts: Vec<&str> = mem_total_line.trim().split_whitespace().collect(); + if let Some(mem_kb_str) = parts.first() { + if let Ok(mem_kb) = mem_kb_str.parse::() { + return Ok(mem_kb / 1024.0); // Convert KB to MB + } + } + } + } + + Err(CollectorError::ParseError { + message: "Could not parse total memory".to_string(), + }) + } + async fn get_disk_usage(&self) -> Result { let output = Command::new("/run/current-system/sw/bin/df") .args(["-BG", "--output=size,used,avail", "/"]) @@ -1185,12 +1209,18 @@ impl Collector for ServiceCollector { used_gb: 0.0, }); - // Set disk quota to system total capacity for services that don't have specific quotas + // Get system memory total for services without memory quotas + let system_memory_total_mb = self.get_system_memory_total().await.unwrap_or(8192.0); // Default 8GB + + // Set quotas to system totals for services that don't have specific quotas let system_disk_capacity_gb = disk_usage.total_capacity_gb; for service in &mut services { if service.disk_quota_gb == 0.0 { service.disk_quota_gb = system_disk_capacity_gb; } + if service.memory_quota_mb == 0.0 { + service.memory_quota_mb = system_memory_total_mb; + } } // Calculate overall services status diff --git a/dashboard/src/ui/services.rs b/dashboard/src/ui/services.rs index 8c80d74..dfd90a1 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(), "Memory (GB)".to_string(), "CPU".to_string(), "Disk".to_string()] + vec!["Service".to_string(), "RAM (GB)".to_string(), "CPU".to_string(), "Disk".to_string()] ); @@ -142,11 +142,11 @@ fn format_memory_value(used: f32, quota: f32) -> String { let quota_gb = quota / 1000.0; if quota > 0.05 { - format!("{:.1}/{:.1} GB", used_gb, quota_gb) + format!("{:.1}/{:.1}", used_gb, quota_gb) } else if used > 0.05 { - format!("{:.1} GB", used_gb) + format!("{:.1}", used_gb) } else { - "0.0 GB".to_string() + "0.0".to_string() } }