ualex73 / monitor_docker

Monitor Docker containers from Home Assistant
Apache License 2.0
268 stars 34 forks source link

Feature request: make CPU% usage stats based on total cpu count #19

Closed LordShadowen closed 3 years ago

LordShadowen commented 3 years ago

Currently the CPU usage is being reported as % of a single core (also known as the Irix mode on Linux). This is actually the same thing that docker stats reports, so it's "correct".

However, other Docker monitoring systems (like the one from Synology) report on the Solaris mode, where is a percentage of total core availability. So, for example, a container reporting 36% usage on a 12-core system is reported as only 3%

I prefer the Solaris mode (more intuitive) and makes for nice graphs in Home Assistant :) Any way this could be a config option? I don't know if there is any way to get this directly out of Docker, but a quick and dirty way would be to just divide by number of cores on the host.

ualex73 commented 3 years ago

The number of (online) CPUs is available, so I did such simple divide option. A new option "containers_1cpu_percentage" is now available. I just push the commit to the repository, but it is not available in HACS yet (maybe next week?)

ualex73 commented 3 years ago

Just released version 1.2, should be available in 5-6 hours in HACS.

LordShadowen commented 3 years ago

Just tried it. The main "sensor.docker_1cpu" seems to be working great, but all the individual container _1cpu sensors are returning "unknown". Any idea why?

ualex73 commented 3 years ago

I included partially the code for "container_1cpu", but I need to add a bit more code to make it work (the number of CPUs is unavailable in a container, only in the overall docker sensor). Currently it will give None/Unknown.

ualex73 commented 3 years ago

It should be working per container too, please verify - then we can close this one ;-)

LordShadowen commented 3 years ago

Yes, seems to work fine :)

ualex73 commented 3 years ago

ok, then we can close it ;-)