diff --git a/Cargo.lock b/Cargo.lock index e524353b..9471ad96 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ [root] name = "cernan" -version = "0.2.3" +version = "0.2.4" dependencies = [ "chrono 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.9.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 0086d798..becec1a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cernan" -version = "0.2.3" +version = "0.2.4" authors = ["Brian L. Troutwine "] build = "build.rs" diff --git a/src/backends/librato.rs b/src/backends/librato.rs index a54e5dec..4c4c4094 100644 --- a/src/backends/librato.rs +++ b/src/backends/librato.rs @@ -135,7 +135,7 @@ impl Backend for Librato { debug!("librato - {}", payload); let mime: Mime = "application/json".parse().unwrap(); let uri = url::Url::parse(&(self.host)).expect("malformed url"); - client.post(uri) + let res = client.post(uri) .body(&payload) .header(ContentType(mime)) .header(Authorization(Basic { @@ -143,8 +143,11 @@ impl Backend for Librato { password: Some(self.auth_token.clone()), })) .header(Connection::keep_alive()) - .send() - .unwrap(); + .send(); + match res { + Ok(_) => trace!("Successfully wrote librato payload"), + Err(e) => debug!("Could not write librato payload with error {}", e), + } } } diff --git a/src/server.rs b/src/server.rs index 5e2c75f3..e4e6bd52 100644 --- a/src/server.rs +++ b/src/server.rs @@ -16,7 +16,7 @@ pub enum Event { /// statsd pub fn udp_server(chan: Sender, port: u16) { let addr = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), port); - let socket = UdpSocket::bind(addr).ok().unwrap(); + let socket = UdpSocket::bind(addr).ok().expect("Unable to bind to UDP socket"); info!("statsd server started on 127.0.0.1:{}", port); let mut buf = [0; 8192]; loop { @@ -25,13 +25,13 @@ pub fn udp_server(chan: Sender, port: u16) { Err(_) => panic!("Could not read UDP socket."), }; let bytes = Vec::from(&buf[..len]); - chan.send(Event::UdpMessage(bytes)).unwrap(); + chan.send(Event::UdpMessage(bytes)).expect("[UDP] Unable to write into chan!"); } } pub fn tcp_server(chan: Sender, port: u16) { let addr = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), port); - let listener = TcpListener::bind(addr).unwrap(); + let listener = TcpListener::bind(addr).expect("Unable to bind to TCP socket"); info!("graphite server started on 127.0.0.1:{}", port); for stream in listener.incoming() { let newchan = chan.clone(); @@ -49,7 +49,7 @@ fn handle_client(chan: Sender, stream: TcpStream) { for line in line_reader.lines() { match line { Ok(line) => { - chan.send(Event::TcpMessage(line.into_bytes())).unwrap(); + chan.send(Event::TcpMessage(line.into_bytes())).expect("[TCP] Unable to write to chan!"); } Err(_) => break, } @@ -61,6 +61,6 @@ pub fn flush_timer_loop(chan: Sender, interval: u64) { let duration = Duration::new(interval, 0); loop { sleep(duration); - chan.send(Event::TimerFlush).unwrap(); + chan.send(Event::TimerFlush).expect("[FLUSH] Unable to write to chan!"); } }