1 unstable release
| 0.1.0 | Mar 22, 2026 |
|---|
#2 in #kafka
18KB
219 lines
prometheus-extensions
Prometheus extensions for richer metric collection in Rust.
Types
| Type | Purpose |
|---|---|
AggregateCounter |
A CounterVec wrapper that automatically emits an extra unlabeled total alongside every per-label counter. |
ScientificEncoder |
A Prometheus text-format encoder that renders values in scientific notation with a trailing comma after the last label (Kafka JMX exporter compatible). |
Sensor |
A lock-free exponential moving average (EMA) gauge for tracking smoothed rates. |
Usage
use prometheus::Opts;
use prometheus::core::Collector;
use prometheus_extensions::{AggregateCounter, ScientificEncoder};
let counter = AggregateCounter::new(
Opts::new("http_requests_total", "Total HTTP requests"),
&["method"],
).unwrap();
counter.with_label_values(&["GET"]).inc_by(100.0);
counter.with_label_values(&["POST"]).inc_by(42.0);
// Collecting yields 3 metrics: unlabeled total (142) + two labeled.
let families = counter.collect();
// Encode in scientific notation
let encoder = ScientificEncoder::new();
let mut buf = Vec::new();
encoder.encode(&families, &mut buf).unwrap();
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Dependencies
~0.5–1.2MB
~25K SLoC