@@ -3,26 +3,121 @@ package aggregation
3
3
import (
4
4
"github.com/prometheus/client_golang/prometheus"
5
5
"github.com/prometheus/client_golang/prometheus/promauto"
6
+
7
+ "github.com/grafana/loki/v3/pkg/util/constants"
6
8
)
7
9
8
- type ChunkMetrics struct {
10
+ type Metrics struct {
11
+ reg prometheus.Registerer
12
+
9
13
chunks * prometheus.GaugeVec
10
14
samples * prometheus.CounterVec
15
+
16
+ // push operation
17
+ pushErrors * prometheus.CounterVec
18
+ pushRetries * prometheus.CounterVec
19
+ pushSuccesses * prometheus.CounterVec
20
+ payloadSize * prometheus.HistogramVec
21
+
22
+ // Batch metrics
23
+ streamsPerPush * prometheus.HistogramVec
24
+ entriesPerPush * prometheus.HistogramVec
25
+ servicesTracked * prometheus.GaugeVec
26
+
27
+ writeTimeout * prometheus.CounterVec
11
28
}
12
29
13
- func NewChunkMetrics (r prometheus.Registerer , metricsNamespace string ) * ChunkMetrics {
14
- return & ChunkMetrics {
30
+ func NewMetrics (r prometheus.Registerer ) * Metrics {
31
+ var m Metrics
32
+ m .reg = r
33
+
34
+ m = Metrics {
15
35
chunks : promauto .With (r ).NewGaugeVec (prometheus.GaugeOpts {
16
- Namespace : metricsNamespace ,
36
+ Namespace : constants . Loki ,
17
37
Subsystem : "pattern_ingester" ,
18
38
Name : "metric_chunks" ,
19
39
Help : "The total number of chunks in memory." ,
20
40
}, []string {"service_name" }),
21
41
samples : promauto .With (r ).NewCounterVec (prometheus.CounterOpts {
22
- Namespace : metricsNamespace ,
42
+ Namespace : constants . Loki ,
23
43
Subsystem : "pattern_ingester" ,
24
44
Name : "metric_samples" ,
25
45
Help : "The total number of samples in memory." ,
26
46
}, []string {"service_name" }),
47
+ pushErrors : promauto .With (r ).NewCounterVec (prometheus.CounterOpts {
48
+ Namespace : constants .Loki ,
49
+ Subsystem : "pattern_ingester" ,
50
+ Name : "push_errors_total" ,
51
+ Help : "Total number of errors when pushing metrics to Loki." ,
52
+ }, []string {"tenant_id" , "error_type" }),
53
+
54
+ pushRetries : promauto .With (r ).NewCounterVec (prometheus.CounterOpts {
55
+ Namespace : constants .Loki ,
56
+ Subsystem : "pattern_ingester" ,
57
+ Name : "push_retries_total" ,
58
+ Help : "Total number of retries when pushing metrics to Loki." ,
59
+ }, []string {"tenant_id" }),
60
+
61
+ pushSuccesses : promauto .With (r ).NewCounterVec (prometheus.CounterOpts {
62
+ Namespace : constants .Loki ,
63
+ Subsystem : "pattern_ingester" ,
64
+ Name : "push_successes_total" ,
65
+ Help : "Total number of successful pushes to Loki." ,
66
+ }, []string {"tenant_id" }),
67
+
68
+ // Batch metrics
69
+ payloadSize : promauto .With (r ).NewHistogramVec (prometheus.HistogramOpts {
70
+ Namespace : constants .Loki ,
71
+ Subsystem : "pattern_ingester" ,
72
+ Name : "push_payload_bytes" ,
73
+ Help : "Size of push payloads in bytes." ,
74
+ Buckets : []float64 {1024 , 4096 , 16384 , 65536 , 262144 , 1048576 },
75
+ }, []string {"tenant_id" }),
76
+
77
+ streamsPerPush : promauto .With (r ).NewHistogramVec (prometheus.HistogramOpts {
78
+ Namespace : constants .Loki ,
79
+ Subsystem : "pattern_ingester" ,
80
+ Name : "streams_per_push" ,
81
+ Help : "Number of streams in each push request." ,
82
+ Buckets : []float64 {1 , 5 , 10 , 25 , 50 , 100 , 250 , 500 , 1000 },
83
+ }, []string {"tenant_id" }),
84
+
85
+ entriesPerPush : promauto .With (r ).NewHistogramVec (prometheus.HistogramOpts {
86
+ Namespace : constants .Loki ,
87
+ Subsystem : "pattern_ingester" ,
88
+ Name : "entries_per_push" ,
89
+ Help : "Number of entries in each push request." ,
90
+ Buckets : []float64 {10 , 50 , 100 , 500 , 1000 , 5000 , 10000 },
91
+ }, []string {"tenant_id" }),
92
+
93
+ servicesTracked : promauto .With (r ).NewGaugeVec (prometheus.GaugeOpts {
94
+ Namespace : constants .Loki ,
95
+ Subsystem : "pattern_ingester" ,
96
+ Name : "services_tracked" ,
97
+ Help : "Number of unique services being tracked." ,
98
+ }, []string {"tenant_id" }),
99
+ writeTimeout : promauto .With (r ).NewCounterVec (prometheus.CounterOpts {
100
+ Namespace : constants .Loki ,
101
+ Subsystem : "pattern_ingester" ,
102
+ Name : "write_timeouts_total" ,
103
+ Help : "Total number of write timeouts." ,
104
+ }, []string {"tenant_id" }),
27
105
}
106
+
107
+ if m .reg != nil {
108
+ m .reg .MustRegister (
109
+ m .chunks ,
110
+ m .samples ,
111
+ m .pushErrors ,
112
+ m .pushRetries ,
113
+ m .pushSuccesses ,
114
+ m .payloadSize ,
115
+ m .streamsPerPush ,
116
+ m .entriesPerPush ,
117
+ m .servicesTracked ,
118
+ m .writeTimeout ,
119
+ )
120
+ }
121
+
122
+ return & m
28
123
}
0 commit comments