into-docker / clj-docker-client

An idiomatic, data-driven, REPL friendly Clojure Docker client
https://cljdoc.org/d/lispyclouds/clj-docker-client/CURRENT
GNU Lesser General Public License v3.0
176 stars 13 forks source link

Add support for container stats #7

Closed gklijs closed 5 years ago

gklijs commented 5 years ago

Currently the stats are not part of the Clojure api. I just ran into this and locally it's now solved by adding

(defn container-stats
  "Returns the resource stats of a created container by name or id."
  [^DockerClient connection name]
  (-> connection
      (.stats name)
      (u/spotify-obj->Map)))

locally, I could easily create a pr to add it. Possibly also adding an optional different mapping that gives back the most important stats in a flat map.

lispyclouds commented 5 years ago

Hey @gklijs , thanks a lot for this request. I would be more than happy to accept your PR. As its a feature I'm personally not using at the moment, I'd say you making the PR with the features you would want would be a faster process. I'm happy to answer any questions. Looking forward to it!

gklijs commented 5 years ago

As you can always get all the data with the code in the first post, I would like to made it so that it just returns %cpu used from the last time the function was called for that container, and the current used memory, both in MiB and a percentage. There is also some Network I/O stats there but I think for now those can be ignored.

lispyclouds commented 5 years ago

Sounds good! More features can always be added when needed. Thanks a lot! 😄