infiniband: Handle iWARP* RDMA modules N/A (#974)

* infiniband: Add not connected i40iw0/ports/1 fixtures
* infiniband: Handle issue when iWARP* RDMA modules are not available

This is related to #966, and handle this error,

Jun 07 13:33:24 hostname node_exporter[81888]: time="2018-06-07T13:33:24+02:00" level=error msg="ERROR: infiniband
collector failed after 0.000929s: strconv.ParseUint: parsing \"N/A (no PMA)\": invalid syntax" source="collector.go:132"

Signed-off-by: Mario Trangoni <mjtrangoni@gmail.com>
This commit is contained in:
Mario Trangoni 2018-10-04 15:05:59 +02:00 committed by Ben Kochie
commit 3659260b66
5 changed files with 116 additions and 1 deletions

View file

@ -20,6 +20,7 @@ import (
"errors"
"os"
"path/filepath"
"strings"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
@ -144,6 +145,15 @@ func infinibandPorts(infinibandPath, device string) ([]string, error) {
func readMetric(directory, metricFile string) (uint64, error) {
metric, err := readUintFromFile(filepath.Join(directory, metricFile))
if err != nil {
// Ugly workaround for handling #966, when counters are
// `N/A (not available)`.
// This was already patched and submitted, see
// https://www.spinics.net/lists/linux-rdma/msg68596.html
// Remove this as soon as the fix lands in the enterprise distros.
if strings.Contains(err.Error(), "N/A (no PMA)") {
log.Debugf("%q value is N/A", metricFile)
return 0, nil
}
log.Debugf("Error reading %q file", metricFile)
return 0, err
}