mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-23 13:16:36 +00:00
tcp: fix panic on collector (#1699)
This commit is contained in:
@@ -10,3 +10,7 @@ import (
|
|||||||
func BenchmarkCollector(b *testing.B) {
|
func BenchmarkCollector(b *testing.B) {
|
||||||
testutils.FuncBenchmarkCollector(b, tcp.Name, tcp.NewWithFlags)
|
testutils.FuncBenchmarkCollector(b, tcp.Name, tcp.NewWithFlags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCollector(t *testing.T) {
|
||||||
|
testutils.TestCollector(t, tcp.New, nil)
|
||||||
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func (c *Collector) Collect() (map[string]map[string]perftypes.CounterValues, er
|
|||||||
return nil, fmt.Errorf("QueryPerformanceData: %w", err)
|
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
|
return map[string]map[string]perftypes.CounterValues{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -418,6 +418,10 @@ func QueryPerformanceData(query string, counterName string) ([]*PerfObject, erro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if counterName != "" {
|
||||||
|
return objects[i : i+1], nil
|
||||||
|
}
|
||||||
|
|
||||||
// Next perfObjectType
|
// Next perfObjectType
|
||||||
objOffset += int64(obj.TotalByteLength)
|
objOffset += int64(obj.TotalByteLength)
|
||||||
numFilteredObjects++
|
numFilteredObjects++
|
||||||
|
|||||||
Reference in New Issue
Block a user