From d5e9c7fb5e0232356ab7fb8802078bc63079611c Mon Sep 17 00:00:00 2001 From: Howard Wu <9260812+howardwu@users.noreply.github.com> Date: Tue, 19 Dec 2023 10:29:50 -0800 Subject: [PATCH 1/2] Updates the metrics with all types --- metrics/src/lib.rs | 62 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/metrics/src/lib.rs b/metrics/src/lib.rs index 82665c1b55..83e9748539 100644 --- a/metrics/src/lib.rs +++ b/metrics/src/lib.rs @@ -20,13 +20,43 @@ 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()); +} From f6aaf895b9336a249f612779d2c4b0eaa8f228e1 Mon Sep 17 00:00:00 2001 From: Howard Wu <9260812+howardwu@users.noreply.github.com> Date: Tue, 19 Dec 2023 10:43:15 -0800 Subject: [PATCH 2/2] Make gauges names private --- metrics/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metrics/src/lib.rs b/metrics/src/lib.rs index 83e9748539..4108fb9a86 100644 --- a/metrics/src/lib.rs +++ b/metrics/src/lib.rs @@ -14,7 +14,7 @@ #![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";