pagefile: BREAKING: move paging metrics from os to dedicated collector (click PR for more information) (#1735)

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2024-11-14 22:39:59 +01:00
committed by GitHub
parent df8513ab8e
commit 7a9a4e5831
13 changed files with 238 additions and 25 deletions

View File

@@ -5,6 +5,7 @@ package v2
import (
"errors"
"fmt"
"slices"
"strings"
"unsafe"
@@ -14,9 +15,10 @@ import (
)
type Collector struct {
object string
counters map[string]Counter
handle pdhQueryHandle
object string
counters map[string]Counter
handle pdhQueryHandle
totalCounterRequested bool
}
type Counter struct {
@@ -39,9 +41,10 @@ func NewCollector(object string, instances []string, counters []string) (*Collec
}
collector := &Collector{
object: object,
counters: make(map[string]Counter, len(counters)),
handle: handle,
object: object,
counters: make(map[string]Counter, len(counters)),
handle: handle,
totalCounterRequested: slices.Contains(instances, "_Total"),
}
for _, counterName := range counters {
@@ -166,12 +169,10 @@ func (c *Collector) Collect() (map[string]map[string]perftypes.CounterValues, er
metricType = prometheus.GaugeValue
}
_, isTotalCounterRequests := c.counters["_Total"]
for _, item := range items {
if item.RawValue.CStatus == PdhCstatusValidData || item.RawValue.CStatus == PdhCstatusNewData {
instanceName := windows.UTF16PtrToString(item.SzName)
if strings.HasSuffix(instanceName, "_Total") && !isTotalCounterRequests {
if strings.HasSuffix(instanceName, "_Total") && !c.totalCounterRequested {
continue
}