forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nvidia_smi_test.go
151 lines (145 loc) · 4.65 KB
/
nvidia_smi_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package nvidia_smi
import (
"io/ioutil"
"path/filepath"
"testing"
"time"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require"
)
func TestGatherValidXML(t *testing.T) {
tests := []struct {
name string
filename string
expected []telegraf.Metric
}{
{
name: "GeForce GTX 1070 Ti",
filename: "gtx-1070-ti.xml",
expected: []telegraf.Metric{
testutil.MustMetric(
"nvidia_smi",
map[string]string{
"name": "GeForce GTX 1070 Ti",
"compute_mode": "Default",
"index": "0",
"pstate": "P8",
"uuid": "GPU-f9ba66fc-a7f5-94c5-da19-019ef2f9c665",
},
map[string]interface{}{
"clocks_current_graphics": 135,
"clocks_current_memory": 405,
"clocks_current_sm": 135,
"clocks_current_video": 405,
"encoder_stats_average_fps": 0,
"encoder_stats_average_latency": 0,
"encoder_stats_session_count": 0,
"fan_speed": 100,
"memory_free": 4054,
"memory_total": 4096,
"memory_used": 42,
"pcie_link_gen_current": 1,
"pcie_link_width_current": 16,
"temperature_gpu": 39,
"utilization_gpu": 0,
"utilization_memory": 0,
},
time.Unix(0, 0)),
},
},
{
name: "GeForce GTX 1660 Ti",
filename: "gtx-1660-ti.xml",
expected: []telegraf.Metric{
testutil.MustMetric(
"nvidia_smi",
map[string]string{
"compute_mode": "Default",
"index": "0",
"name": "Graphics Device",
"pstate": "P8",
"uuid": "GPU-304a277d-3545-63b8-3a36-dfde3c992989",
},
map[string]interface{}{
"clocks_current_graphics": 300,
"clocks_current_memory": 405,
"clocks_current_sm": 300,
"clocks_current_video": 540,
"cuda_version": "10.1",
"driver_version": "418.43",
"encoder_stats_average_fps": 0,
"encoder_stats_average_latency": 0,
"encoder_stats_session_count": 0,
"fbc_stats_average_fps": 0,
"fbc_stats_average_latency": 0,
"fbc_stats_session_count": 0,
"fan_speed": 0,
"memory_free": 5912,
"memory_total": 5912,
"memory_used": 0,
"pcie_link_gen_current": 1,
"pcie_link_width_current": 16,
"power_draw": 8.93,
"temperature_gpu": 40,
"utilization_gpu": 0,
"utilization_memory": 1,
"utilization_encoder": 0,
"utilization_decoder": 0,
},
time.Unix(0, 0)),
},
},
{
name: "Quadro P400",
filename: "quadro-p400.xml",
expected: []telegraf.Metric{
testutil.MustMetric(
"nvidia_smi",
map[string]string{
"compute_mode": "Default",
"index": "0",
"name": "Quadro P400",
"pstate": "P8",
"uuid": "GPU-8f750be4-dfbc-23b9-b33f-da729a536494",
},
map[string]interface{}{
"clocks_current_graphics": 139,
"clocks_current_memory": 405,
"clocks_current_sm": 139,
"clocks_current_video": 544,
"cuda_version": "10.1",
"driver_version": "418.43",
"encoder_stats_average_fps": 0,
"encoder_stats_average_latency": 0,
"encoder_stats_session_count": 0,
"fbc_stats_average_fps": 0,
"fbc_stats_average_latency": 0,
"fbc_stats_session_count": 0,
"fan_speed": 34,
"memory_free": 1998,
"memory_total": 1998,
"memory_used": 0,
"pcie_link_gen_current": 1,
"pcie_link_width_current": 16,
"temperature_gpu": 33,
"utilization_gpu": 0,
"utilization_memory": 3,
"utilization_encoder": 0,
"utilization_decoder": 0,
},
time.Unix(0, 0)),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var acc testutil.Accumulator
octets, err := ioutil.ReadFile(filepath.Join("testdata", tt.filename))
require.NoError(t, err)
err = gatherNvidiaSMI(octets, &acc)
require.NoError(t, err)
testutil.RequireMetricsEqual(t, tt.expected, acc.GetTelegrafMetrics(), testutil.IgnoreTime())
})
}
}