I am using docker-py and trying to get docker stats. But I am unable to get any API for returning stats for particular container. Is there a REST API or any other way to programmatically get the stats ?
>>> cli = docker.Client(base_url="tcp://xxxxx:2375", version='1.21')
>>> cli.containers() >> gives the right o/p
>>> cli.containers.get()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute 'get'
>>> docker.version
'1.10.6'
You may be looking for Container.stats
.
Get stats for a particular container name example: "monitoring-tinydb". Note: change this container name with your desired container id or name.
import docker
client = docker.from_env()
container = client.containers.get("monitoring-tinydb")
status = container.stats(decode=None, stream = False)
print(status)
Get stats for all containers running in the docker host
import docker
client = docker.DockerClient(base_url='unix:///var/run/docker.sock')
for containers in client.containers.list():
print(containers.stats(decode=None, stream = False))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With