go.d intelgpu switch to using ndsudo (#17380)
Ilya Mashchenko committed
Apr 11, 2024 at 14:14 UTC
72a1f36dcc1878843c592de927520829b6173ad3
10 files changed
+34
-62
src/go/collectors/go.d.plugin/config/go.d/intelgpu.conf
-1
@@ -3,4 +3,3 @@
3
4
jobs:
5
- name: intelgpu
6
- binary_path: /usr/bin/intel_gpu_top
src/go/collectors/go.d.plugin/modules/intelgpu/config_schema.json
-12
@@ -10,17 +10,8 @@
10
"type": "integer",
11
"minimum": 1,
12
"default": 1
13
- },
14
- "binary_path": {
15
- "title": "Binary path",
16
- "description": "Path to the `intel_gpu_top` binary.",
17
- "type": "string",
18
- "default": "/usr/bin/intel_gpu_top"
13
}
14
},
21
- "required": [
22
- "binary_path"
23
- ],
15
"additionalProperties": false,
16
"patternProperties": {
17
"^name$": {}
@@ -29,9 +20,6 @@
20
"uiSchema": {
21
"uiOptions": {
22
"fullPage": true
32
- },
33
- "binary_path": {
34
- "ui:help": "If an absolute path is provided, the collector will use it directly; otherwise, it will search for the binary in directories specified in the PATH environment variable."
23
}
24
}
25
}
src/go/collectors/go.d.plugin/modules/intelgpu/exec.go
+11
-4
@@ -10,11 +10,14 @@ import (
10
"strconv"
11
"sync"
12
"time"
13
+
14
+ "github.com/netdata/netdata/go/go.d.plugin/logger"
15
)
16
15
-func newIntelGpuTopExec(binPath string, updateEvery int) (*intelGpuTopExec, error) {
17
+func newIntelGpuTopExec(ndsudoPath string, updateEvery int, log *logger.Logger) (*intelGpuTopExec, error) {
18
topExec := &intelGpuTopExec{
17
- binPath: binPath,
19
+ Logger: log,
20
+ ndsudoPath: ndsudoPath,
21
updateEvery: updateEvery,
22
}
23
@@ -26,7 +29,9 @@ func newIntelGpuTopExec(binPath string, updateEvery int) (*intelGpuTopExec, erro
29
}
30
31
type intelGpuTopExec struct {
29
- binPath string
32
+ *logger.Logger
33
+
34
+ ndsudoPath string
35
updateEvery int
36
37
cmd *exec.Cmd
@@ -42,7 +47,9 @@ func (e *intelGpuTopExec) run() error {
47
refresh = e.updateEvery*1000 - 500 // milliseconds
48
}
49
45
- cmd := exec.Command(e.binPath, "-J", "-s", strconv.Itoa(refresh))
50
+ cmd := exec.Command(e.ndsudoPath, "igt-json", "--interval", strconv.Itoa(refresh))
51
+
52
+ e.Debugf("executing '%s'", cmd)
53
54
r, err := cmd.StdoutPipe()
55
if err != nil {
src/go/collectors/go.d.plugin/modules/intelgpu/init.go
+8
-9
@@ -5,18 +5,17 @@ package intelgpu
5
import (
6
"fmt"
7
"os"
8
- "os/exec"
8
+ "path/filepath"
9
+
10
+ "github.com/netdata/netdata/go/go.d.plugin/agent/executable"
11
)
12
13
func (ig *IntelGPU) initIntelGPUTopExec() (intelGpuTop, error) {
12
- binPath := ig.BinaryPath
13
- if _, err := os.Stat(binPath); os.IsNotExist(err) {
14
- path, err := exec.LookPath(ig.binName)
15
- if err != nil {
16
- return nil, fmt.Errorf("error on lookup '%s': %v", ig.binName, err)
17
- }
18
- binPath = path
14
+ ndsudoPath := filepath.Join(executable.Directory, ig.ndsudoName)
15
+ if _, err := os.Stat(ndsudoPath); err != nil {
16
+ return nil, fmt.Errorf("ndsudo executable not found: %v", err)
17
+
18
}
19
21
- return newIntelGpuTopExec(binPath, ig.UpdateEvery)
20
+ return newIntelGpuTopExec(ndsudoPath, ig.UpdateEvery, ig.Logger)
21
}
src/go/collectors/go.d.plugin/modules/intelgpu/intelgpu.go
+6
-10
@@ -21,18 +21,14 @@ func init() {
21
22
func New() *IntelGPU {
23
return &IntelGPU{
24
- Config: Config{
25
- BinaryPath: "/usr/bin/intel_gpu_top",
26
- },
27
- binName: "intel_gpu_top",
28
- charts: charts.Copy(),
29
- engines: make(map[string]bool),
24
+ ndsudoName: "ndsudo",
25
+ charts: charts.Copy(),
26
+ engines: make(map[string]bool),
27
}
28
}
29
30
type Config struct {
34
- UpdateEvery int `yaml:"update_every" json:"update_every"`
35
- BinaryPath string `yaml:"binary_path" json:"binary_path"`
31
+ UpdateEvery int `yaml:"update_every" json:"update_every"`
32
}
33
34
type (
@@ -42,8 +38,8 @@ type (
38
39
charts *module.Charts
40
45
- exec intelGpuTop
46
- binName string
41
+ exec intelGpuTop
42
+ ndsudoName string
43
44
engines map[string]bool
45
}
src/go/collectors/go.d.plugin/modules/intelgpu/intelgpu_test.go
+2
-2
@@ -39,10 +39,10 @@ func TestIntelGPU_Init(t *testing.T) {
39
prepare func(igt *IntelGPU)
40
wantFail bool
41
}{
42
- "fails if can't find intel_gpu_top": {
42
+ "fails if can't locate ndsudo": {
43
wantFail: true,
44
prepare: func(igt *IntelGPU) {
45
- igt.binName += "!!!"
45
+ igt.ndsudoName += "!!!"
46
},
47
},
48
}
src/go/collectors/go.d.plugin/modules/intelgpu/metadata.yaml
+5
-21
@@ -23,8 +23,10 @@ modules:
23
overview:
24
data_collection:
25
metrics_description: |
26
- This collector monitors Intel integrated GPUs performance metrics using
27
- the [intel_gpu_top](https://manpages.debian.org/testing/intel-gpu-tools/intel_gpu_top.1.en.html) CLI tool.
26
+ This collector gathers performance metrics for Intel integrated GPUs.
27
+ It relies on the [`intel_gpu_top`](https://manpages.debian.org/testing/intel-gpu-tools/intel_gpu_top.1.en.html) CLI tool but avoids directly executing the binary.
28
+ Instead, it utilizes `ndsudo`, a Netdata helper specifically designed to run privileged commands securely within the Netdata environment.
29
+ This approach eliminates the need to grant the CAP_PERFMON capability to `intel_gpu_top`, improving security and potentially simplifying permission management.
30
method_description: ""
31
supported_platforms:
32
include: []
@@ -44,14 +46,6 @@ modules:
46
list:
47
- title: Install intel-gpu-tools
48
description: Install `intel-gpu-tools` using your distribution's package manager.
47
- - title: Add CAP_PERFMON to `intel_gpu_top`
48
- description: |
49
- When running as a normal user CAP_PERFMON is required to access performance monitoring.
50
- See [capabilities(7)](https://man7.org/linux/man-pages/man7/capabilities.7.html) and [setcap(8)](https://man7.org/linux/man-pages/man8/setcap.8.html).
51
-
52
- ```bash
53
- sudo setcap cap_perfmon=eip /usr/bin/intel_gpu_top
54
- ```
49
configuration:
50
file:
51
name: go.d/intelgpu.conf
@@ -66,21 +60,11 @@ modules:
60
description: Data collection frequency.
61
default_value: 1
62
required: false
69
- - name: binary_path
70
- description: Path to the `intel_gpu_top` binary. If an absolute path is provided, the collector will use it directly; otherwise, it will search for the binary in directories specified in the PATH environment variable.
71
- default_value: /usr/bin/intel_gpu_top
72
- required: true
63
examples:
64
folding:
65
title: Config
66
enabled: true
77
- list:
78
- - name: Custom binary path
79
- description: The executable is not in the directories specified in the PATH environment variable.
80
- config: |
81
- jobs:
82
- - name: nvidia_smi
83
- binary_path: /usr/local/sbin/intel_gpu_top
67
+ list: []
68
troubleshooting:
69
problems:
70
list: []
src/go/collectors/go.d.plugin/modules/intelgpu/testdata/config.json
+1
-2
@@ -1,4 +1,3 @@
1
{
2
- "update_every": 123,
3
- "binary_path": "ok"
2
+ "update_every": 123
3
}
src/go/collectors/go.d.plugin/modules/intelgpu/testdata/config.yaml
-1
@@ -1,2 +1 @@
1
update_every: 123
2
-binary_path: "ok"
src/go/collectors/go.d.plugin/modules/zfspool/init.go
+1
@@ -32,6 +32,7 @@ func (z *ZFSPool) initZPoolCLIExec() (zpoolCLI, error) {
32
}
33
34
zpoolExec := newZpoolCLIExec(binPath, z.Timeout.Duration())
35
+ zpoolExec.Logger = z.Logger
36
37
return zpoolExec, nil
38
}