feat(#1974): hivectl migrate-stats — backfill per-agent token history to otel

This commit is contained in:
damocles 2026-06-24 20:48:38 +02:00
commit ef6a86872d
3 changed files with 233 additions and 0 deletions

View file

@ -204,6 +204,26 @@ enum Cmd {
#[command(subcommand)]
cmd: SubvolCmd,
},
/// One-shot backfill of historical per-agent turn stats into the OTEL
/// collector as cumulative `claude_code.token.usage` metrics, so
/// pre-OTEL token history shows up in grafana alongside the live
/// stream. Reads each agent's `hyperhive-turn-stats.sqlite` and POSTs
/// OTLP/HTTP JSON to the collector. Every datapoint is tagged
/// `hyperhive-migration="true"`. Safe to re-run (cumulative samples
/// at fixed historical timestamps are idempotent on the backend).
MigrateStats {
/// OTLP collector base URL (e.g. `http://10.42.0.1:4318`).
/// Defaults to `$OTEL_EXPORTER_OTLP_ENDPOINT`, then
/// `$HYPERHIVE_OTEL_ENDPOINT`.
#[arg(long)]
endpoint: Option<String>,
/// Limit to a single agent (default: every agent with a state dir).
#[arg(long)]
agent: Option<String>,
/// Report datapoint counts without sending anything.
#[arg(long)]
dry_run: bool,
},
/// Emit the full CLI reference as `CommonMark` to stdout.
///
/// Hidden tooling command (not part of day-to-day operator admin):
@ -608,6 +628,11 @@ async fn main() -> Result<()> {
SubvolCmd::Upgrade { name, yes } => subvol_upgrade(&socket, &name, yes).await,
},
Cmd::Choom { name, fresh } => choom(&name, fresh),
Cmd::MigrateStats {
endpoint,
agent,
dry_run,
} => hive_c0re::otel_migrate::run(endpoint, agent, dry_run).await,
Cmd::Quota { cmd } => match cmd {
QuotaCmd::Enable => quota_enable().await,
QuotaCmd::Show { name } => quota_show(name.as_deref()).await,