rpcfetch: implement Windows system stats fetching
Unfortunately I could not find any loadavg equivalent on Windows, so it returns a fixed value for now. Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
parent
1d28743f31
commit
0a1213edd5
54
fetch/apply_windows.go
Normal file
54
fetch/apply_windows.go
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
kernel32 = syscall.NewLazyDLL("kernel32.dll")
|
||||||
|
globalMemoryStatusEx = kernel32.NewProc("GlobalMemoryStatusEx")
|
||||||
|
)
|
||||||
|
|
||||||
|
type globalMemoryStatusExT struct {
|
||||||
|
dwLength uint32
|
||||||
|
dwMemoryLoad uint32
|
||||||
|
ullTotalPhys uint64
|
||||||
|
ullAvailPhys uint64
|
||||||
|
unused [5]uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if h, err := os.Hostname(); err != nil {
|
||||||
|
log.Fatalf("error reading hostname: %s", err)
|
||||||
|
} else {
|
||||||
|
hostname = h
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *applyState) populateLoadavg() {
|
||||||
|
if s.loadavg != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// loadavg is unsupported on Windows
|
||||||
|
s.loadavg = &[3]string{"0.00", "0.00", "0.00"}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *applyState) populateMem() {
|
||||||
|
if s.mem != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// failure defaults
|
||||||
|
s.mem = &[2]int{-1, -1}
|
||||||
|
|
||||||
|
v := new(globalMemoryStatusExT)
|
||||||
|
v.dwLength = 64
|
||||||
|
r1, _, err := globalMemoryStatusEx.Call(uintptr(unsafe.Pointer(v)))
|
||||||
|
log.Printf("call to globalMemoryStatusEx, r1=%d, %s", r1, err)
|
||||||
|
s.mem[0] = int(v.ullAvailPhys / (1 << 10))
|
||||||
|
s.mem[1] = int(v.ullTotalPhys / (1 << 10))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user