running parallel tokio tasks for heartbeat and metrics
This commit is contained in:
@@ -21,20 +21,33 @@ impl Collector {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run(&mut self, base_url: &str) -> Result<(), Box<dyn Error>> {
|
||||
pub async fn run(&mut self, base_url: &str) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
loop {
|
||||
println!(
|
||||
"[{}] Starting metrics collection...",
|
||||
chrono::Local::now().format("%H:%M:%S")
|
||||
);
|
||||
let metrics = self.collect().await?;
|
||||
let metrics = match self.collect().await {
|
||||
Ok(metrics) => metrics,
|
||||
Err(e) => {
|
||||
eprintln!("Error collecting metrics: {}", e);
|
||||
tokio::time::sleep(Duration::from_secs(10)).await;
|
||||
continue;
|
||||
}
|
||||
};
|
||||
api::send_metrics(base_url, &metrics).await?;
|
||||
tokio::time::sleep(Duration::from_secs(20)).await;
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn collect(&mut self) -> Result<MetricDto, Box<dyn Error>> {
|
||||
let hardware = HardwareInfo::collect().await?;
|
||||
pub async fn collect(&mut self) -> Result<MetricDto, Box<dyn Error + Send + Sync>> {
|
||||
let hardware = match HardwareInfo::collect().await {
|
||||
Ok(hw) => hw,
|
||||
Err(e) => {
|
||||
eprintln!("Fehler beim Sammeln der Hardware-Infos: {e}");
|
||||
return Err(e.into());
|
||||
}
|
||||
};
|
||||
// Collect network usage
|
||||
let (_, _) = self.network_monitor.update_usage().unwrap_or((0.0, 0.0));
|
||||
|
||||
|
Reference in New Issue
Block a user