ethtool-linux: split between create and show entry

Signed-off-by: t-falconnet <tfalconnet.externe@bedrockstreaming.com>
This commit is contained in:
t-falconnet 2022-02-11 17:04:33 +01:00
parent b0708e4c47
commit db87173be0

View File

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