diff --git a/metrics/src/lib.rs b/metrics/src/lib.rs index 82665c1b55..4108fb9a86 100644 --- a/metrics/src/lib.rs +++ b/metrics/src/lib.rs @@ -14,19 +14,49 @@ #![forbid(unsafe_code)] -pub const GAUGE_NAMES: [&str; 1] = [committee::TOTAL_STAKE]; +const GAUGE_NAMES: [&str; 1] = [committee::TOTAL_STAKE]; pub mod committee { pub const TOTAL_STAKE: &str = "snarkvm_ledger_committee_total_stake"; } -/// Registers all metrics. +/// Registers all snarkVM metrics. pub fn register_metrics() { for name in GAUGE_NAMES { - ::metrics::register_gauge!(name); + register_gauge(name); } } +/******** Counter ********/ + +/// Registers a counter with the given name. +pub fn register_counter(name: &'static str) { + ::metrics::register_counter!(name); +} + +/// Updates a counter with the given name to the given value. +/// +/// Counters represent a single monotonic value, which means the value can only be incremented, +/// not decremented, and always starts out with an initial value of zero. +pub fn counter>(name: &'static str, value: V) { + ::metrics::counter!(name, value.into()); +} + +/// Increments a counter with the given name by one. +/// +/// Counters represent a single monotonic value, which means the value can only be incremented, +/// not decremented, and always starts out with an initial value of zero. +pub fn increment_counter(name: &'static str) { + ::metrics::increment_counter!(name); +} + +/******** Gauge ********/ + +/// Registers a gauge with the given name. +pub fn register_gauge(name: &'static str) { + ::metrics::register_gauge!(name); +} + /// Updates a gauge with the given name to the given value. /// /// Gauges represent a single value that can go up or down over time, @@ -34,3 +64,31 @@ pub fn register_metrics() { pub fn gauge>(name: &'static str, value: V) { ::metrics::gauge!(name, value.into()); } + +/// Increments a gauge with the given name by the given value. +/// +/// Gauges represent a single value that can go up or down over time, +/// and always starts out with an initial value of zero. +pub fn increment_gauge>(name: &'static str, value: V) { + ::metrics::increment_gauge!(name, value.into()); +} + +/// Decrements a gauge with the given name by the given value. +/// +/// Gauges represent a single value that can go up or down over time, +/// and always starts out with an initial value of zero. +pub fn decrement_gauge>(name: &'static str, value: V) { + ::metrics::decrement_gauge!(name, value.into()); +} + +/******** Histogram ********/ + +/// Registers a histogram with the given name. +pub fn register_histogram(name: &'static str) { + ::metrics::register_histogram!(name); +} + +/// Updates a histogram with the given name to the given value. +pub fn histogram>(name: &'static str, value: V) { + ::metrics::histogram!(name, value.into()); +}