Skip to content

Commit

Permalink
Allow configuring datadog tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Castell committed Feb 12, 2017
1 parent f22b325 commit 3c807ee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dkron/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 9 additions & 0 deletions dkron/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -130,20 +135,24 @@ 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)

if err := cmdFlags.Parse(args); err != nil {
log.Fatal(err)
}

// Set array params defaults
ut, err := UnmarshalTags(tag)
if err != nil {
log.Fatal(err)
}
viper.SetDefault("tags", ut)
viper.SetDefault("join", startJoin)
viper.SetDefault("webhook_headers", webhookHeaders)
viper.SetDefault("dog_statsd_tags", dogStatsdTags)

return ReadConfig(agent)
}
Expand Down
7 changes: 7 additions & 0 deletions dkron/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 3c807ee

Please sign in to comment.