summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolas@nicolargo.com>2021-01-17 12:23:14 +0100
committernicolargo <nicolas@nicolargo.com>2021-01-17 12:23:14 +0100
commitc3ef20c3616d3df2e3a59e4a003b47f61c0e38e0 (patch)
tree318330ba516ac33f0c9a250ce7f621b5d6c2012f
parentf22c3d4f34044cb2677575430fed4f2e069367bc (diff)
First try. Have to be optimized
-rw-r--r--glances/plugins/glances_network.py18
-rw-r--r--glances/plugins/glances_plugin.py19
2 files changed, 30 insertions, 7 deletions
diff --git a/glances/plugins/glances_network.py b/glances/plugins/glances_network.py
index 00fc88b0..12388eb0 100644
--- a/glances/plugins/glances_network.py
+++ b/glances/plugins/glances_network.py
@@ -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]
diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py
index e092ff05..6a3f68c8 100644
--- a/glances/plugins/glances_plugin.py
+++ b/glances/plugins/glances_plugin.py
@@ -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