Version to be tested. All feature are implemented. Documentation to be done.

This commit is contained in:
nicolargo 2019-03-31 18:27:03 +02:00
parent 20ca58d5a4
commit a35a7d547b
5 changed files with 28 additions and 11 deletions

1
NEWS
View File

@ -7,6 +7,7 @@ Version 3.1.1
Enhancements and new features:
* Please add some sparklines! #1446
* Add authprovider for cassandra export (thanks to @EmilienMottet) #1395
* Curses's browser server list sorting added (thanks to @limfreee) #1396
* ElasticSearch: add date to index, unbreak object push (thanks to @genevera) # 1438

View File

@ -240,6 +240,8 @@ Examples of use:
dest='fahrenheit', help='display temperature in Fahrenheit (default is Celsius)')
parser.add_argument('--fs-free-space', action='store_true', default=False,
dest='fs_free_space', help='display FS free space instead of used')
parser.add_argument('--sparkline', action='store_true', default=False,
dest='sparkline', help='displat sparklines instead of bar in the curses interface')
parser.add_argument('--theme-white', action='store_true', default=False,
dest='theme_white', help='optimize display colors for white background')
# Globals options

View File

@ -73,6 +73,7 @@ class _GlancesCurses(object):
'Q': {'switch': 'enable_irq'},
'R': {'switch': 'disable_raid'},
's': {'switch': 'disable_sensors'},
'S': {'switch': 'sparkline'},
'T': {'switch': 'network_sum'},
'U': {'switch': 'network_cumul'},
'W': {'switch': 'disable_wifi'},

View File

@ -149,19 +149,19 @@ class GlancesPlugin(object):
except UnicodeDecodeError:
return json.dumps(d, ensure_ascii=False)
def _history_enable(self):
def history_enable(self):
return self.args is not None and not self.args.disable_history and self.get_items_history_list() is not None
def init_stats_history(self):
"""Init the stats history (dict of GlancesAttribute)."""
if self._history_enable():
if self.history_enable():
init_list = [a['name'] for a in self.get_items_history_list()]
logger.debug("Stats history activated for plugin {} (items: {})".format(self.plugin_name, init_list))
return GlancesHistory()
def reset_stats_history(self):
"""Reset the stats history (dict of GlancesAttribute)."""
if self._history_enable():
if self.history_enable():
reset_list = [a['name'] for a in self.get_items_history_list()]
logger.debug("Reset history for plugin {} (items: {})".format(self.plugin_name, reset_list))
self.stats_history.reset()
@ -174,7 +174,7 @@ class GlancesPlugin(object):
else:
item_name = self.get_key()
# Build the history
if self.get_export() and self._history_enable():
if self.get_export() and self.history_enable():
for i in self.get_items_history_list():
if isinstance(self.get_export(), list):
# Stats is a list of data

View File

@ -43,6 +43,9 @@ else:
items_history_list = [{'name': 'cpu',
'description': 'CPU percent usage',
'y_unit': '%'},
{'name': 'percpu',
'description': 'PERCPU percent usage',
'y_unit': '%'},
{'name': 'mem',
'description': 'MEM percent usage',
'y_unit': '%'},
@ -120,10 +123,11 @@ class Plugin(GlancesPlugin):
if not self.stats or self.is_disable():
return ret
# Define the data (Sparkline or Bar)
# Sparkline is the default behavor (see https://github.com/nicolargo/glances/issues/1446)
data = Sparkline(max_width)
sparkline_tag = data.available
# Define the data: Bar (default behavor) or Sparkline
sparkline_tag = False
if self.args.sparkline and self.history_enable():
data = Sparkline(max_width)
sparkline_tag = data.available
if not sparkline_tag:
# Fallback to bar if Sparkline module is not installed
data = Bar(max_width)
@ -139,13 +143,22 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_new_line())
for key in ['cpu', 'mem', 'swap']:
if key == 'cpu' and args.percpu:
for cpu in self.stats['percpu']:
bar.percent = cpu['total']
if sparkline_tag:
raw_cpu = self.get_raw_history(item='percpu', nb=data.size)
for cpu_index, cpu in enumerate(self.stats['percpu']):
if sparkline_tag:
# Sparkline display an history
data.percents = [i[1][cpu_index]['total'] for i in raw_cpu]
# A simple padding in order to align metrics to the right
data.percents += [None] * (data.size - len(data.percents))
else:
# Bar only the last value
data.percent = cpu['total']
if cpu[cpu['key']] < 10:
msg = '{:3}{} '.format(key.upper(), cpu['cpu_number'])
else:
msg = '{:4} '.format(cpu['cpu_number'])
ret.extend(self._msg_create_line(msg, bar, key))
ret.extend(self._msg_create_line(msg, data, key))
ret.append(self.curse_new_line())
else:
if sparkline_tag: