Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tail input seeking when used with pipe #2090

Merged
merged 2 commits into from
Dec 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
- [#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 @@ -41,6 +42,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