ant_quic/metrics/
mod.rs

1//! Metrics collection and export system
2//!
3//! This module provides metrics collection and export capabilities for ant-quic.
4//! It includes both internal metrics collection (always available) and optional
5//! Prometheus export functionality.
6
7pub use crate::logging::metrics::*;
8
9#[cfg(feature = "prometheus")]
10pub mod prometheus;
11
12#[cfg(feature = "prometheus")]
13pub mod http_server;
14
15#[cfg(feature = "prometheus")]
16pub use self::prometheus::PrometheusExporter;
17
18#[cfg(feature = "prometheus")]
19pub use self::http_server::MetricsServer;
20
21/// Configuration for metrics collection and export
22#[derive(Debug, Clone)]
23pub struct MetricsConfig {
24    /// Whether to enable metrics collection
25    pub enabled: bool,
26    /// Port for the metrics HTTP server (only used when prometheus feature is enabled)
27    pub port: u16,
28    /// Address to bind the metrics server to
29    pub bind_address: std::net::IpAddr,
30    /// Update interval for metrics collection
31    pub update_interval: std::time::Duration,
32}
33
34impl Default for MetricsConfig {
35    fn default() -> Self {
36        Self {
37            enabled: false,
38            port: 9090,
39            bind_address: std::net::IpAddr::V4(std::net::Ipv4Addr::new(0, 0, 0, 0)),
40            update_interval: std::time::Duration::from_secs(30),
41        }
42    }
43}
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_metrics_config_default() {
51        let config = MetricsConfig::default();
52        assert!(!config.enabled);
53        assert_eq!(config.port, 9090);
54        assert_eq!(config.bind_address, std::net::IpAddr::V4(std::net::Ipv4Addr::new(0, 0, 0, 0)));
55        assert_eq!(config.update_interval, std::time::Duration::from_secs(30));
56    }
57}