mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
udp: statistics: show number of peers
This commit is contained in:
parent
59e95894b9
commit
c78716153b
3 changed files with 23 additions and 1 deletions
|
|
@ -234,6 +234,8 @@ pub struct Statistics {
|
|||
pub bytes_sent: AtomicUsize,
|
||||
pub torrents_ipv4: Vec<AtomicUsize>,
|
||||
pub torrents_ipv6: Vec<AtomicUsize>,
|
||||
pub peers_ipv4: Vec<AtomicUsize>,
|
||||
pub peers_ipv6: Vec<AtomicUsize>,
|
||||
}
|
||||
|
||||
impl Statistics {
|
||||
|
|
@ -245,6 +247,8 @@ impl Statistics {
|
|||
bytes_sent: Default::default(),
|
||||
torrents_ipv4: Self::create_atomic_usize_vec(num_request_workers),
|
||||
torrents_ipv6: Self::create_atomic_usize_vec(num_request_workers),
|
||||
peers_ipv4: Self::create_atomic_usize_vec(num_request_workers),
|
||||
peers_ipv6: Self::create_atomic_usize_vec(num_request_workers),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -128,6 +128,14 @@ pub fn run_request_worker(
|
|||
if now > last_cleaning + cleaning_interval {
|
||||
torrents.clean(&config, &state.access_list);
|
||||
|
||||
if !statistics_update_interval.is_zero() {
|
||||
let peers_ipv4 = torrents.ipv4.values().map(|t| t.peers.len()).sum();
|
||||
let peers_ipv6 = torrents.ipv6.values().map(|t| t.peers.len()).sum();
|
||||
|
||||
state.statistics.peers_ipv4[worker_index.0].store(peers_ipv4, Ordering::SeqCst);
|
||||
state.statistics.peers_ipv6[worker_index.0].store(peers_ipv6, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
last_cleaning = now;
|
||||
}
|
||||
if !statistics_update_interval.is_zero()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::sync::atomic::Ordering;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
use super::common::*;
|
||||
use crate::config::Config;
|
||||
|
|
@ -37,6 +37,8 @@ pub fn gather_and_print_statistics(state: &State, config: &Config) {
|
|||
.iter()
|
||||
.map(|n| n.load(Ordering::SeqCst))
|
||||
.sum();
|
||||
let num_peers_ipv4 = sum_atomic_usize_vec(&state.statistics.peers_ipv4);
|
||||
let num_peers_ipv6 = sum_atomic_usize_vec(&state.statistics.peers_ipv6);
|
||||
|
||||
let access_list_len = state.access_list.load().len();
|
||||
|
||||
|
|
@ -55,8 +57,16 @@ pub fn gather_and_print_statistics(state: &State, config: &Config) {
|
|||
"ipv4 torrents: {}, ipv6 torrents: {}",
|
||||
num_torrents_ipv4, num_torrents_ipv6,
|
||||
);
|
||||
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_usize_vec(vec: &Vec<AtomicUsize>) -> usize {
|
||||
vec.iter().map(|n| n.load(Ordering::SeqCst)).sum()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue