Merge pull request #3 from prometheus/fix/escape-names

Escape all illegal chars in metric names.
This commit is contained in:
juliusv 2013-08-15 05:46:33 -07:00
commit 94065ff28b
1 changed files with 4 additions and 2 deletions

View File

@ -8,7 +8,7 @@ import (
"github.com/prometheus/node_exporter/exporter/ganglia" "github.com/prometheus/node_exporter/exporter/ganglia"
"io" "io"
"net" "net"
"strings" "regexp"
"time" "time"
) )
@ -25,6 +25,8 @@ type gmondCollector struct {
registry prometheus.Registry 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. // 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) { func NewGmondCollector(config config, registry prometheus.Registry) (collector gmondCollector, err error) {
collector = gmondCollector{ collector = gmondCollector{
@ -84,7 +86,7 @@ func (c *gmondCollector) Update() (updates int, err error) {
for _, host := range cluster.Hosts { for _, host := range cluster.Hosts {
for _, metric := range host.Metrics { for _, metric := range host.Metrics {
name := strings.Replace(strings.ToLower(metric.Name), ".", "_", -1) name := illegalCharsRE.ReplaceAllString(metric.Name, "_")
var labels = map[string]string{ var labels = map[string]string{
"cluster": cluster.Name, "cluster": cluster.Name,