diff --git a/dkron/agent.go b/dkron/agent.go index e88e3af6a..a98e6b459 100644 --- a/dkron/agent.go +++ b/dkron/agent.go @@ -102,6 +102,10 @@ Options: -webhook-header Headers to use when calling the webhook URL. Can be specified multiple times. -log-level=info Log level (debug, info, warn, error, fatal, panic). Default to info. + + -dog-statsd-addr DataDog Agent address + -dog-statsd-tags Datadog tags, specified as key:value + -statsd-addr Statsd Address ` return strings.TrimSpace(helpText) } diff --git a/dkron/config.go b/dkron/config.go index c494c7276..ffff71830 100644 --- a/dkron/config.go +++ b/dkron/config.go @@ -48,7 +48,12 @@ type Config struct { WebhookPayload string WebhookHeaders []string + // DogStatsdAddr is the address of a dogstatsd instance. If provided, + // metrics will be sent to that instance DogStatsdAddr string + // 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 StatsdAddr string } @@ -130,6 +135,8 @@ func NewConfig(args []string, agent *AgentCommand) *Config { cmdFlags.String("dog-statsd-addr", "", "DataDog Agent address") viper.SetDefault("dog_statsd_addr", cmdFlags.Lookup("dog-statsd-addr").Value) + var dogStatsdTags []string + cmdFlags.Var((*AppendSliceValue)(&dogStatsdTags), "dog-statsd-tags", "Datadog tags, specified as key:value") cmdFlags.String("statsd-addr", "", "Statsd Address") viper.SetDefault("statsd_addr", cmdFlags.Lookup("statsd-addr").Value) @@ -137,6 +144,7 @@ func NewConfig(args []string, agent *AgentCommand) *Config { log.Fatal(err) } + // Set array params defaults ut, err := UnmarshalTags(tag) if err != nil { log.Fatal(err) @@ -144,6 +152,7 @@ func NewConfig(args []string, agent *AgentCommand) *Config { viper.SetDefault("tags", ut) viper.SetDefault("join", startJoin) viper.SetDefault("webhook_headers", webhookHeaders) + viper.SetDefault("dog_statsd_tags", dogStatsdTags) return ReadConfig(agent) } diff --git a/dkron/metrics.go b/dkron/metrics.go index cff1cec72..c77665d94 100644 --- a/dkron/metrics.go +++ b/dkron/metrics.go @@ -27,11 +27,18 @@ func initMetrics(a *AgentCommand) int { // Configure the DogStatsd sink if a.config.DogStatsdAddr != "" { + var tags []string + + if a.config.DogStatsdTags != nil { + tags = a.config.DogStatsdTags + } + sink, err := datadog.NewDogStatsdSink(a.config.DogStatsdAddr, a.config.NodeName) if err != nil { a.Ui.Error(fmt.Sprintf("Failed to start DogStatsd sink. Got: %s", err)) return 1 } + sink.SetTags(tags) fanout = append(fanout, sink) }