#prometheus #exporter #hyper #metrics #http-server

prometheus_exporter

Helper libary to export prometheus metrics using hyper

8 unstable releases (3 breaking)

✓ Uses Rust 2018 edition

0.4.1 Oct 1, 2019
0.4.0 Jun 24, 2019
0.3.2 Apr 3, 2019
0.3.0 Mar 14, 2019
0.1.1 Jan 24, 2019
Download history 42/week @ 2019-06-18 73/week @ 2019-06-25 61/week @ 2019-07-02 105/week @ 2019-07-09 44/week @ 2019-07-16 145/week @ 2019-07-23 103/week @ 2019-07-30 96/week @ 2019-08-06 58/week @ 2019-08-13 231/week @ 2019-08-20 83/week @ 2019-08-27 139/week @ 2019-09-03 43/week @ 2019-09-10 137/week @ 2019-09-17 81/week @ 2019-09-24

439 downloads per month

MIT license

10KB
156 lines

prometheus_exporter

Build Status crates.io docs.rs

Helper libary to export prometheus metrics using hyper. It's intended to help writing prometheus exporters without the need to setup and maintain a http webserver. If the program also uses a http server for other purposes this package is probably not the best way and rust-prometheus should be used directly.

It uses rust-prometheus for collecting and rendering the prometheus metrics and hyper for exposing the metrics through http.

NOTICE: You have to use the same prometheus crate version that is used by this crate to make sure that the global registrar use by the prometheus macros works as expected. Currently this crate uses prometheus version 0.7.

Usage

Add this to your Cargo.toml:

[dependencies]
prometheus_exporter = "0.4"

There are three ways on how to use the exporter:

  • PrometheusExporter::run: Just starts the hyper http server and exports metrics from the global prometheus register under the path /metrics. Allows the most freedom on how and when to update/generate metrics.

  • PrometheusExporter::run_and_notify: Starts the http server and opens channels to allow notification of when a request is made. This is usefull for cases where metrics should be updated everytime somebody calls the /metrics path.

  • PrometheusExporter::run_and_repeat: Starts the http server and opens channels that will send a message to the original caller when a duration inteval is reached. This will be repeated forever. This is usefull for cases where metrics should be gathered in a set interval. For example if the metric collection is expensive it makes more sense to not collect the metrics all the time.

For examples on how to use prometheus_exporter see the examples folder.

Dependencies

~3.5MB
~72K SLoC