Skip to content

Commit 36755ba

Browse files
committed
Show only active Disk I/O (and network interface) nicolargo#2929
1 parent a3895e4 commit 36755ba

File tree

8 files changed

+161
-125
lines changed

8 files changed

+161
-125
lines changed

conf/glances.conf

+4
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ hide=docker.*,lo
220220
hide_no_up=True
221221
# Automatically hide interface with no IP address (default is False)
222222
hide_no_ip=True
223+
# Set hide_zero to True to automatically hide interface with no traffic
224+
hide_zero=False
223225
# It is possible to overwrite the bitrate thresholds per interface
224226
# WLAN 0 Default limits (in bits per second aka bps) for interface bitrate
225227
#wlan0_rx_careful=4000000
@@ -280,6 +282,8 @@ disable=False
280282
# Define the list of hidden disks (comma-separated regexp)
281283
#hide=sda2,sda5,loop.*
282284
hide=loop.*,/dev/loop.*
285+
# Set hide_zero to True to automatically hide disk with no read/write
286+
hide_zero=False
283287
# Define the list of disks to be show (comma-separated)
284288
#show=sda.*
285289
# Alias for sda1 and sdb1

docker-compose/glances.conf

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ max_processes_display=25
3636
# Set URL prefix for the WebUI and the API
3737
# Example: url_prefix=/glances/ => http://localhost/glances/
3838
# Note: The final / is mandatory
39-
# Default is no prefix
39+
# Default is no prefix (/)
4040
#url_prefix=/glances/
4141
# Set root path for WebUI statics files
4242
# Why ? On Debian system, WebUI statics files are not provided.
@@ -220,6 +220,8 @@ tx_critical=90
220220
hide_no_up=True
221221
# Automatically hide interface with no IP address (default is False)
222222
hide_no_ip=True
223+
# Set hide_zero to True to automatically hide interface with no traffic
224+
hide_zero=False
223225
# It is possible to overwrite the bitrate thresholds per interface
224226
# WLAN 0 Default limits (in bits per second aka bps) for interface bitrate
225227
#wlan0_rx_careful=4000000
@@ -280,6 +282,8 @@ disable=False
280282
# Define the list of hidden disks (comma-separated regexp)
281283
#hide=sda2,sda5,loop.*
282284
hide=loop.*,/dev/loop.*
285+
# Set hide_zero to True to automatically hide disk with no read/write
286+
hide_zero=False
283287
# Define the list of disks to be show (comma-separated)
284288
#show=sda.*
285289
# Alias for sda1 and sdb1

docs/aoa/diskio.rst

+8
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,12 @@ Filtering is based on regular expression. Please be sure that your regular
4242
expression works as expected. You can use an online tool like `regex101`_ in
4343
order to test your regular expression.
4444

45+
You also can automatically hide disk with no read or write using the
46+
``hide_zero`` configuration key.
47+
48+
.. code-block:: ini
49+
50+
[diskio]
51+
hide_zero=True
52+
4553
.. _regex101: https://regex101.com/

docs/aoa/network.rst

+10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ virtual docker interface (docker0, docker1, ...):
4747
hide_no_up=True
4848
# Automatically hide interface with no IP address (default is False)
4949
hide_no_ip=True
50+
# Set hide_zero to True to automatically hide interface with no traffic
51+
hide_zero=False
5052
# WLAN 0 alias
5153
alias=wlan0:Wireless IF
5254
# It is possible to overwrite the bitrate thresholds per interface
@@ -64,4 +66,12 @@ Filtering is based on regular expression. Please be sure that your regular
6466
expression works as expected. You can use an online tool like `regex101`_ in
6567
order to test your regular expression.
6668

69+
You also can automatically hide intercae with no traffic using the
70+
``hide_zero`` configuration key.
71+
72+
.. code-block:: ini
73+
74+
[diskio]
75+
hide_zero=True
76+
6777
.. _regex101: https://regex101.com/

glances/plugins/diskio/__init__.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(self, args=None, config=None):
7575
self.hide_zero = config.get_bool_value(self.plugin_name, 'hide_zero', default=False)
7676
else:
7777
self.hide_zero = False
78-
self.hide_zero_fields = ['read_bytes', 'write_bytes']
78+
self.hide_zero_fields = ['read_bytes_rate_per_sec', 'write_bytes_rate_per_sec']
7979

8080
# Force a first update because we need two updates to have the first stat
8181
self.update()
@@ -141,9 +141,6 @@ def update_views(self):
141141
# Call the father's method
142142
super().update_views()
143143

144-
# Check if the stats should be hidden
145-
self.update_views_hidden()
146-
147144
# Add specifics information
148145
# Alert
149146
for i in self.get_raw():

glances/plugins/network/__init__.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def __init__(self, args=None, config=None):
8686
self.hide_zero = config.get_bool_value(self.plugin_name, 'hide_zero', default=False)
8787
else:
8888
self.hide_zero = False
89-
self.hide_zero_fields = ['bytes_recv', 'bytes_sent']
89+
self.hide_zero_fields = ['bytes_recv_rate_per_sec', 'bytes_sent_rate_per_sec']
9090

9191
# Add support for automatically hiding network interfaces that are down
9292
# or that don't have any IP addresses #2799
@@ -196,9 +196,6 @@ def update_views(self):
196196
# Call the father's method
197197
super().update_views()
198198

199-
# Check if the stats should be hidden
200-
self.update_views_hidden()
201-
202199
# Add specifics information
203200
# Alert
204201
for i in self.get_raw():

glances/plugins/plugin/model.py

+30-57
Original file line numberDiff line numberDiff line change
@@ -430,46 +430,6 @@ def get_item_info(self, item, key, default=None):
430430
return default
431431
return self.fields_description[item].get(key, default)
432432

433-
def update_views_hidden(self):
434-
"""Update the hidden views
435-
436-
If the self.hide_zero is set then update the hidden field of the view
437-
It will check if all fields values are already be different from 0
438-
In this case, the hidden field is set to True
439-
440-
Note: This function should be called by plugin (in the update_views method)
441-
442-
Example (for network plugin):
443-
__Init__
444-
self.hide_zero_fields = ['rx', 'tx']
445-
Update views
446-
...
447-
self.update_views_hidden()
448-
"""
449-
if not self.hide_zero:
450-
return False
451-
if isinstance(self.get_raw(), list) and self.get_raw() is not None and self.get_key() is not None:
452-
# Stats are stored in a list of dict (ex: NETWORK, FS...)
453-
for i in self.get_raw():
454-
if any(i[f] for f in self.hide_zero_fields):
455-
for f in self.hide_zero_fields:
456-
self.views[i[self.get_key()]][f]['_zero'] = self.views[i[self.get_key()]][f]['hidden']
457-
for f in self.hide_zero_fields:
458-
self.views[i[self.get_key()]][f]['hidden'] = self.views[i[self.get_key()]][f]['_zero'] and i[f] == 0
459-
elif isinstance(self.get_raw(), dict) and self.get_raw() is not None:
460-
#
461-
# Warning: This code has never been tested because
462-
# no plugin with dict instance use the hidden function...
463-
#
464-
# Stats are stored in a dict (ex: CPU, LOAD...)
465-
for key in listkeys(self.get_raw()):
466-
if any(self.get_raw()[f] for f in self.hide_zero_fields):
467-
for f in self.hide_zero_fields:
468-
self.views[f]['_zero'] = self.views[f]['hidden']
469-
for f in self.hide_zero_fields:
470-
self.views[f]['hidden'] = self.views['_zero'] and self.views[f] == 0
471-
return True
472-
473433
def update_views(self):
474434
"""Update the stats views.
475435
@@ -480,43 +440,56 @@ def update_views(self):
480440
'optional': False, >>> Is the stat optional
481441
'additional': False, >>> Is the stat provide additional information
482442
'splittable': False, >>> Is the stat can be cut (like process lon name)
483-
'hidden': False, >>> Is the stats should be hidden in the UI
484-
'_zero': True} >>> For internal purpose only
443+
'hidden': False} >>> Is the stats should be hidden in the UI
485444
"""
486445
ret = {}
487446

488447
if isinstance(self.get_raw(), list) and self.get_raw() is not None and self.get_key() is not None:
489448
# Stats are stored in a list of dict (ex: DISKIO, NETWORK, FS...)
490449
for i in self.get_raw():
491-
ret[i[self.get_key()]] = {}
492-
for key in listkeys(i):
450+
key = i[self.get_key()]
451+
ret[key] = {}
452+
for field in listkeys(i):
493453
value = {
494454
'decoration': 'DEFAULT',
495455
'optional': False,
496456
'additional': False,
497457
'splittable': False,
498-
'hidden': False,
499-
'_zero': (
500-
self.views[i[self.get_key()]][key]['_zero']
501-
if i[self.get_key()] in self.views
502-
and key in self.views[i[self.get_key()]]
503-
and 'zero' in self.views[i[self.get_key()]][key]
504-
else True
505-
),
506458
}
507-
ret[i[self.get_key()]][key] = value
459+
# Manage the hidden feature
460+
# Allow to automatically hide fields when values is never different than 0
461+
# Refactoring done for #2929
462+
if not self.hide_zero:
463+
value['hidden'] = False
464+
elif key in self.views and field in self.views[key] and 'hidden' in self.views[key][field]:
465+
value['hidden'] = self.views[key][field]['hidden']
466+
if field in self.hide_zero_fields and i[field] != 0:
467+
value['hidden'] = False
468+
else:
469+
value['hidden'] = field in self.hide_zero_fields
470+
ret[key][field] = value
508471
elif isinstance(self.get_raw(), dict) and self.get_raw() is not None:
509472
# Stats are stored in a dict (ex: CPU, LOAD...)
510-
for key in listkeys(self.get_raw()):
473+
for field in listkeys(self.get_raw()):
511474
value = {
512475
'decoration': 'DEFAULT',
513476
'optional': False,
514477
'additional': False,
515478
'splittable': False,
516479
'hidden': False,
517-
'_zero': self.views[key]['_zero'] if key in self.views and '_zero' in self.views[key] else True,
518480
}
519-
ret[key] = value
481+
# Manage the hidden feature
482+
# Allow to automatically hide fields when values is never different than 0
483+
# Refactoring done for #2929
484+
if not self.hide_zero:
485+
value['hidden'] = False
486+
elif field in self.views and 'hidden' in self.views[field]:
487+
value['hidden'] = self.views[field]['hidden']
488+
if field in self.hide_zero_fields and self.get_raw()[field] != 0:
489+
value['hidden'] = False
490+
else:
491+
value['hidden'] = field in self.hide_zero_fields
492+
ret[field] = value
520493

521494
self.views = ret
522495

@@ -544,7 +517,7 @@ def get_views(self, item=None, key=None, option=None):
544517
else:
545518
item_views = self.views[item]
546519

547-
if key is None:
520+
if key is None or key not in item_views:
548521
return item_views
549522
if option is None:
550523
return item_views[key]

0 commit comments

Comments
 (0)