Add power draw field to nvidia_smi plugin (#4262)
This commit is contained in:
parent
33fdc2ef29
commit
397a9b3fce
|
@ -27,6 +27,7 @@ This plugin uses a query on the [`nvidia-smi`](https://developer.nvidia.com/nvid
|
||||||
- `memory_free` (integer, KB)
|
- `memory_free` (integer, KB)
|
||||||
- `memory_used` (integer, KB)
|
- `memory_used` (integer, KB)
|
||||||
- `memory_total` (integer, KB)
|
- `memory_total` (integer, KB)
|
||||||
|
- `power_draw` (float, W)
|
||||||
- `temperature_gpu` (integer, degrees C)
|
- `temperature_gpu` (integer, degrees C)
|
||||||
- `utilization_gpu` (integer, percentage)
|
- `utilization_gpu` (integer, percentage)
|
||||||
- `utilization_memory` (integer, percentage)
|
- `utilization_memory` (integer, percentage)
|
||||||
|
|
|
@ -16,20 +16,21 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
measurement = "nvidia_smi"
|
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{
|
metricNames = [][]string{
|
||||||
[]string{"fan_speed", "field"},
|
[]string{"fan_speed", "integer"},
|
||||||
[]string{"memory_total", "field"},
|
[]string{"memory_total", "integer"},
|
||||||
[]string{"memory_used", "field"},
|
[]string{"memory_used", "integer"},
|
||||||
[]string{"memory_free", "field"},
|
[]string{"memory_free", "integer"},
|
||||||
[]string{"pstate", "tag"},
|
[]string{"pstate", "tag"},
|
||||||
[]string{"temperature_gpu", "field"},
|
[]string{"temperature_gpu", "integer"},
|
||||||
[]string{"name", "tag"},
|
[]string{"name", "tag"},
|
||||||
[]string{"uuid", "tag"},
|
[]string{"uuid", "tag"},
|
||||||
[]string{"compute_mode", "tag"},
|
[]string{"compute_mode", "tag"},
|
||||||
[]string{"utilization_gpu", "field"},
|
[]string{"utilization_gpu", "integer"},
|
||||||
[]string{"utilization_memory", "field"},
|
[]string{"utilization_memory", "integer"},
|
||||||
[]string{"index", "tag"},
|
[]string{"index", "tag"},
|
||||||
|
[]string{"power_draw", "float"},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -127,7 +128,7 @@ func parseLine(line string) (map[string]string, map[string]interface{}, error) {
|
||||||
for i, m := range metricNames {
|
for i, m := range metricNames {
|
||||||
col := strings.TrimSpace(met[i])
|
col := strings.TrimSpace(met[i])
|
||||||
|
|
||||||
// First handle the tags
|
// Handle the tags
|
||||||
if m[1] == "tag" {
|
if m[1] == "tag" {
|
||||||
tags[m[0]] = col
|
tags[m[0]] = col
|
||||||
continue
|
continue
|
||||||
|
@ -137,12 +138,23 @@ func parseLine(line string) (map[string]string, map[string]interface{}, error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then parse the integers out of the fields
|
// Parse the integers
|
||||||
out, err := strconv.ParseInt(col, 10, 64)
|
if m[1] == "integer" {
|
||||||
if err != nil {
|
out, err := strconv.ParseInt(col, 10, 64)
|
||||||
return tags, fields, err
|
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
|
// Return the tags and fields
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParseLineStandard(t *testing.T) {
|
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)
|
tags, fields, err := parseLine(line)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -37,7 +37,7 @@ func TestParseLineBad(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseLineNotSupported(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)
|
_, fields, err := parseLine(line)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, nil, fields["fan_speed"])
|
require.Equal(t, nil, fields["fan_speed"])
|
||||||
|
|
Loading…
Reference in New Issue