1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 14:16:00 +00:00

[docker_] Get CPU count from os.cpu_count() everywhere

Docker-py and os.cpu_count() disagree on the count, leading to data
going beyond the scale of the graph. As Docker-py seems to have dummy
CPU data in the stats, we instead always rely on Python's CPU count.

Signed-off-by: Olivier Mehani <shtrom@ssji.net>
This commit is contained in:
Olivier Mehani 2020-09-18 12:11:41 +10:00
parent 5bb9b46e08
commit 109144ded5

View file

@ -260,14 +260,13 @@ def parallel_container_stats(client):
def print_containers_cpu(client): def print_containers_cpu(client):
for container, stats in parallel_container_stats(client): for container, stats in parallel_container_stats(client):
cpu_count = len(stats["cpu_stats"]["cpu_usage"]["percpu_usage"])
cpu_percent = 0.0 cpu_percent = 0.0
cpu_delta = (float(stats["cpu_stats"]["cpu_usage"]["total_usage"]) cpu_delta = (float(stats["cpu_stats"]["cpu_usage"]["total_usage"])
- float(stats["precpu_stats"]["cpu_usage"]["total_usage"])) - float(stats["precpu_stats"]["cpu_usage"]["total_usage"]))
system_delta = (float(stats["cpu_stats"]["system_cpu_usage"]) system_delta = (float(stats["cpu_stats"]["system_cpu_usage"])
- float(stats["precpu_stats"]["system_cpu_usage"])) - float(stats["precpu_stats"]["system_cpu_usage"]))
if system_delta > 0.0: if system_delta > 0.0:
cpu_percent = cpu_delta / system_delta * 100.0 * cpu_count cpu_percent = cpu_delta / system_delta * 100.0 * os.cpu_count()
print(container.name + '.value', cpu_percent) print(container.name + '.value', cpu_percent)
print(container.name + '.extinfo', container_attributes(container)) print(container.name + '.extinfo', container_attributes(container))