Skip to content

Commit 7024ce0

Browse files
Bjoern TeipelBjoern Teipel
authored andcommitted
multi_interface.py: Adding regular expression support for the exclude_interfaces parameter
1 parent 5260659 commit 7024ce0

2 files changed

Lines changed: 26 additions & 22 deletions

File tree

network/multi_interface/conf.d/multi_interface.pyconf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ modules {
1212
}
1313

1414
# Alternatively leave the interfaces list at value = "" then exclude
15-
# specific interfaces e.g. dummy, lo etc.
15+
# specific interfaces by name or regular expression e.g. dummy, lo, eth[0-9]+ etc.
1616
param excluded_interfaces {
17-
value = "dummy0 eth0_rename tunl0 gre0"
17+
value = "lo vnet[0-9]+"
1818
}
1919

2020

network/multi_interface/python_modules/multi_interface.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -113,27 +113,31 @@ def metric_cleanup():
113113
pass
114114

115115
def get_interfaces(watch_interfaces, excluded_interfaces):
116-
global INTERFACES
116+
global INTERFACES
117+
if_excluded = 0
117118

118-
# check if particular interfaces have been specifieid. Watch only those
119-
if watch_interfaces != "":
120-
INTERFACES = watch_interfaces.split(" ")
121-
122-
else:
123-
124-
if excluded_interfaces != "":
125-
excluded_if_list = excluded_interfaces.split(" ")
126-
127-
f = open(net_stats_file, "r")
128-
for line in f:
129-
# Find only lines with :
130-
if re.search(":", line):
131-
a = line.split(":")
132-
dev_name = a[0].lstrip()
133-
if dev_name not in excluded_if_list:
134-
INTERFACES.append(dev_name)
135-
136-
return 0
119+
# check if particular interfaces have been specifieid. Watch only those
120+
if watch_interfaces != "":
121+
INTERFACES = watch_interfaces.split(" ")
122+
else:
123+
if excluded_interfaces != "":
124+
excluded_if_list = excluded_interfaces.split(" ")
125+
f = open(net_stats_file, "r")
126+
for line in f:
127+
# Find only lines with :
128+
if re.search(":", line):
129+
a = line.split(":")
130+
dev_name = a[0].lstrip()
131+
132+
# Determine if interface is excluded by name or regex
133+
for ex in excluded_if_list:
134+
if re.match(ex,dev_name):
135+
if_excluded = 1
136+
137+
if not if_excluded:
138+
INTERFACES.append(dev_name)
139+
if_excluded = 0
140+
return 0
137141

138142

139143
def get_metrics():

0 commit comments

Comments
 (0)