summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolas@nicolargo.com>2021-05-30 17:52:33 +0200
committernicolargo <nicolas@nicolargo.com>2021-05-30 17:52:33 +0200
commitad14969d0611711c49d9eeba1ea5d305e9c0b428 (patch)
tree99762140c493d39207844f6e61342e1916af20e8
parent39631d0b097318f2463d06e56b6dcf07e68de775 (diff)
Default refresh time for sensors is refresh rate * 2
-rw-r--r--Makefile7
-rw-r--r--conf/glances.conf2
-rw-r--r--glances/cpu_percent.py48
-rw-r--r--glances/plugins/glances_plugin.py20
-rw-r--r--glances/plugins/glances_sensors.py11
-rw-r--r--glances/timer.py4
6 files changed, 53 insertions, 39 deletions
diff --git a/Makefile b/Makefile
index 14cf8284..e2f880dd 100644
--- a/Makefile
+++ b/Makefile
@@ -42,10 +42,6 @@ run: venv
run-debug: venv
./venv/bin/python -m glances -C ./conf/glances.conf -d
-run-profiling: venv venv-dev
- @echo "Please complete and run: sudo ./venv/bin/py-spy record --pid <GLANCES PID> -o /tmp/glances.svg -d 60 -s "
-
-
run-webserver: venv
./venv/bin/python -m glances -C ./conf/glances.conf -w
@@ -55,4 +51,7 @@ run-server: venv
run-client: venv
./venv/bin/python -m glances -C ./conf/glances.conf -c localhost
+profiling: venv venv-dev
+ @echo "Please complete and run: sudo ./venv/bin/py-spy record -o /tmp/glances.svg -d 60 -s --pid <GLANCES PID>"
+
.PHONY: test docs docs-server
diff --git a/conf/glances.conf b/conf/glances.conf
index aca36468..f93225ef 100644
--- a/conf/glances.conf
+++ b/conf/glances.conf
@@ -258,6 +258,8 @@ port=7634
[sensors]
# Documentation: https://glances.readthedocs.io/en/latest/aoa/sensors.html
disable=False
+# By default refresh every refresh time * 2
+#refresh=6
# Hide some sensors
#hide=ambient
# Sensors core thresholds (in Celsius...)
diff --git a/glances/cpu_percent.py b/glances/cpu_percent.py
index 37c3200d..5141596d 100644
--- a/glances/cpu_percent.py
+++ b/glances/cpu_percent.py
@@ -19,6 +19,7 @@
"""CPU percent stats shared between CPU and Quicklook plugins."""
+from glances.logger import logger
from glances.timer import Timer
import psutil
@@ -28,18 +29,25 @@ class CpuPercent(object):
"""Get and store the CPU percent."""
- def __init__(self, cached_time=1):
+ def __init__(self, cached_timer_cpu=3):
self.cpu_info = {}
self.cpu_percent = 0
self.percpu_percent = []
- # cached_time is the minimum time interval between stats updates
+ # Get CPU name
+ self.__get_cpu_name()
+
+ # cached_timer_cpu is the minimum time interval between stats updates
# since last update is passed (will retrieve old cached info instead)
- self.cached_time = 1
- self.timer_cpu_info = Timer(0)
+ self.cached_timer_cpu = cached_timer_cpu
self.timer_cpu = Timer(0)
self.timer_percpu = Timer(0)
+ # psutil.cpu_freq() consumes lots of CPU
+ # So refresh the stats every refresh*2 (6 seconds)
+ self.cached_timer_cpu_info = cached_timer_cpu * 2
+ self.timer_cpu_info = Timer(0)
+
def get_key(self):
"""Return the key of the per CPU list."""
return 'cpu_number'
@@ -54,33 +62,37 @@ class CpuPercent(object):
def get_info(self):
"""Get additional informations about the CPU"""
- # Never update more than 1 time per cached_time
+ # Never update more than 1 time per cached_timer_cpu
if self.timer_cpu_info.finished():
- # Get the CPU name from the /proc/cpuinfo file
- # @TODO: Multisystem...
- try:
- self.cpu_info['cpu_name'] = open('/proc/cpuinfo', 'r').readlines()[4].split(':')[1][1:-2]
- except:
- self.cpu_info['cpu_name'] = 'CPU'
# Get the CPU freq current/max
- self.cpu_info['cpu_hz_current'] = psutil.cpu_freq().current
- self.cpu_info['cpu_hz'] = psutil.cpu_freq().max
+ cpu_freq = psutil.cpu_freq()
+ self.cpu_info['cpu_hz_current'] = cpu_freq.current
+ self.cpu_info['cpu_hz'] = cpu_freq.max
# Reset timer for cache
- self.timer_cpu_info = Timer(self.cached_time)
+ self.timer_cpu_info.reset(duration=self.cached_timer_cpu_info)
return self.cpu_info
+ def __get_cpu_name(self):
+ # Get the CPU name once from the /proc/cpuinfo file
+ # @TODO: Multisystem...
+ try:
+ self.cpu_info['cpu_name'] = open('/proc/cpuinfo', 'r').readlines()[4].split(':')[1][1:-2]
+ except:
+ self.cpu_info['cpu_name'] = 'CPU'
+ return self.cpu_info['cpu_name']
+
def __get_cpu(self):
"""Update and/or return the CPU using the psutil library."""
- # Never update more than 1 time per cached_time
+ # Never update more than 1 time per cached_timer_cpu
if self.timer_cpu.finished():
self.cpu_percent = psutil.cpu_percent(interval=0.0)
# Reset timer for cache
- self.timer_cpu = Timer(self.cached_time)
+ self.timer_cpu.reset(duration=self.cached_timer_cpu)
return self.cpu_percent
def __get_percpu(self):
"""Update and/or return the per CPU list using the psutil library."""
- # Never update more than 1 time per cached_time
+ # Never update more than 1 time per cached_timer_cpu
if self.timer_percpu.finished():
self.percpu_percent = []
for cpu_number, cputimes in enumerate(psutil.cpu_times_percent(interval=0.0, percpu=True)):
@@ -108,7 +120,7 @@ class CpuPercent(object):
# Append new CPU to the list
self.percpu_percent.append(cpu)
# Reset timer for cache
- self.timer_percpu = Timer(self.cached_time)
+ self.timer_percpu.reset(duration=self.cached_timer_cpu)
return self.percpu_percent
diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py
index deef6f8f..1e0d889e 100644
--- a/glances/plugins/glances_plugin.py
+++ b/glances/plugins/glances_plugin.py
@@ -592,8 +592,15 @@ class GlancesPlugin(object):
self.set_limits('refresh', value)
def get_refresh(self):
- """Get the plugin refresh rate"""
- return self.get_limits('refresh')
+ """Return the plugin refresh time"""
+ ret = self.get_limits(item='refresh')
+ if ret is None:
+ ret = self.args.time
+ return ret
+
+ def get_refresh_time(self):
+ """Return the plugin refresh time"""
+ return self.get_refresh()
def set_limits(self, item, value):
"""Return the limits object."""
@@ -1011,13 +1018,6 @@ class GlancesPlugin(object):
ret = '\\'
return ret
- def get_refresh_time(self):
- """Return the plugin refresh time"""
- ret = self.get_limits(item='refresh')
- if ret is None:
- ret = self.args.time
- return ret
-
def _check_decorator(fct):
"""Check decorator for update method.
It checks:
@@ -1029,7 +1029,7 @@ class GlancesPlugin(object):
# Run the method
ret = fct(self, *args, **kw)
# Reset the timer
- self.refresh_timer.set(self.get_refresh_time())
+ self.refresh_timer.set(self.get_refresh())
self.refresh_timer.reset()
else:
# No need to call the method
diff --git a/glances/plugins/glances_sensors.py b/glances/plugins/glances_sensors.py
index a4998a54..bfd1e16b 100644
--- a/glances/plugins/glances_sensors.py
+++ b/glances/plugins/glances_sensors.py
@@ -69,6 +69,11 @@ class Plugin(GlancesPlugin):
# We want to display the stat in the curse interface
self.display_curse = True
+ # Not necessary to refresh every refresh time
+ # By default set to refresh * 2
+ if self.get_refresh() == args.time:
+ self.set_refresh(self.get_refresh() * 2)
+
def get_key(self):
"""Return the key of the list."""
return 'label'
@@ -258,12 +263,6 @@ class GlancesGrabSensors(object):
else:
self.init_fan = True
- # !!! Disable Fan: High CPU consumption with psutil 5.2.0 or higher
- # Delete the two followings lines when corrected (https://github.com/giampaolo/psutil/issues/1199)
- # Correct and tested with PsUtil 5.6.1 (Ubuntu 18.04)
- # self.init_fan = False
- # logger.debug("Fan speed sensors disable (see https://github.com/giampaolo/psutil/issues/1199)")
-
# Init the stats
self.reset()
diff --git a/glances/timer.py b/glances/timer.py
index c97d9c3a..f7ad043c 100644
--- a/glances/timer.py
+++ b/glances/timer.py
@@ -51,7 +51,9 @@ class Timer(object):
def start(self):
self.target = time() + self.duration
- def reset(self):
+ def reset(self, duration=None):
+ if duration is not None:
+ self.set(duration)
self.start()
def get(self):