From 0b0c5624e17ce91f39b8f596374101c65c8aaece Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Fri, 5 Feb 2021 18:10:42 +0100 Subject: [PATCH] Fix network_route collector naming * Use `device` label to match other `node_network_...` metics. * Fix naming convention to match Promehteus best practices. Signed-off-by: Ben Kochie --- collector/network_route_linux.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/collector/network_route_linux.go b/collector/network_route_linux.go index cdd0c8cc..dc9840f8 100644 --- a/collector/network_route_linux.go +++ b/collector/network_route_linux.go @@ -27,9 +27,9 @@ import ( ) type networkRouteCollector struct { - routeDesc *prometheus.Desc - routesTotalDesc *prometheus.Desc - logger log.Logger + routeInfoDesc *prometheus.Desc + routesDesc *prometheus.Desc + logger log.Logger } func init() { @@ -40,19 +40,19 @@ 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, - logger: logger, + 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