Handle nonexisting bonding_masters file (#569)

* silently ignore nonexisting bonding_masters file

Add an empty fixtures dir without a bonding_masters file to test.

* Moved the check to the Update() method

Dropped the empty test dir.
This commit is contained in:
Kai S 2017-04-24 21:19:17 +02:00 committed by Tobias Schmidt
parent e9aad0157c
commit 59f9b8c5c1
1 changed files with 7 additions and 1 deletions

View File

@ -23,6 +23,7 @@ import (
"strings"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
)
type bondingCollector struct {
@ -52,8 +53,13 @@ func NewBondingCollector() (Collector, error) {
// Update reads and exposes bonding states, implements Collector interface. Caution: This works only on linux.
func (c *bondingCollector) Update(ch chan<- prometheus.Metric) error {
bondingStats, err := readBondingStats(sysFilePath("class/net"))
statusfile := sysFilePath("class/net")
bondingStats, err := readBondingStats(statusfile)
if err != nil {
if os.IsNotExist(err) {
log.Debugf("Not collecting bonding, file does not exist: %s", statusfile)
return nil
}
return err
}
for master, status := range bondingStats {