mirror of
https://github.com/nicolargo/glances.git
synced 2024-09-11 12:47:14 +03:00
Add sort information on Docker plugin (console mode). Related to #2138
This commit is contained in:
parent
16832111ee
commit
94d1e00692
@ -58,6 +58,16 @@ items_history_list = [{'name': 'cpu_percent', 'description': 'Container CPU cons
|
|||||||
# List of key to remove before export
|
# List of key to remove before export
|
||||||
export_exclude_list = ['cpu', 'io', 'memory', 'network']
|
export_exclude_list = ['cpu', 'io', 'memory', 'network']
|
||||||
|
|
||||||
|
# Sort dictionary for human
|
||||||
|
sort_for_human = {
|
||||||
|
'io_counters': 'disk IO',
|
||||||
|
'cpu_percent': 'CPU consumption',
|
||||||
|
'memory_usage': 'memory consumption',
|
||||||
|
'cpu_times': 'uptime',
|
||||||
|
'name': 'container name',
|
||||||
|
None: 'None',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
"""Glances Docker plugin.
|
"""Glances Docker plugin.
|
||||||
@ -96,6 +106,9 @@ class Plugin(GlancesPlugin):
|
|||||||
# value: network stats dict
|
# value: network stats dict
|
||||||
self.io_old = {}
|
self.io_old = {}
|
||||||
|
|
||||||
|
# Sort key
|
||||||
|
self.sort_key = None
|
||||||
|
|
||||||
# Force a first update because we need two update to have the first stat
|
# Force a first update because we need two update to have the first stat
|
||||||
self.update()
|
self.update()
|
||||||
self.refresh_timer.set(0)
|
self.refresh_timer.set(0)
|
||||||
@ -303,7 +316,7 @@ class Plugin(GlancesPlugin):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# Sort and update the stats
|
# Sort and update the stats
|
||||||
self.stats = sort_stats(stats)
|
self.sort_key, self.stats = sort_docker_stats(stats)
|
||||||
|
|
||||||
return self.stats
|
return self.stats
|
||||||
|
|
||||||
@ -533,8 +546,10 @@ class Plugin(GlancesPlugin):
|
|||||||
ret.append(self.curse_add_line(msg, "TITLE"))
|
ret.append(self.curse_add_line(msg, "TITLE"))
|
||||||
msg = ' {}'.format(len(self.stats['containers']))
|
msg = ' {}'.format(len(self.stats['containers']))
|
||||||
ret.append(self.curse_add_line(msg))
|
ret.append(self.curse_add_line(msg))
|
||||||
msg = ' (served by Docker {})'.format(self.stats['version']["Version"])
|
msg = ' sorted by {}'.format(sort_for_human[self.sort_key])
|
||||||
ret.append(self.curse_add_line(msg))
|
ret.append(self.curse_add_line(msg))
|
||||||
|
# msg = ' (served by Docker {})'.format(self.stats['version']["Version"])
|
||||||
|
# ret.append(self.curse_add_line(msg))
|
||||||
ret.append(self.curse_new_line())
|
ret.append(self.curse_new_line())
|
||||||
# Header
|
# Header
|
||||||
ret.append(self.curse_new_line())
|
ret.append(self.curse_new_line())
|
||||||
@ -545,15 +560,15 @@ class Plugin(GlancesPlugin):
|
|||||||
len(max(self.stats['containers'], key=lambda x: len(x['name']))['name']),
|
len(max(self.stats['containers'], key=lambda x: len(x['name']))['name']),
|
||||||
)
|
)
|
||||||
msg = ' {:{width}}'.format('Name', width=name_max_width)
|
msg = ' {:{width}}'.format('Name', width=name_max_width)
|
||||||
ret.append(self.curse_add_line(msg))
|
ret.append(self.curse_add_line(msg, 'SORT' if self.sort_key == 'name' else 'DEFAULT'))
|
||||||
msg = '{:>10}'.format('Status')
|
msg = '{:>10}'.format('Status')
|
||||||
ret.append(self.curse_add_line(msg))
|
ret.append(self.curse_add_line(msg))
|
||||||
msg = '{:>10}'.format('Uptime')
|
msg = '{:>10}'.format('Uptime')
|
||||||
ret.append(self.curse_add_line(msg))
|
ret.append(self.curse_add_line(msg))
|
||||||
msg = '{:>6}'.format('CPU%')
|
msg = '{:>6}'.format('CPU%')
|
||||||
ret.append(self.curse_add_line(msg))
|
ret.append(self.curse_add_line(msg, 'SORT' if self.sort_key == 'cpu_percent' else 'DEFAULT'))
|
||||||
msg = '{:>7}'.format('MEM')
|
msg = '{:>7}'.format('MEM')
|
||||||
ret.append(self.curse_add_line(msg))
|
ret.append(self.curse_add_line(msg, 'SORT' if self.sort_key == 'memory_usage' else 'DEFAULT'))
|
||||||
msg = '/{:<7}'.format('MAX')
|
msg = '/{:<7}'.format('MAX')
|
||||||
ret.append(self.curse_add_line(msg))
|
ret.append(self.curse_add_line(msg))
|
||||||
msg = '{:>7}'.format('IOR/s')
|
msg = '{:>7}'.format('IOR/s')
|
||||||
@ -700,8 +715,8 @@ class ThreadDockerGrabber(threading.Thread):
|
|||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
if self.stopped():
|
if self.stopped():
|
||||||
break
|
break
|
||||||
except:
|
except Exception as e:
|
||||||
logger.debug("docker plugin - Exception thrown during run")
|
logger.debug("docker plugin - Exception thrown during run ({})".format(e))
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -724,12 +739,22 @@ class ThreadDockerGrabber(threading.Thread):
|
|||||||
return self._stopper.is_set()
|
return self._stopper.is_set()
|
||||||
|
|
||||||
|
|
||||||
def sort_stats(stats):
|
def sort_docker_stats(stats):
|
||||||
# Sort Docker stats using the same function than processes
|
# Sort Docker stats using the same function than processes
|
||||||
sort_by = 'cpu_percent'
|
sort_by = glances_processes.sort_key
|
||||||
sort_by_secondary = 'memory_usage'
|
sort_by_secondary = 'memory_usage'
|
||||||
if glances_processes.sort_key.startswith('memory'):
|
if sort_by == 'memory_percent':
|
||||||
sort_by = 'memory_usage'
|
sort_by = 'memory_usage'
|
||||||
sort_by_secondary = 'cpu_percent'
|
sort_by_secondary = 'cpu_percent'
|
||||||
sort_stats_processes(stats['containers'], sorted_by=sort_by, sorted_by_secondary=sort_by_secondary)
|
elif sort_by in ['username', 'io_counters', 'cpu_times']:
|
||||||
return stats
|
sort_by = 'cpu_percent'
|
||||||
|
|
||||||
|
# Sort docker stats
|
||||||
|
sort_stats_processes(stats['containers'],
|
||||||
|
sorted_by=sort_by,
|
||||||
|
sorted_by_secondary=sort_by_secondary,
|
||||||
|
# Reverse for all but name
|
||||||
|
reverse=glances_processes.sort_key != 'name')
|
||||||
|
|
||||||
|
# Return the main sort key and the sorted stats
|
||||||
|
return sort_by, stats
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
"""Process count plugin."""
|
"""Process count plugin."""
|
||||||
|
|
||||||
from glances.processes import glances_processes
|
from glances.processes import glances_processes, sort_for_human
|
||||||
from glances.plugins.glances_plugin import GlancesPlugin
|
from glances.plugins.glances_plugin import GlancesPlugin
|
||||||
|
|
||||||
# Define the history items list
|
# Define the history items list
|
||||||
@ -27,16 +27,6 @@ class Plugin(GlancesPlugin):
|
|||||||
stats is a list
|
stats is a list
|
||||||
"""
|
"""
|
||||||
|
|
||||||
sort_for_human = {
|
|
||||||
'io_counters': 'disk IO',
|
|
||||||
'cpu_percent': 'CPU consumption',
|
|
||||||
'memory_percent': 'memory consumption',
|
|
||||||
'cpu_times': 'process time',
|
|
||||||
'username': 'user name',
|
|
||||||
'name': 'process name',
|
|
||||||
None: 'None',
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(self, args=None, config=None):
|
def __init__(self, args=None, config=None):
|
||||||
"""Init the plugin."""
|
"""Init the plugin."""
|
||||||
super(Plugin, self).__init__(args=args, config=config, items_history_list=items_history_list)
|
super(Plugin, self).__init__(args=args, config=config, items_history_list=items_history_list)
|
||||||
@ -133,7 +123,7 @@ class Plugin(GlancesPlugin):
|
|||||||
# Display sort information
|
# Display sort information
|
||||||
msg = 'Programs' if self.args.programs else 'Threads'
|
msg = 'Programs' if self.args.programs else 'Threads'
|
||||||
try:
|
try:
|
||||||
sort_human = self.sort_for_human[glances_processes.sort_key]
|
sort_human = sort_for_human[glances_processes.sort_key]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
sort_human = glances_processes.sort_key
|
sort_human = glances_processes.sort_key
|
||||||
if glances_processes.auto_sort:
|
if glances_processes.auto_sort:
|
||||||
|
@ -20,6 +20,17 @@ import psutil
|
|||||||
# This constant defines the list of available processes sort key
|
# This constant defines the list of available processes sort key
|
||||||
sort_processes_key_list = ['cpu_percent', 'memory_percent', 'username', 'cpu_times', 'io_counters', 'name']
|
sort_processes_key_list = ['cpu_percent', 'memory_percent', 'username', 'cpu_times', 'io_counters', 'name']
|
||||||
|
|
||||||
|
# Sort dictionary for human
|
||||||
|
sort_for_human = {
|
||||||
|
'io_counters': 'disk IO',
|
||||||
|
'cpu_percent': 'CPU consumption',
|
||||||
|
'memory_percent': 'memory consumption',
|
||||||
|
'cpu_times': 'process time',
|
||||||
|
'username': 'user name',
|
||||||
|
'name': 'processs name',
|
||||||
|
None: 'None',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class GlancesProcesses(object):
|
class GlancesProcesses(object):
|
||||||
"""Get processed stats using the psutil library."""
|
"""Get processed stats using the psutil library."""
|
||||||
|
Loading…
Reference in New Issue
Block a user