Fix windows counters on non english systems

This commit is contained in:
Johannes Drummer 2021-02-01 10:32:53 +01:00
parent a9a6146c93
commit 6e7f4ffe99
2 changed files with 5 additions and 4 deletions

View File

@ -72,6 +72,7 @@ var (
PdhOpenQuery = ModPdh.NewProc("PdhOpenQuery")
PdhAddCounter = ModPdh.NewProc("PdhAddCounterW")
PdhAddEnglishCounterW = ModPdh.NewProc("PdhAddEnglishCounterW")
PdhCollectQueryData = ModPdh.NewProc("PdhCollectQueryData")
PdhGetFormattedCounterValue = ModPdh.NewProc("PdhGetFormattedCounterValue")
PdhCloseQuery = ModPdh.NewProc("PdhCloseQuery")
@ -113,10 +114,10 @@ func CreateQuery() (windows.Handle, error) {
return query, nil
}
// CreateCounter with a PdhAddCounter call
// CreateCounter with a PdhAddEnglishCounterW call
func CreateCounter(query windows.Handle, pname, cname string) (*CounterInfo, error) {
var counter windows.Handle
r, _, err := PdhAddCounter.Call(
r, _, err := PdhAddEnglishCounterW.Call(
uintptr(query),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(cname))),
0,
@ -159,7 +160,7 @@ func NewWin32PerformanceCounter(postName, counterName string) (*Win32Performance
PostName: postName,
CounterName: counterName,
}
r, _, err := PdhAddCounter.Call(
r, _, err := PdhAddEnglishCounterW.Call(
uintptr(counter.Query),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(counter.CounterName))),
0,

View File

@ -36,7 +36,7 @@ func loadAvgGoroutine() {
counter, err := common.ProcessorQueueLengthCounter()
if err != nil || counter == nil {
log.Println("gopsutil: unexpected processor queue length counter error, please file an issue on github")
log.Println("gopsutil: unexpected processor queue length counter error, please file an issue on github: err")
return
}