metrics_exporter_prometheus/exporter/
mod.rs

1#[cfg(feature = "http-listener")]
2use http_listener::HttpListeningError;
3#[cfg(any(feature = "http-listener", feature = "push-gateway"))]
4use std::future::Future;
5#[cfg(feature = "http-listener")]
6use std::net::SocketAddr;
7#[cfg(any(feature = "http-listener", feature = "push-gateway"))]
8use std::pin::Pin;
9#[cfg(feature = "push-gateway")]
10use std::time::Duration;
11
12#[cfg(feature = "push-gateway")]
13use hyper::Uri;
14
15/// Error types possible from an exporter
16#[cfg(any(feature = "http-listener", feature = "push-gateway"))]
17#[derive(Debug)]
18pub enum ExporterError {
19    #[cfg(feature = "http-listener")]
20    HttpListener(HttpListeningError),
21    PushGateway(()),
22}
23/// Convenience type for Future implementing an exporter.
24#[cfg(any(feature = "http-listener", feature = "push-gateway"))]
25pub type ExporterFuture = Pin<Box<dyn Future<Output = Result<(), ExporterError>> + Send + 'static>>;
26
27#[cfg(feature = "http-listener")]
28#[derive(Clone, Debug)]
29enum ListenDestination {
30    Tcp(SocketAddr),
31    #[cfg(feature = "uds-listener")]
32    Uds(std::path::PathBuf),
33}
34
35#[derive(Clone, Debug)]
36enum ExporterConfig {
37    // Run an HTTP listener on the given `listen_address`.
38    #[cfg(feature = "http-listener")]
39    HttpListener { destination: ListenDestination },
40
41    // Run a push gateway task sending to the given `endpoint` after `interval` time has elapsed,
42    // infinitely.
43    #[cfg(feature = "push-gateway")]
44    PushGateway {
45        endpoint: Uri,
46        interval: Duration,
47        username: Option<String>,
48        password: Option<String>,
49        use_http_post_method: bool,
50    },
51
52    #[allow(dead_code)]
53    Unconfigured,
54}
55
56impl ExporterConfig {
57    #[cfg_attr(not(any(feature = "http-listener", feature = "push-gateway")), allow(dead_code))]
58    fn as_type_str(&self) -> &'static str {
59        match self {
60            #[cfg(feature = "http-listener")]
61            Self::HttpListener { .. } => "http-listener",
62            #[cfg(feature = "push-gateway")]
63            Self::PushGateway { .. } => "push-gateway",
64            Self::Unconfigured => "unconfigured,",
65        }
66    }
67}
68
69#[cfg(feature = "http-listener")]
70mod http_listener;
71
72#[cfg(feature = "push-gateway")]
73mod push_gateway;
74
75pub(crate) mod builder;