From eecc2b1deab70279660daf92915ce0cf83329c04 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Thu, 16 Dec 2021 14:13:20 +0100 Subject: [PATCH] Add device filter flags to arp collector Allow filtering APR entries based on device. Useful for ignoring entries for network namespaces (containers). Signed-off-by: Ben Kochie --- CHANGELOG.md | 1 + collector/arp_linux.go | 15 +++++++++++++-- collector/fixtures/proc/net/arp | 1 + end-to-end-test.sh | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8eff0f40..f5671cd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * [BUGFIX] * [ENHANCEMENT] Add node_softirqs_total metric #2221 +* [ENHANCEMENT] Add device filter flags to arp collector #2254 ## 1.3.1 / 2021-12-01 diff --git a/collector/arp_linux.go b/collector/arp_linux.go index 99b8acfa..7592057d 100644 --- a/collector/arp_linux.go +++ b/collector/arp_linux.go @@ -25,11 +25,18 @@ import ( "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" + "gopkg.in/alecthomas/kingpin.v2" +) + +var ( + arpDeviceInclude = kingpin.Flag("collector.arp.device-include", "Regexp of arp devices to include (mutually exclusive to device-exclude).").String() + arpDeviceExclude = kingpin.Flag("collector.arp.device-exclude", "Regexp of arp devices to exclude (mutually exclusive to device-include).").String() ) type arpCollector struct { - entries *prometheus.Desc - logger log.Logger + deviceFilter netDevFilter + entries *prometheus.Desc + logger log.Logger } func init() { @@ -39,6 +46,7 @@ func init() { // NewARPCollector returns a new Collector exposing ARP stats. func NewARPCollector(logger log.Logger) (Collector, error) { return &arpCollector{ + deviceFilter: newNetDevFilter(*arpDeviceExclude, *arpDeviceInclude), entries: prometheus.NewDesc( prometheus.BuildFQName(namespace, "arp", "entries"), "ARP entries by device", @@ -98,6 +106,9 @@ func (c *arpCollector) Update(ch chan<- prometheus.Metric) error { } for device, entryCount := range entries { + if c.deviceFilter.ignored(device) { + continue + } ch <- prometheus.MustNewConstMetric( c.entries, prometheus.GaugeValue, float64(entryCount), device) } diff --git a/collector/fixtures/proc/net/arp b/collector/fixtures/proc/net/arp index 84c67f8c..3b9e4e76 100644 --- a/collector/fixtures/proc/net/arp +++ b/collector/fixtures/proc/net/arp @@ -5,3 +5,4 @@ IP address HW type Flags HW address Mask Device 192.168.1.4 0x1 0x2 dd:ee:ff:aa:bb:cc * eth1 192.168.1.5 0x1 0x2 ee:ff:aa:bb:cc:dd * eth1 192.168.1.6 0x1 0x2 ff:aa:bb:cc:dd:ee * eth1 +10.0.0.1 0x1 0x2 de:ad:be:ef:00:00 * nope diff --git a/end-to-end-test.sh b/end-to-end-test.sh index b458de59..8c1060e3 100755 --- a/end-to-end-test.sh +++ b/end-to-end-test.sh @@ -109,6 +109,7 @@ fi --collector.textfile.directory="collector/fixtures/textfile/two_metric_files/" \ --collector.wifi.fixtures="collector/fixtures/wifi" \ --collector.qdisc.fixtures="collector/fixtures/qdisc/" \ + --collector.arp.device-exclude="nope" \ --collector.netclass.ignored-devices="(dmz|int)" \ --collector.netclass.ignore-invalid-speed \ --collector.bcache.priorityStats \