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
```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`).
- `<value>` — 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 <name> <value> [--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

View file

@ -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.