Skip to content

Commit

Permalink
Export position in file, not bytes read.
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Wilkie <[email protected]>
  • Loading branch information
tomwilkie committed Mar 20, 2019
1 parent 385d277 commit b2fafdf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/promtail/targets/filetarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
7 changes: 2 additions & 5 deletions pkg/promtail/targets/tailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand Down

0 comments on commit b2fafdf

Please sign in to comment.