go.d intelgpu add an option to select specific GPU (#17884)
go.d intel_gpu_top add an option to select specific GPU
Ilya Mashchenko committed
Jun 14, 2024 at 08:53 UTC
8575cb5ba10d8745469acf2b8bb0616f3fe7bdb1
7 files changed
+30
-10
src/go/collectors/go.d.plugin/modules/intelgpu/config_schema.json
+8
@@ -10,6 +10,11 @@
10
"type": "integer",
11
"minimum": 1,
12
"default": 1
13
+ },
14
+ "device": {
15
+ "title": "Device selector",
16
+ "description": "Select Intel GPU ([supported filters](https://manpages.debian.org/testing/intel-gpu-tools/intel_gpu_top.1.en.html#DEVICE_SELECTION)). Use `intel_gpu_top -L` for listing devices. If not set, defaults to first.",
17
+ "type": "string"
18
}
19
},
20
"additionalProperties": false,
@@ -20,6 +25,9 @@
25
"uiSchema": {
26
"uiOptions": {
27
"fullPage": true
28
+ },
29
+ "device": {
30
+ "ui:placeholder": "For systems with multiple GPUs, create separate data collection jobs and specify the device for each job."
31
}
32
}
33
}
src/go/collectors/go.d.plugin/modules/intelgpu/exec.go
+12
-7
@@ -14,11 +14,12 @@ import (
14
"github.com/netdata/netdata/go/go.d.plugin/logger"
15
)
16
17
-func newIntelGpuTopExec(ndsudoPath string, updateEvery int, log *logger.Logger) (*intelGpuTopExec, error) {
17
+func newIntelGpuTopExec(log *logger.Logger, ndsudoPath string, updateEvery int, device string) (*intelGpuTopExec, error) {
18
topExec := &intelGpuTopExec{
19
Logger: log,
20
ndsudoPath: ndsudoPath,
21
updateEvery: updateEvery,
22
+ device: device,
23
firstSampleTimeout: time.Second * 3,
24
}
25
@@ -34,6 +35,7 @@ type intelGpuTopExec struct {
35
36
ndsudoPath string
37
updateEvery int
38
+ device string
39
firstSampleTimeout time.Duration
40
41
cmd *exec.Cmd
@@ -44,7 +46,13 @@ type intelGpuTopExec struct {
46
}
47
48
func (e *intelGpuTopExec) run() error {
47
- cmd := exec.Command(e.ndsudoPath, "igt-json", "--interval", e.calcIntervalArg())
49
+ var cmd *exec.Cmd
50
+
51
+ if e.device != "" {
52
+ cmd = exec.Command(e.ndsudoPath, "igt-device-json", "--interval", e.calcIntervalArg(), "--device", e.device)
53
+ } else {
54
+ cmd = exec.Command(e.ndsudoPath, "igt-json", "--interval", e.calcIntervalArg())
55
+ }
56
57
e.Debugf("executing '%s'", cmd)
58
@@ -146,11 +154,8 @@ func (e *intelGpuTopExec) stop() error {
154
func (e *intelGpuTopExec) calcIntervalArg() string {
155
// intel_gpu_top appends the end marker ("},\n") of the previous sample to the beginning of the next sample.
156
// interval must be < than 'firstSampleTimeout'
149
- var interval int
150
- m := min(e.updateEvery, int(e.firstSampleTimeout.Seconds()))
151
- if m <= 1 {
152
- interval = 900
153
- } else {
157
+ interval := 900
158
+ if m := min(e.updateEvery, int(e.firstSampleTimeout.Seconds())); m > 1 {
159
interval = m*1000 - 500 // milliseconds
160
}
161
return strconv.Itoa(interval)
src/go/collectors/go.d.plugin/modules/intelgpu/init.go
+1
-1
@@ -17,5 +17,5 @@ func (ig *IntelGPU) initIntelGPUTopExec() (intelGpuTop, error) {
17
18
}
19
20
- return newIntelGpuTopExec(ndsudoPath, ig.UpdateEvery, ig.Logger)
20
+ return newIntelGpuTopExec(ig.Logger, ndsudoPath, ig.UpdateEvery, ig.Device)
21
}
src/go/collectors/go.d.plugin/modules/intelgpu/intelgpu.go
+2
-1
@@ -29,7 +29,8 @@ func New() *IntelGPU {
29
}
30
31
type Config struct {
32
- UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
32
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
33
+ Device string `yaml:"device,omitempty" json:"device"`
34
}
35
36
type (
src/go/collectors/go.d.plugin/modules/intelgpu/metadata.yaml
+4
@@ -60,6 +60,10 @@ modules:
60
description: Data collection frequency.
61
default_value: 1
62
required: false
63
+ - name: device
64
+ description: 'Select a specific GPU using [supported filter](https://manpages.debian.org/testing/intel-gpu-tools/intel_gpu_top.1.en.html#DESCRIPTION).'
65
+ default_value: ""
66
+ required: false
67
examples:
68
folding:
69
title: Config
src/go/collectors/go.d.plugin/modules/intelgpu/testdata/config.json
+2
-1
@@ -1,3 +1,4 @@
1
{
2
- "update_every": 123
2
+ "update_every": 123,
3
+ "device": "ok"
4
}
src/go/collectors/go.d.plugin/modules/intelgpu/testdata/config.yaml
+1
@@ -1 +1,2 @@
1
update_every: 123
2
+device: "ok"