mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-11 15:36:37 +00:00
45
pkg/headers/psapi/psapi.go
Normal file
45
pkg/headers/psapi/psapi.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package psapi
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// PerformanceInformation is a wrapper of the PERFORMANCE_INFORMATION struct.
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/psapi/ns-psapi-performance_information
|
||||
type PerformanceInformation struct {
|
||||
cb uint32
|
||||
CommitTotal uint
|
||||
CommitLimit uint
|
||||
CommitPeak uint
|
||||
PhysicalTotal uint
|
||||
PhysicalAvailable uint
|
||||
SystemCache uint
|
||||
KernelTotal uint
|
||||
KernelPaged uint
|
||||
KernelNonpaged uint
|
||||
PageSize uint
|
||||
HandleCount uint32
|
||||
ProcessCount uint32
|
||||
ThreadCount uint32
|
||||
}
|
||||
|
||||
var (
|
||||
psapi = windows.NewLazySystemDLL("psapi.dll")
|
||||
procGetPerformanceInfo = psapi.NewProc("GetPerformanceInfo")
|
||||
)
|
||||
|
||||
// GetPerformanceInfo returns the dereferenced version of GetLPPerformanceInfo.
|
||||
func GetPerformanceInfo() (PerformanceInformation, error) {
|
||||
var lppi PerformanceInformation
|
||||
size := (uint32)(unsafe.Sizeof(lppi))
|
||||
lppi.cb = size
|
||||
r1, _, err := procGetPerformanceInfo.Call(uintptr(unsafe.Pointer(&lppi)), uintptr(size))
|
||||
|
||||
if ret := *(*bool)(unsafe.Pointer(&r1)); !ret {
|
||||
return PerformanceInformation{}, err
|
||||
}
|
||||
|
||||
return lppi, nil
|
||||
}
|
||||
Reference in New Issue
Block a user