diff --git a/metric/cpu/cpu_windows.go b/metric/cpu/cpu_windows.go index 77a19dea2..d0d88ef4f 100644 --- a/metric/cpu/cpu_windows.go +++ b/metric/cpu/cpu_windows.go @@ -50,7 +50,7 @@ func New(hostfs resolve.Resolver, opts ...OptionFunc) (*Monitor, error) { for _, o := range opts { o(&op) } - if !op.usePerformanceCounter { + if op.usePerformanceCounter { if query, err = buildQuery(); err != nil { return nil, err } diff --git a/metric/cpu/metric_windows_test.go b/metric/cpu/metric_windows_test.go index 3cfaf75cc..3ddce0b70 100644 --- a/metric/cpu/metric_windows_test.go +++ b/metric/cpu/metric_windows_test.go @@ -28,7 +28,7 @@ import ( ) func TestCounterLength(t *testing.T) { - monitor, err := New(systemtests.DockerTestResolver()) + monitor, err := New(systemtests.DockerTestResolver(), WithWindowsPerformanceCounter()) require.NoError(t, err) require.NoError(t, monitor.query.CollectData()) @@ -52,3 +52,9 @@ func TestCounterLength(t *testing.T) { require.Equal(t, kernelRawData[i].InstanceName, idleRawData[i].InstanceName, "InstanceName should be equal") } } + +func TestCounterDisabled(t *testing.T) { + monitor, err := New(systemtests.DockerTestResolver()) + require.NoError(t, err) + require.Nil(t, monitor.query) +}