diff options
Diffstat (limited to '')
-rw-r--r-- | src/go/plugin/go.d/modules/dmcache/exec.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/go/plugin/go.d/modules/dmcache/exec.go b/src/go/plugin/go.d/modules/dmcache/exec.go new file mode 100644 index 000000000..1cd11be31 --- /dev/null +++ b/src/go/plugin/go.d/modules/dmcache/exec.go @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package dmcache + +import ( + "context" + "fmt" + "os/exec" + "time" + + "github.com/netdata/netdata/go/plugins/logger" +) + +func newDmsetupExec(ndsudoPath string, timeout time.Duration, log *logger.Logger) *dmsetupExec { + return &dmsetupExec{ + Logger: log, + ndsudoPath: ndsudoPath, + timeout: timeout, + } +} + +type dmsetupExec struct { + *logger.Logger + + ndsudoPath string + timeout time.Duration +} + +func (e *dmsetupExec) cacheStatus() ([]byte, error) { + ctx, cancel := context.WithTimeout(context.Background(), e.timeout) + defer cancel() + + cmd := exec.CommandContext(ctx, e.ndsudoPath, "dmsetup-status-cache") + 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 +} |