Sensors plugin generates a peak of CPU consumption
- Run Glances with the sensor plugin enabled: every 3 refreshs a peak of Glances process CPU is observed.
- Run Glances with the sensor plugin disabled: no CPU peak observed.
Note: the peak every "3 refreshs" is related to the following key in the sensors code:
# Define the default refresh multiplicator
# Default value is 3 * Glances refresh time
# Can be overwritten by the refresh option in the sensors section of the glances.conf file
DEFAULT_REFRESH = 3
The goal is to understand why the CPU peak is so high (from 5% to 11% on my system).
A specific branch (issue2851) has been created with a specific test script (test-data/issues/issue2851.py):
./venv/bin/python ./test-data/issues/issue2851.py
Init Glances to make the stats more relevant (wait 6 seconds)
CPU consumption with sensors plugin disable
1/6: 0 sensor
2/6: 0 sensor
3/6: 0 sensor
4/6: 0 sensor
5/6: 0 sensor
6/6: 0 sensor
CPU consumption with sensors plugin disable: 5.8
CPU consumption with sensors plugin enable
1/6: 9 sensors
2/6: 9 sensors
3/6: 9 sensors
4/6: 9 sensors
5/6: 9 sensors
6/6: 9 sensors
CPU consumption with sensors plugin enable: 8.3
After a quick analyse, the peak (between 2 and 3% of a CPU core) came from the calls to psutil.sensors_temperatures() and psutil.sensors_fans().
I don't know if it's related to this issue, but I noticed significantly higher CPU usage on recent versions of glances.
I've noticed this on multiple machines, but it's currently running on Docker version 25.0.6.
Old version with good CPU usage:
glances:
container_name: glances
environment:
- GLANCES_OPT=-w --disable-check-update --time 2 --disable-plugin amps,containers,processcount
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
pid: host
network_mode: host
image: docker.io/nicolargo/glances:3.4.0.5-full
restart: unless-stopped
Newer version with high CPU usage:
glances:
container_name: glances
environment:
- GLANCES_OPT=-w --disable-check-update --time 2 --disable-plugin amps,containers,processcount
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
pid: host
network_mode: host
image: docker.io/nicolargo/glances:latest #4.1.2.1
restart: unless-stopped
This issue is stale because it has been open for 3 months with no activity.