Struct prometheus::core::MetricVec

source ·
pub struct MetricVec<T: MetricVecBuilder> { /* private fields */ }
Expand description

A Collector to bundle metrics of the same name that differ in their label values. It is usually not used directly but as a building block for implementations of vectors of a given metric type. GaugeVec and CounterVec are examples already provided in this package.

Implementations§

source§

impl<P: Atomic> MetricVec<CounterVecBuilder<P>>

source

pub fn new(opts: Opts, label_names: &[&str]) -> Result<Self>

Create a new GenericCounterVec based on the provided Opts and partitioned by the given label names. At least one label name must be provided.

source

pub fn local(&self) -> GenericLocalCounterVec<P>

Return a GenericLocalCounterVec for single thread usage.

source§

impl<P: Atomic> MetricVec<GaugeVecBuilder<P>>

source

pub fn new(opts: Opts, label_names: &[&str]) -> Result<Self>

Create a new GenericGaugeVec based on the provided Opts and partitioned by the given label names. At least one label name must be provided.

source§

impl MetricVec<HistogramVecBuilder>

source

pub fn new(opts: HistogramOpts, label_names: &[&str]) -> Result<HistogramVec>

Create a new HistogramVec based on the provided HistogramOpts and partitioned by the given label names. At least one label name must be provided.

source

pub fn local(&self) -> LocalHistogramVec

Return a LocalHistogramVec for single thread usage.

source§

impl<T: MetricVecBuilder> MetricVec<T>

source

pub fn create( metric_type: MetricType, new_metric: T, opts: T::P, ) -> Result<MetricVec<T>>

create creates a MetricVec with description desc, a metric type metric_type and a MetricVecBuilder new_metric.

source

pub fn get_metric_with_label_values(&self, vals: &[&str]) -> Result<T::M>

get_metric_with_label_values returns the Metric for the given slice of label values (same order as the VariableLabels in Desc). If that combination of label values is accessed for the first time, a new Metric is created.

It is possible to call this method without using the returned Metric to only create the new Metric but leave it at its start value (e.g. a Histogram without any observations).

Keeping the Metric for later use is possible (and should be considered if performance is critical), but keep in mind that Reset, DeleteLabelValues and Delete can be used to delete the Metric from the MetricVec. In that case, the Metric will still exist, but it will not be exported anymore, even if a Metric with the same label values is created later. See also the CounterVec example.

An error is returned if the number of label values is not the same as the number of VariableLabels in Desc.

Note that for more than one label value, this method is prone to mistakes caused by an incorrect order of arguments. Consider get_metric_with(labels) as an alternative to avoid that type of mistake. For higher label numbers, the latter has a much more readable (albeit more verbose) syntax, but it comes with a performance overhead (for creating and processing the Labels map).

source

pub fn get_metric_with(&self, labels: &HashMap<&str, &str>) -> Result<T::M>

get_metric_with returns the Metric for the given Labels map (the label names must match those of the VariableLabels in Desc). If that label map is accessed for the first time, a new Metric is created. Implications of creating a Metric without using it and keeping the Metric for later use are the same as for GetMetricWithLabelValues.

An error is returned if the number and names of the Labels are inconsistent with those of the VariableLabels in Desc.

This method is used for the same purpose as get_metric_with_label_values. See there for pros and cons of the two methods.

source

pub fn with_label_values(&self, vals: &[&str]) -> T::M

with_label_values works as get_metric_with_label_values, but panics if an error occurs.

§Examples
use prometheus::{CounterVec, Opts};
let vec = CounterVec::new(
    Opts::new("requests_total", "Number of requests."),
    &["code", "http_method"]
).unwrap();
vec.with_label_values(&["404", "POST"]).inc()
source

pub fn with(&self, labels: &HashMap<&str, &str>) -> T::M

with works as get_metric_with, but panics if an error occurs. The method allows neat syntax like: httpReqs.with(Labels{“status”:“404”, “method”:“POST”}).inc()

source

pub fn remove_label_values(&self, vals: &[&str]) -> Result<()>

remove_label_values removes the metric where the variable labels are the same as those passed in as labels (same order as the VariableLabels in Desc). It returns true if a metric was deleted.

It returns an error if the number of label values is not the same as the number of VariableLabels in Desc.

Note that for more than one label value, this method is prone to mistakes caused by an incorrect order of arguments. Consider delete(labels) as an alternative to avoid that type of mistake. For higher label numbers, the latter has a much more readable (albeit more verbose) syntax, but it comes with a performance overhead (for creating and processing the Labels map).

source

pub fn remove(&self, labels: &HashMap<&str, &str>) -> Result<()>

remove removes the metric where the variable labels are the same as those passed in as labels. It returns true if a metric was deleted.

It returns an error if the number and names of the Labels are inconsistent with those of the VariableLabels in the Desc of the MetricVec.

This method is used for the same purpose as delete_label_values. See there for pros and cons of the two methods.

source

pub fn reset(&self)

reset deletes all metrics in this vector.

Trait Implementations§

source§

impl<T: Clone + MetricVecBuilder> Clone for MetricVec<T>

source§

fn clone(&self) -> MetricVec<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: MetricVecBuilder> Collector for MetricVec<T>

source§

fn desc(&self) -> Vec<&Desc>

Return descriptors for metrics.
source§

fn collect(&self) -> Vec<MetricFamily>

Collect metrics.
source§

impl<T: MetricVecBuilder> Debug for MetricVec<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for MetricVec<T>

§

impl<T> !RefUnwindSafe for MetricVec<T>

§

impl<T> Send for MetricVec<T>

§

impl<T> Sync for MetricVec<T>

§

impl<T> Unpin for MetricVec<T>

§

impl<T> !UnwindSafe for MetricVec<T>

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> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.