mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-25 22:26:37 +00:00
logical_disk: Implement Perfdata collector (#1673)
This commit is contained in:
@@ -1,18 +1,11 @@
|
||||
package process_test
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log/slog"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/collector/process"
|
||||
"github.com/prometheus-community/windows_exporter/internal/testutils"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
func BenchmarkProcessCollector(b *testing.B) {
|
||||
@@ -23,48 +16,6 @@ func BenchmarkProcessCollector(b *testing.B) {
|
||||
testutils.FuncBenchmarkCollector(b, process.Name, process.NewWithFlags)
|
||||
}
|
||||
|
||||
func TestProcessCollector(t *testing.T) {
|
||||
t.Setenv("WINDOWS_EXPORTER_PERF_COUNTERS_ENGINE", "pdh")
|
||||
|
||||
var (
|
||||
metrics []prometheus.Metric
|
||||
err error
|
||||
)
|
||||
|
||||
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
|
||||
c := process.New(nil)
|
||||
ch := make(chan prometheus.Metric, 10000)
|
||||
|
||||
wmiClient := &wmi.Client{
|
||||
AllowMissingFields: true,
|
||||
}
|
||||
wmiClient.SWbemServicesClient, err = wmi.InitializeSWbemServices(wmiClient)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, c.Close(logger))
|
||||
})
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
for metric := range ch {
|
||||
metrics = append(metrics, metric)
|
||||
}
|
||||
}()
|
||||
|
||||
require.NoError(t, c.Build(logger, wmiClient))
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
require.NoError(t, c.Collect(nil, logger, ch))
|
||||
|
||||
close(ch)
|
||||
|
||||
wg.Wait()
|
||||
|
||||
require.NotEmpty(t, metrics)
|
||||
func TestCollector(t *testing.T) {
|
||||
testutils.TestCollector(t, process.New, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user