summaryrefslogtreecommitdiff
path: root/guestmetric/guestmetric.go
blob: 836f10511de0560753105b9e934fbb29f04a49f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package guestmetric

import (
	"bytes"
	"os/exec"
)

type GuestMetric map[string]string

type CollectFunc func() (GuestMetric, error)

type GuestMetricsCollector interface {
	CollectOS() (GuestMetric, error)
	CollectMisc() (GuestMetric, error)
	CollectNetworkAddr() (GuestMetric, error)
	CollectDisk() (GuestMetric, error)
	CollectMemory() (GuestMetric, error)
}

func runCmd(name string, args ...string) (output string, err error) {
	cmd := exec.Command(name, args...)
	var out bytes.Buffer
	cmd.Stdout = &out
	err = cmd.Run()
	if err != nil {
		return "", err
	}
	output = out.String()
	return output, nil
}

func prefixKeys(prefix string, m GuestMetric) GuestMetric {
	m1 := make(GuestMetric, 0)
	for k, v := range m {
		m1[prefix+k] = v
	}
	return m1
}