prometheus_client/
metrics.rs

1//! Metric type implementations.
2
3pub mod counter;
4pub mod exemplar;
5pub mod family;
6pub mod gauge;
7pub mod histogram;
8pub mod info;
9
10/// A metric that is aware of its Open Metrics metric type.
11pub trait TypedMetric {
12    /// The OpenMetrics metric type.
13    const TYPE: MetricType = MetricType::Unknown;
14}
15
16/// OpenMetrics metric type.
17#[derive(Clone, Copy, Debug)]
18#[allow(missing_docs)]
19pub enum MetricType {
20    Counter,
21    Gauge,
22    Histogram,
23    Info,
24    Unknown,
25    // Not (yet) supported metric types.
26    //
27    // GaugeHistogram,
28    // StateSet,
29    // Summary
30}
31
32impl MetricType {
33    /// Returns the given metric type's str representation.
34    pub fn as_str(&self) -> &str {
35        match self {
36            MetricType::Counter => "counter",
37            MetricType::Gauge => "gauge",
38            MetricType::Histogram => "histogram",
39            MetricType::Info => "info",
40            MetricType::Unknown => "unknown",
41        }
42    }
43}