Path: blob/main/component/loki/source/file/metrics.go
4096 views
package file12// This code is copied from Promtail. The metrics struct provides a common set3// of metrics that are reused between all implementations of the reader4// interface.56import "github.com/prometheus/client_golang/prometheus"78// metrics hold the set of file-based metrics.9type metrics struct {10// Registerer used. May be nil.11reg prometheus.Registerer1213// File-specific metrics14readBytes *prometheus.GaugeVec15totalBytes *prometheus.GaugeVec16readLines *prometheus.CounterVec17encodingFailures *prometheus.CounterVec18filesActive prometheus.Gauge19}2021// newMetrics creates a new set of file metrics. If reg is non-nil, the metrics22// will be registered.23func newMetrics(reg prometheus.Registerer) *metrics {24var m metrics25m.reg = reg2627m.readBytes = prometheus.NewGaugeVec(prometheus.GaugeOpts{28Name: "loki_source_file_read_bytes_total",29Help: "Number of bytes read.",30}, []string{"path"})31m.totalBytes = prometheus.NewGaugeVec(prometheus.GaugeOpts{32Name: "loki_source_file_file_bytes_total",33Help: "Number of bytes total.",34}, []string{"path"})35m.readLines = prometheus.NewCounterVec(prometheus.CounterOpts{36Name: "loki_source_file_read_lines_total",37Help: "Number of lines read.",38}, []string{"path"})39m.encodingFailures = prometheus.NewCounterVec(prometheus.CounterOpts{40Name: "loki_source_file_encoding_failures_total",41Help: "Number of encoding failures.",42}, []string{"path"})43m.filesActive = prometheus.NewGauge(prometheus.GaugeOpts{44Name: "loki_source_file_files_active_total",45Help: "Number of active files.",46})4748if reg != nil {49reg.MustRegister(50m.readBytes,51m.totalBytes,52m.readLines,53m.encodingFailures,54m.filesActive,55)56}5758return &m59}606162