Skip to main content

MetricsCore

Struct MetricsCore 

Source
pub struct MetricsCore { /* private fields */ }
Expand description

Main metrics interface - the core of everything

Implementations§

Source§

impl MetricsCore

Source

pub fn new() -> Self

Create new metrics core

Source

pub fn counter(&self, name: &str) -> Arc<Counter>

Get or create a counter by name. Requires the count feature.

name is accepted as &str — string literals ("counter") and owned/borrowed runtime names both work. The first lookup for a given name allocates a String key inside the registry; subsequent lookups of the same name reuse the cached Arc and perform no allocations.

Source

pub fn counter_with(&self, name: &str, labels: &LabelSet) -> Arc<Counter>

Get or create a labeled counter. Requires the count feature.

Routes to the cardinality overflow sink when the cap is full; use Self::try_counter_with to receive an explicit error instead.

Source

pub fn try_counter_with( &self, name: &str, labels: &LabelSet, ) -> Result<Arc<Counter>>

Labeled counter returning Err(CardinalityExceeded) when the cap is full. Requires the count feature.

Source

pub fn gauge(&self, name: &str) -> Arc<Gauge>

Get or create a gauge by name. Requires the gauge feature.

name is accepted as &str — see Self::counter for allocation semantics.

Source

pub fn gauge_with(&self, name: &str, labels: &LabelSet) -> Arc<Gauge>

Get or create a labeled gauge. Requires the gauge feature.

Source

pub fn try_gauge_with( &self, name: &str, labels: &LabelSet, ) -> Result<Arc<Gauge>>

Labeled gauge returning Err(CardinalityExceeded) when the cap is full. Requires the gauge feature.

Source

pub fn timer(&self, name: &str) -> Arc<Timer>

Get or create a timer by name. Requires the timer feature.

name is accepted as &str — see Self::counter for allocation semantics.

Source

pub fn timer_with(&self, name: &str, labels: &LabelSet) -> Arc<Timer>

Get or create a labeled timer. Requires the timer feature.

Source

pub fn try_timer_with( &self, name: &str, labels: &LabelSet, ) -> Result<Arc<Timer>>

Labeled timer returning Err(CardinalityExceeded) when the cap is full. Requires the timer feature.

Source

pub fn time<T>(&self, name: &str, f: impl FnOnce() -> T) -> T

Time a synchronous closure and record the elapsed duration. Requires the timer feature.

Source

pub fn system(&self) -> &SystemHealth

Get system health interface

Source

pub fn registry(&self) -> &Registry

Get registry for advanced operations

Source

pub fn scoped(&self, prefix: impl Into<String>) -> ScopedRegistry<'_>

Create a ScopedRegistry over this MetricsCore’s Registry.

Shorthand for self.registry().scoped(prefix). Useful for tying a metrics namespace to a subsystem. Available since v0.9.5.

§Example
use metrics_lib::{init, metrics};
init();
let http = metrics().scoped("http.");
http.counter("requests").inc();

Trait Implementations§

Source§

impl Default for MetricsCore

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.