Skip to content

Commit

Permalink
Show only active Disk I/O (and network interface) #2929
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolargo committed Sep 8, 2024
1 parent a3895e4 commit 36755ba
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 125 deletions.
4 changes: 4 additions & 0 deletions conf/glances.conf
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ hide=docker.*,lo
hide_no_up=True
# Automatically hide interface with no IP address (default is False)
hide_no_ip=True
# Set hide_zero to True to automatically hide interface with no traffic
hide_zero=False
# It is possible to overwrite the bitrate thresholds per interface
# WLAN 0 Default limits (in bits per second aka bps) for interface bitrate
#wlan0_rx_careful=4000000
Expand Down Expand Up @@ -280,6 +282,8 @@ disable=False
# Define the list of hidden disks (comma-separated regexp)
#hide=sda2,sda5,loop.*
hide=loop.*,/dev/loop.*
# Set hide_zero to True to automatically hide disk with no read/write
hide_zero=False
# Define the list of disks to be show (comma-separated)
#show=sda.*
# Alias for sda1 and sdb1
Expand Down
6 changes: 5 additions & 1 deletion docker-compose/glances.conf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ max_processes_display=25
# Set URL prefix for the WebUI and the API
# Example: url_prefix=/glances/ => http://localhost/glances/
# Note: The final / is mandatory
# Default is no prefix
# Default is no prefix (/)
#url_prefix=/glances/
# Set root path for WebUI statics files
# Why ? On Debian system, WebUI statics files are not provided.
Expand Down Expand Up @@ -220,6 +220,8 @@ tx_critical=90
hide_no_up=True
# Automatically hide interface with no IP address (default is False)
hide_no_ip=True
# Set hide_zero to True to automatically hide interface with no traffic
hide_zero=False
# It is possible to overwrite the bitrate thresholds per interface
# WLAN 0 Default limits (in bits per second aka bps) for interface bitrate
#wlan0_rx_careful=4000000
Expand Down Expand Up @@ -280,6 +282,8 @@ disable=False
# Define the list of hidden disks (comma-separated regexp)
#hide=sda2,sda5,loop.*
hide=loop.*,/dev/loop.*
# Set hide_zero to True to automatically hide disk with no read/write
hide_zero=False
# Define the list of disks to be show (comma-separated)
#show=sda.*
# Alias for sda1 and sdb1
Expand Down
8 changes: 8 additions & 0 deletions docs/aoa/diskio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,12 @@ Filtering is based on regular expression. Please be sure that your regular
expression works as expected. You can use an online tool like `regex101`_ in
order to test your regular expression.

You also can automatically hide disk with no read or write using the
``hide_zero`` configuration key.

.. code-block:: ini
[diskio]
hide_zero=True
.. _regex101: https://regex101.com/
10 changes: 10 additions & 0 deletions docs/aoa/network.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ virtual docker interface (docker0, docker1, ...):
hide_no_up=True
# Automatically hide interface with no IP address (default is False)
hide_no_ip=True
# Set hide_zero to True to automatically hide interface with no traffic
hide_zero=False
# WLAN 0 alias
alias=wlan0:Wireless IF
# It is possible to overwrite the bitrate thresholds per interface
Expand All @@ -64,4 +66,12 @@ Filtering is based on regular expression. Please be sure that your regular
expression works as expected. You can use an online tool like `regex101`_ in
order to test your regular expression.

You also can automatically hide intercae with no traffic using the
``hide_zero`` configuration key.

.. code-block:: ini
[diskio]
hide_zero=True
.. _regex101: https://regex101.com/
5 changes: 1 addition & 4 deletions glances/plugins/diskio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(self, args=None, config=None):
self.hide_zero = config.get_bool_value(self.plugin_name, 'hide_zero', default=False)
else:
self.hide_zero = False
self.hide_zero_fields = ['read_bytes', 'write_bytes']
self.hide_zero_fields = ['read_bytes_rate_per_sec', 'write_bytes_rate_per_sec']

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

# Check if the stats should be hidden
self.update_views_hidden()

# Add specifics information
# Alert
for i in self.get_raw():
Expand Down
5 changes: 1 addition & 4 deletions glances/plugins/network/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __init__(self, args=None, config=None):
self.hide_zero = config.get_bool_value(self.plugin_name, 'hide_zero', default=False)
else:
self.hide_zero = False
self.hide_zero_fields = ['bytes_recv', 'bytes_sent']
self.hide_zero_fields = ['bytes_recv_rate_per_sec', 'bytes_sent_rate_per_sec']

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

# Check if the stats should be hidden
self.update_views_hidden()

# Add specifics information
# Alert
for i in self.get_raw():
Expand Down
87 changes: 30 additions & 57 deletions glances/plugins/plugin/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,46 +430,6 @@ def get_item_info(self, item, key, default=None):
return default
return self.fields_description[item].get(key, default)

def update_views_hidden(self):
"""Update the hidden views
If the self.hide_zero is set then update the hidden field of the view
It will check if all fields values are already be different from 0
In this case, the hidden field is set to True
Note: This function should be called by plugin (in the update_views method)
Example (for network plugin):
__Init__
self.hide_zero_fields = ['rx', 'tx']
Update views
...
self.update_views_hidden()
"""
if not self.hide_zero:
return False
if isinstance(self.get_raw(), list) and self.get_raw() is not None and self.get_key() is not None:
# Stats are stored in a list of dict (ex: NETWORK, FS...)
for i in self.get_raw():
if any(i[f] for f in self.hide_zero_fields):
for f in self.hide_zero_fields:
self.views[i[self.get_key()]][f]['_zero'] = self.views[i[self.get_key()]][f]['hidden']
for f in self.hide_zero_fields:
self.views[i[self.get_key()]][f]['hidden'] = self.views[i[self.get_key()]][f]['_zero'] and i[f] == 0
elif isinstance(self.get_raw(), dict) and self.get_raw() is not None:
#
# Warning: This code has never been tested because
# no plugin with dict instance use the hidden function...
#
# Stats are stored in a dict (ex: CPU, LOAD...)
for key in listkeys(self.get_raw()):
if any(self.get_raw()[f] for f in self.hide_zero_fields):
for f in self.hide_zero_fields:
self.views[f]['_zero'] = self.views[f]['hidden']
for f in self.hide_zero_fields:
self.views[f]['hidden'] = self.views['_zero'] and self.views[f] == 0
return True

def update_views(self):
"""Update the stats views.
Expand All @@ -480,43 +440,56 @@ def update_views(self):
'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
'hidden': False} >>> Is the stats should be hidden in the UI
"""
ret = {}

if isinstance(self.get_raw(), list) and self.get_raw() is not None and self.get_key() is not None:
# Stats are stored in a list of dict (ex: DISKIO, NETWORK, FS...)
for i in self.get_raw():
ret[i[self.get_key()]] = {}
for key in listkeys(i):
key = i[self.get_key()]
ret[key] = {}
for field in listkeys(i):
value = {
'decoration': 'DEFAULT',
'optional': False,
'additional': 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()]]
and 'zero' in self.views[i[self.get_key()]][key]
else True
),
}
ret[i[self.get_key()]][key] = value
# Manage the hidden feature
# Allow to automatically hide fields when values is never different than 0
# Refactoring done for #2929
if not self.hide_zero:
value['hidden'] = False
elif key in self.views and field in self.views[key] and 'hidden' in self.views[key][field]:
value['hidden'] = self.views[key][field]['hidden']
if field in self.hide_zero_fields and i[field] != 0:
value['hidden'] = False
else:
value['hidden'] = field in self.hide_zero_fields
ret[key][field] = value
elif isinstance(self.get_raw(), dict) and self.get_raw() is not None:
# Stats are stored in a dict (ex: CPU, LOAD...)
for key in listkeys(self.get_raw()):
for field in listkeys(self.get_raw()):
value = {
'decoration': 'DEFAULT',
'optional': False,
'additional': 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
# Manage the hidden feature
# Allow to automatically hide fields when values is never different than 0
# Refactoring done for #2929
if not self.hide_zero:
value['hidden'] = False
elif field in self.views and 'hidden' in self.views[field]:
value['hidden'] = self.views[field]['hidden']
if field in self.hide_zero_fields and self.get_raw()[field] != 0:
value['hidden'] = False
else:
value['hidden'] = field in self.hide_zero_fields
ret[field] = value

self.views = ret

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

if key is None:
if key is None or key not in item_views:
return item_views
if option is None:
return item_views[key]
Expand Down
Loading

0 comments on commit 36755ba

Please sign in to comment.