From e656b79297b574d4766b82e3da2839d3e2b05de6 Mon Sep 17 00:00:00 2001 From: Jan Fajerski Date: Mon, 19 Apr 2021 16:21:06 +0200 Subject: [PATCH 1/2] netclass: retrieve interface names and filter before parsing We should filter excluded interfaces before parsing the interface details. This change is based on https://github.com/prometheus/procfs/pull/376 Signed-off-by: Jan Fajerski --- collector/netclass_linux.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/collector/netclass_linux.go b/collector/netclass_linux.go index a2984a5e..7d48b456 100644 --- a/collector/netclass_linux.go +++ b/collector/netclass_linux.go @@ -183,15 +183,21 @@ func pushMetric(ch chan<- prometheus.Metric, subsystem string, name string, valu } func (c *netClassCollector) getNetClassInfo() (sysfs.NetClass, error) { - netClass, err := c.fs.NetClass() + netClass := sysfs.NetClass{} + netDevices, err := c.fs.NetClassDevices() if err != nil { return netClass, err } - for device := range netClass { + for _, device := range netDevices { if c.ignoredDevicesPattern.MatchString(device) { - delete(netClass, device) + continue } + interfaceClass, err := c.fs.NetClassByIface(device) + if err != nil { + return netClass, err + } + netClass[device] = *interfaceClass } return netClass, nil From 8d99079a158f67a1863f0bdc86d1304ea6f9602f Mon Sep 17 00:00:00 2001 From: Jan Fajerski Date: Mon, 28 Jun 2021 10:54:21 +0200 Subject: [PATCH 2/2] mod: update procfs dependency to v0.7.0 Signed-off-by: Jan Fajerski --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 70880530..3c40a562 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/prometheus/client_model v0.2.0 github.com/prometheus/common v0.26.0 github.com/prometheus/exporter-toolkit v0.5.1 - github.com/prometheus/procfs v0.6.0 + github.com/prometheus/procfs v0.7.0 github.com/safchain/ethtool v0.0.0-20200804214954-8f958a28363a github.com/siebenmann/go-kstat v0.0.0-20200303194639-4e8294f9e9d5 github.com/soundcloud/go-runit v0.0.0-20150630195641-06ad41a06c4a diff --git a/go.sum b/go.sum index 5045e570..6e4d33a5 100644 --- a/go.sum +++ b/go.sum @@ -281,8 +281,8 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= -github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4= -github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= +github.com/prometheus/procfs v0.7.0 h1:OQZ41sZU9XkRpzrz8/TD0EldH/Rwbddkdu5wDyUwzfE= +github.com/prometheus/procfs v0.7.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=