Glances client can export stats grabbed from the server

This commit is contained in:
Nicolargo 2014-12-28 23:29:40 +01:00
parent 751fb8948c
commit a7c12763d7
2 changed files with 22 additions and 3 deletions

View File

@ -136,7 +136,7 @@ class GlancesClient(object):
if self.get_mode() == 'glances' and version.split('.')[0] == client_version.split('.')[0]:
# Init stats
self.stats = GlancesStatsClient()
self.stats = GlancesStatsClient(config=self.config, args=self.args)
self.stats.set_plugins(json.loads(self.client.getAllPlugins()))
logger.debug(
"Client version: %s / Server version: %s" % (version, client_version))
@ -153,7 +153,7 @@ class GlancesClient(object):
from glances.core.glances_stats import GlancesStatsClientSNMP
# Init stats
self.stats = GlancesStatsClientSNMP(args=self.args)
self.stats = GlancesStatsClientSNMP(config=self.config, args=self.args)
if not self.stats.check_snmp():
self.log_and_exit("Connection to SNMP server failed")
@ -234,6 +234,9 @@ class GlancesClient(object):
cs_status=cs_status,
return_to_browser=self.return_to_browser)
# Export stats using export modules
self.stats.export(self.stats)
return self.get_mode()
def end(self):

View File

@ -252,11 +252,22 @@ class GlancesStatsClient(GlancesStats):
"""This class stores, updates and gives stats for the client."""
def __init__(self):
def __init__(self, config=None, args=None):
"""Init the GlancesStatsClient class."""
# Init the plugin list dict
self._plugins = collections.defaultdict(dict)
# Init the configuration
self.config = config
# Init the arguments
self.args = args
# Init the export modules list dict
self._exports = collections.defaultdict(dict)
# Load the plugins
self.load_exports(args=args)
def set_plugins(self, input_plugins):
"""Set the plugin list according to the Glances server."""
header = "glances_"
@ -293,6 +304,11 @@ class GlancesStatsClientSNMP(GlancesStats):
# Load plugins
self.load_plugins(args=self.args)
# Init the export modules list dict
self._exports = collections.defaultdict(dict)
# Load the plugins
self.load_exports(args=args)
def check_snmp(self):
"""Chek if SNMP is available on the server."""
# Import the SNMP client class