Merge pull request #1953 from prometheus/superq/fix_network_route

Fix network_route collector naming
This commit is contained in:
Ben Kochie 2021-02-05 21:20:44 +01:00 committed by GitHub
commit a2b556a0ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 15 deletions

View File

@ -27,8 +27,8 @@ import (
)
type networkRouteCollector struct {
routeDesc *prometheus.Desc
routesTotalDesc *prometheus.Desc
routeInfoDesc *prometheus.Desc
routesDesc *prometheus.Desc
logger log.Logger
}
@ -40,18 +40,18 @@ func init() {
func NewNetworkRouteCollector(logger log.Logger) (Collector, error) {
const subsystem = "network"
routeDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "route"),
"network routing table", []string{"if", "src", "dest", "gw", "priority", "proto", "weight"}, nil,
routeInfoDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "route_info"),
"network routing table information", []string{"device", "src", "dest", "gw", "priority", "proto", "weight"}, nil,
)
routeTotalDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "routes_total"),
"network total routes", []string{"if"}, nil,
routesDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "routes"),
"network routes by interface", []string{"device"}, nil,
)
return &networkRouteCollector{
routeDesc: routeDesc,
routesTotalDesc: routeTotalDesc,
routeInfoDesc: routeInfoDesc,
routesDesc: routesDesc,
logger: logger,
}, nil
}
@ -98,7 +98,7 @@ func (n networkRouteCollector) Update(ch chan<- prometheus.Metric) error {
networkRouteProtocolToString(route.Protocol), // proto
strconv.Itoa(int(nextHop.Hop.Hops) + 1), // weight
}
ch <- prometheus.MustNewConstMetric(n.routeDesc, prometheus.GaugeValue, 1, labels...)
ch <- prometheus.MustNewConstMetric(n.routeInfoDesc, prometheus.GaugeValue, 1, labels...)
deviceRoutes[ifName]++
}
} else {
@ -119,13 +119,13 @@ func (n networkRouteCollector) Update(ch chan<- prometheus.Metric) error {
networkRouteProtocolToString(route.Protocol), // proto
"", // weight
}
ch <- prometheus.MustNewConstMetric(n.routeDesc, prometheus.GaugeValue, 1, labels...)
ch <- prometheus.MustNewConstMetric(n.routeInfoDesc, prometheus.GaugeValue, 1, labels...)
deviceRoutes[ifName]++
}
}
for dev, total := range deviceRoutes {
ch <- prometheus.MustNewConstMetric(n.routesTotalDesc, prometheus.GaugeValue, float64(total), dev)
ch <- prometheus.MustNewConstMetric(n.routesDesc, prometheus.GaugeValue, float64(total), dev)
}
return nil