monitor_docker
monitor_docker copied to clipboard
CPU/Mem Stats compatibility for Podman with cgroup v2
Podman's realisation of Docker API uses cpuacct for per_cpu
and online_cpus
, which are only available with cgroup v1.
Also Podman realisation of Docker API with cgroup v2 doesn't provides memory_stats.stats
.
Question, you added a new "if "stats" in raw["memory_stats"]:" for the version1904 code. Now that "stats" must exist before that part of the code will be executed, what is the scenario where that will happen? If it is for podman, then we should add some code to get the correct "cache" value (with the new code, it is set to 0)
As I understood, cgroup v2 doesn't report cache stats at all, or at least Podman API realisation with cgroup v2 doesn't report it, The previous code assumed that memory_stats.stats
to get cache value would be always reported, so I've added a check to be sure that in situation when memory_stats.stats
are not present the code will run correctly and the cache will be assumed equal to 0 - that is exactly the case with Podman+cgroup_v2.
cgroup v2 seems to be general less reportive as v1, but I would like to have container stats at least partially without need to set up older version of cgroup. I said "partially" because f.e. Podman API assumes memory_stats.limit
to be equal MAXINT64 instead of total available memory, so memory_stats.usage_percent
will be just always equals to 0. Fortunately containers_memory_percentage
uses total available memory as a basis, not the memory_stats.limit
.
I tested these fixes on a Podman install and I see far less errors now.
I was seeing errors every few seconds before and now I just get an occasional Container not available anymore (3) (DockerError(900, 'Cannot connect to Docker Engine via unix:///run/docker.sock [[Errno 32] Broken pipe]'))
.