Skip to content

Commit

Permalink
fix tail input seeking when used with pipe (influxdata#2090)
Browse files Browse the repository at this point in the history
  • Loading branch information
phemmer authored and Nick White committed Jan 31, 2017
1 parent fb11dcc commit 1bdca26
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ in their config file.

- [#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.
- [#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.
- [#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.
Expand All @@ -80,6 +81,7 @@ in their config file.
- [#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.
- [#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]

Expand Down
2 changes: 2 additions & 0 deletions plugins/inputs/tail/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ The plugin expects messages in one of the
files = ["/var/mymetrics.out"]
## Read file from beginning.
from_beginning = false
## Whether file is a named pipe
pipe = false

## Data format to consume.
## Each data format has it's own unique set of configuration options, read
Expand Down
20 changes: 15 additions & 5 deletions plugins/inputs/tail/tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
type Tail struct {
Files []string
FromBeginning bool
Pipe bool

tailers []*tail.Tail
parser parsers.Parser
Expand Down Expand Up @@ -44,6 +45,8 @@ const sampleConfig = `
files = ["/var/mymetrics.out"]
## Read file from beginning.
from_beginning = false
## Whether file is a named pipe
pipe = false
## Data format to consume.
## Each data format has it's own unique set of configuration options, read
Expand All @@ -70,10 +73,12 @@ func (t *Tail) Start(acc telegraf.Accumulator) error {

t.acc = acc

var seek tail.SeekInfo
if !t.FromBeginning {
seek.Whence = 2
seek.Offset = 0
var seek *tail.SeekInfo
if !t.Pipe && !t.FromBeginning {
seek = &tail.SeekInfo{
Whence: 2,
Offset: 0,
}
}

var errS string
Expand All @@ -88,8 +93,9 @@ func (t *Tail) Start(acc telegraf.Accumulator) error {
tail.Config{
ReOpen: true,
Follow: true,
Location: &seek,
Location: seek,
MustExist: true,
Pipe: t.Pipe,
})
if err != nil {
errS += err.Error() + " "
Expand Down Expand Up @@ -130,6 +136,10 @@ func (t *Tail) receiver(tailer *tail.Tail) {
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() {
Expand Down

0 comments on commit 1bdca26

Please sign in to comment.