Skip to content

Commit

Permalink
Add collector.ethtool.metrics-include
Browse files Browse the repository at this point in the history
This adds a new flag --collector.ethtool.metrics-include to the ethtool
collector. Only metrics matching this regexp will be collected.

Signed-off-by: Johannes 'fish' Ziemke <github@freigeist.org>
  • Loading branch information
discordianfish authored and oblitorum committed Apr 9, 2024
1 parent 04aa32d commit c68cae9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions collector/ethtool_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ import (
)

var (
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_`)
ethtoolIgnoredDevices = kingpin.Flag("collector.ethtool.ignored-devices", "Regexp of net devices to ignore for ethtool collector.").Default("^$").String()
ethtoolIncludedMetrics = kingpin.Flag("collector.ethtool.metrics-include", "Regexp of ethtool stats to include.").Default(".*").String()
receivedRegex = regexp.MustCompile(`_rx_`)
transmittedRegex = regexp.MustCompile(`_tx_`)
)

type EthtoolStats interface {
Expand All @@ -57,6 +58,7 @@ type ethtoolCollector struct {
fs sysfs.FS
entries map[string]*prometheus.Desc
ignoredDevicesPattern *regexp.Regexp
metricsPattern *regexp.Regexp
logger log.Logger
stats EthtoolStats
}
Expand All @@ -74,6 +76,7 @@ func makeEthtoolCollector(logger log.Logger) (*ethtoolCollector, error) {
return &ethtoolCollector{
fs: fs,
ignoredDevicesPattern: regexp.MustCompile(*ethtoolIgnoredDevices),
metricsPattern: regexp.MustCompile(*ethtoolIncludedMetrics),
logger: logger,
stats: &ethtoolStats{},
entries: map[string]*prometheus.Desc{
Expand Down Expand Up @@ -176,6 +179,9 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error {
sort.Strings(keys)

for _, metric := range keys {
if !c.metricsPattern.MatchString(metric) {
continue
}
val := stats[metric]
metricFQName := prometheus.BuildFQName(namespace, "ethtool", metric)
metricFQName = receivedRegex.ReplaceAllString(metricFQName, "_received_")
Expand Down

0 comments on commit c68cae9

Please sign in to comment.