2017-02-01 18:26:00 +00:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func DoSysctrl(mib string) ([]string, error) {
|
|
|
|
sysctl, err := exec.LookPath("/sbin/sysctl")
|
|
|
|
if err != nil {
|
|
|
|
return []string{}, err
|
|
|
|
}
|
2018-10-19 18:33:23 +00:00
|
|
|
cmd := exec.Command(sysctl, "-n", mib)
|
|
|
|
cmd.Env = getSysctrlEnv(os.Environ())
|
|
|
|
out, err := cmd.Output()
|
2017-02-01 18:26:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return []string{}, err
|
|
|
|
}
|
|
|
|
v := strings.Replace(string(out), "{ ", "", 1)
|
|
|
|
v = strings.Replace(string(v), " }", "", 1)
|
|
|
|
values := strings.Fields(string(v))
|
|
|
|
|
|
|
|
return values, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NumProcs() (uint64, error) {
|
|
|
|
f, err := os.Open(HostProc())
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
2018-10-19 18:33:23 +00:00
|
|
|
|
|
|
|
list, err := f.Readdirnames(-1)
|
2017-02-01 18:26:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return uint64(len(list)), err
|
|
|
|
}
|