Add polling method to logparser and tail inputs (#3213)

This commit is contained in:
Daniel Nelson
2017-09-11 11:56:04 -07:00
committed by GitHub
parent cb40972635
commit b06e2a0c3d
4 changed files with 42 additions and 6 deletions

View File

@@ -15,10 +15,15 @@ import (
"github.com/influxdata/telegraf/plugins/parsers"
)
const (
defaultWatchMethod = "inotify"
)
type Tail struct {
Files []string
FromBeginning bool
Pipe bool
WatchMethod string
tailers []*tail.Tail
parser parsers.Parser
@@ -50,6 +55,9 @@ const sampleConfig = `
## Whether file is a named pipe
pipe = false
## Method used to watch for file updates. Can be either "inotify" or "poll".
# watch_method = "inotify"
## Data format to consume.
## Each data format has its own unique set of configuration options, read
## more about them here:
@@ -83,6 +91,11 @@ func (t *Tail) Start(acc telegraf.Accumulator) error {
}
}
var poll bool
if t.WatchMethod == "poll" {
poll = true
}
// Create a "tailer" for each file
for _, filepath := range t.Files {
g, err := globpath.Compile(filepath)
@@ -96,6 +109,7 @@ func (t *Tail) Start(acc telegraf.Accumulator) error {
Follow: true,
Location: seek,
MustExist: true,
Poll: poll,
Pipe: t.Pipe,
Logger: tail.DiscardingLogger,
})