提交 f0e8ef44 编写于 作者: N nicolargo

Refactor all the way config file is loaded (now by each plugin). Should solve issues #1508.

上级 504450ca
......@@ -188,15 +188,17 @@ critical=90
#folder_3_path=/nonexisting
#folder_4_path=/root
[hddtemp]
# Define hddtemp server IP and port (default is 127.0.0.1 and 7634 (TCP))
host=127.0.0.1
port=7634
[sensors]
# Sensors core thresholds (in Celsius...)
# Default values if not defined: 60/70/80
temperature_core_careful=60
temperature_core_warning=70
temperature_core_critical=80
# Define hddtemp server IP and port (default is 127.0.0.1 and 7634 (TCP))
hddtemp_host=127.0.0.1
hddtemp_port=7634
# Temperatures threshold in °C for hddtemp
# Default values if not defined: 45/52/60
temperature_hdd_careful=45
......
......@@ -88,9 +88,10 @@ class Plugin(GlancesPlugin):
Only for display.
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
config=config,
stats_init_value=[])
# We want to display the stat in the curse interface
......
......@@ -30,6 +30,7 @@ class Plugin(GlancesPlugin):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
config=config,
stats_init_value=[])
self.args = args
self.config = config
......
......@@ -51,9 +51,9 @@ class Plugin(GlancesPlugin):
stats is a dict
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args)
super(Plugin, self).__init__(args=args, config=config)
# We want to display the stat in the curse interface
self.display_curse = True
......
......@@ -32,9 +32,9 @@ class Plugin(GlancesPlugin):
stats is integer (number of core)
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args)
super(Plugin, self).__init__(args=args, config=config)
# We dot not want to display the stat in the curse interface
# The core number is displayed by the load plugin
......
......@@ -59,9 +59,11 @@ class Plugin(GlancesPlugin):
percentage.
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the CPU plugin."""
super(Plugin, self).__init__(args=args, items_history_list=items_history_list)
super(Plugin, self).__init__(args=args,
config=config,
items_history_list=items_history_list)
# We want to display the stat in the curse interface
self.display_curse = True
......
......@@ -42,9 +42,10 @@ class Plugin(GlancesPlugin):
stats is a list
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
config=config,
items_history_list=items_history_list,
stats_init_value=[])
......
......@@ -72,9 +72,10 @@ class Plugin(GlancesPlugin):
stats is a dict: {'version': {...}, 'containers': [{}, {}]}
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
config=config,
items_history_list=items_history_list)
# The plgin can be disable using: args.disable_docker
......
......@@ -34,6 +34,7 @@ class Plugin(GlancesPlugin):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
config=config,
stats_init_value=[])
self.args = args
self.config = config
......
......@@ -70,9 +70,10 @@ class Plugin(GlancesPlugin):
stats is a list
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
config=config,
items_history_list=items_history_list,
stats_init_value=[])
......
......@@ -48,9 +48,10 @@ class Plugin(GlancesPlugin):
stats is a list of dictionaries with one entry per GPU
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
config=config,
stats_init_value=[])
# Init the NVidia API
......
......@@ -32,7 +32,7 @@ class Plugin(GlancesPlugin):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args)
super(Plugin, self).__init__(args=args, config=config)
# Set the config instance
self.config = config
......
......@@ -53,9 +53,9 @@ class Plugin(GlancesPlugin):
stats is a dict
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args)
super(Plugin, self).__init__(args=args, config=config)
# We want to display the stat in the curse interface
self.display_curse = True
......
......@@ -33,9 +33,10 @@ class Plugin(GlancesPlugin):
stats is a list
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
config=config,
stats_init_value=[])
# We want to display the stat in the curse interface
......
......@@ -50,9 +50,10 @@ class Plugin(GlancesPlugin):
stats is a dict
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
config=config,
items_history_list=items_history_list)
# We want to display the stat in the curse interface
......
......@@ -59,9 +59,10 @@ class Plugin(GlancesPlugin):
stats is a dict
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
config=config,
items_history_list=items_history_list)
# We want to display the stat in the curse interface
......
......@@ -47,9 +47,10 @@ class Plugin(GlancesPlugin):
stats is a dict
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
config=config,
items_history_list=items_history_list)
# We want to display the stat in the curse interface
......
......@@ -51,9 +51,10 @@ class Plugin(GlancesPlugin):
stats is a list
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
config=config,
items_history_list=items_history_list,
stats_init_value=[])
......
......@@ -31,9 +31,9 @@ class Plugin(GlancesPlugin):
stats is (string)
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args)
super(Plugin, self).__init__(args=args, config=config)
# We want to display the stat in the curse interface
self.display_curse = True
......
......@@ -39,9 +39,10 @@ class Plugin(GlancesPlugin):
for each CPU.
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
config=config,
items_history_list=items_history_list,
stats_init_value=[])
......
......@@ -41,6 +41,7 @@ class GlancesPlugin(object):
def __init__(self,
args=None,
config=None,
items_history_list=None,
stats_init_value={}):
"""Init the plugin of plugins class.
......@@ -66,7 +67,8 @@ class GlancesPlugin(object):
:stats_init_value: Default value for a stats item
"""
# Plugin name (= module name without glances_)
self.plugin_name = self.__class__.__module__[len('glances_'):]
pos = self.__class__.__module__.find('glances_') + len('glances') + 1
self.plugin_name = self.__class__.__module__[pos:]
# logger.debug("Init plugin %s" % self.plugin_name)
# Init the args
......@@ -83,8 +85,11 @@ class GlancesPlugin(object):
self.items_history_list = items_history_list
self.stats_history = self.init_stats_history()
# Init the limits dictionnary
# Init the limits (configuration keys) dictionnary
self._limits = dict()
if not self.load_limits(config=config):
logger.debug('Can not load section {} in {}'.format(self.plugin_name,
config))
# Init the actions
self.actions = GlancesActions(args=args)
......
......@@ -48,6 +48,7 @@ class Plugin(GlancesPlugin):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
config=config,
stats_init_value=[])
self.args = args
self.config = config
......
......@@ -51,9 +51,10 @@ class Plugin(GlancesPlugin):
'name': 'process name',
None: 'None'}
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
config=config,
items_history_list=items_history_list)
# We want to display the stat in the curse interface
......
......@@ -91,9 +91,10 @@ class Plugin(GlancesPlugin):
'name': '[{}]'
}
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
config=config,
stats_init_value=[])
# We want to display the stat in the curse interface
......
......@@ -29,9 +29,9 @@ class Plugin(GlancesPlugin):
stats is a tuple
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args)
super(Plugin, self).__init__(args=args, config=config)
self.reset()
......
......@@ -59,9 +59,10 @@ class Plugin(GlancesPlugin):
'stats' is a dictionary.
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the quicklook plugin."""
super(Plugin, self).__init__(args=args,
config=config,
items_history_list=items_history_list)
# We want to display the stat in the curse interface
self.display_curse = True
......
......@@ -39,9 +39,9 @@ class Plugin(GlancesPlugin):
stats is a dict (see pymdstat documentation)
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args)
super(Plugin, self).__init__(args=args, config=config)
# We want to display the stat in the curse interface
self.display_curse = True
......
......@@ -24,8 +24,8 @@ import warnings
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.sensors.glances_batpercent import Plugin as BatPercentPlugin
from glances.plugins.sensors.glances_hddtemp import Plugin as HddTempPlugin
from glances.plugins.glances_plugin import GlancesPlugin
SENSOR_TEMP_UNIT = 'C'
......@@ -45,9 +45,10 @@ class Plugin(GlancesPlugin):
The hard disks are already sorted by name.
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
config=config,
stats_init_value=[])
# Init the sensor class
......@@ -55,11 +56,11 @@ class Plugin(GlancesPlugin):
# Instance for the HDDTemp Plugin in order to display the hard disks
# temperatures
self.hddtemp_plugin = HddTempPlugin(args=args)
self.hddtemp_plugin = HddTempPlugin(args=args, config=config)
# Instance for the BatPercent in order to display the batteries
# capacities
self.batpercent_plugin = BatPercentPlugin(args=args)
self.batpercent_plugin = BatPercentPlugin(args=args, config=config)
# We want to display the stat in the curse interface
self.display_curse = True
......
......@@ -152,6 +152,7 @@ class Plugin(GlancesPlugin):
def __init__(self,
args=None,
config=None,
stats_init_value=[]):
"""Init the plugin."""
# check if user is admin
......@@ -159,7 +160,7 @@ class Plugin(GlancesPlugin):
disable(args, "smart")
logger.debug("Current user is not admin, HDD SMART plugin disabled.")
super(Plugin, self).__init__(args=args)
super(Plugin, self).__init__(args=args, config=config)
# We want to display the stat in the curse interface
self.display_curse = True
......
......@@ -83,9 +83,9 @@ class Plugin(GlancesPlugin):
stats is a dict
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args)
super(Plugin, self).__init__(args=args, config=config)
# We want to display the stat in the curse interface
self.display_curse = True
......
......@@ -35,9 +35,9 @@ class Plugin(GlancesPlugin):
stats is date (string)
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args)
super(Plugin, self).__init__(args=args, config=config)
# We want to display the stat in the curse interface
self.display_curse = True
......
......@@ -49,9 +49,10 @@ class Plugin(GlancesPlugin):
Get stats of the current Wifi hotspots.
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
config=config,
stats_init_value=[])
# We want to display the stat in the curse interface
......
......@@ -49,9 +49,10 @@ class Plugin(GlancesPlugin):
stats is a list
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
config=config,
stats_init_value=[])
# Init the sensor class
......
......@@ -33,17 +33,20 @@ class Plugin(GlancesPlugin):
stats is a list
"""
def __init__(self, args=None):
def __init__(self, args=None, config=None):
"""Init the plugin."""
super(Plugin, self).__init__(args=args,
config=config,
stats_init_value=[])
# Init the sensor class
hddtemp_host = self.get_conf_value("host",
default=["127.0.0.1"])[0]
hddtemp_port = int(self.get_conf_value("port",
default="7634"))
self.hddtemp = GlancesGrabHDDTemp(args=args,
host=self.get_conf_value("hddtemp_host",
default="127.0.0.1"),
port=int(self.get_conf_value("hddtemp_port",
default="7634")))
host=hddtemp_host,
port=hddtemp_port)
# We do not want to display the stat in a dedicated area
# The HDD temp is displayed within the sensors plugin
......
......@@ -47,7 +47,8 @@ class GlancesStats(object):
self.load_modules(self.args)
# Load the limits (for plugins)
self.load_limits(self.config)
# Not necessary anymore, configuration file is loaded on init
# self.load_limits(self.config)
def __getattr__(self, item):
"""Overwrite the getattr method in case of attribute is not found.
......@@ -109,14 +110,13 @@ class GlancesStats(object):
# for example, the file glances_xxx.py
# generate self._plugins_list["xxx"] = ...
name = plugin_script[len(self.header):-3].lower()
# Loaf the plugin class
try:
# Import the plugin
plugin = __import__(plugin_script[:-3])
# Init and add the plugin to the dictionary
if name in ('help', 'amps', 'ports', 'folders'):
self._plugins[name] = plugin.Plugin(args=args, config=config)
else:
self._plugins[name] = plugin.Plugin(args=args)
self._plugins[name] = plugin.Plugin(args=args, config=config)
except Exception as e:
# If a plugin can not be loaded, display a critical message
# on the console but do not crash
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册