fix tail input seeking when used with pipe (#2090)
This commit is contained in:
parent
d27c78a979
commit
f57b8aac0b
|
@ -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.
|
||||
|
@ -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]
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
type Tail struct {
|
||||
Files []string
|
||||
FromBeginning bool
|
||||
Pipe bool
|
||||
|
||||
tailers []*tail.Tail
|
||||
parser parsers.Parser
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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() + " "
|
||||
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue