nom_openmetrics/
metric_descriptor.rs

1/// The HELP, TYPE, and UNIT of a metric
2#[derive(Debug, PartialEq)]
3pub enum MetricDescriptor<'a> {
4    /// The `MetricType`
5    Type {
6        metric: &'a str,
7        r#type: MetricType<'a>,
8    },
9    /// The metric description
10    Help { metric: &'a str, help: String },
11    /// The metric unit
12    Unit { metric: &'a str, unit: &'a str },
13}
14
15impl<'a> MetricDescriptor<'a> {
16    /// Crate a HELP descriptor
17    pub fn help(metric: &'a str, help: String) -> Self {
18        Self::Help { metric, help }
19    }
20
21    /// Crate a TYPE descriptor
22    pub fn r#type(metric: &'a str, r#type: MetricType<'a>) -> Self {
23        Self::Type { metric, r#type }
24    }
25
26    /// Crate a UNIT descriptor
27    pub fn unit(metric: &'a str, unit: &'a str) -> Self {
28        Self::Unit { metric, unit }
29    }
30
31    /// The metric name
32    pub fn metric(&self) -> &'a str {
33        match self {
34            MetricDescriptor::Type { metric, .. }
35            | MetricDescriptor::Help { metric, .. }
36            | MetricDescriptor::Unit { metric, .. } => metric,
37        }
38    }
39}
40
41/// The type of the metric
42#[derive(Debug, PartialEq, strum::Display)]
43pub enum MetricType<'a> {
44    /// A counter measures discrete events
45    Counter,
46    /// A guage measures a current value
47    Gauge,
48    /// A gauge histogram measures current distributions
49    Gaugehistogram,
50    /// A distribution of discrete events
51    Histogram,
52    /// Exposes textual information through labels
53    Info,
54    /// A series of related boolean values
55    Stateset,
56    /// A quantile summary of discrete events
57    Summary,
58    /// Unknown type
59    #[strum(to_string = "{0}")]
60    Unknown(&'a str),
61}