Skip to content

Commit

Permalink
changing the log length histogram to be a normal histogram with only …
Browse files Browse the repository at this point in the history
…a `path` label, also removing the label values when no longer tailing the file. Following the same pattern we used for readBytes and totalBytes.
  • Loading branch information
slim-bean authored and tomwilkie committed Jul 2, 2019
1 parent 2f46a3c commit 922b2d0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
8 changes: 6 additions & 2 deletions pkg/promtail/targets/filetarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,22 @@ var (
Name: "file_bytes_total",
Help: "Number of bytes total.",
}, []string{"path"})

readLines = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: "promtail",
Name: "read_lines_total",
Help: "Number of lines read.",
}, []string{"path"})

filesActive = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "promtail",
Name: "files_active_total",
Help: "Number of active files.",
})
logLengthHistogram = promauto.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "promtail",
Name: "log_entries_bytes",
Help: "the total count of bytes",
Buckets: prometheus.ExponentialBuckets(16, 2, 8),
}, []string{"path"})
)

const (
Expand Down
4 changes: 1 addition & 3 deletions pkg/promtail/targets/filetargetmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"strings"
"sync"

"github.com/grafana/loki/pkg/logentry/metric"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -113,7 +111,7 @@ func NewFileTargetManager(
targets: map[string]*FileTarget{},
droppedTargets: []Target{},
hostname: hostname,
entryHandler: pipeline.Wrap(metric.LogSize(prometheus.DefaultRegisterer, client)),
entryHandler: pipeline.Wrap(client),
targetConfig: targetConfig,
}
tm.syncers[cfg.JobName] = s
Expand Down
3 changes: 2 additions & 1 deletion pkg/promtail/targets/tailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (t *tailer) run() {
}

readLines.WithLabelValues(t.path).Inc()

logLengthHistogram.WithLabelValues(t.path).Observe(float64(len(line.Text)))
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 Down Expand Up @@ -128,6 +128,7 @@ func (t *tailer) stop() error {
// When we stop tailing the file, also un-export metrics related to the file
readBytes.DeleteLabelValues(t.path)
totalBytes.DeleteLabelValues(t.path)
logLengthHistogram.DeleteLabelValues(t.path)
level.Info(t.logger).Log("msg", "stopped tailing file", "path", t.path)
return err
}
Expand Down

0 comments on commit 922b2d0

Please sign in to comment.