summaryrefslogtreecommitdiffstats
path: root/glances/core/glances_stats.py
diff options
context:
space:
mode:
Diffstat (limited to 'glances/core/glances_stats.py')
-rw-r--r--glances/core/glances_stats.py45
1 files changed, 26 insertions, 19 deletions
diff --git a/glances/core/glances_stats.py b/glances/core/glances_stats.py
index 8b92334f..1f039eb6 100644
--- a/glances/core/glances_stats.py
+++ b/glances/core/glances_stats.py
@@ -25,7 +25,7 @@ import re
import sys
import threading
-from glances.core.glances_globals import plugins_path, exports_path, sys_path
+from glances.core.glances_globals import exports_path, plugins_path, sys_path
from glances.core.glances_logging import logger
# SNMP OID regexp pattern to short system name dict
@@ -152,13 +152,17 @@ class GlancesStats(object):
# For standalone and server modes
# For each plugins, call the update method
for p in self._plugins:
- # logger.debug("Update %s stats" % p)
+ # logger.debug("Update %s stats" % p)
self._plugins[p].update()
- def export(self, input_stats={}):
+ def export(self, input_stats=None):
"""Export all the stats.
- Each export module is ran in a dedicated thread."""
+
+ Each export module is ran in a dedicated thread.
+ """
# threads = []
+ input_stats = input_stats or {}
+
for e in self._exports:
logger.debug("Export stats using the %s module" % e)
thread = threading.Thread(target=self._exports[e].update,
@@ -167,11 +171,11 @@ class GlancesStats(object):
thread.start()
def getAll(self):
- """Return all the stats (list)"""
+ """Return all the stats (list)."""
return [self._plugins[p].get_raw() for p in self._plugins]
def getAllAsDict(self):
- """Return all the stats (dict)"""
+ """Return all the stats (dict)."""
# Python > 2.6
# {p: self._plugins[p].get_raw() for p in self._plugins}
ret = {}
@@ -181,21 +185,21 @@ class GlancesStats(object):
def getAllLimits(self):
"""Return the plugins limits list."""
- return [self._plugins[p].get_limits() for p in self._plugins]
+ return [self._plugins[p].limits for p in self._plugins]
def getAllLimitsAsDict(self):
- """Return all the stats limits (dict)"""
+ """Return all the stats limits (dict)."""
ret = {}
for p in self._plugins:
- ret[p] = self._plugins[p].get_limits()
+ ret[p] = self._plugins[p].limits
return ret
def getAllViews(self):
- """Return the plugins views"""
+ """Return the plugins views."""
return [self._plugins[p].get_views() for p in self._plugins]
def getAllViewsAsDict(self):
- """Return all the stats views (dict)"""
+ """Return all the stats views (dict)."""
ret = {}
for p in self._plugins:
ret[p] = self._plugins[p].get_views()
@@ -203,7 +207,7 @@ class GlancesStats(object):
def get_plugin_list(self):
"""Return the plugin list."""
- self._plugins
+ return self._plugins
def get_plugin(self, plugin_name):
"""Return the plugin name."""
@@ -213,7 +217,7 @@ class GlancesStats(object):
return None
def end(self):
- """End of the Glances stats"""
+ """End of the Glances stats."""
# Close the export module
for e in self._exports:
self._exports[e].exit()
@@ -231,8 +235,10 @@ class GlancesStatsServer(GlancesStats):
# all_stats is a dict of dicts filled by the server
self.all_stats = collections.defaultdict(dict)
- def update(self, input_stats={}):
+ def update(self, input_stats=None):
"""Update the stats."""
+ input_stats = input_stats or {}
+
# Force update of all the stats
GlancesStats.update(self)
@@ -240,7 +246,7 @@ class GlancesStatsServer(GlancesStats):
self.all_stats = self._set_stats(input_stats)
def _set_stats(self, input_stats):
- """Set the stats to the input_stats one"""
+ """Set the stats to the input_stats one."""
# Build the all_stats with the get_raw() method of the plugins
ret = collections.defaultdict(dict)
for p in self._plugins:
@@ -248,11 +254,11 @@ class GlancesStatsServer(GlancesStats):
return ret
def getAll(self):
- """Return the stats as a list"""
+ """Return the stats as a list."""
return self.all_stats
def getAllAsDict(self):
- """Return the stats as a dict"""
+ """Return the stats as a dict."""
# Python > 2.6
# return {p: self.all_stats[p] for p in self._plugins}
ret = {}
@@ -359,7 +365,7 @@ class GlancesStatsClientSNMP(GlancesStats):
return ret
def get_system_name(self, oid_system_name):
- """Get the short os name from the OS name OID string"""
+ """Get the short os name from the OS name OID string."""
short_system_name = None
if oid_system_name == '':
@@ -383,7 +389,8 @@ class GlancesStatsClientSNMP(GlancesStats):
# For each plugins, call the update method
for p in self._plugins:
# Set the input method to SNMP
- self._plugins[p].set_input('snmp', self.system_name)
+ self._plugins[p].input_method = 'snmp'
+ self._plugins[p].short_system_name = self.system_name
try:
self._plugins[p].update()
except Exception as e: