all functions established; needed to remove orphan functions
This commit is contained in:
@@ -2,10 +2,12 @@ use std::error::Error;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::api;
|
||||
use crate::hardware::network::NetworkMonitor;
|
||||
use crate::hardware::HardwareInfo;
|
||||
use crate::models::MetricDto;
|
||||
|
||||
pub struct Collector {
|
||||
network_monitor: NetworkMonitor,
|
||||
server_id: i32,
|
||||
ip_address: String,
|
||||
}
|
||||
@@ -13,6 +15,7 @@ pub struct Collector {
|
||||
impl Collector {
|
||||
pub fn new(server_id: i32, ip_address: String) -> Self {
|
||||
Self {
|
||||
network_monitor: NetworkMonitor::new(),
|
||||
server_id,
|
||||
ip_address,
|
||||
}
|
||||
@@ -28,6 +31,8 @@ impl Collector {
|
||||
|
||||
pub async fn collect(&mut self) -> Result<MetricDto, Box<dyn Error>> {
|
||||
let hardware = HardwareInfo::collect().await?;
|
||||
// Collect network usage
|
||||
let (_, _) = self.network_monitor.update_usage().unwrap_or((0.0, 0.0));
|
||||
|
||||
Ok(MetricDto {
|
||||
server_id: self.server_id,
|
||||
@@ -43,8 +48,8 @@ impl Collector {
|
||||
disk_size: hardware.disk.total.unwrap_or_default(),
|
||||
disk_usage: hardware.disk.used.unwrap_or_default(),
|
||||
disk_temp: 0.0, // not supported
|
||||
net_rx: hardware.network.rx_bytes.unwrap_or_default(),
|
||||
net_tx: hardware.network.tx_bytes.unwrap_or_default(),
|
||||
net_rx: hardware.network.rx_rate.unwrap_or_default(),
|
||||
net_tx: hardware.network.tx_rate.unwrap_or_default(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user