mirror of
https://github.com/prometheus/node_exporter.git
synced 2025-02-02 08:42:31 -08:00
ethtool: Log stats collection errors.
Signed-off-by: W. Andrew Denton <git@flying-snail.net>
This commit is contained in:
parent
807f3c3af3
commit
892893ff05
|
@ -25,12 +25,14 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/go-kit/kit/log"
|
"github.com/go-kit/kit/log"
|
||||||
"github.com/go-kit/kit/log/level"
|
"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"
|
||||||
"github.com/safchain/ethtool"
|
"github.com/safchain/ethtool"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -138,8 +140,23 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
stats, err = c.stats.Stats(device)
|
stats, err = c.stats.Stats(device)
|
||||||
|
|
||||||
|
// If Stats() returns EOPNOTSUPP it doesn't support ethtool stats. Log that only at Debug level.
|
||||||
|
// Otherwise log it at Error level.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Suppressing errors because it's hard to tell what interfaces support ethtool and which don't.
|
if errno, ok := err.(syscall.Errno); ok {
|
||||||
|
if err == unix.EOPNOTSUPP {
|
||||||
|
level.Debug(c.logger).Log("msg", "ethtool stats error", "err", err, "device", device, "errno", uint(errno))
|
||||||
|
} else if errno != 0 {
|
||||||
|
level.Error(c.logger).Log("msg", "ethtool stats error", "err", err, "device", device, "errno", uint(errno))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
level.Error(c.logger).Log("msg", "ethtool stats error", "err", err, "device", device)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if stats == nil || len(stats) < 1 {
|
||||||
|
// No stats returned; device does not support ethtool stats.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import (
|
||||||
|
|
||||||
"github.com/go-kit/kit/log"
|
"github.com/go-kit/kit/log"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EthtoolFixture struct {
|
type EthtoolFixture struct {
|
||||||
|
@ -36,9 +37,9 @@ func (e *EthtoolFixture) Stats(intf string) (map[string]uint64, error) {
|
||||||
|
|
||||||
fixtureFile, err := os.Open(filepath.Join(e.fixturePath, intf))
|
fixtureFile, err := os.Open(filepath.Join(e.fixturePath, intf))
|
||||||
if e, ok := err.(*os.PathError); ok && e.Err == syscall.ENOENT {
|
if e, ok := err.(*os.PathError); ok && e.Err == syscall.ENOENT {
|
||||||
// The fixture for this interface doesn't exist. That's OK because it replicates
|
// The fixture for this interface doesn't exist. Translate that to unix.EOPNOTSUPP
|
||||||
// an interface that doesn't support ethtool.
|
// to replicate an interface that doesn't support ethtool stats
|
||||||
return res, nil
|
return res, unix.EOPNOTSUPP
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
|
@ -60,6 +61,9 @@ func (e *EthtoolFixture) Stats(intf string) (map[string]uint64, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
if items[0] == "ERROR" {
|
||||||
|
return res, unix.Errno(val)
|
||||||
|
}
|
||||||
res[items[0]] = val
|
res[items[0]] = val
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
collector/fixtures/ethtool/bond0
Normal file
1
collector/fixtures/ethtool/bond0
Normal file
|
@ -0,0 +1 @@
|
||||||
|
ERROR: 1
|
Loading…
Reference in a new issue