hew.metrics
Actor-owned Prometheus metrics for Hew — typed counters, gauges, histograms, labels, and export
Use version 0.7.0
hew add hew.metrics --version 0.7.0
- Declared Hew requirement
- >=0.10.0, <0.12.0
- Licence
- MIT OR Apache-2.0
- Published
- 2026-11-13T06:01:21.034Z
Dependencies
No package dependencies.
Package README
# hew.metrics
Actor-owned Prometheus counters, gauges, histograms, labels, and text export.
Every registration, mutation and export handler declares `fails
MetricsError`, so a call replies `Result<T, ActorError<MetricsError>>`: match
`.Ok(value)`, `.Err(.Failed(error))` for a metrics error, and `.Err(_)` for a
registry that could not answer. Registration replies the metric handle,
`export` the text, and every mutation `()`. Stopping the actor releases its
native registry.
Each labeled metric retains at most 1024 distinct label-value tuples. Once the
limit is reached, existing tuples remain mutable and operations with a new
tuple return `MetricsError.SeriesLimit`.
```hew
import hew.metrics;
fn export_requests() -> string {
let registry = spawn metrics.Registry;
let text = match registry.counter("requests_total", "Handled requests") {
.Ok(counter) => {
let _ = registry.counter_inc(counter);
let _ = registry.counter_add(counter, 2.0);
match registry.export() {
.Ok(text) => text,
.Err(.Failed(error)) => metrics.error_message(error),
.Err(_) => "metrics actor stopped before replying",
}
}
.Err(.Failed(error)) => metrics.error_message(error),
.Err(_) => "metrics actor stopped before replying",
};
stop(registry);
stopped(registry);
text
}
fn main() {
println(export_requests());
}
#[test]
#[real_time]
fn exports_the_incremented_counter() {
assert(export_requests().contains("\nrequests_total 3\n"));
}
```
This is [`examples/basic.hew`](examples/basic.hew) without its header comment. Run it
from the ecosystem checkout:
```sh
hew run --pkg-path . metrics/examples/basic.hew
```
It prints the Prometheus text exposition of everything the registry holds:
```text
# HELP requests_total Handled requests
# TYPE requests_total counter
requests_total 3
```
`export()` is what makes a registry observable, so the example calls it rather
than incrementing a counter and exiting silently, and its test checks the
`requests_total 3` line.