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

added statsd support #139

Merged
merged 1 commit into from Aug 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions config/config.go
Expand Up @@ -71,6 +71,7 @@ type Metrics struct {
Prefix string
Interval time.Duration
GraphiteAddr string
StatsDAddr string
}

type Registry struct {
Expand Down
1 change: 1 addition & 0 deletions config/load.go
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.StatsDAddr, "metrics.statsd.addr", Default.Metrics.StatsDAddr, "graphite 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")
f.StringVar(&cfg.Registry.Static.Routes, "registry.static.routes", Default.Registry.Static.Routes, "static routes")
Expand Down
7 changes: 7 additions & 0 deletions fabio.properties
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}
# statsd: report metrics to StatsD on ${metrics.statsd.addr}
#
# The default is
#
Expand Down Expand Up @@ -495,6 +496,12 @@
#
# metrics.graphite.addr =

# metrics.statsd.addr configures the host:port of the Graphite
# server. This is required when ${metrics.target} is set to "statsd".
#
# The default is
#
# metrics.statsd.addr =

# runtime.gogc configures GOGC (the GC target percentage).
#
Expand Down
19 changes: 19 additions & 0 deletions metrics/metrics.go
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/cyberdelia/go-metrics-graphite"
"github.com/eBay/fabio/config"
"github.com/eBay/fabio/exit"
"github.com/pubnub/go-metrics-statsd"
gometrics "github.com/rcrowley/go-metrics"
)

Expand Down Expand Up @@ -41,6 +42,14 @@ func Init(cfg config.Metrics) error {

log.Printf("[INFO] Sending metrics to Graphite on %s as %q", cfg.GraphiteAddr, pfx)
return initGraphite(cfg.GraphiteAddr, cfg.Interval)
case "statsd":
if cfg.StatsDAddr == "" {
return errors.New("metrics: statsd addr missing")
}

log.Printf("[INFO] Sending metrics to StatsD on %s as %q", cfg.StatsDAddr, pfx)
return initStatsD(cfg.StatsDAddr, cfg.Interval)

case "":
log.Printf("[INFO] Metrics disabled")
default:
Expand Down Expand Up @@ -96,3 +105,13 @@ func initGraphite(addr string, interval time.Duration) error {
go graphite.Graphite(ServiceRegistry, interval, pfx, a)
return nil
}

func initStatsD(addr string, interval time.Duration) error {
a, err := net.ResolveUDPAddr("udp", addr)
if err != nil {
return fmt.Errorf("metrics: cannot connect to StatsD: %s", err)
}
go statsd.StatsD(gometrics.DefaultRegistry, interval, pfx, a)
go statsd.StatsD(ServiceRegistry, interval, pfx, a)
return nil
}
21 changes: 21 additions & 0 deletions vendor/github.com/pubnub/go-metrics-statsd/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions vendor/github.com/pubnub/go-metrics-statsd/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

117 changes: 117 additions & 0 deletions vendor/github.com/pubnub/go-metrics-statsd/statsd.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions vendor/vendor.json
Expand Up @@ -12,6 +12,11 @@
"revision": "b8345b7f01d571b05366d5791a034d872f1bb36f",
"revisionTime": "2015-08-25T20:22:00-07:00"
},
{
"path": "github.com/pubnub/go-metrics-statsd",
"revision": "979a88f88cc815576d43a09678d3925e84ca0ed9",
"revisionTime": "2016-08-12T16:29:00-09:00"
},
{
"path": "github.com/fatih/structs",
"revision": "5ada2f449b108d87dbd8c1e60c32cdd065c27886",
Expand Down