提交 4addd06d 编写于 作者: W WAKAYAMA shirou

implements uptime on FreeBSD.

上级 ea83f563
......@@ -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
......
......@@ -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
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册