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//!
7//! ## Feature Gates
8//!
9//! - **Basic metrics**: Always available (no feature flag required)
10//! - **Prometheus export**: Requires the `prometheus` feature flag
11//!
12//! ## Example
13//!
14//! ```rust
15//! use ant_quic::metrics::MetricsConfig;
16//!
17//! // Basic metrics config (always available)
18//! let config = MetricsConfig::default();
19//! assert!(!config.enabled);
20//!
21//! #[cfg(feature = "prometheus")]
22//! {
23//! // Prometheus-specific functionality only available with feature flag
24//! use ant_quic::metrics::{PrometheusExporter, MetricsServer};
25//! }
26//! ```
27
28pub use crate::logging::metrics::*;
29
30#[cfg(feature = "prometheus")]
31pub mod prometheus;
32
33#[cfg(feature = "prometheus")]
34pub mod http_server;
35
36#[cfg(feature = "prometheus")]
37pub use self::prometheus::PrometheusExporter;
38
39#[cfg(feature = "prometheus")]
40pub use self::http_server::MetricsServer;
41
42/// Configuration for metrics collection and export
43#[derive(Debug, Clone)]
44pub struct MetricsConfig {
45 /// Whether to enable metrics collection
46 pub enabled: bool,
47 /// Port for the metrics HTTP server (only used when prometheus feature is enabled)
48 pub port: u16,
49 /// Address to bind the metrics server to
50 pub bind_address: std::net::IpAddr,
51 /// Update interval for metrics collection
52 pub update_interval: std::time::Duration,
53}
54
55impl Default for MetricsConfig {
56 fn default() -> Self {
57 Self {
58 enabled: false,
59 port: 9090,
60 bind_address: std::net::IpAddr::V4(std::net::Ipv4Addr::new(0, 0, 0, 0)),
61 update_interval: std::time::Duration::from_secs(30),
62 }
63 }
64}
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69
70 #[test]
71 fn test_metrics_config_default() {
72 let config = MetricsConfig::default();
73 assert!(!config.enabled);
74 assert_eq!(config.port, 9090);
75 assert_eq!(config.bind_address, std::net::IpAddr::V4(std::net::Ipv4Addr::new(0, 0, 0, 0)));
76 assert_eq!(config.update_interval, std::time::Duration::from_secs(30));
77 }
78}