mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 18:25:30 +00:00
udp: only include prometheus fields in config if feature enabled
This commit is contained in:
parent
9bd4062e44
commit
3806faaff9
3 changed files with 41 additions and 9 deletions
|
|
@ -14,16 +14,18 @@ pub struct StatisticsCollector {
|
|||
last_update: Instant,
|
||||
pending_histograms: Vec<Histogram<u64>>,
|
||||
last_complete_histogram: PeerHistogramStatistics,
|
||||
#[cfg(feature = "prometheus")]
|
||||
ip_version: String,
|
||||
}
|
||||
|
||||
impl StatisticsCollector {
|
||||
pub fn new(shared: Arc<Statistics>, ip_version: String) -> Self {
|
||||
pub fn new(shared: Arc<Statistics>, #[cfg(feature = "prometheus")] ip_version: String) -> Self {
|
||||
Self {
|
||||
shared,
|
||||
last_update: Instant::now(),
|
||||
pending_histograms: Vec::new(),
|
||||
last_complete_histogram: Default::default(),
|
||||
#[cfg(feature = "prometheus")]
|
||||
ip_version,
|
||||
}
|
||||
}
|
||||
|
|
@ -37,7 +39,10 @@ impl StatisticsCollector {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn collect_from_shared(&mut self, config: &Config) -> CollectedStatistics {
|
||||
pub fn collect_from_shared(
|
||||
&mut self,
|
||||
#[cfg(feature = "prometheus")] config: &Config,
|
||||
) -> CollectedStatistics {
|
||||
let requests_received = Self::fetch_and_reset(&self.shared.requests_received);
|
||||
let responses_sent_connect = Self::fetch_and_reset(&self.shared.responses_sent_connect);
|
||||
let responses_sent_announce = Self::fetch_and_reset(&self.shared.responses_sent_announce);
|
||||
|
|
|
|||
|
|
@ -57,8 +57,16 @@ pub fn run_statistics_worker(
|
|||
None
|
||||
};
|
||||
|
||||
let mut ipv4_collector = StatisticsCollector::new(shared_state.statistics_ipv4, "4".into());
|
||||
let mut ipv6_collector = StatisticsCollector::new(shared_state.statistics_ipv6, "6".into());
|
||||
let mut ipv4_collector = StatisticsCollector::new(
|
||||
shared_state.statistics_ipv4,
|
||||
#[cfg(feature = "prometheus")]
|
||||
"4".into(),
|
||||
);
|
||||
let mut ipv6_collector = StatisticsCollector::new(
|
||||
shared_state.statistics_ipv6,
|
||||
#[cfg(feature = "prometheus")]
|
||||
"6".into(),
|
||||
);
|
||||
|
||||
loop {
|
||||
::std::thread::sleep(Duration::from_secs(config.statistics.interval));
|
||||
|
|
@ -70,8 +78,14 @@ pub fn run_statistics_worker(
|
|||
}
|
||||
}
|
||||
|
||||
let statistics_ipv4 = ipv4_collector.collect_from_shared(&config);
|
||||
let statistics_ipv6 = ipv6_collector.collect_from_shared(&config);
|
||||
let statistics_ipv4 = ipv4_collector.collect_from_shared(
|
||||
#[cfg(feature = "prometheus")]
|
||||
&config,
|
||||
);
|
||||
let statistics_ipv6 = ipv6_collector.collect_from_shared(
|
||||
#[cfg(feature = "prometheus")]
|
||||
&config,
|
||||
);
|
||||
|
||||
if config.statistics.print_to_stdout {
|
||||
println!("General:");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue