diff options
author | Kai S <kai@xs4all.nl> | 2017-04-24 21:19:17 +0200 |
---|---|---|
committer | Tobias Schmidt <tobidt@gmail.com> | 2017-04-24 23:19:17 +0400 |
commit | 59f9b8c5c1c65b4b975abba5fbdf1a171e394cf4 (patch) | |
tree | 73ea3708150e3a662804aa4aef3d0fe1f47f6fed /collector/bonding_linux.go | |
parent | e9aad0157c27560f319cb4ff9c57d90f1ed21665 (diff) | |
download | prometheus_node_collector-59f9b8c5c1c65b4b975abba5fbdf1a171e394cf4.tar.bz2 prometheus_node_collector-59f9b8c5c1c65b4b975abba5fbdf1a171e394cf4.tar.xz prometheus_node_collector-59f9b8c5c1c65b4b975abba5fbdf1a171e394cf4.zip |
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.
Diffstat (limited to 'collector/bonding_linux.go')
-rw-r--r-- | collector/bonding_linux.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/collector/bonding_linux.go b/collector/bonding_linux.go index 75f865e..fa9714b 100644 --- a/collector/bonding_linux.go +++ b/collector/bonding_linux.go | |||
@@ -23,6 +23,7 @@ import ( | |||
23 | "strings" | 23 | "strings" |
24 | 24 | ||
25 | "github.com/prometheus/client_golang/prometheus" | 25 | "github.com/prometheus/client_golang/prometheus" |
26 | "github.com/prometheus/common/log" | ||
26 | ) | 27 | ) |
27 | 28 | ||
28 | type bondingCollector struct { | 29 | type bondingCollector struct { |
@@ -52,8 +53,13 @@ func NewBondingCollector() (Collector, error) { | |||
52 | 53 | ||
53 | // Update reads and exposes bonding states, implements Collector interface. Caution: This works only on linux. | 54 | // Update reads and exposes bonding states, implements Collector interface. Caution: This works only on linux. |
54 | func (c *bondingCollector) Update(ch chan<- prometheus.Metric) error { | 55 | func (c *bondingCollector) Update(ch chan<- prometheus.Metric) error { |
55 | bondingStats, err := readBondingStats(sysFilePath("class/net")) | 56 | statusfile := sysFilePath("class/net") |
57 | bondingStats, err := readBondingStats(statusfile) | ||
56 | if err != nil { | 58 | if err != nil { |
59 | if os.IsNotExist(err) { | ||
60 | log.Debugf("Not collecting bonding, file does not exist: %s", statusfile) | ||
61 | return nil | ||
62 | } | ||
57 | return err | 63 | return err |
58 | } | 64 | } |
59 | for master, status := range bondingStats { | 65 | for master, status := range bondingStats { |