all functions established; needed to remove orphan functions
This commit is contained in:
@@ -19,7 +19,7 @@ pub async fn get_memory_info() -> Result<MemoryInfo> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_memory_usage(sys: &mut System) -> 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
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ mod cpu;
|
||||
mod disk;
|
||||
mod gpu;
|
||||
mod memory;
|
||||
mod network;
|
||||
pub(crate) mod network;
|
||||
|
||||
pub use cpu::get_cpu_info;
|
||||
pub use disk::get_disk_info;
|
||||
@@ -20,16 +20,19 @@ pub struct HardwareInfo {
|
||||
pub memory: memory::MemoryInfo,
|
||||
pub disk: disk::DiskInfo,
|
||||
pub network: network::NetworkInfo,
|
||||
network_monitor: network::NetworkMonitor,
|
||||
}
|
||||
|
||||
impl HardwareInfo {
|
||||
pub async fn collect() -> anyhow::Result<Self, Box<dyn Error>> {
|
||||
let mut network_monitor = network::NetworkMonitor::new();
|
||||
Ok(Self {
|
||||
cpu: get_cpu_info().await?,
|
||||
gpu: get_gpu_info().await?,
|
||||
memory: get_memory_info().await?,
|
||||
disk: get_disk_info().await?,
|
||||
network: get_network_info().await?,
|
||||
network: get_network_info(&mut network_monitor).await?,
|
||||
network_monitor,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@@ -5,10 +5,11 @@ use std::time::Instant;
|
||||
#[derive(Debug)]
|
||||
pub struct NetworkInfo {
|
||||
pub interfaces: Option<Vec<String>>,
|
||||
pub rx_bytes: Option<f64>,
|
||||
pub tx_bytes: Option<f64>,
|
||||
pub rx_rate: Option<f64>,
|
||||
pub tx_rate: Option<f64>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct NetworkMonitor {
|
||||
prev_rx: u64,
|
||||
prev_tx: u64,
|
||||
@@ -24,7 +25,7 @@ impl NetworkMonitor {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_usage(&mut self) -> Result<(f64, f64), Box<dyn Error>> {
|
||||
pub fn update_usage(&mut self) -> Result<(f64, f64), Box<dyn Error>> {
|
||||
let (current_rx, current_tx) = get_network_bytes()?;
|
||||
let elapsed = self.last_update.elapsed().as_secs_f64();
|
||||
self.last_update = Instant::now();
|
||||
@@ -48,12 +49,12 @@ impl NetworkMonitor {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_network_info() -> Result<NetworkInfo, Box<dyn Error>> {
|
||||
let (rx, tx) = get_network_bytes()?;
|
||||
pub async fn get_network_info(monitor: &mut NetworkMonitor) -> Result<NetworkInfo, Box<dyn Error>> {
|
||||
let (rx_rate, tx_rate) = monitor.update_usage()?;
|
||||
Ok(NetworkInfo {
|
||||
interfaces: Some(get_network_interfaces()),
|
||||
rx_bytes: Some(rx as f64),
|
||||
tx_bytes: Some(tx as f64),
|
||||
rx_rate: Some(rx_rate as f64),
|
||||
tx_rate: Some(tx_rate as f64),
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user