diff --git a/WatcherAgent/src/hardware/cpu.rs b/WatcherAgent/src/hardware/cpu.rs index 73efa06..2c5cc0a 100644 --- a/WatcherAgent/src/hardware/cpu.rs +++ b/WatcherAgent/src/hardware/cpu.rs @@ -1,6 +1,5 @@ use anyhow::Result; use std::error::Error; -//use std::result::Result; use sysinfo::System; #[derive(Debug)] @@ -9,13 +8,17 @@ pub struct CpuInfo { pub cores: Option, pub current_load: Option, pub current_temp: Option, + pub uptime: Option, + pub host_name: Option, } pub async fn get_cpu_info() -> Result> { - let mut sys = System::new(); - sys.refresh_cpu_all(); + let mut sys = System::new_all(); let cpus = sys.cpus(); + let uptime = System::uptime() as f64; + + let host_name = System::host_name().unwrap_or_else(|| "unknown".to_string()); Ok(CpuInfo { name: Some( cpus.first() @@ -25,6 +28,8 @@ pub async fn get_cpu_info() -> Result> { cores: Some(cpus.len() as i32), current_load: get_cpu_load(&mut sys).await.ok(), current_temp: get_cpu_temp().await.ok(), + uptime: Some(uptime), + host_name: Some(host_name), }) }