udp: split statistics by ipv4/ipv6

This commit is contained in:
Joakim Frostegård 2021-11-21 20:04:18 +01:00
parent 34f263f6b9
commit f68bbff700
4 changed files with 100 additions and 74 deletions

View file

@ -8,62 +8,51 @@ pub fn run_statistics_worker(config: Config, state: State) {
loop {
::std::thread::sleep(Duration::from_secs(config.statistics.interval));
gather_and_print_statistics(&config, &state);
println!("General:");
println!(" access list entries: {}", state.access_list.load().len());
println!("IPv4:");
gather_and_print_for_protocol(&config, &state.statistics_ipv4);
println!("IPv6:");
gather_and_print_for_protocol(&config, &state.statistics_ipv6);
println!();
}
}
fn gather_and_print_statistics(config: &Config, state: &State) {
fn gather_and_print_for_protocol(config: &Config, statistics: &Statistics) {
let interval = config.statistics.interval;
let requests_received: f64 = state
.statistics
.requests_received
.fetch_and(0, Ordering::AcqRel) as f64;
let responses_sent: f64 = state
.statistics
.responses_sent
.fetch_and(0, Ordering::AcqRel) as f64;
let bytes_received: f64 = state
.statistics
.bytes_received
.fetch_and(0, Ordering::AcqRel) as f64;
let bytes_sent: f64 = state.statistics.bytes_sent.fetch_and(0, Ordering::AcqRel) as f64;
let requests_received: f64 = statistics.requests_received.fetch_and(0, Ordering::AcqRel) as f64;
let responses_sent: f64 = statistics.responses_sent.fetch_and(0, Ordering::AcqRel) as f64;
let bytes_received: f64 = statistics.bytes_received.fetch_and(0, Ordering::AcqRel) as f64;
let bytes_sent: f64 = statistics.bytes_sent.fetch_and(0, Ordering::AcqRel) as f64;
let requests_per_second = requests_received / interval as f64;
let responses_per_second: f64 = responses_sent / interval as f64;
let bytes_received_per_second: f64 = bytes_received / interval as f64;
let bytes_sent_per_second: f64 = bytes_sent / interval as f64;
let num_torrents_ipv4: usize = sum_atomic_usizes(&state.statistics.torrents_ipv4);
let num_torrents_ipv6 = sum_atomic_usizes(&state.statistics.torrents_ipv6);
let num_peers_ipv4 = sum_atomic_usizes(&state.statistics.peers_ipv4);
let num_peers_ipv6 = sum_atomic_usizes(&state.statistics.peers_ipv6);
let access_list_len = state.access_list.load().len();
let num_torrents: usize = sum_atomic_usizes(&statistics.torrents);
let num_peers = sum_atomic_usizes(&statistics.peers);
println!(
"stats: {:.2} requests/second, {:.2} responses/second",
" requests/second: {:10.2}, responses/second: {:10.2}",
requests_per_second, responses_per_second
);
println!(
"bandwidth: {:7.2} Mbit/s in, {:7.2} Mbit/s out",
" bandwidth: {:7.2} Mbit/s in, {:7.2} Mbit/s out",
bytes_received_per_second * 8.0 / 1_000_000.0,
bytes_sent_per_second * 8.0 / 1_000_000.0,
);
println!(" number of torrents: {}", num_torrents);
println!(
"ipv4 torrents: {}, ipv6 torrents: {}",
num_torrents_ipv4, num_torrents_ipv6,
" number of peers: {} (updated every {} seconds)",
num_peers, config.cleaning.torrent_cleaning_interval
);
println!(
"ipv4 peers: {}, ipv6 peers: {} (both updated every {} seconds)",
num_peers_ipv4, num_peers_ipv6, config.cleaning.torrent_cleaning_interval
);
println!("access list entries: {}", access_list_len,);
println!();
}
fn sum_atomic_usizes(values: &[AtomicUsize]) -> usize {