Skip to content

Commit

Permalink
agent: statsd support. Fixes #247
Browse files Browse the repository at this point in the history
  • Loading branch information
armon committed Sep 2, 2014
1 parent 289cc26 commit 98acc0a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ IMPROVEMENTS:
* Support for HTTP `?pretty` parameter to pretty format JSON output.
* Use $SHELL when invoking handlers. [GH-237]
* Agent takes the `-encrypt` CLI Flag [GH-245]
* New `statsd_add` config for Statsd support. [GH-247]

BUG FIXES:

Expand Down
21 changes: 18 additions & 3 deletions command/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,31 @@ func (c *Command) Run(args []string) int {
metrics.DefaultInmemSignal(inm)
metricsConf := metrics.DefaultConfig("consul")

// Optionally configure a statsite sink if provided
// Configure the statsite sink
var fanout metrics.FanoutSink
if config.StatsiteAddr != "" {
sink, err := metrics.NewStatsiteSink(config.StatsiteAddr)
if err != nil {
c.Ui.Error(fmt.Sprintf("Failed to start statsite sink. Got: %s", err))
return 1
}
fanout := metrics.FanoutSink{inm, sink}
metrics.NewGlobal(metricsConf, fanout)
fanout = append(fanout, sink)
}

// Configure the statsd sink
if config.StatsdAddr != "" {
sink, err := metrics.NewStatsdSink(config.StatsdAddr)
if err != nil {
c.Ui.Error(fmt.Sprintf("Failed to start statsd sink. Got: %s", err))
return 1
}
fanout = append(fanout, sink)
}

// Initialize the global sink
if len(fanout) > 0 {
fanout = append(fanout, inm)
metrics.NewGlobal(metricsConf, fanout)
} else {
metricsConf.EnableHostname = false
metrics.NewGlobal(metricsConf, inm)
Expand Down
7 changes: 7 additions & 0 deletions command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ type Config struct {
// metrics will be streamed to that instance.
StatsiteAddr string `mapstructure:"statsite_addr"`

// StatsdAddr is the address of a statsd instance. If provided,
// metrics will be sent to that instance.
StatsdAddr string `mapstructure:"statsd_addr"`

// Protocol is the Consul protocol version to use.
Protocol int `mapstructure:"protocol"`

Expand Down Expand Up @@ -575,6 +579,9 @@ func MergeConfig(a, b *Config) *Config {
if b.StatsiteAddr != "" {
result.StatsiteAddr = b.StatsiteAddr
}
if b.StatsdAddr != "" {
result.StatsdAddr = b.StatsdAddr
}
if b.EnableDebug {
result.EnableDebug = true
}
Expand Down
16 changes: 16 additions & 0 deletions command/agent/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,20 @@ func TestDecodeConfig(t *testing.T) {
if !config.DisableRemoteExec {
t.Fatalf("bad: %#v", config)
}

// stats(d|ite) exec
input = `{"statsite_addr": "127.0.0.1:7250", "statsd_addr": "127.0.0.1:7251"}`
config, err = DecodeConfig(bytes.NewReader([]byte(input)))
if err != nil {
t.Fatalf("err: %s", err)
}

if config.StatsiteAddr != "127.0.0.1:7250" {
t.Fatalf("bad: %#v", config)
}
if config.StatsdAddr != "127.0.0.1:7251" {
t.Fatalf("bad: %#v", config)
}
}

func TestDecodeConfig_Service(t *testing.T) {
Expand Down Expand Up @@ -578,6 +592,8 @@ func TestMergeConfig(t *testing.T) {
},
},
DisableRemoteExec: true,
StatsiteAddr: "127.0.0.1:7250",
StatsdAddr: "127.0.0.1:7251",
}

c := MergeConfig(a, b)
Expand Down
8 changes: 7 additions & 1 deletion website/source/docs/agent/options.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,15 @@ definitions support being updated during a reload.
* `start_join` - An array of strings specifying addresses of nodes to
join upon startup.

* `statsd_addr` - This provides the address of a statsd instance. If provided
Consul will send various telemetry information to that instance for aggregation.
This can be used to capture various runtime information. This sends UDP packets
only, and can be used with statsd or statsite.

* `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 various runtime information.
This can be used to capture various runtime information. This streams via
TCP and can only be used with statsite.

* `syslog_facility` - When `enable_syslog` is provided, this controls which
facility messages are sent to. By default, `LOCAL0` will be used.
Expand Down

0 comments on commit 98acc0a

Please sign in to comment.