Skip to content

Commit f57b8aa

Browse files
phemmersparrc
authored andcommitted
fix tail input seeking when used with pipe (#2090)
1 parent d27c78a commit f57b8aa

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ in their config file.
3131

3232
- [#2049](https://github.com/influxdata/telegraf/pull/2049): Fix the Value data format not trimming null characters from input.
3333
- [#1949](https://github.com/influxdata/telegraf/issues/1949): Fix windows `net` plugin.
34+
- [#1775](https://github.com/influxdata/telegraf/issues/1775): Cache & expire metrics for delivery to prometheus
3435
- [#1775](https://github.com/influxdata/telegraf/issues/1775): Cache & expire metrics for delivery to prometheus.
3536
- [#2146](https://github.com/influxdata/telegraf/issues/2146): Fix potential panic in aggregator plugin metric maker.
3637
- [#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.
4142
- [#1693](https://github.com/influxdata/telegraf/issues/1693): Properly collect nested jolokia struct data.
4243
- [#1917](https://github.com/influxdata/telegraf/pull/1917): fix puppetagent inputs plugin to support string for config variable.
4344
- [#1987](https://github.com/influxdata/telegraf/issues/1987): fix docker input plugin tags when registry has port.
45+
- [#2089](https://github.com/influxdata/telegraf/issues/2089): Fix tail input when reading from a pipe.
4446

4547
## v1.1.2 [2016-12-12]
4648

plugins/inputs/tail/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ The plugin expects messages in one of the
3636
files = ["/var/mymetrics.out"]
3737
## Read file from beginning.
3838
from_beginning = false
39+
## Whether file is a named pipe
40+
pipe = false
3941

4042
## Data format to consume.
4143
## Each data format has it's own unique set of configuration options, read

plugins/inputs/tail/tail.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
type Tail struct {
1717
Files []string
1818
FromBeginning bool
19+
Pipe bool
1920

2021
tailers []*tail.Tail
2122
parser parsers.Parser
@@ -44,6 +45,8 @@ const sampleConfig = `
4445
files = ["/var/mymetrics.out"]
4546
## Read file from beginning.
4647
from_beginning = false
48+
## Whether file is a named pipe
49+
pipe = false
4750
4851
## Data format to consume.
4952
## 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 {
7073

7174
t.acc = acc
7275

73-
var seek tail.SeekInfo
74-
if !t.FromBeginning {
75-
seek.Whence = 2
76-
seek.Offset = 0
76+
var seek *tail.SeekInfo
77+
if !t.Pipe && !t.FromBeginning {
78+
seek = &tail.SeekInfo{
79+
Whence: 2,
80+
Offset: 0,
81+
}
7782
}
7883

7984
var errS string
@@ -88,8 +93,9 @@ func (t *Tail) Start(acc telegraf.Accumulator) error {
8893
tail.Config{
8994
ReOpen: true,
9095
Follow: true,
91-
Location: &seek,
96+
Location: seek,
9297
MustExist: true,
98+
Pipe: t.Pipe,
9399
})
94100
if err != nil {
95101
errS += err.Error() + " "
@@ -130,6 +136,10 @@ func (t *Tail) receiver(tailer *tail.Tail) {
130136
tailer.Filename, line.Text, err)
131137
}
132138
}
139+
if err := tailer.Err(); err != nil {
140+
log.Printf("E! Error tailing file %s, Error: %s\n",
141+
tailer.Filename, err)
142+
}
133143
}
134144

135145
func (t *Tail) Stop() {

0 commit comments

Comments
 (0)