From 22fbd7d630390f1e3070259b6212a0fca97eb176 Mon Sep 17 00:00:00 2001 From: Justin Martin Date: Fri, 7 Feb 2025 19:02:07 -0500 Subject: [PATCH] other: return `None` when `mem_total` is zero (#1667) --- src/collection/memory/arc.rs | 12 ++++++++---- src/collection/memory/sysinfo.rs | 13 ++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/collection/memory/arc.rs b/src/collection/memory/arc.rs index 46251d64..3f6eefe0 100644 --- a/src/collection/memory/arc.rs +++ b/src/collection/memory/arc.rs @@ -63,8 +63,12 @@ pub(crate) fn get_arc_usage() -> Option { } }; - 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 + } } diff --git a/src/collection/memory/sysinfo.rs b/src/collection/memory/sysinfo.rs index f7540b23..fb67b718 100644 --- a/src/collection/memory/sysinfo.rs +++ b/src/collection/memory/sysinfo.rs @@ -19,11 +19,14 @@ pub(crate) fn get_ram_usage(sys: &System) -> Option { pub(crate) fn get_swap_usage(sys: &System) -> Option { 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