From b2fafdf3603909eed77a8e0c1d6da50c49441c53 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Wed, 20 Mar 2019 18:18:30 +0000 Subject: [PATCH] Export position in file, not bytes read. Signed-off-by: Tom Wilkie --- pkg/promtail/targets/filetarget.go | 2 +- pkg/promtail/targets/tailer.go | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/pkg/promtail/targets/filetarget.go b/pkg/promtail/targets/filetarget.go index 0e3654f0e0..57eb5cd804 100644 --- a/pkg/promtail/targets/filetarget.go +++ b/pkg/promtail/targets/filetarget.go @@ -21,7 +21,7 @@ import ( ) var ( - readBytes = promauto.NewCounterVec(prometheus.CounterOpts{ + readBytes = promauto.NewGaugeVec(prometheus.GaugeOpts{ Namespace: "promtail", Name: "read_bytes_total", Help: "Number of bytes read.", diff --git a/pkg/promtail/targets/tailer.go b/pkg/promtail/targets/tailer.go index 4a1f2876f9..b08295101e 100644 --- a/pkg/promtail/targets/tailer.go +++ b/pkg/promtail/targets/tailer.go @@ -102,11 +102,6 @@ func (t *tailer) run() { level.Error(t.logger).Log("msg", "error reading line", "path", t.path, "error", line.Err) } - readLines.WithLabelValues(t.path).Inc() - // The line we receive from the tailer is stripped of the newline character, which causes counts to be - // off between the file size and this metric of bytes read, so we are adding back a byte to represent the newline - // If you are reading this you are probably using Windows which has a 2 byte /r/n newline string.... sorry - readBytes.WithLabelValues(t.path).Add(float64(len(line.Text) + 1)) if err := t.handler.Handle(model.LabelSet{}, line.Time, line.Text); err != nil { level.Error(t.logger).Log("msg", "error handling line", "path", t.path, "error", err) } @@ -121,6 +116,8 @@ func (t *tailer) markPosition() error { if err != nil { return err } + + readBytes.WithLabelValues(t.path).Add(float64(pos)) level.Debug(t.logger).Log("path", t.path, "filename", t.filename, "current_position", pos) t.positions.Put(t.filename, pos) return nil