Commit 5b57210a by bergquist

fix(metrics): replaces . with _ in instance name

closes #5739
parent f8f7543d
...@@ -23,7 +23,7 @@ test: ...@@ -23,7 +23,7 @@ test:
# GO VET # GO VET
- go vet ./pkg/... - go vet ./pkg/...
# Go test # Go test
- godep go test -v ./pkg/... - godep go test ./pkg/...
# js tests # js tests
- npm test - npm test
- npm run coveralls - npm run coveralls
......
...@@ -356,7 +356,7 @@ enabled = true ...@@ -356,7 +356,7 @@ enabled = true
interval_seconds = 60 interval_seconds = 60
# Send internal Grafana metrics to graphite # Send internal Grafana metrics to graphite
; [metrics.graphite] [metrics.graphite]
; address = localhost:2003 ; address = localhost:2003
; prefix = prod.grafana.%(instance_name)s. ; prefix = prod.grafana.%(instance_name)s.
......
...@@ -298,15 +298,15 @@ check_for_updates = true ...@@ -298,15 +298,15 @@ check_for_updates = true
# Metrics available at HTTP API Url /api/metrics # Metrics available at HTTP API Url /api/metrics
[metrics] [metrics]
# Disable / Enable internal metrics # Disable / Enable internal metrics
;enabled = true enabled = true
# Publish interval # Publish interval
;interval_seconds = 10 ;interval_seconds = 10
# Send internal metrics to Graphite # Send internal metrics to Graphite. %instance_name% in prefix will be replaced with the value of instance_name
; [metrics.graphite] [metrics.graphite]
; address = localhost:2003 ; address = localhost:2003
; prefix = prod.grafana.%(instance_name)s. ; prefix = service.grafana.%instance_name%
#################################### Internal Grafana Metrics ########################## #################################### Internal Grafana Metrics ##########################
# Url used to to import dashboards directly from Grafana.net # Url used to to import dashboards directly from Grafana.net
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"net" "net"
"strings"
"time" "time"
"github.com/grafana/grafana/pkg/log" "github.com/grafana/grafana/pkg/log"
...@@ -20,14 +21,18 @@ type GraphitePublisher struct { ...@@ -20,14 +21,18 @@ type GraphitePublisher struct {
func CreateGraphitePublisher() (*GraphitePublisher, error) { func CreateGraphitePublisher() (*GraphitePublisher, error) {
graphiteSection, err := setting.Cfg.GetSection("metrics.graphite") graphiteSection, err := setting.Cfg.GetSection("metrics.graphite")
if err != nil { if err != nil {
return nil, nil return nil, err
} }
publisher := &GraphitePublisher{} publisher := &GraphitePublisher{}
publisher.prevCounts = make(map[string]int64) publisher.prevCounts = make(map[string]int64)
publisher.protocol = "tcp" publisher.protocol = "tcp"
publisher.address = graphiteSection.Key("address").MustString("localhost:2003") publisher.address = graphiteSection.Key("address").MustString("localhost:2003")
publisher.prefix = graphiteSection.Key("prefix").MustString("service.grafana.%(instance_name)s")
safeInstanceName := strings.Replace(setting.InstanceName, ".", "_", -1)
prefix := graphiteSection.Key("prefix").MustString("service.grafana.%instance_name%")
publisher.prefix = strings.Replace(prefix, "%instance_name%", safeInstanceName, -1)
return publisher, nil return publisher, nil
} }
......
package metrics
import (
"testing"
"github.com/grafana/grafana/pkg/setting"
. "github.com/smartystreets/goconvey/convey"
)
func TestGraphitePublisher(t *testing.T) {
Convey("Test graphite prefix", t, func() {
err := setting.NewConfigContext(&setting.CommandLineArgs{
HomePath: "../../",
Args: []string{
"cfg:metrics.graphite.prefix=service.grafana.%instance_name%",
"cfg:metrics.graphite.address=localhost:2003",
},
})
So(err, ShouldBeNil)
setting.InstanceName = "hostname.with.dots.com"
publisher, err2 := CreateGraphitePublisher()
So(err2, ShouldBeNil)
So(publisher, ShouldNotBeNil)
So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com")
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment