Skip to content

Commit

Permalink
Merge pull request #13 from andrecloutier-pd/add-statsd-host-option
Browse files Browse the repository at this point in the history
Added an option to provide a statsd host
  • Loading branch information
theckman authored Jan 29, 2017
2 parents 1c651e1 + 8a6a7b3 commit 5d61ae3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Application Options:
-F, --log-fail when a command fails, log its full output (stdout/stderr) to the log directory using the UUID as the filename
-g, --group=<group> emit a cronner_group:<group> tag with statsd metrics
-G, --event-group=<group> emit a cronner_group:<group> tag with Datadog events, does not get sent with statsd metrics
-H, --statsd-host=<host> destination host to send datadog metrics
-k, --lock lock based on label so that multiple commands with the same label can not run concurrently
-l, --label= name for cron job to be used in statsd emissions and DogStatsd events. alphanumeric only; cronner will lowercase it
--log-path= where to place the log files for command output (path for -F/--log-fail output) (default: /var/log/cronner)
Expand Down
1 change: 1 addition & 0 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type binArgs struct {
LogFail bool `short:"F" long:"log-fail" description:"when a command fails, log its full output (stdout/stderr) to the log directory using the UUID as the filename"`
Group string `short:"g" long:"group" value-name:"<group>" description:"emit a cronner_group:<group> tag with statsd metrics"`
EventGroup string `short:"G" long:"event-group" value-name:"<group>" description:"emit a cronner_group:<group> tag with Datadog events, does not get sent with statsd metrics"`
StatsdHost string `short:"H" long:"statsd-host" value-name:"<host>" description:"destination host to send datadog metrics"`
Lock bool `short:"k" long:"lock" description:"lock based on label so that multiple commands with the same label can not run concurrently"`
Label string `short:"l" long:"label" description:"name for cron job to be used in statsd emissions and DogStatsd events. alphanumeric only; cronner will lowercase it"`
LogPath string `long:"log-path" default:"/var/log/cronner" description:"where to place the log files for command output (path for -F/--log-fail output)"`
Expand Down
6 changes: 6 additions & 0 deletions args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) {
"-F",
"-G", "test_group",
"-g", "metric_group",
"-H", "test_host",
"-k",
"-l", "test",
"-L", "info",
Expand All @@ -151,6 +152,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) {
c.Check(args.LogFail, Equals, true)
c.Check(args.EventGroup, Equals, "test_group")
c.Check(args.Group, Equals, "metric_group")
c.Check(args.StatsdHost, Equals, "test_host")
c.Check(args.Lock, Equals, true)
c.Check(args.Label, Equals, "test")
c.Check(args.LogLevel, Equals, "info")
Expand All @@ -176,6 +178,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) {
"--log-fail",
"--event-group", "test_group",
"--group", "metric_group",
"--statsd-host", "test_host",
"--lock",
"--label", "test",
"--log-path", "/var/log/testcronner",
Expand All @@ -200,6 +203,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) {
c.Check(args.LogFail, Equals, true)
c.Check(args.EventGroup, Equals, "test_group")
c.Check(args.Group, Equals, "metric_group")
c.Check(args.StatsdHost, Equals, "test_host")
c.Check(args.Lock, Equals, true)
c.Check(args.Label, Equals, "test")
c.Check(args.LogPath, Equals, "/var/log/testcronner")
Expand All @@ -223,6 +227,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) {
"--lock-dir=/var/testlock",
"--event-group=test_group",
"--group=metric_group",
"--statsd-host=test_host",
"--label=test",
"--log-path=/var/log/testcronner",
"--log-level=info",
Expand All @@ -240,6 +245,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) {
c.Check(args.LockDir, Equals, "/var/testlock")
c.Check(args.EventGroup, Equals, "test_group")
c.Check(args.Group, Equals, "metric_group")
c.Check(args.StatsdHost, Equals, "test_host")
c.Check(args.Label, Equals, "test")
c.Check(args.LogPath, Equals, "/var/log/testcronner")
c.Check(args.LogLevel, Equals, "info")
Expand Down
7 changes: 6 additions & 1 deletion cronner.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ func main() {
}

// build a Godspeed client
gs, err := godspeed.NewDefault()
var gs *godspeed.Godspeed
if opts.StatsdHost == "" {
gs, err = godspeed.NewDefault()
} else {
gs, err = godspeed.New(opts.StatsdHost, godspeed.DefaultPort, false)
}

// make sure nothing went wrong with Godspeed
if err != nil {
Expand Down

0 comments on commit 5d61ae3

Please sign in to comment.