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

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,