From 413e5af5021a95f8090db09a8a7d44ae43c60a3d Mon Sep 17 00:00:00 2001 From: Robert Clark Date: Thu, 9 Mar 2017 11:05:36 -0600 Subject: [PATCH] Skip metric files that don't exist In case a metric file within the InfiniBand collector doesn't exist, skip the metric in order to allow collection of the remaining valid InfiniBand metrics. Signed-Off-By: Robert Clark --- collector/infiniband_linux.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/collector/infiniband_linux.go b/collector/infiniband_linux.go index 9fbd3f99..0ec1bd8b 100644 --- a/collector/infiniband_linux.go +++ b/collector/infiniband_linux.go @@ -18,6 +18,7 @@ package collector import ( "errors" + "os" "path/filepath" "github.com/prometheus/client_golang/prometheus" @@ -158,6 +159,9 @@ func (c *infinibandCollector) Update(ch chan<- prometheus.Metric) error { // Add metrics for the InfiniBand counters. for metricName, infinibandMetric := range c.counters { + if _, err := os.Stat(filepath.Join(portFiles, "counters", infinibandMetric.File)); os.IsNotExist(err) { + continue + } metric, err := readMetric(filepath.Join(portFiles, "counters"), infinibandMetric.File) if err != nil { return err