Add --collector.netdev.device-whitelist flag (#1279)
* Add --collector.netdev.device-whitelist flag Sometimes it is desired to monitor only one netdev. The golang regexp does not support a negated regex, so the ignored-devices flag is too cumbersome for this task. This change introduces a new flag: accept-devices, which is mutually exclusive to ignored-devices. This flag allows specifying ONLY the netdev you'd like. Signed-off-by: Noam Meltzer <noam@cynerio.co>
This commit is contained in:
parent
fc02b5dfbc
commit
501ccf9fb4
7 changed files with 72 additions and 16 deletions
|
|
@ -19,14 +19,14 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestNetDevStats(t *testing.T) {
|
||||
func TestNetDevStatsIgnore(t *testing.T) {
|
||||
file, err := os.Open("fixtures/proc/net/dev")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
netStats, err := parseNetDevStats(file, regexp.MustCompile("^veth"))
|
||||
netStats, err := parseNetDevStats(file, regexp.MustCompile("^veth"), nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -59,3 +59,23 @@ func TestNetDevStats(t *testing.T) {
|
|||
t.Error("want fixture interface 💩0 to exist, but it does not")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNetDevStatsAccept(t *testing.T) {
|
||||
file, err := os.Open("fixtures/proc/net/dev")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
netStats, err := parseNetDevStats(file, nil, regexp.MustCompile("^💩0$"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if want, got := 1, len(netStats); want != got {
|
||||
t.Errorf("want count of devices to be %d, got %d", want, got)
|
||||
}
|
||||
if want, got := "72", netStats["💩0"]["receive_multicast"]; want != got {
|
||||
t.Error("want fixture interface 💩0 to exist, but it does not")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue