diff --git a/host_freebsd.go b/host_freebsd.go new file mode 100644 index 0000000..b08895c --- /dev/null +++ b/host_freebsd.go @@ -0,0 +1,38 @@ +// +build freebsd + +package gopsutil + +import ( + "os" + "strings" + "strconv" +) + +func HostInfo() (HostInfoStat, error) { + ret := HostInfoStat{} + + hostname, err := os.Hostname() + ret.Hostname = hostname + if err != nil { + return ret, err + } + + return ret, nil +} + + +func Boot_time() (int64, error){ + values,err := do_sysctrl("kern.boottime") + if err != nil { + return 0, err + } + // ex: { sec = 1392261637, usec = 627534 } Thu Feb 13 12:20:37 2014 + v := strings.Replace(values[2], ",", "", 1) + + boottime, err := strconv.ParseInt(v, 10, 64) + if err != nil { + return 0, err + } + + return boottime, nil +} diff --git a/host_unix.go b/host_linux.go similarity index 94% rename from host_unix.go rename to host_linux.go index 19ccff9..e1e6c1f 100644 --- a/host_unix.go +++ b/host_linux.go @@ -1,4 +1,4 @@ -// +build linux freebsd +// +build linux package gopsutil diff --git a/load_freebsd.go b/load_freebsd.go index 4217bdf..235896d 100644 --- a/load_freebsd.go +++ b/load_freebsd.go @@ -3,19 +3,14 @@ package gopsutil import ( - "os/exec" "strconv" - "strings" ) func LoadAvg() (LoadAvgStat, error) { - out, err := exec.Command("/sbin/sysctl", "-n", "vm.loadavg").Output() + values,err := do_sysctrl("vm.loadavg") if err != nil { return LoadAvgStat{}, err } - v := strings.Replace(string(out), "{ ", "", 1) - v = strings.Replace(string(v), " }", "", 1) - values := strings.Fields(string(v)) load1, err := strconv.ParseFloat(values[0], 64) if err != nil { diff --git a/mem_linux.go b/mem_linux.go index a85605b..e4b1e73 100644 --- a/mem_linux.go +++ b/mem_linux.go @@ -1,4 +1,4 @@ -// +build freebsd linux +// +build linux package gopsutil