diff options
author | Stuart Stock <stuart@int08h.com> | 2019-01-23 20:56:56 -0600 |
---|---|---|
committer | Stuart Stock <stuart@int08h.com> | 2019-01-23 20:56:56 -0600 |
commit | ea61800c269c542d0231b9129863e6a07b5869f6 (patch) | |
tree | e1d0497465be79b2e8e26006eac8ca2391580432 /src | |
parent | ce425f96a3f0b4413325926c5d0209998e0aad45 (diff) | |
download | roughenough-ea61800c269c542d0231b9129863e6a07b5869f6.zip |
Enhanced client stats logging output
Diffstat (limited to 'src')
-rw-r--r-- | src/server.rs | 18 | ||||
-rw-r--r-- | src/stats/mod.rs | 10 |
2 files changed, 24 insertions, 4 deletions
diff --git a/src/server.rs b/src/server.rs index b23404d..6045191 100644 --- a/src/server.rs +++ b/src/server.rs @@ -28,6 +28,8 @@ use time; use byteorder::{LittleEndian, WriteBytesExt}; +use humansize::{FileSize, file_size_opts as fsopts}; + use mio::net::{TcpListener, UdpSocket}; use mio::{Events, Poll, PollOpt, Ready, Token}; use mio::tcp::Shutdown; @@ -264,9 +266,21 @@ impl Server { } STATUS => { + for (addr, counts) in self.stats.iter() { + info!( + "{:16}: {} valid, {} invalid requests; {} responses ({} sent)", + format!("{}", addr), counts.valid_requests, counts.invalid_requests, + counts.responses_sent, + counts.bytes_sent.file_size(fsopts::BINARY).unwrap() + ); + } + info!( - "responses {}, invalid requests {}", - self.stats.total_responses_sent(), self.stats.total_invalid_requests() + "Totals: {} unique clients; {} valid, {} invalid requests; {} responses ({} sent)", + self.stats.total_unique_clients(), + self.stats.total_valid_requests(), self.stats.total_invalid_requests(), + self.stats.total_responses_sent(), + self.stats.total_bytes_sent().file_size(fsopts::BINARY).unwrap() ); self.timer.set_timeout(self.config.status_interval(), ()); diff --git a/src/stats/mod.rs b/src/stats/mod.rs index 126b88b..35fabdf 100644 --- a/src/stats/mod.rs +++ b/src/stats/mod.rs @@ -13,6 +13,8 @@ // limitations under the License. use hashbrown::HashMap; +use hashbrown::hash_map::Iter; + use std::net::IpAddr; /// Maximum number of stats entries to maintain. @@ -42,6 +44,8 @@ pub trait ClientStats { fn get_stats(&self, addr: &IpAddr) -> Option<&StatEntry>; + fn iter(&self) -> Iter<IpAddr, StatEntry>; + fn clear(&mut self); } @@ -196,11 +200,13 @@ impl ClientStats for SimpleStats { } fn get_stats(&self, addr: &IpAddr) -> Option<&StatEntry> { - self.clients.iter() - self.clients.get(addr) } + fn iter(&self) -> Iter<IpAddr, StatEntry> { + self.clients.iter() + } + fn clear(&mut self) { self.clients.clear(); self.num_overflows = 0; |