physical_disk: refactor collector (#1734)

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2024-11-14 22:28:28 +01:00
committed by GitHub
parent baa4dc16ae
commit 1956330ac4
6 changed files with 74 additions and 66 deletions

View File

@@ -74,12 +74,12 @@ func NewCollector(object string, instances []string, counters []string) (*Collec
// Get the info with the current buffer size
bufLen := uint32(0)
if ret := PdhGetCounterInfo(counterHandle, 1, &bufLen, nil); ret != PdhMoreData {
if ret := PdhGetCounterInfo(counterHandle, 0, &bufLen, nil); ret != PdhMoreData {
return nil, fmt.Errorf("PdhGetCounterInfo: %w", NewPdhError(ret))
}
buf := make([]byte, bufLen)
if ret := PdhGetCounterInfo(counterHandle, 1, &bufLen, &buf[0]); ret != ErrorSuccess {
if ret := PdhGetCounterInfo(counterHandle, 0, &bufLen, &buf[0]); ret != ErrorSuccess {
return nil, fmt.Errorf("PdhGetCounterInfo: %w", NewPdhError(ret))
}