From 9ad511ad05dd44866bfd59305244ae34bc89cce9 Mon Sep 17 00:00:00 2001 From: Tacitor Date: Sun, 20 Oct 2024 21:46:43 -0400 Subject: [PATCH] add the changes to give a threshold in the config to cut off small values --- conf/glances.conf | 5 ++++- docker-compose/glances.conf | 6 +++++- glances/plugins/diskio/__init__.py | 2 ++ glances/plugins/plugin/model.py | 6 ++++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/conf/glances.conf b/conf/glances.conf index aa034891..0a73282d 100644 --- a/conf/glances.conf +++ b/conf/glances.conf @@ -221,8 +221,9 @@ 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 -#TODO: change this to a Byte threshold "hide_threshold_bytes " hide_zero=False +# Set hide_threshold_bytes to an integer value to automatically hide interface with traffic less than this value +hide_threshold_bytes=0 # 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 @@ -285,6 +286,8 @@ disable=False hide=loop.*,/dev/loop.* # Set hide_zero to True to automatically hide disk with no read/write hide_zero=False +# Set hide_threshold_bytes to an integer value to automatically hide disk with read/write less than this value +hide_threshold_bytes=0 # Define the list of disks to be show (comma-separated) #show=sda.* # Alias for sda1 and sdb1 diff --git a/docker-compose/glances.conf b/docker-compose/glances.conf index ff80851d..07e95268 100755 --- a/docker-compose/glances.conf +++ b/docker-compose/glances.conf @@ -13,7 +13,7 @@ check_update=False # Default is 1200 values (~1h with the default refresh rate) history_size=1200 # Set the way Glances should display the date (default is %Y-%m-%d %H:%M:%S %Z) -#strftime_format=%Y-%m-%d %H:%M:%S %Z +# strftime_format=%Y-%m-%d %H:%M:%S %Z # Define external directory for loading additional plugins # The layout follows the glances standard for plugin definitions #plugin_dir=/home/user/dev/plugins @@ -222,6 +222,8 @@ hide_no_up=True hide_no_ip=True # Set hide_zero to True to automatically hide interface with no traffic hide_zero=False +# Set hide_threshold_bytes to an integer value to automatically hide interface with traffic less than this value +hide_threshold_bytes=0 # 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 @@ -284,6 +286,8 @@ disable=False hide=loop.*,/dev/loop.* # Set hide_zero to True to automatically hide disk with no read/write hide_zero=False +# Set hide_threshold_bytes to an integer value to automatically hide disk with read/write less than this value +hide_threshold_bytes=0 # Define the list of disks to be show (comma-separated) #show=sda.* # Alias for sda1 and sdb1 diff --git a/glances/plugins/diskio/__init__.py b/glances/plugins/diskio/__init__.py index 8864b478..145c35e7 100644 --- a/glances/plugins/diskio/__init__.py +++ b/glances/plugins/diskio/__init__.py @@ -73,8 +73,10 @@ class PluginModel(GlancesPluginModel): # Hide stats if it has never been != 0 if config is not None: self.hide_zero = config.get_bool_value(self.plugin_name, 'hide_zero', default=False) + self.hide_threshold_bytes = config.get_int_value(self.plugin_name, 'hide_threshold_bytes', default=0) else: self.hide_zero = False + self.hide_threshold_bytes = 0 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 diff --git a/glances/plugins/plugin/model.py b/glances/plugins/plugin/model.py index 6bbba6fe..c38a2bf7 100644 --- a/glances/plugins/plugin/model.py +++ b/glances/plugins/plugin/model.py @@ -110,6 +110,8 @@ class GlancesPluginModel: # Hide stats if all the hide_zero_fields has never been != 0 # Default is False, always display stats self.hide_zero = False + # The threshold needed to display a value if hide_zero is true. Only hide a value if it is less than hide_threshold_bytes. + self.hide_threshold_bytes = 0 self.hide_zero_fields = [] # Set the initial refresh time to display stats the first time @@ -463,7 +465,7 @@ class GlancesPluginModel: 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: + if field in self.hide_zero_fields and i[field] >= self.hide_threshold_bytes: value['hidden'] = False else: value['hidden'] = field in self.hide_zero_fields @@ -485,7 +487,7 @@ class GlancesPluginModel: 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: + if field in self.hide_zero_fields and self.get_raw()[field] >= self.hide_threshold_bytes: value['hidden'] = False else: value['hidden'] = field in self.hide_zero_fields