shirou_gopsutil/host_unix.go

27 lines
386 B
Go
Raw Normal View History

2014-04-18 20:28:00 +08:00
// +build linux freebsd
2014-04-22 08:44:22 +08:00
package gopsutil
2014-04-18 20:28:00 +08:00
import (
"os"
"syscall"
)
func (h Host) HostInfo() (HostInfo, error) {
ret := HostInfo{}
2014-04-22 08:48:48 +08:00
2014-04-18 20:28:00 +08:00
hostname, err := os.Hostname()
ret.Hostname = hostname
2014-04-22 08:48:48 +08:00
if err != nil {
return ret, err
}
sysinfo := &syscall.Sysinfo_t{}
if err := syscall.Sysinfo(sysinfo); err != nil {
return ret, err
}
2014-04-18 20:28:00 +08:00
ret.Uptime = sysinfo.Uptime
return ret, nil
}