82 lines
2.6 KiB
Go
82 lines
2.6 KiB
Go
//go:build windows
|
|
|
|
package windows_system
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
type WindowsSystemCheckTools struct {
|
|
/*
|
|
* Win32 API
|
|
*/
|
|
Kernel32 *windows.LazyDLL
|
|
/*
|
|
* Performance Data Helper
|
|
*/
|
|
PDH *windows.LazyDLL
|
|
/*
|
|
* Windows memory information
|
|
*/
|
|
ProcGlobalMemoryStatusEx *windows.LazyProc
|
|
/*
|
|
* Windows processor information
|
|
*/
|
|
SystemTimes *windows.LazyProc
|
|
/*
|
|
* Windows uptime metrics
|
|
*/
|
|
Uptime *windows.LazyProc
|
|
/*
|
|
* Opening PDH queries
|
|
*/
|
|
ProcPdhOpenQuery *windows.LazyProc
|
|
/*
|
|
* Adding counters to open queries
|
|
*/
|
|
ProcPdhAddCounter *windows.LazyProc
|
|
/*
|
|
* Collecting query data
|
|
*/
|
|
ProcPdhCollectQueryData *windows.LazyProc
|
|
/*
|
|
* Extracting formatted query value from data
|
|
*/
|
|
ProcPdhGetFormattedCounterValue *windows.LazyProc
|
|
/*
|
|
* Closing PDH queries
|
|
*/
|
|
ProcPdhCloseQuery *windows.LazyProc
|
|
}
|
|
|
|
func GetWindowsTools() WindowsSystemCheckTools {
|
|
kernel32 := sync.OnceValue(func() *windows.LazyDLL { return windows.NewLazySystemDLL("kernel32.dll") })
|
|
pdh := sync.OnceValue(func() *windows.LazyDLL { return windows.NewLazySystemDLL("pdh.dll") })
|
|
|
|
procGlobalMemoryStatusEx := sync.OnceValue(func() *windows.LazyProc { return kernel32().NewProc("GlobalMemoryStatusEx") })
|
|
systemTimes := sync.OnceValue(func() *windows.LazyProc { return kernel32().NewProc("GetSystemTimes") })
|
|
uptime := sync.OnceValue(func() *windows.LazyProc { return kernel32().NewProc("GetTickCount64") })
|
|
|
|
// PDH functions
|
|
procPdhOpenQuery := sync.OnceValue(func() *windows.LazyProc { return pdh().NewProc("PdhOpenQueryW") })
|
|
procPdhAddCounter := sync.OnceValue(func() *windows.LazyProc { return pdh().NewProc("PdhAddEnglishCounterW") })
|
|
procPdhCollectQueryData := sync.OnceValue(func() *windows.LazyProc { return pdh().NewProc("PdhCollectQueryData") })
|
|
procPdhGetFormattedCounterValue := sync.OnceValue(func() *windows.LazyProc { return pdh().NewProc("PdhGetFormattedCounterValue") })
|
|
procPdhCloseQuery := sync.OnceValue(func() *windows.LazyProc { return pdh().NewProc("PdhCloseQuery") })
|
|
|
|
return WindowsSystemCheckTools{
|
|
Kernel32: kernel32(),
|
|
PDH: pdh(),
|
|
ProcGlobalMemoryStatusEx: procGlobalMemoryStatusEx(),
|
|
SystemTimes: systemTimes(),
|
|
Uptime: uptime(),
|
|
ProcPdhOpenQuery: procPdhOpenQuery(),
|
|
ProcPdhAddCounter: procPdhAddCounter(),
|
|
ProcPdhCollectQueryData: procPdhCollectQueryData(),
|
|
ProcPdhGetFormattedCounterValue: procPdhGetFormattedCounterValue(),
|
|
ProcPdhCloseQuery: procPdhCloseQuery(),
|
|
}
|
|
}
|