From e0a8568f65907a764883a975b6389a70f02e2fb3 Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sun, 5 Feb 2017 15:17:23 +0100 Subject: [PATCH 1/4] Remove Py3sensors and replace it by PsUtil --- NEWS | 4 +++ README.rst | 4 +-- glances/plugins/glances_sensors.py | 47 ++++++++++++++---------------- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/NEWS b/NEWS index ac3ed624..42d77b61 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,10 @@ Glances Version 2 Version 2.8.1 ============= +Changes: + * Use new sensors-related APIs of Psutil 5.1.0 (issue #1018) + + Bugs corrected: * Autodiscover error while binding on IPv6 addresses (issue #1002) diff --git a/README.rst b/README.rst index b96bd5cc..42a1465c 100644 --- a/README.rst +++ b/README.rst @@ -64,7 +64,6 @@ Optional dependencies: - ``nvidia-ml-py`` (for the GPU plugin) - ``pika`` (for the RabbitMQ/ActiveMQ export module) - ``potsdb`` (for the OpenTSDB export module) -- ``py3sensors`` (for hardware monitoring support) [Linux-only] - ``py-cpuinfo`` (for the Quicklook CPU info module) - ``pymdstat`` (for RAID support) [Linux-only] - ``pysnmp`` (for SNMP support) @@ -132,12 +131,11 @@ just install psutil from the binary installation file. to install the *wireless-tools* package on your system. You can also install the following libraries in order to use optional -features (like the Web interface, exports modules, sensors...): +features (like the Web interface, exports modules...): .. code-block:: console pip install glances[action,batinfo,browser,cpuinfo,chart,docker,export,folders,gpu,ip,raid,snmp,web,wifi] - pip install https://bitbucket.org/gleb_zhulik/py3sensors/get/tip.zip To upgrade Glances to the latest version: diff --git a/glances/plugins/glances_sensors.py b/glances/plugins/glances_sensors.py index f4d5a3a6..22b1dfab 100644 --- a/glances/plugins/glances_sensors.py +++ b/glances/plugins/glances_sensors.py @@ -19,14 +19,10 @@ """Sensors plugin.""" -# Sensors library (optional; Linux-only) -# Py3Sensors: https://bitbucket.org/gleb_zhulik/py3sensors -try: - import sensors -except ImportError: - pass +from psutil import sensors_temperatures from glances.logger import logger +from glances.compat import iteritems from glances.plugins.glances_batpercent import Plugin as BatPercentPlugin from glances.plugins.glances_hddtemp import Plugin as HddTempPlugin from glances.plugins.glances_plugin import GlancesPlugin @@ -228,7 +224,7 @@ class GlancesGrabSensors(object): def __init__(self): """Init sensors stats.""" try: - sensors.init() + sensors_temperatures() except Exception: self.initok = False else: @@ -246,24 +242,25 @@ class GlancesGrabSensors(object): # Reset the list self.reset() - if self.initok: - for chip in sensors.iter_detected_chips(): - for feature in chip: - sensors_current = {} - if feature.name.startswith(b'temp'): - # Temperature sensor - sensors_current['unit'] = SENSOR_TEMP_UNIT - elif feature.name.startswith(b'fan'): - # Fan speed sensor - sensors_current['unit'] = SENSOR_FAN_UNIT - if sensors_current: - try: - sensors_current['label'] = feature.label - sensors_current['value'] = int(feature.get_value()) - except Exception as e: - logger.debug("Cannot grab sensor stat (%s)" % e) - else: - self.sensors_list.append(sensors_current) + if not self.initok: + return self.sensors_list + + # Temperature sensor + for chipname, chip in iteritems(sensors_temperatures()): + i = 1 + for feature in chip: + sensors_current = {} + # Sensor name + if feature.label == '': + sensors_current['label'] = chipname + ' ' + str(i) + else: + sensors_current['label'] = feature.label + # Temperature and unit + sensors_current['value'] = int(feature.current) + sensors_current['unit'] = SENSOR_TEMP_UNIT + # Add sensor to the list + self.sensors_list.append(sensors_current) + i += 1 return self.sensors_list From e40640d47d6e93592b85218b12e13824887abd2f Mon Sep 17 00:00:00 2001 From: Alessio Sergi Date: Wed, 8 Feb 2017 12:42:02 +0100 Subject: [PATCH 2/4] psutil.sensors_temperatures() is available in version 5.1.0 or greater --- glances/plugins/glances_sensors.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/glances/plugins/glances_sensors.py b/glances/plugins/glances_sensors.py index 22b1dfab..1c841a60 100644 --- a/glances/plugins/glances_sensors.py +++ b/glances/plugins/glances_sensors.py @@ -19,7 +19,7 @@ """Sensors plugin.""" -from psutil import sensors_temperatures +import psutil from glances.logger import logger from glances.compat import iteritems @@ -219,13 +219,14 @@ class Plugin(GlancesPlugin): class GlancesGrabSensors(object): - """Get sensors stats using the py3sensors library.""" + """Get sensors stats.""" def __init__(self): """Init sensors stats.""" try: - sensors_temperatures() - except Exception: + # XXX: psutil>=5.1.0 is required + self.stemps = psutil.sensors_temperatures() + except AttributeError: self.initok = False else: self.initok = True @@ -246,7 +247,7 @@ class GlancesGrabSensors(object): return self.sensors_list # Temperature sensor - for chipname, chip in iteritems(sensors_temperatures()): + for chipname, chip in iteritems(self.stemps): i = 1 for feature in chip: sensors_current = {} From 06e12a21241946cd4ba8b6f472fe31bcfd42e8e1 Mon Sep 17 00:00:00 2001 From: Alessio Sergi Date: Wed, 8 Feb 2017 13:01:07 +0100 Subject: [PATCH 3/4] Drop py3sensors from optional-requirements.txt and tox.ini too --- optional-requirements.txt | 1 - tox.ini | 1 - 2 files changed, 2 deletions(-) diff --git a/optional-requirements.txt b/optional-requirements.txt index 926c046a..ac97594d 100644 --- a/optional-requirements.txt +++ b/optional-requirements.txt @@ -21,4 +21,3 @@ scandir; python_version < "3.5" statsd wifi zeroconf -https://bitbucket.org/gleb_zhulik/py3sensors/get/tip.zip diff --git a/tox.ini b/tox.ini index 8506e5ee..3c54c1d2 100644 --- a/tox.ini +++ b/tox.ini @@ -15,7 +15,6 @@ deps = psutil bottle batinfo - https://bitbucket.org/gleb_zhulik/py3sensors/get/tip.tar.gz commands = python unitest.py python unitest-restful.py From fd45d4121a3636d6cc0a0d1802ab1aff36aacb78 Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sat, 11 Feb 2017 10:05:54 +0100 Subject: [PATCH 4/4] Remove batinfo dep --- NEWS | 6 +++++- README.rst | 3 +-- docs/aoa/sensors.rst | 7 +------ docs/man/glances.1 | 2 +- optional-requirements.txt | 1 - setup.py | 1 - tox.ini | 1 - 7 files changed, 8 insertions(+), 13 deletions(-) diff --git a/NEWS b/NEWS index 624cf682..30944f89 100644 --- a/NEWS +++ b/NEWS @@ -5,9 +5,13 @@ Glances Version 2 Version 2.x ============= -Bugs corrected: +Enhancements and new features: * Use new sensors-related APIs of Psutil 5.1.0 (issue #1018) + => Remove Py3Sensors and Batinfo dependencies + +Bugs corrected: + * Unable to launch Glances on Windows (issue #1021) Version 2.8.2 diff --git a/README.rst b/README.rst index 73c42a7d..6055e200 100644 --- a/README.rst +++ b/README.rst @@ -50,7 +50,6 @@ Requirements Optional dependencies: -- ``batinfo`` (for battery monitoring support) [Linux-only] - ``bernhard`` (for the Riemann export module) - ``bottle`` (for Web server mode) - ``cassandra-driver`` (for the Cassandra export module) @@ -135,7 +134,7 @@ features (like the Web interface, exports modules...): .. code-block:: console - pip install glances[action,batinfo,browser,cpuinfo,chart,docker,export,folders,gpu,ip,raid,snmp,web,wifi] + pip install glances[action,browser,cpuinfo,chart,docker,export,folders,gpu,ip,raid,snmp,web,wifi] To upgrade Glances to the latest version: diff --git a/docs/aoa/sensors.rst b/docs/aoa/sensors.rst index d2d459ea..4b2aaaef 100644 --- a/docs/aoa/sensors.rst +++ b/docs/aoa/sensors.rst @@ -7,10 +7,7 @@ Sensors .. image:: ../_static/sensors.png -Glances can displays the sensors information using ``lm-sensors``, -``hddtemp`` and `batinfo`_. - -All of the above libraries are available only on Linux. +Glances can displays the sensors information using ``PsUtil`` and ``hddtemp``. As of ``lm-sensors``, a filter is being applied in order to display temperature and fan speed only. @@ -20,5 +17,3 @@ There is no alert on this information. .. note:: Limit values and sensors alias names can be defined in the configuration file under the ``[sensors]`` section. - -.. _batinfo: https://github.com/nicolargo/batinfo diff --git a/docs/man/glances.1 b/docs/man/glances.1 index aa8355e4..4f2dd2ec 100644 --- a/docs/man/glances.1 +++ b/docs/man/glances.1 @@ -1,6 +1,6 @@ .\" Man page generated from reStructuredText. . -.TH "GLANCES" "1" "Feb 07, 2017" "2.8.2" "Glances" +.TH "GLANCES" "1" "Feb 11, 2017" "2.8.3_DEVELOP" "Glances" .SH NAME glances \- An eye on your system . diff --git a/optional-requirements.txt b/optional-requirements.txt index d7555fe4..61527d31 100644 --- a/optional-requirements.txt +++ b/optional-requirements.txt @@ -1,4 +1,3 @@ -batinfo bernhard bottle cassandra-driver diff --git a/setup.py b/setup.py index 3069aaf4..7eab9392 100755 --- a/setup.py +++ b/setup.py @@ -79,7 +79,6 @@ setup( install_requires=get_install_requires(), extras_require={ 'action': ['pystache'], - 'batinfo': ['batinfo'], 'browser': ['zeroconf>=0.17'], 'cpuinfo': ['py-cpuinfo'], 'chart': ['matplotlib'], diff --git a/tox.ini b/tox.ini index 3c54c1d2..daa48306 100644 --- a/tox.ini +++ b/tox.ini @@ -14,7 +14,6 @@ deps = requests psutil bottle - batinfo commands = python unitest.py python unitest-restful.py