optimize timestamps
This commit is contained in:
parent
b67ac078b8
commit
507fc8acf1
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue