diff --git a/glances/exports/glances_history.py b/glances/exports/glances_history.py index 4353f0a0ffec01a153613b8d3a50bcd206fe8520..1df1451e3f7020d0e24035df8114c54308fecfd5 100644 --- a/glances/exports/glances_history.py +++ b/glances/exports/glances_history.py @@ -71,7 +71,7 @@ class GlancesHistory(object): def get_graph_legend(self, item): """Get the item's legend.""" - return item['name'] + return item['description'] def get_graph_yunit(self, item, pre_label=''): """Get the item's Y unit.""" @@ -95,9 +95,12 @@ class GlancesHistory(object): index_all = 0 for p in stats.getAllPlugins(): + # History h = stats.get_plugin(p).get_stats_history() - # Data - if h is None: + # Current plugin item history list + ih = stats.get_plugin(p).get_items_history_list() + # Check if we must process history + if h is None or ih is None: # History (h) not available for plugin (p) continue # Init graph @@ -105,7 +108,7 @@ class GlancesHistory(object): index_graph = 0 handles = [] labels = [] - for i in stats.get_plugin(p).get_items_history_list(): + for i in ih: if i['name'] in iterkeys(h): # The key exist # Add the curves in the current chart diff --git a/glances/plugins/glances_cpu.py b/glances/plugins/glances_cpu.py index 8627682b4bcea89bd9a39e3524cc6c07d74444d3..e4243ac11c764401903458ec47911fecb980ddd9 100644 --- a/glances/plugins/glances_cpu.py +++ b/glances/plugins/glances_cpu.py @@ -46,8 +46,14 @@ snmp_oid = {'default': {'user': '1.3.6.1.4.1.2021.11.9.0', # - 'color' define the graph color in #RGB format # - 'y_unit' define the Y label # All items in this list will be historised if the --enable-history tag is set -items_history_list = [{'name': 'user', 'color': '#00FF00', 'y_unit': '%'}, - {'name': 'system', 'color': '#FF0000', 'y_unit': '%'}] +items_history_list = [{'name': 'user', + 'description': 'User CPU usage', + 'color': '#00FF00', + 'y_unit': '%'}, + {'name': 'system', + 'description': 'System CPU usage', + 'color': '#FF0000', + 'y_unit': '%'}] class Plugin(GlancesPlugin): diff --git a/glances/plugins/glances_diskio.py b/glances/plugins/glances_diskio.py index ffb346f759a5fb75b264a04256948ef3e83983ef..9f006d1fab3aa972657bf418b1af61c31b633449 100644 --- a/glances/plugins/glances_diskio.py +++ b/glances/plugins/glances_diskio.py @@ -30,8 +30,14 @@ import psutil # 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': 'read_bytes', 'color': '#00FF00', 'y_unit': 'B/s'}, - {'name': 'write_bytes', 'color': '#FF0000', 'y_unit': 'B/s'}] +items_history_list = [{'name': 'read_bytes', + 'description': 'Bytes read per second', + 'color': '#00FF00', + 'y_unit': 'B/s'}, + {'name': 'write_bytes', + 'description': 'Bytes write per second', + 'color': '#FF0000', + 'y_unit': 'B/s'}] class Plugin(GlancesPlugin): diff --git a/glances/plugins/glances_fs.py b/glances/plugins/glances_fs.py index f8e62208ce614b7eef41a87ba789cab4ba113183..baa7091f30d81c79ec2acbcfaeb4a12133d85f6b 100644 --- a/glances/plugins/glances_fs.py +++ b/glances/plugins/glances_fs.py @@ -59,7 +59,9 @@ snmp_oid['esxi'] = snmp_oid['windows'] # 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': 'percent', 'color': '#00FF00'}] +items_history_list = [{'name': 'percent', + 'description': 'File system usage in percent', + 'color': '#00FF00'}] class Plugin(GlancesPlugin): diff --git a/glances/plugins/glances_load.py b/glances/plugins/glances_load.py index b038833830919cfe5693769b4fc156a7139490e0..de8050007344168f63897e65143ea66ec2bc64fe 100644 --- a/glances/plugins/glances_load.py +++ b/glances/plugins/glances_load.py @@ -36,9 +36,15 @@ snmp_oid = {'min1': '1.3.6.1.4.1.2021.10.1.3.1', # 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'}] +items_history_list = [{'name': 'min1', + 'description': '1 minute load', + 'color': '#0000FF'}, + {'name': 'min5', + 'description': '5 minutes load', + 'color': '#0000AA'}, + {'name': 'min15', + 'description': '15 minutes load', + 'color': '#000044'}] class Plugin(GlancesPlugin): diff --git a/glances/plugins/glances_mem.py b/glances/plugins/glances_mem.py index 050c5b8ddc1b15f7a911c9033eaae180c0f94982..f82cf29f848215c91682c8f6c1980ff1df6a7343 100644 --- a/glances/plugins/glances_mem.py +++ b/glances/plugins/glances_mem.py @@ -49,7 +49,10 @@ snmp_oid = {'default': {'total': '1.3.6.1.4.1.2021.4.5.0', # 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': 'percent', 'color': '#00FF00', 'y_unit': '%'}] +items_history_list = [{'name': 'percent', + 'description': 'RAM memory usage', + 'color': '#00FF00', + 'y_unit': '%'}] class Plugin(GlancesPlugin): diff --git a/glances/plugins/glances_memswap.py b/glances/plugins/glances_memswap.py index 7343ff6bbd4e975a51c16aa6b9d22f869a0f35d7..4e94c3bd7571d3e4d51f101f326fbf3e9a8ea2e6 100644 --- a/glances/plugins/glances_memswap.py +++ b/glances/plugins/glances_memswap.py @@ -37,7 +37,10 @@ snmp_oid = {'default': {'total': '1.3.6.1.4.1.2021.4.3.0', # 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': 'percent', 'color': '#00FF00', 'y_unit': '%'}] +items_history_list = [{'name': 'percent', + 'description': 'Swap memory usage', + 'color': '#00FF00', + 'y_unit': '%'}] class Plugin(GlancesPlugin): diff --git a/glances/plugins/glances_network.py b/glances/plugins/glances_network.py index 68a8f7cb8976b003ba1217ad99150ea3c4d63a58..1820e53356d346b5443fa362133ab889f8d08aef 100644 --- a/glances/plugins/glances_network.py +++ b/glances/plugins/glances_network.py @@ -37,8 +37,14 @@ snmp_oid = {'default': {'interface_name': '1.3.6.1.2.1.2.2.1.2', # 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': 'rx', 'color': '#00FF00', 'y_unit': 'bit/s'}, - {'name': 'tx', 'color': '#FF0000', 'y_unit': 'bit/s'}] +items_history_list = [{'name': 'rx', + 'description': 'Download rate per second', + 'color': '#00FF00', + 'y_unit': 'bit/s'}, + {'name': 'tx', + 'description': 'Upload rate per second', + 'color': '#FF0000', + 'y_unit': 'bit/s'}] class Plugin(GlancesPlugin): diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py index 81858ba9221f25f712b5a7f7de206dc5835e7dc9..303b63d1a2309c6d6c351ca3b7b41490b05f6bcc 100644 --- a/glances/plugins/glances_plugin.py +++ b/glances/plugins/glances_plugin.py @@ -30,6 +30,7 @@ from operator import itemgetter from glances.compat import iterkeys, itervalues, listkeys, map from glances.actions import GlancesActions +from glances.attribute import GlancesAttribute from glances.logger import logger from glances.logs import glances_logs @@ -86,34 +87,39 @@ class GlancesPlugin(object): """Return the key of the list.""" return None - def add_item_history(self, key, value): + def add_item_history(self, key, value, + description='', + history_max_size=None, + is_rate=False): """Add an new item (key, value) to the current history.""" - try: - self.stats_history[key].append(value) - except KeyError: - self.stats_history[key] = [value] + if key not in self.stats_history: + self.stats_history[key] = GlancesAttribute(key, + description=description, + history_max_size=history_max_size) + self.stats_history[key].value = value def init_stats_history(self): - """Init the stats history (dict of list).""" - ret = None + """Init the stats history (dict of GlancesAttribute).""" + ret = {} if self.args is not None and self.args.enable_history and self.get_items_history_list() is not None: - init_list = [i['name'] for i in self.get_items_history_list()] + init_list = [a['name'] for a in self.get_items_history_list()] logger.debug("Stats history activated for plugin {0} (items: {1})".format(self.plugin_name, init_list)) - ret = {} return ret def reset_stats_history(self): - """Reset the stats history (dict of list).""" + """Reset the stats history (dict of GlancesAttribute).""" if self.args is not None and self.args.enable_history and self.get_items_history_list() is not None: - reset_list = [i['name'] for i in self.get_items_history_list()] + reset_list = [a['name'] for a in self.get_items_history_list()] logger.debug("Reset history for plugin {0} (items: {1})".format(self.plugin_name, reset_list)) - self.stats_history = {} + for a in self.stats_history: + self.stats_history[a].history_reset() def update_stats_history(self, item_name=''): """Update stats history.""" if (self.stats and self.args is not None and self.args.enable_history and self.get_items_history_list() is not None): + # TODO in attribute ? self.add_item_history('date', datetime.now()) for i in self.get_items_history_list(): if isinstance(self.stats, list): @@ -122,18 +128,24 @@ class GlancesPlugin(object): # interface) for l in self.stats: self.add_item_history( - l[item_name] + '_' + i['name'], l[i['name']]) + l[item_name] + '_' + i['name'], + l[i['name']], + description=i['description'], + history_max_size=None) else: # Stats is not a list # Add the item to the history directly - self.add_item_history(i['name'], self.stats[i['name']]) + self.add_item_history(i['name'], + self.stats[i['name']], + description=i['description'], + history_max_size=None) def get_stats_history(self): - """Return the stats history.""" - return self.stats_history + """Return the stats history (dict of list).""" + return {i: self.stats_history[i].history for i in self.stats_history} def get_items_history_list(self): - """Return the items history list.""" + """Return the items history list (define inside the plugins scripts).""" return self.items_history_list @property