|
|
@ -93,7 +93,7 @@ func NewNetDevCollector(logger log.Logger) (Collector, error) {
|
|
|
|
}, nil
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *netDevCollector) metricDesc(key string) *prometheus.Desc {
|
|
|
|
func (c *netDevCollector) metricDesc(key string, labels []string) *prometheus.Desc {
|
|
|
|
c.metricDescsMutex.Lock()
|
|
|
|
c.metricDescsMutex.Lock()
|
|
|
|
defer c.metricDescsMutex.Unlock()
|
|
|
|
defer c.metricDescsMutex.Unlock()
|
|
|
|
|
|
|
|
|
|
|
@ -101,7 +101,7 @@ func (c *netDevCollector) metricDesc(key string) *prometheus.Desc {
|
|
|
|
c.metricDescs[key] = prometheus.NewDesc(
|
|
|
|
c.metricDescs[key] = prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName(namespace, c.subsystem, key+"_total"),
|
|
|
|
prometheus.BuildFQName(namespace, c.subsystem, key+"_total"),
|
|
|
|
fmt.Sprintf("Network device statistic %s.", key),
|
|
|
|
fmt.Sprintf("Network device statistic %s.", key),
|
|
|
|
[]string{"device"},
|
|
|
|
labels,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -114,13 +114,29 @@ func (c *netDevCollector) Update(ch chan<- prometheus.Metric) error {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("couldn't get netstats: %w", err)
|
|
|
|
return fmt.Errorf("couldn't get netstats: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
netDevLabels, err := getNetDevLabels()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return fmt.Errorf("couldn't get netdev labels: %w", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for dev, devStats := range netDev {
|
|
|
|
for dev, devStats := range netDev {
|
|
|
|
if !*netdevDetailedMetrics {
|
|
|
|
if !*netdevDetailedMetrics {
|
|
|
|
legacy(devStats)
|
|
|
|
legacy(devStats)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
labels := []string{"device"}
|
|
|
|
|
|
|
|
labelValues := []string{dev}
|
|
|
|
|
|
|
|
if devLabels, exists := netDevLabels[dev]; exists {
|
|
|
|
|
|
|
|
for labelName, labelValue := range devLabels {
|
|
|
|
|
|
|
|
labels = append(labels, labelName)
|
|
|
|
|
|
|
|
labelValues = append(labelValues, labelValue)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for key, value := range devStats {
|
|
|
|
for key, value := range devStats {
|
|
|
|
desc := c.metricDesc(key)
|
|
|
|
desc := c.metricDesc(key, labels)
|
|
|
|
ch <- prometheus.MustNewConstMetric(desc, prometheus.CounterValue, float64(value), dev)
|
|
|
|
ch <- prometheus.MustNewConstMetric(desc, prometheus.CounterValue, float64(value), labelValues...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if *netdevAddressInfo {
|
|
|
|
if *netdevAddressInfo {
|
|
|
|