diff --git a/aquatic_udp/src/workers/statistics/collector.rs b/aquatic_udp/src/workers/statistics/collector.rs index d1a5bfd..ae029d5 100644 --- a/aquatic_udp/src/workers/statistics/collector.rs +++ b/aquatic_udp/src/workers/statistics/collector.rs @@ -128,6 +128,9 @@ impl StatisticsCollector { "worker_index" => worker_index.to_string(), ); } + + self.last_complete_histogram + .update_metrics(self.ip_version.clone()); } let num_peers: usize = num_peers_by_worker.into_iter().sum(); @@ -188,7 +191,7 @@ pub struct CollectedStatistics { #[derive(Clone, Debug, Serialize, Default)] pub struct PeerHistogramStatistics { - pub p0: u64, + pub min: u64, pub p10: u64, pub p20: u64, pub p30: u64, @@ -200,13 +203,14 @@ pub struct PeerHistogramStatistics { pub p90: u64, pub p95: u64, pub p99: u64, - pub p100: u64, + pub p999: u64, + pub max: u64, } impl PeerHistogramStatistics { fn new(h: Histogram) -> Self { Self { - p0: h.value_at_percentile(0.0), + min: h.min(), p10: h.value_at_percentile(10.0), p20: h.value_at_percentile(20.0), p30: h.value_at_percentile(30.0), @@ -218,7 +222,90 @@ impl PeerHistogramStatistics { p90: h.value_at_percentile(90.0), p95: h.value_at_percentile(95.0), p99: h.value_at_percentile(99.0), - p100: h.value_at_percentile(100.0), + p999: h.value_at_percentile(99.9), + max: h.max(), } } + + #[cfg(feature = "prometheus")] + fn update_metrics(&self, ip_version: String) { + ::metrics::gauge!( + "aquatic_peers_per_torrent", + self.min as f64, + "type" => "max", + "ip_version" => ip_version.clone(), + ); + ::metrics::gauge!( + "aquatic_peers_per_torrent", + self.p10 as f64, + "type" => "p10", + "ip_version" => ip_version.clone(), + ); + ::metrics::gauge!( + "aquatic_peers_per_torrent", + self.p20 as f64, + "type" => "p20", + "ip_version" => ip_version.clone(), + ); + ::metrics::gauge!( + "aquatic_peers_per_torrent", + self.p30 as f64, + "type" => "p30", + "ip_version" => ip_version.clone(), + ); + ::metrics::gauge!( + "aquatic_peers_per_torrent", + self.p40 as f64, + "type" => "p40", + "ip_version" => ip_version.clone(), + ); + ::metrics::gauge!( + "aquatic_peers_per_torrent", + self.p50 as f64, + "type" => "p50", + "ip_version" => ip_version.clone(), + ); + ::metrics::gauge!( + "aquatic_peers_per_torrent", + self.p60 as f64, + "type" => "p60", + "ip_version" => ip_version.clone(), + ); + ::metrics::gauge!( + "aquatic_peers_per_torrent", + self.p70 as f64, + "type" => "p70", + "ip_version" => ip_version.clone(), + ); + ::metrics::gauge!( + "aquatic_peers_per_torrent", + self.p80 as f64, + "type" => "p80", + "ip_version" => ip_version.clone(), + ); + ::metrics::gauge!( + "aquatic_peers_per_torrent", + self.p90 as f64, + "type" => "p90", + "ip_version" => ip_version.clone(), + ); + ::metrics::gauge!( + "aquatic_peers_per_torrent", + self.p99 as f64, + "type" => "p99", + "ip_version" => ip_version.clone(), + ); + ::metrics::gauge!( + "aquatic_peers_per_torrent", + self.p999 as f64, + "type" => "p99.9", + "ip_version" => ip_version.clone(), + ); + ::metrics::gauge!( + "aquatic_peers_per_torrent", + self.max as f64, + "type" => "max", + "ip_version" => ip_version.clone(), + ); + } } diff --git a/aquatic_udp/src/workers/statistics/mod.rs b/aquatic_udp/src/workers/statistics/mod.rs index 40cfc5d..f54052e 100644 --- a/aquatic_udp/src/workers/statistics/mod.rs +++ b/aquatic_udp/src/workers/statistics/mod.rs @@ -151,7 +151,7 @@ fn print_to_stdout(config: &Config, statistics: &CollectedStatistics) { " peers per torrent (updated every {}s)", config.cleaning.torrent_cleaning_interval ); - println!(" min {:>10}", statistics.peer_histogram.p0); + println!(" min {:>10}", statistics.peer_histogram.min); println!(" p10 {:>10}", statistics.peer_histogram.p10); println!(" p20 {:>10}", statistics.peer_histogram.p20); println!(" p30 {:>10}", statistics.peer_histogram.p30); @@ -163,7 +163,8 @@ fn print_to_stdout(config: &Config, statistics: &CollectedStatistics) { println!(" p90 {:>10}", statistics.peer_histogram.p90); println!(" p95 {:>10}", statistics.peer_histogram.p95); println!(" p99 {:>10}", statistics.peer_histogram.p99); - println!(" max {:>10}", statistics.peer_histogram.p100); + println!(" p99.9 {:>10}", statistics.peer_histogram.p999); + println!(" max {:>10}", statistics.peer_histogram.max); } } diff --git a/aquatic_udp/templates/statistics.html b/aquatic_udp/templates/statistics.html index a62f42d..2007d01 100644 --- a/aquatic_udp/templates/statistics.html +++ b/aquatic_udp/templates/statistics.html @@ -76,7 +76,7 @@ Updated every { peer_update_interval } seconds Minimum - { ipv4.peer_histogram.p0 } + { ipv4.peer_histogram.min } 10th percentile @@ -122,9 +122,13 @@ 99th percentile { ipv4.peer_histogram.p99 } + + 99.9th percentile + { ipv4.peer_histogram.p999 } + Maximum - { ipv4.peer_histogram.p100 } + { ipv4.peer_histogram.max } @@ -188,7 +192,7 @@ Updated every { peer_update_interval } seconds Minimum - { ipv6.peer_histogram.p0 } + { ipv6.peer_histogram.min } 10th percentile @@ -234,9 +238,13 @@ 99th percentile { ipv6.peer_histogram.p99 } + + 99.9th percentile + { ipv6.peer_histogram.p999 } + Maximum - { ipv6.peer_histogram.p100 } + { ipv6.peer_histogram.max }