mirror of
https://github.com/nicolargo/glances.git
synced 2025-01-07 02:20:26 +03:00
Make the Quicklook stats list configurable (TODO on the WebUI)
This commit is contained in:
parent
e564c21b89
commit
5092475d7f
@ -45,8 +45,11 @@ max_processes_display=25
|
|||||||
# Set to true to disable a plugin
|
# Set to true to disable a plugin
|
||||||
# Note: you can also disable it from the command line (see --disable-plugin <plugin_name>)
|
# Note: you can also disable it from the command line (see --disable-plugin <plugin_name>)
|
||||||
disable=False
|
disable=False
|
||||||
# Graphical percentage char used in the terminal user interface (default is |)
|
# Stats list (default is cpu,mem,load)
|
||||||
percentage_char=|
|
# Available stats are: cpu,mem,load,swap
|
||||||
|
list=cpu,mem,load
|
||||||
|
# Graphical bar char used in the terminal user interface (default is |)
|
||||||
|
bar_char=|
|
||||||
# Define CPU, MEM and SWAP thresholds in %
|
# Define CPU, MEM and SWAP thresholds in %
|
||||||
cpu_careful=50
|
cpu_careful=50
|
||||||
cpu_warning=70
|
cpu_warning=70
|
||||||
@ -58,6 +61,7 @@ swap_careful=50
|
|||||||
swap_warning=70
|
swap_warning=70
|
||||||
swap_critical=90
|
swap_critical=90
|
||||||
# Source: http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages
|
# Source: http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages
|
||||||
|
# With 1 CPU core, the load should be lower than 1.00 (100%)
|
||||||
load_careful=70
|
load_careful=70
|
||||||
load_warning=100
|
load_warning=100
|
||||||
load_critical=500
|
load_critical=500
|
||||||
|
@ -28,10 +28,14 @@ class Bar(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, size,
|
def __init__(self, size,
|
||||||
percentage_char='|', empty_char=' ', pre_char='[', post_char=']',
|
bar_char='|',
|
||||||
display_value=True, min_value=0, max_value=100):
|
empty_char=' ',
|
||||||
|
pre_char='[', post_char=']',
|
||||||
|
unit_char='%',
|
||||||
|
display_value=True,
|
||||||
|
min_value=0, max_value=100):
|
||||||
# Build curses_bars
|
# Build curses_bars
|
||||||
self.__curses_bars = [empty_char] * 5 + [percentage_char] * 5
|
self.__curses_bars = [empty_char] * 5 + [bar_char] * 5
|
||||||
# Bar size
|
# Bar size
|
||||||
self.__size = size
|
self.__size = size
|
||||||
# Bar current percent
|
# Bar current percent
|
||||||
@ -43,6 +47,8 @@ class Bar(object):
|
|||||||
self.__pre_char = pre_char
|
self.__pre_char = pre_char
|
||||||
self.__post_char = post_char
|
self.__post_char = post_char
|
||||||
self.__empty_char = empty_char
|
self.__empty_char = empty_char
|
||||||
|
self.__unit_char = unit_char
|
||||||
|
# Value should be displayed ?
|
||||||
self.__display_value = display_value
|
self.__display_value = display_value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -82,9 +88,13 @@ class Bar(object):
|
|||||||
ret += self.__empty_char * int(self.size - whole)
|
ret += self.__empty_char * int(self.size - whole)
|
||||||
if self.__display_value:
|
if self.__display_value:
|
||||||
if self.percent > self.max_value:
|
if self.percent > self.max_value:
|
||||||
ret = '{}>{:4.0f}%'.format(ret, self.max_value)
|
ret = '{}>{:4.0f}{}'.format(ret,
|
||||||
|
self.max_value,
|
||||||
|
self.__unit_char)
|
||||||
else:
|
else:
|
||||||
ret = '{}{:5.1f}%'.format(ret, self.percent)
|
ret = '{}{:5.1f}{}'.format(ret,
|
||||||
|
self.percent,
|
||||||
|
self.__unit_char)
|
||||||
if overwrite and len(overwrite) < len(ret) - 6:
|
if overwrite and len(overwrite) < len(ret) - 6:
|
||||||
ret = overwrite + ret[len(overwrite):]
|
ret = overwrite + ret[len(overwrite):]
|
||||||
return ret
|
return ret
|
||||||
|
@ -35,7 +35,8 @@ class Sparkline(object):
|
|||||||
"""Manage sparklines (see https://pypi.org/project/sparklines/)."""
|
"""Manage sparklines (see https://pypi.org/project/sparklines/)."""
|
||||||
|
|
||||||
def __init__(self, size,
|
def __init__(self, size,
|
||||||
pre_char='[', post_char=']', empty_char=' ',
|
pre_char='[', post_char=']',
|
||||||
|
unit_char='%',
|
||||||
display_value=True):
|
display_value=True):
|
||||||
# If the sparklines python module available ?
|
# If the sparklines python module available ?
|
||||||
self.__available = sparklines_module
|
self.__available = sparklines_module
|
||||||
@ -46,7 +47,8 @@ class Sparkline(object):
|
|||||||
# Char used for the decoration
|
# Char used for the decoration
|
||||||
self.__pre_char = pre_char
|
self.__pre_char = pre_char
|
||||||
self.__post_char = post_char
|
self.__post_char = post_char
|
||||||
self.__empty_char = empty_char
|
self.__unit_char = unit_char
|
||||||
|
# Value should be displayed ?
|
||||||
self.__display_value = display_value
|
self.__display_value = display_value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -83,7 +85,9 @@ class Sparkline(object):
|
|||||||
if self.__display_value:
|
if self.__display_value:
|
||||||
percents_without_none = [x for x in self.percents if x is not None]
|
percents_without_none = [x for x in self.percents if x is not None]
|
||||||
if len(percents_without_none) > 0:
|
if len(percents_without_none) > 0:
|
||||||
ret = '{}{:5.1f}%'.format(ret, percents_without_none[-1])
|
ret = '{}{:5.1f}{}'.format(ret,
|
||||||
|
percents_without_none[-1],
|
||||||
|
self.__unit_char)
|
||||||
ret = nativestr(ret)
|
ret = nativestr(ret)
|
||||||
if overwrite and len(overwrite) < len(ret) - 6:
|
if overwrite and len(overwrite) < len(ret) - 6:
|
||||||
ret = overwrite + ret[len(overwrite):]
|
ret = overwrite + ret[len(overwrite):]
|
||||||
|
@ -71,6 +71,9 @@ class PluginModel(GlancesPluginModel):
|
|||||||
'stats' is a dictionary.
|
'stats' is a dictionary.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
AVAILABLE_STATS_LIST = ['cpu', 'mem', 'swap', 'load']
|
||||||
|
DEFAULT_STATS_LIST = ['cpu', 'mem', 'load']
|
||||||
|
|
||||||
def __init__(self, args=None, config=None):
|
def __init__(self, args=None, config=None):
|
||||||
"""Init the quicklook plugin."""
|
"""Init the quicklook plugin."""
|
||||||
super(PluginModel, self).__init__(
|
super(PluginModel, self).__init__(
|
||||||
@ -81,6 +84,12 @@ class PluginModel(GlancesPluginModel):
|
|||||||
# We want to display the stat in the curse interface
|
# We want to display the stat in the curse interface
|
||||||
self.display_curse = True
|
self.display_curse = True
|
||||||
|
|
||||||
|
# Define the stats list
|
||||||
|
self.stats_list = self.get_conf_value('list', default=self.DEFAULT_STATS_LIST)
|
||||||
|
if not set(self.stats_list).issubset(self.AVAILABLE_STATS_LIST):
|
||||||
|
logger.warning('Quicklook plugin: Invalid stats list: {}'.format(self.stats_list))
|
||||||
|
self.stats_list = self.AVAILABLE_STATS_LIST
|
||||||
|
|
||||||
@GlancesPluginModel._check_decorator
|
@GlancesPluginModel._check_decorator
|
||||||
@GlancesPluginModel._log_result_decorator
|
@GlancesPluginModel._log_result_decorator
|
||||||
def update(self):
|
def update(self):
|
||||||
@ -115,7 +124,7 @@ class PluginModel(GlancesPluginModel):
|
|||||||
stats['cpucore'] = get_nb_log_core()
|
stats['cpucore'] = get_nb_log_core()
|
||||||
try:
|
try:
|
||||||
# Load average is a tuple (1 min, 5 min, 15 min)
|
# Load average is a tuple (1 min, 5 min, 15 min)
|
||||||
# Process only the 15 min value
|
# Process only the 15 min value (index 2)
|
||||||
stats['load'] = get_load_average(percent=True)[2]
|
stats['load'] = get_load_average(percent=True)[2]
|
||||||
except (TypeError, IndexError):
|
except (TypeError, IndexError):
|
||||||
stats['load'] = None
|
stats['load'] = None
|
||||||
@ -135,7 +144,7 @@ class PluginModel(GlancesPluginModel):
|
|||||||
super(PluginModel, self).update_views()
|
super(PluginModel, self).update_views()
|
||||||
|
|
||||||
# Alert for CPU, MEM and SWAP
|
# Alert for CPU, MEM and SWAP
|
||||||
for key in ['cpu', 'mem', 'swap']:
|
for key in self.stats_list:
|
||||||
if key in self.stats:
|
if key in self.stats:
|
||||||
self.views[key]['decoration'] = self.get_alert(self.stats[key], header=key)
|
self.views[key]['decoration'] = self.get_alert(self.stats[key], header=key)
|
||||||
|
|
||||||
@ -159,14 +168,14 @@ class PluginModel(GlancesPluginModel):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
# Define the data: Bar (default behavior) or Sparkline
|
# Define the data: Bar (default behavior) or Sparkline
|
||||||
sparkline_tag = False
|
data = dict()
|
||||||
if self.args.sparkline and self.history_enable() and not self.args.client:
|
for key in self.stats_list:
|
||||||
data = Sparkline(max_width)
|
if self.args.sparkline and self.history_enable() and not self.args.client:
|
||||||
sparkline_tag = data.available
|
data[key] = Sparkline(max_width)
|
||||||
if not sparkline_tag:
|
else:
|
||||||
# Fallback to bar if Sparkline module is not installed
|
# Fallback to bar if Sparkline module is not installed
|
||||||
data = Bar(max_width,
|
data[key] = Bar(max_width,
|
||||||
percentage_char=self.get_conf_value('percentage_char', default=['|'])[0])
|
bar_char=self.get_conf_value('bar_char', default=['|'])[0])
|
||||||
|
|
||||||
# Build the string message
|
# Build the string message
|
||||||
##########################
|
##########################
|
||||||
@ -186,36 +195,36 @@ class PluginModel(GlancesPluginModel):
|
|||||||
ret.append(self.curse_new_line())
|
ret.append(self.curse_new_line())
|
||||||
|
|
||||||
# Loop over CPU, MEM and LOAD
|
# Loop over CPU, MEM and LOAD
|
||||||
for key in ['cpu', 'mem', 'load']:
|
for key in self.stats_list:
|
||||||
if key == 'cpu' and args.percpu:
|
if key == 'cpu' and args.percpu:
|
||||||
if sparkline_tag:
|
if type(data[key]).__name__ == 'Sparkline':
|
||||||
raw_cpu = self.get_raw_history(item='percpu', nb=data.size)
|
raw_cpu = self.get_raw_history(item='percpu', nb=data[key].size)
|
||||||
for cpu_index, cpu in enumerate(self.stats['percpu']):
|
for cpu_index, cpu in enumerate(self.stats['percpu']):
|
||||||
if sparkline_tag:
|
if type(data[key]).__name__ == 'Sparkline':
|
||||||
# Sparkline display an history
|
# Sparkline display an history
|
||||||
data.percents = [i[1][cpu_index]['total'] for i in raw_cpu]
|
data[key].percents = [i[1][cpu_index]['total'] for i in raw_cpu]
|
||||||
# A simple padding in order to align metrics to the right
|
# A simple padding in order to align metrics to the right
|
||||||
data.percents += [None] * (data.size - len(data.percents))
|
data[key].percents += [None] * (data[key].size - len(data[key].percents))
|
||||||
else:
|
else:
|
||||||
# Bar only the last value
|
# Bar only the last value
|
||||||
data.percent = cpu['total']
|
data[key].percent = cpu['total']
|
||||||
if cpu[cpu['key']] < 10:
|
if cpu[cpu['key']] < 10:
|
||||||
msg = '{:3}{} '.format(key.upper(), cpu['cpu_number'])
|
msg = '{:3}{} '.format(key.upper(), cpu['cpu_number'])
|
||||||
else:
|
else:
|
||||||
msg = '{:4} '.format(cpu['cpu_number'])
|
msg = '{:4} '.format(cpu['cpu_number'])
|
||||||
ret.extend(self._msg_create_line(msg, data, key))
|
ret.extend(self._msg_create_line(msg, data[key], key))
|
||||||
ret.append(self.curse_new_line())
|
ret.append(self.curse_new_line())
|
||||||
else:
|
else:
|
||||||
if sparkline_tag:
|
if type(data[key]).__name__ == 'Sparkline':
|
||||||
# Sparkline display an history
|
# Sparkline display an history
|
||||||
data.percents = [i[1] for i in self.get_raw_history(item=key, nb=data.size)]
|
data[key].percents = [i[1] for i in self.get_raw_history(item=key, nb=data[key].size)]
|
||||||
# A simple padding in order to align metrics to the right
|
# A simple padding in order to align metrics to the right
|
||||||
data.percents += [None] * (data.size - len(data.percents))
|
data[key].percents += [None] * (data[key].size - len(data[key].percents))
|
||||||
else:
|
else:
|
||||||
# Bar only the last value
|
# Bar only the last value
|
||||||
data.percent = self.stats[key]
|
data[key].percent = self.stats[key]
|
||||||
msg = '{:4} '.format(key.upper())
|
msg = '{:4} '.format(key.upper())
|
||||||
ret.extend(self._msg_create_line(msg, data, key))
|
ret.extend(self._msg_create_line(msg, data[key], key))
|
||||||
ret.append(self.curse_new_line())
|
ret.append(self.curse_new_line())
|
||||||
|
|
||||||
# Remove the last new line
|
# Remove the last new line
|
||||||
@ -226,10 +235,10 @@ class PluginModel(GlancesPluginModel):
|
|||||||
|
|
||||||
def _msg_create_line(self, msg, data, key):
|
def _msg_create_line(self, msg, data, key):
|
||||||
"""Create a new line to the Quick view."""
|
"""Create a new line to the Quick view."""
|
||||||
if key == 'mem' and self.get_alert(self.stats['swap'], header='swap') != 'DEFAULT':
|
# if key == 'mem' and self.get_alert(self.stats['swap'], header='swap') != 'DEFAULT':
|
||||||
overwrite = 'SWAP'
|
# overwrite = 'SWAP'
|
||||||
else:
|
# else:
|
||||||
overwrite = ''
|
overwrite = ''
|
||||||
return [
|
return [
|
||||||
self.curse_add_line(msg),
|
self.curse_add_line(msg),
|
||||||
self.curse_add_line(data.pre_char, decoration='BOLD'),
|
self.curse_add_line(data.pre_char, decoration='BOLD'),
|
||||||
|
Loading…
Reference in New Issue
Block a user