From 98acc0a908ddaab1d6d5e7a8fc5f83f22de1ec41 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Tue, 2 Sep 2014 11:26:08 -0700 Subject: [PATCH] agent: statsd support. Fixes #247 --- CHANGELOG.md | 1 + command/agent/command.go | 21 ++++++++++++++++--- command/agent/config.go | 7 +++++++ command/agent/config_test.go | 16 ++++++++++++++ .../source/docs/agent/options.html.markdown | 8 ++++++- 5 files changed, 49 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eae0762783..2eb81ccad1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/command/agent/command.go b/command/agent/command.go index afc5ae327f..78837e06cd 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -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) diff --git a/command/agent/config.go b/command/agent/config.go index efb15e9757..2e6b6ae6aa 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -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"` @@ -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 } diff --git a/command/agent/config_test.go b/command/agent/config_test.go index bf939a6981..ca556233c7 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -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) { @@ -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) diff --git a/website/source/docs/agent/options.html.markdown b/website/source/docs/agent/options.html.markdown index 088d72712d..8670b22b8f 100644 --- a/website/source/docs/agent/options.html.markdown +++ b/website/source/docs/agent/options.html.markdown @@ -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.