prometheus_exporter
Helper libary to export prometheus metrics using tiny-http. 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 tiny-http 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. This crate re-exports the prometheuse crate to make it easier
to keep versions in sync (see examples). Currently this crate uses prometheus
version 0.11
.
For information on how to migrate from an older crate version follow MIGRATION.
Usage
Add this to your Cargo.toml
:
[]
= "0.8"
The most basic way to use this crate is to run the following:
.unwrap )
start
This will start the exporter and bind the http server to 0.0.0.0:9184
. After
that you can just update the metrics how you see fit. As long as those metrics
are put into the global prometheus registry the changed metrics will be
exported.
Another way to use the crate is like this:
let exporter = start.unwrap );
let guard = exporter.wait_request
This will block the current thread until a request has been received on the http server. It also returns a guard which will make the http server wait until the guard is dropped. This is useful to always export consistent metrics as all of the metrics can be updated before they get exported.
See the documentation and the examples for more information on how to use this crate.
Basic Example
A very simple example looks like this (from
examples/simple.rs
):
// Will create an exporter with a single metric that does not change
use ;
use info;
use register_gauge;
use SocketAddr;