Prometheus Rust client library
This is the Rust client library for Prometheus. The main Structures and APIs are ported from Go client.
Usage
-
Add dependency to your
Cargo.toml
:= "0.8"
-
Optional: Better performance for Rust nightly.
= { = "0.8", = ["nightly"] }
Note
The crate has a pre-generated protobuf binding file for protobuf
v2.0, if you need use the latest version of protobuf
, you can generate the binding file on building with the gen
feature.
= { = "0.8", = ["gen"] }
Example
use ;
// Create a Counter.
let counter_opts = new;
let counter = with_opts.unwrap;
// Create a Registry and register Counter.
let r = new;
r.register.unwrap;
// Inc.
counter.inc;
// Gather the metrics.
let mut buffer = vec!;
let encoder = new;
let metric_families = r.gather;
encoder.encode.unwrap;
// Output to the standard output.
println!;
Advanced
Static Metric
Static metric helps you make metric vectors faster.
See static-metric directory for details.