From 61dfceb10033bbbaf15ea921117f0df528968759 Mon Sep 17 00:00:00 2001 From: damocles Date: Sun, 5 Jul 2026 01:10:40 +0200 Subject: [PATCH] fix(hive-metric): multi-thread runtime + counter default --- docs/observability.md | 18 +++++++++--------- hive-metric/src/main.rs | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/observability.md b/docs/observability.md index 1982dca5..c95d5d52 100644 --- a/docs/observability.md +++ b/docs/observability.md @@ -136,13 +136,13 @@ Agents can push arbitrary labeled metrics to the same OTEL collector via the ### Usage ```text -hive-metric [--type gauge|counter] [--labels key=value...] +hive-metric [--type counter|gauge] [--labels key=value...] ``` - `` — metric name (e.g. `tasks_completed`, `latency_ms`). - `` — numeric value (f64; integers and floats both accepted). -- `--type gauge|counter` — metric kind: `gauge` (instantaneous, default) or - `counter` (monotonically increasing cumulative sum). +- `--type counter|gauge` — metric kind: `counter` (cumulative sum, default) or + `gauge` (instantaneous point-in-time value). - `--labels key=value` — extra per-data-point labels. May be repeated. The resource labels (agent, hive, swarm, service.name) are inherited automatically from `OTEL_RESOURCE_ATTRIBUTES` — do not re-specify them. @@ -150,14 +150,14 @@ hive-metric [--type gauge|counter] [--labels key=value...] ### Examples ```text -# Gauge: current queue depth -hive-metric queue_depth 17 +# Counter: cumulative tasks finished (default type — no --type flag needed) +hive-metric tasks_completed 1 --labels phase=scan -# Counter: cumulative tasks finished, with a custom label -hive-metric tasks_completed 1 --type counter --labels phase=scan +# Gauge: current queue depth (absolute value — must use --type gauge) +hive-metric queue_depth 17 --type gauge -# Float gauge with multiple labels -hive-metric api_latency_ms 142.5 --labels model=sonnet --labels tier=api +# Float gauge with multiple labels (instantaneous measurement) +hive-metric api_latency_ms 142.5 --type gauge --labels model=sonnet --labels tier=api ``` ### Error when OTEL is not configured diff --git a/hive-metric/src/main.rs b/hive-metric/src/main.rs index e7b8cd8b..967e4c00 100644 --- a/hive-metric/src/main.rs +++ b/hive-metric/src/main.rs @@ -33,8 +33,8 @@ struct Cli { /// Numeric value (f64). Floats and integers both accepted. value: f64, - /// Metric kind: `gauge` (instantaneous, default) or `counter` (cumulative sum). - #[arg(long = "type", value_name = "TYPE", default_value = "gauge")] + /// Metric kind: `counter` (cumulative sum, default) or `gauge` (instantaneous value). + #[arg(long = "type", value_name = "TYPE", default_value = "counter")] metric_type: MetricKind, /// Extra label(s) as `key=value` pairs. May be repeated. @@ -46,13 +46,13 @@ struct Cli { #[derive(Clone, Debug, clap::ValueEnum)] enum MetricKind { - /// Gauge: point-in-time value (default). - Gauge, - /// Counter: monotonically increasing cumulative sum. + /// Counter: monotonically increasing cumulative sum (default). Counter, + /// Gauge: point-in-time instantaneous value. + Gauge, } -#[tokio::main(flavor = "current_thread")] +#[tokio::main] async fn main() -> Result<()> { let cli = Cli::parse(); @@ -80,12 +80,12 @@ async fn main() -> Result<()> { let meter = provider.meter("hive-metric"); match cli.metric_type { - MetricKind::Gauge => { - meter.f64_gauge(cli.name).build().record(cli.value, &labels); - } MetricKind::Counter => { meter.f64_counter(cli.name).build().add(cli.value, &labels); } + MetricKind::Gauge => { + meter.f64_gauge(cli.name).build().record(cli.value, &labels); + } } // Flush pending metrics and shut down cleanly.