#prometheus #metrics

prometheus

Prometheus instrumentation library for Rust applications

28 releases

✓ Uses Rust 2018 edition

0.6.1 Jun 4, 2019
0.5.0 Jan 14, 2019
0.4.2 Jun 13, 2018
0.3.13 Feb 13, 2018
0.1.0 Jan 22, 2016

#7 in Parser implementations

Download history 3701/week @ 2019-02-19 4098/week @ 2019-02-26 3534/week @ 2019-03-05 4558/week @ 2019-03-12 4530/week @ 2019-03-19 3647/week @ 2019-03-26 3932/week @ 2019-04-02 4009/week @ 2019-04-09 2694/week @ 2019-04-16 2128/week @ 2019-04-23 2713/week @ 2019-04-30 3465/week @ 2019-05-07 3885/week @ 2019-05-14 3178/week @ 2019-05-21 4078/week @ 2019-05-28

15,233 downloads per month
Used in 21 crates

Apache-2.0

278KB
6.5K SLoC

Prometheus Rust client library

Build Status docs.rs crates.io

This is the Rust client library for Prometheus. The main Structures and APIs are ported from Go client.

Usage

  • Add this to your Cargo.toml:

    [dependencies]
    prometheus = "0.6"
    
  • Add this to your crate in lib.rs:

    extern crate prometheus;
    
  • Or enable nightly feature for better performance.

    [dependencies.prometheus]
    git = "https://github.com/pingcap/rust-prometheus.git"
    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.

[dependencies.prometheus]
git = "https://github.com/pingcap/rust-prometheus.git"
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

~4.5MB
~89K SLoC