 (defn- stop [telemetry]
   (log/info "<- stopping telemetry")
   (close! (:killswitch telemetry))
+  (flush telemetry)
   (when-let [client (:r-client telemetry)]
-    (flush-queue client (:queue telemetry))
     (riemann/close! client)))
 
 (mnt/defstate telemetry

(defn custom [telemetry message]
  (enqueue telemetry message))

(defmacro timed
  "Wraps expr in a timer and reports the elapsed time as a metric named with identifier."
  [identifier expr & [props]]


(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
