[][src]Crate epimetheus

An easy-to-use prometheus-compatible metrics library

A metric has a name and a value of type f64. There is a single global set of metrics which can be set or incremented from any thread.

use epimetheus::metric;

metric!(foobar).set(12.3);
metric!(foobar).add(0.7);

If you increment a metric which has never been set, it is considered to start from zero.

metric!(barqux).add(6.5);

You can include labels. A metric's name must be known at compile-time, but the label values can be any runtime value which implements Display. This can be useful, but comes at a performance cost (see notes below).

let my_user = User { id: 7, admin: true };
metric!(whizzbang{user=my_user.id, admin=my_user.admin}).add(2.0);

Any rust expression is allowed:

metric!(whizzbang{user=1+1, admin=true && false}).add(12.3);

The first time you update a metric, a thread is spawned which acts as a very basic HTTP server. Connect to the server to see the current values of all metrics. Metrics appear in the output after being updated for the first time.

$ curl localhost:9898
barqux 6.5
foobar 20
whizzbang{admin="false",user="2"} 12.3
whizzbang{admin="true",user="7"} 2

By default the HTTP server runs on port 9898, but you can change this by setting the RUST_METRICS_PORT environment variable. Tip: If you want to specify the metrics port in your application iteself, do this at the start of your main() function like so:

std::env::set_var("RUST_METRICS_PORT", "1234");

Make sure you do this before updating any metrics.

Macros

metric

Refer to a metric.

Structs

Metric

A named metric; it has a associated global mutable f64 value.