From 507fc8acf17352efda0275de407849c79f38151c Mon Sep 17 00:00:00 2001 From: dom Date: Wed, 11 Jul 2018 11:31:20 +0200 Subject: [PATCH] optimize timestamps --- plugins/inputs/rss/rss.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/inputs/rss/rss.go b/plugins/inputs/rss/rss.go index 255e31032..67d8ef01b 100644 --- a/plugins/inputs/rss/rss.go +++ b/plugins/inputs/rss/rss.go @@ -10,7 +10,7 @@ import ( "github.com/mmcdole/gofeed" ) -var ts = time.Now() +var ts time.Time type RSS struct { URLs []string `toml:"urls"` @@ -35,6 +35,10 @@ func (r *RSS) SampleConfig() string { } func (r *RSS) Gather(acc telegraf.Accumulator) error { + if ts.IsZero() { + ts = time.Now() + } + var wg sync.WaitGroup for _, u := range r.URLs { wg.Add(1) @@ -72,15 +76,15 @@ func (r *RSS) gatherFeed(acc telegraf.Accumulator, url string, ts time.Time) err tags["feed_version"] = feed.FeedVersion for _, item := range feed.Items { - time := item.PublishedParsed - if time.Before(ts) { + pubtime := item.PublishedParsed + if pubtime.Before(ts) { continue } fields["title"] = item.Title fields["description"] = item.Description - acc.AddFields("rss", fields, tags, *time) + acc.AddFields("rss", fields, tags, *pubtime) } return nil