             [swarmpit.influxdb.mapper :as m]
             [swarmpit.config :refer [config]]))
 
+(def nodes-memo (memo/ttl docker/nodes :ttl/threshold 5000))
+
 (defn active-hosts
   []
   "List of running nodes"
-  (->> (docker/nodes)
+  (->> (nodes-memo)
        (filter #(= "ready" (get-in % [:Status :State])))
        (map :ID)
        (set)))
-
-(def active-hosts-memo (memo/ttl active-hosts :ttl/threshold 5000))
 
 (def cache (atom (cache/basic-cache-factory {})))
 

  "Get latest cluster statistics"
  []
  (let [cached-hosts (vals @cache)
        active-hosts (active-hosts-memo)
        hosts (filter #(contains? active-hosts (:id %)) cached-hosts)
        sum-fn (fn [ks] (reduce + (map #(get-in % ks) hosts)))
        mean-fn (fn [ks] (/ (sum-fn ks) (count hosts)))]

(defn hosts-timeseries
  "Get hosts timeseries data for last 24 hours"
  []
  (let [nodes (->> (nodes-memo)
                   (group-by :ID))
        node-name #(or (-> (get nodes %) first :Description :Hostname) %)]
    (->> (-> (influx/read-host-stats)
