Add --collector.ethtool.ignored-devices
Other network related collectors allow to filter out unwanted devices. Add this support to the new ethtool collector as well. Signed-off-by: Benjamin Drung <benjamin.drung@ionos.com>
This commit is contained in:
parent
4d0c1650b5
commit
3afd382e75
|
@ -33,11 +33,13 @@ import (
|
|||
"github.com/prometheus/procfs/sysfs"
|
||||
"github.com/safchain/ethtool"
|
||||
"golang.org/x/sys/unix"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
receivedRegex = regexp.MustCompile(`_rx_`)
|
||||
transmittedRegex = regexp.MustCompile(`_tx_`)
|
||||
ethtoolIgnoredDevices = kingpin.Flag("collector.ethtool.ignored-devices", "Regexp of net devices to ignore for ethtool collector.").Default("^$").String()
|
||||
receivedRegex = regexp.MustCompile(`_rx_`)
|
||||
transmittedRegex = regexp.MustCompile(`_tx_`)
|
||||
)
|
||||
|
||||
type EthtoolStats interface {
|
||||
|
@ -52,10 +54,11 @@ func (e *ethtoolStats) Stats(intf string) (map[string]uint64, error) {
|
|||
}
|
||||
|
||||
type ethtoolCollector struct {
|
||||
fs sysfs.FS
|
||||
entries map[string]*prometheus.Desc
|
||||
logger log.Logger
|
||||
stats EthtoolStats
|
||||
fs sysfs.FS
|
||||
entries map[string]*prometheus.Desc
|
||||
ignoredDevicesPattern *regexp.Regexp
|
||||
logger log.Logger
|
||||
stats EthtoolStats
|
||||
}
|
||||
|
||||
// makeEthtoolCollector is the internal constructor for EthtoolCollector.
|
||||
|
@ -69,8 +72,10 @@ func makeEthtoolCollector(logger log.Logger) (*ethtoolCollector, error) {
|
|||
|
||||
// Pre-populate some common ethtool metrics.
|
||||
return ðtoolCollector{
|
||||
fs: fs,
|
||||
stats: ðtoolStats{},
|
||||
fs: fs,
|
||||
ignoredDevicesPattern: regexp.MustCompile(*ethtoolIgnoredDevices),
|
||||
logger: logger,
|
||||
stats: ðtoolStats{},
|
||||
entries: map[string]*prometheus.Desc{
|
||||
"rx_bytes": prometheus.NewDesc(
|
||||
"node_ethtool_received_bytes_total",
|
||||
|
@ -108,7 +113,6 @@ func makeEthtoolCollector(logger log.Logger) (*ethtoolCollector, error) {
|
|||
[]string{"device"}, nil,
|
||||
),
|
||||
},
|
||||
logger: logger,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -139,6 +143,10 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error {
|
|||
var stats map[string]uint64
|
||||
var err error
|
||||
|
||||
if c.ignoredDevicesPattern.MatchString(device) {
|
||||
continue
|
||||
}
|
||||
|
||||
stats, err = c.stats.Stats(device)
|
||||
|
||||
// If Stats() returns EOPNOTSUPP it doesn't support ethtool stats. Log that only at Debug level.
|
||||
|
|
|
@ -96,6 +96,7 @@ func TestEthtoolCollector(t *testing.T) {
|
|||
prometheus.NewDesc("node_ethtool_transmitted_packets_total", "Network interface packets sent", []string{"device"}, nil).String(),
|
||||
}
|
||||
|
||||
*ethtoolIgnoredDevices = "^$"
|
||||
*sysPath = "fixtures/sys"
|
||||
|
||||
collector, err := NewEthtoolTestCollector(log.NewNopLogger())
|
||||
|
|
Loading…
Reference in New Issue