diff --git a/README.md b/README.md index 25a698d8..3fb16b94 100644 --- a/README.md +++ b/README.md @@ -788,6 +788,14 @@ The rate limit service generates various statistics for each configured rate lim users both for visibility and for setting alarms. Ratelimit uses [gostats](https://github.com/lyft/gostats) as its statistics library. Please refer to [gostats' documentation](https://godoc.org/github.com/lyft/gostats) for more information on the library. +Statistics default to using [StatsD](https://github.com/statsd/statsd) and configured via the env vars from [gostats](https://github.com/lyft/gostats). + +To output statistics to stdout instead, set env var `USE_STATSD` to `false` + +Configure statistics output frequency with `STATS_FLUSH_INTERVAL`, where the type is `time.Duration`, e.g. `10s` is the default value. + +To disable statistics entirely, set env var `DISABLE_STATS` to `true` + Rate Limit Statistic Path: ``` diff --git a/src/service_cmd/runner/runner.go b/src/service_cmd/runner/runner.go index 6e125be9..f196ea4f 100644 --- a/src/service_cmd/runner/runner.go +++ b/src/service_cmd/runner/runner.go @@ -39,14 +39,21 @@ type Runner struct { func NewRunner(s settings.Settings) Runner { var store gostats.Store - // use statsd - if s.UseStatsd { + + if s.DisableStats { + logger.Info("Stats disabled") + store = gostats.NewStore(gostats.NewNullSink(), false) + } else if s.UseStatsd { + logger.Info("Stats initialized for statsd") store = gostats.NewStore(gostats.NewTCPStatsdSink(gostats.WithStatsdHost(s.StatsdHost), gostats.WithStatsdPort(s.StatsdPort)), false) } else { - store = gostats.NewStore(gostats.NewNullSink(), false) + logger.Info("Stats initialized for stdout") + store = gostats.NewStore(gostats.NewLoggingSink(), false) } - go store.Start(time.NewTicker(10 * time.Second)) + logger.Infof("Stats flush interval: %s", s.StatsFlushInterval) + + go store.Start(time.NewTicker(s.StatsFlushInterval)) return Runner{ statsManager: stats.NewStatManager(store, s), diff --git a/src/settings/settings.go b/src/settings/settings.go index f3c3721d..5a6c40f1 100644 --- a/src/settings/settings.go +++ b/src/settings/settings.go @@ -76,10 +76,12 @@ type Settings struct { XdsClientBackoffJitter bool `envconfig:"XDS_CLIENT_BACKOFF_JITTER" default:"true"` // Stats-related settings - UseStatsd bool `envconfig:"USE_STATSD" default:"true"` - StatsdHost string `envconfig:"STATSD_HOST" default:"localhost"` - StatsdPort int `envconfig:"STATSD_PORT" default:"8125"` - ExtraTags map[string]string `envconfig:"EXTRA_TAGS" default:""` + UseStatsd bool `envconfig:"USE_STATSD" default:"true"` + StatsdHost string `envconfig:"STATSD_HOST" default:"localhost"` + StatsdPort int `envconfig:"STATSD_PORT" default:"8125"` + ExtraTags map[string]string `envconfig:"EXTRA_TAGS" default:""` + StatsFlushInterval time.Duration `envconfig:"STATS_FLUSH_INTERVAL" default:"10s"` + DisableStats bool `envconfig:"DISABLE_STATS" default:"false"` // Settings for rate limit configuration RuntimePath string `envconfig:"RUNTIME_ROOT" default:"/srv/runtime_data/current"`