Skip to content

Commit

Permalink
Merge pull request #2259 from AleoHQ/feat/metrics-expand
Browse files Browse the repository at this point in the history
Updates the metrics with all types
  • Loading branch information
howardwu authored Dec 19, 2023
2 parents bbec2a6 + f6aaf89 commit 0e5b7e6
Showing 1 changed file with 61 additions and 3 deletions.
64 changes: 61 additions & 3 deletions metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,81 @@

#![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<V: Into<u64>>(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,
/// and always starts out with an initial value of zero.
pub fn gauge<V: Into<f64>>(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<V: Into<f64>>(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<V: Into<f64>>(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<V: Into<f64>>(name: &'static str, value: V) {
::metrics::histogram!(name, value.into());
}

0 comments on commit 0e5b7e6

Please sign in to comment.