提交 412b8afc 编写于 作者: N Nicolargo

Correct issue #433 on battery percent update

上级 4abad6e8
......@@ -84,12 +84,14 @@ class GlancesGrabBat(object):
self.initok = True
self.bat_list = []
self.update()
except Exception:
except Exception as e:
self.initok = False
logger.debug("Can not init GlancesGrabBat class (%s)" % e)
def update(self):
"""Update the stats."""
if self.initok:
self.bat.update()
self.bat_list = [{'label': _("Battery (%)"), 'value': self.getcapacitypercent()}]
else:
self.bat_list = []
......
......@@ -64,6 +64,7 @@ class Plugin(GlancesPlugin):
"""Reset/init the stats."""
self.stats = {}
@GlancesPlugin._log_result_decorator
def update(self):
"""Update CPU stats using the input method."""
# Reset stats
......
......@@ -53,6 +53,7 @@ class Plugin(GlancesPlugin):
"""Reset/init the stats."""
self.stats = []
@GlancesPlugin._log_result_decorator
def update(self):
"""Update disk I/O stats using the input method."""
# Reset stats
......
......@@ -77,6 +77,7 @@ class Plugin(GlancesPlugin):
"""Reset/init the stats."""
self.stats = []
@GlancesPlugin._log_result_decorator
def update(self):
"""Update the FS stats using the input method."""
# Reset the list
......
......@@ -38,7 +38,7 @@ snmp_oid = {'min1': '1.3.6.1.4.1.2021.10.1.3.1',
# Define the history items list
# All items in this list will be historised if the --enable-history tag is set
# 'color' define the graph color in #RGB format
items_history_list = [{'name': 'min1', 'color': '#0000FF'},
items_history_list = [{'name': 'min1', 'color': '#0000FF'},
{'name': 'min5', 'color': '#0000AA'},
{'name': 'min15', 'color': '#000044'}]
......@@ -52,7 +52,8 @@ class Plugin(GlancesPlugin):
def __init__(self, args=None):
"""Init the plugin."""
GlancesPlugin.__init__(self, args=args, items_history_list=items_history_list)
GlancesPlugin.__init__(
self, args=args, items_history_list=items_history_list)
# We want to display the stat in the curse interface
self.display_curse = True
......@@ -70,6 +71,7 @@ class Plugin(GlancesPlugin):
"""Reset/init the stats."""
self.stats = {}
@GlancesPlugin._log_result_decorator
def update(self):
"""Update load stats."""
# Reset stats
......
......@@ -72,6 +72,7 @@ class Plugin(GlancesPlugin):
"""Reset/init the stats."""
self.stats = {}
@GlancesPlugin._log_result_decorator
def update(self):
"""Update RAM memory stats using the input method."""
# Reset stats
......
......@@ -61,6 +61,7 @@ class Plugin(GlancesPlugin):
"""Reset/init the stats."""
self.stats = {}
@GlancesPlugin._log_result_decorator
def update(self):
"""Update swap memory stats using the input method."""
# Reset stats
......
......@@ -61,6 +61,7 @@ class Plugin(GlancesPlugin):
"""Reset/init the stats."""
self.stats = []
@GlancesPlugin._log_result_decorator
def update(self):
"""Update network stats using the input method.
......
......@@ -494,3 +494,15 @@ class GlancesPlugin(object):
return '{0:.{decimal}f}{symbol}'.format(
value, decimal=decimal_precision, symbol=symbol)
return '{0!s}'.format(number)
def _log_result_decorator(fct):
"""Log (DEBUG) the result of the function fct"""
def wrapper(*args, **kw):
ret = fct(*args, **kw)
logger.debug("%s %s %s return %s" % (args[0].__class__.__name__, args[
0].__class__.__module__[len('glances_'):], fct.func_name, ret))
return ret
return wrapper
# Mandatory to call the decorator in childs' classes
_log_result_decorator = staticmethod(_log_result_decorator)
......@@ -27,7 +27,7 @@ except ImportError:
pass
# Import Glances lib
from glances.core.glances_globals import is_py3
from glances.core.glances_globals import is_py3, logger
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
......@@ -67,6 +67,7 @@ class Plugin(GlancesPlugin):
"""Reset/init the stats."""
self.stats = []
@GlancesPlugin._log_result_decorator
def update(self):
"""Update sensors stats using the input method."""
# Reset the stats
......@@ -77,14 +78,14 @@ class Plugin(GlancesPlugin):
try:
self.stats = self.__set_type(self.glancesgrabsensors.get(),
'temperature_core')
except:
pass
except Exception as e:
logger.error("Can not grab sensors temperatures (%s)" % e)
# Update HDDtemp stats
try:
hddtemp = self.__set_type(self.hddtemp_plugin.update(),
'temperature_hdd')
except:
pass
except Exception as e:
logger.error("Can not grab HDD temperature (%s)" % e)
else:
# Append HDD temperature
self.stats.extend(hddtemp)
......@@ -92,11 +93,12 @@ class Plugin(GlancesPlugin):
try:
batpercent = self.__set_type(self.batpercent_plugin.update(),
'battery')
except:
pass
except Exception as e:
logger.error("Can not grab battery percent (%s)" % e)
else:
# Append Batteries %
self.stats.extend(batpercent)
elif self.get_input() == 'snmp':
# Update stats using SNMP
# No standard:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册