From 4fcd1a9b383c3d0b62880ab025d06248bfd331a6 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Thu, 15 Aug 2013 13:20:06 +0200 Subject: [PATCH] Escape all illegal chars in metric names. E.g. right now there are some metrics with dashes in their names, which cannot be queried through the UI. --- exporter/gmond_collector.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/exporter/gmond_collector.go b/exporter/gmond_collector.go index c126f432..e6c1fe4b 100644 --- a/exporter/gmond_collector.go +++ b/exporter/gmond_collector.go @@ -8,7 +8,7 @@ import ( "github.com/prometheus/node_exporter/exporter/ganglia" "io" "net" - "strings" + "regexp" "time" ) @@ -25,6 +25,8 @@ type gmondCollector struct { registry prometheus.Registry } +var illegalCharsRE = regexp.MustCompile(`[^a-zA-Z0-9_]`) + // Takes a config struct and prometheus registry and returns a new Collector scraping ganglia. func NewGmondCollector(config config, registry prometheus.Registry) (collector gmondCollector, err error) { collector = gmondCollector{ @@ -84,7 +86,7 @@ func (c *gmondCollector) Update() (updates int, err error) { for _, host := range cluster.Hosts { for _, metric := range host.Metrics { - name := strings.Replace(strings.ToLower(metric.Name), ".", "_", -1) + name := illegalCharsRE.ReplaceAllString(metric.Name, "_") var labels = map[string]string{ "cluster": cluster.Name,