diff --git a/config/config.go b/config/config.go index 884fcbb42..2454fcf9a 100644 --- a/config/config.go +++ b/config/config.go @@ -71,6 +71,7 @@ type Metrics struct { Prefix string Interval time.Duration GraphiteAddr string + RiemannAddr string StatsDAddr string } diff --git a/config/load.go b/config/load.go index 29d8f6055..c77fc1525 100644 --- a/config/load.go +++ b/config/load.go @@ -109,6 +109,7 @@ func load(p *properties.Properties) (cfg *Config, err error) { f.StringVar(&cfg.Metrics.Prefix, "metrics.prefix", Default.Metrics.Prefix, "prefix for reported metrics") f.DurationVar(&cfg.Metrics.Interval, "metrics.interval", Default.Metrics.Interval, "metrics reporting interval") f.StringVar(&cfg.Metrics.GraphiteAddr, "metrics.graphite.addr", Default.Metrics.GraphiteAddr, "graphite server address") + f.StringVar(&cfg.Metrics.RiemannAddr, "metrics.riemann.addr", Default.Metrics.RiemannAddr, "riemann server address") f.StringVar(&cfg.Metrics.StatsDAddr, "metrics.statsd.addr", Default.Metrics.StatsDAddr, "statsd server address") f.StringVar(&cfg.Registry.Backend, "registry.backend", Default.Registry.Backend, "registry backend") f.StringVar(&cfg.Registry.File.Path, "registry.file.path", Default.Registry.File.Path, "path to file based routing table") diff --git a/config/load_test.go b/config/load_test.go index 525b05e9b..b6275c325 100644 --- a/config/load_test.go +++ b/config/load_test.go @@ -47,6 +47,7 @@ metrics.target = graphite metrics.prefix = someprefix metrics.interval = 5s metrics.graphite.addr = 5.6.7.8:9999 +metrics.riemann.addr = 8.8.8.8:7777 runtime.gogc = 666 runtime.gomaxprocs = 12 ui.addr = 7.8.9.0:1234 @@ -121,6 +122,7 @@ aws.apigw.cert.cn = furb Prefix: "someprefix", Interval: 5 * time.Second, GraphiteAddr: "5.6.7.8:9999", + RiemannAddr: "8.8.8.8:7777", }, Runtime: Runtime{ GOGC: 666, diff --git a/fabio.properties b/fabio.properties index 336c8171c..218cc36a1 100644 --- a/fabio.properties +++ b/fabio.properties @@ -461,6 +461,7 @@ # : do not report metrics # stdout: report metrics to stdout # graphite: report metrics to Graphite on ${metrics.graphite.addr} +# riemann: report metrics to Riemann on ${metrics.riemann.addr} # statsd: report metrics to StatsD on ${metrics.statsd.addr} # # The default is @@ -497,6 +498,14 @@ # metrics.graphite.addr = +# metrics.riemann.addr configures the host:port of the Riemann +# server. This is required when ${metrics.target} is set to "riemann". +# +# The default is +# +# metrics.riemann.addr = + + # metrics.statsd.addr configures the host:port of the StatsD # server. This is required when ${metrics.target} is set to "statsd". # diff --git a/metrics/gometrics/provider.go b/metrics/gometrics/provider.go index f3f64bded..c7c6c2c35 100644 --- a/metrics/gometrics/provider.go +++ b/metrics/gometrics/provider.go @@ -15,6 +15,7 @@ import ( "github.com/eBay/fabio/metrics/metricslib" graphite "github.com/cyberdelia/go-metrics-graphite" + riemann "github.com/pingles/go-metrics-riemann" statsd "github.com/pubnub/go-metrics-statsd" gm "github.com/rcrowley/go-metrics" ) @@ -45,6 +46,18 @@ func GraphiteProvider(prefix, addr string, interval time.Duration) (metricslib.P return &gmProvider{registry}, nil } +// RiemannProvider returns a provider that reports to a Riemann server. +func RiemannProvider(prefix, addr string, interval time.Duration) (metricslib.Provider, error) { + if addr == "" { + return nil, errors.New("metrics: riemann addr missing") + } + + registry := gm.NewRegistry() + go riemann.Report(gm.DefaultRegistry, interval, addr) + go riemann.Report(registry, interval, addr) + return &gmProvider{registry}, nil +} + // StatsDProvider returns a provider that reports to a StatsD server. func StatsDProvider(prefix, addr string, interval time.Duration) (metricslib.Provider, error) { if addr == "" { diff --git a/metrics/metrics.go b/metrics/metrics.go index 7d063c38a..5bfe3a958 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -61,6 +61,10 @@ func Init(cfg config.Metrics) error { log.Printf("[INFO] Sending metrics to Graphite on %s as %q", cfg.GraphiteAddr, prefix) Provider, err = gometrics.GraphiteProvider(prefix, cfg.GraphiteAddr, cfg.Interval) + case "riemann": + log.Printf("[INFO] Sending metrics to Riemann on %s as %q", cfg.RiemannAddr, prefix) + Provider, err = gometrics.RiemannProvider(prefix, cfg.RiemannAddr, cfg.Interval) + case "statsd": log.Printf("[INFO] Sending metrics to StatsD on %s as %q", cfg.StatsDAddr, prefix) Provider, err = gometrics.StatsDProvider(prefix, cfg.StatsDAddr, cfg.Interval)