open-nomad/vendor/github.com/shirou/gopsutil/internal/common/common_linux.go
James Nugent d778d9d566 Update gopsutil (#2927)
* deps: Update github.com/go-ole/go-ole/...

* deps: Update github.com/StackExchange/wmi

* deps: Update github.com/shirou/gopsutil/...

* deps: Update github.com/ugorji/go/codec
2017-07-28 09:46:44 -07:00

44 lines
763 B
Go

// +build linux
package common
import (
"os"
"os/exec"
"strings"
)
func DoSysctrl(mib string) ([]string, error) {
err := os.Setenv("LC_ALL", "C")
if err != nil {
return []string{}, err
}
sysctl, err := exec.LookPath("/sbin/sysctl")
if err != nil {
return []string{}, err
}
out, err := exec.Command(sysctl, "-n", mib).Output()
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()
list, err := f.Readdirnames(-1)
if err != nil {
return 0, err
}
return uint64(len(list)), err
}