 (ns swarmpit.stats
   (:require [clojure.core.cache :as cache]
+            [clojure.core.memoize :as memo]
+            [swarmpit.docker.engine.client :as docker]
             [swarmpit.influxdb.client :as influx]
             [swarmpit.influxdb.mapper :as m]
             [swarmpit.config :refer [config]]))
+
+(defn active-hosts
+  []
+  "List of running nodes"
+  (->> (docker/nodes)
+       (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 {})))
 

  (map #(m/->host-ts %)
       (-> (influx/read-host-stats)
           (first)
           (get "series"))))


  (some? (config :influxdb-url)))

(defn ready? []
  (not (and (empty? @cache)
            (empty? (active-hosts-memo)))))

(defn store-to-cache
  "Store stats in local cache"
