From 4d8b5c39e5b344ed8c4fcfe8a2c0e68cc99e4af4 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Thu, 30 Oct 2025 13:33:47 +0100 Subject: [PATCH] docker stats nightmare --- WatcherAgent/src/docker/stats/cpu.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/WatcherAgent/src/docker/stats/cpu.rs b/WatcherAgent/src/docker/stats/cpu.rs index 3eab6eb..69eae23 100644 --- a/WatcherAgent/src/docker/stats/cpu.rs +++ b/WatcherAgent/src/docker/stats/cpu.rs @@ -51,19 +51,19 @@ pub async fn get_single_container_cpu_stats( if let (Some(cpu_usage), Some(pre_cpu_usage)) = (&cpu_stats.cpu_usage, &precpu_stats.cpu_usage) { - let cpu_delta = cpu_usage + let cpu_delta: f64 = cpu_usage .total_usage .unwrap_or(0) - .saturating_sub(pre_cpu_usage.total_usage.unwrap_or(0)); + .saturating_sub(pre_cpu_usage.total_usage.unwrap_or(0)) as f64; - let system_delta = cpu_stats + let system_delta: f64 = cpu_stats .system_cpu_usage .unwrap_or(0) - .saturating_sub(precpu_stats.system_cpu_usage.unwrap_or(0)); + .saturating_sub(precpu_stats.system_cpu_usage.unwrap_or(0)) as f64; let online_cpus = cpu_stats.online_cpus.unwrap_or(1); - let cpu_percent = if system_delta > 0 && online_cpus > 0 { + let cpu_percent = if system_delta > 0.0 && online_cpus > 0 { (cpu_delta as f64 / system_delta as f64) * online_cpus as f64 * 100.0 } else { 0.0