MySQL 9.1.0
Source Code Documentation
metrics_handler.h
Go to the documentation of this file.
1/* Copyright (c) 2023, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef METRICS_HANDLER_INCLUDED
25#define METRICS_HANDLER_INCLUDED
26
27#include <atomic>
28#include "my_systime.h"
29
30/*
31 Forward declarations
32*/
33class Gcs_message;
34
35/**
36 @class Metrics
37
38 Handle metrics captured on Group Replication.
39*/
41 public:
42 enum class enum_message_type {
43 CONTROL, // Control messages.
44 DATA // Messages that contain transaction data.
45 };
46
47 Metrics_handler() = default;
48
49 virtual ~Metrics_handler() = default;
50
51 /**
52 Return time in microseconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC)
53
54 @return time in microseconds.
55 */
56 inline static uint64_t get_current_time() { return my_micro_time(); }
57
58 /**
59 Reset the metrics.
60 */
61 void reset();
62
63 /**
64 Number of control messages sent by this member.
65
66 @return number of messages.
67 */
68 uint64_t get_control_messages_sent_count() const;
69
70 /**
71 Number of messages that contain transaction data sent by this member.
72
73 @return number of messages.
74 */
75 uint64_t get_data_messages_sent_count() const;
76
77 /**
78 Sum of bytes of control messages sent by this member.
79 The size is the over the wire size.
80
81 @return sum of bytes.
82 */
84
85 /**
86 Sum of bytes of messages that contain transaction data sent by this member.
87 The size is the over the wire size.
88
89 @return sum of bytes.
90 */
91 uint64_t get_data_messages_sent_bytes_sum() const;
92
93 /**
94 Sum of the roundtrip time in micro-seconds of control messages sent by this
95 member. The time is measured between the send and the delivery of
96 the message on the sender member.
97 @see Metrics_handler::get_current_time()
98
99 @return sum of the roundtrip time.
100 */
102
103 /**
104 Sum of the roundtrip time in micro-seconds of messages that contain
105 transaction data sent by this member. The time is measured between the send
106 and the delivery of the message on the sender member.
107 @see Metrics_handler::get_current_time()
108
109 @return sum of the roundtrip time.
110 */
112
113 /**
114 Number of transactions executed with group_replication_consistency=BEFORE or
115 BEFORE_AND_AFTER.
116
117 @return number of transactions.
118 */
120
121 /**
122 Sum of the time that the member waited until its `group_replication_applier`
123 channel was consumed before execute the transaction with
124 group_replication_consistency=BEFORE or BEFORE_AND_AFTER.
125 @see Metrics_handler::get_current_time()
126
127 @return sum of the wait time.
128 */
130
131 /**
132 Number of transactions executed with group_replication_consistency=AFTER or
133 BEFORE_AND_AFTER.
134
135 @return number of transactions.
136 */
138
139 /**
140 Sum of the time spent between the delivery of the transaction executed with
141 group_replication_consistency= AFTER or BEFORE_AND_AFTER, and the
142 acknowledge of the other group members that the transaction is prepared.
143 @see Metrics_handler::get_current_time()
144
145 @return sum of the wait time.
146 */
148
149 /**
150 Number of transactions executed with group_replication_consistency=AFTER or
151 BEFORE_AND_AFTER.
152
153 @return number of transactions.
154 */
156
157 /**
158 Sum of the time that transactions on secondaries waited to start, while
159 waiting for transactions from the primary with
160 group_replication_consistency=AFTER or BEFORE_AND_AFTER to be committed.
161 @see Metrics_handler::get_current_time()
162
163 @return sum of the wait time.
164 */
166
167 /**
168 Number of times certification garbage collection did run.
169
170 @return number of garbage collect runs.
171 */
173
174 /**
175 Sum of the time that garbage collection runs took.
176 @see Metrics_handler::get_current_time()
177
178 @return sum of the time.
179 */
181
182 /**
183 Account message sent.
184
185 @param message the message to be accounted.
186 */
187 void add_message_sent(const Gcs_message &message);
188
189 /**
190 Account transaction that waited until its `group_replication_applier`
191 channel was consumed before execute the transaction with
192 group_replication_consistency=BEFORE or BEFORE_AND_AFTER.
193 @see Metrics_handler::get_current_time()
194
195 @param begin_timestamp time on which the wait began.
196 @param end_timestamp time on which the wait ended.
197 */
198 void add_transaction_consistency_before_begin(const uint64_t begin_timestamp,
199 const uint64_t end_timestamp);
200
201 /**
202 Account transaction executed with group_replication_consistency=AFTER or
203 BEFORE_AND_AFTER that waited for the acknowledge of the other group members
204 that the transaction is prepared.
205 @see Metrics_handler::get_current_time()
206
207 @param begin_timestamp time on which the wait began.
208 @param end_timestamp time on which the wait ended.
209 */
211 const uint64_t begin_timestamp, const uint64_t end_timestamp);
212
213 /**
214 Account transaction that waited for transactions from the primary with
215 group_replication_consistency=AFTER or BEFORE_AND_AFTER to be committed.
216 @see Metrics_handler::get_current_time()
217
218 @param begin_timestamp time on which the wait began.
219 @param end_timestamp time on which the wait ended.
220 */
221 void add_transaction_consistency_after_sync(const uint64_t begin_timestamp,
222 const uint64_t end_timestamp);
223
224 /**
225 Account a certification garbage collection run.
226 @see Metrics_handler::get_current_time()
227
228 @param begin_timestamp time on which the operation began.
229 @param end_timestamp time on which the operation ended.
230 */
231 void add_garbage_collection_run(const uint64_t begin_timestamp,
232 const uint64_t end_timestamp);
233
234 /**
235 Number of times flow control did run.
236
237 @return number of transactions throttled.
238 */
239 uint64_t get_flow_control_throttle_count() const;
240
241 /**
242 Total time flow control delayed transactions.
243
244 @return time flow control delayed transactions
245 */
246 uint64_t get_flow_control_throttle_time() const;
247
248 /**
249 Flow control is active.
250
251 @return number of transactions being throttled.
252 */
253 uint64_t get_flow_control_throttle_active() const;
254
255 /**
256 Flow control last timestamp of a transaction being throttled.
257
258 @return microseconds since epoch
259 */
261
262 /**
263 Update state of flow control.
264 @see Metrics_handler::get_current_time()
265
266 @param begin_timestamp time on which the operation began.
267 @param end_timestamp time on which the operation ended.
268 */
269 void add_flow_control_throttle_stats(const uint64_t begin_timestamp,
270 const uint64_t end_timestamp);
271
272 /**
273 Increment number of transactions currently throttled.
274 */
276
277 /**
278 Decrement number of transactions currently throttled.
279 */
281
282 private:
283 /**
284 Account message sent.
285 @see Metrics_handler::get_current_time()
286
287 @param type message type.
288 @param bytes message length.
289 @param sent_timestamp time on which the message was sent.
290 @param received_timestamp time on which the message was received.
291 */
293 const uint64_t bytes,
294 const uint64_t sent_timestamp,
295 const uint64_t received_timestamp);
296
297 std::atomic<uint64_t> m_control_messages_sent_count{0};
298 std::atomic<uint64_t> m_data_messages_sent_count{0};
299
300 std::atomic<uint64_t> m_control_messages_sent_bytes_sum{0};
301 std::atomic<uint64_t> m_data_messages_sent_bytes_sum{0};
302
305
308
311 0};
312
315
318
319 std::atomic<uint64_t> m_flow_control_count{0};
320 std::atomic<uint64_t> m_flow_control_throttle_active{0};
321 std::atomic<uint64_t> m_flow_control_throttle_time{0};
322 /* Number of microsends since the Epoch*/
324};
325
326#endif /* METRICS_HANDLER_INCLUDED */
Class that represents the data that is exchanged within a group.
Definition: gcs_message.h:357
Definition: metrics_handler.h:40
uint64_t get_data_messages_sent_bytes_sum() const
Sum of bytes of messages that contain transaction data sent by this member.
Definition: metrics_handler.cc:74
Metrics_handler()=default
std::atomic< uint64_t > m_certification_garbage_collector_time_sum
Definition: metrics_handler.h:317
std::atomic< uint64_t > m_data_messages_sent_bytes_sum
Definition: metrics_handler.h:301
std::atomic< uint64_t > m_data_messages_sent_count
Definition: metrics_handler.h:298
void add_transaction_consistency_after_sync(const uint64_t begin_timestamp, const uint64_t end_timestamp)
Account transaction that waited for transactions from the primary with group_replication_consistency=...
Definition: metrics_handler.cc:300
uint64_t get_transactions_consistency_after_termination_time_sum() const
Sum of the time spent between the delivery of the transaction executed with group_replication_consist...
Definition: metrics_handler.cc:102
std::atomic< uint64_t > m_data_messages_sent_roundtrip_time_sum
Definition: metrics_handler.h:304
uint64_t get_control_messages_sent_count() const
Number of control messages sent by this member.
Definition: metrics_handler.cc:62
enum_message_type
Definition: metrics_handler.h:42
uint64_t get_flow_control_throttle_time() const
Total time flow control delayed transactions.
Definition: metrics_handler.cc:133
uint64_t get_control_messages_sent_bytes_sum() const
Sum of bytes of control messages sent by this member.
Definition: metrics_handler.cc:70
uint64_t get_flow_control_throttle_last_throttle_timestamp() const
Flow control last timestamp of a transaction being throttled.
Definition: metrics_handler.cc:137
void add_transaction_consistency_after_termination(const uint64_t begin_timestamp, const uint64_t end_timestamp)
Account transaction executed with group_replication_consistency=AFTER or BEFORE_AND_AFTER that waited...
Definition: metrics_handler.cc:289
std::atomic< uint64_t > m_flow_control_count
Definition: metrics_handler.h:319
uint64_t get_flow_control_throttle_count() const
Number of times flow control did run.
Definition: metrics_handler.cc:125
std::atomic< uint64_t > m_flow_control_throttle_time
Definition: metrics_handler.h:321
void reset()
Reset the metrics.
Definition: metrics_handler.cc:41
std::atomic< uint64_t > m_transactions_consistency_after_sync_time_sum
Definition: metrics_handler.h:314
uint64_t get_transactions_consistency_before_begin_time_sum() const
Sum of the time that the member waited until its group_replication_applier channel was consumed befor...
Definition: metrics_handler.cc:91
uint64_t get_transactions_consistency_after_sync_count() const
Number of transactions executed with group_replication_consistency=AFTER or BEFORE_AND_AFTER.
Definition: metrics_handler.cc:107
uint64_t get_transactions_consistency_before_begin_count() const
Number of transactions executed with group_replication_consistency=BEFORE or BEFORE_AND_AFTER.
Definition: metrics_handler.cc:86
uint64_t get_certification_garbage_collector_time_sum() const
Sum of the time that garbage collection runs took.
Definition: metrics_handler.cc:121
std::atomic< uint64_t > m_flow_control_throttle_active
Definition: metrics_handler.h:320
void increment_flow_control_throttle()
Increment number of transactions currently throttled.
Definition: metrics_handler.cc:333
std::atomic< uint64_t > m_transactions_consistency_after_sync_count
Definition: metrics_handler.h:313
std::atomic< uint64_t > m_transactions_consistency_after_termination_time_sum
Definition: metrics_handler.h:310
uint64_t get_certification_garbage_collector_count() const
Number of times certification garbage collection did run.
Definition: metrics_handler.cc:117
void add_message_sent_internal(const enum_message_type type, const uint64_t bytes, const uint64_t sent_timestamp, const uint64_t received_timestamp)
Account message sent.
Definition: metrics_handler.cc:248
void add_garbage_collection_run(const uint64_t begin_timestamp, const uint64_t end_timestamp)
Account a certification garbage collection run.
Definition: metrics_handler.cc:311
uint64_t get_transactions_consistency_after_sync_time_sum() const
Sum of the time that transactions on secondaries waited to start, while waiting for transactions from...
Definition: metrics_handler.cc:112
uint64_t get_flow_control_throttle_active() const
Flow control is active.
Definition: metrics_handler.cc:129
virtual ~Metrics_handler()=default
std::atomic< uint64_t > m_control_messages_sent_roundtrip_time_sum
Definition: metrics_handler.h:303
void add_message_sent(const Gcs_message &message)
Account message sent.
Definition: metrics_handler.cc:142
void decrement_flow_control_throttle()
Decrement number of transactions currently throttled.
Definition: metrics_handler.cc:337
std::atomic< uint64_t > m_transactions_consistency_before_begin_count
Definition: metrics_handler.h:306
std::atomic< uint64_t > m_transactions_consistency_after_termination_count
Definition: metrics_handler.h:309
std::atomic< uint64_t > m_control_messages_sent_count
Definition: metrics_handler.h:297
uint64_t get_data_messages_sent_roundtrip_time_sum() const
Sum of the roundtrip time in micro-seconds of messages that contain transaction data sent by this mem...
Definition: metrics_handler.cc:82
uint64_t get_control_messages_sent_roundtrip_time_sum() const
Sum of the roundtrip time in micro-seconds of control messages sent by this member.
Definition: metrics_handler.cc:78
static uint64_t get_current_time()
Return time in microseconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC)
Definition: metrics_handler.h:56
std::atomic< uint64_t > m_certification_garbage_collector_count
Definition: metrics_handler.h:316
std::atomic< uint64_t > m_transactions_consistency_before_begin_time_sum
Definition: metrics_handler.h:307
uint64_t get_transactions_consistency_after_termination_count() const
Number of transactions executed with group_replication_consistency=AFTER or BEFORE_AND_AFTER.
Definition: metrics_handler.cc:96
uint64_t get_data_messages_sent_count() const
Number of messages that contain transaction data sent by this member.
Definition: metrics_handler.cc:66
std::atomic< uint64_t > m_flow_control_throttle_last_throttle_timestamp
Definition: metrics_handler.h:323
void add_flow_control_throttle_stats(const uint64_t begin_timestamp, const uint64_t end_timestamp)
Update state of flow control.
Definition: metrics_handler.cc:322
std::atomic< uint64_t > m_control_messages_sent_bytes_sum
Definition: metrics_handler.h:300
void add_transaction_consistency_before_begin(const uint64_t begin_timestamp, const uint64_t end_timestamp)
Account transaction that waited until its group_replication_applier channel was consumed before execu...
Definition: metrics_handler.cc:278
Defines for getting and processing the current system type programmatically.
unsigned long long int my_micro_time()
Return time in microseconds.
Definition: my_systime.h:182
required string type
Definition: replication_group_member_actions.proto:34