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.
This commit is contained in:
Julius Volz 2013-08-15 13:20:06 +02:00
parent 9ea37d8b44
commit 4fcd1a9b38
1 changed files with 4 additions and 2 deletions

View File

@ -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,