From 2bf2b51039192609c54387b27ab081b20286c060 Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Tue, 8 May 2018 13:11:12 -0700 Subject: [PATCH] Skip fields that report "not supported" in nvidia-smi (#4123) --- plugins/inputs/nvidia_smi/nvidia_smi.go | 9 +++++++-- plugins/inputs/nvidia_smi/nvidia_smi_test.go | 9 +++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/nvidia_smi/nvidia_smi.go b/plugins/inputs/nvidia_smi/nvidia_smi.go index 35e56c9b7..efac941b9 100644 --- a/plugins/inputs/nvidia_smi/nvidia_smi.go +++ b/plugins/inputs/nvidia_smi/nvidia_smi.go @@ -125,15 +125,20 @@ func parseLine(line string) (map[string]string, map[string]interface{}, error) { // Make sure there are as many metrics in the line as there were queried. if len(met) == len(metricNames) { for i, m := range metricNames { + col := strings.TrimSpace(met[i]) // First handle the tags if m[1] == "tag" { - tags[m[0]] = strings.TrimSpace(met[i]) + tags[m[0]] = col + continue + } + + if strings.Contains(col, "[Not Supported]") { continue } // Then parse the integers out of the fields - out, err := strconv.ParseInt(strings.TrimSpace(met[i]), 10, 64) + out, err := strconv.ParseInt(col, 10, 64) if err != nil { return tags, fields, err } diff --git a/plugins/inputs/nvidia_smi/nvidia_smi_test.go b/plugins/inputs/nvidia_smi/nvidia_smi_test.go index 62ddee3b8..573a69b19 100644 --- a/plugins/inputs/nvidia_smi/nvidia_smi_test.go +++ b/plugins/inputs/nvidia_smi/nvidia_smi_test.go @@ -2,6 +2,8 @@ package nvidia_smi import ( "testing" + + "github.com/stretchr/testify/require" ) func TestParseLineStandard(t *testing.T) { @@ -33,3 +35,10 @@ func TestParseLineBad(t *testing.T) { t.Fail() } } + +func TestParseLineNotSupported(t *testing.T) { + line := "[Not Supported], 7606, 0, 7606, P0, 38, Tesla P4, GPU-xxx, Default, 0, 0, 0\n" + _, fields, err := parseLine(line) + require.NoError(t, err) + require.Equal(t, nil, fields["fan_speed"]) +}