2015-04-04 00:22:31 +00:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package mem
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
"unsafe"
|
|
|
|
|
2015-05-22 23:45:14 +00:00
|
|
|
common "github.com/influxdb/telegraf/plugins/system/ps/common"
|
2015-04-04 00:22:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
procGlobalMemoryStatusEx = common.Modkernel32.NewProc("GlobalMemoryStatusEx")
|
|
|
|
)
|
|
|
|
|
|
|
|
type MEMORYSTATUSEX struct {
|
|
|
|
cbSize uint32
|
|
|
|
dwMemoryLoad uint32
|
|
|
|
ullTotalPhys uint64 // in bytes
|
|
|
|
ullAvailPhys uint64
|
|
|
|
ullTotalPageFile uint64
|
|
|
|
ullAvailPageFile uint64
|
|
|
|
ullTotalVirtual uint64
|
|
|
|
ullAvailVirtual uint64
|
|
|
|
ullAvailExtendedVirtual uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
func VirtualMemory() (*VirtualMemoryStat, error) {
|
|
|
|
var memInfo MEMORYSTATUSEX
|
|
|
|
memInfo.cbSize = uint32(unsafe.Sizeof(memInfo))
|
|
|
|
mem, _, _ := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&memInfo)))
|
|
|
|
if mem == 0 {
|
|
|
|
return nil, syscall.GetLastError()
|
|
|
|
}
|
|
|
|
|
|
|
|
ret := &VirtualMemoryStat{
|
|
|
|
Total: memInfo.ullTotalPhys,
|
|
|
|
Available: memInfo.ullAvailPhys,
|
|
|
|
UsedPercent: float64(memInfo.dwMemoryLoad),
|
|
|
|
}
|
|
|
|
|
|
|
|
ret.Used = ret.Total - ret.Available
|
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func SwapMemory() (*SwapMemoryStat, error) {
|
|
|
|
ret := &SwapMemoryStat{}
|
|
|
|
|
|
|
|
return ret, nil
|
|
|
|
}
|