Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command line flag to specify statsd port #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type binArgs struct {
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"`
StatsdPort int `long:"statsd-port" value-name:"<port>" description:"destination port 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
4 changes: 4 additions & 0 deletions args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) {
"--event-group", "test_group",
"--group", "metric_group",
"--statsd-host", "test_host",
"--statsd-port", "8127",
"--lock",
"--label", "test",
"--log-path", "/var/log/testcronner",
Expand Down Expand Up @@ -212,6 +213,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) {
c.Check(args.EventGroup, Equals, "test_group")
c.Check(args.Group, Equals, "metric_group")
c.Check(args.StatsdHost, Equals, "test_host")
c.Check(args.StatsdPort, Equals, int(8127))
c.Check(args.Lock, Equals, true)
c.Check(args.Label, Equals, "test")
c.Check(args.LogPath, Equals, "/var/log/testcronner")
Expand Down Expand Up @@ -239,6 +241,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) {
"--event-group=test_group",
"--group=metric_group",
"--statsd-host=test_host",
"--statsd-port=8127",
"--label=test",
"--log-path=/var/log/testcronner",
"--log-level=info",
Expand All @@ -259,6 +262,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) {
c.Check(args.EventGroup, Equals, "test_group")
c.Check(args.Group, Equals, "metric_group")
c.Check(args.StatsdHost, Equals, "test_host")
c.Check(args.StatsdPort, Equals, int(8127))
c.Check(args.Label, Equals, "test")
c.Check(args.LogPath, Equals, "/var/log/testcronner")
c.Check(args.LogLevel, Equals, "info")
Expand Down
17 changes: 13 additions & 4 deletions cronner.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,21 @@ func main() {

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

var StatsdHost string
StatsdHost = godspeed.DefaultHost
if opts.StatsdHost != "" {
StatsdHost = opts.StatsdHost
}

var StatsdPort int
StatsdPort = godspeed.DefaultPort
if opts.StatsdPort != 0 {
StatsdPort = opts.StatsdPort
}

gs, err = godspeed.New(StatsdHost, StatsdPort, false)

// make sure nothing went wrong with Godspeed
if err != nil {
logger.Errorf("error: %v\n", err)
Expand Down