mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 02:35:31 +00:00
udp statistics: improve peer client reporting
- fix prometheus peer id prefix reporting - don't report peer id prefix in html output (current method was incorrect and output would become huge)
This commit is contained in:
parent
4ff65cc6bd
commit
08b28c9e1b
3 changed files with 33 additions and 30 deletions
|
|
@ -2,7 +2,6 @@ use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use crossbeam_channel::Receiver;
|
|
||||||
use hdrhistogram::Histogram;
|
use hdrhistogram::Histogram;
|
||||||
use num_format::{Locale, ToFormattedString};
|
use num_format::{Locale, ToFormattedString};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ struct TemplateData {
|
||||||
ipv6: CollectedStatistics,
|
ipv6: CollectedStatistics,
|
||||||
last_updated: String,
|
last_updated: String,
|
||||||
peer_update_interval: String,
|
peer_update_interval: String,
|
||||||
peer_clients: Vec<(CompactString, CompactString, usize)>,
|
peer_clients: Vec<(CompactString, usize)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_statistics_worker(
|
pub fn run_statistics_worker(
|
||||||
|
|
@ -71,7 +71,7 @@ pub fn run_statistics_worker(
|
||||||
"6".into(),
|
"6".into(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut peer_clients: IndexMap<PeerClient, (usize, CompactString)> = IndexMap::default();
|
let mut peer_clients: IndexMap<PeerClient, usize> = IndexMap::default();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let start_time = Instant::now();
|
let start_time = Instant::now();
|
||||||
|
|
@ -81,15 +81,35 @@ pub fn run_statistics_worker(
|
||||||
StatisticsMessage::Ipv4PeerHistogram(h) => ipv4_collector.add_histogram(&config, h),
|
StatisticsMessage::Ipv4PeerHistogram(h) => ipv4_collector.add_histogram(&config, h),
|
||||||
StatisticsMessage::Ipv6PeerHistogram(h) => ipv6_collector.add_histogram(&config, h),
|
StatisticsMessage::Ipv6PeerHistogram(h) => ipv6_collector.add_histogram(&config, h),
|
||||||
StatisticsMessage::PeerAdded(peer_id) => {
|
StatisticsMessage::PeerAdded(peer_id) => {
|
||||||
peer_clients
|
let client = peer_id.client();
|
||||||
.entry(peer_id.client())
|
let first_8_bytes_hex = peer_id.first_8_bytes_hex();
|
||||||
.or_insert((0, peer_id.first_8_bytes_hex()))
|
|
||||||
.0 += 1;
|
#[cfg(feature = "prometheus")]
|
||||||
|
if config.statistics.run_prometheus_endpoint {
|
||||||
|
::metrics::increment_gauge!(
|
||||||
|
"aquatic_peer_clients",
|
||||||
|
1.0,
|
||||||
|
"client" => client.to_string(),
|
||||||
|
"peer_id_prefix_hex" => first_8_bytes_hex.to_string(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
*peer_clients.entry(client).or_insert(0) += 1;
|
||||||
}
|
}
|
||||||
StatisticsMessage::PeerRemoved(peer_id) => {
|
StatisticsMessage::PeerRemoved(peer_id) => {
|
||||||
let client = peer_id.client();
|
let client = peer_id.client();
|
||||||
|
|
||||||
if let Some((count, _)) = peer_clients.get_mut(&client) {
|
#[cfg(feature = "prometheus")]
|
||||||
|
if config.statistics.run_prometheus_endpoint {
|
||||||
|
::metrics::decrement_gauge!(
|
||||||
|
"aquatic_peer_clients",
|
||||||
|
1.0,
|
||||||
|
"client" => client.to_string(),
|
||||||
|
"peer_id_prefix_hex" => peer_id.first_8_bytes_hex().to_string(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(count) = peer_clients.get_mut(&client) {
|
||||||
if *count == 1 {
|
if *count == 1 {
|
||||||
drop(count);
|
drop(count);
|
||||||
|
|
||||||
|
|
@ -102,18 +122,6 @@ pub fn run_statistics_worker(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "prometheus")]
|
|
||||||
if config.statistics.run_prometheus_endpoint && config.statistics.extended {
|
|
||||||
for (peer_client, (count, first_8_bytes)) in peer_clients.iter() {
|
|
||||||
::metrics::gauge!(
|
|
||||||
"aquatic_peer_clients",
|
|
||||||
*count as f64,
|
|
||||||
"client" => peer_client.to_string(),
|
|
||||||
"peer_id_prefix_hex" => first_8_bytes.to_string(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let statistics_ipv4 = ipv4_collector.collect_from_shared(
|
let statistics_ipv4 = ipv4_collector.collect_from_shared(
|
||||||
#[cfg(feature = "prometheus")]
|
#[cfg(feature = "prometheus")]
|
||||||
&config,
|
&config,
|
||||||
|
|
@ -146,19 +154,13 @@ pub fn run_statistics_worker(
|
||||||
let mut peer_clients = if config.statistics.extended {
|
let mut peer_clients = if config.statistics.extended {
|
||||||
peer_clients
|
peer_clients
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(peer_client, (count, first_8_bytes))| {
|
.map(|(peer_client, count)| (peer_client.to_compact_string(), *count))
|
||||||
(
|
|
||||||
peer_client.to_compact_string(),
|
|
||||||
first_8_bytes.to_owned(),
|
|
||||||
*count,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
};
|
};
|
||||||
|
|
||||||
peer_clients.sort_unstable_by(|a, b| b.2.cmp(&a.2));
|
peer_clients.sort_unstable_by(|a, b| b.1.cmp(&a.1));
|
||||||
|
|
||||||
let template_data = TemplateData {
|
let template_data = TemplateData {
|
||||||
stylesheet: STYLESHEET_CONTENTS.to_string(),
|
stylesheet: STYLESHEET_CONTENTS.to_string(),
|
||||||
|
|
@ -183,6 +185,10 @@ pub fn run_statistics_worker(
|
||||||
Duration::from_secs(config.statistics.interval).checked_sub(start_time.elapsed())
|
Duration::from_secs(config.statistics.interval).checked_sub(start_time.elapsed())
|
||||||
{
|
{
|
||||||
::std::thread::sleep(time_remaining);
|
::std::thread::sleep(time_remaining);
|
||||||
|
} else {
|
||||||
|
::log::warn!(
|
||||||
|
"statistics interval not long enough to process all data, output may be misleading"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -260,7 +260,6 @@
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Client</th>
|
<th>Client</th>
|
||||||
<th>Peer ID prefix (hex)</th>
|
|
||||||
<th>Count</th>
|
<th>Count</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
@ -268,7 +267,6 @@
|
||||||
{{ for value in peer_clients }}
|
{{ for value in peer_clients }}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{ value.0 }</td>
|
<td>{ value.0 }</td>
|
||||||
<td>{ value.1 }</td>
|
|
||||||
<td>{ value.2 }</td>
|
<td>{ value.2 }</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{ endfor }}
|
{{ endfor }}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue