improve agent + config

This commit is contained in:
csehviktor
2025-07-03 06:10:59 +02:00
parent 1f89f8d4cb
commit c291353690
2 changed files with 21 additions and 32 deletions

View File

@@ -1,19 +1,23 @@
use config::{load_config, Config};
use mqtt::MqttHandle;
use collector::Collector;
use std::time::Duration;
use std::thread;
use std::time;
pub mod collector;
const REFRESH_INTERVAL: u64 = 3000;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let cfg = load_config()?;
let cfg: &'static mut Config = Box::leak(Box::new(cfg));
fn main() {
let client = MqttHandle::create(&mut cfg.mqtt).await;
let mut collector = Collector::new();
loop {
let metrics = collector.collect_all();
client.send_metrics(metrics).await?;
println!("Metrics: {:?}", metrics);
thread::sleep(time::Duration::from_millis(REFRESH_INTERVAL));
thread::sleep(Duration::from_secs(cfg.send_interval_seconds));
}
}