mirror of
https://github.com/prometheus-community/windows_exporter
synced 2024-12-26 00:12:06 +00:00
tcp: fix panic on collector (#1699)
This commit is contained in:
parent
92b7e445e1
commit
ce2df385a6
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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++
|
||||
|
Loading…
Reference in New Issue
Block a user