ethtool_linux: add mutex around entries access
Signed-off-by: t-falconnet <tfalconnet.externe@bedrockstreaming.com>pull/2289/head
parent
f7086d437b
commit
4426962ec8
|
@ -27,6 +27,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
|
@ -73,6 +74,7 @@ func (e *ethtoolLibrary) LinkInfo(intf string) (ethtool.EthtoolCmd, error) {
|
||||||
type ethtoolCollector struct {
|
type ethtoolCollector struct {
|
||||||
fs sysfs.FS
|
fs sysfs.FS
|
||||||
entries map[string]*prometheus.Desc
|
entries map[string]*prometheus.Desc
|
||||||
|
entriesMutex sync.Mutex
|
||||||
ethtool Ethtool
|
ethtool Ethtool
|
||||||
deviceFilter netDevFilter
|
deviceFilter netDevFilter
|
||||||
infoDesc *prometheus.Desc
|
infoDesc *prometheus.Desc
|
||||||
|
@ -420,15 +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, exists := c.entries[metric]
|
entry := c.entries(metric)
|
||||||
if !exists {
|
|
||||||
entry = prometheus.NewDesc(
|
|
||||||
metricFQName,
|
|
||||||
fmt.Sprintf("Network interface %s", metric),
|
|
||||||
[]string{"device"}, nil,
|
|
||||||
)
|
|
||||||
c.entries[metric] = entry
|
|
||||||
}
|
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
entry, prometheus.UntypedValue, float64(val), device)
|
entry, prometheus.UntypedValue, float64(val), device)
|
||||||
}
|
}
|
||||||
|
@ -436,3 +430,18 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ethtoolCollector) entries(key string) *prometheus.Desc {
|
||||||
|
c.entriesMutex.Lock()
|
||||||
|
defer c.entriesMutex.Unlock()
|
||||||
|
|
||||||
|
if _, ok := c.entries[key]; !ok {
|
||||||
|
c.entries[key] = prometheus.NewDesc(
|
||||||
|
metricFQName,
|
||||||
|
fmt.Sprintf("Network interface %s", metric),
|
||||||
|
[]string{"device"}, nil,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.entries[key]
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue