Allow configuring cache_ttl for cloudwatch metrics.

This commit is contained in:
John Engelman 2016-05-04 12:01:19 -05:00
parent a2f66682df
commit eac7f23609
1 changed files with 9 additions and 2 deletions

View File

@ -22,6 +22,7 @@ type (
Delay internal.Duration `toml:"delay"`
Namespace string `toml:"namespace"`
Metrics []*Metric `toml:"metrics"`
CacheTTL string `toml:"cache_ttl"`
client cloudwatchClient
metricCache *MetricCache
}
@ -74,6 +75,10 @@ func (c *CloudWatch) SampleConfig() string {
## gaps or overlap in pulled data
interval = '1m'
## Configure the TTL for the internal cache of metrics.
## Defaults to 1 hr if not specified
#cache_ttl = '10m'
## Metric Statistic Namespace (required)
namespace = 'AWS/ELB'
@ -152,7 +157,9 @@ func (c *CloudWatch) Gather(acc telegraf.Accumulator) error {
func init() {
inputs.Add("cloudwatch", func() telegraf.Input {
return &CloudWatch{}
return &CloudWatch{
CacheTTL: "1hr",
}
})
}
@ -197,7 +204,7 @@ func (c *CloudWatch) fetchNamespaceMetrics() (metrics []*cloudwatch.Metric, err
more = token != nil
}
cacheTTL, _ := time.ParseDuration("1hr")
cacheTTL, _ := time.ParseDuration(c.CacheTTL)
c.metricCache = &MetricCache{
Metrics: metrics,
Fetched: time.Now(),