mirror of
https://github.com/nicolargo/glances.git
synced 2025-01-01 14:04:50 +03:00
Add batteries % to the sensors list
This commit is contained in:
parent
a5a4fab805
commit
87258ebf95
@ -40,11 +40,13 @@ class Plugin(GlancesPlugin):
|
||||
def __init__(self, args=None):
|
||||
GlancesPlugin.__init__(self, args=args)
|
||||
|
||||
#!!! TODO: display plugin...
|
||||
|
||||
# Init the sensor class
|
||||
self.glancesgrabbat = glancesGrabBat()
|
||||
|
||||
# We do not want to display the stat in a dedicated area
|
||||
# The HDD temp is displayed within the sensors plugin
|
||||
self.display_curse = False
|
||||
|
||||
# Init stats
|
||||
self.reset()
|
||||
|
||||
@ -66,7 +68,7 @@ class Plugin(GlancesPlugin):
|
||||
if self.get_input() == 'local':
|
||||
# Update stats using the standard system lib
|
||||
|
||||
self.stats = self.glancesgrabbat.getcapacitypercent()
|
||||
self.stats = self.glancesgrabbat.get()
|
||||
|
||||
elif self.get_input() == 'snmp':
|
||||
# Update stats using SNMP
|
||||
@ -89,9 +91,11 @@ class glancesGrabBat:
|
||||
self.initok = True
|
||||
self.bat_list = []
|
||||
self.__update__()
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
print "Warning: Can not grab batterie sensor. Missing BatInfo lib (%s)" % e
|
||||
self.initok = False
|
||||
|
||||
|
||||
def __update__(self):
|
||||
"""
|
||||
Update the stats
|
||||
@ -99,29 +103,33 @@ class glancesGrabBat:
|
||||
if self.initok:
|
||||
try:
|
||||
self.bat.update()
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
self.bat_list = []
|
||||
else:
|
||||
self.bat_list = self.bat.stat
|
||||
self.bat_list = []
|
||||
new_item = { 'label': _("Batterie (%)"),
|
||||
'value': self.getcapacitypercent() }
|
||||
self.bat_list.append(new_item)
|
||||
else:
|
||||
self.bat_list = []
|
||||
|
||||
def get(self):
|
||||
# Update the stats
|
||||
self.__update__()
|
||||
return self.bat_list
|
||||
|
||||
def getcapacitypercent(self):
|
||||
if not self.initok or self.bat_list == []:
|
||||
if not self.initok or self.bat.stat == []:
|
||||
return []
|
||||
|
||||
# Init the bsum (sum of percent) and bcpt (number of batteries)
|
||||
# and Loop over batteries (yes a computer could have more than 1 battery)
|
||||
bsum = 0
|
||||
for bcpt in range(len(self.get())):
|
||||
for bcpt in range(len(self.bat.stat)):
|
||||
try:
|
||||
bsum = bsum + int(self.bat_list[bcpt].capacity)
|
||||
bsum = bsum + int(self.bat.stat[bcpt].capacity)
|
||||
except ValueError:
|
||||
return []
|
||||
bcpt = bcpt + 1
|
||||
|
||||
# Return the global percent
|
||||
return int(bsum / bcpt)
|
||||
|
@ -26,8 +26,9 @@ except ImportError:
|
||||
|
||||
# Import Glances lib
|
||||
from glances.core.glances_globals import is_py3
|
||||
from glances.plugins.glances_hddtemp import Plugin as HddTempPlugin
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
from glances.plugins.glances_hddtemp import Plugin as HddTempPlugin
|
||||
from glances.plugins.glances_batpercent import Plugin as BatPercentPlugin
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
@ -45,9 +46,12 @@ class Plugin(GlancesPlugin):
|
||||
# Init the sensor class
|
||||
self.glancesgrabsensors = glancesGrabSensors()
|
||||
|
||||
# Instance for the CorePlugin in order to display the core number
|
||||
# Instance for the HDDTemp Plugin in order to display the hard disks temperatures
|
||||
self.hddtemp_plugin = HddTempPlugin()
|
||||
|
||||
# Instance for the BatPercent in order to display the batteries capacities
|
||||
self.batpercent_plugin = BatPercentPlugin()
|
||||
|
||||
# We want to display the stat in the curse interface
|
||||
self.display_curse = True
|
||||
# Set the message position
|
||||
@ -76,9 +80,13 @@ class Plugin(GlancesPlugin):
|
||||
|
||||
if self.get_input() == 'local':
|
||||
# Update stats using the standard system lib
|
||||
self.hddtemp_plugin.update()
|
||||
self.stats = self.glancesgrabsensors.get()
|
||||
self.stats.extend(self.hddtemp_plugin.stats)
|
||||
# Append HDD temperature
|
||||
hddtemp = self.hddtemp_plugin.update()
|
||||
self.stats.extend(hddtemp)
|
||||
# Append Batteries %
|
||||
batpercent = self.batpercent_plugin.update()
|
||||
self.stats.extend(batpercent)
|
||||
elif self.get_input() == 'snmp':
|
||||
# Update stats using SNMP
|
||||
# No standard: http://www.net-snmp.org/wiki/index.php/Net-SNMP_and_lm-sensors_on_Ubuntu_10.04
|
||||
|
Loading…
Reference in New Issue
Block a user