2025-10-12 20:29:08 +02:00

66 lines
1.5 KiB
Rust

use anyhow::Result;
use clap::Parser;
use tokio::signal;
use tracing::{error, info};
use tracing_subscriber::EnvFilter;
mod collectors;
mod discovery;
mod notifications;
mod simple_agent;
use simple_agent::SimpleAgent;
#[derive(Parser)]
#[command(name = "cm-dashboard-agent")]
#[command(about = "CM Dashboard metrics agent with auto-detection")]
#[command(version)]
struct Cli {
/// Increase logging verbosity (-v, -vv)
#[arg(short, long, action = clap::ArgAction::Count)]
verbose: u8,
}
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
// Setup logging
let log_level = match cli.verbose {
0 => "info",
1 => "debug",
_ => "trace",
};
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env().add_directive(log_level.parse()?))
.init();
info!("CM Dashboard Agent starting...");
// Create and run agent
let mut agent = SimpleAgent::new().await?;
// Setup graceful shutdown
let ctrl_c = async {
signal::ctrl_c()
.await
.expect("failed to install Ctrl+C handler");
};
// Run agent with graceful shutdown
tokio::select! {
result = agent.run() => {
if let Err(e) = result {
error!("Agent error: {}", e);
return Err(e);
}
}
_ = ctrl_c => {
info!("Shutdown signal received");
}
}
info!("Agent shutdown complete");
Ok(())
}