diff --git a/host.go b/host.go index d90c03f..ae3b327 100644 --- a/host.go +++ b/host.go @@ -8,7 +8,7 @@ import ( // This is not in the psutil but it useful. type HostInfoStat struct { Hostname string `json:"hostname"` - Uptime int64 `json:"uptime"` + Uptime uint64 `json:"uptime"` Procs uint64 `json:"procs"` // number of processes OS string `json:"os"` // ex: freebsd, linux Platform string `json:"platform"` // ex: ubuntu, linuxmint diff --git a/host_freebsd.go b/host_freebsd.go index 96a7832..71f05f8 100644 --- a/host_freebsd.go +++ b/host_freebsd.go @@ -7,19 +7,41 @@ import ( "encoding/binary" "io/ioutil" "os" + "os/exec" + "runtime" "strconv" "strings" "unsafe" ) func HostInfo() (*HostInfoStat, error) { - ret := &HostInfoStat{} + ret := &HostInfoStat{ + OS: runtime.GOOS, + PlatformFamily: "freebsd", + } hostname, err := os.Hostname() - ret.Hostname = hostname if err != nil { return ret, err } + ret.Hostname = hostname + + out, err := exec.Command("uname", "-s").Output() + if err == nil { + ret.Platform = strings.ToLower(strings.TrimSpace(string(out))) + } + + out, err = exec.Command("uname", "-r").Output() + if err == nil { + ret.PlatformVersion = strings.ToLower(strings.TrimSpace(string(out))) + } + + values, err := doSysctrl("kern.boottime") + if err == nil { + // ex: { sec = 1392261637, usec = 627534 } Thu Feb 13 12:20:37 2014 + v := strings.Replace(values[2], ",", "", 1) + ret.Uptime = mustParseUint64(v) + } return ret, nil }