fix iis collector panic

If the `dst_cache` slice is empty, the program panics when trying to access `dst_cache[0]`

added a `if len(dst_cache) > 0 {}` block around the use of that variable to prevent that panic.
This commit is contained in:
Steve Zook
2018-07-19 13:29:33 -04:00
parent bb67658853
commit 8ea862a3da

View File

@@ -1738,6 +1738,7 @@ func (c *IISCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, e
return nil, err return nil, err
} }
if len(dst_cache) > 0 {
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.ServiceCache_ActiveFlushedEntries, c.ServiceCache_ActiveFlushedEntries,
prometheus.GaugeValue, prometheus.GaugeValue,
@@ -1946,6 +1947,7 @@ func (c *IISCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, e
prometheus.CounterValue, prometheus.CounterValue,
float64(dst_cache[0].OutputCacheTotalFlushes), float64(dst_cache[0].OutputCacheTotalFlushes),
) )
}
return nil, nil return nil, nil
} }