Docker-py: How to get CPU percentage?

Created on 1 Nov 2016  路  2Comments  路  Source: docker/docker-py

Hi,
How do I calculate the cpu usage in percentage from client API stats, just like docker stats? I would like to get the cpu usage% per container.
Thanks,
Stef

u'precpu_stats': {u'cpu_usage': {u'percpu_usage': [11560917626, 1978360658, 1071486642, 970512213, 936742111, 1712364125, 10794787053, 16830506771, 3165123669, 3162181933, 969342059, 356121958, 371654069, 405707458, 5432826116, 8755028900], u'total_usage': 68473663361, u'usage_in_kernelmode': 4650000000, u'usage_in_usermode': 56330000000}, u'system_cpu_usage': 120560150000000,

Most helpful comment

This is how I'm doing the calculation in sen: https://github.com/TomasTomecek/sen/blob/master/sen/util.py#L158 (which is the exact copy of how docker client does it)

All 2 comments

This is how I'm doing the calculation in sen: https://github.com/TomasTomecek/sen/blob/master/sen/util.py#L158 (which is the exact copy of how docker client does it)

Thank you, this code worked fine!

Cheers

Was this page helpful?
0 / 5 - 0 ratings