diff --git a/Cargo.toml b/Cargo.toml index 9e6fb4f..5271601 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,14 +6,14 @@ authors = ["Jonathan Strong "] [[example]] name = "zmq-logger" path = "examples/zmq-logger.rs" -required-features = ["warnings"] +required-features = ["warnings", "zmq"] [[example]] name = "hist-interval" path = "examples/hist-interval.rs" [dependencies] -zmq = "0.8" +zmq = { version = "0.8", optional = true } influent = "0.4" chrono = { version = "0.4", features = ["serde"] } hyper = "0.10" diff --git a/src/influx.rs b/src/influx.rs index 7041d3f..ceca19d 100644 --- a/src/influx.rs +++ b/src/influx.rs @@ -15,6 +15,7 @@ use hyper::client::response::Response; use hyper::Url; use hyper::client::Client; use influent::measurement::{Measurement, Value}; +#[cfg(feature = "zmq")] use zmq; #[allow(unused_imports)] use chrono::{DateTime, Utc}; @@ -398,8 +399,10 @@ impl Drop for InfluxWriter { } } +#[cfg(feature = "zmq")] const WRITER_ADDR: &'static str = "ipc:///tmp/mm/influx"; +#[cfg(feature = "zmq")] pub fn pull(ctx: &zmq::Context) -> Result { let socket = ctx.socket(zmq::PULL)?; socket.bind(WRITER_ADDR)?; @@ -407,6 +410,7 @@ pub fn pull(ctx: &zmq::Context) -> Result { Ok(socket) } +#[cfg(feature = "zmq")] pub fn push(ctx: &zmq::Context) -> Result { let socket = ctx.socket(zmq::PUSH)?; socket.connect(WRITER_ADDR)?; @@ -583,6 +587,7 @@ pub fn serialize_owned(measurement: &OwnedMeasurement, line: &mut String) { #[cfg(feature = "warnings")] #[deprecated(since="0.4", note="Replace with InfluxWriter")] +#[cfg(feature = "zmq")] pub fn writer(warnings: Sender) -> thread::JoinHandle<()> { assert!(false); thread::Builder::new().name("mm:inflx-wtr".into()).spawn(move || { @@ -998,6 +1003,7 @@ mod tests { }); } + #[cfg(feature = "zmq")] #[cfg(feature = "warnings")] #[test] #[ignore] diff --git a/src/latency.rs b/src/latency.rs index 2ef984a..9e31a28 100644 --- a/src/latency.rs +++ b/src/latency.rs @@ -647,7 +647,6 @@ impl LatencyManager { let thread = Some(thread::spawn(move || { let logger = file_logger("var/log/latency-manager.log", Severity::Info); - info!(logger, "initializing zmq"); info!(logger, "initializing DurationWindows"); let mut gdax_ws = windows::DurationWindow::new(d); diff --git a/src/lib.rs b/src/lib.rs index b4667f8..35fc687 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,6 @@ #[macro_use] extern crate money; extern crate test; -extern crate zmq; extern crate influent; extern crate chrono; extern crate hyper; @@ -24,6 +23,8 @@ extern crate uuid; extern crate hdrhistogram; extern crate smallvec; extern crate num; +#[cfg(feature = "zmq")] +extern crate zmq; extern crate pubsub as pub_sub; diff --git a/src/warnings.rs b/src/warnings.rs index 2eb0be3..34d7db0 100644 --- a/src/warnings.rs +++ b/src/warnings.rs @@ -9,6 +9,7 @@ use std::fmt::{self, Display, Error as FmtError, Formatter}; use std::io::{self, Write}; use std::fs; +#[cfg(feature = "zmq")] use zmq; use chrono::{DateTime, Utc}; use termion::color::{self, Fg, Bg}; @@ -417,6 +418,7 @@ impl WarningsManager { /// `measurement_name` is the name of the influxdb measurement /// we will save log entries to. /// + #[cfg(feature = "zmq")] pub fn new(measurement_name: &'static str) -> Self { let warnings = Arc::new(RwLock::new(VecDeque::new())); let warnings_copy = warnings.clone(); @@ -486,6 +488,7 @@ impl Drop for WarningsManager { } } +#[cfg(feature = "zmq")] #[allow(dead_code)] pub struct ZmqDrain where D: Drain, @@ -496,6 +499,7 @@ pub struct ZmqDrain buf: Arc>> } +#[cfg(feature = "zmq")] impl ZmqDrain where D: Drain, { @@ -517,6 +521,7 @@ impl ZmqDrain const TIMESTAMP_FORMAT: &'static str = "%b %d %H:%M:%S%.3f"; +#[cfg(feature = "zmq")] impl Drain for ZmqDrain where D: Drain { @@ -557,6 +562,7 @@ impl Drain for ZmqDrain /// Can be used as a `Write` with `slog_term` and /// other libraries. /// +#[cfg(feature = "zmq")] #[allow(dead_code)] pub struct ZmqIo { ctx: zmq::Context, @@ -564,6 +570,7 @@ pub struct ZmqIo { buf: Vec } +#[cfg(feature = "zmq")] impl ZmqIo { pub fn new(addr: &str) -> Self { let _ = fs::create_dir("/tmp/mm"); @@ -576,6 +583,7 @@ impl ZmqIo { } } +#[cfg(feature = "zmq")] impl Write for ZmqIo { fn write(&mut self, buf: &[u8]) -> io::Result { self.buf.write(buf)