logical_disk: Implement Perfdata collector (#1673)

This commit is contained in:
Jan-Otto Kröpke
2024-10-07 00:15:54 +02:00
committed by GitHub
parent efb20b1e31
commit 2ef1a5fdf1
19 changed files with 400 additions and 88 deletions

View File

@@ -2,6 +2,7 @@ package v1
import (
"fmt"
"strings"
"github.com/prometheus-community/windows_exporter/internal/perfdata/perftypes"
"github.com/prometheus/client_golang/prometheus"
@@ -43,11 +44,23 @@ func (c *Collector) Collect() (map[string]map[string]perftypes.CounterValues, er
return nil, fmt.Errorf("QueryPerformanceData: %w", err)
}
if len(perfObjects) == 0 {
return map[string]map[string]perftypes.CounterValues{}, nil
}
data := make(map[string]map[string]perftypes.CounterValues, len(perfObjects[0].Instances))
for _, perfObject := range perfObjects {
if perfObject.Name != c.object {
continue
}
for _, perfInstance := range perfObject.Instances {
instanceName := perfInstance.Name
if strings.HasSuffix(instanceName, "_Total") {
continue
}
if instanceName == "" || instanceName == "*" {
instanceName = perftypes.EmptyInstance
}
@@ -57,6 +70,10 @@ func (c *Collector) Collect() (map[string]map[string]perftypes.CounterValues, er
}
for _, perfCounter := range perfInstance.Counters {
if perfCounter.Def.IsBaseValue && !perfCounter.Def.IsNanosecondCounter {
continue
}
if _, ok := data[instanceName][perfCounter.Def.Name]; !ok {
data[instanceName][perfCounter.Def.Name] = perftypes.CounterValues{
Type: prometheus.GaugeValue,