Skip to content

Commit

Permalink
Add power draw field to nvidia_smi plugin (influxdata#4262)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcv81 authored and otherpirate committed Mar 15, 2019
1 parent 2a36d74 commit 974c7f1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
1 change: 1 addition & 0 deletions plugins/inputs/nvidia_smi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This plugin uses a query on the [`nvidia-smi`](https://developer.nvidia.com/nvid
- `memory_free` (integer, KB)
- `memory_used` (integer, KB)
- `memory_total` (integer, KB)
- `power_draw` (float, W)
- `temperature_gpu` (integer, degrees C)
- `utilization_gpu` (integer, percentage)
- `utilization_memory` (integer, percentage)
Expand Down
40 changes: 26 additions & 14 deletions plugins/inputs/nvidia_smi/nvidia_smi.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@ import (

var (
measurement = "nvidia_smi"
metrics = "fan.speed,memory.total,memory.used,memory.free,pstate,temperature.gpu,name,uuid,compute_mode,utilization.gpu,utilization.memory,index"
metrics = "fan.speed,memory.total,memory.used,memory.free,pstate,temperature.gpu,name,uuid,compute_mode,utilization.gpu,utilization.memory,index,power.draw"
metricNames = [][]string{
[]string{"fan_speed", "field"},
[]string{"memory_total", "field"},
[]string{"memory_used", "field"},
[]string{"memory_free", "field"},
[]string{"fan_speed", "integer"},
[]string{"memory_total", "integer"},
[]string{"memory_used", "integer"},
[]string{"memory_free", "integer"},
[]string{"pstate", "tag"},
[]string{"temperature_gpu", "field"},
[]string{"temperature_gpu", "integer"},
[]string{"name", "tag"},
[]string{"uuid", "tag"},
[]string{"compute_mode", "tag"},
[]string{"utilization_gpu", "field"},
[]string{"utilization_memory", "field"},
[]string{"utilization_gpu", "integer"},
[]string{"utilization_memory", "integer"},
[]string{"index", "tag"},
[]string{"power_draw", "float"},
}
)

Expand Down Expand Up @@ -127,7 +128,7 @@ func parseLine(line string) (map[string]string, map[string]interface{}, error) {
for i, m := range metricNames {
col := strings.TrimSpace(met[i])

// First handle the tags
// Handle the tags
if m[1] == "tag" {
tags[m[0]] = col
continue
Expand All @@ -137,12 +138,23 @@ func parseLine(line string) (map[string]string, map[string]interface{}, error) {
continue
}

// Then parse the integers out of the fields
out, err := strconv.ParseInt(col, 10, 64)
if err != nil {
return tags, fields, err
// Parse the integers
if m[1] == "integer" {
out, err := strconv.ParseInt(col, 10, 64)
if err != nil {
return tags, fields, err
}
fields[m[0]] = out
}

// Parse the floats
if m[1] == "float" {
out, err := strconv.ParseFloat(col, 64)
if err != nil {
return tags, fields, err
}
fields[m[0]] = out
}
fields[m[0]] = out
}

// Return the tags and fields
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/nvidia_smi/nvidia_smi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func TestParseLineStandard(t *testing.T) {
line := "85, 8114, 553, 7561, P2, 61, GeForce GTX 1070 Ti, GPU-d1911b8a-f5c8-5e66-057c-486561269de8, Default, 100, 93, 1\n"
line := "85, 8114, 553, 7561, P2, 61, GeForce GTX 1070 Ti, GPU-d1911b8a-f5c8-5e66-057c-486561269de8, Default, 100, 93, 1, 0.0\n"
tags, fields, err := parseLine(line)
if err != nil {
t.Fail()
Expand Down Expand Up @@ -37,7 +37,7 @@ func TestParseLineBad(t *testing.T) {
}

func TestParseLineNotSupported(t *testing.T) {
line := "[Not Supported], 7606, 0, 7606, P0, 38, Tesla P4, GPU-xxx, Default, 0, 0, 0\n"
line := "[Not Supported], 7606, 0, 7606, P0, 38, Tesla P4, GPU-xxx, Default, 0, 0, 0, 0.0\n"
_, fields, err := parseLine(line)
require.NoError(t, err)
require.Equal(t, nil, fields["fan_speed"])
Expand Down

0 comments on commit 974c7f1

Please sign in to comment.