From a182d40a7463164ef5dcac379d1a1768d77209d2 Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Mon, 12 Feb 2024 17:40:28 +0000 Subject: [PATCH] fix: memory display, closes #33 Memory usage calculation now uses correct methodology --- src/docker_data/mod.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/docker_data/mod.rs b/src/docker_data/mod.rs index 18c2544..302f0d5 100644 --- a/src/docker_data/mod.rs +++ b/src/docker_data/mod.rs @@ -1,7 +1,7 @@ use bollard::{ container::{ - ListContainersOptions, LogsOptions, RemoveContainerOptions, StartContainerOptions, Stats, - StatsOptions, + ListContainersOptions, LogsOptions, MemoryStatsStats, RemoveContainerOptions, + StartContainerOptions, Stats, StatsOptions, }, service::ContainerSummary, Docker, @@ -121,8 +121,19 @@ impl DockerData { .take(1); while let Some(Ok(stats)) = stream.next().await { + // Memory stats are only collected if the container is alive - is this the behaviour we want? let mem_stat = if state.is_alive() { - Some(stats.memory_stats.usage.unwrap_or_default()) + let mem_cache = stats.memory_stats.stats.map_or(0, |i| match i { + MemoryStatsStats::V1(x) => x.inactive_file, + MemoryStatsStats::V2(x) => x.inactive_file, + }); + Some( + stats + .memory_stats + .usage + .unwrap_or_default() + .saturating_sub(mem_cache), + ) } else { None };