Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/loki/source/file/metrics.go
4096 views
1
package file
2
3
// This code is copied from Promtail. The metrics struct provides a common set
4
// of metrics that are reused between all implementations of the reader
5
// interface.
6
7
import "github.com/prometheus/client_golang/prometheus"
8
9
// metrics hold the set of file-based metrics.
10
type metrics struct {
11
// Registerer used. May be nil.
12
reg prometheus.Registerer
13
14
// File-specific metrics
15
readBytes *prometheus.GaugeVec
16
totalBytes *prometheus.GaugeVec
17
readLines *prometheus.CounterVec
18
encodingFailures *prometheus.CounterVec
19
filesActive 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
Name: "loki_source_file_read_bytes_total",
30
Help: "Number of bytes read.",
31
}, []string{"path"})
32
m.totalBytes = prometheus.NewGaugeVec(prometheus.GaugeOpts{
33
Name: "loki_source_file_file_bytes_total",
34
Help: "Number of bytes total.",
35
}, []string{"path"})
36
m.readLines = prometheus.NewCounterVec(prometheus.CounterOpts{
37
Name: "loki_source_file_read_lines_total",
38
Help: "Number of lines read.",
39
}, []string{"path"})
40
m.encodingFailures = prometheus.NewCounterVec(prometheus.CounterOpts{
41
Name: "loki_source_file_encoding_failures_total",
42
Help: "Number of encoding failures.",
43
}, []string{"path"})
44
m.filesActive = prometheus.NewGauge(prometheus.GaugeOpts{
45
Name: "loki_source_file_files_active_total",
46
Help: "Number of active files.",
47
})
48
49
if reg != nil {
50
reg.MustRegister(
51
m.readBytes,
52
m.totalBytes,
53
m.readLines,
54
m.encodingFailures,
55
m.filesActive,
56
)
57
}
58
59
return &m
60
}
61
62