forked from ContentSquare/chproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
284 lines (278 loc) · 10.1 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
package main
import (
"github.com/contentsquare/chproxy/config"
"github.com/contentsquare/chproxy/internal/topology"
"github.com/prometheus/client_golang/prometheus"
)
var (
statusCodes *prometheus.CounterVec
requestSum *prometheus.CounterVec
requestSuccess *prometheus.CounterVec
limitExcess *prometheus.CounterVec
concurrentQueries *prometheus.GaugeVec
requestQueueSize *prometheus.GaugeVec
userQueueOverflow *prometheus.CounterVec
clusterUserQueueOverflow *prometheus.CounterVec
requestBodyBytes *prometheus.CounterVec
responseBodyBytes *prometheus.CounterVec
cacheFailedInsert *prometheus.CounterVec
cacheCorruptedFetch *prometheus.CounterVec
cacheHit *prometheus.CounterVec
cacheMiss *prometheus.CounterVec
cacheSize *prometheus.GaugeVec
cacheItems *prometheus.GaugeVec
cacheSkipped *prometheus.CounterVec
requestDuration *prometheus.SummaryVec
proxiedResponseDuration *prometheus.SummaryVec
cachedResponseDuration *prometheus.SummaryVec
canceledRequest *prometheus.CounterVec
cacheHitFromConcurrentQueries *prometheus.CounterVec
cacheMissFromConcurrentQueries *prometheus.CounterVec
killedRequests *prometheus.CounterVec
timeoutRequest *prometheus.CounterVec
configSuccess prometheus.Gauge
configSuccessTime prometheus.Gauge
badRequest prometheus.Counter
retryRequest *prometheus.CounterVec
)
func initMetrics(cfg *config.Config) {
namespace := cfg.Server.Metrics.Namespace
statusCodes = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "status_codes_total",
Help: "Distribution by status codes",
},
[]string{"user", "cluster", "cluster_user", "replica", "cluster_node", "code"},
)
requestSum = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "request_sum_total",
Help: "Total number of sent requests",
},
[]string{"user", "cluster", "cluster_user", "replica", "cluster_node"},
)
requestSuccess = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "request_success_total",
Help: "Total number of sent success requests",
},
[]string{"user", "cluster", "cluster_user", "replica", "cluster_node"},
)
limitExcess = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "concurrent_limit_excess_total",
Help: "Total number of max_concurrent_queries excess",
},
[]string{"user", "cluster", "cluster_user", "replica", "cluster_node"},
)
concurrentQueries = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "concurrent_queries",
Help: "The number of concurrent queries at current time",
},
[]string{"user", "cluster", "cluster_user", "replica", "cluster_node"},
)
requestQueueSize = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "request_queue_size",
Help: "Request queue sizes at the current time",
},
[]string{"user", "cluster", "cluster_user"},
)
userQueueOverflow = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "user_queue_overflow_total",
Help: "The number of overflows for per-user request queues",
},
[]string{"user", "cluster", "cluster_user"},
)
clusterUserQueueOverflow = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "cluster_user_queue_overflow_total",
Help: "The number of overflows for per-cluster_user request queues",
},
[]string{"user", "cluster", "cluster_user"},
)
requestBodyBytes = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "request_body_bytes_total",
Help: "The amount of bytes read from request bodies",
},
[]string{"user", "cluster", "cluster_user", "replica", "cluster_node"},
)
responseBodyBytes = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "response_body_bytes_total",
Help: "The amount of bytes written to response bodies",
},
[]string{"user", "cluster", "cluster_user", "replica", "cluster_node"},
)
cacheFailedInsert = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "cache_insertion_failures_total",
Help: "The number of insertion in the cache that didn't work out",
},
[]string{"cache", "user", "cluster", "cluster_user"},
)
cacheCorruptedFetch = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "cache_get_corrutpion_total",
Help: "The number of time a data fetching from redis was corrupted",
},
[]string{"cache", "user", "cluster", "cluster_user"},
)
cacheHit = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "cache_hits_total",
Help: "The amount of cache hits",
},
[]string{"cache", "user", "cluster", "cluster_user"},
)
cacheMiss = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "cache_miss_total",
Help: "The amount of cache misses",
},
[]string{"cache", "user", "cluster", "cluster_user"},
)
cacheSize = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "cache_size",
Help: "Cache size at the current time",
},
[]string{"cache"},
)
cacheItems = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "cache_items",
Help: "Cache items at the current time",
},
[]string{"cache"},
)
cacheSkipped = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "cache_payloadsize_too_big_total",
Help: "The amount of too big payloads to be cached",
},
[]string{"cache", "user", "cluster", "cluster_user"},
)
requestDuration = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Namespace: namespace,
Name: "request_duration_seconds",
Help: "Request duration. Includes possible wait time in the queue",
Objectives: map[float64]float64{0.5: 1e-1, 0.9: 1e-2, 0.99: 1e-3, 0.999: 1e-4, 1: 1e-5},
},
[]string{"user", "cluster", "cluster_user", "replica", "cluster_node"},
)
proxiedResponseDuration = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Namespace: namespace,
Name: "proxied_response_duration_seconds",
Help: "Response duration proxied from clickhouse",
Objectives: map[float64]float64{0.5: 1e-1, 0.9: 1e-2, 0.99: 1e-3, 0.999: 1e-4, 1: 1e-5},
},
[]string{"user", "cluster", "cluster_user", "replica", "cluster_node"},
)
cachedResponseDuration = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Namespace: namespace,
Name: "cached_response_duration_seconds",
Help: "Response duration served from the cache",
Objectives: map[float64]float64{0.5: 1e-1, 0.9: 1e-2, 0.99: 1e-3, 0.999: 1e-4, 1: 1e-5},
},
[]string{"cache", "user", "cluster", "cluster_user"},
)
canceledRequest = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "canceled_request_total",
Help: "The number of requests canceled by remote client",
},
[]string{"user", "cluster", "cluster_user", "replica", "cluster_node"},
)
cacheHitFromConcurrentQueries = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "cache_hit_concurrent_query_total",
Help: "The amount of cache hits after having awaited concurrently executed queries",
},
[]string{"cache", "user", "cluster", "cluster_user"},
)
cacheMissFromConcurrentQueries = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "cache_miss_concurrent_query_total",
Help: "The amount of cache misses, even if previously reported as queries available in the cache, after having awaited concurrently executed queries",
},
[]string{"cache", "user", "cluster", "cluster_user"},
)
killedRequests = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "killed_request_total",
Help: "The number of requests killed by proxy",
},
[]string{"user", "cluster", "cluster_user", "replica", "cluster_node"},
)
timeoutRequest = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "timeout_request_total",
Help: "The number of timed out requests",
},
[]string{"user", "cluster", "cluster_user", "replica", "cluster_node"},
)
configSuccess = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "config_last_reload_successful",
Help: "Whether the last configuration reload attempt was successful.",
})
configSuccessTime = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "config_last_reload_success_timestamp_seconds",
Help: "Timestamp of the last successful configuration reload.",
})
badRequest = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "bad_requests_total",
Help: "Total number of unsupported requests",
})
retryRequest = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "retry_request_total",
Help: "The number of retry requests",
},
[]string{"user", "cluster", "cluster_user", "replica", "cluster_node"},
)
}
func registerMetrics(cfg *config.Config) {
topology.RegisterMetrics(cfg)
initMetrics(cfg)
prometheus.MustRegister(statusCodes, requestSum, requestSuccess,
limitExcess, concurrentQueries,
requestQueueSize, userQueueOverflow, clusterUserQueueOverflow,
requestBodyBytes, responseBodyBytes, cacheFailedInsert, cacheCorruptedFetch,
cacheHit, cacheMiss, cacheSize, cacheItems, cacheSkipped,
requestDuration, proxiedResponseDuration, cachedResponseDuration,
canceledRequest, timeoutRequest,
configSuccess, configSuccessTime, badRequest, retryRequest)
}