Skip to content

Commit

Permalink
Merge pull request #1293 from talwai/master
Browse files Browse the repository at this point in the history
Add options to send telemetry to DogStatsD
  • Loading branch information
slackpad committed Nov 13, 2015
2 parents a1ab10f + f6f2e19 commit 8defe75
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
18 changes: 18 additions & 0 deletions command/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down Expand Up @@ -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
}
Expand Down
24 changes: 24 additions & 0 deletions command/agent/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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{
Expand Down
9 changes: 9 additions & 0 deletions website/source/docs/agent/options.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <a name="dogstatsd_addr"></a><a href="#dogstatsd_addr">`dogstatsd_addr`</a> 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.
* <a name="dogstatsd_tags"></a><a href="#dogstatsd_tags">`dogstatsd_tags`</a> 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".
* <a name="statsite_addr"></a><a href="#statsite_addr">`statsite_addr`</a> 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
Expand Down

0 comments on commit 8defe75

Please sign in to comment.