mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-20 15:52:16 +03:00
First try. Have to be optimized
This commit is contained in:
parent
f22c3d4f34
commit
c3ef20c361
@ -227,9 +227,21 @@ class Plugin(GlancesPlugin):
|
||||
# Alert
|
||||
for i in self.stats:
|
||||
ifrealname = i['interface_name'].split(':')[0]
|
||||
# Convert rate in bps ( to be able to compare to interface speed)
|
||||
# Convert rate in bps (to be able to compare to interface speed)
|
||||
bps_rx = int(i['rx'] // i['time_since_update'] * 8)
|
||||
bps_tx = int(i['tx'] // i['time_since_update'] * 8)
|
||||
|
||||
# Check if the stats should be hidden
|
||||
if bps_rx != 0 or bps_tx != 0:
|
||||
self.views[i[self.get_key(
|
||||
)]]['rx']['_zero'] = self.views[i[self.get_key()]]['rx']['hidden']
|
||||
self.views[i[self.get_key(
|
||||
)]]['tx']['_zero'] = self.views[i[self.get_key()]]['rx']['hidden']
|
||||
self.views[i[self.get_key(
|
||||
)]]['rx']['hidden'] = self.views[i[self.get_key()]]['rx']['_zero'] and bps_rx == 0
|
||||
self.views[i[self.get_key(
|
||||
)]]['tx']['hidden'] = self.views[i[self.get_key()]]['tx']['_zero'] and bps_tx == 0
|
||||
|
||||
# Decorate the bitrate with the configuration file thresolds
|
||||
alert_rx = self.get_alert(bps_rx, header=ifrealname + '_rx')
|
||||
alert_tx = self.get_alert(bps_tx, header=ifrealname + '_tx')
|
||||
@ -290,6 +302,10 @@ class Plugin(GlancesPlugin):
|
||||
# Do not display interface in down state (issue #765)
|
||||
if ('is_up' in i) and (i['is_up'] is False):
|
||||
continue
|
||||
# Hide 0 value (issue #1787)
|
||||
if self.get_views(item=i[self.get_key()], key='rx', option='hidden') and \
|
||||
self.get_views(item=i[self.get_key()], key='tx', option='hidden'):
|
||||
continue
|
||||
# Format stats
|
||||
# Is there an alias for the interface name ?
|
||||
ifrealname = i['interface_name'].split(':')[0]
|
||||
|
@ -428,10 +428,12 @@ class GlancesPlugin(object):
|
||||
The V of MVC
|
||||
A dict of dict with the needed information to display the stats.
|
||||
Example for the stat xxx:
|
||||
'xxx': {'decoration': 'DEFAULT',
|
||||
'optional': False,
|
||||
'additional': False,
|
||||
'splittable': False}
|
||||
'xxx': {'decoration': 'DEFAULT', >>> The decoration of the stats
|
||||
'optional': False, >>> Is the stat optional
|
||||
'additional': False, >>> Is the stat provide additional information
|
||||
'splittable': False, >>> Is the stat can be cut (like process lon name)
|
||||
'hidden': False, >>> Is the stats should be hidden in the UI
|
||||
'_zero': True} >>> For internal purpose only
|
||||
"""
|
||||
ret = {}
|
||||
|
||||
@ -440,12 +442,15 @@ class GlancesPlugin(object):
|
||||
self.get_key() is not None):
|
||||
# Stats are stored in a list of dict (ex: NETWORK, FS...)
|
||||
for i in self.get_raw():
|
||||
# i[self.get_key()] is the interface name (example for NETWORK)
|
||||
ret[i[self.get_key()]] = {}
|
||||
for key in listkeys(i):
|
||||
value = {'decoration': 'DEFAULT',
|
||||
'optional': False,
|
||||
'additional': False,
|
||||
'splittable': False}
|
||||
'splittable': False,
|
||||
'hidden': False,
|
||||
'_zero': self.views[i[self.get_key()]][key]['_zero'] if i[self.get_key()] in self.views and key in self.views[i[self.get_key()]] else True}
|
||||
ret[i[self.get_key()]][key] = value
|
||||
elif isinstance(self.get_raw(), dict) and self.get_raw() is not None:
|
||||
# Stats are stored in a dict (ex: CPU, LOAD...)
|
||||
@ -453,7 +458,9 @@ class GlancesPlugin(object):
|
||||
value = {'decoration': 'DEFAULT',
|
||||
'optional': False,
|
||||
'additional': False,
|
||||
'splittable': False}
|
||||
'splittable': False,
|
||||
'hidden': False,
|
||||
'_zero': self.views[key]['_zero'] if key in self.views and '_zero' in self.views[key] else True}
|
||||
ret[key] = value
|
||||
|
||||
self.views = ret
|
||||
|
Loading…
Reference in New Issue
Block a user