Skip to content

Commit

Permalink
Add stats for connection errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sorz committed Nov 19, 2018
1 parent c690dd2 commit 59203ac
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
1 change: 1 addition & 0 deletions src/monitor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 9 additions & 1 deletion src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct ProxyServerStatus {
traffic: Traffic,
conn_alive: u32,
conn_total: u32,
conn_error: u32,
}

impl Hash for ProxyServer {
Expand Down Expand Up @@ -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<Duration>) {
self.status().delay = delay;
self.status().score =
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 59203ac

Please sign in to comment.