From 5fed4f01e9a617ea099d5637f59bfcbc5aa3fc26 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Sat, 13 Jun 2020 11:07:01 +0200 Subject: [PATCH] Handle no data from powersupplyclass Handle the case when /sys/class/power_supply doesn't exist. Fixes logging error spam. Requires https://github.com/prometheus/procfs/pull/308 Signed-off-by: Ben Kochie --- CHANGELOG.md | 2 +- collector/powersupplyclass.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f32b944..4c4ce354 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ * [CHANGE] * [FEATURE] * [ENHANCEMENT] -* [BUGFIX] +* [BUGFIX] Handle no data from powersupplyclass ## 1.0.0 / 2020-05-25 diff --git a/collector/powersupplyclass.go b/collector/powersupplyclass.go index 988b0eed..368235ea 100644 --- a/collector/powersupplyclass.go +++ b/collector/powersupplyclass.go @@ -18,6 +18,7 @@ package collector import ( "fmt" + "os" "regexp" "github.com/go-kit/kit/log" @@ -54,6 +55,9 @@ func NewPowerSupplyClassCollector(logger log.Logger) (Collector, error) { func (c *powerSupplyClassCollector) Update(ch chan<- prometheus.Metric) error { powerSupplyClass, err := getPowerSupplyClassInfo(c.ignoredPattern) if err != nil { + if os.IsNotExist(err) { + return ErrNoData + } return fmt.Errorf("could not get power_supply class info: %s", err) } for _, powerSupply := range powerSupplyClass {