From 59f9b8c5c1c65b4b975abba5fbdf1a171e394cf4 Mon Sep 17 00:00:00 2001 From: Kai S Date: Mon, 24 Apr 2017 21:19:17 +0200 Subject: [PATCH] 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. --- collector/bonding_linux.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/collector/bonding_linux.go b/collector/bonding_linux.go index 75f865ea..fa9714ba 100644 --- a/collector/bonding_linux.go +++ b/collector/bonding_linux.go @@ -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 {