You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gopsutil/host/host_windows.go

65 lines
1.0 KiB
Go

11 years ago
// +build windows
package host
11 years ago
import (
"os"
"time"
"github.com/StackExchange/wmi"
common "github.com/shirou/gopsutil/common"
process "github.com/shirou/gopsutil/process"
)
var (
procGetSystemTimeAsFileTime = common.Modkernel32.NewProc("GetSystemTimeAsFileTime")
11 years ago
)
type Win32_OperatingSystem struct {
LastBootUpTime time.Time
}
func HostInfo() (*HostInfoStat, error) {
ret := &HostInfoStat{}
11 years ago
hostname, err := os.Hostname()
if err != nil {
return ret, err
}
ret.Hostname = hostname
uptime, err := BootTime()
if err == nil {
ret.Uptime = uptime
}
procs, err := process.Pids()
if err != nil {
return ret, err
}
ret.Procs = uint64(len(procs))
11 years ago
return ret, nil
}
11 years ago
func BootTime() (uint64, error) {
now := time.Now()
var dst []Win32_OperatingSystem
q := wmi.CreateQuery(&dst, "")
err := wmi.Query(q, &dst)
if err != nil {
return 0, err
}
t := dst[0].LastBootUpTime.Local()
return uint64(now.Sub(t).Seconds()), nil
11 years ago
}
11 years ago
func Users() ([]UserStat, error) {
var ret []UserStat
11 years ago
return ret, nil
}