From dca8c7957619a55c5ff091b05de6c1cd950a26cb Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Thu, 20 Feb 2014 14:59:54 -0800 Subject: [PATCH] agent: Adding support for statsite telemetry --- command/agent/command.go | 18 ++++++++++++++++-- command/agent/config.go | 4 ++++ .../source/docs/agent/options.html.markdown | 6 ++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/command/agent/command.go b/command/agent/command.go index 641a431106..089b6c9d42 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -59,6 +59,7 @@ func (c *Command) readConfig() *Config { cmdFlags.StringVar(&cmdConfig.DNSAddr, "dns-addr", "", "address to bind dns server to") cmdFlags.BoolVar(&cmdConfig.Server, "server", false, "run agent as server") cmdFlags.BoolVar(&cmdConfig.Bootstrap, "bootstrap", false, "enable server bootstrap mode") + cmdFlags.StringVar(&cmdConfig.StatsiteAddr, "statsite", "", "address of statsite instance") if err := cmdFlags.Parse(c.args); err != nil { return nil } @@ -195,8 +196,21 @@ func (c *Command) Run(args []string) int { inm := metrics.NewInmemSink(10*time.Second, time.Minute) metrics.DefaultInmemSignal(inm) metricsConf := metrics.DefaultConfig("consul") - metricsConf.EnableHostname = false - metrics.NewGlobal(metricsConf, inm) + + // Optionally configure a statsite sink if provided + 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) + + } else { + metricsConf.EnableHostname = false + metrics.NewGlobal(metricsConf, inm) + } // Create the agent if err := c.setupAgent(config, logOutput, logWriter); err != nil { diff --git a/command/agent/config.go b/command/agent/config.go index bc59e07847..57b3a9e77e 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -93,6 +93,10 @@ type Config struct { // the INT signal. Defaults false. This can be changed on reload. SkipLeaveOnInt bool `mapstructure:"skip_leave_on_interrupt"` + // StatsiteAddr is the address of a statsite instance. If provided, + // metrics will be streamed to that instance. + StatsiteAddr string `mapstructure:"statsite_addr"` + // Checks holds the provided check definitions Checks []*CheckDefinition `mapstructure:"-"` diff --git a/website/source/docs/agent/options.html.markdown b/website/source/docs/agent/options.html.markdown index 5631dd149c..2c436dcd5c 100644 --- a/website/source/docs/agent/options.html.markdown +++ b/website/source/docs/agent/options.html.markdown @@ -114,6 +114,10 @@ The options below are all specified on the command-line. nodes are able to self-elect. Once there are multiple servers in a datacenter, it is generally a good idea to disable bootstrap mode on all of them. +* `-statsite` - This flag 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. + ## Configuration Files In addition to the command-line options, configuration can be put into @@ -194,3 +198,5 @@ They are documented seperately under [check configuration](/docs/agent/checks.ht gracefully leave, but setting this to true disables that. Defaults to false. Interrupts are usually from a Control-C from a shell. +* `statsite_addr` - Equivalent to the `-statsite` command-line flag. +