diff options
Diffstat (limited to 'src/go/collectors/go.d.plugin/modules/zfspool/exec.go')
-rw-r--r-- | src/go/collectors/go.d.plugin/modules/zfspool/exec.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/modules/zfspool/exec.go b/src/go/collectors/go.d.plugin/modules/zfspool/exec.go new file mode 100644 index 0000000000..0c155872e4 --- /dev/null +++ b/src/go/collectors/go.d.plugin/modules/zfspool/exec.go @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package zfspool + +import ( + "context" + "fmt" + "os/exec" + "time" + + "github.com/netdata/netdata/go/go.d.plugin/logger" +) + +func newZpoolCLIExec(binPath string, timeout time.Duration) *zpoolCLIExec { + return &zpoolCLIExec{ + binPath: binPath, + timeout: timeout, + } +} + +type zpoolCLIExec struct { + *logger.Logger + + binPath string + timeout time.Duration +} + +func (e *zpoolCLIExec) list() ([]byte, error) { + ctx, cancel := context.WithTimeout(context.Background(), e.timeout) + defer cancel() + + cmd := exec.CommandContext(ctx, e.binPath, "list", "-p") + e.Debugf("executing '%s'", cmd) + + bs, err := cmd.Output() + if err != nil { + return nil, fmt.Errorf("error on '%s': %v", cmd, err) + } + + return bs, nil +} |