pub struct Registry<K, S>
where K: Hashable, S: Storage<K>,
{ /* private fields */ }
Available on crate feature registry only.
Expand description

A high-performance metric registry.

Registry provides the ability to maintain a central listing of metrics mapped by a given key. Metrics themselves are stored in the objects returned by S.

§Using Registry as the basis of an exporter

As a reusable building blocking for building exporter implementations, users should look at Key and AtomicStorage to use for their key and storage, respectively.

These two implementations provide behavior that is suitable for most exporters, providing seamless integration with the existing key type used by the core Recorder trait, as well as atomic storage for metrics.

In some cases, users may prefer GenerationalAtomicStorage when know if a metric has been touched, even if its value has not changed since the last time it was observed, is necessary.

§Performance

Registry is optimized for reads.

Implementations§

source§

impl Registry<Key, AtomicStorage>

source

pub fn atomic() -> Self

Creates a new Registry using a regular Key and atomic storage.

source§

impl<K, S> Registry<K, S>
where K: Clone + Eq + Hashable, S: Storage<K>,

source

pub fn new(storage: S) -> Self

Creates a new Registry.

source

pub fn clear(&self)

Removes all metrics from the registry.

This operation is eventually consistent: metrics will be removed piecemeal, and this method does not ensure that callers will see the registry as entirely empty at any given point.

source

pub fn get_or_create_counter<O, V>(&self, key: &K, op: O) -> V
where O: FnOnce(&S::Counter) -> V,

Gets or creates the given counter.

The op function will be called for the counter under the given key, with the counter first being created if it does not already exist.

source

pub fn get_or_create_gauge<O, V>(&self, key: &K, op: O) -> V
where O: FnOnce(&S::Gauge) -> V,

Gets or creates the given gauge.

The op function will be called for the gauge under the given key, with the gauge first being created if it does not already exist.

source

pub fn get_or_create_histogram<O, V>(&self, key: &K, op: O) -> V
where O: FnOnce(&S::Histogram) -> V,

Gets or creates the given histogram.

The op function will be called for the histogram under the given key, with the histogram first being created if it does not already exist.

source

pub fn delete_counter(&self, key: &K) -> bool

Deletes a counter from the registry.

Returns true if the counter existed and was removed, false otherwise.

source

pub fn delete_gauge(&self, key: &K) -> bool

Deletes a gauge from the registry.

Returns true if the gauge existed and was removed, false otherwise.

source

pub fn delete_histogram(&self, key: &K) -> bool

Deletes a histogram from the registry.

Returns true if the histogram existed and was removed, false otherwise.

source

pub fn visit_counters<F>(&self, collect: F)
where F: FnMut(&K, &S::Counter),

Visits every counter stored in this registry.

This operation does not lock the entire registry, but proceeds directly through the “subshards” that are kept internally. As a result, all subshards will be visited, but a metric that existed at the exact moment that visit_counters was called may not actually be observed if it is deleted before that subshard is reached. Likewise, a metric that is added after the call to visit_counters, but before visit_counters finishes, may also not be observed.

source

pub fn visit_gauges<F>(&self, collect: F)
where F: FnMut(&K, &S::Gauge),

Visits every gauge stored in this registry.

This operation does not lock the entire registry, but proceeds directly through the “subshards” that are kept internally. As a result, all subshards will be visited, but a metric that existed at the exact moment that visit_gauges was called may not actually be observed if it is deleted before that subshard is reached. Likewise, a metric that is added after the call to visit_gauges, but before visit_gauges finishes, may also not be observed.

source

pub fn visit_histograms<F>(&self, collect: F)
where F: FnMut(&K, &S::Histogram),

Visits every histogram stored in this registry.

This operation does not lock the entire registry, but proceeds directly through the “subshards” that are kept internally. As a result, all subshards will be visited, but a metric that existed at the exact moment that visit_histograms was called may not actually be observed if it is deleted before that subshard is reached. Likewise, a metric that is added after the call to visit_histograms, but before visit_histograms finishes, may also not be observed.

source

pub fn get_counter_handles(&self) -> HashMap<K, S::Counter>

Gets a map of all present counters, mapped by key.

This map is a point-in-time snapshot of the registry.

source

pub fn get_gauge_handles(&self) -> HashMap<K, S::Gauge>

Gets a map of all present gauges, mapped by key.

This map is a point-in-time snapshot of the registry.

source

pub fn get_histogram_handles(&self) -> HashMap<K, S::Histogram>

Gets a map of all present histograms, mapped by key.

This map is a point-in-time snapshot of the registry.

source

pub fn get_counter(&self, key: &K) -> Option<S::Counter>

Gets a copy of an existing counter.

source

pub fn get_gauge(&self, key: &K) -> Option<S::Gauge>

Gets a copy of an existing gauge.

source

pub fn get_histogram(&self, key: &K) -> Option<S::Histogram>

Gets a copy of an existing histogram.

source

pub fn retain_counters<F>(&self, f: F)
where F: FnMut(&K, &S::Counter) -> bool,

Retains only counters specified by the predicate.

Remove all counters for which f(&k, &c) returns false. This operation proceeds through the “subshards” in the same way as visit_counters.

source

pub fn retain_gauges<F>(&self, f: F)
where F: FnMut(&K, &S::Gauge) -> bool,

Retains only gauges specified by the predicate.

Remove all gauges for which f(&k, &g) returns false. This operation proceeds through the “subshards” in the same way as visit_gauges.

source

pub fn retain_histograms<F>(&self, f: F)
where F: FnMut(&K, &S::Histogram) -> bool,

Retains only histograms specified by the predicate.

Remove all histograms for which f(&k, &h) returns false. This operation proceeds through the “subshards” in the same way as visit_histograms.

Auto Trait Implementations§

§

impl<K, S> Freeze for Registry<K, S>
where S: Freeze,

§

impl<K, S> RefUnwindSafe for Registry<K, S>
where S: RefUnwindSafe,

§

impl<K, S> Send for Registry<K, S>
where K: Send, S: Send, <S as Storage<K>>::Counter: Send, <S as Storage<K>>::Gauge: Send, <S as Storage<K>>::Histogram: Send,

§

impl<K, S> Sync for Registry<K, S>
where K: Sync + Send, S: Sync, <S as Storage<K>>::Counter: Sync + Send, <S as Storage<K>>::Gauge: Sync + Send, <S as Storage<K>>::Histogram: Sync + Send,

§

impl<K, S> Unpin for Registry<K, S>
where K: Unpin, S: Unpin, <S as Storage<K>>::Counter: Unpin, <S as Storage<K>>::Gauge: Unpin, <S as Storage<K>>::Histogram: Unpin,

§

impl<K, S> UnwindSafe for Registry<K, S>
where S: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.