summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/modules/lvm/exec.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/go/collectors/go.d.plugin/modules/lvm/exec.go')
-rw-r--r--src/go/collectors/go.d.plugin/modules/lvm/exec.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/modules/lvm/exec.go b/src/go/collectors/go.d.plugin/modules/lvm/exec.go
new file mode 100644
index 0000000000..529cbdef3d
--- /dev/null
+++ b/src/go/collectors/go.d.plugin/modules/lvm/exec.go
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package lvm
+
+import (
+ "context"
+ "fmt"
+ "os/exec"
+ "time"
+
+ "github.com/netdata/netdata/go/go.d.plugin/logger"
+)
+
+func newLVMCLIExec(ndsudoPath string, timeout time.Duration, log *logger.Logger) *lvmCLIExec {
+ return &lvmCLIExec{
+ Logger: log,
+ ndsudoPath: ndsudoPath,
+ timeout: timeout,
+ }
+}
+
+type lvmCLIExec struct {
+ *logger.Logger
+
+ ndsudoPath string
+ timeout time.Duration
+}
+
+func (e *lvmCLIExec) lvsReportJson() ([]byte, error) {
+ ctx, cancel := context.WithTimeout(context.Background(), e.timeout)
+ defer cancel()
+
+ cmd := exec.CommandContext(ctx,
+ e.ndsudoPath,
+ "lvs-report-json",
+ "--options",
+ "vg_name,lv_name,lv_size,data_percent,metadata_percent,lv_attr",
+ )
+ 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
+}