docker-collectd-plugin
docker-collectd-plugin copied to clipboard
Cpu Usage Percentage: Constant ZERO percentage which is inconsistent with 'docker stats' results
When we using 'docker-collectd-plugin' to collect the cpu usage percentage of docker images, we noticed that we constantly get 'ZERO' cpu usage percentage. It looks like the following piece of code never been executed and we noticed that there is NO key named ': precpu_stats' existing in the 'stats' results.
if 'precpu_stats' in stats:
precpu_stats = stats['precpu_stats']
precpu_usage = precpu_stats['cpu_usage']
cpu_delta = cpu_usage['total_usage'] - precpu_usage['total_usage']
system_delta = system_cpu_usage - precpu_stats['system_cpu_usage']
if system_delta > 0 and cpu_delta > 0:
cpu_percent = 100.0 * cpu_delta / system_delta * len(percpu)
An example 'stats' results returned by running the script.
{'read': '2015-09-21T14:24:33.520403545Z', 'memory_stats': {'usage': 17383424, 'limit': 12454260736, 'failcnt': 0, 'stats': {'unevictable': 0, 'total_inactive_file': 1208320, 'total_rss_huge': 2097152, 'hierarchical_memsw_limit': 18446744073709551615L, 'total_cache': 3108864, 'total_mapped_file': 348160, 'mapped_file': 348160, 'pgfault': 55822, 'total_writeback': 0, 'hierarchical_memory_limit': 18446744073709551615L, 'total_active_file': 1855488, 'rss_huge': 2097152, 'cache': 3108864, 'active_anon': 13950976, 'pgmajfault': 7, 'total_pgpgout': 47684, 'writeback': 0, 'pgpgout': 47684, 'swap': 0, 'total_active_anon': 13950976, 'total_unevictable': 0, 'total_pgfault': 55822, 'total_pgmajfault': 7, 'total_inactive_anon': 0, 'total_swap': 0, 'inactive_file': 1208320, 'pgpgin': 51327, 'total_pgpgin': 51327, 'rss': 13905920, 'active_file': 1855488, 'inactive_anon': 0, 'total_rss': 13905920}, 'max_usage': 17960960}, 'blkio_stats': {'io_service_time_recursive': [], 'sectors_recursive': [], 'io_service_bytes_recursive': [], 'io_serviced_recursive': [], 'io_time_recursive': [], 'io_queue_recursive': [], 'io_merged_recursive': [], 'io_wait_time_recursive': []}, 'network': {'tx_dropped': 0, 'rx_packets': 0, 'rx_bytes': 0, 'tx_errors': 0, 'rx_errors': 0, 'tx_bytes': 0, 'rx_dropped': 0, 'tx_packets': 0}, 'cpu_stats': {'cpu_usage': {'usage_in_usermode': 118660000000, 'total_usage': 687452661813, 'percpu_usage': [86961004788, 85721611081, 84682975064, 86005552073, 86024993357, 83312731162, 82217459541, 92526334747], 'usage_in_kernelmode': 266830000000}, 'system_cpu_usage': 487433850000000, 'throttling_data': {'throttled_time': 0, 'periods': 0, 'throttled_periods': 0}}}
Hi, i have got same problem as zsuzhengdu stated exactly After viewing https://github.com/lebauce/docker-collectd-plugin/pull/17/commits where it said it was solved for me now graphite doesn't show any results for cpu percentage (cpu_percent)
You must be running an old version of docker, precpu_stats arrived in May this year: https://github.com/docker/docker/pull/13320
There is an issue around the fact that it is currently not documented, hence it might be a bit confusing : https://github.com/docker/docker/issues/16849
@jeanpralo You are right. Running Docker 1.7.1 and found this issue.
The fix recorded the cup_usage in previous cycle with interval 1second.