From cfd9fef3e95561b0bd3dc97f25a06e260cb71817 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Sat, 9 Aug 2025 17:52:01 +0200 Subject: [PATCH] =?UTF-8?q?trying=20different=20st=C3=B6ff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WatcherAgent/src/hardware/cpu.rs | 2 +- WatcherAgent/src/hardware/disk.rs | 6 +----- WatcherAgent/src/hardware/gpu.rs | 6 +++--- WatcherAgent/src/hardware/mod.rs | 8 ++++---- WatcherAgent/src/hardware/network.rs | 6 +++--- WatcherAgent/src/main.rs | 10 +++++----- 6 files changed, 17 insertions(+), 21 deletions(-) diff --git a/WatcherAgent/src/hardware/cpu.rs b/WatcherAgent/src/hardware/cpu.rs index f876292..59684b2 100644 --- a/WatcherAgent/src/hardware/cpu.rs +++ b/WatcherAgent/src/hardware/cpu.rs @@ -242,7 +242,7 @@ pub async fn get_cpu_temp() -> Result> { (*services).Release(); (*locator).Release(); - return Ok(result.unwrap() as f64).map_err(|e| e.into()); + Ok(result.unwrap() as f64).map_err(|e| e.into()) } } diff --git a/WatcherAgent/src/hardware/disk.rs b/WatcherAgent/src/hardware/disk.rs index 92ff559..30a6cbc 100644 --- a/WatcherAgent/src/hardware/disk.rs +++ b/WatcherAgent/src/hardware/disk.rs @@ -132,11 +132,7 @@ pub fn get_disk_utitlization() -> Result<(f64, f64, f64, f64), Box> { } pub fn _get_disk_temp_for_component(component: &Component) -> Option { - if let Some(temp) = component.temperature() { - Some(temp as f64) - } else { - None - } + component.temperature().map(|temp| temp as f64) } pub fn _get_disk_load_for_disk(disk: &Disk) -> Result<(f64, f64, f64, f64), Box> { diff --git a/WatcherAgent/src/hardware/gpu.rs b/WatcherAgent/src/hardware/gpu.rs index a041759..f11db0b 100644 --- a/WatcherAgent/src/hardware/gpu.rs +++ b/WatcherAgent/src/hardware/gpu.rs @@ -21,8 +21,8 @@ pub async fn get_gpu_info() -> Result> { name: Some(gpu_name), current_load: get_gpu_load(&device).ok(), current_temp: get_gpu_temp(&device).ok(), - vram_total: Some(total as f64), - vram_used: Some(used as f64), + vram_total: Some(total), + vram_used: Some(used), }) } @@ -72,7 +72,7 @@ fn fallback_gpu_name() -> Option { #[cfg(target_os = "windows")] { let output = std::process::Command::new("wmic") - .args(&["path", "win32_VideoController", "get", "name"]) + .args(["path", "win32_VideoController", "get", "name"]) .output() .ok()?; Some( diff --git a/WatcherAgent/src/hardware/mod.rs b/WatcherAgent/src/hardware/mod.rs index 779be3d..50039cb 100644 --- a/WatcherAgent/src/hardware/mod.rs +++ b/WatcherAgent/src/hardware/mod.rs @@ -1,11 +1,11 @@ //use anyhow::Result; use std::error::Error; -pub(crate) mod cpu; -pub(crate) mod disk; +pub mod cpu; +pub mod disk; pub mod gpu; -pub(crate) mod memory; -pub(crate) mod network; +pub mod memory; +pub mod network; pub use cpu::get_cpu_info; pub use disk::get_disk_info; diff --git a/WatcherAgent/src/hardware/network.rs b/WatcherAgent/src/hardware/network.rs index c7c1e6e..b90921b 100644 --- a/WatcherAgent/src/hardware/network.rs +++ b/WatcherAgent/src/hardware/network.rs @@ -53,8 +53,8 @@ pub async fn get_network_info(monitor: &mut NetworkMonitor) -> Result Result<(u64, u64), Box> { } if rx_total == 0 && tx_total == 0 { - return Err(anyhow::anyhow!("No network data available").into()); + Err(anyhow::anyhow!("No network data available").into()) } else { Ok((rx_total, tx_total)) } diff --git a/WatcherAgent/src/main.rs b/WatcherAgent/src/main.rs index d7539b5..3ace2f6 100644 --- a/WatcherAgent/src/main.rs +++ b/WatcherAgent/src/main.rs @@ -1,12 +1,12 @@ /// WatcherAgent - A Rust-based system monitoring agent /// This agent collects hardware metrics and sends them to a backend server. /// It supports CPU, GPU, RAM, disk, and network metrics. -mod api; -mod hardware; -mod metrics; -mod models; +pub mod api; +pub mod hardware; +pub mod metrics; +pub mod models; -use crate::hardware::gpu; +pub use crate::hardware::gpu; use anyhow::Result; use std::error::Error;