From 6e34814d343987f68e86b63ed4eeb3f5678b8b60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Wed, 24 Apr 2019 18:48:10 +1000 Subject: [PATCH] Adding more internal statistics --- include/MySQL_Data_Stream.h | 8 ++++++++ lib/MySQL_Session.cpp | 9 +++++++-- lib/mysql_connection.cpp | 5 +++++ lib/mysql_data_stream.cpp | 4 ++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/include/MySQL_Data_Stream.h b/include/MySQL_Data_Stream.h index d0bb7d7c0..48c941681 100644 --- a/include/MySQL_Data_Stream.h +++ b/include/MySQL_Data_Stream.h @@ -84,6 +84,12 @@ class MySQL_Data_Stream unsigned long long wait_until; unsigned long long killed_at; unsigned long long max_connect_time; + + struct { + unsigned long long questions; + unsigned long long myconnpoll_get; + unsigned long long myconnpoll_put; + } statuses; PtrSizeArray *PSarrayIN; PtrSizeArray *PSarrayOUT; @@ -180,6 +186,7 @@ class MySQL_Data_Stream // safe way to attach a MySQL Connection void attach_connection(MySQL_Connection *mc) { + statuses.myconnpoll_get++; myconn=mc; mc->myds=this; } @@ -187,6 +194,7 @@ class MySQL_Data_Stream // safe way to detach a MySQL Connection void detach_connection() { assert(myconn); + statuses.myconnpoll_put++; myconn->myds=NULL; myconn=NULL; } diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index eea75453d..9e550506c 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -739,12 +739,15 @@ void MySQL_Session::generate_proxysql_internal_session_json(json &j) { j["backends"][i]["hostgroup_id"] = _mybe->hostgroup_id; if (_mybe->server_myds) { MySQL_Data_Stream *_myds=_mybe->server_myds; + j["backends"][i]["stream"]["questions"] = _myds->statuses.questions; + j["backends"][i]["stream"]["myconnpoll_get"] = _myds->statuses.myconnpoll_get; + j["backends"][i]["stream"]["myconnpoll_put"] = _myds->statuses.myconnpoll_put; /* when fast_forward is not used, these metrics are always 0. Explicitly disabled j["backend"][i]["stream"]["pkts_recv"] = _myds->pkts_recv; j["backend"][i]["stream"]["pkts_sent"] = _myds->pkts_sent; - j["backend"][i]["stream"]["bytes_recv"] = _myds->bytes_info.bytes_recv; - j["backend"][i]["stream"]["bytes_sent"] = _myds->bytes_info.bytes_sent; */ + j["backends"][i]["stream"]["bytes_recv"] = _myds->bytes_info.bytes_recv; + j["backends"][i]["stream"]["bytes_sent"] = _myds->bytes_info.bytes_sent; if (_myds->myconn) { MySQL_Connection * _myconn = _myds->myconn; j["backends"][i]["conn"]["sql_mode"] = ( _myconn->options.sql_mode ? _myconn->options.sql_mode : "") ; @@ -2644,6 +2647,7 @@ __get_pkts_from_client: } } mybe->server_myds->mysql_real_query.init(&pkt); + mybe->server_myds->statuses.questions++; client_myds->setDSS_STATE_QUERY_SENT_NET(); } else { switch (session_type) { @@ -2774,6 +2778,7 @@ __get_pkts_from_client: mybe->server_myds->killed_at=0; mybe->server_myds->kill_type=0; mybe->server_myds->mysql_real_query.init(&pkt); // fix memory leak for PREPARE in prepared statements #796 + mybe->server_myds->statuses.questions++; client_myds->setDSS_STATE_QUERY_SENT_NET(); } GloMyStmt->unlock(); diff --git a/lib/mysql_connection.cpp b/lib/mysql_connection.cpp index 02f2556db..ae3b366cf 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -792,6 +792,7 @@ handler_again: __sync_fetch_and_add(&parent->queries_sent,1); __sync_fetch_and_add(&parent->bytes_sent,query.length); myds->sess->thread->status_variables.queries_backends_bytes_sent+=query.length; + myds->bytes_info.bytes_sent += query.length; if (myds->sess->with_gtid == true) { __sync_fetch_and_add(&parent->queries_gtid_sync,1); } @@ -823,6 +824,7 @@ handler_again: __sync_fetch_and_add(&parent->queries_sent,1); __sync_fetch_and_add(&parent->bytes_sent,query.length); myds->sess->thread->status_variables.queries_backends_bytes_sent+=query.length; + myds->bytes_info.bytes_sent += query.length; if (async_exit_status) { next_event(ASYNC_STMT_PREPARE_CONT); } else { @@ -855,6 +857,7 @@ handler_again: __sync_fetch_and_add(&parent->queries_sent,1); __sync_fetch_and_add(&parent->bytes_sent,query.stmt_meta->size); myds->sess->thread->status_variables.queries_backends_bytes_sent+=query.stmt_meta->size; + myds->bytes_info.bytes_sent += query.stmt_meta->size; if (async_exit_status) { next_event(ASYNC_STMT_EXECUTE_CONT); } else { @@ -917,6 +920,7 @@ handler_again: } __sync_fetch_and_add(&parent->bytes_recv,total_size); myds->sess->thread->status_variables.queries_backends_bytes_recv+=total_size; + myds->bytes_info.bytes_recv += total_size; } } /* @@ -1039,6 +1043,7 @@ handler_again: unsigned int br=MyRS->add_row(mysql_row); __sync_fetch_and_add(&parent->bytes_recv,br); myds->sess->thread->status_variables.queries_backends_bytes_recv+=br; + myds->bytes_info.bytes_recv += br; processed_bytes+=br; // issue #527 : this variable will store the amount of bytes processed during this event if ( (processed_bytes > (unsigned int)mysql_thread___threshold_resultset_size*8) diff --git a/lib/mysql_data_stream.cpp b/lib/mysql_data_stream.cpp index 95c889e48..d755bfa4b 100644 --- a/lib/mysql_data_stream.cpp +++ b/lib/mysql_data_stream.cpp @@ -217,6 +217,10 @@ MySQL_Data_Stream::MySQL_Data_Stream() { CompPktOUT.partial=0; multi_pkt.ptr=NULL; multi_pkt.size=0; + + statuses.questions = 0; + statuses.myconnpoll_get = 0; + statuses.myconnpoll_put = 0; } // Destructor