mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-26 02:31:36 +03:00
Grab FAN speed in the Glances sensors plugin (issue #501)
This commit is contained in:
parent
d390e03a5c
commit
672ff0d977
9
NEWS
9
NEWS
@ -5,7 +5,14 @@ Glances Version 2.x
|
||||
Version 2.4
|
||||
===========
|
||||
|
||||
...
|
||||
Enhancements and news features:
|
||||
|
||||
* Grab FAN speed in the Glances sensors plugin (issue #501)
|
||||
|
||||
Bugs corrected:
|
||||
|
||||
* Correct monitor list, all processes are take into account (issue #507)
|
||||
* Correct duplicated --enable-history in the doc (issue #511)
|
||||
|
||||
Version 2.3
|
||||
===========
|
||||
|
@ -94,7 +94,7 @@ class GlancesGrabBat(object):
|
||||
"""Update the stats."""
|
||||
if self.initok:
|
||||
self.bat.update()
|
||||
self.bat_list = [{'label': _("Battery (%)"), 'value': self.getcapacitypercent()}]
|
||||
self.bat_list = [{'label': _("Battery"), 'value': self.getcapacitypercent(), 'unit': '%'}]
|
||||
else:
|
||||
self.bat_list = []
|
||||
|
||||
|
@ -33,6 +33,11 @@ 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
|
||||
|
||||
if is_py3:
|
||||
SENSOR_TEMP_UNIT = _('°C')
|
||||
else:
|
||||
SENSOR_TEMP_UNIT = _('°C ')
|
||||
SENSOR_FAN_UNIT = _('RPM')
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
|
||||
@ -80,11 +85,25 @@ class Plugin(GlancesPlugin):
|
||||
|
||||
if self.get_input() == 'local':
|
||||
# Update stats using the dedicated lib
|
||||
self.stats = []
|
||||
# Get the temperature
|
||||
try:
|
||||
self.stats = self.__set_type(self.glancesgrabsensors.get(),
|
||||
temperature = self.__set_type(self.glancesgrabsensors.get('temperature_core'),
|
||||
'temperature_core')
|
||||
except Exception as e:
|
||||
logger.error("Cannot grab sensors temperatures (%s)" % e)
|
||||
else:
|
||||
# Append temperature
|
||||
self.stats.extend(temperature)
|
||||
# Get the FAN speed
|
||||
try:
|
||||
fan_speed = self.__set_type(self.glancesgrabsensors.get('fan_speed'),
|
||||
'fan_speed')
|
||||
except Exception as e:
|
||||
logger.error("Cannot grab FAN speed (%s)" % e)
|
||||
else:
|
||||
# Append FAN speed
|
||||
self.stats.extend(fan_speed)
|
||||
# Update HDDtemp stats
|
||||
try:
|
||||
hddtemp = self.__set_type(self.hddtemp_plugin.update(),
|
||||
@ -119,10 +138,11 @@ class Plugin(GlancesPlugin):
|
||||
def __set_type(self, stats, sensor_type):
|
||||
"""Set the plugin type.
|
||||
|
||||
3 types of stats is possible in the sensors plugin:
|
||||
- Core temperature
|
||||
- HDD temperature
|
||||
- Battery capacity
|
||||
4 types of stats is possible in the sensors plugin:
|
||||
- Core temperature: 'temperature_core'
|
||||
- Fan speed: 'fan_speed'
|
||||
- HDD temperature: 'temperature_hdd'
|
||||
- Battery capacity: 'battery'
|
||||
"""
|
||||
for i in stats:
|
||||
i.update({'type': sensor_type})
|
||||
@ -149,18 +169,13 @@ class Plugin(GlancesPlugin):
|
||||
ret = []
|
||||
|
||||
# Only process if stats exist and display plugin enable...
|
||||
if not self.stats or args.disable_sensors:
|
||||
if not self.stats or args.disable_sensors or self.stats == []:
|
||||
return ret
|
||||
|
||||
# Build the string message
|
||||
# Header
|
||||
msg = '{0:18}'.format(_("SENSORS"))
|
||||
ret.append(self.curse_add_line(msg, "TITLE"))
|
||||
if is_py3:
|
||||
msg = '{0:>5}'.format(_("°C"))
|
||||
else:
|
||||
msg = '{0:>6}'.format(_("°C"))
|
||||
ret.append(self.curse_add_line(msg))
|
||||
|
||||
for i in self.stats:
|
||||
if i['value'] is not None and i['value'] != []:
|
||||
@ -170,10 +185,12 @@ class Plugin(GlancesPlugin):
|
||||
label = self.has_alias(i['label'].lower())
|
||||
if label is None:
|
||||
label = i['label']
|
||||
label = label[:18]
|
||||
msg = '{0:18}'.format(label)
|
||||
try:
|
||||
msg = "{0:12} {1:3}".format(label[:11], i['unit'])
|
||||
except KeyError:
|
||||
msg = '{0:16}'.format(label[:15])
|
||||
ret.append(self.curse_add_line(msg))
|
||||
msg = '{0:>5}'.format(i['value'])
|
||||
msg = '{0:>7}'.format(i['value'])
|
||||
ret.append(self.curse_add_line(
|
||||
msg, self.get_views(item=i[self.get_key()],
|
||||
key='value',
|
||||
@ -207,22 +224,38 @@ class GlancesGrabSensors(object):
|
||||
# Reset the list
|
||||
self.reset()
|
||||
|
||||
# grab only temperature stats
|
||||
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 != {}:
|
||||
sensors_current['label'] = feature.label
|
||||
sensors_current['value'] = int(feature.get_value())
|
||||
self.sensors_list.append(sensors_current)
|
||||
|
||||
return self.sensors_list
|
||||
|
||||
def get(self):
|
||||
def get(self, type='temperature_core'):
|
||||
"""Get sensors list."""
|
||||
self.__update__()
|
||||
return self.sensors_list
|
||||
if type == 'temperature_core':
|
||||
logger.info(type)
|
||||
ret = [s for s in self.sensors_list if s['unit'] == SENSOR_TEMP_UNIT]
|
||||
elif type == 'fan_speed':
|
||||
logger.info(type)
|
||||
ret = [s for s in self.sensors_list if s['unit'] == SENSOR_FAN_UNIT]
|
||||
else:
|
||||
# Unknown type
|
||||
logger.debug("Unknown sensor type %s" % type)
|
||||
ret = []
|
||||
logger.info(ret)
|
||||
return ret
|
||||
|
||||
def quit(self):
|
||||
"""End of connection."""
|
||||
|
Loading…
Reference in New Issue
Block a user