tencrypt-metrics-snapshot 0.1.1

One-shot metrics snapshot CLI for tencrypt state files
//! metrics-snapshot — reads a tencrypt state file and prints a CertMetrics
//! JSON snapshot to stdout, then exits.
//!
//! Designed to run as an ephemeral cell or cron job, not a long-lived server.

use std::path::PathBuf;

use clap::Parser;
use tencrypt_core::{CertMetrics, CertState, StateStore};

#[derive(Debug, Parser)]
#[command(name = "tencrypt-metrics-snapshot")]
#[command(about = "Print a CertMetrics JSON snapshot from a state file and exit")]
struct Cli {
    /// Path to the JSON state file produced by `tencrypt reconcile`.
    #[arg(long)]
    state_file: PathBuf,
}

fn main() -> anyhow::Result<()> {
    let cli = Cli::parse();
    let store = StateStore::load(&cli.state_file)?;

    let mut metrics = CertMetrics::default();
    for record in &store.certs {
        match record.state {
            CertState::Issued => metrics.issued_total += 1,
            CertState::Failed | CertState::Revoked => metrics.failed_total += 1,
            _ => metrics.in_flight += 1,
        }
    }

    println!("{}", serde_json::to_string_pretty(&metrics)?);
    Ok(())
}