mirror of https://github.com/nicolargo/glances.git
Change the way AMP are loaded #1930
This commit is contained in:
parent
48251c8271
commit
3a7c479524
|
|
@ -42,7 +42,7 @@ class GlancesAmp(object):
|
|||
|
||||
# AMP name (= module name without glances_)
|
||||
if name is None:
|
||||
self.amp_name = self.__class__.__module__[len('glances_') :]
|
||||
self.amp_name = self.__class__.__module__
|
||||
else:
|
||||
self.amp_name = name
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ from subprocess import check_output, STDOUT, CalledProcessError
|
|||
|
||||
from glances.globals import u, to_ascii
|
||||
from glances.logger import logger
|
||||
from glances.amps.glances_amp import GlancesAmp
|
||||
from glances.amps.amp import GlancesAmp
|
||||
|
||||
|
||||
class Amp(GlancesAmp):
|
||||
|
|
@ -47,7 +47,7 @@ status_url=http://localhost/nginx_status
|
|||
import requests
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.amps.glances_amp import GlancesAmp
|
||||
from glances.amps.amp import GlancesAmp
|
||||
|
||||
|
||||
class Amp(GlancesAmp):
|
||||
|
|
@ -39,7 +39,7 @@ from subprocess import check_output, CalledProcessError
|
|||
|
||||
from glances.logger import logger
|
||||
from glances.globals import iteritems, to_ascii
|
||||
from glances.amps.glances_amp import GlancesAmp
|
||||
from glances.amps.amp import GlancesAmp
|
||||
|
||||
|
||||
class Amp(GlancesAmp):
|
||||
|
|
@ -38,7 +38,7 @@ from subprocess import check_output, STDOUT
|
|||
|
||||
from glances.logger import logger
|
||||
from glances.globals import iteritems
|
||||
from glances.amps.glances_amp import GlancesAmp
|
||||
from glances.amps.amp import GlancesAmp
|
||||
|
||||
|
||||
class Amp(GlancesAmp):
|
||||
|
|
@ -45,41 +45,30 @@ class AmpsList(object):
|
|||
if self.config is None:
|
||||
return False
|
||||
|
||||
# Display a warning (deprecated) message if the monitor section exist
|
||||
if "monitor" in self.config.sections():
|
||||
logger.warning(
|
||||
"A deprecated [monitor] section exists in the Glances configuration file. You should use the new \
|
||||
Applications Monitoring Process module instead \
|
||||
(http://glances.readthedocs.io/en/develop/aoa/amps.html)."
|
||||
)
|
||||
|
||||
# TODO: Change the way AMP are loaded (use folder/module instead of glances_foo.py file)
|
||||
# See https://github.com/nicolargo/glances/issues/1930
|
||||
header = "glances_"
|
||||
# For each AMP script, call the load_config method
|
||||
for s in self.config.sections():
|
||||
if s.startswith("amp_"):
|
||||
# An AMP section exists in the configuration file
|
||||
# If an AMP script exist in the glances/amps folder, use it
|
||||
amp_conf_name = s[4:]
|
||||
amp_script = os.path.join(amps_path, header + s[4:] + ".py")
|
||||
if not os.path.exists(amp_script):
|
||||
# If an AMP module exist in amps_path (glances/amps) folder then use it
|
||||
amp_name = s[4:]
|
||||
amp_module = os.path.join(amps_path, amp_name)
|
||||
if not os.path.exists(amp_module):
|
||||
# If not, use the default script
|
||||
amp_script = os.path.join(amps_path, "glances_default.py")
|
||||
amp_module = os.path.join(amps_path, "default")
|
||||
try:
|
||||
amp = __import__(os.path.basename(amp_script)[:-3])
|
||||
amp = __import__(os.path.basename(amp_module))
|
||||
except ImportError as e:
|
||||
logger.warning("Missing Python Lib ({}), cannot load {} AMP".format(e, amp_conf_name))
|
||||
logger.warning("Missing Python Lib ({}), cannot load AMP {}".format(e, amp_name))
|
||||
except Exception as e:
|
||||
logger.warning("Cannot load {} AMP ({})".format(amp_conf_name, e))
|
||||
logger.warning("Cannot load AMP {} ({})".format(amp_name, e))
|
||||
else:
|
||||
# Add the AMP to the dictionary
|
||||
# The key is the AMP name
|
||||
# for example, the file glances_xxx.py
|
||||
# generate self._amps_list["xxx"] = ...
|
||||
self.__amps_dict[amp_conf_name] = amp.Amp(name=amp_conf_name, args=self.args)
|
||||
self.__amps_dict[amp_name] = amp.Amp(name=amp_name, args=self.args)
|
||||
# Load the AMP configuration
|
||||
self.__amps_dict[amp_conf_name].load_config(self.config)
|
||||
self.__amps_dict[amp_name].load_config(self.config)
|
||||
# Log AMPs list
|
||||
logger.debug("AMPs list: {}".format(self.getList()))
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class GlancesExport(object):
|
|||
def __init__(self, config=None, args=None):
|
||||
"""Init the export class."""
|
||||
# Export name (= module name without glances_)
|
||||
self.export_name = self.__class__.__module__[len('glances_') :]
|
||||
self.export_name = self.__class__.__module__
|
||||
logger.debug("Init export module %s" % self.export_name)
|
||||
|
||||
# Init the config & args
|
||||
|
|
|
|||
Loading…
Reference in New Issue