Skip to content

Commit

Permalink
Issue #126: Add Riemann metrics support
Browse files Browse the repository at this point in the history
  • Loading branch information
magiconair committed Aug 29, 2016
1 parent f208fcd commit a8eb521
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Metrics struct {
Prefix string
Interval time.Duration
GraphiteAddr string
RiemannAddr string
StatsDAddr string
}

Expand Down
1 change: 1 addition & 0 deletions config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions fabio.properties
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@
# <empty>: 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
Expand Down Expand Up @@ -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".
#
Expand Down
13 changes: 13 additions & 0 deletions metrics/gometrics/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 == "" {
Expand Down
4 changes: 4 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a8eb521

Please sign in to comment.