Skip to content

Commit

Permalink
other: return None when mem_total is zero (#1667)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamartin9 authored Feb 8, 2025
1 parent ec1a4cb commit 22fbd7d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/collection/memory/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ pub(crate) fn get_arc_usage() -> Option<MemHarvest> {
}
};

Some(MemHarvest {
total_bytes: mem_total,
used_bytes: mem_used,
})
if mem_total > 0 {
Some(MemHarvest {
total_bytes: mem_total,
used_bytes: mem_used,
})
} else {
None
}
}
13 changes: 8 additions & 5 deletions src/collection/memory/sysinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ pub(crate) fn get_ram_usage(sys: &System) -> Option<MemHarvest> {
pub(crate) fn get_swap_usage(sys: &System) -> Option<MemHarvest> {
let mem_used = sys.used_swap();
let mem_total = sys.total_swap();

Some(MemHarvest {
used_bytes: mem_used,
total_bytes: mem_total,
})
if mem_total > 0 {
Some(MemHarvest {
used_bytes: mem_used,
total_bytes: mem_total,
})
} else {
None
}
}

/// Returns cache usage. sysinfo has no way to do this directly but it should
Expand Down

0 comments on commit 22fbd7d

Please sign in to comment.