vise_exporter/
metrics.rs

1//! Internal metrics for the exporter itself.
2
3use std::{fmt, time::Duration};
4
5use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Global, Histogram, Metrics, Unit};
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)]
8#[metrics(label = "facade")]
9pub(crate) enum Facade {
10    Vise,
11}
12
13impl fmt::Display for Facade {
14    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
15        formatter.write_str(match self {
16            Self::Vise => "vise",
17        })
18    }
19}
20
21const BYTE_BUCKETS: Buckets = Buckets::exponential(1_024.0..=1_024.0 * 1_024.0, 4.0);
22
23#[derive(Debug, Metrics)]
24#[metrics(prefix = "vise_exporter")]
25pub(crate) struct ExporterMetrics {
26    /// Scraping latency of the exporter.
27    #[metrics(buckets = Buckets::LATENCIES, unit = Unit::Seconds)]
28    pub scrape_latency: Family<Facade, Histogram<Duration>>,
29    /// Size of all metrics using a certain façade.
30    #[metrics(buckets = BYTE_BUCKETS, unit = Unit::Bytes)]
31    pub scraped_size: Family<Facade, Histogram<usize>>,
32}
33
34// Due to the recursive nature of the metrics definition, using a collector is problematic.
35#[vise::register]
36pub(crate) static EXPORTER_METRICS: Global<ExporterMetrics> = Global::new();