modulized everthing
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
use anyhow::Result;
|
||||
use sysinfo::System;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MemoryInfo {
|
||||
pub total: Option<f64>,
|
||||
pub used: Option<f64>,
|
||||
pub free: Option<f64>,
|
||||
}
|
||||
|
||||
pub async fn get_memory_info() -> Result<MemoryInfo> {
|
||||
let mut sys = System::new();
|
||||
sys.refresh_memory();
|
||||
|
||||
Ok(MemoryInfo {
|
||||
total: Some(sys.total_memory() as f64),
|
||||
used: Some(sys.used_memory() as f64),
|
||||
free: Some(sys.free_memory() as f64),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_memory_usage(sys: &mut System) -> f64 {
|
||||
sys.refresh_memory();
|
||||
(sys.used_memory() as f64 / sys.total_memory() as f64) * 100.0
|
||||
}
|
||||
|
Reference in New Issue
Block a user