diff --git a/Cargo.toml b/Cargo.toml index 63c4eaa..7144d93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ rlimit = "0.10.0" [target.'cfg(target_os = "linux")'.dependencies] once_cell = "1.13.1" -procfs = { version = "0.15.1", default-features = false } +procfs = { version = "0.16.0", default-features = false } [target.'cfg(target_os = "windows")'.dependencies.windows] version = "0.51.0" diff --git a/src/collector/linux.rs b/src/collector/linux.rs index 433355e..1cfdab3 100644 --- a/src/collector/linux.rs +++ b/src/collector/linux.rs @@ -1,4 +1,5 @@ use once_cell::sync::Lazy; +use procfs::prelude::*; use procfs::process::{LimitValue, Process}; use super::Metrics; @@ -15,7 +16,7 @@ pub fn collect() -> Metrics { Some(bts + ((stat.starttime as f64) / *TICKS_PER_SECOND) as u64); } metrics.cpu_seconds_total = Some((stat.utime + stat.stime) as f64 / *TICKS_PER_SECOND); - metrics.resident_memory_bytes = Some(stat.rss_bytes()); + metrics.resident_memory_bytes = Some(stat.rss_bytes().get()); metrics.virtual_memory_bytes = Some(stat.vsize); metrics.threads = Some(stat.num_threads as u64); } diff --git a/src/collector/windows.rs b/src/collector/windows.rs index b305e08..102d854 100644 --- a/src/collector/windows.rs +++ b/src/collector/windows.rs @@ -55,9 +55,13 @@ pub fn collect() -> Metrics { metrics.cpu_seconds_total = cpu_seconds_total; let (virtual_memory_bytes, resident_memory_bytes) = { - let memcounters = &PROCESS_MEMORY_COUNTERS_EX::default(); - let memcounters = memcounters as *const _ as *mut PROCESS_MEMORY_COUNTERS; - let memcounters = &mut *memcounters; + // We need to use PROCESS_MEMORY_COUNTERS_EX but GetProcessMemoryInfoEx is not provided + // thus we need to cast PROCESS_MEMORY_COUNTERS_EX into PROCESS_MEMORY_COUNTERS to use + // it with GetProcessMemoryInfo. + let memcounters = { + let m = &PROCESS_MEMORY_COUNTERS_EX::default(); + m as *const _ as *mut PROCESS_MEMORY_COUNTERS + }; let cb = size_of::(); let ret = GetProcessMemoryInfo(h, memcounters, cb as u32); if ret.is_ok() {