optimize timestamps
This commit is contained in:
parent
b67ac078b8
commit
507fc8acf1
|
@ -10,7 +10,7 @@ import (
|
||||||
"github.com/mmcdole/gofeed"
|
"github.com/mmcdole/gofeed"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ts = time.Now()
|
var ts time.Time
|
||||||
|
|
||||||
type RSS struct {
|
type RSS struct {
|
||||||
URLs []string `toml:"urls"`
|
URLs []string `toml:"urls"`
|
||||||
|
@ -35,6 +35,10 @@ func (r *RSS) SampleConfig() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RSS) Gather(acc telegraf.Accumulator) error {
|
func (r *RSS) Gather(acc telegraf.Accumulator) error {
|
||||||
|
if ts.IsZero() {
|
||||||
|
ts = time.Now()
|
||||||
|
}
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for _, u := range r.URLs {
|
for _, u := range r.URLs {
|
||||||
wg.Add(1)
|
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
|
tags["feed_version"] = feed.FeedVersion
|
||||||
|
|
||||||
for _, item := range feed.Items {
|
for _, item := range feed.Items {
|
||||||
time := item.PublishedParsed
|
pubtime := item.PublishedParsed
|
||||||
if time.Before(ts) {
|
if pubtime.Before(ts) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
fields["title"] = item.Title
|
fields["title"] = item.Title
|
||||||
fields["description"] = item.Description
|
fields["description"] = item.Description
|
||||||
|
|
||||||
acc.AddFields("rss", fields, tags, *time)
|
acc.AddFields("rss", fields, tags, *pubtime)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue