[−][src]Crate epimetheus
A simple prometheus-compatible metrics framework
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);
A metric's name can include labels. Whereas the base part of a metric's
name must be known at compile-time, the labels can be any runtime value
which implements Display
. This can be useful - but see the performance
notes below.
metric!(whizzbang{user=7, admin=is_admin(7)}).add(2.0); metric!(whizzbang{user=2, admin=is_admin(2)}).add(12.3);
The first time you update some metric, a thread is spawned which runs an
extremely simple HTTP server. By default it runs on port 9898, but you
can change this by setting the RUST_METRICS_PORT
environment variable.
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
Tip: If you want to specify the metrics port in your application iteself,
do this at the start of your main()
function:
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 |