Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip fields that report "not supported" in nvidia-smi #4123

Merged
merged 1 commit into from
May 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions plugins/inputs/nvidia_smi/nvidia_smi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions plugins/inputs/nvidia_smi/nvidia_smi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package nvidia_smi

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestParseLineStandard(t *testing.T) {
Expand Down Expand Up @@ -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"])
}