Move CloudWatch rate limit to config (#1673)
* Move CloudWatch rate limit to config Reference #1670 * make that variable a string * ahem, apparently limiter wants an int * add the ratelimit to the sample config * update the test to include the rate * set a default value of 10 for ratelimit * Move default ratelimit to init
This commit is contained in:
commit
2dc47285bd
|
@ -34,6 +34,11 @@ API endpoint. In the following order the plugin will attempt to authenticate.
|
||||||
## Metric Statistic Namespace (required)
|
## Metric Statistic Namespace (required)
|
||||||
namespace = 'AWS/ELB'
|
namespace = 'AWS/ELB'
|
||||||
|
|
||||||
|
## Maximum requests per second. Note that the global default AWS rate limit is
|
||||||
|
## 10 reqs/sec, so if you define multiple namespaces, these should add up to a
|
||||||
|
## maximum of 10. Optional - default value is 10.
|
||||||
|
ratelimit = 10
|
||||||
|
|
||||||
## Metrics to Pull (optional)
|
## Metrics to Pull (optional)
|
||||||
## Defaults to all Metrics in Namespace if nothing is provided
|
## Defaults to all Metrics in Namespace if nothing is provided
|
||||||
## Refreshes Namespace available metrics every 1h
|
## Refreshes Namespace available metrics every 1h
|
||||||
|
|
|
@ -33,6 +33,7 @@ type (
|
||||||
Namespace string `toml:"namespace"`
|
Namespace string `toml:"namespace"`
|
||||||
Metrics []*Metric `toml:"metrics"`
|
Metrics []*Metric `toml:"metrics"`
|
||||||
CacheTTL internal.Duration `toml:"cache_ttl"`
|
CacheTTL internal.Duration `toml:"cache_ttl"`
|
||||||
|
RateLimit int `toml:"ratelimit"`
|
||||||
client cloudwatchClient
|
client cloudwatchClient
|
||||||
metricCache *MetricCache
|
metricCache *MetricCache
|
||||||
}
|
}
|
||||||
|
@ -96,6 +97,11 @@ func (c *CloudWatch) SampleConfig() string {
|
||||||
## Metric Statistic Namespace (required)
|
## Metric Statistic Namespace (required)
|
||||||
namespace = 'AWS/ELB'
|
namespace = 'AWS/ELB'
|
||||||
|
|
||||||
|
## Maximum requests per second. Note that the global default AWS rate limit is
|
||||||
|
## 10 reqs/sec, so if you define multiple namespaces, these should add up to a
|
||||||
|
## maximum of 10. Optional - default value is 10.
|
||||||
|
ratelimit = 10
|
||||||
|
|
||||||
## Metrics to Pull (optional)
|
## Metrics to Pull (optional)
|
||||||
## Defaults to all Metrics in Namespace if nothing is provided
|
## Defaults to all Metrics in Namespace if nothing is provided
|
||||||
## Refreshes Namespace available metrics every 1h
|
## Refreshes Namespace available metrics every 1h
|
||||||
|
@ -175,7 +181,7 @@ func (c *CloudWatch) Gather(acc telegraf.Accumulator) error {
|
||||||
// limit concurrency or we can easily exhaust user connection limit
|
// limit concurrency or we can easily exhaust user connection limit
|
||||||
// see cloudwatch API request limits:
|
// see cloudwatch API request limits:
|
||||||
// http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/cloudwatch_limits.html
|
// http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/cloudwatch_limits.html
|
||||||
lmtr := limiter.NewRateLimiter(10, time.Second)
|
lmtr := limiter.NewRateLimiter(c.RateLimit, time.Second)
|
||||||
defer lmtr.Stop()
|
defer lmtr.Stop()
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(len(metrics))
|
wg.Add(len(metrics))
|
||||||
|
@ -195,7 +201,8 @@ func init() {
|
||||||
inputs.Add("cloudwatch", func() telegraf.Input {
|
inputs.Add("cloudwatch", func() telegraf.Input {
|
||||||
ttl, _ := time.ParseDuration("1hr")
|
ttl, _ := time.ParseDuration("1hr")
|
||||||
return &CloudWatch{
|
return &CloudWatch{
|
||||||
CacheTTL: internal.Duration{Duration: ttl},
|
CacheTTL: internal.Duration{Duration: ttl},
|
||||||
|
RateLimit: 10,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,7 @@ func TestGather(t *testing.T) {
|
||||||
Namespace: "AWS/ELB",
|
Namespace: "AWS/ELB",
|
||||||
Delay: internalDuration,
|
Delay: internalDuration,
|
||||||
Period: internalDuration,
|
Period: internalDuration,
|
||||||
|
RateLimit: 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
Loading…
Reference in New Issue