From f5a82235d98e93a70ae08ba753ffad4e318826a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Wed, 10 Oct 2018 02:15:29 +0200 Subject: [PATCH] Added more status variables to improve troubleshooting --- include/MySQL_Session.h | 4 +- include/MySQL_Thread.h | 8 ++++ lib/MySQL_HostGroups_Manager.cpp | 2 +- lib/MySQL_Session.cpp | 15 +++++- lib/MySQL_Thread.cpp | 80 ++++++++++++++++++++++++++++++++ 5 files changed, 106 insertions(+), 3 deletions(-) diff --git a/include/MySQL_Session.h b/include/MySQL_Session.h index cd270832a..22191e4e8 100644 --- a/include/MySQL_Session.h +++ b/include/MySQL_Session.h @@ -225,19 +225,21 @@ class MySQL_Session class KillArgs { public: + MySQL_Thread *mt; char *username; char *password; char *hostname; unsigned int port; unsigned long id; int kill_type; - KillArgs(char *u, char *p, char *h, unsigned int P, unsigned long i, int kt) { + KillArgs(char *u, char *p, char *h, unsigned int P, unsigned long i, int kt, MySQL_Thread *_mt) { username=strdup(u); password=strdup(p); hostname=strdup(h); port=P; id=i; kill_type=kt; + mt=_mt; }; ~KillArgs() { free(username); diff --git a/include/MySQL_Thread.h b/include/MySQL_Thread.h index beef37bca..bc64fe870 100644 --- a/include/MySQL_Thread.h +++ b/include/MySQL_Thread.h @@ -231,6 +231,10 @@ class MySQL_Thread unsigned long long gtid_session_collected; unsigned long long generated_pkt_err; unsigned long long max_connect_timeout_err; + unsigned long long unexpected_com_quit; + unsigned long long unexpected_packet; + unsigned long long killed_connections; + unsigned long long killed_queries; unsigned int active_transactions; } status_variables; @@ -489,6 +493,10 @@ class MySQL_Threads_Handler unsigned long long get_ConnPool_get_conn_failure(); unsigned long long get_generated_pkt_err(); unsigned long long get_max_connect_timeout(); + unsigned long long get_unexpected_com_quit(); + unsigned long long get_unexpected_packet(); + unsigned long long get_killed_connections(); + unsigned long long get_killed_queries(); iface_info *MLM_find_iface_from_fd(int fd) { return MLM->find_iface_from_fd(fd); } diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index 1b6ef09a0..f8b0b3c04 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -2334,7 +2334,7 @@ void MySQL_HostGroups_Manager::destroy_MyConn_from_pool(MySQL_Connection *c, boo auth_password=ui->password; } } - KillArgs *ka = new KillArgs(ui->username, auth_password, c->parent->address, c->parent->port, c->mysql->thread_id, KILL_CONNECTION); + KillArgs *ka = new KillArgs(ui->username, auth_password, c->parent->address, c->parent->port, c->mysql->thread_id, KILL_CONNECTION, NULL); pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 89220c1a5..5142a4954 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -81,6 +81,7 @@ class KillArgs { void * kill_query_thread(void *arg) { KillArgs *ka=(KillArgs *)arg; MYSQL *mysql; + MySQL_Thread * thread = ka->mt; mysql=mysql_init(NULL); mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "program_name", "proxysql_killer"); if (!mysql) { @@ -91,9 +92,15 @@ void * kill_query_thread(void *arg) { switch (ka->kill_type) { case KILL_QUERY: proxy_warning("KILL QUERY %lu on %s:%d\n", ka->id, ka->hostname, ka->port); + if (thread) { + thread->status_variables.killed_queries++; + } break; case KILL_CONNECTION: proxy_warning("KILL CONNECTION %lu on %s:%d\n", ka->id, ka->hostname, ka->port); + if (thread) { + thread->status_variables.killed_connections++; + } break; default: break; @@ -1086,7 +1093,7 @@ void MySQL_Session::handler_again___new_thread_to_kill_connection() { auth_password=ui->password; } } - KillArgs *ka = new KillArgs(ui->username, auth_password, myds->myconn->parent->address, myds->myconn->parent->port, myds->myconn->mysql->thread_id, KILL_QUERY); + KillArgs *ka = new KillArgs(ui->username, auth_password, myds->myconn->parent->address, myds->myconn->parent->port, myds->myconn->mysql->thread_id, KILL_QUERY, thread); pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); @@ -2559,11 +2566,17 @@ __get_pkts_from_client: proxy_error("Unexpected COM_QUIT from client %s . Session_status: %d , client_status: %d Disconnecting it\n", buf, status, client_myds->status); proxy_debug(PROXY_DEBUG_MYSQL_COM, 5, "Got COM_QUIT packet\n"); l_free(pkt.size,pkt.ptr); + if (thread) { + thread->status_variables.unexpected_com_quit++; + } handler_ret = -1; return handler_ret; } } proxy_error("Unexpected packet from client %s . Session_status: %d , client_status: %d Disconnecting it\n", buf, status, client_myds->status); + if (thread) { + thread->status_variables.unexpected_packet++; + } handler_ret = -1; return handler_ret; } diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 7e797d276..13fa5c36b 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -3677,6 +3677,10 @@ MySQL_Thread::MySQL_Thread() { status_variables.gtid_session_collected = 0; status_variables.generated_pkt_err = 0; status_variables.max_connect_timeout_err = 0; + status_variables.unexpected_com_quit = 0; + status_variables.unexpected_packet = 0; + status_variables.killed_connections = 0; + status_variables.killed_queries = 0; match_regexes=NULL; @@ -4155,6 +4159,30 @@ SQLite3_result * MySQL_Threads_Handler::SQL3_GlobalStatus(bool _memory) { pta[1]=buf; result->add_row(pta); } + { // Unexpected COM_QUIT + pta[0]=(char *)"mysql_unexpected_frontend_com_quit"; + sprintf(buf,"%llu",get_unexpected_com_quit()); + pta[1]=buf; + result->add_row(pta); + } + { // Unexpected packet + pta[0]=(char *)"mysql_unexpected_frontend_packets"; + sprintf(buf,"%llu",get_unexpected_packet()); + pta[1]=buf; + result->add_row(pta); + } + { // killed connections + pta[0]=(char *)"mysql_killed_backend_connections"; + sprintf(buf,"%llu",get_killed_connections()); + pta[1]=buf; + result->add_row(pta); + } + { // killed queries + pta[0]=(char *)"mysql_killed_backend_queries"; + sprintf(buf,"%llu",get_killed_queries()); + pta[1]=buf; + result->add_row(pta); + } free(pta); return result; } @@ -5100,3 +5128,55 @@ unsigned long long MySQL_Threads_Handler::get_max_connect_timeout() { } return q; } + +unsigned long long MySQL_Threads_Handler::get_unexpected_com_quit() { + unsigned long long q=0; + unsigned int i; + for (i=0;istatus_variables.unexpected_com_quit,0); + } + } + return q; +} + +unsigned long long MySQL_Threads_Handler::get_unexpected_packet() { + unsigned long long q=0; + unsigned int i; + for (i=0;istatus_variables.unexpected_packet,0); + } + } + return q; +} + +unsigned long long MySQL_Threads_Handler::get_killed_connections() { + unsigned long long q=0; + unsigned int i; + for (i=0;istatus_variables.killed_connections,0); + } + } + return q; +} + +unsigned long long MySQL_Threads_Handler::get_killed_queries() { + unsigned long long q=0; + unsigned int i; + for (i=0;istatus_variables.killed_queries,0); + } + } + return q; +}