pub struct MetricsRegistry { /* private fields */ }Expand description
A lightweight, thread-safe metrics registry that can export its state in Prometheus text format.
Metrics are keyed by a full name that includes labels encoded as
name{label1="val1",label2="val2"}. The helper methods
counter_with_labels etc. build
these keys automatically.
Implementations§
Source§impl MetricsRegistry
impl MetricsRegistry
Sourcepub fn register_counter(&self, name: &str, help: &str)
pub fn register_counter(&self, name: &str, help: &str)
Register a counter with help text.
Sourcepub fn register_gauge(&self, name: &str, help: &str)
pub fn register_gauge(&self, name: &str, help: &str)
Register a gauge with help text.
Sourcepub fn register_histogram(&self, name: &str, help: &str)
pub fn register_histogram(&self, name: &str, help: &str)
Register a histogram with help text.
Sourcepub fn counter_inc(&self, key: &str)
pub fn counter_inc(&self, key: &str)
Increment a counter by 1.
Sourcepub fn counter_add(&self, key: &str, n: u64)
pub fn counter_add(&self, key: &str, n: u64)
Increment a counter by n.
Sourcepub fn counter_with_labels(&self, name: &str, labels: &[(&str, &str)])
pub fn counter_with_labels(&self, name: &str, labels: &[(&str, &str)])
Build a label-encoded key and increment the counter by 1.
Sourcepub fn counter_add_with_labels(
&self,
name: &str,
labels: &[(&str, &str)],
n: u64,
)
pub fn counter_add_with_labels( &self, name: &str, labels: &[(&str, &str)], n: u64, )
Build a label-encoded key and add n to the counter.
Sourcepub fn counter_get(&self, key: &str) -> u64
pub fn counter_get(&self, key: &str) -> u64
Get the current value of a counter.
Sourcepub fn histogram_observe(&self, key: &str, value: f64)
pub fn histogram_observe(&self, key: &str, value: f64)
Record a value in a histogram, creating it with default buckets if it does not yet exist.
Sourcepub fn histogram_observe_with_labels(
&self,
name: &str,
labels: &[(&str, &str)],
value: f64,
)
pub fn histogram_observe_with_labels( &self, name: &str, labels: &[(&str, &str)], value: f64, )
Record a value in a histogram with labels.
Sourcepub fn histogram_get(&self, key: &str) -> Option<(Vec<(f64, u64)>, f64, u64)>
pub fn histogram_get(&self, key: &str) -> Option<(Vec<(f64, u64)>, f64, u64)>
Get a histogram’s snapshot: (buckets, sum, count).
Sourcepub fn export_prometheus(&self) -> String
pub fn export_prometheus(&self) -> String
Export all metrics in Prometheus text exposition format.
Trait Implementations§
Source§impl Debug for MetricsRegistry
impl Debug for MetricsRegistry
Auto Trait Implementations§
impl Freeze for MetricsRegistry
impl !RefUnwindSafe for MetricsRegistry
impl Send for MetricsRegistry
impl Sync for MetricsRegistry
impl Unpin for MetricsRegistry
impl UnsafeUnpin for MetricsRegistry
impl UnwindSafe for MetricsRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more