Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add device filter flags to arp collector #2254

Merged
merged 1 commit into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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