summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolashennion@gmail.com>2024-06-01 11:02:58 +0200
committernicolargo <nicolashennion@gmail.com>2024-06-01 11:02:58 +0200
commitd0de547e4104b9667b39cb4dcdf31e119854adb2 (patch)
tree8addb1ba7cab7166f9ae1061f4c2cee56bc1de31
parentd00be3425593689d90b5067e97ac338c185f9c80 (diff)
Add support for automatically hiding network interfaces that are down or that don't have any IP addresses #2799
-rw-r--r--conf/glances.conf4
-rwxr-xr-xdocker-compose/glances.conf4
-rw-r--r--docs/aoa/network.rst6
-rw-r--r--docs/api.rst160
-rw-r--r--docs/config.rst30
-rw-r--r--docs/man/glances.132
-rw-r--r--glances/plugins/network/__init__.py16
7 files changed, 165 insertions, 87 deletions
diff --git a/conf/glances.conf b/conf/glances.conf
index 30931fc1..fb68fac2 100644
--- a/conf/glances.conf
+++ b/conf/glances.conf
@@ -216,6 +216,10 @@ tx_critical=90
hide=docker.*,lo
# Define the list of wireless network interfaces to be show (comma-separated)
#show=docker.*
+# Automatically hide interface not up (default is False)
+#hide_no_up=True
+# Automatically hide interface with no IP address (default is False)
+#hide_no_ip=True
# 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
diff --git a/docker-compose/glances.conf b/docker-compose/glances.conf
index 3d073744..67e982fd 100755
--- a/docker-compose/glances.conf
+++ b/docker-compose/glances.conf
@@ -216,6 +216,10 @@ tx_critical=90
#hide=docker.*,lo
# Define the list of wireless network interfaces to be show (comma-separated)
#show=docker.*
+# Automatically hide interface not up (default is False)
+hide_no_up=True
+# Automatically hide interface with no IP address (default is False)
+hide_no_ip=True
# 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
diff --git a/docs/aoa/network.rst b/docs/aoa/network.rst
index a1f116ac..d6b02d91 100644
--- a/docs/aoa/network.rst
+++ b/docs/aoa/network.rst
@@ -17,6 +17,8 @@ In this case thresholds values are define in bps.
Additionally, you can define:
- a list of network interfaces to hide
+- automatically hide interfaces not up
+- automatically hide interfaces without IP address
- per-interface limit values
- aliases for interface name
@@ -41,6 +43,10 @@ virtual docker interface (docker0, docker1, ...):
hide=docker.*,lo
# Define the list of network interfaces to show (comma-separated regexp)
#show=eth0,eth1
+ # Automatically hide interface not up (default is False)
+ hide_no_up=True
+ # Automatically hide interface with no IP address (default is False)
+ hide_no_ip=True
# WLAN 0 alias
wlan0_alias=Wireless IF
# It is possible to overwrite the bitrate thresholds per interface
diff --git a/docs/api.rst b/docs/api.rst
index bf15a090..fc011e2f 100644
--- a/docs/api.rst
+++ b/docs/api.rst
@@ -141,7 +141,7 @@ Get plugin stats::
"refresh": 3.0,
"regex": True,
"result": None,
- "timer": 0.3478415012359619},
+ "timer": 0.20159220695495605},
{"count": 0,
"countmax": 20.0,
"countmin": None,
@@ -150,7 +150,7 @@ Get plugin stats::
"refresh": 3.0,
"regex": True,
"result": None,
- "timer": 0.3477509021759033}]
+ "timer": 0.2015385627746582}]
Fields descriptions:
@@ -178,7 +178,7 @@ Get a specific item when field matches the given value::
"refresh": 3.0,
"regex": True,
"result": None,
- "timer": 0.3478415012359619}]}
+ "timer": 0.20159220695495605}]}
GET cloud
---------
@@ -265,14 +265,14 @@ Get plugin stats::
# curl http://localhost:61208/api/4/cpu
{"cpucore": 16,
- "ctx_switches": 308044421,
+ "ctx_switches": 363245993,
"guest": 0.0,
- "idle": 1.0,
- "interrupts": 272946404,
+ "idle": 0.0,
+ "interrupts": 310774900,
"iowait": 0.0,
"irq": 0.0,
"nice": 0.0,
- "soft_interrupts": 94947380,
+ "soft_interrupts": 110081877,
"steal": 0.0,
"syscalls": 0,
"system": 0.0,
@@ -320,10 +320,10 @@ Get plugin stats::
# curl http://localhost:61208/api/4/diskio
[{"disk_name": "nvme0n1",
"key": "disk_name",
- "read_bytes": 5076893184,
- "read_count": 211280,
- "write_bytes": 16891180032,
- "write_count": 974804},
+ "read_bytes": 5107998208,
+ "read_count": 213222,
+ "write_bytes": 19003274240,
+ "write_count": 1083418},
{"disk_name": "nvme0n1p1",
"key": "disk_name",
"read_bytes": 8103936,
@@ -363,10 +363,10 @@ Get a specific item when field matches the given value::
# curl http://localhost:61208/api/4/diskio/disk_name/nvme0n1
{"nvme0n1": [{"disk_name": "nvme0n1",
"key": "disk_name",
- "read_bytes": 5076893184,
- "read_count": 211280,
- "write_bytes": 16891180032,
- "write_count": 974804}]}
+ "read_bytes": 5107998208,
+ "read_count": 213222,
+ "write_bytes": 19003274240,
+ "write_count": 1083418}]}
GET folders
-----------
@@ -393,13 +393,13 @@ Get plugin stats::
# curl http://localhost:61208/api/4/fs
[{"device_name": "/dev/mapper/ubuntu--vg-ubuntu--lv",
- "free": 904218632192,
+ "free": 904231985152,
"fs_type": "ext4",
"key": "mnt_point",
"mnt_point": "/",
"percent": 5.1,
"size": 1003736440832,
- "used": 48455303168}]
+ "used": 48441950208}]
Fields descriptions:
@@ -420,13 +420,13 @@ Get a specific item when field matches the given value::
# curl http://localhost:61208/api/4/fs/mnt_point//
{"/": [{"device_name": "/dev/mapper/ubuntu--vg-ubuntu--lv",
- "free": 904218632192,
+ "free": 904231985152,
"fs_type": "ext4",
"key": "mnt_point",
"mnt_point": "/",
"percent": 5.1,
"size": 1003736440832,
- "used": 48455303168}]}
+ "used": 48441950208}]}
GET gpu
-------
@@ -500,9 +500,9 @@ Get plugin stats::
# curl http://localhost:61208/api/4/load
{"cpucore": 16,
- "min1": 1.04150390625,
- "min15": 0.9111328125,
- "min5": 1.05859375}
+ "min1": 1.11376953125,
+ "min15": 0.7109375,
+ "min5": 0.72509765625}
Fields descriptions:
@@ -514,7 +514,7 @@ Fields descriptions:
Get a specific field::
# curl http://localhost:61208/api/4/load/min1
- {"min1": 1.04150390625}
+ {"min1": 1.11376953125}
GET mem
-------
@@ -522,16 +522,16 @@ GET mem
Get plugin stats::
# curl http://localhost:61208/api/4/mem
- {"active": 8740761600,
- "available": 7811407872,
- "buffers": 431038464,
- "cached": 7773085696,
- "free": 7811407872,
- "inactive": 4876947456,
- "percent": 52.4,
- "shared": 893501440,
+ {"active": 8551362560,
+ "available": 7806128128,
+ "buffers": 376303616,
+ "cached": 7295451136,
+ "free": 7806128128,
+ "inactive": 4770967552,
+ "percent": 52.5,
+ "shared": 944717824,
"total": 16422486016,
- "used": 8611078144}
+ "used": 8616357888}
Fields descriptions:
@@ -558,13 +558,13 @@ GET memswap
Get plugin stats::
# curl http://localhost:61208/api/4/memswap
- {"free": 4293652480,
+ {"free": 4293390336,
"percent": 0.0,
"sin": 0,
- "sout": 118784,
+ "sout": 126976,
"time_since_update": 1,
"total": 4294963200,
- "used": 1310720}
+ "used": 1572864}
Fields descriptions:
@@ -589,15 +589,15 @@ Get plugin stats::
# curl http://localhost:61208/api/4/network
[{"alias": None,
"bytes_all": 0,
- "bytes_all_gauge": 2577813495,
+ "bytes_all_gauge": 4388860700,
"bytes_recv": 0,
- "bytes_recv_gauge": 2223235128,
+ "bytes_recv_gauge": 3993390925,
"bytes_sent": 0,
- "bytes_sent_gauge": 354578367,
+ "bytes_sent_gauge": 395469775,
"interface_name": "wlp0s20f3",
"key": "interface_name",
"speed": 0,
- "time_since_update": 0.35242390632629395}]
+ "time_since_update": 0.20540308952331543}]
Fields descriptions:
@@ -626,15 +626,15 @@ Get a specific item when field matches the given value::
# curl http://localhost:61208/api/4/network/interface_name/wlp0s20f3
{"wlp0s20f3": [{"alias": None,
"bytes_all": 0,
- "bytes_all_gauge": 2577813495,
+ "bytes_all_gauge": 4388860700,
"bytes_recv": 0,
- "bytes_recv_gauge": 2223235128,
+ "bytes_recv_gauge": 3993390925,
"bytes_sent": 0,
- "bytes_sent_gauge": 354578367,
+ "bytes_sent_gauge": 395469775,
"interface_name": "wlp0s20f3",
"key": "interface_name",
"speed": 0,
- "time_since_update": 0.35242390632629395}]}
+ "time_since_update": 0.20540308952331543}]}
GET now
-------
@@ -642,7 +642,7 @@ GET now
Get plugin stats::
# curl http://localhost:61208/api/4/now
- {"custom": "2024-05-28 13:29:16 CEST", "iso": "2024-05-28T13:29:16+02:00"}
+ {"custom": "2024-06-01 11:02:27 CEST", "iso": "2024-06-01T11:02:27+02:00"}
Fields descriptions:
@@ -652,7 +652,7 @@ Fields descriptions:
Get a specific field::
# curl http://localhost:61208/api/4/now/iso
- {"iso": "2024-05-28T13:29:16+02:00"}
+ {"iso": "2024-06-01T11:02:27+02:00"}
GET percpu
----------
@@ -719,7 +719,7 @@ Get plugin stats::
"port": 0,
"refresh": 30,
"rtt_warning": None,
- "status": 0.00586,
+ "status": 0.007192,
"timeout": 3}]
Fields descriptions:
@@ -747,7 +747,7 @@ Get a specific item when field matches the given value::
"port": 0,
"refresh": 30,
"rtt_warning": None,
- "status": 0.00586,
+ "status": 0.007192,
"timeout": 3}]}
GET processcount
@@ -756,7 +756,7 @@ GET processcount
Get plugin stats::
# curl http://localhost:61208/api/4/processcount
- {"pid_max": 0, "running": 0, "sleeping": 292, "thread": 1700, "total": 423}
+ {"pid_max": 0, "running": 0, "sleeping": 291, "thread": 1650, "total": 418}
Fields descriptions:
@@ -769,7 +769,7 @@ Fields descriptions:
Get a specific field::
# curl http://localhost:61208/api/4/processcount/total
- {"total": 423}
+ {"total": 418}
GET processlist
---------------
@@ -811,12 +811,12 @@ Get plugin stats::
# curl http://localhost:61208/api/4/quicklook
{"cpu": 0.0,
"cpu_hz": 4475000000.0,
- "cpu_hz_current": 1293040187.4999998,
+ "cpu_hz_current": 1536400499.9999998,
"cpu_log_core": 16,
"cpu_name": "13th Gen Intel(R) Core(TM) i7-13620H",
"cpu_phys_core": 10,
- "load": 5.7,
- "mem": 52.4,
+ "load": 4.4,
+ "mem": 52.5,
"percpu": [{"cpu_number": 0,
"guest": 0.0,
"guest_nice": 0.0,
@@ -937,7 +937,7 @@ Get plugin stats::
{"cpu_number": 9,
"guest": 0.0,
"guest_nice": 0.0,
- "idle": 1.0,
+ "idle": 0.0,
"iowait": 0.0,
"irq": 0.0,
"key": "cpu_number",
@@ -945,7 +945,7 @@ Get plugin stats::
"softirq": 0.0,
"steal": 0.0,
"system": 0.0,
- "total": 99.0,
+ "total": 100.0,
"user": 0.0},
{"cpu_number": 10,
"guest": 0.0,
@@ -1015,7 +1015,7 @@ Get plugin stats::
{"cpu_number": 15,
"guest": 0.0,
"guest_nice": 0.0,
- "idle": 0.0,
+ "idle": 1.0,
"iowait": 0.0,
"irq": 0.0,
"key": "cpu_number",
@@ -1023,7 +1023,7 @@ Get plugin stats::
"softirq": 0.0,
"steal": 0.0,
"system": 0.0,
- "total": 100.0,
+ "total": 99.0,
"user": 0.0}],
"swap": 0.0}
@@ -1063,14 +1063,14 @@ Get plugin stats::
"label": "Ambient",
"type": "temperature_core",
"unit": "C",
- "value": 34,
+ "value": 39,
"warning": 0},
{"critical": None,
"key": "label",
"label": "Ambient 3",
"type": "temperature_core",
"unit": "C",
- "value": 29,
+ "value": 31,
"warning": 0}]
Fields descriptions:
@@ -1131,7 +1131,7 @@ Get a specific item when field matches the given value::
"label": "Ambient",
"type": "temperature_core",
"unit": "C",
- "value": 34,
+ "value": 39,
"warning": 0}]}
GET smart
@@ -1175,7 +1175,7 @@ GET uptime
Get plugin stats::
# curl http://localhost:61208/api/4/uptime
- "14 days, 14:21:53"
+ "18 days, 11:55:00"
GET version
-----------
@@ -1192,8 +1192,8 @@ Get plugin stats::
# curl http://localhost:61208/api/4/wifi
[{"key": "ssid",
- "quality_level": -61.0,
- "quality_link": 49.0,
+ "quality_level": -60.0,
+ "quality_link": 50.0,
"ssid": "wlp0s20f3"}]
Get a specific field::
@@ -1205,8 +1205,8 @@ Get a specific item when field matches the given value::
# curl http://localhost:61208/api/4/wifi/ssid/wlp0s20f3
{"wlp0s20f3": [{"key": "ssid",
- "quality_level": -61.0,
- "quality_link": 49.0,
+ "quality_level": -60.0,
+ "quality_link": 50.0,
"ssid": "wlp0s20f3"}]}
GET all stats
@@ -1251,34 +1251,34 @@ GET stats history
History of a plugin::
# curl http://localhost:61208/api/4/cpu/history
- {"system": [["2024-05-28T13:29:18.134731", 0.0],
- ["2024-05-28T13:29:19.167225", 0.0],
- ["2024-05-28T13:29:20.241827", 0.0]],
- "user": [["2024-05-28T13:29:18.134716", 0.0],
- ["2024-05-28T13:29:19.167219", 2.0],
- ["2024-05-28T13:29:20.241811", 2.0]]}
+ {"system": [["2024-06-01T11:02:28.510012", 0.0],
+ ["2024-06-01T11:02:29.538825", 0.0],
+ ["2024-06-01T11:02:30.595929", 0.0]],
+ "user": [["2024-06-01T11:02:28.510001", 0.0],
+ ["2024-06-01T11:02:29.538819", 0.0],
+ ["2024-06-01T11:02:30.595919", 0.0]]}
Limit history to last 2 values::
# curl http://localhost:61208/api/4/cpu/history/2
- {"system": [["2024-05-28T13:29:19.167225", 0.0],
- ["2024-05-28T13:29:20.241827", 0.0]],
- "user": [["2024-05-28T13:29:19.167219", 2.0],
- ["2024-05-28T13:29:20.241811", 2.0]]}
+ {"system": [["2024-06-01T11:02:29.538825", 0.0],
+ ["2024-06-01T11:02:30.595929", 0.0]],
+ "user": [["2024-06-01T11:02:29.538819", 0.0],
+ ["2024-06-01T11:02:30.595919", 0.0]]}
History for a specific field::
# curl http://localhost:61208/api/4/cpu/system/history
- {"system": [["2024-05-28T13:29:16.956417", 0.0],
- ["2024-05-28T13:29:18.134731", 0.0],
- ["2024-05-28T13:29:19.167225", 0.0],
- ["2024-05-28T13:29:20.241827", 0.0]]}
+ {"system": [["2024-06-01T11:02:27.412868", 0.0],
+ ["2024-06-01T11:02:28.510012", 0.0],
+ ["2024-06-01T11:02:29.538825", 0.0],
+ ["2024-06-01T11:02:30.595929", 0.0]]}
Limit history for a specific field to last 2 values::
# curl http://localhost:61208/api/4/cpu/system/history
- {"system": [["2024-05-28T13:29:19.167225", 0.0],
- ["2024-05-28T13:29:20.241827", 0.0]]}
+ {"system": [["2024-06-01T11:02:29.538825", 0.0],
+ ["2024-06-01T11:02:30.595929", 0.0]]}
GET limits (used for thresholds)
--------------------------------
diff --git a/docs/config.rst b/docs/config.rst
index d793b7ca..0c87a81b 100644
--- a/docs/config.rst
+++ b/docs/config.rst
@@ -60,17 +60,41 @@ than a second one concerning the user interface:
.. code-block:: ini
[outputs]
+ # Options for all UIs
+ #--------------------
# Separator in the Curses and WebUI interface (between top and others plugins)
separator=True
# Set the the Curses and WebUI interface left menu plugin list (comma-separated)
#left_menu=network,wifi,connections,ports,diskio,fs,irq,folders,raid,smart,sensors,now
- # Limit the number of processes to display (for the WebUI)
+ # Limit the number of processes to display (in the WebUI)
max_processes_display=25
- # Set the URL prefix (for the WebUI and the API)
+ # Options for WebUI
+ #------------------
+ # Set URL prefix for the WebUI and the API
# Example: url_prefix=/glances/ => http://localhost/glances/
- # The final / is mandatory
+ # Note: The final / is mandatory
# Default is no prefix (/)
#url_prefix=/glances/
+ # Set root path for WebUI statics files
+ # Why ? On Debian system, WebUI statics files are not provided.
+ # You can download it in a specific folder
+ # thanks to https://github.com/nicolargo/glances/issues/2021
+ # then configure this folder with the webui_root_path key
+ # Default is folder where glances_restfull_api.py is hosted
+ #webui_root_path=
+ # CORS options
+ # Comma separated list of origins that should be permitted to make cross-origin requests.
+ # Default is *
+ #cors_origins=*
+ # Indicate that cookies should be supported for cross-origin requests.
+ # Default is True
+ #cors_credentials=True
+ # Comma separated list of HTTP methods that should be allowed for cross-origin requests.
+ # Default is *
+ #cors_methods=*
+ # Comma separated list of HTTP request headers that should be supported for cross-origin requests.
+ # Default is *
+ #cors_headers=*
Each plugin, export module, and application monitoring process (AMP) can
have a section. Below is an example for the CPU plugin:
diff --git a/docs/man/glances.1 b/docs/man/glances.1
index 4c917635..d388a908 100644
--- a/docs/man/glances.1
+++ b/docs/man/glances.1
@@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
-.TH "GLANCES" "1" "May 28, 2024" "4.1.0_beta01" "Glances"
+.TH "GLANCES" "1" "Jun 01, 2024" "4.1.0_beta01" "Glances"
.SH NAME
glances \- An eye on your system
.SH SYNOPSIS
@@ -641,17 +641,41 @@ than a second one concerning the user interface:
.nf
.ft C
[outputs]
+# Options for all UIs
+#\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
# Separator in the Curses and WebUI interface (between top and others plugins)
separator=True
# Set the the Curses and WebUI interface left menu plugin list (comma\-separated)
#left_menu=network,wifi,connections,ports,diskio,fs,irq,folders,raid,smart,sensors,now
-# Limit the number of processes to display (for the WebUI)
+# Limit the number of processes to display (in the WebUI)
max_processes_display=25
-# Set the URL prefix (for the WebUI and the API)
+# Options for WebUI
+#\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
+# Set URL prefix for the WebUI and the API
# Example: url_prefix=/glances/ => http://localhost/glances/
-# The final / is mandatory
+# Note: The final / is mandatory
# Default is no prefix (/)
#url_prefix=/glances/
+# Set root path for WebUI statics files
+# Why ? On Debian system, WebUI statics files are not provided.
+# You can download it in a specific folder
+# thanks to https://github.com/nicolargo/glances/issues/2021
+# then configure this folder with the webui_root_path key
+# Default is folder where glances_restfull_api.py is hosted
+#webui_root_path=
+# CORS options
+# Comma separated list of origins that should be permitted to make cross\-origin requests.
+# Default is *
+#cors_origins=*
+# Indicate that cookies should be supported for cross\-origin requests.
+# Default is True
+#cors_credentials=True
+# Comma separated list of HTTP methods that should be allowed for cross\-origin requests.
+# Default is *
+#cors_methods=*
+# Comma separated list of HTTP request headers that should be supported for cross\-origin requests.
+# Default is *
+#cors_headers=*
.ft P
.fi
.UNINDENT
diff --git a/glances/plugins/network/__init__.py b/glances/plugins/network/__init__.py
index 396a1d4f..15427806 100644
--- a/glances/plugins/network/__init__.py
+++ b/glances/plugins/network/__init__.py
@@ -88,6 +88,11 @@ class PluginModel(GlancesPluginModel):
self.hide_zero = False
self.hide_zero_fields = ['bytes_recv', 'bytes_sent']
+ # Add support for automatically hiding network interfaces that are down
+ # or that don't have any IP addresses #2799
+ self.hide_no_up = config.get_bool_value(self.plugin_name, 'hide_no_up', default=False)
+ self.hide_no_ip = config.get_bool_value(self.plugin_name, 'hide_no_ip', default=False)
+
# Force a first update because we need two updates to have the first stat
self.update()
self.refresh_timer.set(0)
@@ -140,10 +145,21 @@ class PluginModel(GlancesPluginModel):
net_status = {}
try:
net_status = psutil.net_if_stats()
+ net_addrs = psutil.net_if_addrs()
except OSError as e:
# see psutil #797/glances #1106
logger.debug(f'Can not get network interface status ({e})')
+ # Filter interfaces (related to #2799)
+ if self.hide_no_up:
+ net_status = {k: v for k, v in net_status.items() if v.isup}
+ if self.hide_no_ip:
+ net_status = {
+ k: v
+ for k, v in net_status.items()
+ if k in net_addrs and any(a.family != psutil.AF_LINK for a in net_addrs[k])
+ }
+
for interface_name, interface_stat in net_io_counters.items():
# Do not take hidden interface into account
# or KeyError: 'eth0' when interface is not connected #1348