#prometheus #metrics

prometheus

Prometheus instrumentation library for Rust applications

30 releases

✓ Uses Rust 2018 edition

0.8.0 Mar 1, 2020
0.7.0 Jun 20, 2019
0.6.1 Jun 4, 2019
0.5.0 Jan 14, 2019
0.1.0 Jan 22, 2016

#3 in Debugging

Download history 14160/week @ 2019-12-02 15651/week @ 2019-12-09 12883/week @ 2019-12-16 5201/week @ 2019-12-23 5962/week @ 2019-12-30 10786/week @ 2020-01-06 12700/week @ 2020-01-13 12326/week @ 2020-01-20 12436/week @ 2020-01-27 12247/week @ 2020-02-03 13296/week @ 2020-02-10 12200/week @ 2020-02-17 13524/week @ 2020-02-24 13384/week @ 2020-03-02 14231/week @ 2020-03-09 14944/week @ 2020-03-16

50,214 downloads per month
Used in 71 crates (40 directly)

Apache-2.0

275KB
6.5K SLoC

Prometheus Rust client library

Build Status docs.rs crates.io Dependency Status

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:

    prometheus = "0.8"
    
  • Optional: Better performance for Rust nightly.

    prometheus = { version = "0.8", features = ["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.

prometheus = { version = "0.8", features = ["gen"] }

Example

use prometheus::{Opts, Registry, Counter, TextEncoder, Encoder};

// Create a Counter.
let counter_opts = Opts::new("test_counter", "test counter help");
let counter = Counter::with_opts(counter_opts).unwrap();

// Create a Registry and register Counter.
let r = Registry::new();
r.register(Box::new(counter.clone())).unwrap();

// Inc.
counter.inc();

// Gather the metrics.
let mut buffer = vec![];
let encoder = TextEncoder::new();
let metric_families = r.gather();
encoder.encode(&metric_families, &mut buffer).unwrap();

// Output to the standard output.
println!("{}", String::from_utf8(buffer).unwrap());

More Examples

Advanced

Static Metric

Static metric helps you make metric vectors faster.

See static-metric directory for details.

Thanks

Dependencies

~1.6–5MB
~116K SLoC