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