Struct MetricsEncoder

Source
pub struct MetricsEncoder<W: Write> { /* private fields */ }
Expand description

MetricsEncoder provides methods to encode metrics in a text format that can be understood by Prometheus.

Metrics are encoded with the block time included, to allow Prometheus to discard out-of-order samples collected from replicas that are behind.

See Exposition Formats for an informal specification of the text format.

Implementations§

Source§

impl<W: Write> MetricsEncoder<W>

Source

pub fn new(writer: W, now_millis: i64) -> Self

Constructs a new encoder dumping metrics with the given timestamp into the specified writer.

Source

pub fn into_inner(self) -> W

Returns the internal buffer that was used to record the metrics.

Source

pub fn encode_histogram( &mut self, name: &str, buckets: impl Iterator<Item = (f64, f64)>, sum: f64, help: &str, ) -> Result<()>

Encodes the metadata and the value of a histogram.

SUM is the sum of all observed values, before they were put into buckets.

BUCKETS is a list (key, value) pairs, where KEY is the bucket and VALUE is the number of items in this bucket (i.e., it’s not a cumulative value).

Source

pub fn histogram_vec<'a>( &'a mut self, name: &'a str, help: &'a str, ) -> Result<LabeledHistogramBuilder<'a, W>>

Source

pub fn encode_single_value( &mut self, typ: &str, name: &str, value: f64, help: &str, ) -> Result<()>

Source

pub fn encode_counter( &mut self, name: &str, value: f64, help: &str, ) -> Result<()>

Encodes the metadata and the value of a counter.

§Panics

This function panics if the name argument does not match pattern [a-zA-Z_][a-zA-Z0-9_].

Source

pub fn encode_gauge(&mut self, name: &str, value: f64, help: &str) -> Result<()>

Encodes the metadata and the value of a gauge.

§Panics

This function panics if the name argument does not match pattern [a-zA-Z_][a-zA-Z0-9_].

Source

pub fn counter_vec<'a>( &'a mut self, name: &'a str, help: &'a str, ) -> Result<LabeledMetricsBuilder<'a, W>>

Starts encoding of a counter that uses labels.

§Panics

This function panics if the name argument does not match pattern [a-zA-Z_][a-zA-Z0-9_].

Source

pub fn gauge_vec<'a>( &'a mut self, name: &'a str, help: &'a str, ) -> Result<LabeledMetricsBuilder<'a, W>>

Starts encoding of a gauge that uses labels.

§Panics

This function panics if the name argument does not match pattern [a-zA-Z_][a-zA-Z0-9_].

Auto Trait Implementations§

§

impl<W> Freeze for MetricsEncoder<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for MetricsEncoder<W>
where W: RefUnwindSafe,

§

impl<W> Send for MetricsEncoder<W>
where W: Send,

§

impl<W> Sync for MetricsEncoder<W>
where W: Sync,

§

impl<W> Unpin for MetricsEncoder<W>
where W: Unpin,

§

impl<W> UnwindSafe for MetricsEncoder<W>
where W: 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, 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.