3

As command "docker stats" gives details like:(I have put just header, not values)

CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 

I want the above details using python script. I have done following:

client = docker.DockerClient(base_url='unix:///var/run/docker.sock') for i in client.containers.list(): print(i.stats)

But not getting any useful information using i.stats and it's attribute. What should I do to get above details?

1 Answer 1

4

stats is a function. So you need to call it as i.stats(). It also streams the result by default as a python generator. If you want to get the current stats only, you can use the stream=False parameter.

client = docker.DockerClient(base_url='unix:///var/run/docker.sock') for i in client.containers.list(): print(i.stats(stream=False)) 

If you want to keep printing the stats realtime:

for stat in i.stats(): print(stat) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.