Remove Py3sensors and replace it by PsUtil

pull/1044/head
nicolargo 2017-02-05 15:17:23 +01:00
parent 83d04ccf59
commit e0a8568f65
3 changed files with 27 additions and 28 deletions

4
NEWS
View File

@ -5,6 +5,10 @@ Glances Version 2
Version 2.8.1 Version 2.8.1
============= =============
Changes:
* Use new sensors-related APIs of Psutil 5.1.0 (issue #1018)
Bugs corrected: Bugs corrected:
* Autodiscover error while binding on IPv6 addresses (issue #1002) * Autodiscover error while binding on IPv6 addresses (issue #1002)

View File

@ -64,7 +64,6 @@ Optional dependencies:
- ``nvidia-ml-py`` (for the GPU plugin) - ``nvidia-ml-py`` (for the GPU plugin)
- ``pika`` (for the RabbitMQ/ActiveMQ export module) - ``pika`` (for the RabbitMQ/ActiveMQ export module)
- ``potsdb`` (for the OpenTSDB export module) - ``potsdb`` (for the OpenTSDB export module)
- ``py3sensors`` (for hardware monitoring support) [Linux-only]
- ``py-cpuinfo`` (for the Quicklook CPU info module) - ``py-cpuinfo`` (for the Quicklook CPU info module)
- ``pymdstat`` (for RAID support) [Linux-only] - ``pymdstat`` (for RAID support) [Linux-only]
- ``pysnmp`` (for SNMP support) - ``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. to install the *wireless-tools* package on your system.
You can also install the following libraries in order to use optional 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 .. code-block:: console
pip install glances[action,batinfo,browser,cpuinfo,chart,docker,export,folders,gpu,ip,raid,snmp,web,wifi] 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: To upgrade Glances to the latest version:

View File

@ -19,14 +19,10 @@
"""Sensors plugin.""" """Sensors plugin."""
# Sensors library (optional; Linux-only) from psutil import sensors_temperatures
# Py3Sensors: https://bitbucket.org/gleb_zhulik/py3sensors
try:
import sensors
except ImportError:
pass
from glances.logger import logger from glances.logger import logger
from glances.compat import iteritems
from glances.plugins.glances_batpercent import Plugin as BatPercentPlugin from glances.plugins.glances_batpercent import Plugin as BatPercentPlugin
from glances.plugins.glances_hddtemp import Plugin as HddTempPlugin from glances.plugins.glances_hddtemp import Plugin as HddTempPlugin
from glances.plugins.glances_plugin import GlancesPlugin from glances.plugins.glances_plugin import GlancesPlugin
@ -228,7 +224,7 @@ class GlancesGrabSensors(object):
def __init__(self): def __init__(self):
"""Init sensors stats.""" """Init sensors stats."""
try: try:
sensors.init() sensors_temperatures()
except Exception: except Exception:
self.initok = False self.initok = False
else: else:
@ -246,24 +242,25 @@ class GlancesGrabSensors(object):
# Reset the list # Reset the list
self.reset() self.reset()
if self.initok: if not self.initok:
for chip in sensors.iter_detected_chips(): return self.sensors_list
# Temperature sensor
for chipname, chip in iteritems(sensors_temperatures()):
i = 1
for feature in chip: for feature in chip:
sensors_current = {} sensors_current = {}
if feature.name.startswith(b'temp'): # Sensor name
# Temperature sensor if feature.label == '':
sensors_current['unit'] = SENSOR_TEMP_UNIT sensors_current['label'] = chipname + ' ' + str(i)
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: 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) self.sensors_list.append(sensors_current)
i += 1
return self.sensors_list return self.sensors_list