Skip to content
Prometheus instrumentation library for Rust applications
Branch: master
Clone or download
lucab and overvenus registry: add optional common prefix and labels (#233)
This adds an additional constructor to provide common namespace/labels
for a registry, to be used for all collected metrics.
Latest commit 1312ad8 Apr 9, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Create issue templates (#208) Oct 25, 2018
benches Update reqwest to 0.9.5 (#215) Dec 24, 2018
examples registry: add optional common prefix and labels (#233) Apr 9, 2019
proto Make protobuf dependency optional (#216) Feb 7, 2019
src registry: add optional common prefix and labels (#233) Apr 9, 2019
static-metric Update reqwest to 0.9.5 (#215) Dec 24, 2018
.gitignore
.travis.yml Use stable clippy (#203) Sep 24, 2018
CHANGELOG.md TLS & Basic Auth support to push mode (#187) Jul 27, 2018
CODE_OF_CONDUCT.md Create a Code of Conduct (#193) Sep 7, 2018
Cargo.toml Make protobuf dependency optional (#216) Feb 7, 2019
LICENSE Initial commit Aug 11, 2016
Makefile Use `cargo clippy` instead of the clippy plugin #176 (#184) Jun 22, 2018
README.md Fix typos in multiple files. (#188) Aug 1, 2018
build.rs Make protobuf dependency optional (#216) Feb 7, 2019
rustfmt.toml Use `cargo clippy` instead of the clippy plugin #176 (#184) Jun 22, 2018

README.md

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

You can’t perform that action at this time.