fix: windows_cpu_processor_utility_total is always 0 (#1966)

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>

(cherry picked from commit 9db4318ea9)
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2025-04-05 22:20:07 +02:00
parent 6f0209ddb7
commit c300935170
4 changed files with 37 additions and 14 deletions

View File

@@ -122,6 +122,11 @@ func NewCollectorWithReflection(resultType CounterType, object string, instances
continue
}
secondValue := strings.HasSuffix(counterName, ",secondvalue")
if secondValue {
counterName = strings.TrimSuffix(counterName, ",secondvalue")
}
var counter Counter
if counter, ok = collector.counters[counterName]; !ok {
counter = Counter{
@@ -132,9 +137,7 @@ func NewCollectorWithReflection(resultType CounterType, object string, instances
}
}
if strings.HasSuffix(counterName, ",secondvalue") {
counterName = strings.TrimSuffix(counterName, ",secondvalue")
if secondValue {
counter.FieldIndexSecondValue = f.Index[0]
} else {
counter.FieldIndexValue = f.Index[0]
@@ -198,11 +201,14 @@ func NewCollectorWithReflection(resultType CounterType, object string, instances
continue
}
ci := (*CounterInfo)(unsafe.Pointer(&buf[0]))
counter.Type = ci.DwType
counter.Desc = windows.UTF16PtrToString(ci.SzExplainText)
counter.Desc = windows.UTF16PtrToString(ci.SzExplainText)
counterInfo := (*CounterInfo)(unsafe.Pointer(&buf[0]))
if counterInfo == nil {
errs = append(errs, errors.New("GetCounterInfo: counter info is nil"))
continue
}
counter.Type = counterInfo.DwType
if val, ok := SupportedCounterTypes[counter.Type]; ok {
counter.MetricType = val
} else {