github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/clients/pkg/promtail/targets/file/metrics.go (about) 1 package file 2 3 import "github.com/prometheus/client_golang/prometheus" 4 5 // Metrics hold the set of file-based metrics. 6 type Metrics struct { 7 // Registerer used. May be nil. 8 reg prometheus.Registerer 9 10 // File-specific metrics 11 readBytes *prometheus.GaugeVec 12 totalBytes *prometheus.GaugeVec 13 readLines *prometheus.CounterVec 14 encodingFailures *prometheus.CounterVec 15 filesActive prometheus.Gauge 16 17 // Manager metrics 18 failedTargets *prometheus.CounterVec 19 targetsActive prometheus.Gauge 20 } 21 22 // NewMetrics creates a new set of file metrics. If reg is non-nil, the metrics 23 // will be registered. 24 func NewMetrics(reg prometheus.Registerer) *Metrics { 25 var m Metrics 26 m.reg = reg 27 28 m.readBytes = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 29 Namespace: "promtail", 30 Name: "read_bytes_total", 31 Help: "Number of bytes read.", 32 }, []string{"path"}) 33 m.totalBytes = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 34 Namespace: "promtail", 35 Name: "file_bytes_total", 36 Help: "Number of bytes total.", 37 }, []string{"path"}) 38 m.readLines = prometheus.NewCounterVec(prometheus.CounterOpts{ 39 Namespace: "promtail", 40 Name: "read_lines_total", 41 Help: "Number of lines read.", 42 }, []string{"path"}) 43 m.filesActive = prometheus.NewGauge(prometheus.GaugeOpts{ 44 Namespace: "promtail", 45 Name: "files_active_total", 46 Help: "Number of active files.", 47 }) 48 49 m.failedTargets = prometheus.NewCounterVec(prometheus.CounterOpts{ 50 Namespace: "promtail", 51 Name: "targets_failed_total", 52 Help: "Number of failed targets.", 53 }, []string{"reason"}) 54 m.targetsActive = prometheus.NewGauge(prometheus.GaugeOpts{ 55 Namespace: "promtail", 56 Name: "targets_active_total", 57 Help: "Number of active total.", 58 }) 59 60 if reg != nil { 61 reg.MustRegister( 62 m.readBytes, 63 m.totalBytes, 64 m.readLines, 65 m.filesActive, 66 m.failedTargets, 67 m.targetsActive, 68 ) 69 } 70 71 return &m 72 }