prometheus-extensions 0.1.0

Prometheus extensions: AggregateCounter (per-label + total metrics), scientific-notation encoder, and EMA sensor.
Documentation
  • Coverage
  • 100%
    11 out of 11 items documented4 out of 11 items with examples
  • Size
  • Source code size: 23.57 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.25 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 38s Average build duration of successful builds.
  • all releases: 38s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • aovestdipaperino

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.