 (defn custom [telemetry message]
   (enqueue telemetry message))
 
+(defn flush [telemetry]
+  (when-let [client (:r-client telemetry)]
+    (flush-queue client (:queue telemetry))))
+
 (defmacro timed
   "Wraps expr in a timer and reports the elapsed time as a metric named with identifier."
   [identifier expr & [props]]

            [gorillalabs.tesla.component.configuration :as config]
            [mount.core :as mnt]
            [riemann.client :as riemann])
  (:import (java.net InetAddress)))

(defn- now []
  (/ (System/currentTimeMillis) 1000))


(defn- start []
  (log/info "-> starting telemetry")
  (let [config      (config/config config/configuration [:telemetry])
        riemann-cfg (:riemann config)
        queue       (chan (sliding-buffer (:queue-size config 1000)))
        killswitch  (chan)
        client      (when (:host riemann-cfg) (riemann/tcp-client riemann-cfg))]
    (worker killswitch client queue (:interval config 30))
    {:host       (:host config (localhost))
     :r-client   client
