以编程方式获取 docker stats

Vin*_*Vin 4 python docker

我正在使用 docker-py 并尝试获取 docker stats。但是我无法获得任何 API 来返回特定容器的统计信息。是否有 REST API 或任何其他方式以编程方式获取统计信息?

>>> 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'
Run Code Online (Sandbox Code Playgroud)

sha*_*k3r 5

您可能正在寻找Container.stats.

  • 我通过 https://github.com/TomasTomecek/sen/blob/master/sen/util.py#L158 获取 CPU % (2认同)