aquatic: print bandwidth used (based on bytes received and sent)

This commit is contained in:
Joakim Frostegård 2020-04-08 11:43:18 +02:00
parent a865f4a1ae
commit 52078ab1ad
3 changed files with 24 additions and 1 deletions

View file

@ -124,6 +124,8 @@ pub struct Statistics {
pub requests_received: AtomicUsize,
pub responses_sent: AtomicUsize,
pub readable_events: AtomicUsize,
pub bytes_received: AtomicUsize,
pub bytes_sent: AtomicUsize,
}

View file

@ -39,9 +39,15 @@ pub fn run(){
.fetch_and(0, Ordering::SeqCst) as f64;
let responses_sent: f64 = state.statistics.responses_sent
.fetch_and(0, Ordering::SeqCst) as f64;
let bytes_received: f64 = state.statistics.bytes_received
.fetch_and(0, Ordering::SeqCst) as f64;
let bytes_sent: f64 = state.statistics.bytes_sent
.fetch_and(0, Ordering::SeqCst) 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 readable_events: f64 = state.statistics.readable_events
.fetch_and(0, Ordering::SeqCst) as f64;
@ -58,6 +64,12 @@ pub fn run(){
requests_per_readable_event
);
println!(
"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,
);
let mut peers_per_torrent = Histogram::new();
for torrent in state.torrents.iter(){

View file

@ -113,6 +113,8 @@ fn handle_readable_socket(
){
let mut requests_received: usize = 0;
let mut responses_sent: usize = 0;
let mut bytes_received: usize = 0;
let mut bytes_sent: usize = 0;
loop {
match socket.recv_from(&mut buffer[..]) {
@ -122,6 +124,8 @@ fn handle_readable_socket(
config.max_scrape_torrents
);
bytes_received += amt;
if request.is_ok(){
requests_received += 1;
}
@ -189,8 +193,9 @@ fn handle_readable_socket(
let amt = cursor.position() as usize;
match socket.send_to(&cursor.get_ref()[..amt], src){
Ok(_bytes_sent) => {
Ok(amt) => {
responses_sent += 1;
bytes_sent += amt;
},
Err(err) => {
match err.kind(){
@ -209,4 +214,8 @@ fn handle_readable_socket(
.fetch_add(requests_received, Ordering::SeqCst);
state.statistics.responses_sent
.fetch_add(responses_sent, Ordering::SeqCst);
state.statistics.bytes_received
.fetch_add(bytes_received, Ordering::SeqCst);
state.statistics.bytes_sent
.fetch_add(bytes_sent, Ordering::SeqCst);
}