modulized everthing

This commit is contained in:
2025-08-08 18:59:57 +02:00
parent f0b89a9c32
commit abfa0b6fc0
11 changed files with 690 additions and 570 deletions

View File

@@ -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
}