#prometheus #metrics

prometheus

Prometheus instrumentation library for Rust applications

26 releases

0.5.0 Jan 14, 2019
0.4.2 Jun 13, 2018
0.4.1 May 10, 2018
0.3.13 Feb 13, 2018
0.1.0 Jan 22, 2016

#1 in #metrics

Download history 399/week @ 2018-12-20 164/week @ 2018-12-27 710/week @ 2019-01-03 973/week @ 2019-01-10 1285/week @ 2019-01-17 1772/week @ 2019-01-24 1945/week @ 2019-01-31 2842/week @ 2019-02-07 3544/week @ 2019-02-14 3594/week @ 2019-02-21 4207/week @ 2019-02-28 3720/week @ 2019-03-07 4668/week @ 2019-03-14 4093/week @ 2019-03-21 3772/week @ 2019-03-28

5,495 downloads per month
Used in 17 crates

Apache-2.0

266KB
6K 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.4"
    
  • 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"
    default-features = false
    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