summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolas@nicolargo.com>2020-11-15 09:50:53 +0100
committernicolargo <nicolas@nicolargo.com>2020-11-15 09:50:53 +0100
commit7c1e039e3ac6b25a8c47048f7d39ad7c6b511e4a (patch)
tree1f4fc7af2c3fe008371010b0babcc9d819cc2095
parentbc0cf31a12f7ab2b8ab6db38fb16b6dfa308b02b (diff)
Filter docker containers #1748
-rw-r--r--conf/glances.conf6
-rw-r--r--docs/aoa/docker.rst4
-rw-r--r--docs/man/glances.111
-rw-r--r--glances/plugins/glances_docker.py6
-rw-r--r--glances/plugins/glances_plugin.py19
5 files changed, 31 insertions, 15 deletions
diff --git a/conf/glances.conf b/conf/glances.conf
index 6393a11f..587a2b26 100644
--- a/conf/glances.conf
+++ b/conf/glances.conf
@@ -327,7 +327,11 @@ port_default_gateway=True
[docker]
disable=False
-# Hide some containers (comma separeted list)
+# Only show specific containers (comma separeted list of container name or regular expression)
+# Comment this line to display all containers (default configuration)
+#show=telegraf
+# Hide some containers (comma separeted list of container name or regular expression)
+# Comment this line to display all containers (default configuration)
#hide=telegraf
# Define the maximum docker size name (default is 20 chars)
max_name_size=20
diff --git a/docs/aoa/docker.rst b/docs/aoa/docker.rst
index 0fb440ff..c21dc850 100644
--- a/docs/aoa/docker.rst
+++ b/docs/aoa/docker.rst
@@ -21,6 +21,10 @@ under the ``[docker]`` section:
[docker]
disable=False
+ # Only show specific containers (comma separeted list of container name or regular expression)
+ show=thiscontainer,andthisone,andthoseones.*
+ # Hide some containers (comma separeted list of container name or regular expression)
+ hide=donotshowthisone,andthose.*
# Define the maximum docker size name (default is 20 chars)
max_name_size=20
# Global containers' thresholds for CPU and MEM (in %)
diff --git a/docs/man/glances.1 b/docs/man/glances.1
index 170620fc..e20960cb 100644
--- a/docs/man/glances.1
+++ b/docs/man/glances.1
@@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
-.TH "GLANCES" "1" "Nov 07, 2020" "3.1.6_b1" "Glances"
+.TH "GLANCES" "1" "Nov 15, 2020" "3.1.6_b1" "Glances"
.SH NAME
glances \- An eye on your system
.
@@ -395,9 +395,6 @@ Sort processes by I/O rate
Show/hide IP module
.TP
.B \fBk\fP
-Kill selected process (only in curses/standalone mode)
-.TP
-.B \fBK\fP
Show/hide TCP connections
.TP
.B \fBl\fP
@@ -483,12 +480,6 @@ Enable/disable mean GPU mode
.B \fB/\fP
Switch between process command line or command name
.TP
-.B \fBUP\fP
-Up in the processes list
-.TP
-.B \fBDOWN\fP
-Down in the processes list
-.TP
.B \fBF5\fP
Refresh stats in curses user interface
.UNINDENT
diff --git a/glances/plugins/glances_docker.py b/glances/plugins/glances_docker.py
index 14f35af8..82dd1693 100644
--- a/glances/plugins/glances_docker.py
+++ b/glances/plugins/glances_docker.py
@@ -210,7 +210,11 @@ class Plugin(GlancesPlugin):
# Get stats for all containers
stats['containers'] = []
for container in containers:
- # Do not take hide container into account
+ # Only show specific containers
+ if not self.is_show(nativestr(container.name)):
+ continue
+
+ # Do not take hiden container into account
if self.is_hide(nativestr(container.name)):
continue
diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py
index 936db58c..e092ff05 100644
--- a/glances/plugins/glances_plugin.py
+++ b/glances/plugins/glances_plugin.py
@@ -752,6 +752,21 @@ class GlancesPlugin(object):
except KeyError:
return default
+ def is_show(self, value, header=""):
+ """Return True if the value is in the show configuration list.
+ If the show value is empty, return True (show by default)
+
+ The show configuration list is defined in the glances.conf file.
+ It is a comma separed list of regexp.
+ Example for diskio:
+ show=sda.*
+ """
+ # @TODO: possible optimisation: create a re.compile list
+ if self.get_conf_value('show', header=header) == []:
+ return True
+ else:
+ return any(j for j in [re.match(i, value) for i in self.get_conf_value('show', header=header)])
+
def is_hide(self, value, header=""):
"""Return True if the value is in the hide configuration list.
@@ -760,9 +775,7 @@ class GlancesPlugin(object):
Example for diskio:
hide=sda2,sda5,loop.*
"""
- # TODO: possible optimisation: create a re.compile list
- # Old version (see issue #1691)
- #return not all(j is None for j in [re.match(i, value.lower()) for i in self.get_conf_value('hide', header=header)])
+ # @TODO: possible optimisation: create a re.compile list
return any(j for j in [re.match(i, value) for i in self.get_conf_value('hide', header=header)])
def has_alias(self, header):