From 59203ac9bbab2e713e2c0f515dc207ff16bf21aa Mon Sep 17 00:00:00 2001 From: sorz Date: Mon, 19 Nov 2018 23:52:08 +0800 Subject: [PATCH] Add stats for connection errors --- src/client/mod.rs | 4 ++-- src/monitor/mod.rs | 1 + src/proxy/mod.rs | 10 +++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/client/mod.rs b/src/client/mod.rs index 4346678..70ffe38 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -158,13 +158,13 @@ impl ConnectedClient { pipe(left, right, server.clone(), shared_buf) .then(move |result| match result { Ok(amt) => { - server.update_stats_conn_close(); + server.update_stats_conn_close(false); debug!("tx {}, rx {} bytes ({} => {})", amt.tx_bytes, amt.rx_bytes, server.tag, dest); Ok(()) }, Err(_) => { - server.update_stats_conn_close(); + server.update_stats_conn_close(true); warn!("{} (=> {}) close with error", server.tag, dest); Err(()) diff --git a/src/monitor/mod.rs b/src/monitor/mod.rs index 5910395..d624f5e 100644 --- a/src/monitor/mod.rs +++ b/src/monitor/mod.rs @@ -156,6 +156,7 @@ fn send_metrics(monitor: Monitor, handle: Handle) Some(r("rx_bytes", traffic.rx_bytes as u64)), Some(r("conns.total", server.conn_total() as u64)), Some(r("conns.alive", server.conn_alive() as u64)), + Some(r("conns.error", server.conn_error() as u64)), ] }).filter_map(|v| v); let mut buf = Vec::new(); diff --git a/src/proxy/mod.rs b/src/proxy/mod.rs index f1bff65..1ddaf36 100644 --- a/src/proxy/mod.rs +++ b/src/proxy/mod.rs @@ -55,6 +55,7 @@ struct ProxyServerStatus { traffic: Traffic, conn_alive: u32, conn_total: u32, + conn_error: u32, } impl Hash for ProxyServer { @@ -207,6 +208,10 @@ impl ProxyServer { self.status().conn_total } + pub fn conn_error(&self) -> u32 { + self.status().conn_error + } + pub fn set_delay(&self, delay: Option) { self.status().delay = delay; self.status().score = @@ -241,8 +246,11 @@ impl ProxyServer { self.status().conn_total += 1; } - pub fn update_stats_conn_close(&self) { + pub fn update_stats_conn_close(&self, has_error: bool) { self.status().conn_alive -= 1; + if has_error { + self.status().conn_error += 1; + } } pub fn traffic(&self) -> Traffic {