#prometheus #metrics

prometheus

Prometheus instrumentation library for Rust applications

26 releases

new 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

#12 in Parser implementations

Download history 1633/week @ 2018-10-27 1937/week @ 2018-11-03 1915/week @ 2018-11-10 1679/week @ 2018-11-17 1059/week @ 2018-11-24 1558/week @ 2018-12-01 1308/week @ 2018-12-08 1409/week @ 2018-12-15 1077/week @ 2018-12-22 552/week @ 2018-12-29 409/week @ 2019-01-05 921/week @ 2019-01-12 1028/week @ 2019-01-19

5,495 downloads per month
Used in 13 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

~4MB
~91K SLoC