Easily registered distributed metrics.
More docs todo...
Creating a Metric
Registering a metric is straightforward. All that's needed is to declare a
static within the [metric] macro. By default, the metric will have the
name of the path to the static variable you used to declare it but this can
be overridden by passing the name parameter to the macro.
# // This should remain in sync with the example below.
use *;
/// A counter metric named "<crate name>::COUNTER_A"
static COUNTER_A: Counter = new;
/// A counter metric named "my.metric.name"
static COUNTER_B: Counter = new;
#
# let metrics = metrics;
# // Metrics may be in any arbitrary order
# let mut names: = metrics.iter.map.collect;
# names.sort;
#
# assert_eq!;
# assert_eq!;
# assert_eq!;
Accessing Metrics
All metrics registered via the [metric] macro can be accessed by calling
the [metrics] function. This will return an instance of the [Metric]
struct which allows you to access all staticly and dynamically registered
metrics.
Suppose we have the metrics declared in the example above.
# // This should remain in sync with the example above.
# use *;
# /// A counter metric named "<crate name>::COUNTER_A"
#
# static COUNTER_A: Counter = new;
#
# /// A counter metric named "my.metric.name"
#
# static COUNTER_B: Counter = new;
#
let metrics = metrics;
// Metrics may be in any arbitrary order
let mut names: = metrics.iter.map.collect;
names.sort;
assert_eq!;
assert_eq!;
assert_eq!;
How it Works
Behind the scenes, this crate uses the [linkme] crate to create a
distributed slice containing a [MetricEntry] instance for each metric that
is registered via the [metric] attribute.