Type Alias GaugeVec
pub type GaugeVec = MetricVec<GaugeVecBuilder<AtomicF64>>;
Expand description
A [Collector
] that bundles a set of Gauge
s that all share
the same [Desc
], but have different values for their variable labels. This is
used if you want to count the same thing partitioned by various dimensions
(e.g. number of operations queued, partitioned by user and operation type).
Aliased Type§
struct GaugeVec { /* private fields */ }
Implementations
§impl<P> MetricVec<GaugeVecBuilder<P>>where
P: Atomic,
impl<P> MetricVec<GaugeVecBuilder<P>>where
P: Atomic,
§impl<T> MetricVec<T>where
T: MetricVecBuilder,
impl<T> MetricVec<T>where
T: MetricVecBuilder,
pub fn create(
metric_type: MetricType,
new_metric: T,
opts: <T as MetricVecBuilder>::P,
) -> Result<MetricVec<T>, Error>
pub fn create( metric_type: MetricType, new_metric: T, opts: <T as MetricVecBuilder>::P, ) -> Result<MetricVec<T>, Error>
create
creates a MetricVec with description desc
, a metric type metric_type
and
a MetricVecBuilder new_metric
.
pub fn get_metric_with_label_values(
&self,
vals: &[&str],
) -> Result<<T as MetricVecBuilder>::M, Error>
pub fn get_metric_with_label_values( &self, vals: &[&str], ) -> Result<<T as MetricVecBuilder>::M, Error>
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).
pub fn get_metric_with(
&self,
labels: &HashMap<&str, &str>,
) -> Result<<T as MetricVecBuilder>::M, Error>
pub fn get_metric_with( &self, labels: &HashMap<&str, &str>, ) -> Result<<T as MetricVecBuilder>::M, Error>
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.
pub fn with_label_values(&self, vals: &[&str]) -> <T as MetricVecBuilder>::M
pub fn with_label_values(&self, vals: &[&str]) -> <T as MetricVecBuilder>::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()
pub fn with(&self, labels: &HashMap<&str, &str>) -> <T as MetricVecBuilder>::M
pub fn with(&self, labels: &HashMap<&str, &str>) -> <T as MetricVecBuilder>::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()
pub fn remove_label_values(&self, vals: &[&str]) -> Result<(), Error>
pub fn remove_label_values(&self, vals: &[&str]) -> Result<(), Error>
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).
pub fn remove(&self, labels: &HashMap<&str, &str>) -> Result<(), Error>
pub fn remove(&self, labels: &HashMap<&str, &str>) -> Result<(), Error>
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.
pub fn reset(&self)
pub fn reset(&self)
reset
deletes all metrics in this vector.