ethtool-linux: split between create and show entry
@@ -422,7 +422,7 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error {
val := stats[metric]
// Check to see if this metric exists; if not then create it and store it in c.entries.
- entry := c.entry(metric, metricFQName)
+ entry := c.entryWithCreate(metric, metricFQName)
ch <- prometheus.MustNewConstMetric(
entry, prometheus.UntypedValue, float64(val), device)
}
@@ -431,7 +431,7 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error {
return nil
}
-func (c *ethtoolCollector) entry(key, metricFQName string) *prometheus.Desc {
+func (c *ethtoolCollector) entryWithCreate(key, metricFQName string) *prometheus.Desc {
c.entriesMutex.Lock()
defer c.entriesMutex.Unlock()
@@ -445,3 +445,9 @@ func (c *ethtoolCollector) entry(key, metricFQName string) *prometheus.Desc {
return c.entries[key]
}
+
+func (c *ethtoolCollector) entry(key) *prometheus.Desc {
+ c.entriesMutex.Lock()
+ defer c.entriesMutex.Unlock()
+ return c.entries[key]
+}
