summaryrefslogtreecommitdiffstats
path: root/glances/plugins/glances_load.py
diff options
context:
space:
mode:
Diffstat (limited to 'glances/plugins/glances_load.py')
-rw-r--r--glances/plugins/glances_load.py49
1 files changed, 30 insertions, 19 deletions
diff --git a/glances/plugins/glances_load.py b/glances/plugins/glances_load.py
index 4b6a7a14..22a3cd04 100644
--- a/glances/plugins/glances_load.py
+++ b/glances/plugins/glances_load.py
@@ -23,6 +23,7 @@
import os
# Import Glances libs
+from glances.core.glances_globals import logger
from glances.plugins.glances_core import Plugin as CorePlugin
from glances.plugins.glances_plugin import GlancesPlugin
@@ -34,6 +35,13 @@ snmp_oid = {'min1': '1.3.6.1.4.1.2021.10.1.3.1',
'min5': '1.3.6.1.4.1.2021.10.1.3.2',
'min15': '1.3.6.1.4.1.2021.10.1.3.3'}
+# 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'},
+ {'name': 'min5', 'color': '#0000AA'},
+ {'name': 'min15', 'color': '#000044'}]
+
class Plugin(GlancesPlugin):
@@ -44,20 +52,20 @@ class Plugin(GlancesPlugin):
def __init__(self, args=None):
"""Init the plugin."""
- GlancesPlugin.__init__(self, args=args)
+ 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
- # Set the message position
- # It is NOT the curse position but the Glances column/line
- # Enter -1 to right align
- self.column_curse = 1
- # Enter -1 to diplay bottom
- self.line_curse = 1
# Init stats
self.reset()
+ # Call CorePlugin in order to display the core number
+ try:
+ self.nb_log_core = CorePlugin(args=self.args).update()["log"]
+ except Exception:
+ self.nb_log_core = 0
+
def reset(self):
"""Reset/init the stats."""
self.stats = {}
@@ -67,12 +75,6 @@ class Plugin(GlancesPlugin):
# Reset stats
self.reset()
- # Call CorePlugin in order to display the core number
- try:
- nb_log_core = CorePlugin().update()["log"]
- except Exception:
- nb_log_core = 0
-
if self.get_input() == 'local':
# Update stats using the standard system lib
@@ -85,19 +87,28 @@ class Plugin(GlancesPlugin):
self.stats = {'min1': load[0],
'min5': load[1],
'min15': load[2],
- 'cpucore': nb_log_core}
+ 'cpucore': self.nb_log_core}
elif self.get_input() == 'snmp':
# Update stats using SNMP
self.stats = self.set_stats_snmp(snmp_oid=snmp_oid)
- self.stats['cpucore'] = nb_log_core
-
if self.stats['min1'] == '':
self.reset()
return self.stats
- for key in self.stats.iterkeys():
- self.stats[key] = float(self.stats[key])
+ # Python 3 return a dict like:
+ # {'min1': "b'0.08'", 'min5': "b'0.12'", 'min15': "b'0.15'"}
+ try:
+ iteritems = self.stats.iteritems()
+ except AttributeError:
+ iteritems = self.stats.items()
+ for k, v in iteritems:
+ self.stats[k] = float(v)
+
+ self.stats['cpucore'] = self.nb_log_core
+
+ # Update the history list
+ self.update_stats_history()
return self.stats
@@ -116,7 +127,7 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_add_line(msg, "TITLE"))
# Core number
if self.stats['cpucore'] > 0:
- msg = _("{0}-core").format(self.stats['cpucore'], '>1')
+ msg = _("{0:d}-core").format(int(self.stats['cpucore']), '>1')
ret.append(self.curse_add_line(msg))
# New line
ret.append(self.curse_new_line())