Crate near_metrics[−][src]
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() { for i in 0..100 { inc_counter(&RUN_COUNT); let timer = start_timer(&RUN_TIME); for j in 0..10 { set_gauge(&CURRENT_VALUE, j); println!("Howdy partner"); } stop_timer(timer); } }
Structs
Histogram | A |
TextEncoder | An implementation of an |
Traits
Encoder | An interface for encoding metric families into an underlying wire protocol. |
Functions
dec_gauge | |
gather | Collect all the metrics for reporting. |
get_counter | |
inc_counter | |
inc_counter_by | |
inc_counter_by_opt | |
inc_counter_opt | |
inc_counter_vec | |
inc_gauge | |
observe | Sets the value of a |
set_gauge | |
start_timer | Starts a timer for the given |
start_timer_vec | Starts a timer for the given |
stop_timer | Stops a timer created with |
try_create_histogram | Attempts to crate a |
try_create_histogram_vec | Attempts to create a |
try_create_int_counter | Attempts to crate an |
try_create_int_counter_vec | Attempts to crate an |
try_create_int_gauge | Attempts to crate an |
Type Definitions
HistogramVec | A |
IntCounter | The integer version of |
IntCounterVec | The integer version of |
IntGauge | The integer version of |
Result | A specialized Result type for prometheus. |