diff --git a/command/agent/command.go b/command/agent/command.go index 2d642b20e310..165a73994a38 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -15,6 +15,7 @@ import ( "time" "github.com/armon/go-metrics" + "github.com/armon/go-metrics/datadog" "github.com/hashicorp/consul/watch" "github.com/hashicorp/go-checkpoint" "github.com/hashicorp/go-syslog" @@ -604,6 +605,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) diff --git a/command/agent/config.go b/command/agent/config.go index 6240b33f22b2..3577a18c30c6 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -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 } diff --git a/command/agent/config_test.go b/command/agent/config_test.go index dc0517f34976..8fb1ae370e79 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -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{ diff --git a/website/source/docs/agent/options.html.markdown b/website/source/docs/agent/options.html.markdown index 1851f87b3622..043e537453a2 100644 --- a/website/source/docs/agent/options.html.markdown +++ b/website/source/docs/agent/options.html.markdown @@ -562,6 +562,15 @@ definitions support being updated during a reload. This can be used to capture runtime information. This sends UDP packets only and can be used with statsd or statsite. +* `dogstatsd_addr` This provides the + address of a DogStatsD instance. DogStatsD is a protocol-compatible flavor of statsd, with the added ability + to decorate metrics with tags and event information. If provided, Consul will send various telemetry information + to that instance for aggregation. This can be used to capture runtime information. + +* `dogstatsd_tags` This provides a list of global tags + that will be added to all telemetry packets sent to DogStatsD. It is a list of strings, where each string + looks like "my_tag_name:my_tag_value". + * `statsite_addr` This provides the address of a statsite instance. If provided, Consul will stream various telemetry information to that instance for aggregation. This can be used to capture runtime information. This streams via