#prometheus #metrics

prometheus

Prometheus instrumentation library for Rust applications

25 releases

0.4.2 Jun 13, 2018
0.4.0 Apr 9, 2018
0.3.13 Feb 13, 2018
0.3.6 Dec 13, 2017
0.1.0 Jan 22, 2016

#3 in Visualization

Download history 473/week @ 2018-05-27 529/week @ 2018-06-03 607/week @ 2018-06-10 873/week @ 2018-06-17 806/week @ 2018-06-24 975/week @ 2018-07-01 683/week @ 2018-07-08 781/week @ 2018-07-15 757/week @ 2018-07-22 693/week @ 2018-07-29 1089/week @ 2018-08-05 976/week @ 2018-08-12 963/week @ 2018-08-19

2,728 downloads per month
Used in 9 crates

Apache-2.0

260KB
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_familys = r.gather();
encoder.encode(&metric_familys, &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

~2.5MB
~57K SLoC