mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-10 15:06:36 +00:00
Converted most metrics to non-wmi
Signed-off-by: Ben Ridley <benridley29@gmail.com>
This commit is contained in:
43
headers/sysinfoapi/sysinfoapi.go
Normal file
43
headers/sysinfoapi/sysinfoapi.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package sysinfoapi
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// MemoryStatusEx is a wrapper for MEMORYSTATUSEX
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-memorystatusex
|
||||
type MemoryStatusEx struct {
|
||||
dwLength uint32
|
||||
DwMemoryLoad uint32
|
||||
UllTotalPhys uint64
|
||||
UllAvailPhys uint64
|
||||
UllTotalPageFile uint64
|
||||
UllAvailPageFile uint64
|
||||
UllTotalVirtual uint64
|
||||
UllAvailVirtual uint64
|
||||
UllAvailExtendedVirtual uint64
|
||||
}
|
||||
|
||||
var (
|
||||
kernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
||||
procGetSystemInfo = kernel32.NewProc("GetSystemInfo")
|
||||
procGlobalMemoryStatusEx = kernel32.NewProc("GlobalMemoryStatusEx")
|
||||
)
|
||||
|
||||
// GlobalMemoryStatusEx retrieves information about the system's current usage of both physical and virtual memory.
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-globalmemorystatusex
|
||||
func GlobalMemoryStatusEx() (MemoryStatusEx, error) {
|
||||
var mse MemoryStatusEx
|
||||
mse.dwLength = (uint32)(unsafe.Sizeof(mse))
|
||||
pMse := uintptr(unsafe.Pointer(&mse))
|
||||
r1, _, err := procGlobalMemoryStatusEx.Call(pMse)
|
||||
|
||||
if ret := *(*bool)(unsafe.Pointer(&r1)); ret == false {
|
||||
// returned false
|
||||
return MemoryStatusEx{}, err
|
||||
}
|
||||
|
||||
return mse, nil
|
||||
}
|
||||
Reference in New Issue
Block a user