提交 396f3acf 编写于 作者: N nicolargo

Add new attribute class. Only for history for the moment

上级 42d45c29
...@@ -71,7 +71,7 @@ class GlancesHistory(object): ...@@ -71,7 +71,7 @@ class GlancesHistory(object):
def get_graph_legend(self, item): def get_graph_legend(self, item):
"""Get the item's legend.""" """Get the item's legend."""
return item['name'] return item['description']
def get_graph_yunit(self, item, pre_label=''): def get_graph_yunit(self, item, pre_label=''):
"""Get the item's Y unit.""" """Get the item's Y unit."""
...@@ -95,9 +95,12 @@ class GlancesHistory(object): ...@@ -95,9 +95,12 @@ class GlancesHistory(object):
index_all = 0 index_all = 0
for p in stats.getAllPlugins(): for p in stats.getAllPlugins():
# History
h = stats.get_plugin(p).get_stats_history() h = stats.get_plugin(p).get_stats_history()
# Data # Current plugin item history list
if h is None: 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) # History (h) not available for plugin (p)
continue continue
# Init graph # Init graph
...@@ -105,7 +108,7 @@ class GlancesHistory(object): ...@@ -105,7 +108,7 @@ class GlancesHistory(object):
index_graph = 0 index_graph = 0
handles = [] handles = []
labels = [] labels = []
for i in stats.get_plugin(p).get_items_history_list(): for i in ih:
if i['name'] in iterkeys(h): if i['name'] in iterkeys(h):
# The key exist # The key exist
# Add the curves in the current chart # Add the curves in the current chart
......
...@@ -46,8 +46,14 @@ snmp_oid = {'default': {'user': '1.3.6.1.4.1.2021.11.9.0', ...@@ -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 # - 'color' define the graph color in #RGB format
# - 'y_unit' define the Y label # - 'y_unit' define the Y label
# All items in this list will be historised if the --enable-history tag is set # All items in this list will be historised if the --enable-history tag is set
items_history_list = [{'name': 'user', 'color': '#00FF00', 'y_unit': '%'}, items_history_list = [{'name': 'user',
{'name': 'system', 'color': '#FF0000', 'y_unit': '%'}] 'description': 'User CPU usage',
'color': '#00FF00',
'y_unit': '%'},
{'name': 'system',
'description': 'System CPU usage',
'color': '#FF0000',
'y_unit': '%'}]
class Plugin(GlancesPlugin): class Plugin(GlancesPlugin):
......
...@@ -30,8 +30,14 @@ import psutil ...@@ -30,8 +30,14 @@ import psutil
# Define the history items list # Define the history items list
# All items in this list will be historised if the --enable-history tag is set # All items in this list will be historised if the --enable-history tag is set
# 'color' define the graph color in #RGB format # 'color' define the graph color in #RGB format
items_history_list = [{'name': 'read_bytes', 'color': '#00FF00', 'y_unit': 'B/s'}, items_history_list = [{'name': 'read_bytes',
{'name': 'write_bytes', 'color': '#FF0000', 'y_unit': 'B/s'}] '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): class Plugin(GlancesPlugin):
......
...@@ -59,7 +59,9 @@ snmp_oid['esxi'] = snmp_oid['windows'] ...@@ -59,7 +59,9 @@ snmp_oid['esxi'] = snmp_oid['windows']
# Define the history items list # Define the history items list
# All items in this list will be historised if the --enable-history tag is set # All items in this list will be historised if the --enable-history tag is set
# 'color' define the graph color in #RGB format # '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): class Plugin(GlancesPlugin):
......
...@@ -36,9 +36,15 @@ snmp_oid = {'min1': '1.3.6.1.4.1.2021.10.1.3.1', ...@@ -36,9 +36,15 @@ snmp_oid = {'min1': '1.3.6.1.4.1.2021.10.1.3.1',
# Define the history items list # Define the history items list
# All items in this list will be historised if the --enable-history tag is set # All items in this list will be historised if the --enable-history tag is set
# 'color' define the graph color in #RGB format # 'color' define the graph color in #RGB format
items_history_list = [{'name': 'min1', 'color': '#0000FF'}, items_history_list = [{'name': 'min1',
{'name': 'min5', 'color': '#0000AA'}, 'description': '1 minute load',
{'name': 'min15', 'color': '#000044'}] 'color': '#0000FF'},
{'name': 'min5',
'description': '5 minutes load',
'color': '#0000AA'},
{'name': 'min15',
'description': '15 minutes load',
'color': '#000044'}]
class Plugin(GlancesPlugin): class Plugin(GlancesPlugin):
......
...@@ -49,7 +49,10 @@ snmp_oid = {'default': {'total': '1.3.6.1.4.1.2021.4.5.0', ...@@ -49,7 +49,10 @@ snmp_oid = {'default': {'total': '1.3.6.1.4.1.2021.4.5.0',
# Define the history items list # Define the history items list
# All items in this list will be historised if the --enable-history tag is set # All items in this list will be historised if the --enable-history tag is set
# 'color' define the graph color in #RGB format # '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): class Plugin(GlancesPlugin):
......
...@@ -37,7 +37,10 @@ snmp_oid = {'default': {'total': '1.3.6.1.4.1.2021.4.3.0', ...@@ -37,7 +37,10 @@ snmp_oid = {'default': {'total': '1.3.6.1.4.1.2021.4.3.0',
# Define the history items list # Define the history items list
# All items in this list will be historised if the --enable-history tag is set # All items in this list will be historised if the --enable-history tag is set
# 'color' define the graph color in #RGB format # '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): class Plugin(GlancesPlugin):
......
...@@ -37,8 +37,14 @@ snmp_oid = {'default': {'interface_name': '1.3.6.1.2.1.2.2.1.2', ...@@ -37,8 +37,14 @@ snmp_oid = {'default': {'interface_name': '1.3.6.1.2.1.2.2.1.2',
# Define the history items list # Define the history items list
# All items in this list will be historised if the --enable-history tag is set # All items in this list will be historised if the --enable-history tag is set
# 'color' define the graph color in #RGB format # 'color' define the graph color in #RGB format
items_history_list = [{'name': 'rx', 'color': '#00FF00', 'y_unit': 'bit/s'}, items_history_list = [{'name': 'rx',
{'name': 'tx', 'color': '#FF0000', 'y_unit': 'bit/s'}] '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): class Plugin(GlancesPlugin):
......
...@@ -30,6 +30,7 @@ from operator import itemgetter ...@@ -30,6 +30,7 @@ from operator import itemgetter
from glances.compat import iterkeys, itervalues, listkeys, map from glances.compat import iterkeys, itervalues, listkeys, map
from glances.actions import GlancesActions from glances.actions import GlancesActions
from glances.attribute import GlancesAttribute
from glances.logger import logger from glances.logger import logger
from glances.logs import glances_logs from glances.logs import glances_logs
...@@ -86,34 +87,39 @@ class GlancesPlugin(object): ...@@ -86,34 +87,39 @@ class GlancesPlugin(object):
"""Return the key of the list.""" """Return the key of the list."""
return None 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.""" """Add an new item (key, value) to the current history."""
try: if key not in self.stats_history:
self.stats_history[key].append(value) self.stats_history[key] = GlancesAttribute(key,
except KeyError: description=description,
self.stats_history[key] = [value] history_max_size=history_max_size)
self.stats_history[key].value = value
def init_stats_history(self): def init_stats_history(self):
"""Init the stats history (dict of list).""" """Init the stats history (dict of GlancesAttribute)."""
ret = None ret = {}
if self.args is not None and self.args.enable_history and self.get_items_history_list() is not None: 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)) logger.debug("Stats history activated for plugin {0} (items: {1})".format(self.plugin_name, init_list))
ret = {}
return ret return ret
def reset_stats_history(self): 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: 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)) 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=''): def update_stats_history(self, item_name=''):
"""Update stats history.""" """Update stats history."""
if (self.stats and self.args is not None and if (self.stats and self.args is not None and
self.args.enable_history and self.args.enable_history and
self.get_items_history_list() is not None): self.get_items_history_list() is not None):
# TODO in attribute ?
self.add_item_history('date', datetime.now()) self.add_item_history('date', datetime.now())
for i in self.get_items_history_list(): for i in self.get_items_history_list():
if isinstance(self.stats, list): if isinstance(self.stats, list):
...@@ -122,18 +128,24 @@ class GlancesPlugin(object): ...@@ -122,18 +128,24 @@ class GlancesPlugin(object):
# interface) # interface)
for l in self.stats: for l in self.stats:
self.add_item_history( 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: else:
# Stats is not a list # Stats is not a list
# Add the item to the history directly # 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): def get_stats_history(self):
"""Return the stats history.""" """Return the stats history (dict of list)."""
return self.stats_history return {i: self.stats_history[i].history for i in self.stats_history}
def get_items_history_list(self): 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 return self.items_history_list
@property @property
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册