Silence missing netclass errors
* Handle no such file and permission denied errors. * Reduce excessive error wrapping. Fixes: https://github.com/prometheus/node_exporter/issues/1840 Signed-off-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
parent
57d572e194
commit
3c73a869af
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
* [BUGFIX] Handle errors from disabled PSI subsystem #1983
|
* [BUGFIX] Handle errors from disabled PSI subsystem #1983
|
||||||
* [BUGFIX] Sanitize strings from /sys/class/power_supply #1984
|
* [BUGFIX] Sanitize strings from /sys/class/power_supply #1984
|
||||||
|
* [BUGFIX] Silence missing netclass errors #1986
|
||||||
|
|
||||||
## 1.1.1 / 2021-02-12
|
## 1.1.1 / 2021-02-12
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,13 @@
|
||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"github.com/go-kit/kit/log"
|
"github.com/go-kit/kit/log"
|
||||||
|
"github.com/go-kit/kit/log/level"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/procfs/sysfs"
|
"github.com/prometheus/procfs/sysfs"
|
||||||
"gopkg.in/alecthomas/kingpin.v2"
|
"gopkg.in/alecthomas/kingpin.v2"
|
||||||
|
@ -61,6 +64,10 @@ func NewNetClassCollector(logger log.Logger) (Collector, error) {
|
||||||
func (c *netClassCollector) Update(ch chan<- prometheus.Metric) error {
|
func (c *netClassCollector) Update(ch chan<- prometheus.Metric) error {
|
||||||
netClass, err := c.getNetClassInfo()
|
netClass, err := c.getNetClassInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, os.ErrNotExist) || errors.Is(err, os.ErrPermission) {
|
||||||
|
level.Debug(c.logger).Log("msg", "Could not read netclass file", "err", err)
|
||||||
|
return ErrNoData
|
||||||
|
}
|
||||||
return fmt.Errorf("could not get net class info: %w", err)
|
return fmt.Errorf("could not get net class info: %w", err)
|
||||||
}
|
}
|
||||||
for _, ifaceInfo := range netClass {
|
for _, ifaceInfo := range netClass {
|
||||||
|
@ -173,9 +180,8 @@ func pushMetric(ch chan<- prometheus.Metric, subsystem string, name string, valu
|
||||||
|
|
||||||
func (c *netClassCollector) getNetClassInfo() (sysfs.NetClass, error) {
|
func (c *netClassCollector) getNetClassInfo() (sysfs.NetClass, error) {
|
||||||
netClass, err := c.fs.NetClass()
|
netClass, err := c.fs.NetClass()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return netClass, fmt.Errorf("error obtaining net class info: %w", err)
|
return netClass, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for device := range netClass {
|
for device := range netClass {
|
||||||
|
|
Loading…
Reference in New Issue