diff --git a/collector/ethtool_linux.go b/collector/ethtool_linux.go index 95bca73d..b7b413fc 100644 --- a/collector/ethtool_linux.go +++ b/collector/ethtool_linux.go @@ -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] +}