forked from mostafa/xk6-kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.go
233 lines (189 loc) · 6.01 KB
/
stats.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
package kafka
import (
"go.k6.io/k6/js/modules"
"go.k6.io/k6/metrics"
)
type kafkaMetrics struct {
ReaderDials *metrics.Metric
ReaderFetches *metrics.Metric
ReaderMessages *metrics.Metric
ReaderBytes *metrics.Metric
ReaderRebalances *metrics.Metric
ReaderTimeouts *metrics.Metric
ReaderErrors *metrics.Metric
ReaderDialTime *metrics.Metric
ReaderReadTime *metrics.Metric
ReaderWaitTime *metrics.Metric
ReaderFetchSize *metrics.Metric
ReaderFetchBytes *metrics.Metric
ReaderOffset *metrics.Metric
ReaderLag *metrics.Metric
ReaderMinBytes *metrics.Metric
ReaderMaxBytes *metrics.Metric
ReaderMaxWait *metrics.Metric
ReaderQueueLength *metrics.Metric
ReaderQueueCapacity *metrics.Metric
WriterWrites *metrics.Metric
WriterMessages *metrics.Metric
WriterBytes *metrics.Metric
WriterErrors *metrics.Metric
WriterWriteTime *metrics.Metric
WriterWaitTime *metrics.Metric
WriterRetries *metrics.Metric
WriterBatchSize *metrics.Metric
WriterBatchBytes *metrics.Metric
WriterMaxAttempts *metrics.Metric
WriterMaxBatchSize *metrics.Metric
WriterBatchTimeout *metrics.Metric
WriterReadTimeout *metrics.Metric
WriterWriteTimeout *metrics.Metric
WriterRequiredAcks *metrics.Metric
WriterAsync *metrics.Metric
}
// registerMetrics registers the metrics for the kafka module in the metrics registry
func registerMetrics(vu modules.VU) (kafkaMetrics, error) {
var err error
registry := vu.InitEnv().Registry
m := kafkaMetrics{}
m.ReaderDials, err = registry.NewMetric("kafka.reader.dial.count", metrics.Counter)
if err != nil {
return m, err
}
m.ReaderFetches, err = registry.NewMetric("kafka.reader.fetches.count", metrics.Counter)
if err != nil {
return m, err
}
m.ReaderMessages, err = registry.NewMetric("kafka.reader.message.count", metrics.Counter)
if err != nil {
return m, err
}
m.ReaderBytes, err = registry.NewMetric("kafka.reader.message.bytes", metrics.Counter, metrics.Data)
if err != nil {
return m, err
}
m.ReaderRebalances, err = registry.NewMetric("kafka.reader.rebalance.count", metrics.Counter)
if err != nil {
return m, err
}
m.ReaderTimeouts, err = registry.NewMetric("kafka.reader.timeouts.count", metrics.Counter)
if err != nil {
return m, err
}
m.ReaderErrors, err = registry.NewMetric("kafka.reader.error.count", metrics.Counter)
if err != nil {
return m, err
}
m.ReaderDialTime, err = registry.NewMetric("kafka.reader.dial.seconds", metrics.Trend, metrics.Time)
if err != nil {
return m, err
}
m.ReaderReadTime, err = registry.NewMetric("kafka.reader.read.seconds", metrics.Trend, metrics.Time)
if err != nil {
return m, err
}
m.ReaderWaitTime, err = registry.NewMetric("kafka.reader.wait.seconds", metrics.Trend, metrics.Time)
if err != nil {
return m, err
}
m.ReaderFetchSize, err = registry.NewMetric("kafka.reader.fetch.size", metrics.Counter)
if err != nil {
return m, err
}
m.ReaderFetchBytes, err = registry.NewMetric("kafka.reader.fetch.bytes", metrics.Counter, metrics.Data)
if err != nil {
return m, err
}
m.ReaderOffset, err = registry.NewMetric("kafka.reader.offset", metrics.Gauge)
if err != nil {
return m, err
}
m.ReaderLag, err = registry.NewMetric("kafka.reader.lag", metrics.Gauge)
if err != nil {
return m, err
}
m.ReaderMinBytes, err = registry.NewMetric("kafka.reader.fetch_bytes.min", metrics.Gauge)
if err != nil {
return m, err
}
m.ReaderMaxBytes, err = registry.NewMetric("kafka.reader.fetch_bytes.max", metrics.Gauge)
if err != nil {
return m, err
}
m.ReaderMaxWait, err = registry.NewMetric("kafka.reader.fetch_wait.max", metrics.Gauge, metrics.Time)
if err != nil {
return m, err
}
m.ReaderQueueLength, err = registry.NewMetric("kafka.reader.queue.length", metrics.Gauge)
if err != nil {
return m, err
}
m.ReaderQueueCapacity, err = registry.NewMetric("kafka.reader.queue.capacity", metrics.Gauge)
if err != nil {
return m, err
}
m.WriterWrites, err = registry.NewMetric("kafka.writer.write.count", metrics.Counter)
if err != nil {
return m, err
}
m.WriterMessages, err = registry.NewMetric("kafka.writer.message.count", metrics.Counter)
if err != nil {
return m, err
}
m.WriterBytes, err = registry.NewMetric("kafka.writer.message.bytes", metrics.Counter, metrics.Data)
if err != nil {
return m, err
}
m.WriterErrors, err = registry.NewMetric("kafka.writer.error.count", metrics.Counter)
if err != nil {
return m, err
}
m.WriterWriteTime, err = registry.NewMetric("kafka.writer.write.seconds", metrics.Trend, metrics.Time)
if err != nil {
return m, err
}
m.WriterWaitTime, err = registry.NewMetric("kafka.writer.wait.seconds", metrics.Trend, metrics.Time)
if err != nil {
return m, err
}
m.WriterRetries, err = registry.NewMetric("kafka.writer.retries.count", metrics.Counter)
if err != nil {
return m, err
}
m.WriterBatchSize, err = registry.NewMetric("kafka.writer.batch.size", metrics.Counter)
if err != nil {
return m, err
}
m.WriterBatchBytes, err = registry.NewMetric("kafka.writer.batch.bytes", metrics.Counter, metrics.Data)
if err != nil {
return m, err
}
m.WriterMaxAttempts, err = registry.NewMetric("kafka.writer.attempts.max", metrics.Gauge)
if err != nil {
return m, err
}
m.WriterMaxBatchSize, err = registry.NewMetric("kafka.writer.batch.max", metrics.Gauge)
if err != nil {
return m, err
}
m.WriterBatchTimeout, err = registry.NewMetric("kafka.writer.batch.timeout", metrics.Gauge, metrics.Time)
if err != nil {
return m, err
}
m.WriterReadTimeout, err = registry.NewMetric("kafka.writer.read.timeout", metrics.Gauge, metrics.Time)
if err != nil {
return m, err
}
m.WriterWriteTimeout, err = registry.NewMetric("kafka.writer.write.timeout", metrics.Gauge, metrics.Time)
if err != nil {
return m, err
}
m.WriterRequiredAcks, err = registry.NewMetric("kafka.writer.acks.required", metrics.Gauge)
if err != nil {
return m, err
}
m.WriterAsync, err = registry.NewMetric("kafka.writer.async", metrics.Rate)
if err != nil {
return m, err
}
return m, nil
}