Add DogStatsd configuration

This commit is contained in:
talwai 2015-06-16 18:05:55 -04:00
parent 4836080a20
commit e6e842d9e7
3 changed files with 57 additions and 0 deletions

View File

@ -15,6 +15,8 @@ import (
"time"
"github.com/armon/go-metrics"
"github.com/armon/go-metrics/datadog"
"github.com/hashicorp/consul-migrate/migrator"
"github.com/hashicorp/consul/watch"
"github.com/hashicorp/go-checkpoint"
"github.com/hashicorp/go-syslog"
@ -604,6 +606,23 @@ func (c *Command) Run(args []string) int {
fanout = append(fanout, sink)
}
// Configure the DogStatsd sink
if config.DogStatsdAddr != "" {
var tags []string
if config.DogStatsdTags != nil {
tags = config.DogStatsdTags
}
sink, err := datadog.NewDogStatsdSink(config.DogStatsdAddr, metricsConf.HostName)
if err != nil {
c.Ui.Error(fmt.Sprintf("Failed to start DogStatsd sink. Got: %s", err))
return 1
}
sink.SetTags(tags)
fanout = append(fanout, sink)
}
// Initialize the global sink
if len(fanout) > 0 {
fanout = append(fanout, inm)

View File

@ -184,6 +184,14 @@ type Config struct {
// metrics will be sent to that instance.
StatsdAddr string `mapstructure:"statsd_addr"`
// DogStatsdAddr is the address of a dogstatsd instance. If provided,
// metrics will be sent to that instance
DogStatsdAddr string `mapstructure:"dogstatsd_addr"`
// DogStatsdTags are the global tags that should be sent with each packet to dogstatsd
// It is a list of strings, where each string looks like "my_tag_name:my_tag_value"
DogStatsdTags []string `mapstructure:"dogstatsd_tags"`
// Protocol is the Consul protocol version to use.
Protocol int `mapstructure:"protocol"`
@ -916,6 +924,12 @@ func MergeConfig(a, b *Config) *Config {
if b.StatsdAddr != "" {
result.StatsdAddr = b.StatsdAddr
}
if b.DogStatsdAddr != "" {
result.DogStatsdAddr = b.DogStatsdAddr
}
if b.DogStatsdTags != nil {
result.DogStatsdTags = b.DogStatsdTags
}
if b.EnableDebug {
result.EnableDebug = true
}

View File

@ -629,6 +629,28 @@ func TestDecodeConfig(t *testing.T) {
t.Fatalf("bad: %#v", config)
}
// dogstatsd
input = `{"dogstatsd_addr": "127.0.0.1:7254", "dogstatsd_tags":["tag_1:val_1", "tag_2:val_2"]}`
config, err = DecodeConfig(bytes.NewReader([]byte(input)))
if err != nil {
t.Fatalf("err: %s", err)
}
if config.DogStatsdAddr != "127.0.0.1:7254" {
t.Fatalf("bad: %#v", config)
}
if len(config.DogStatsdTags) != 2 {
t.Fatalf("bad: %#v", config)
}
if config.DogStatsdTags[0] != "tag_1:val_1" {
t.Fatalf("bad: %#v", config)
}
if config.DogStatsdTags[1] != "tag_2:val_2" {
t.Fatalf("bad: %#v", config)
}
// Statsite prefix
input = `{"statsite_prefix": "my_prefix"}`
config, err = DecodeConfig(bytes.NewReader([]byte(input)))
@ -1216,6 +1238,8 @@ func TestMergeConfig(t *testing.T) {
StatsiteAddr: "127.0.0.1:7250",
StatsitePrefix: "stats_prefix",
StatsdAddr: "127.0.0.1:7251",
DogStatsdAddr: "127.0.0.1:7254",
DogStatsdTags: []string{"tag_1:val_1", "tag_2:val_2"},
DisableUpdateCheck: true,
DisableAnonymousSignature: true,
HTTPAPIResponseHeaders: map[string]string{