Skip to content

Commit

Permalink
Merge pull request #4 from jcoene/config-env-vars
Browse files Browse the repository at this point in the history
Support configuration with environment variables
  • Loading branch information
jcoene committed Feb 25, 2014
2 parents c98130c + c04ae5d commit 1dc2fd9
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
statsd_darwin_amd64
statsd_linux_amd64
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: go

go:
- 1.2

install:
- export PATH=$PATH:$HOME/gopath/bin
- go get code.google.com/p/go.tools/cmd/cover
- go get -t

script:
- go test -cover
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
default: fmt run

fmt:
go fmt *.go

test:
go test -cover
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
# StatsD Server for Librato

This is an implementation of Etsy's StatsD written in Go that submits data to Librato Metrics.
[![Build Status](https://secure.travis-ci.org/jcoene/statsd-librato.png?branch=master)](http://travis-ci.org/jcoene/statsd-librato)

This was forked from [jbuchbinder/statsd-go](https://github.com/jbuchbinder/statsd-go) and altered to provide support for Librato as a submission backend.
This is an implementation of Etsy's StatsD written in Go that submits data to Librato Metrics.

# Usage

```
Usage of statsd:
-address="0.0.0.0:8125": UDP service address
-debug=false: Enable Debugging
-flush=30: Flush Interval (seconds)
-percentiles="": Percentiles to track (eg. "95,99.5")
-token="": Librato API Token
-user="": Librato Username
-address="0.0.0.0:8125": udp listen address
-debug=false: enable logging of inputs and submissions
-flush=60: interval at which data is sent to librato (in seconds)
-percentiles="": comma separated list of percentiles to calculate for timers (eg. "95,99.5")
-source="": librato api source (LIBRATO_SOURCE)
-token="": librato api token (LIBRATO_TOKEN)
-user="": librato api username (LIBRATO_USER)
```

## Credits

This was forked from [jbuchbinder/statsd-go](https://github.com/jbuchbinder/statsd-go) and altered to provide support for Librato as a submission backend.

## License

MIT License, see LICENSE for details.
41 changes: 34 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ var sanitizeRegexp = regexp.MustCompile("[^a-zA-Z0-9\\-_\\.:\\|@]")
var packetRegexp = regexp.MustCompile("([a-zA-Z0-9_\\.]+):(\\-?[0-9\\.]+)\\|(c|ms|g)(\\|@([0-9\\.]+))?")

var (
serviceAddress = flag.String("address", "0.0.0.0:8125", "UDP service address")
libratoUser = flag.String("user", "", "Librato Username")
libratoToken = flag.String("token", "", "Librato API Token")
libratoSource = flag.String("source", "", "Librato Source")
flushInterval = flag.Int64("flush", 60, "Flush Interval (seconds)")
percentiles = flag.String("percentiles", "", "List of Percentiles to Calculate with timers")
debug = flag.Bool("debug", false, "Enable Debugging")
serviceAddress = flag.String("address", "0.0.0.0:8125", "udp listen address")
libratoUser = flag.String("user", "", "librato api username (LIBRATO_USER)")
libratoToken = flag.String("token", "", "librato api token (LIBRATO_TOKEN)")
libratoSource = flag.String("source", "", "librato api source (LIBRATO_SOURCE)")
flushInterval = flag.Int64("flush", 60, "interval at which data is sent to librato (in seconds)")
percentiles = flag.String("percentiles", "", "comma separated list of percentiles to calculate for timers (eg. \"95,99.5\")")
debug = flag.Bool("debug", false, "enable logging of inputs and submissions")
)

var (
Expand Down Expand Up @@ -292,6 +292,33 @@ func main() {
log = logger.NewLogger(logger.LOG_LEVEL_INFO, "statsd")
}

if *libratoUser == "" {
if !getEnv(libratoUser, "LIBRATO_USER") {
log.Fatal("specify a librato user with -user or the LIBRATO_USER environment variable")
}
}

if *libratoToken == "" {
if !getEnv(libratoToken, "LIBRATO_TOKEN") {
log.Fatal("specify a librato token with -token or the LIBRATO_TOKEN environment variable")
}
}

if *libratoSource == "" {
getEnv(libratoSource, "LIBRATO_SOURCE")
}

log.Info("user: %s, token: %s, source: %s", *libratoUser, *libratoToken, *libratoSource)

go listen()
monitor()
}

func getEnv(p *string, key string) bool {
if s := os.Getenv(key); s != "" {
*p = s
return true
}

return false
}
9 changes: 9 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import (
"testing"
)

func TestBuilds(t *testing.T) {
return
}

0 comments on commit 1dc2fd9

Please sign in to comment.