fix tail input seeking when used with pipe (#2090)

This commit is contained in:
Patrick Hemmer 2016-12-16 09:01:49 -05:00 committed by Cameron Sparr
parent d27c78a979
commit f57b8aac0b
3 changed files with 19 additions and 5 deletions

View File

@ -31,6 +31,7 @@ in their config file.
- [#2049](https://github.com/influxdata/telegraf/pull/2049): Fix the Value data format not trimming null characters from input. - [#2049](https://github.com/influxdata/telegraf/pull/2049): Fix the Value data format not trimming null characters from input.
- [#1949](https://github.com/influxdata/telegraf/issues/1949): Fix windows `net` plugin. - [#1949](https://github.com/influxdata/telegraf/issues/1949): Fix windows `net` plugin.
- [#1775](https://github.com/influxdata/telegraf/issues/1775): Cache & expire metrics for delivery to prometheus
- [#1775](https://github.com/influxdata/telegraf/issues/1775): Cache & expire metrics for delivery to prometheus. - [#1775](https://github.com/influxdata/telegraf/issues/1775): Cache & expire metrics for delivery to prometheus.
- [#2146](https://github.com/influxdata/telegraf/issues/2146): Fix potential panic in aggregator plugin metric maker. - [#2146](https://github.com/influxdata/telegraf/issues/2146): Fix potential panic in aggregator plugin metric maker.
- [#1843](https://github.com/influxdata/telegraf/pull/1843) & [#1668](https://github.com/influxdata/telegraf/issues/1668): Add optional ability to define PID as a tag. - [#1843](https://github.com/influxdata/telegraf/pull/1843) & [#1668](https://github.com/influxdata/telegraf/issues/1668): Add optional ability to define PID as a tag.
@ -41,6 +42,7 @@ in their config file.
- [#1693](https://github.com/influxdata/telegraf/issues/1693): Properly collect nested jolokia struct data. - [#1693](https://github.com/influxdata/telegraf/issues/1693): Properly collect nested jolokia struct data.
- [#1917](https://github.com/influxdata/telegraf/pull/1917): fix puppetagent inputs plugin to support string for config variable. - [#1917](https://github.com/influxdata/telegraf/pull/1917): fix puppetagent inputs plugin to support string for config variable.
- [#1987](https://github.com/influxdata/telegraf/issues/1987): fix docker input plugin tags when registry has port. - [#1987](https://github.com/influxdata/telegraf/issues/1987): fix docker input plugin tags when registry has port.
- [#2089](https://github.com/influxdata/telegraf/issues/2089): Fix tail input when reading from a pipe.
## v1.1.2 [2016-12-12] ## v1.1.2 [2016-12-12]

View File

@ -36,6 +36,8 @@ The plugin expects messages in one of the
files = ["/var/mymetrics.out"] files = ["/var/mymetrics.out"]
## Read file from beginning. ## Read file from beginning.
from_beginning = false from_beginning = false
## Whether file is a named pipe
pipe = false
## Data format to consume. ## Data format to consume.
## Each data format has it's own unique set of configuration options, read ## Each data format has it's own unique set of configuration options, read

View File

@ -16,6 +16,7 @@ import (
type Tail struct { type Tail struct {
Files []string Files []string
FromBeginning bool FromBeginning bool
Pipe bool
tailers []*tail.Tail tailers []*tail.Tail
parser parsers.Parser parser parsers.Parser
@ -44,6 +45,8 @@ const sampleConfig = `
files = ["/var/mymetrics.out"] files = ["/var/mymetrics.out"]
## Read file from beginning. ## Read file from beginning.
from_beginning = false from_beginning = false
## Whether file is a named pipe
pipe = false
## Data format to consume. ## Data format to consume.
## Each data format has it's own unique set of configuration options, read ## Each data format has it's own unique set of configuration options, read
@ -70,10 +73,12 @@ func (t *Tail) Start(acc telegraf.Accumulator) error {
t.acc = acc t.acc = acc
var seek tail.SeekInfo var seek *tail.SeekInfo
if !t.FromBeginning { if !t.Pipe && !t.FromBeginning {
seek.Whence = 2 seek = &tail.SeekInfo{
seek.Offset = 0 Whence: 2,
Offset: 0,
}
} }
var errS string var errS string
@ -88,8 +93,9 @@ func (t *Tail) Start(acc telegraf.Accumulator) error {
tail.Config{ tail.Config{
ReOpen: true, ReOpen: true,
Follow: true, Follow: true,
Location: &seek, Location: seek,
MustExist: true, MustExist: true,
Pipe: t.Pipe,
}) })
if err != nil { if err != nil {
errS += err.Error() + " " errS += err.Error() + " "
@ -130,6 +136,10 @@ func (t *Tail) receiver(tailer *tail.Tail) {
tailer.Filename, line.Text, err) tailer.Filename, line.Text, err)
} }
} }
if err := tailer.Err(); err != nil {
log.Printf("E! Error tailing file %s, Error: %s\n",
tailer.Filename, err)
}
} }
func (t *Tail) Stop() { func (t *Tail) Stop() {