Crate near_metrics
source · [−]Expand description
A fork of the lighthouse_metrics crate used to implement prometheus
A wrapper around the prometheus
crate that provides a global, lazy_static
metrics registry
and functions to add and use the following components (more info at
Prometheus docs):
Histogram
: used withstart_timer(..)
andstop_timer(..)
to record durations (e.g., block processing time).IncCounter
: used to represent an ideally ever-growing, never-shrinking integer (e.g., number of block processing requests).IntGauge
: used to represent an varying integer (e.g., number of attestations per block).
Important
Metrics will fail if two items have the same name
. All metrics must have a unique name
.
Because we use a global registry there is no namespace per crate, it’s one big global space.
See the Prometheus naming best practices when choosing metric names.
Example
#[macro_use]
extern crate lazy_static;
use near_metrics::*;
// These metrics are "magically" linked to the global registry defined in `lighthouse_metrics`.
lazy_static! {
pub static ref RUN_COUNT: Result<IntCounter> = try_create_int_counter(
"runs_total",
"Total number of runs"
);
pub static ref CURRENT_VALUE: Result<IntGauge> = try_create_int_gauge(
"current_value",
"The current value"
);
pub static ref RUN_TIME: Result<Histogram> =
try_create_histogram("run_seconds", "Time taken (measured to high precision)");
}
fn main() {
let run_count: Result<IntCounter> = try_create_int_counter(&"RUN_COUNT", &"RUN_COUNT");
let run_time: Result<Histogram> = try_create_histogram("RUN_TIME", &"RUN_TIME");
let current_value: Result<IntGauge> = try_create_int_gauge("CURRENT_VALUE", "RUN_COUNT");
for i in 0..100 {
inc_counter(&run_count);
let timer = start_timer(&run_time);
for j in 0..10 {
set_gauge(¤t_value, j);
println!("Howdy partner");
}
stop_timer(timer);
}
}
Structs
An implementation of an Encoder
that converts a MetricFamily
proto message
into text format.
Traits
An interface for encoding metric families into an underlying wire protocol.
Functions
Collect all the metrics for reporting.
Sets the value of a Histogram
manually.
Starts a timer for the given Histogram
, stopping when it gets dropped or given to stop_timer(..)
.
Starts a timer for the given HistogramVec
and labels, stopping when it gets dropped or given to stop_timer(..)
.
Stops a timer created with start_timer(..)
.
Attempts to crate a Histogram
, returning Err
if the registry does not accept the counter
(potentially due to naming conflict).
Attempts to create a HistogramVector
, returning Err
if the registry does not accept the counter
(potentially due to naming conflict).
Attempts to crate an IntCounter
, returning Err
if the registry does not accept the counter
(potentially due to naming conflict).
Attempts to crate an IntCounterVec
, returning Err
if the registry does not accept the counter
(potentially due to naming conflict).
Attempts to crate an IntGauge
, returning Err
if the registry does not accept the gauge
(potentially due to naming conflict).
Attempts to crate an IntGaugeVec
, returning Err
if the registry does not accept the gauge
(potentially due to naming conflict).
Type Definitions
The integer version of Counter
. Provides better performance if metric values
are all positive integers (natural numbers).
The integer version of CounterVec
. Provides better performance if metric
are all positive integers (natural numbers).
The integer version of Gauge
. Provides better performance if metric values are
all integers.
The integer version of GaugeVec
. Provides better performance if metric values
are all integers.
A specialized Result type for prometheus.