From e195b056b065f23e3840ad547b88512e863d0964 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 18 Jan 2022 11:47:31 +0100 Subject: [PATCH] Update sysinfo version --- Cargo.lock | 9 ++++----- Cargo.toml | 2 +- src/app/data_harvester.rs | 2 +- src/app/data_harvester/network/sysinfo.rs | 6 +++--- src/app/data_harvester/processes/macos.rs | 12 ++++++------ src/app/data_harvester/processes/windows.rs | 12 ++++++------ src/app/data_harvester/temperature/sysinfo.rs | 12 +++++------- 7 files changed, 26 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2dedf3d1..02838794 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -887,9 +887,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.104" +version = "0.2.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b2f96d100e1cf1929e7719b7edb3b90ab5298072638fccd77be9ce942ecdfce" +checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" [[package]] name = "lock_api" @@ -1394,13 +1394,12 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.18.2" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d404aefa651a24a7f2a1190fec9fb6380ba84ac511a6fefad79eb0e63d39a97d" +checksum = "9e757000a4bed2b1be9be65a3f418b9696adf30bb419214c73997422de73a591" dependencies = [ "cfg-if", "core-foundation-sys 0.8.3", - "doc-comment", "libc", "ntapi", "once_cell", diff --git a/Cargo.toml b/Cargo.toml index ce0f843f..0c7f2304 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,7 +50,7 @@ once_cell = "1.5.2" regex = "1.5.4" serde = { version = "1.0.125", features = ["derive"] } # Sysinfo is still used in Linux for the ProcessStatus -sysinfo = "0.18.2" +sysinfo = "0.23.0" thiserror = "1.0.24" time = { version = "0.3.5", features = ["formatting", "macros"] } toml = "0.5.8" diff --git a/src/app/data_harvester.rs b/src/app/data_harvester.rs index 79427a9f..59e01237 100644 --- a/src/app/data_harvester.rs +++ b/src/app/data_harvester.rs @@ -144,7 +144,7 @@ impl DataCollector { #[cfg(not(target_os = "linux"))] { self.sys.refresh_memory(); - self.mem_total_kb = self.sys.get_total_memory(); + self.mem_total_kb = self.sys.total_memory(); // TODO: Would be good to get this and network list running on a timer instead...? // Refresh components list once... diff --git a/src/app/data_harvester/network/sysinfo.rs b/src/app/data_harvester/network/sysinfo.rs index cb8e260a..634cf779 100644 --- a/src/app/data_harvester/network/sysinfo.rs +++ b/src/app/data_harvester/network/sysinfo.rs @@ -17,7 +17,7 @@ pub async fn get_network_data( let mut total_rx: u64 = 0; let mut total_tx: u64 = 0; - let networks = sys.get_networks(); + let networks = sys.networks(); for (name, network) in networks { let to_keep = if let Some(filter) = filter { let mut ret = filter.is_list_ignored; @@ -33,8 +33,8 @@ pub async fn get_network_data( }; if to_keep { - total_rx += network.get_total_received() * 8; - total_tx += network.get_total_transmitted() * 8; + total_rx += network.total_received() * 8; + total_tx += network.total_transmitted() * 8; } } diff --git a/src/app/data_harvester/processes/macos.rs b/src/app/data_harvester/processes/macos.rs index f0c3980d..f08e17ca 100644 --- a/src/app/data_harvester/processes/macos.rs +++ b/src/app/data_harvester/processes/macos.rs @@ -1,7 +1,7 @@ //! Process data collection for macOS. Uses sysinfo. use super::ProcessHarvest; -use sysinfo::{ProcessExt, ProcessStatus, ProcessorExt, System, SystemExt}; +use sysinfo::{PidExt, ProcessExt, ProcessStatus, ProcessorExt, System, SystemExt}; fn get_macos_process_cpu_usage( pids: &[i32], @@ -38,9 +38,9 @@ pub fn get_process_data( sys: &System, use_current_cpu_total: bool, mem_total_kb: u64, ) -> crate::utils::error::Result> { let mut process_vector: Vec = Vec::new(); - let process_hashmap = sys.get_processes(); - let cpu_usage = sys.get_global_processor_info().get_cpu_usage() as f64 / 100.0; - let num_processors = sys.get_processors().len() as f64; + let process_hashmap = sys.processes(); + let cpu_usage = sys.global_processor_info().cpu_usage() as f64 / 100.0; + let num_processors = sys.processors().len() as f64; for process_val in process_hashmap.values() { let name = if process_val.name().is_empty() { let process_cmd = process_val.cmd(); @@ -87,8 +87,8 @@ pub fn get_process_data( let disk_usage = process_val.disk_usage(); process_vector.push(ProcessHarvest { - pid: process_val.pid(), - parent_pid: process_val.parent(), + pid: process_val.pid().as_u32() as _, + parent_pid: process_val.parent().map(|p| p.as_u32() as _), name, command, mem_usage_percent: if mem_total_kb > 0 { diff --git a/src/app/data_harvester/processes/windows.rs b/src/app/data_harvester/processes/windows.rs index 08cde500..af9ead5f 100644 --- a/src/app/data_harvester/processes/windows.rs +++ b/src/app/data_harvester/processes/windows.rs @@ -1,15 +1,15 @@ //! Process data collection for Windows. Uses sysinfo. use super::ProcessHarvest; -use sysinfo::{ProcessExt, ProcessorExt, System, SystemExt}; +use sysinfo::{PidExt, ProcessExt, ProcessorExt, System, SystemExt}; pub fn get_process_data( sys: &System, use_current_cpu_total: bool, mem_total_kb: u64, ) -> crate::utils::error::Result> { let mut process_vector: Vec = Vec::new(); - let process_hashmap = sys.get_processes(); - let cpu_usage = sys.get_global_processor_info().get_cpu_usage() as f64 / 100.0; - let num_processors = sys.get_processors().len() as f64; + let process_hashmap = sys.processes(); + let cpu_usage = sys.global_processor_info().cpu_usage() as f64 / 100.0; + let num_processors = sys.processors().len() as f64; for process_val in process_hashmap.values() { let name = if process_val.name().is_empty() { let process_cmd = process_val.cmd(); @@ -56,8 +56,8 @@ pub fn get_process_data( let disk_usage = process_val.disk_usage(); process_vector.push(ProcessHarvest { - pid: process_val.pid(), - parent_pid: process_val.parent(), + pid: process_val.pid().as_u32() as _, + parent_pid: process_val.parent().map(|p| p.as_u32() as _), name, command, mem_usage_percent: if mem_total_kb > 0 { diff --git a/src/app/data_harvester/temperature/sysinfo.rs b/src/app/data_harvester/temperature/sysinfo.rs index f0f79b1a..bc246636 100644 --- a/src/app/data_harvester/temperature/sysinfo.rs +++ b/src/app/data_harvester/temperature/sysinfo.rs @@ -22,20 +22,18 @@ pub async fn get_temperature_data( let mut temperature_vec: Vec = Vec::new(); - let sensor_data = sys.get_components(); + let sensor_data = sys.components(); for component in sensor_data { - let name = component.get_label().to_string(); + let name = component.label().to_string(); if is_temp_filtered(filter, &name) { temperature_vec.push(TempHarvest { name, temperature: match temp_type { - TemperatureType::Celsius => component.get_temperature(), - TemperatureType::Kelvin => { - convert_celsius_to_kelvin(component.get_temperature()) - } + TemperatureType::Celsius => component.temperature(), + TemperatureType::Kelvin => convert_celsius_to_kelvin(component.temperature()), TemperatureType::Fahrenheit => { - convert_celsius_to_fahrenheit(component.get_temperature()) + convert_celsius_to_fahrenheit(component.temperature()) } }, });