46 lines
1.4 KiB
Rust
46 lines
1.4 KiB
Rust
mod query;
|
|
mod runner;
|
|
mod types;
|
|
|
|
use anyhow::Result;
|
|
use std::collections::HashSet;
|
|
use std::env;
|
|
use std::sync::Arc;
|
|
use rustls;
|
|
use tokio::sync::Mutex;
|
|
use tokio::time::{sleep, Duration};
|
|
use tracing::{error, info};
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
// Install default rustls crypto provider (required for cert expiry checks)
|
|
rustls::crypto::ring::default_provider()
|
|
.install_default()
|
|
.ok(); // ok() — ignore error if already installed
|
|
|
|
tracing_subscriber::fmt()
|
|
.with_env_filter(env::var("RUST_LOG").unwrap_or_else(|_| "info".into()))
|
|
.init();
|
|
|
|
let coordinator_url = env::var("COORDINATOR_URL")
|
|
.unwrap_or_else(|_| "http://localhost:3000".into());
|
|
let monitor_token = env::var("MONITOR_TOKEN")
|
|
.expect("MONITOR_TOKEN must be set");
|
|
|
|
info!("PingQL monitor starting, coordinator: {coordinator_url}");
|
|
|
|
let client = reqwest::Client::builder()
|
|
.user_agent("PingQL-Monitor/0.1")
|
|
.build()?;
|
|
|
|
let in_flight: Arc<Mutex<HashSet<String>>> = Arc::new(Mutex::new(HashSet::new()));
|
|
|
|
loop {
|
|
match runner::fetch_and_run(&client, &coordinator_url, &monitor_token, &in_flight).await {
|
|
Ok(n) => { if n > 0 { info!("Spawned {n} checks"); } },
|
|
Err(e) => error!("Check cycle failed: {e}"),
|
|
}
|
|
sleep(Duration::from_millis(50)).await;
|
|
}
|
|
}
|