-
Notifications
You must be signed in to change notification settings - Fork 986
/
MySQL_Thread.cpp
5735 lines (5399 loc) · 220 KB
/
MySQL_Thread.cpp
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//#define __CLASS_STANDARD_MYSQL_THREAD_H
#include <functional>
#include <vector>
#include "MySQL_HostGroups_Manager.h"
#include "prometheus_helpers.h"
#define MYSQL_THREAD_IMPLEMENTATION
#include "proxysql.h"
#include "cpp.h"
#include "MySQL_Thread.h"
#include <dirent.h>
#include <libgen.h>
#include "re2/re2.h"
#include "re2/regexp.h"
#include "MySQL_Data_Stream.h"
#include "query_processor.h"
#include "StatCounters.h"
#include "MySQL_PreparedStatement.h"
#include "MySQL_Logger.hpp"
#include <fcntl.h>
using std::vector;
using std::function;
#ifdef DEBUG
MySQL_Session *sess_stopat;
#endif
#ifdef epoll_create1
#define EPOLL_CREATE epoll_create1(0)
#else
#define EPOLL_CREATE epoll_create(1)
#endif
#define PROXYSQL_LISTEN_LEN 1024
#define MIN_THREADS_FOR_MAINTENANCE 8
extern Query_Processor *GloQPro;
extern MySQL_Authentication *GloMyAuth;
extern MySQL_Threads_Handler *GloMTH;
extern MySQL_Monitor *GloMyMon;
extern MySQL_Logger *GloMyLogger;
typedef struct mythr_st_vars {
enum MySQL_Thread_status_variable v_idx;
p_th_counter::metric m_idx;
char * name;
uint32_t conv;
} mythr_st_vars_t;
typedef struct mythr_g_st_vars {
enum MySQL_Thread_status_variable v_idx;
p_th_gauge::metric m_idx;
char * name;
uint32_t conv;
} mythr_g_st_vars_t;
// Note: the order here is not important.
mythr_st_vars_t MySQL_Thread_status_variables_counter_array[] {
{ st_var_backend_stmt_prepare, p_th_counter::com_backend_stmt_prepare, (char *)"Com_backend_stmt_prepare" },
{ st_var_backend_stmt_execute, p_th_counter::com_backend_stmt_execute, (char *)"Com_backend_stmt_execute" },
{ st_var_backend_stmt_close, p_th_counter::com_backend_stmt_close, (char *)"Com_backend_stmt_close" },
{ st_var_frontend_stmt_prepare, p_th_counter::com_frontend_stmt_prepare, (char *)"Com_frontend_stmt_prepare" },
{ st_var_frontend_stmt_execute, p_th_counter::com_frontend_stmt_execute, (char *)"Com_frontend_stmt_execute" },
{ st_var_frontend_stmt_close, p_th_counter::com_frontend_stmt_close, (char *)"Com_frontend_stmt_close" },
{ st_var_queries, p_th_counter::questions, (char *)"Questions" },
{ st_var_queries_slow, p_th_counter::slow_queries, (char *)"Slow_queries" },
{ st_var_queries_gtid, p_th_counter::gtid_consistent_queries, (char *)"GTID_consistent_queries" },
{ st_var_gtid_session_collected,p_th_counter::gtid_session_collected, (char *)"GTID_session_collected" },
{ st_var_queries_backends_bytes_recv, p_th_counter::queries_backends_bytes_recv, (char *)"Queries_backends_bytes_recv" },
{ st_var_queries_backends_bytes_sent, p_th_counter::queries_backends_bytes_sent, (char *)"Queries_backends_bytes_sent" },
{ st_var_queries_frontends_bytes_recv, p_th_counter::queries_frontends_bytes_recv, (char *)"Queries_frontends_bytes_recv" },
{ st_var_queries_frontends_bytes_sent, p_th_counter::queries_frontends_bytes_sent, (char *)"Queries_frontends_bytes_sent" },
{ st_var_query_processor_time , p_th_counter::query_processor_time_nsec, (char *)"Query_Processor_time_nsec", 1000*1000*1000 },
{ st_var_backend_query_time , p_th_counter::backend_query_time_nsec, (char *)"Backend_query_time_nsec", 1000*1000*1000 },
{ st_var_ConnPool_get_conn_latency_awareness , p_th_counter::connpool_get_conn_latency_awareness, (char *)"ConnPool_get_conn_latency_awareness" },
{ st_var_ConnPool_get_conn_immediate, p_th_counter::connpool_get_conn_immediate, (char *)"ConnPool_get_conn_immediate" },
{ st_var_ConnPool_get_conn_success, p_th_counter::connpool_get_conn_success, (char *)"ConnPool_get_conn_success" },
{ st_var_ConnPool_get_conn_failure, p_th_counter::connpool_get_conn_failure, (char *)"ConnPool_get_conn_failure" },
{ st_var_killed_connections, p_th_counter::mysql_killed_backend_connections, (char *)"mysql_killed_backend_connections" },
{ st_var_killed_queries, p_th_counter::mysql_killed_backend_queries, (char *)"mysql_killed_backend_queries" },
{ st_var_hostgroup_locked_set_cmds, p_th_counter::hostgroup_locked_set_cmds, (char *)"hostgroup_locked_set_cmds" },
{ st_var_hostgroup_locked_queries, p_th_counter::hostgroup_locked_queries, (char *)"hostgroup_locked_queries" },
{ st_var_unexpected_com_quit, p_th_counter::mysql_unexpected_frontend_com_quit,(char *)"mysql_unexpected_frontend_com_quit" },
{ st_var_unexpected_packet, p_th_counter::mysql_unexpected_frontend_packets,(char *)"mysql_unexpected_frontend_packets" },
{ st_var_queries_with_max_lag_ms__total_wait_time_us , p_th_counter::queries_with_max_lag_ms__total_wait_time_us, (char *)"queries_with_max_lag_ms__total_wait_time_us" },
{ st_var_queries_with_max_lag_ms__delayed , p_th_counter::queries_with_max_lag_ms__delayed, (char *)"queries_with_max_lag_ms__delayed" },
{ st_var_queries_with_max_lag_ms, p_th_counter::queries_with_max_lag_ms, (char *)"queries_with_max_lag_ms" },
{ st_var_backend_lagging_during_query,p_th_counter::backend_lagging_during_query, (char *)"backend_lagging_during_query" },
{ st_var_backend_offline_during_query,p_th_counter::backend_offline_during_query, (char *)"backend_offline_during_query" },
{ st_var_aws_aurora_replicas_skipped_during_query , p_th_counter::aws_aurora_replicas_skipped_during_query, (char *)"get_aws_aurora_replicas_skipped_during_query" },
{ st_var_automatic_detected_sqli, p_th_counter::automatic_detected_sql_injection, (char *)"automatic_detected_sql_injection" },
{ st_var_whitelisted_sqli_fingerprint,p_th_counter::whitelisted_sqli_fingerprint, (char *)"whitelisted_sqli_fingerprint" },
{ st_var_max_connect_timeout_err, p_th_counter::max_connect_timeouts, (char *)"max_connect_timeouts" },
{ st_var_generated_pkt_err, p_th_counter::generated_error_packets, (char *)"generated_error_packets" },
{ st_var_client_host_error_killed_connections, p_th_counter::client_host_error_killed_connections, (char *)"client_host_error_killed_connections" },
};
mythr_g_st_vars_t MySQL_Thread_status_variables_gauge_array[] {
{ st_var_hostgroup_locked, p_th_gauge::client_connections_hostgroup_locked, (char *)"Client_Connections_hostgroup_locked" }
};
extern mysql_variable_st mysql_tracked_variables[];
const MARIADB_CHARSET_INFO * proxysql_find_charset_nr(unsigned int nr) {
const MARIADB_CHARSET_INFO * c = mariadb_compiled_charsets;
do {
if (c->nr == nr) {
return c;
}
++c;
} while (c[0].nr != 0);
return NULL;
}
MARIADB_CHARSET_INFO * proxysql_find_charset_name(const char *name) {
MARIADB_CHARSET_INFO *c = (MARIADB_CHARSET_INFO *)mariadb_compiled_charsets;
do {
if (!strcasecmp(c->csname, name)) {
return c;
}
++c;
} while (c[0].nr != 0);
return NULL;
}
MARIADB_CHARSET_INFO * proxysql_find_charset_collate_names(const char *csname, const char *collatename) {
MARIADB_CHARSET_INFO *c = (MARIADB_CHARSET_INFO *)mariadb_compiled_charsets;
do {
if (!strcasecmp(c->csname, csname) && !strcasecmp(c->name, collatename)) {
return c;
}
++c;
} while (c[0].nr != 0);
return NULL;
}
MARIADB_CHARSET_INFO * proxysql_find_charset_collate(const char *collatename) {
MARIADB_CHARSET_INFO *c = (MARIADB_CHARSET_INFO *)mariadb_compiled_charsets;
do {
if (!strcasecmp(c->name, collatename)) {
return c;
}
++c;
} while (c[0].nr != 0);
return NULL;
}
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#ifdef DEBUG
#define DEB "_DEBUG"
#else
#define DEB ""
#endif /* DEBUG */
#define MYSQL_THREAD_VERSION "0.2.0902" DEB
#define DEFAULT_NUM_THREADS 4
#define DEFAULT_STACK_SIZE 1024*1024
#define SESSIONS_FOR_CONNECTIONS_HANDLER 64
__thread unsigned int __thread_MySQL_Thread_Variables_version;
volatile static unsigned int __global_MySQL_Thread_Variables_version;
static unsigned int near_pow_2 (unsigned int n) {
unsigned int i = 1;
while (i < n) i <<= 1;
return i ? i : n;
}
void ProxySQL_Poll::shrink() {
unsigned int new_size=near_pow_2(len+1);
fds=(struct pollfd *)realloc(fds,new_size*sizeof(struct pollfd));
myds=(MySQL_Data_Stream **)realloc(myds,new_size*sizeof(MySQL_Data_Stream *));
last_recv=(unsigned long long *)realloc(last_recv,new_size*sizeof(unsigned long long));
last_sent=(unsigned long long *)realloc(last_sent,new_size*sizeof(unsigned long long));
size=new_size;
}
void ProxySQL_Poll::expand(unsigned int more) {
if ( (len+more) > size ) {
unsigned int new_size=near_pow_2(len+more);
fds=(struct pollfd *)realloc(fds,new_size*sizeof(struct pollfd));
myds=(MySQL_Data_Stream **)realloc(myds,new_size*sizeof(MySQL_Data_Stream *));
last_recv=(unsigned long long *)realloc(last_recv,new_size*sizeof(unsigned long long));
last_sent=(unsigned long long *)realloc(last_sent,new_size*sizeof(unsigned long long));
size=new_size;
}
}
ProxySQL_Poll::ProxySQL_Poll() {
loop_counters=new StatCounters(15,10);
poll_timeout=0;
loops=0;
len=0;
pending_listener_add=0;
pending_listener_del=0;
size=MIN_POLL_LEN;
fds=(struct pollfd *)malloc(size*sizeof(struct pollfd));
myds=(MySQL_Data_Stream **)malloc(size*sizeof(MySQL_Data_Stream *));
last_recv=(unsigned long long *)malloc(size*sizeof(unsigned long long));
last_sent=(unsigned long long *)malloc(size*sizeof(unsigned long long));
}
ProxySQL_Poll::~ProxySQL_Poll() {
unsigned int i;
for (i=0;i<len;i++) {
if (
myds[i] && // fix bug #278 . This should be caused by not initialized datastreams used to ping the backend
myds[i]->myds_type==MYDS_LISTENER) {
delete myds[i];
}
}
free(myds);
free(fds);
free(last_recv);
free(last_sent);
delete loop_counters;
}
void ProxySQL_Poll::add(uint32_t _events, int _fd, MySQL_Data_Stream *_myds, unsigned long long sent_time) {
if (len==size) {
expand(1);
}
myds[len]=_myds;
fds[len].fd=_fd;
fds[len].events=_events;
fds[len].revents=0;
if (_myds) {
_myds->mypolls=this;
_myds->poll_fds_idx=len; // fix a serious bug
}
last_recv[len]=monotonic_time();
last_sent[len]=sent_time;
len++;
}
void ProxySQL_Poll::remove_index_fast(unsigned int i) {
if ((int)i==-1) return;
myds[i]->poll_fds_idx=-1; // this prevents further delete
if (i != (len-1)) {
myds[i]=myds[len-1];
fds[i].fd=fds[len-1].fd;
fds[i].events=fds[len-1].events;
fds[i].revents=fds[len-1].revents;
myds[i]->poll_fds_idx=i; // fix a serious bug
last_recv[i]=last_recv[len-1];
last_sent[i]=last_sent[len-1];
}
len--;
if ( ( len>MIN_POLL_LEN ) && ( size > len*MIN_POLL_DELETE_RATIO ) ) {
shrink();
}
}
int ProxySQL_Poll::find_index(int fd) {
unsigned int i;
for (i=0; i<len; i++) {
if (fds[i].fd==fd) {
return i;
}
}
return -1;
}
MySQL_Listeners_Manager::MySQL_Listeners_Manager() {
ifaces=new PtrArray();
}
MySQL_Listeners_Manager::~MySQL_Listeners_Manager() {
while (ifaces->len) {
iface_info *ifi=(iface_info *)ifaces->remove_index_fast(0);
shutdown(ifi->fd,SHUT_RDWR);
close(ifi->fd);
if (ifi->port==0) {
unlink(ifi->address);
}
delete ifi;
}
delete ifaces;
ifaces=NULL;
}
int MySQL_Listeners_Manager::add(const char *iface, unsigned int num_threads, int **perthrsocks) {
for (unsigned int i=0; i<ifaces->len; i++) {
iface_info *ifi=(iface_info *)ifaces->index(i);
if (strcmp(ifi->iface,iface)==0) {
return -1;
}
}
char *address=NULL; char *port=NULL;
int s = -1;
char *h = NULL;
bool is_ipv6 = false;
if (*(char *)iface == '[') {
is_ipv6 = true;
char *p = strchr((char *)iface, ']');
if (p == NULL) {
proxy_error("Invalid IPv6 address: %s\n", iface);
return -1;
}
h = (char *)++iface; // remove first '['
*p = '\0';
iface = p++; // remove last ']'
address = h;
port = ++p; // remove ':'
} else {
c_split_2(iface, ":" , &address, &port);
}
#ifdef SO_REUSEPORT
if (GloVars.global.reuseport==false) {
s = ( atoi(port) ? listen_on_port(address, atoi(port), PROXYSQL_LISTEN_LEN) : listen_on_unix(address, PROXYSQL_LISTEN_LEN));
} else {
if (atoi(port)==0) {
s = listen_on_unix(address, PROXYSQL_LISTEN_LEN);
} else {
// for TCP we will use SO_REUSEPORT
int *l_perthrsocks=(int *)malloc(sizeof(int)*num_threads);
unsigned int i;
for (i=0;i<num_threads;i++) {
s=listen_on_port(address, atoi(port), PROXYSQL_LISTEN_LEN, true);
ioctl_FIONBIO(s,1);
iface_info *ifi=new iface_info((char *)iface, address, atoi(port), s);
ifaces->add(ifi);
l_perthrsocks[i]=s;
}
*perthrsocks=l_perthrsocks;
s=0;
}
}
#else
s = ( atoi(port) ? listen_on_port(address, atoi(port), PROXYSQL_LISTEN_LEN) : listen_on_unix(address, PROXYSQL_LISTEN_LEN));
#endif /* SO_REUSEPORT */
if (s==-1) {
if (is_ipv6 == false) {
free(address);
free(port);
}
return s;
}
if (s>0) {
ioctl_FIONBIO(s,1);
iface_info *ifi=new iface_info((char *)iface, address, atoi(port), s);
ifaces->add(ifi);
}
if (is_ipv6 == false) {
free(address);
free(port);
}
return s;
}
int MySQL_Listeners_Manager::find_idx(const char *iface) {
for (unsigned int i=0; i<ifaces->len; i++) {
iface_info *ifi=(iface_info *)ifaces->index(i);
if (strcmp(ifi->iface,iface)==0) {
return i;
}
}
return -1;
}
iface_info * MySQL_Listeners_Manager::find_iface_from_fd(int fd) {
for (unsigned int i=0; i<ifaces->len; i++) {
iface_info *ifi=(iface_info *)ifaces->index(i);
if (ifi->fd==fd) {
return ifi;
}
}
return NULL;
}
int MySQL_Listeners_Manager::find_idx(const char *address, int port) {
for (unsigned int i=0; i<ifaces->len; i++) {
iface_info *ifi=(iface_info *)ifaces->index(i);
if (strcmp(ifi->address,address)==0 && ifi->port==port) {
return i;
}
}
return -1;
}
int MySQL_Listeners_Manager::get_fd(unsigned int idx) {
iface_info *ifi=(iface_info *)ifaces->index(idx);
return ifi->fd;
}
void MySQL_Listeners_Manager::del(unsigned int idx) {
iface_info *ifi=(iface_info *)ifaces->remove_index_fast(idx);
if (ifi->port==0) {
unlink(ifi->address);
}
delete ifi;
}
static char * mysql_thread_variables_names[]= {
(char *)"shun_on_failures",
(char *)"shun_recovery_time_sec",
(char *)"unshun_algorithm",
(char *)"query_retries_on_failure",
(char *)"client_host_cache_size",
(char *)"client_host_error_counts",
(char *)"connect_retries_on_failure",
(char *)"connect_retries_delay",
(char *)"connection_delay_multiplex_ms",
(char *)"connection_max_age_ms",
(char *)"connect_timeout_client",
(char *)"connect_timeout_server",
(char *)"connect_timeout_server_max",
(char *)"enable_client_deprecate_eof",
(char *)"enable_server_deprecate_eof",
(char *)"enable_load_data_local_infile",
(char *)"eventslog_filename",
(char *)"eventslog_filesize",
(char *)"eventslog_default_log",
(char *)"eventslog_format",
(char *)"auditlog_filename",
(char *)"auditlog_filesize",
//(char *)"default_charset", // removed in 2.0.13 . Obsoleted previously using MySQL_Variables instead
(char *)"handle_unknown_charset",
(char *)"free_connections_pct",
(char *)"connection_warming",
#ifdef IDLE_THREADS
(char *)"session_idle_ms",
#endif // IDLE_THREADS
(char *)"have_ssl",
(char *)"have_compress",
(char *)"interfaces",
(char *)"log_mysql_warnings_enabled",
(char *)"monitor_enabled",
(char *)"monitor_history",
(char *)"monitor_connect_interval",
(char *)"monitor_connect_timeout",
(char *)"monitor_ping_interval",
(char *)"monitor_ping_max_failures",
(char *)"monitor_ping_timeout",
(char *)"monitor_read_only_interval",
(char *)"monitor_read_only_timeout",
(char *)"monitor_read_only_max_timeout_count",
(char *)"monitor_replication_lag_group_by_host",
(char *)"monitor_replication_lag_interval",
(char *)"monitor_replication_lag_timeout",
(char *)"monitor_replication_lag_count",
(char *)"monitor_groupreplication_healthcheck_interval",
(char *)"monitor_groupreplication_healthcheck_timeout",
(char *)"monitor_groupreplication_healthcheck_max_timeout_count",
(char *)"monitor_groupreplication_max_transactions_behind_count",
(char *)"monitor_groupreplication_max_transactions_behind_for_read_only",
(char *)"monitor_galera_healthcheck_interval",
(char *)"monitor_galera_healthcheck_timeout",
(char *)"monitor_galera_healthcheck_max_timeout_count",
(char *)"monitor_username",
(char *)"monitor_password",
(char *)"monitor_replication_lag_use_percona_heartbeat",
(char *)"monitor_query_interval",
(char *)"monitor_query_timeout",
(char *)"monitor_slave_lag_when_null",
(char *)"monitor_threads_min",
(char *)"monitor_threads_max",
(char *)"monitor_threads_queue_maxsize",
(char *)"monitor_local_dns_cache_ttl",
(char *)"monitor_local_dns_cache_refresh_interval",
(char *)"monitor_local_dns_resolver_queue_maxsize",
(char *)"monitor_wait_timeout",
(char *)"monitor_writer_is_also_reader",
(char *)"max_allowed_packet",
(char *)"tcp_keepalive_time",
(char *)"use_tcp_keepalive",
(char *)"automatic_detect_sqli",
(char *)"firewall_whitelist_enabled",
(char *)"firewall_whitelist_errormsg",
(char *)"throttle_connections_per_sec_to_hostgroup",
(char *)"max_transaction_idle_time",
(char *)"max_transaction_time",
(char *)"multiplexing",
(char *)"log_unhealthy_connections",
(char *)"enforce_autocommit_on_reads",
(char *)"autocommit_false_not_reusable",
(char *)"autocommit_false_is_transaction",
(char *)"verbose_query_error",
(char *)"hostgroup_manager_verbose",
(char *)"binlog_reader_connect_retry_msec",
(char *)"threshold_query_length",
(char *)"threshold_resultset_size",
(char *)"query_digests_max_digest_length",
(char *)"query_digests_max_query_length",
(char *)"query_digests_grouping_limit",
(char *)"query_digests_groups_grouping_limit",
(char *)"wait_timeout",
(char *)"throttle_max_bytes_per_second_to_client",
(char *)"throttle_ratio_server_to_client",
(char *)"max_connections",
(char *)"max_stmts_per_connection",
(char *)"max_stmts_cache",
(char *)"mirror_max_concurrency",
(char *)"mirror_max_queue_length",
(char *)"default_max_latency_ms",
(char *)"default_query_delay",
(char *)"default_query_timeout",
(char *)"query_processor_iterations",
(char *)"query_processor_regex",
(char *)"set_query_lock_on_hostgroup",
(char *)"reset_connection_algorithm",
(char *)"auto_increment_delay_multiplex",
(char *)"auto_increment_delay_multiplex_timeout_ms",
(char *)"long_query_time",
(char *)"query_cache_size_MB",
(char *)"query_cache_soft_ttl_pct",
(char *)"ping_interval_server_msec",
(char *)"ping_timeout_server",
(char *)"default_schema",
(char *)"poll_timeout",
(char *)"poll_timeout_on_failure",
(char *)"server_capabilities",
(char *)"server_version",
(char *)"keep_multiplexing_variables",
(char *)"kill_backend_connection_when_disconnect",
(char *)"client_session_track_gtid",
(char *)"sessions_sort",
#ifdef IDLE_THREADS
(char *)"session_idle_show_processlist",
#endif // IDLE_THREADS
(char *)"show_processlist_extended",
(char *)"commands_stats",
(char *)"query_digests",
(char *)"query_digests_lowercase",
(char *)"query_digests_replace_null",
(char *)"query_digests_no_digits",
(char *)"query_digests_normalize_digest_text",
(char *)"query_digests_track_hostname",
(char *)"query_digests_keep_comment",
(char *)"parse_failure_logs_digest",
(char *)"servers_stats",
(char *)"default_reconnect",
#ifdef DEBUG
(char *)"session_debug",
#endif /* DEBUG */
(char *)"ssl_p2s_ca",
(char *)"ssl_p2s_capath",
(char *)"ssl_p2s_cert",
(char *)"ssl_p2s_key",
(char *)"ssl_p2s_cipher",
(char *)"ssl_p2s_crl",
(char *)"ssl_p2s_crlpath",
(char *)"stacksize",
(char *)"threads",
(char *)"init_connect",
(char *)"ldap_user_variable",
(char *)"add_ldap_user_comment",
(char *)"default_tx_isolation",
(char *)"default_session_track_gtids",
(char *)"connpoll_reset_queue_length",
(char *)"min_num_servers_lantency_awareness",
(char *)"aurora_max_lag_ms_only_read_from_replicas",
(char *)"stats_time_backend_query",
(char *)"stats_time_query_processor",
(char *)"query_cache_stores_empty_result",
NULL
};
using metric_name = std::string;
using metric_help = std::string;
using metric_tags = std::map<std::string, std::string>;
using th_counter_tuple =
std::tuple<
p_th_counter::metric,
metric_name,
metric_help,
metric_tags
>;
using th_gauge_tuple =
std::tuple<
p_th_gauge::metric,
metric_name,
metric_help,
metric_tags
>;
using th_counter_vector = std::vector<th_counter_tuple>;
using th_gauge_vector = std::vector<th_gauge_tuple>;
/**
* @brief Metrics map holding the metrics for the MySQL_Thread module.
*
* @note Many metrics in this map, share a common "id name", because
* they differ only by label, because of this, HELP is shared between
* them. For better visual identification of this groups they are
* separated using a line separator comment.
*/
const std::tuple<th_counter_vector, th_gauge_vector>
th_metrics_map = std::make_tuple(
th_counter_vector {
// ====================================================================
std::make_tuple (
p_th_counter::queries_backends_bytes_sent,
"proxysql_queries_backends_bytes_total",
"Total number of bytes (sent|received) in backend connections.",
metric_tags {
{ "traffic_flow", "sent" }
}
),
std::make_tuple (
p_th_counter::queries_backends_bytes_recv,
"proxysql_queries_backends_bytes_total",
"Total number of bytes (sent|received) in backend connections.",
metric_tags {
{ "traffic_flow", "received" }
}
),
// ====================================================================
// ====================================================================
std::make_tuple (
p_th_counter::queries_frontends_bytes_sent,
"proxysql_queries_frontends_bytes_total",
"Total number of bytes (sent|received) in frontend connections.",
metric_tags {
{ "traffic_flow", "sent" }
}
),
std::make_tuple (
p_th_counter::queries_frontends_bytes_recv,
"proxysql_queries_frontends_bytes_total",
"Total number of bytes (sent|received) in frontend connections.",
metric_tags {
{ "traffic_flow", "received" }
}
),
// ====================================================================
// ====================================================================
std::make_tuple (
p_th_counter::client_connections_created,
"proxysql_client_connections_total",
"Total number of client connections created or failed (including improperly closed).",
metric_tags {
{ "status", "created" }
}
),
std::make_tuple (
p_th_counter::client_connections_aborted,
"proxysql_client_connections_total",
"Total number of client connections created or failed (including improperly closed).",
metric_tags {
{ "status", "aborted" }
}
),
// ====================================================================
std::make_tuple (
p_th_counter::query_processor_time_nsec,
"proxysql_query_processor_time_seconds_total",
"The time spent inside the \"Query Processor\" to determine what action needs to be taken with the query (internal module).",
metric_tags {}
),
std::make_tuple (
p_th_counter::backend_query_time_nsec,
"proxysql_backend_query_time_seconds_total",
"Time spent making network calls to communicate with the backends.",
metric_tags {}
),
// ====================================================================
std::make_tuple (
p_th_counter::com_backend_stmt_prepare,
"proxysql_com_backend_stmt_total",
"Represents the number of statements (PREPARE|EXECUTE|CLOSE) executed by ProxySQL against the backends.",
metric_tags {
{ "op", "prepare" }
}
),
std::make_tuple (
p_th_counter::com_backend_stmt_execute,
"proxysql_com_backend_stmt_total",
"Represents the number of statements (PREPARE|EXECUTE|CLOSE) executed by ProxySQL against the backends.",
metric_tags {
{ "op", "execute" }
}
),
std::make_tuple (
p_th_counter::com_backend_stmt_close,
"proxysql_com_backend_stmt_total",
"Represents the number of statements (PREPARE|EXECUTE|CLOSE) executed by ProxySQL against the backends.",
metric_tags {
{ "op", "close" }
}
),
// ====================================================================
// ====================================================================
std::make_tuple (
p_th_counter::com_frontend_stmt_prepare,
"proxysql_com_frontend_stmt_total",
"Represents the number of statements (PREPARE|EXECUTE|CLOSE) executed by clients.",
metric_tags {
{ "op", "prepare" }
}
),
std::make_tuple (
p_th_counter::com_frontend_stmt_execute,
"proxysql_com_frontend_stmt_total",
"Represents the number of statements (PREPARE|EXECUTE|CLOSE) executed by clients.",
metric_tags {
{ "op", "execute" }
}
),
std::make_tuple (
p_th_counter::com_frontend_stmt_close,
"proxysql_com_frontend_stmt_total",
"Represents the number of statements (PREPARE|EXECUTE|CLOSE) executed by clients.",
metric_tags {
{ "op", "close" }
}
),
// ====================================================================
std::make_tuple (
p_th_counter::questions,
"proxysql_questions_total",
"The total number of client requests / statements executed.",
metric_tags {}
),
std::make_tuple (
p_th_counter::slow_queries,
"proxysql_slow_queries_total",
"The total number of queries with an execution time greater than \"mysql-long_query_time\" milliseconds.",
metric_tags {}
),
std::make_tuple (
p_th_counter::gtid_consistent_queries,
"proxysql_gtid_consistent_queries_total",
"Total queries with GTID consistent read.",
metric_tags {}
),
std::make_tuple (
p_th_counter::gtid_session_collected,
"proxysql_gtid_session_collected_total",
"Total queries with GTID session state.",
metric_tags {}
),
// ====================================================================
std::make_tuple (
p_th_counter::connpool_get_conn_latency_awareness,
"proxysql_connpool_get_conn_success_latency_awareness_total",
"The connection was picked using the latency awareness algorithm.",
metric_tags {}
),
std::make_tuple (
p_th_counter::connpool_get_conn_immediate,
"proxysql_connpool_get_conn_success_immediate_total",
"The connection is provided from per-thread cache.",
metric_tags {}
),
std::make_tuple (
p_th_counter::connpool_get_conn_success,
"proxysql_connpool_get_conn_success_total",
"The session is able to get a connection, either from per-thread cache or connection pool.",
metric_tags {}
),
std::make_tuple (
p_th_counter::connpool_get_conn_failure,
"proxysql_connpool_get_conn_failure_total",
"The connection pool cannot provide any connection.",
metric_tags {}
),
// ====================================================================
std::make_tuple (
p_th_counter::generated_error_packets,
"proxysql_generated_error_packets_total",
"Total generated error packets.",
metric_tags {}
),
std::make_tuple (
p_th_counter::max_connect_timeouts,
"proxysql_max_connect_timeouts_total",
"Maximum connection timeout reached when trying to connect to backend sever.",
metric_tags {}
),
std::make_tuple (
p_th_counter::backend_lagging_during_query,
"proxysql_backend_lagging_during_query_total",
"Query failed because server was shunned due to lag.",
metric_tags {}
),
std::make_tuple (
p_th_counter::backend_offline_during_query,
"proxysql_backend_offline_during_query_total",
"Query failed because server was offline.",
metric_tags {}
),
std::make_tuple (
p_th_counter::queries_with_max_lag_ms,
"proxysql_queries_with_max_lag_total",
"Received queries that have a 'max_lag' attribute.",
metric_tags {}
),
std::make_tuple (
p_th_counter::queries_with_max_lag_ms__delayed,
"proxysql_queries_with_max_lag__delayed_total",
"Query delayed because no connection was selected due to 'max_lag' annotation.",
metric_tags {}
),
std::make_tuple (
p_th_counter::queries_with_max_lag_ms__total_wait_time_us,
"proxysql_queries_with_max_lag__total_wait_time_total",
"Total waited time due to connection selection because of 'max_lag' annotation.",
metric_tags {}
),
std::make_tuple (
p_th_counter::mysql_unexpected_frontend_com_quit,
"proxysql_mysql_unexpected_frontend_com_quit_total",
"Unexpected 'COM_QUIT' received from the client.",
metric_tags {}
),
std::make_tuple (
p_th_counter::hostgroup_locked_set_cmds,
"proxysql_hostgroup_locked_set_cmds_total",
"Total number of connections that have been locked in a hostgroup.",
metric_tags {}
),
std::make_tuple (
p_th_counter::hostgroup_locked_queries,
"proxysql_hostgroup_locked_queries_total",
"Query blocked because connection is locked into some hostgroup but is trying to reach other.",
metric_tags {}
),
std::make_tuple (
p_th_counter::mysql_unexpected_frontend_packets,
"proxysql_mysql_unexpected_frontend_packets_total",
"Unexpected packet received from client.",
metric_tags {}
),
std::make_tuple (
p_th_counter::aws_aurora_replicas_skipped_during_query,
"proxysql_aws_aurora_replicas_skipped_during_query_total",
"Replicas skipped due to current lag being higher than 'max_lag' annotation.",
metric_tags {}
),
std::make_tuple (
p_th_counter::automatic_detected_sql_injection,
"proxysql_automatic_detected_sql_injection_total",
"Blocked a detected 'sql injection' attempt.",
metric_tags {}
),
std::make_tuple (
p_th_counter::whitelisted_sqli_fingerprint,
"proxysql_whitelisted_sqli_fingerprint_total",
"Detected a whitelisted 'sql injection' fingerprint.",
metric_tags {}
),
std::make_tuple (
p_th_counter::mysql_killed_backend_connections,
"proxysql_mysql_killed_backend_connections_total",
"Number of backend connection killed.",
metric_tags {}
),
std::make_tuple (
p_th_counter::mysql_killed_backend_queries,
"proxysql_mysql_killed_backend_queries_total",
"Killed backend queries.",
metric_tags {}
),
std::make_tuple (
p_th_counter::client_host_error_killed_connections,
"proxysql_client_host_error_killed_connections",
"Killed client connections because address exceeded 'client_host_error_counts'.",
metric_tags {}
)
},
th_gauge_vector {
std::make_tuple (
p_th_gauge::active_transactions,
"proxysql_active_transactions",
"Provides a count of how many client connection are currently processing a transaction.",
metric_tags {}
),
std::make_tuple (
p_th_gauge::client_connections_non_idle,
"proxysql_client_connections_non_idle",
"Number of client connections that are currently handled by the main worker threads.",
metric_tags {}
),
std::make_tuple (
p_th_gauge::client_connections_hostgroup_locked,
"proxysql_client_connections_hostgroup_locked",
"Number of client connection locked to a specific hostgroup.",
metric_tags {}
),
std::make_tuple (
p_th_gauge::mysql_backend_buffers_bytes,
"proxysql_mysql_backend_buffers_bytes",
"Buffers related to backend connections if \"fast_forward\" is used (0 means fast_forward is not used).",
metric_tags {}
),
std::make_tuple (
p_th_gauge::mysql_frontend_buffers_bytes,
"proxysql_mysql_frontend_buffers_bytes",
"Buffers related to frontend connections (read/write buffers and other queues).",
metric_tags {}
),
std::make_tuple (
p_th_gauge::mysql_session_internal_bytes,
"proxysql_mysql_session_internal_bytes",
"Other memory used by ProxySQL to handle MySQL Sessions.",
metric_tags {}
),
std::make_tuple (
p_th_gauge::mirror_concurrency,
"proxysql_mirror_concurrency",
"Mirror current concurrency",
metric_tags {}
),
std::make_tuple (
p_th_gauge::mirror_queue_lengths,
"proxysql_mirror_queue_lengths",
"Mirror queue length",
metric_tags {}
),
std::make_tuple (
p_th_gauge::mysql_thread_workers,
"proxysql_mysql_thread_workers",
"Number of MySQL Thread workers i.e. 'mysql-threads'",
metric_tags {}
),
// global_variables
std::make_tuple (
p_th_gauge::mysql_wait_timeout,
"proxysql_mysql_wait_timeout",
"If a proxy session has been idle for more than this threshold, the proxy will kill the session.",
metric_tags {}
),
std::make_tuple (
p_th_gauge::mysql_max_connections,
"proxysql_mysql_max_connections",
"The maximum number of client connections that the proxy can handle.",
metric_tags {}
),
std::make_tuple (
p_th_gauge::mysql_monitor_enabled,
"proxysql_mysql_monitor_enabled",
"Enables or disables MySQL Monitor.",
metric_tags {}
),
std::make_tuple (
p_th_gauge::mysql_monitor_ping_interval,
"proxysql_mysql_monitor_ping_interval",
"How frequently a ping check is performed, in seconds.",
metric_tags {}
),
std::make_tuple (
p_th_gauge::mysql_monitor_ping_timeout,
"proxysql_mysql_monitor_ping_timeout_seconds",
"Ping timeout in seconds.",
metric_tags {}
),
std::make_tuple (
p_th_gauge::mysql_monitor_ping_max_failures,
"proxysql_mysql_monitor_ping_max_failures",
"Reached maximum ping attempts from monitor.",
metric_tags {}
),
std::make_tuple (
p_th_gauge::mysql_monitor_read_only_interval,
"proxysql_mysql_monitor_read_only_interval_seconds",
"How frequently a read only check is performed, in seconds.",
metric_tags {}
),
std::make_tuple (
p_th_gauge::mysql_monitor_read_only_timeout,
"proxysql_mysql_monitor_read_only_timeout_seconds",
"Read only check timeout in seconds.",
metric_tags {}
),