getting more cpu data
This commit is contained in:
@@ -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<i32>,
|
||||
pub current_load: Option<f64>,
|
||||
pub current_temp: Option<f64>,
|
||||
pub uptime: Option<f64>,
|
||||
pub host_name: Option<String>,
|
||||
}
|
||||
|
||||
pub async fn get_cpu_info() -> Result<CpuInfo, Box<dyn Error + Send + Sync>> {
|
||||
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<CpuInfo, Box<dyn Error + Send + Sync>> {
|
||||
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),
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user