fix(hive-metric): multi-thread runtime + counter default

This commit is contained in:
damocles 2026-07-05 01:10:40 +02:00 committed by mara
commit 61dfceb100
2 changed files with 18 additions and 18 deletions

View file

@ -136,13 +136,13 @@ Agents can push arbitrary labeled metrics to the same OTEL collector via the
### Usage ### Usage
```text ```text
hive-metric <name> <value> [--type gauge|counter] [--labels key=value...] hive-metric <name> <value> [--type counter|gauge] [--labels key=value...]
``` ```
- `<name>` — metric name (e.g. `tasks_completed`, `latency_ms`). - `<name>` — metric name (e.g. `tasks_completed`, `latency_ms`).
- `<value>` — numeric value (f64; integers and floats both accepted). - `<value>` — numeric value (f64; integers and floats both accepted).
- `--type gauge|counter` — metric kind: `gauge` (instantaneous, default) or - `--type counter|gauge` — metric kind: `counter` (cumulative sum, default) or
`counter` (monotonically increasing cumulative sum). `gauge` (instantaneous point-in-time value).
- `--labels key=value` — extra per-data-point labels. May be repeated. - `--labels key=value` — extra per-data-point labels. May be repeated.
The resource labels (agent, hive, swarm, service.name) are inherited The resource labels (agent, hive, swarm, service.name) are inherited
automatically from `OTEL_RESOURCE_ATTRIBUTES` — do not re-specify them. automatically from `OTEL_RESOURCE_ATTRIBUTES` — do not re-specify them.
@ -150,14 +150,14 @@ hive-metric <name> <value> [--type gauge|counter] [--labels key=value...]
### Examples ### Examples
```text ```text
# Gauge: current queue depth # Counter: cumulative tasks finished (default type — no --type flag needed)
hive-metric queue_depth 17 hive-metric tasks_completed 1 --labels phase=scan
# Counter: cumulative tasks finished, with a custom label # Gauge: current queue depth (absolute value — must use --type gauge)
hive-metric tasks_completed 1 --type counter --labels phase=scan hive-metric queue_depth 17 --type gauge
# Float gauge with multiple labels # Float gauge with multiple labels (instantaneous measurement)
hive-metric api_latency_ms 142.5 --labels model=sonnet --labels tier=api hive-metric api_latency_ms 142.5 --type gauge --labels model=sonnet --labels tier=api
``` ```
### Error when OTEL is not configured ### Error when OTEL is not configured

View file

@ -33,8 +33,8 @@ struct Cli {
/// Numeric value (f64). Floats and integers both accepted. /// Numeric value (f64). Floats and integers both accepted.
value: f64, value: f64,
/// Metric kind: `gauge` (instantaneous, default) or `counter` (cumulative sum). /// Metric kind: `counter` (cumulative sum, default) or `gauge` (instantaneous value).
#[arg(long = "type", value_name = "TYPE", default_value = "gauge")] #[arg(long = "type", value_name = "TYPE", default_value = "counter")]
metric_type: MetricKind, metric_type: MetricKind,
/// Extra label(s) as `key=value` pairs. May be repeated. /// Extra label(s) as `key=value` pairs. May be repeated.
@ -46,13 +46,13 @@ struct Cli {
#[derive(Clone, Debug, clap::ValueEnum)] #[derive(Clone, Debug, clap::ValueEnum)]
enum MetricKind { enum MetricKind {
/// Gauge: point-in-time value (default). /// Counter: monotonically increasing cumulative sum (default).
Gauge,
/// Counter: monotonically increasing cumulative sum.
Counter, Counter,
/// Gauge: point-in-time instantaneous value.
Gauge,
} }
#[tokio::main(flavor = "current_thread")] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
let cli = Cli::parse(); let cli = Cli::parse();
@ -80,12 +80,12 @@ async fn main() -> Result<()> {
let meter = provider.meter("hive-metric"); let meter = provider.meter("hive-metric");
match cli.metric_type { match cli.metric_type {
MetricKind::Gauge => {
meter.f64_gauge(cli.name).build().record(cli.value, &labels);
}
MetricKind::Counter => { MetricKind::Counter => {
meter.f64_counter(cli.name).build().add(cli.value, &labels); 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. // Flush pending metrics and shut down cleanly.