diff --git a/internal/collector/tcp/tcp_test.go b/internal/collector/tcp/tcp_test.go index 848df74da..d33cc95fa 100644 --- a/internal/collector/tcp/tcp_test.go +++ b/internal/collector/tcp/tcp_test.go @@ -10,3 +10,7 @@ import ( func BenchmarkCollector(b *testing.B) { testutils.FuncBenchmarkCollector(b, tcp.Name, tcp.NewWithFlags) } + +func TestCollector(t *testing.T) { + testutils.TestCollector(t, tcp.New, nil) +} diff --git a/internal/perfdata/v1/collector.go b/internal/perfdata/v1/collector.go index 5e0ee6862..274fde86b 100644 --- a/internal/perfdata/v1/collector.go +++ b/internal/perfdata/v1/collector.go @@ -44,7 +44,7 @@ func (c *Collector) Collect() (map[string]map[string]perftypes.CounterValues, er return nil, fmt.Errorf("QueryPerformanceData: %w", err) } - if len(perfObjects) == 0 { + if len(perfObjects) == 0 || perfObjects[0] == nil || len(perfObjects[0].Instances) == 0 { return map[string]map[string]perftypes.CounterValues{}, nil } diff --git a/internal/perfdata/v1/perflib.go b/internal/perfdata/v1/perflib.go index 010f0d82d..c392ad16a 100644 --- a/internal/perfdata/v1/perflib.go +++ b/internal/perfdata/v1/perflib.go @@ -418,6 +418,10 @@ func QueryPerformanceData(query string, counterName string) ([]*PerfObject, erro } } + if counterName != "" { + return objects[i : i+1], nil + } + // Next perfObjectType objOffset += int64(obj.TotalByteLength) numFilteredObjects++