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 <superq@gmail.com>
This commit is contained in:
parent
2028460438
commit
eecc2b1dea
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 \
|
||||
|
|
Loading…
Reference in New Issue