mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 23:55:47 -06:00
parent
2b2e015d62
commit
0524d0c625
@ -23,7 +23,7 @@ test:
|
||||
# GO VET
|
||||
- go vet ./pkg/...
|
||||
# Go test
|
||||
- godep go test -v ./pkg/...
|
||||
- godep go test ./pkg/...
|
||||
# js tests
|
||||
- npm test
|
||||
- npm run coveralls
|
||||
|
@ -353,7 +353,7 @@ enabled = true
|
||||
interval_seconds = 60
|
||||
|
||||
# Send internal Grafana metrics to graphite
|
||||
; [metrics.graphite]
|
||||
[metrics.graphite]
|
||||
; address = localhost:2003
|
||||
; prefix = prod.grafana.%(instance_name)s.
|
||||
|
||||
|
@ -297,15 +297,15 @@ check_for_updates = true
|
||||
# Metrics available at HTTP API Url /api/metrics
|
||||
[metrics]
|
||||
# Disable / Enable internal metrics
|
||||
;enabled = true
|
||||
enabled = true
|
||||
|
||||
# Publish interval
|
||||
;interval_seconds = 10
|
||||
|
||||
# Send internal metrics to Graphite
|
||||
; [metrics.graphite]
|
||||
# Send internal metrics to Graphite. %instance_name% in prefix will be replaced with the value of instance_name
|
||||
[metrics.graphite]
|
||||
; address = localhost:2003
|
||||
; prefix = prod.grafana.%(instance_name)s.
|
||||
; prefix = service.grafana.%instance_name%
|
||||
|
||||
#################################### Internal Grafana Metrics ##########################
|
||||
# Url used to to import dashboards directly from Grafana.net
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/log"
|
||||
@ -20,14 +21,18 @@ type GraphitePublisher struct {
|
||||
func CreateGraphitePublisher() (*GraphitePublisher, error) {
|
||||
graphiteSection, err := setting.Cfg.GetSection("metrics.graphite")
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
return nil, err
|
||||
}
|
||||
|
||||
publisher := &GraphitePublisher{}
|
||||
publisher.prevCounts = make(map[string]int64)
|
||||
publisher.protocol = "tcp"
|
||||
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
|
||||
}
|
||||
|
31
pkg/metrics/graphite_test.go
Normal file
31
pkg/metrics/graphite_test.go
Normal file
@ -0,0 +1,31 @@
|
||||
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")
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user