prometheus_client/metrics/
info.rs

1//! Module implementing an Open Metrics info metric.
2//!
3//! See [`Info`] for details.
4
5use crate::{
6    encoding::{EncodeLabelSet, EncodeMetric, MetricEncoder},
7    metrics::{MetricType, TypedMetric},
8};
9
10/// Open Metrics [`Info`] metric "to expose textual information which SHOULD NOT
11/// change during process lifetime".
12///
13/// ```
14/// # use prometheus_client::metrics::info::Info;
15///
16/// let _info = Info::new(vec![("os", "GNU/linux")]);
17/// ```
18#[derive(Debug)]
19pub struct Info<S>(pub(crate) S);
20
21impl<S> Info<S> {
22    /// Create [`Info`] metric with the provided label set.
23    pub fn new(label_set: S) -> Self {
24        Self(label_set)
25    }
26}
27
28impl<S> TypedMetric for Info<S> {
29    const TYPE: MetricType = MetricType::Info;
30}
31
32impl<S> EncodeMetric for Info<S>
33where
34    S: Clone + std::hash::Hash + Eq + EncodeLabelSet,
35{
36    fn encode(&self, mut encoder: MetricEncoder) -> Result<(), std::fmt::Error> {
37        encoder.encode_info(&self.0)
38    }
39
40    fn metric_type(&self) -> MetricType {
41        Self::TYPE
42    }
43}