                  :value (second variable)})))
        (into [])))
 
+(defn ->service-replicas-running
+  [service-tasks]
+  (-> (filter #(= (get-in % [:Status :State]) "running") service-tasks)
+      (count)))
+
 (defn ->service-replicas-state
-  [replicas replicas-running service-mode]
+  [service-replicas service-replicas-running service-mode]
   (if (= service-mode "replicated")
-    (str replicas-running " / " replicas)
-    (str replicas-running " / " replicas-running)))
+    (str service-replicas-running " / " service-replicas)
+    (str service-replicas-running " / " service-replicas-running)))
 
 (defn ->service-state
-  [replicas replicas-running service-mode]
+  [service-replicas service-replicas-running service-mode]
   (case service-mode
-    "replicated" (if (zero? replicas-running)
+    "replicated" (if (zero? service-replicas-running)
                    "not running"
-                   (if (= replicas-running replicas)
+                   (if (= service-replicas-running service-replicas)
                      "running"
                      "partly running"))
-    "global" (if (zero? replicas-running)
+    "global" (if (zero? service-replicas-running)
                "not running"
                "running")))
 

    (array-map
      :id service-id
      :version (get-in service [:Version :Index])
      :createdAt (get service :CreatedAt)
      :updatedAt (get service :UpdatedAt)
      :image image-name
      :imageDigest image-digest
      :serviceName service-name
      :mode service-mode
      :replicas replicas
      :replicasState (->service-replicas-state replicas replicas-running service-mode)
      :state (->service-state replicas replicas-running service-mode)
      :ports (->service-ports service)
      :volumes (->service-volumes service)
      :variables (->service-variables service)
      :tasks service-tasks)))

(defn ->services
  [services tasks nodes]

      :id id
      :taskName task-name
      :version (get-in task [:Version :Index])
      :createdAt (date (get task :CreatedAt))
      :updatedAt (date (get task :UpdatedAt))
      :image image-name
      :imageDigest image-digest
      :state (get-in task [:Status :State])
