From eac7f23609178426de692805210811687b1dd511 Mon Sep 17 00:00:00 2001 From: John Engelman Date: Wed, 4 May 2016 12:01:19 -0500 Subject: [PATCH] Allow configuring cache_ttl for cloudwatch metrics. --- plugins/inputs/cloudwatch/cloudwatch.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/cloudwatch/cloudwatch.go b/plugins/inputs/cloudwatch/cloudwatch.go index bf6fe7031..509457ecd 100644 --- a/plugins/inputs/cloudwatch/cloudwatch.go +++ b/plugins/inputs/cloudwatch/cloudwatch.go @@ -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(),