ethtool_linux: fix entry function

Signed-off-by: t-falconnet <tfalconnet.externe@bedrockstreaming.com>
This commit is contained in:
t-falconnet 2022-02-11 15:58:10 +01:00
parent 4426962ec8
commit 642f64b701

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.entries(metric) entry := c.entry(metric, metricFQName)
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
entry, prometheus.UntypedValue, float64(val), device) entry, prometheus.UntypedValue, float64(val), device)
} }
@ -431,14 +431,14 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error {
return nil return nil
} }
func (c *ethtoolCollector) entries(key string) *prometheus.Desc { func (c *ethtoolCollector) entry(key, metricFQName string) *prometheus.Desc {
c.entriesMutex.Lock() c.entriesMutex.Lock()
defer c.entriesMutex.Unlock() defer c.entriesMutex.Unlock()
if _, ok := c.entries[key]; !ok { if _, ok := c.entries[key]; !ok {
c.entries[key] = prometheus.NewDesc( c.entries[key] = prometheus.NewDesc(
metricFQName, metricFQName,
fmt.Sprintf("Network interface %s", metric), fmt.Sprintf("Network interface %s", key),
[]string{"device"}, nil, []string{"device"}, nil,
) )
} }