Merge pull request #2254 from prometheus/superq/arp_filter

Add device filter flags to arp collector
pull/2262/head
Ben Kochie 3 years ago committed by GitHub
commit 749b1a199e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,6 +6,7 @@
* [BUGFIX] * [BUGFIX]
* [ENHANCEMENT] Add node_softirqs_total metric #2221 * [ENHANCEMENT] Add node_softirqs_total metric #2221
* [ENHANCEMENT] Add device filter flags to arp collector #2254
## 1.3.1 / 2021-12-01 ## 1.3.1 / 2021-12-01

@ -25,11 +25,18 @@ import (
"github.com/go-kit/log" "github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus" "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 { type arpCollector struct {
entries *prometheus.Desc deviceFilter netDevFilter
logger log.Logger entries *prometheus.Desc
logger log.Logger
} }
func init() { func init() {
@ -39,6 +46,7 @@ func init() {
// NewARPCollector returns a new Collector exposing ARP stats. // NewARPCollector returns a new Collector exposing ARP stats.
func NewARPCollector(logger log.Logger) (Collector, error) { func NewARPCollector(logger log.Logger) (Collector, error) {
return &arpCollector{ return &arpCollector{
deviceFilter: newNetDevFilter(*arpDeviceExclude, *arpDeviceInclude),
entries: prometheus.NewDesc( entries: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "arp", "entries"), prometheus.BuildFQName(namespace, "arp", "entries"),
"ARP entries by device", "ARP entries by device",
@ -98,6 +106,9 @@ func (c *arpCollector) Update(ch chan<- prometheus.Metric) error {
} }
for device, entryCount := range entries { for device, entryCount := range entries {
if c.deviceFilter.ignored(device) {
continue
}
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.entries, prometheus.GaugeValue, float64(entryCount), device) c.entries, prometheus.GaugeValue, float64(entryCount), device)
} }

@ -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.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.5 0x1 0x2 ee:ff:aa:bb:cc:dd * eth1
192.168.1.6 0x1 0x2 ff:aa:bb:cc:dd:ee * 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

@ -109,6 +109,7 @@ fi
--collector.textfile.directory="collector/fixtures/textfile/two_metric_files/" \ --collector.textfile.directory="collector/fixtures/textfile/two_metric_files/" \
--collector.wifi.fixtures="collector/fixtures/wifi" \ --collector.wifi.fixtures="collector/fixtures/wifi" \
--collector.qdisc.fixtures="collector/fixtures/qdisc/" \ --collector.qdisc.fixtures="collector/fixtures/qdisc/" \
--collector.arp.device-exclude="nope" \
--collector.netclass.ignored-devices="(dmz|int)" \ --collector.netclass.ignored-devices="(dmz|int)" \
--collector.netclass.ignore-invalid-speed \ --collector.netclass.ignore-invalid-speed \
--collector.bcache.priorityStats \ --collector.bcache.priorityStats \

Loading…
Cancel
Save