mirror of https://github.com/nicolargo/glances
Side bar use more space in SNMP mode
parent
3980730150
commit
c39789b96c
|
@ -304,23 +304,30 @@ class GlancesCurses(object):
|
|||
stats_memswap = stats.get_plugin('memswap').get_stats_display()
|
||||
l += self.get_stats_display_width(stats_load) + self.get_stats_display_width(stats_mem) + self.get_stats_display_width(stats_memswap)
|
||||
# Space between column
|
||||
if screen_x > (3 * self.space_between_column + l):
|
||||
self.space_between_column = int((screen_x - l) / 3)
|
||||
space_number = int(stats_load['msgdict'] != []) + int(stats_mem['msgdict'] != []) + int(stats_memswap['msgdict'] != [])
|
||||
if screen_x > (space_number * self.space_between_column + l):
|
||||
self.space_between_column = int((screen_x - l) / space_number)
|
||||
# Display
|
||||
if self.args.percpu:
|
||||
self.display_plugin(stats_percpu)
|
||||
else:
|
||||
self.display_plugin(stats_cpu, display_optional=(screen_x >= 80))
|
||||
self.display_plugin(stats_load)
|
||||
self.display_plugin(stats_mem, display_optional=(screen_x >= (3 * self.space_between_column + l)))
|
||||
self.display_plugin(stats_mem, display_optional=(screen_x >= (space_number * self.space_between_column + l)))
|
||||
self.display_plugin(stats_memswap)
|
||||
# Space between column
|
||||
self.space_between_column = 3
|
||||
|
||||
# Display left sidebar (NETWORK+DISKIO+FS+SENSORS)
|
||||
self.display_plugin(stats.get_plugin('network').get_stats_display(args=self.args))
|
||||
if cs_status == 'SNMP':
|
||||
# No process list
|
||||
# More space for others plugins
|
||||
plugin_max_width = 43
|
||||
else:
|
||||
plugin_max_width = None
|
||||
self.display_plugin(stats.get_plugin('network').get_stats_display(args=self.args, max_width=plugin_max_width))
|
||||
self.display_plugin(stats.get_plugin('diskio').get_stats_display(args=self.args))
|
||||
self.display_plugin(stats.get_plugin('fs').get_stats_display(args=self.args))
|
||||
self.display_plugin(stats.get_plugin('fs').get_stats_display(args=self.args, max_width=plugin_max_width))
|
||||
self.display_plugin(stats.get_plugin('sensors').get_stats_display(args=self.args))
|
||||
# Display last line (currenttime)
|
||||
self.display_plugin(stats.get_plugin('now').get_stats_display())
|
||||
|
|
|
@ -150,7 +150,7 @@ class Plugin(GlancesPlugin):
|
|||
|
||||
return self.stats
|
||||
|
||||
def msg_curse(self, args=None):
|
||||
def msg_curse(self, args=None, max_width=None):
|
||||
"""Return the dict to display in the curse interface."""
|
||||
# Init the return message
|
||||
ret = []
|
||||
|
@ -159,9 +159,16 @@ class Plugin(GlancesPlugin):
|
|||
if self.stats == [] or args.disable_fs:
|
||||
return ret
|
||||
|
||||
# Max size for the fsname name
|
||||
if max_width is not None and max_width >= 23:
|
||||
# Interface size name = max_width - space for interfaces bitrate
|
||||
fsname_max_width = max_width - 14
|
||||
else:
|
||||
fsname_max_width = 9
|
||||
|
||||
# Build the string message
|
||||
# Header
|
||||
msg = '{0:9}'.format(_("FILE SYS"))
|
||||
msg = '{0:{width}}'.format(_("FILE SYS"), width=fsname_max_width)
|
||||
ret.append(self.curse_add_line(msg, "TITLE"))
|
||||
msg = '{0:>7}'.format(_("Used"))
|
||||
ret.append(self.curse_add_line(msg))
|
||||
|
@ -172,17 +179,17 @@ class Plugin(GlancesPlugin):
|
|||
for i in sorted(self.stats, key=lambda fs: fs['mnt_point']):
|
||||
# New line
|
||||
ret.append(self.curse_new_line())
|
||||
if i['device_name'] == '':
|
||||
if i['device_name'] == '' or i['device_name'] == 'none':
|
||||
mnt_point = i['mnt_point']
|
||||
elif len(i['mnt_point']) + len(i['device_name'].split('/')[-1]) <= 6:
|
||||
elif len(i['mnt_point']) + len(i['device_name'].split('/')[-1]) <= fsname_max_width - 3:
|
||||
# If possible concatenate mode info... Glances touch inside :)
|
||||
mnt_point = i['mnt_point'] + ' (' + i['device_name'].split('/')[-1] + ')'
|
||||
elif len(i['mnt_point']) > 9:
|
||||
elif len(i['mnt_point']) > fsname_max_width:
|
||||
# Cut mount point name if it is too long
|
||||
mnt_point = '_' + i['mnt_point'][-8:]
|
||||
mnt_point = '_' + i['mnt_point'][-fsname_max_width+1:]
|
||||
else:
|
||||
mnt_point = i['mnt_point']
|
||||
msg = '{0:9}'.format(mnt_point)
|
||||
msg = '{0:{width}}'.format(mnt_point, width=fsname_max_width)
|
||||
ret.append(self.curse_add_line(msg))
|
||||
msg = '{0:>7}'.format(self.auto_unit(i['used']))
|
||||
ret.append(self.curse_add_line(msg, self.get_alert(i['used'], max=i['size'])))
|
||||
|
|
|
@ -102,7 +102,7 @@ class Plugin(GlancesPlugin):
|
|||
self.stats['free'] = self.stats['total'] - self.stats['used']
|
||||
break
|
||||
else:
|
||||
self.stats = self.set_stats_snmp(snmp_oid=snmp_oid)
|
||||
self.stats = self.set_stats_snmp(snmp_oid=snmp_oid['default'])
|
||||
|
||||
if self.stats['total'] == '':
|
||||
self.reset()
|
||||
|
|
|
@ -174,9 +174,8 @@ class Plugin(GlancesPlugin):
|
|||
|
||||
return self.stats
|
||||
|
||||
def msg_curse(self, args=None):
|
||||
def msg_curse(self, args=None, max_width=None):
|
||||
"""Return the dict to display in the curse interface."""
|
||||
# !!! TODO: Add alert on network interface bitrate
|
||||
|
||||
# Init the return message
|
||||
ret = []
|
||||
|
@ -185,9 +184,16 @@ class Plugin(GlancesPlugin):
|
|||
if self.stats == [] or args.disable_network:
|
||||
return ret
|
||||
|
||||
# Max size for the interface name
|
||||
if max_width is not None and max_width >= 23:
|
||||
# Interface size name = max_width - space for interfaces bitrate
|
||||
ifname_max_width = max_width - 14
|
||||
else:
|
||||
ifname_max_width = 9
|
||||
|
||||
# Build the string message
|
||||
# Header
|
||||
msg = '{0:9}'.format(_("NETWORK"))
|
||||
msg = '{0:{width}}'.format(_("NETWORK"), width=ifname_max_width)
|
||||
ret.append(self.curse_add_line(msg, "TITLE"))
|
||||
if args.network_cumul:
|
||||
# Cumulative stats
|
||||
|
@ -219,9 +225,9 @@ class Plugin(GlancesPlugin):
|
|||
continue
|
||||
# Format stats
|
||||
ifname = i['interface_name'].split(':')[0]
|
||||
if len(ifname) > 9:
|
||||
if len(ifname) > ifname_max_width:
|
||||
# Cut interface name if it is too long
|
||||
ifname = '_' + ifname[-8:]
|
||||
ifname = '_' + ifname[-ifname_max_width+1:]
|
||||
if args.byte:
|
||||
# Bytes per second (for dummy)
|
||||
if args.network_cumul:
|
||||
|
@ -248,7 +254,7 @@ class Plugin(GlancesPlugin):
|
|||
int(i['tx'] // i['time_since_update'] * 8)) + "b"
|
||||
# New line
|
||||
ret.append(self.curse_new_line())
|
||||
msg = '{0:9}'.format(ifname)
|
||||
msg = '{0:{width}}'.format(ifname, width=ifname_max_width)
|
||||
ret.append(self.curse_add_line(msg))
|
||||
if args.network_sum:
|
||||
msg = '{0:>14}'.format(sx)
|
||||
|
|
|
@ -268,11 +268,11 @@ class GlancesPlugin(object):
|
|||
"""Return True if the value is in the hide configuration list."""
|
||||
return value in self.get_hide(header=header)
|
||||
|
||||
def msg_curse(self, args):
|
||||
def msg_curse(self, args=None, max_width=None):
|
||||
"""Return default string to display in the curse interface."""
|
||||
return [self.curse_add_line(str(self.stats))]
|
||||
|
||||
def get_stats_display(self, args=None):
|
||||
def get_stats_display(self, args=None, max_width=None):
|
||||
"""Return a dict with all the information needed to display the stat.
|
||||
|
||||
key | description
|
||||
|
@ -293,10 +293,18 @@ class GlancesPlugin(object):
|
|||
if hasattr(self, 'line_curse'):
|
||||
line_curse = self.line_curse
|
||||
|
||||
return {'display': display_curse,
|
||||
'msgdict': self.msg_curse(args),
|
||||
'column': column_curse,
|
||||
'line': line_curse}
|
||||
if max_width is not None:
|
||||
ret = {'display': display_curse,
|
||||
'msgdict': self.msg_curse(args, max_width=max_width),
|
||||
'column': column_curse,
|
||||
'line': line_curse}
|
||||
else:
|
||||
ret = {'display': display_curse,
|
||||
'msgdict': self.msg_curse(args),
|
||||
'column': column_curse,
|
||||
'line': line_curse}
|
||||
|
||||
return ret
|
||||
|
||||
def curse_add_line(self, msg, decoration="DEFAULT", optional=False, splittable=False):
|
||||
"""Return a dict with: { 'msg': msg, 'decoration': decoration, 'optional': False }.
|
||||
|
@ -328,6 +336,18 @@ class GlancesPlugin(object):
|
|||
"""Go to a new line."""
|
||||
return self.curse_add_line('\n')
|
||||
|
||||
def set_curse_column(self, column):
|
||||
"""Set the Curse column
|
||||
Enter -1 to right align
|
||||
"""
|
||||
self.column_curse = column
|
||||
|
||||
def set_curse_line(self, line):
|
||||
"""Set the Curse line
|
||||
Enter -1 to right align
|
||||
"""
|
||||
self.line_curse = line
|
||||
|
||||
def auto_unit(self, number, low_precision=False):
|
||||
"""Make a nice human-readable string out of number.
|
||||
|
||||
|
|
|
@ -63,10 +63,9 @@ class Plugin(GlancesPlugin):
|
|||
# Update stats using the standard system lib
|
||||
# Note: Update is done in the processcount plugin
|
||||
# Just return the processes list
|
||||
self.stats = glances_processes.getlist()
|
||||
self.stats = glances_processes.getlist()
|
||||
elif self.get_input() == 'snmp':
|
||||
# Update stats using SNMP
|
||||
# !!! TODO
|
||||
# No SNMP grab for processes
|
||||
pass
|
||||
|
||||
return self.stats
|
||||
|
@ -124,42 +123,68 @@ class Plugin(GlancesPlugin):
|
|||
for p in self.sortlist(process_sort_key):
|
||||
ret.append(self.curse_new_line())
|
||||
# CPU
|
||||
msg = '{0:>6.1f}'.format(p['cpu_percent'])
|
||||
ret.append(self.curse_add_line(msg,
|
||||
self.get_alert(p['cpu_percent'], header="cpu")))
|
||||
if 'cpu_percent' in p:
|
||||
msg = '{0:>6.1f}'.format(p['cpu_percent'])
|
||||
ret.append(self.curse_add_line(msg,
|
||||
self.get_alert(p['cpu_percent'], header="cpu")))
|
||||
else:
|
||||
msg = '{0:>6}'.format('?')
|
||||
ret.append(self.curse_add_line(msg))
|
||||
# MEM
|
||||
msg = '{0:>6.1f}'.format(p['memory_percent'])
|
||||
ret.append(self.curse_add_line(msg,
|
||||
self.get_alert(p['memory_percent'], header="mem")))
|
||||
# VMS
|
||||
msg = '{0:>6}'.format(self.auto_unit(p['memory_info'][1], low_precision=False))
|
||||
ret.append(self.curse_add_line(msg, optional=True))
|
||||
# RSS
|
||||
msg = '{0:>6}'.format(self.auto_unit(p['memory_info'][0], low_precision=False))
|
||||
ret.append(self.curse_add_line(msg, optional=True))
|
||||
if 'memory_percent' in p:
|
||||
msg = '{0:>6.1f}'.format(p['memory_percent'])
|
||||
ret.append(self.curse_add_line(msg,
|
||||
self.get_alert(p['memory_percent'], header="mem")))
|
||||
else:
|
||||
msg = '{0:>6}'.format('?')
|
||||
ret.append(self.curse_add_line(msg))
|
||||
# VMS/RSS
|
||||
if 'memory_info' in p:
|
||||
# VMS
|
||||
msg = '{0:>6}'.format(self.auto_unit(p['memory_info'][1], low_precision=False))
|
||||
ret.append(self.curse_add_line(msg, optional=True))
|
||||
# RSS
|
||||
msg = '{0:>6}'.format(self.auto_unit(p['memory_info'][0], low_precision=False))
|
||||
ret.append(self.curse_add_line(msg, optional=True))
|
||||
else:
|
||||
msg = '{0:>6}'.format('?')
|
||||
ret.append(self.curse_add_line(msg))
|
||||
ret.append(self.curse_add_line(msg))
|
||||
# PID
|
||||
msg = '{0:>6}'.format(p['pid'])
|
||||
ret.append(self.curse_add_line(msg))
|
||||
# USER
|
||||
# docker internal users are displayed as ints only, therefore str()
|
||||
msg = ' {0:9}'.format(str(p['username'])[:9])
|
||||
ret.append(self.curse_add_line(msg))
|
||||
# NICE
|
||||
nice = p['nice']
|
||||
if nice is None:
|
||||
nice = '?'
|
||||
msg = '{0:>5}'.format(nice)
|
||||
if isinstance(nice, int) and ((is_windows and nice != 32) or
|
||||
(not is_windows and nice != 0)):
|
||||
ret.append(self.curse_add_line(msg, decoration='NICE'))
|
||||
if 'username' in p:
|
||||
# docker internal users are displayed as ints only, therefore str()
|
||||
msg = ' {0:9}'.format(str(p['username'])[:9])
|
||||
ret.append(self.curse_add_line(msg))
|
||||
else:
|
||||
msg = ' {0:9}'.format('?')
|
||||
ret.append(self.curse_add_line(msg))
|
||||
# NICE
|
||||
if 'nice' in p:
|
||||
nice = p['nice']
|
||||
if nice is None:
|
||||
nice = '?'
|
||||
msg = '{0:>5}'.format(nice)
|
||||
if isinstance(nice, int) and ((is_windows and nice != 32) or
|
||||
(not is_windows and nice != 0)):
|
||||
ret.append(self.curse_add_line(msg, decoration='NICE'))
|
||||
else:
|
||||
ret.append(self.curse_add_line(msg))
|
||||
else:
|
||||
msg = '{0:>5}'.format('?')
|
||||
ret.append(self.curse_add_line(msg))
|
||||
# STATUS
|
||||
status = p['status']
|
||||
msg = '{0:>2}'.format(status)
|
||||
if status == 'R':
|
||||
ret.append(self.curse_add_line(msg, decoration='STATUS'))
|
||||
if 'status' in p:
|
||||
status = p['status']
|
||||
msg = '{0:>2}'.format(status)
|
||||
if status == 'R':
|
||||
ret.append(self.curse_add_line(msg, decoration='STATUS'))
|
||||
else:
|
||||
ret.append(self.curse_add_line(msg))
|
||||
else:
|
||||
msg = '{0:>2}'.format('?')
|
||||
ret.append(self.curse_add_line(msg))
|
||||
# TIME+
|
||||
if tag_proc_time:
|
||||
|
@ -250,9 +275,14 @@ class Plugin(GlancesPlugin):
|
|||
reverse=sortedreverse)
|
||||
else:
|
||||
# Others sorts
|
||||
listsorted = sorted(self.stats,
|
||||
key=lambda process: process[sortedby],
|
||||
reverse=sortedreverse)
|
||||
try:
|
||||
listsorted = sorted(self.stats,
|
||||
key=lambda process: process[sortedby],
|
||||
reverse=sortedreverse)
|
||||
except KeyError:
|
||||
listsorted = sorted(self.stats,
|
||||
key=lambda process: process['name'],
|
||||
reverse=False)
|
||||
|
||||
self.stats = listsorted
|
||||
|
||||
|
|
Loading…
Reference in New Issue