Skip to content

Commit

Permalink
fix: memory display, closes #33
Browse files Browse the repository at this point in the history
Memory usage calculation now uses correct methodology
  • Loading branch information
mrjackwills committed Feb 12, 2024
1 parent 616338b commit a182d40
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/docker_data/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bollard::{
container::{
ListContainersOptions, LogsOptions, RemoveContainerOptions, StartContainerOptions, Stats,
StatsOptions,
ListContainersOptions, LogsOptions, MemoryStatsStats, RemoveContainerOptions,
StartContainerOptions, Stats, StatsOptions,
},
service::ContainerSummary,
Docker,
Expand Down Expand Up @@ -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
};
Expand Down

0 comments on commit a182d40

Please sign in to comment.