Files
watcheragent/WatcherAgent/src/main.rs

39 lines
1.0 KiB
Rust

/// WatcherAgent - A Rust-based system monitoring agent
/// This agent collects hardware metrics and sends them to a backend server.
/// It supports CPU, GPU, RAM, disk, and network metrics.
mod api;
mod hardware;
mod metrics;
mod models;
use anyhow::Result;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let server_url = "http://localhost:5000";
// Registration
let (server_id, ip) = api::register_with_server(server_url).await?;
// Start background tasks
// Start heartbeat in background
let heartbeat_handle = tokio::spawn({
let ip = ip.clone();
async move {
if let Err(e) = api::heartbeat_loop(server_url, &ip).await {
eprintln!("Heartbeat loop failed: {}", e);
}
}
});
heartbeat_handle.await?;
// Main metrics loop
println!("Starting metrics collection...");
let mut collector = metrics::Collector::new(server_id, ip);
collector.run(server_url).await?;
Ok(())
}