Skip to content

Commit

Permalink
Add device filter flags to arp collector
Browse files Browse the repository at this point in the history
Allow filtering APR entries based on device. Useful for ignoring
entries for network namespaces (containers).

Signed-off-by: Ben Kochie <superq@gmail.com>
  • Loading branch information
SuperQ committed Dec 16, 2021
1 parent 2028460 commit eecc2b1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 13 additions & 2 deletions collector/arp_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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",
Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions collector/fixtures/proc/net/arp
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions end-to-end-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit eecc2b1

Please sign in to comment.