From 1fb41a99592aafb53812f58b8ee0b6dcc50d691f Mon Sep 17 00:00:00 2001 From: WAKAYAMA shirou Date: Tue, 22 Apr 2014 12:04:16 +0900 Subject: [PATCH] linux file still exists. rename it. --- host_freebsd.go | 38 ++++++++++++++++++++++++++++++++++++++ host_linux.go | 29 +++++++++++++++++++++++++++++ host_unix.go | 29 ----------------------------- load_freebsd.go | 7 +------ mem_linux.go | 2 +- 5 files changed, 69 insertions(+), 36 deletions(-) create mode 100644 host_freebsd.go create mode 100644 host_linux.go delete mode 100644 host_unix.go 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_linux.go b/host_linux.go new file mode 100644 index 0000000..e1e6c1f --- /dev/null +++ b/host_linux.go @@ -0,0 +1,29 @@ +// +build linux + +package gopsutil + +import ( + "os" + "syscall" +) + +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){ + sysinfo := &syscall.Sysinfo_t{} + if err := syscall.Sysinfo(sysinfo); err != nil { + return 0, err + } + return sysinfo.Uptime, nil +} diff --git a/host_unix.go b/host_unix.go deleted file mode 100644 index 19ccff9..0000000 --- a/host_unix.go +++ /dev/null @@ -1,29 +0,0 @@ -// +build linux freebsd - -package gopsutil - -import ( - "os" - "syscall" -) - -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){ - sysinfo := &syscall.Sysinfo_t{} - if err := syscall.Sysinfo(sysinfo); err != nil { - return 0, err - } - return sysinfo.Uptime, nil -} 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