Add DoSysctrl() to Linux's common utilities.

This commit is contained in:
Sean Chittenden 2016-08-11 00:48:24 -07:00
parent 4d0c402af6
commit 613ada987d
No known key found for this signature in database
GPG Key ID: 4EBC9DC16C2E5E16
1 changed files with 25 additions and 1 deletions

View File

@ -2,7 +2,31 @@
package common
import "os"
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())