Integrate perflib

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2023-07-10 01:56:17 +02:00
parent 80cf16efe8
commit 750225775b
11 changed files with 841 additions and 80 deletions

View File

@@ -9,7 +9,7 @@ import (
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/leoluk/perflib_exporter/perflib"
"github.com/prometheus-community/windows_exporter/wmi/perflib"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/windows/registry"
)

View File

@@ -6,13 +6,13 @@ import (
"strconv"
"strings"
"github.com/prometheus-community/windows_exporter/wmi/perflib"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
perflibCollector "github.com/leoluk/perflib_exporter/collector"
"github.com/leoluk/perflib_exporter/perflib"
)
var nametable = perflib.QueryNameTable("Counter 009") // Reads the names in English TODO: validate that the English names are always present
var nametable = perflib.CounterNameTable
func MapCounterToIndex(name string) string {
return strconv.Itoa(int(nametable.LookupIndex(name)))
@@ -101,9 +101,9 @@ func unmarshalObject(obj *perflib.PerfObject, vs interface{}, logger log.Logger)
}
switch ctr.Def.CounterType {
case perflibCollector.PERF_ELAPSED_TIME:
case perflib.PERF_ELAPSED_TIME:
target.Field(i).SetFloat(float64(ctr.Value-windowsEpoch) / float64(obj.Frequency))
case perflibCollector.PERF_100NSEC_TIMER, perflibCollector.PERF_PRECISION_100NS_TIMER:
case perflib.PERF_100NSEC_TIMER, perflib.PERF_PRECISION_100NS_TIMER:
target.Field(i).SetFloat(float64(ctr.Value) * ticksToSecondsScaleFactor)
default:
target.Field(i).SetFloat(float64(ctr.Value))

View File

@@ -4,10 +4,9 @@ import (
"reflect"
"testing"
"github.com/go-kit/log"
"github.com/prometheus-community/windows_exporter/wmi/perflib"
perflibCollector "github.com/leoluk/perflib_exporter/collector"
"github.com/leoluk/perflib_exporter/perflib"
"github.com/go-kit/log"
)
type simple struct {
@@ -39,7 +38,7 @@ func TestUnmarshalPerflib(t *testing.T) {
{
Def: &perflib.PerfCounterDef{
Name: "Something",
CounterType: perflibCollector.PERF_COUNTER_COUNTER,
CounterType: perflib.PERF_COUNTER_COUNTER,
},
Value: 123,
},
@@ -59,14 +58,14 @@ func TestUnmarshalPerflib(t *testing.T) {
{
Def: &perflib.PerfCounterDef{
Name: "Something",
CounterType: perflibCollector.PERF_COUNTER_COUNTER,
CounterType: perflib.PERF_COUNTER_COUNTER,
},
Value: 123,
},
{
Def: &perflib.PerfCounterDef{
Name: "Something Else",
CounterType: perflibCollector.PERF_COUNTER_COUNTER,
CounterType: perflib.PERF_COUNTER_COUNTER,
HasSecondValue: true,
},
Value: 256,
@@ -88,7 +87,7 @@ func TestUnmarshalPerflib(t *testing.T) {
{
Def: &perflib.PerfCounterDef{
Name: "Something",
CounterType: perflibCollector.PERF_COUNTER_COUNTER,
CounterType: perflib.PERF_COUNTER_COUNTER,
},
Value: 321,
},
@@ -99,7 +98,7 @@ func TestUnmarshalPerflib(t *testing.T) {
{
Def: &perflib.PerfCounterDef{
Name: "Something",
CounterType: perflibCollector.PERF_COUNTER_COUNTER,
CounterType: perflib.PERF_COUNTER_COUNTER,
},
Value: 231,
},