shirou_gopsutil/host_windows.go

40 lines
692 B
Go
Raw Normal View History

2014-04-18 20:28:00 +08:00
// +build windows
2014-04-22 08:44:22 +08:00
package gopsutil
2014-04-18 20:28:00 +08:00
import (
2014-04-19 00:05:35 +08:00
"github.com/mitchellh/go-ps"
2014-04-18 20:28:00 +08:00
"os"
2014-04-18 21:02:35 +08:00
"syscall"
2014-04-18 20:28:00 +08:00
)
func (h Host) HostInfo() (HostInfo, error) {
ret := HostInfo{}
hostname, err := os.Hostname()
if err != nil {
return ret, err
}
ret.Hostname = hostname
2014-04-18 21:02:35 +08:00
kernel32, err := syscall.LoadLibrary("kernel32.dll")
if err != nil {
return ret, err
}
defer syscall.FreeLibrary(kernel32)
GetTickCount, _ := syscall.GetProcAddress(kernel32, "GetTickCount")
uptimemsec, _, err := syscall.Syscall(uintptr(GetTickCount), 0, 0, 0, 0)
ret.Uptime = int64(uptimemsec) / 1000
2014-04-19 00:05:35 +08:00
procs, err := ps.Processes()
if err != nil {
return ret, err
}
ret.Procs = uint64(len(procs))
2014-04-18 20:28:00 +08:00
return ret, nil
}