Added support for config files; logging statements
@@ -7,10 +7,12 @@ import (
"github.com/DataDog/datadog-go/statsd"
"github.com/Sirupsen/logrus"
+ "github.com/stripe/veneur"
)
var (
- hostport = flag.String("hostport", "", "Hostname and port of destination.")
+ configFile = flag.String("f", "", "The Veneur config file to read for settings.")
+ hostport = flag.String("hostport", "", "Hostname and port of destination. Must be used if config file is not present.")
name = flag.String("name", "", "Name of metric to report. Ex: daemontools.service.starts")
gauge = flag.Float64("gauge", 0, "Report a 'gauge' metric. Value must be float64.")
timing = flag.Duration("timing", time.Now().Sub(time.Now()), "Report a 'timing' metric. Value must be parseable by time.ParseDuration.")
@@ -28,11 +30,20 @@ func main() {
passedFlags := make(map[string]bool)
flag.Visit(func(f *flag.Flag) { passedFlags[f.Name] = true })
- if hostport == nil || *hostport == "" || !strings.Contains(*hostport, ":") {
- logrus.Fatal("You must specifiy a valid destination host and port.")
+ addr := ""
+ if passedFlags["f"] && (configFile == nil || *configFile == "") {
+ conf, err := veneur.ReadConfig(*configFile)
+ if err != nil {
+ logrus.WithError(err).Fatal("Error reading config file")
+ }
+ addr = conf.UdpAddress
+ } else if passedFlags["hostport"] && (hostport == nil || *hostport == "" || !strings.Contains(*hostport, ":")) {
+ addr = *hostport
+ } else {
+ logrus.Fatal("You must either specify a Veneur config file or a valid hostport.")
}
- conn, err := statsd.New(*hostport)
+ conn, err := statsd.New(addr)
if err != nil {
panic("ERROR")
}
@@ -43,21 +54,27 @@ func main() {
if passedFlags["gauge"] {
conn.Gauge(*name, *gauge, nil, 1)
+ logrus.Infof("Sending gauge '%s' -> %f", *name, *gauge)
}
if passedFlags["timing"] {
conn.Timing(*name, *timing, nil, 1)
+ logrus.Infof("Sending timing '%s' -> %f", *name, *timing)
}
if passedFlags["timeinms"] {
conn.TimeInMilliseconds(*name, *timeinms, nil, 1)
+ logrus.Infof("Sending timeinms '%s' -> %f", *name, *timeinms)
}
if *incr {
conn.Incr(*name, nil, 1)
+ logrus.Infof("Sending incr '%s'", *name)
}
if *decr {
conn.Decr(*name, nil, 1)
+ logrus.Infof("Sending decr '%s'", *name)
}
if passedFlags["count"] {
conn.Count(*name, *count, nil, 1)
+ logrus.Infof("Sending count '%s' -> %d", *name, *count)
}
}
