diff --git a/include/MySQL_Thread.h b/include/MySQL_Thread.h index 4efb3955c..de3e7cc3b 100644 --- a/include/MySQL_Thread.h +++ b/include/MySQL_Thread.h @@ -245,6 +245,409 @@ class MySQL_Listeners_Manager { void del(unsigned int idx); }; +struct p_th_counter { + enum metric { + queries_backends_bytes_sent = 0, + queries_backends_bytes_recv, + queries_frontends_bytes_sent, + queries_frontends_bytes_recv, + client_connections_created, + client_connections_aborted, + query_processor_time_nsec, + backend_query_time_nsec, + com_backend_stmt_prepare, + com_backend_stmt_execute, + com_backend_stmt_close, + com_frontend_stmt_prepare, + com_frontend_stmt_execute, + com_frontend_stmt_close, + questions, + slow_queries, + gtid_consistent_queries, + gtid_session_collected, + connpool_get_conn_latency_awareness, + connpool_get_conn_immediate, + connpool_get_conn_success, + connpool_get_conn_failure, + generated_error_packets, + max_connect_timeouts, + backend_lagging_during_query, + backend_offline_during_query, + queries_with_max_lag_ms, + queries_with_max_lag_ms__delayed, + queries_with_max_lag_ms__total_wait_time_us, + mysql_unexpected_frontend_com_quit, + client_connections_hostgroup_locked, + hostgroup_locked_set_cmds, + hostgroup_locked_queries, + mysql_unexpected_frontend_packets, + aws_aurora_replicas_skipped_during_query, + automatic_detected_sql_injection, + whitelisted_sqli_fingerprint, + mysql_killed_backend_connections, + mysql_killed_backend_queries, + __size + }; +}; + +struct p_th_gauge { + enum metric { + active_transactions = 0, + client_connections_non_idle, + mysql_backend_buffers_bytes, + mysql_frontend_buffers_bytes, + mysql_session_internal_bytes, + mirror_concurrency, + mirror_queue_lengths, + mysql_thread_workers, + __size + }; +}; + +struct th_metrics_map_idx { + enum index { + counters = 0, + gauges + }; +}; + +using active_flag = bool; +using metric_name = std::string; +using metric_help = std::string; +using metric_tags = std::map; + +const static std::tuple< + std::vector< + std::tuple< + p_th_counter::metric, + metric_name, + metric_help, + metric_tags + > + >, + std::vector< + std::tuple< + p_th_gauge::metric, + metric_name, + metric_help, + metric_tags + > + > +> +th_metrics_map { + { + { + p_th_counter::queries_backends_bytes_sent, + "proxysql_queries_backends_bytes_sent", + "Total number of bytes sent to backend.", + {} + }, + { + p_th_counter::queries_backends_bytes_recv, + "proxysql_queries_backends_bytes_recv", + "Total number of bytes received from backend.", + {} + }, + { + p_th_counter::queries_frontends_bytes_sent, + "proxysql_queries_frontends_bytes_sent", + "Total number of bytes sent to frontend.", + {} + }, + { + p_th_counter::queries_frontends_bytes_recv, + "proxysql_queries_frontends_bytes_recv", + "Total number of bytes received from frontend.", + {} + }, + { + p_th_counter::client_connections_created, + "proxysql_client_connections_created", + "Total number of client connections created.", + {} + }, + { + p_th_counter::client_connections_aborted, + "proxysql_client_connections_aborted", + "Number of client failed connections (or closed improperly).", + {} + }, + { + // TODO: Change unit + p_th_counter::query_processor_time_nsec, + "proxysql_query_processor_time_nsec", + "The time spent inside the \"Query Processor\" to determine what action needs to be taken with the query (internal module).", + {} + }, + { + // TODO: Change unit + p_th_counter::backend_query_time_nsec, + "proxysql_backend_query_time_nsec", + "Time spent making network calls to communicate with the backends.", + {} + }, + { + p_th_counter::com_backend_stmt_prepare, + "proxysql_com_backend_stmt_prepare", + "Represents the number of “PREPARE” executed by ProxySQL against the backends.", + {} + }, + { + p_th_counter::com_backend_stmt_execute, + "proxysql_com_backend_stmt_execute", + "Represents the number of “EXECUTE” executed by ProxySQL against the backends.", + {} + }, + { + p_th_counter::com_backend_stmt_close, + "proxysql_com_backend_stmt_close", + "Represents the number of “CLOSE” executed by ProxySQL against the backends.", + {} + }, + { + p_th_counter::com_frontend_stmt_prepare, + "proxysql_com_frontend_stmt_prepare", + "Represents the number of “PREPARE” executed by clients.", + {} + }, + { + p_th_counter::com_frontend_stmt_execute, + "proxysql_com_frontend_stmt_execute", + "Represents the number of “EXECUTE” executed by clients.", + {} + }, + { + p_th_counter::com_frontend_stmt_close, + "proxysql_com_frontend_stmt_close", + "Represents the number of “CLOSE” executed by clients.", + {} + }, + { + p_th_counter::questions, + "proxysql_questions", + "The total number of client requests / statements executed.", + {} + }, + { + // TODO: Change unit + p_th_counter::slow_queries, + "proxysql_slow_queries", + "The total number of queries with an execution time greater than \"mysql-long_query_time\" milliseconds.", + {} + }, + { + p_th_counter::gtid_consistent_queries, + "proxysql_gtid_consistent_queries", + "Total queries with GTID consistent read.", + {} + }, + { + p_th_counter::gtid_session_collected, + "proxysql_gtid_session_collected", + "Total queries with GTID session state.", + {} + }, + { + // TODO: Add meaningful HELP + p_th_counter::connpool_get_conn_latency_awareness, + "proxysql_connpool_get_conn_latency_awareness", + "", + {} + }, + { + // TODO: Add meaningful HELP + p_th_counter::connpool_get_conn_immediate, + "proxysql_connpool_get_conn_immediate", + "", + {} + }, + { + // TODO: Add meaningful HELP + p_th_counter::connpool_get_conn_success, + "proxysql_connpool_get_conn_success", + "", + {} + }, + { + // TODO: Add meaningful HELP + p_th_counter::connpool_get_conn_failure, + "proxysql_connpool_get_conn_failure", + "", + {} + }, + { + p_th_counter::generated_error_packets, + "proxysql_generated_error_packets", + "Total generated error packets.", + {} + }, + { + // TODO: Add meaningful HELP + p_th_counter::max_connect_timeouts, + "proxysql_max_connect_timeouts", + "", + {} + }, + { + // TODO: Add meaningful HELP + p_th_counter::backend_lagging_during_query, + "proxysql_backend_lagging_during_query", + "", + {} + }, + { + // TODO: Add meaningful HELP + p_th_counter::backend_offline_during_query, + "proxysql_backend_offline_during_query", + "Number of times a backend was offline during a query.", + {} + }, + { + // TODO: Add meaningful HELP + p_th_counter::queries_with_max_lag_ms, + "proxysql_queries_with_max_lag_ms", + "", + {} + }, + { + // TODO: Add meaningful HELP + p_th_counter::queries_with_max_lag_ms__delayed, + "proxysql_queries_with_max_lag_ms__delayed", + "", + {} + }, + { + // TODO: Add meaningful HELP + p_th_counter::queries_with_max_lag_ms__total_wait_time_us, + "proxysql_queries_with_max_lag_ms__total_wait_time_us", + "", + {} + }, + { + // TODO: Add meaningful HELP + p_th_counter::mysql_unexpected_frontend_com_quit, + "proxysql_mysql_unexpected_frontend_com_quit", + "", + {} + }, + { + // TODO: Add meaningful HELP + p_th_counter::client_connections_hostgroup_locked, + "proxysql_client_connections_hostgroup_locked", + "", + {} + }, + { + // TODO: Add meaningful HELP + p_th_counter::hostgroup_locked_set_cmds, + "proxysql_hostgroup_locked_set_cmds", + "", + {} + }, + { + // TODO: Add meaningful HELP + p_th_counter::hostgroup_locked_queries, + "proxysql_hostgroup_locked_queries", + "", + {} + }, + { + // TODO: Add meaningful HELP + p_th_counter::mysql_unexpected_frontend_packets, + "proxysql_mysql_unexpected_frontend_packets", + "", + {} + }, + { + // TODO: Add meaningful HELP + p_th_counter::aws_aurora_replicas_skipped_during_query, + "proxysql_aws_aurora_replicas_skipped_during_query", + "", + {} + }, + { + // TODO: Add meaningful HELP + p_th_counter::automatic_detected_sql_injection, + "proxysql_automatic_detected_sql_injection", + "", + {} + }, + { + // TODO: Add meaningful HELP + p_th_counter::whitelisted_sqli_fingerprint, + "proxysql_whitelisted_sqli_fingerprint", + "", + {} + }, + { + // TODO: Add meaningful HELP + p_th_counter::mysql_killed_backend_connections, + "proxysql_mysql_killed_backend_connections", + "", + {} + }, + { + // TODO: Add meaningful HELP + p_th_counter::mysql_killed_backend_queries, + "proxysql_mysql_killed_backend_queries", + "", + {} + }, + }, + { + { + p_th_gauge::active_transactions, + "proxysql_active_transactions", + "Provides a count of how many client connection are currently processing a transaction.", + {} + }, + { + 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.", + {} + }, + { + 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).", + {} + }, + { + p_th_gauge::mysql_frontend_buffers_bytes, + "proxysql_mysql_frontend_buffers_bytes", + "Buffers related to frontend connections (read/write buffers and other queues).", + {} + }, + { + p_th_gauge::mysql_session_internal_bytes, + "proxysql_mysql_session_internal_bytes", + "Other memory used by ProxySQL to handle MySQL Sessions.", + {} + }, + { + // TODO: Add meaningful HELP + p_th_gauge::mirror_concurrency, + "proxysql_mirror_concurrency", + "Mirror current concurrency", + {} + }, + { + // TODO: Add meaningful HELP + p_th_gauge::mirror_queue_lengths, + "proxysql_mirror_queue_lengths", + "Mirror queue length", + {} + }, + { + p_th_gauge::mysql_thread_workers, + "proxysql_mysql_thread_workers", + "Number of MySQL Thread workers i.e. “mysql-threads”", + {} + } + } +}; + class MySQL_Threads_Handler { private: @@ -254,6 +657,14 @@ class MySQL_Threads_Handler pthread_rwlock_t rwlock; PtrArray *bind_fds; MySQL_Listeners_Manager *MLM; + /** + * @brief Initalizes the prometheus counters specified in th_metrics_map. + */ + void init_prometheus_counters(); + /** + * @brief Initalizes the prometheus gagues specified in th_metrics_map. + */ + void init_prometheus_gauges(); public: struct { int monitor_history; @@ -398,59 +809,9 @@ class MySQL_Threads_Handler } variables; struct { unsigned int mirror_sessions_current; - - ////////////////////////////////////////////////////// - /// Prometheus Metrics /// - ////////////////////////////////////////////////////// - - prometheus::Gauge* p_active_transations { nullptr }; - prometheus::Gauge* p_non_idle_client_connections { nullptr }; - prometheus::Counter* p_queries_backends_bytes_recv { nullptr }; - prometheus::Counter* p_queries_backends_bytes_sent { nullptr }; - prometheus::Counter* p_queries_frontends_bytes_recv { nullptr }; - prometheus::Counter* p_queries_frontends_bytes_sent { nullptr }; - prometheus::Counter* p_query_processor_time { nullptr }; - prometheus::Counter* p_backend_query_time { nullptr }; - prometheus::Gauge* p_mysql_backend_buffers_bytes { nullptr }; - prometheus::Gauge* p_mysql_frontend_buffers_bytes { nullptr }; - prometheus::Gauge* p_mysql_session_internal_bytes { nullptr }; - prometheus::Counter* p_total_backend_stmt_prepare { nullptr }; - prometheus::Counter* p_total_backend_stmt_execute { nullptr }; - prometheus::Counter* p_total_backend_stmt_close { nullptr }; - prometheus::Counter* p_total_frontend_stmt_prepare { nullptr }; - prometheus::Counter* p_total_frontend_stmt_execute { nullptr }; - prometheus::Counter* p_total_frontend_stmt_close { nullptr }; - prometheus::Gauge* p_mirror_sessions_current { nullptr }; - prometheus::Gauge* p_total_mirror_queue { nullptr }; - prometheus::Counter* p_total_queries { nullptr }; - prometheus::Counter* p_slow_queries { nullptr }; - prometheus::Counter* p_gtid_queries { nullptr }; - prometheus::Counter* p_gtid_session_collected { nullptr }; - prometheus::Counter* p_servers_table_version { nullptr }; - prometheus::Gauge* p_num_threads { nullptr }; - prometheus::Counter* p_ConnPool_get_conn_latency_awareness { nullptr }; - prometheus::Counter* p_ConnPool_get_conn_immediate { nullptr }; - prometheus::Counter* p_ConnPool_get_conn_success { nullptr }; - prometheus::Counter* p_ConnPool_get_conn_failure { nullptr }; - prometheus::Counter* p_generated_error_packets { nullptr }; - prometheus::Counter* p_max_connect_timeout { nullptr }; - prometheus::Counter* p_backend_lagging_during_query { nullptr }; - prometheus::Counter* p_backend_offline_during_query { nullptr }; - prometheus::Counter* p_queries_with_max_lag_ms { nullptr }; - prometheus::Counter* p_queries_with_max_lag_ms__delayed { nullptr }; - prometheus::Counter* p_queries_with_max_lag_ms__total_wait_time_us { nullptr }; - prometheus::Counter* p_mysql_unexpected_frontend_com_quit { nullptr }; - prometheus::Counter* p_get_hostgroup_locked { nullptr }; - prometheus::Counter* p_hostgroup_locked_set_cmds { nullptr }; - prometheus::Counter* p_hostgroup_locked_queries { nullptr }; - prometheus::Counter* p_mysql_unexpected_frontend_packets { nullptr }; - prometheus::Counter* p_aws_aurora_replicas_skipped_during_query { nullptr }; - prometheus::Counter* p_automatic_detected_sqli { nullptr }; - prometheus::Counter* p_whitelisted_sqli_fingerprint { nullptr }; - prometheus::Counter* p_killed_connections { nullptr }; - prometheus::Counter* p_killed_queries { nullptr }; - - ////////////////////////////////////////////////////// + /// Prometheus metrics arrays + std::array p_counter_array {}; + std::array p_gauge_array {}; } status_variables; /** * @brief Callback to update the metrics. diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 04d3fe61b..187a0e406 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -1,4 +1,5 @@ #include "MySQL_HostGroups_Manager.h" +#include "MySQL_Thread.h" #include "proxysql.h" #include "cpp.h" #include "re2/re2.h" @@ -594,7 +595,7 @@ MySQL_Session::~MySQL_Session() { } if (mirror) { __sync_sub_and_fetch(&GloMTH->status_variables.mirror_sessions_current,1); - GloMTH->status_variables.p_mirror_sessions_current->Decrement(); + GloMTH->status_variables.p_gauge_array[p_th_gauge::mirror_concurrency]->Decrement(); } if (ldap_ctx) { GloMyLdapAuth->ldap_ctx_free(ldap_ctx); @@ -1403,7 +1404,7 @@ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C __sync_sub_and_fetch(&GloMTH->status_variables.mirror_sessions_current,1); thread->mirror_queue_mysql_sessions->add(newsess); } else { - GloMTH->status_variables.p_mirror_sessions_current->Increment(); + GloMTH->status_variables.p_gauge_array[p_th_gauge::mirror_concurrency]->Increment(); thread->register_session(newsess); newsess->handler(); // execute immediately //newsess->to_process=0; @@ -1420,7 +1421,7 @@ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C } if (to_cache) { __sync_sub_and_fetch(&GloMTH->status_variables.mirror_sessions_current,1); - GloMTH->status_variables.p_mirror_sessions_current->Decrement(); + GloMTH->status_variables.p_gauge_array[p_th_gauge::mirror_concurrency]->Decrement(); thread->mirror_queue_mysql_sessions_cache->add(newsess); } else { delete newsess; diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 6bdec2b7b..e616721a0 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -492,6 +492,66 @@ static char * mysql_thread_variables_names[]= { NULL }; +void MySQL_Threads_Handler::init_prometheus_counters() { + for (const auto& metric : std::get(th_metrics_map)) { + const auto& tg_metric { std::get<0>(metric) }; + const auto& metric_name { std::get<1>(metric) }; + const auto& metric_help { std::get<2>(metric) }; + const auto& metric_tags { std::get<3>(metric) }; + prometheus::Family* metric_family { nullptr }; + + if (metric_help.empty()) { + metric_family = + std::addressof( + prometheus::BuildCounter() + .Name(metric_name) + .Register(*GloVars.prometheus_registry) + ); + } else { + metric_family = + std::addressof( + prometheus::BuildCounter() + .Name(metric_name) + .Help(metric_help) + .Register(*GloVars.prometheus_registry) + ); + } + + this->status_variables.p_counter_array[tg_metric] = + std::addressof(metric_family->Add(metric_tags)); + } +} + +void MySQL_Threads_Handler::init_prometheus_gauges() { + for (const auto& metric : std::get(th_metrics_map)) { + const auto& tg_metric { std::get<0>(metric) }; + const auto& metric_name { std::get<1>(metric) }; + const auto& metric_help { std::get<2>(metric) }; + const auto& metric_tags { std::get<3>(metric) }; + prometheus::Family* metric_family { nullptr }; + + if (metric_help.empty()) { + metric_family = + std::addressof( + prometheus::BuildGauge() + .Name(metric_name) + .Register(*GloVars.prometheus_registry) + ); + } else { + metric_family = + std::addressof( + prometheus::BuildGauge() + .Name(metric_name) + .Help(metric_help) + .Register(*GloVars.prometheus_registry) + ); + } + + this->status_variables.p_gauge_array[tg_metric] = + std::addressof(metric_family->Add(metric_tags)); + } +} + MySQL_Threads_Handler::MySQL_Threads_Handler() { #ifdef DEBUG if (glovars.has_debug==false) { @@ -656,369 +716,8 @@ MySQL_Threads_Handler::MySQL_Threads_Handler() { MLM = new MySQL_Listeners_Manager(); // Initialize prometheus metrics - auto& active_transactions { - prometheus::BuildGauge() - .Name("proxysql_active_transactions") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_active_transations = - std::addressof(active_transactions.Add({})); - - auto& non_idle_client_connections { - prometheus::BuildGauge() - .Name("proxysql_client_connections_non_idle") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_non_idle_client_connections = - std::addressof(non_idle_client_connections.Add({})); - - auto& queries_backends_bytes_sent { - prometheus::BuildCounter() - .Name("proxysql_queries_backends_bytes_sent") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_queries_backends_bytes_sent = - std::addressof(queries_backends_bytes_sent.Add({})); - - auto& queries_backends_bytes_recv { - prometheus::BuildCounter() - .Name("proxysql_queries_backends_bytes_recv") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_queries_backends_bytes_recv = - std::addressof(queries_backends_bytes_recv.Add({})); - - auto& queries_frontends_bytes_sent { - prometheus::BuildCounter() - .Name("proxysql_queries_frontends_bytes_sent") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_queries_frontends_bytes_sent = - std::addressof(queries_frontends_bytes_sent.Add({})); - - auto& queries_frontends_bytes_recv { - prometheus::BuildCounter() - .Name("proxysql_queries_frontends_bytes_recv") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_queries_frontends_bytes_recv = - std::addressof(queries_frontends_bytes_recv.Add({})); - - // TODO: Change the unit - auto& query_processor_time_nsec { - prometheus::BuildCounter() - .Name("proxysql_query_processor_time_nsec") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_query_processor_time = - std::addressof(query_processor_time_nsec.Add({})); - - auto& backend_query_time_nsec { - prometheus::BuildCounter() - .Name("proxysql_backend_query_time_nsec") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_backend_query_time = - std::addressof(backend_query_time_nsec.Add({})); - - auto& mysql_backend_buffers_bytes { - prometheus::BuildGauge() - .Name("proxysql_mysql_backend_buffers_bytes") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_mysql_backend_buffers_bytes = - std::addressof(mysql_backend_buffers_bytes.Add({})); - - auto& mysql_frontend_buffers_bytes { - prometheus::BuildGauge() - .Name("proxysql_mysql_frontend_buffers_bytes") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_mysql_frontend_buffers_bytes = - std::addressof(mysql_frontend_buffers_bytes.Add({})); - - auto& proxysql_mysql_session_internal_bytes { - prometheus::BuildGauge() - .Name("proxysql_mysql_session_internal_bytes") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_mysql_session_internal_bytes = - std::addressof(proxysql_mysql_session_internal_bytes.Add({})); - - auto& com_backend_stmt_prepare { - prometheus::BuildCounter() - .Name("proxysql_com_backend_stmt_prepare") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_total_backend_stmt_prepare = - std::addressof(com_backend_stmt_prepare.Add({})); - - auto& com_backend_stmt_execute { - prometheus::BuildCounter() - .Name("proxysql_com_backend_stmt_execute") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_total_backend_stmt_execute = - std::addressof(com_backend_stmt_execute.Add({})); - - auto& com_backend_stmt_close { - prometheus::BuildCounter() - .Name("proxysql_com_backend_stmt_close") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_total_backend_stmt_close = - std::addressof(com_backend_stmt_close.Add({})); - - auto& com_frontend_stmt_prepare { - prometheus::BuildCounter() - .Name("proxysql_com_frontend_stmt_prepare") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_total_frontend_stmt_prepare = - std::addressof(com_frontend_stmt_prepare.Add({})); - - auto& com_frontend_stmt_execute { - prometheus::BuildCounter() - .Name("proxysql_com_frontend_stmt_execute") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_total_frontend_stmt_execute = - std::addressof(com_frontend_stmt_execute.Add({})); - - auto& com_frontend_stmt_close { - prometheus::BuildCounter() - .Name("proxysql_com_frontend_stmt_close") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_total_frontend_stmt_close = - std::addressof(com_frontend_stmt_close.Add({})); - - auto& mirror_concurrency { - prometheus::BuildGauge() - .Name("proxysql_mirror_concurrency") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_mirror_sessions_current = - std::addressof(mirror_concurrency.Add({})); - - // TODO: Check units - auto& mirror_queue_lengths { - prometheus::BuildGauge() - .Name("proxysql_mirror_queue_lengths") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_total_mirror_queue = - std::addressof(mirror_queue_lengths.Add({})); - - auto& questions { - prometheus::BuildCounter() - .Name("proxysql_questions") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_total_queries = - std::addressof(questions.Add({})); - - auto& slow_queries { - prometheus::BuildCounter() - .Name("proxysql_slow_queries") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_slow_queries = - std::addressof(slow_queries.Add({})); - - // TODO: Always lowercase? - auto& gtid_consistent_queries { - prometheus::BuildCounter() - .Name("proxysql_gtid_consistent_queries") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_gtid_queries = - std::addressof(gtid_consistent_queries.Add({})); - - auto& gtid_session_collected { - prometheus::BuildCounter() - .Name("proxysql_gtid_session_collected") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_gtid_session_collected = - std::addressof(gtid_session_collected.Add({})); - - auto& num_threads { - prometheus::BuildGauge() - .Name("proxysql_mysql_thread_workers") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_num_threads = - std::addressof(num_threads.Add({})); - - auto& connpool_get_conn_latency_awareness { - prometheus::BuildCounter() - .Name("proxysql_connpool_get_conn_latency_awareness") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_ConnPool_get_conn_latency_awareness = - std::addressof(connpool_get_conn_latency_awareness.Add({})); - - auto& connpool_get_conn_immediate { - prometheus::BuildCounter() - .Name("proxysql_connpool_get_conn_immediate") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_ConnPool_get_conn_immediate = - std::addressof(connpool_get_conn_immediate.Add({})); - - auto& connpool_get_conn_success { - prometheus::BuildCounter() - .Name("proxysql_connpool_get_conn_success") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_ConnPool_get_conn_success = - std::addressof(connpool_get_conn_success.Add({})); - - auto& connpool_get_conn_failure { - prometheus::BuildCounter() - .Name("proxysql_connpool_get_conn_failure") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_ConnPool_get_conn_failure = - std::addressof(connpool_get_conn_failure.Add({})); - - auto& generated_error_packets { - prometheus::BuildCounter() - .Name("proxysql_generated_error_packets") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_generated_error_packets = - std::addressof(generated_error_packets.Add({})); - - auto& max_connect_timeouts { - prometheus::BuildCounter() - .Name("proxysql_max_connect_timeouts") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_max_connect_timeout = - std::addressof(max_connect_timeouts.Add({})); - - auto& backend_lagging_during_query { - prometheus::BuildCounter() - .Name("proxysql_backend_lagging_during_query") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_backend_lagging_during_query = - std::addressof(backend_lagging_during_query.Add({})); - - auto& backend_offline_during_query { - prometheus::BuildCounter() - .Name("proxysql_backend_offline_during_query") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_backend_offline_during_query = - std::addressof(backend_offline_during_query.Add({})); - - auto& queries_with_max_lag_ms { - prometheus::BuildCounter() - .Name("proxysql_queries_with_max_lag_ms") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_queries_with_max_lag_ms = - std::addressof(queries_with_max_lag_ms.Add({})); - - auto& queries_with_max_lag_ms__delayed { - prometheus::BuildCounter() - .Name("proxysql_queries_with_max_lag_ms__delayed") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_queries_with_max_lag_ms__delayed = - std::addressof(queries_with_max_lag_ms__delayed.Add({})); - - auto& queries_with_max_lag_ms__total_wait_time_us { - prometheus::BuildCounter() - .Name("proxysql_queries_with_max_lag_ms__total_wait_time_us") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_queries_with_max_lag_ms__total_wait_time_us = - std::addressof(queries_with_max_lag_ms__total_wait_time_us.Add({})); - - auto& mysql_unexpected_frontend_com_quit { - prometheus::BuildCounter() - .Name("proxysql_mysql_unexpected_frontend_com_quit") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_mysql_unexpected_frontend_com_quit = - std::addressof(mysql_unexpected_frontend_com_quit.Add({})); - - // TODO: Check unit - auto& client_connections_hostgroup_locked { - prometheus::BuildCounter() - .Name("proxysql_client_connections_hostgroup_locked") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_get_hostgroup_locked = - std::addressof(client_connections_hostgroup_locked.Add({})); - - auto& hostgroup_locked_set_cmds { - prometheus::BuildCounter() - .Name("proxysql_hostgroup_locked_set_cmds") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_hostgroup_locked_set_cmds = - std::addressof(hostgroup_locked_set_cmds.Add({})); - - auto& hostgroup_locked_queries { - prometheus::BuildCounter() - .Name("proxysql_hostgroup_locked_queries") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_hostgroup_locked_queries = - std::addressof(hostgroup_locked_queries.Add({})); - - auto& mysql_unexpected_frontend_packets { - prometheus::BuildCounter() - .Name("proxysql_mysql_unexpected_frontend_packets") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_mysql_unexpected_frontend_packets = - std::addressof(mysql_unexpected_frontend_packets.Add({})); - - auto& aws_aurora_replicas_skipped_during_query { - prometheus::BuildCounter() - .Name("proxysql_aws_aurora_replicas_skipped_during_query") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_aws_aurora_replicas_skipped_during_query = - std::addressof(aws_aurora_replicas_skipped_during_query.Add({})); - - auto& automatic_detected_sql_injection { - prometheus::BuildCounter() - .Name("proxysql_automatic_detected_sql_injection") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_automatic_detected_sqli = - std::addressof(automatic_detected_sql_injection.Add({})); - - auto& whitelisted_sqli_fingerprint { - prometheus::BuildCounter() - .Name("proxysql_whitelisted_sqli_fingerprint") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_whitelisted_sqli_fingerprint = - std::addressof(whitelisted_sqli_fingerprint.Add({})); - - auto& mysql_killed_backend_connections { - prometheus::BuildCounter() - .Name("proxysql_mysql_killed_backend_connections") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_killed_connections = - std::addressof(mysql_killed_backend_connections.Add({})); - - auto& mysql_killed_backend_queries { - prometheus::BuildCounter() - .Name("proxysql_mysql_killed_backend_queries") - .Register(*GloVars.prometheus_registry) - }; - this->status_variables.p_killed_queries = - std::addressof(mysql_killed_backend_queries.Add({})); + init_prometheus_counters(); + init_prometheus_gauges(); } @@ -3006,7 +2705,7 @@ bool MySQL_Threads_Handler::set_variable(char *name, const char *value) { // thi unsigned int intv=atoi(value); if ((num_threads==0 || num_threads==intv || mysql_threads==NULL) && intv > 0 && intv < 256) { num_threads=intv; - this->status_variables.p_num_threads->Set(intv); + this->status_variables.p_gauge_array[p_th_gauge::mysql_thread_workers]->Set(intv); return true; } else { return false; @@ -3395,11 +3094,11 @@ void MySQL_Threads_Handler::init(unsigned int num, size_t stack) { } if (num) { num_threads=num; - this->status_variables.p_num_threads->Set(num); + this->status_variables.p_gauge_array[p_th_gauge::mysql_thread_workers]->Set(num); } else { if (num_threads==0) { num_threads=DEFAULT_NUM_THREADS; //default - this->status_variables.p_num_threads->Set(DEFAULT_NUM_THREADS); + this->status_variables.p_gauge_array[p_th_gauge::mysql_thread_workers]->Set(DEFAULT_NUM_THREADS); } } int rc=pthread_attr_setstacksize(&attr, stacksize); @@ -3891,7 +3590,7 @@ __run_skip_1: __sync_sub_and_fetch(&GloMTH->status_variables.mirror_sessions_current,1); goto __mysql_thread_exit_add_mirror; // we can't add more mirror sessions at runtime } else { - GloMTH->status_variables.p_mirror_sessions_current->Increment(); + GloMTH->status_variables.p_gauge_array[p_th_gauge::mirror_concurrency]->Increment(); int idx; idx=fastrand()%(mirror_queue_mysql_sessions->len); MySQL_Session *newsess=(MySQL_Session *)mirror_queue_mysql_sessions->remove_index_fast(idx); @@ -3910,7 +3609,7 @@ __run_skip_1: } if (to_cache) { __sync_sub_and_fetch(&GloMTH->status_variables.mirror_sessions_current,1); - GloMTH->status_variables.p_mirror_sessions_current->Decrement(); + GloMTH->status_variables.p_gauge_array[p_th_gauge::mirror_concurrency]->Decrement(); mirror_queue_mysql_sessions_cache->add(newsess); } else { delete newsess; @@ -4160,7 +3859,7 @@ __run_skip_1a: while (mirror_queue_mysql_sessions_cache->len > mirror_queue_mysql_sessions->len && mirror_queue_mysql_sessions_cache->len > l) { MySQL_Session *newsess=(MySQL_Session *)mirror_queue_mysql_sessions_cache->remove_index_fast(0); __sync_add_and_fetch(&GloMTH->status_variables.mirror_sessions_current,1); - GloMTH->status_variables.p_mirror_sessions_current->Increment(); + GloMTH->status_variables.p_gauge_array[p_th_gauge::mirror_concurrency]->Increment(); delete newsess; } } @@ -4584,7 +4283,7 @@ void MySQL_Thread::process_all_sessions() { } if (to_cache) { __sync_sub_and_fetch(&GloMTH->status_variables.mirror_sessions_current,1); - GloMTH->status_variables.p_mirror_sessions_current->Decrement(); + GloMTH->status_variables.p_gauge_array[p_th_gauge::mirror_concurrency]->Decrement(); mirror_queue_mysql_sessions_cache->add(sess); } else { delete sess; @@ -6009,7 +5708,7 @@ unsigned long long MySQL_Threads_Handler::get_total_mirror_queue() { q+=thr->mirror_queue_mysql_sessions->len; // this is a dirty read } } - this->status_variables.p_total_mirror_queue->Set(q); + this->status_variables.p_gauge_array[p_th_gauge::mirror_queue_lengths]->Set(q); return q; } @@ -6024,8 +5723,8 @@ unsigned long long MySQL_Threads_Handler::get_total_backend_stmt_prepare() { q+=__sync_fetch_and_add(&thr->status_variables.backend_stmt_prepare,0); } } - const auto& curValue { this->status_variables.p_total_backend_stmt_prepare->Value() }; - this->status_variables.p_total_backend_stmt_prepare->Increment(q - curValue); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::com_backend_stmt_prepare]->Value() }; + this->status_variables.p_counter_array[p_th_counter::com_backend_stmt_prepare]->Increment(q - cur_val); return q; } @@ -6040,8 +5739,8 @@ unsigned long long MySQL_Threads_Handler::get_total_backend_stmt_execute() { q+=__sync_fetch_and_add(&thr->status_variables.backend_stmt_execute,0); } } - const auto& curValue { this->status_variables.p_total_backend_stmt_execute->Value() }; - this->status_variables.p_total_backend_stmt_execute->Increment(q - curValue); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::com_backend_stmt_execute]->Value() }; + this->status_variables.p_counter_array[p_th_counter::com_backend_stmt_execute]->Increment(q - cur_val); return q; } @@ -6056,8 +5755,8 @@ unsigned long long MySQL_Threads_Handler::get_total_backend_stmt_close() { q+=__sync_fetch_and_add(&thr->status_variables.backend_stmt_close,0); } } - const auto& curValue { this->status_variables.p_total_backend_stmt_close->Value() }; - this->status_variables.p_total_backend_stmt_close->Increment(q - curValue); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::com_backend_stmt_close]->Value() }; + this->status_variables.p_counter_array[p_th_counter::com_backend_stmt_close]->Increment(q - cur_val); return q; } @@ -6072,8 +5771,8 @@ unsigned long long MySQL_Threads_Handler::get_total_frontend_stmt_prepare() { q+=__sync_fetch_and_add(&thr->status_variables.frontend_stmt_prepare,0); } } - const auto& curValue { this->status_variables.p_total_frontend_stmt_prepare->Value() }; - this->status_variables.p_total_frontend_stmt_prepare->Increment(q - curValue); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::com_frontend_stmt_prepare]->Value() }; + this->status_variables.p_counter_array[p_th_counter::com_frontend_stmt_prepare]->Increment(q - cur_val); return q; } @@ -6088,8 +5787,8 @@ unsigned long long MySQL_Threads_Handler::get_total_frontend_stmt_execute() { q+=__sync_fetch_and_add(&thr->status_variables.frontend_stmt_execute,0); } } - const auto& curValue { this->status_variables.p_total_frontend_stmt_execute->Value() }; - this->status_variables.p_total_frontend_stmt_execute->Increment(q - curValue); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::com_frontend_stmt_execute]->Value() }; + this->status_variables.p_counter_array[p_th_counter::com_frontend_stmt_execute]->Increment(q - cur_val); return q; } @@ -6104,8 +5803,8 @@ unsigned long long MySQL_Threads_Handler::get_total_frontend_stmt_close() { q+=__sync_fetch_and_add(&thr->status_variables.frontend_stmt_close,0); } } - const auto& curValue { this->status_variables.p_total_frontend_stmt_close->Value() }; - this->status_variables.p_total_frontend_stmt_close->Increment(q - curValue); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::com_frontend_stmt_close]->Value() }; + this->status_variables.p_counter_array[p_th_counter::com_frontend_stmt_close]->Increment(q - cur_val); return q; } @@ -6120,8 +5819,8 @@ unsigned long long MySQL_Threads_Handler::get_total_queries() { q+=__sync_fetch_and_add(&thr->status_variables.queries,0); } } - const auto& curValue { this->status_variables.p_total_queries->Value() }; - this->status_variables.p_total_queries->Increment(q - curValue); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::questions]->Value() }; + this->status_variables.p_counter_array[p_th_counter::questions]->Increment(q - cur_val); return q; } @@ -6136,8 +5835,8 @@ unsigned long long MySQL_Threads_Handler::get_slow_queries() { q+=__sync_fetch_and_add(&thr->status_variables.queries_slow,0); } } - const auto& curValue { this->status_variables.p_slow_queries->Value() }; - this->status_variables.p_slow_queries->Increment(q - curValue); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::slow_queries]->Value() }; + this->status_variables.p_counter_array[p_th_counter::slow_queries]->Increment(q - cur_val); return q; } @@ -6152,8 +5851,8 @@ unsigned long long MySQL_Threads_Handler::get_gtid_queries() { q+=__sync_fetch_and_add(&thr->status_variables.queries_gtid,0); } } - const auto& curValue { this->status_variables.p_gtid_queries->Value() }; - this->status_variables.p_gtid_queries->Increment(q - curValue); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::gtid_consistent_queries]->Value() }; + this->status_variables.p_counter_array[p_th_counter::gtid_consistent_queries]->Increment(q - cur_val); return q; } @@ -6168,8 +5867,8 @@ unsigned long long MySQL_Threads_Handler::get_gtid_session_collected() { q+=__sync_fetch_and_add(&thr->status_variables.gtid_session_collected,0); } } - const auto& curValue { this->status_variables.p_gtid_session_collected->Value() }; - this->status_variables.p_gtid_session_collected->Increment(q - curValue); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::gtid_session_collected]->Value() }; + this->status_variables.p_counter_array[p_th_counter::gtid_session_collected]->Increment(q - cur_val); return q; } @@ -6184,8 +5883,8 @@ unsigned long long MySQL_Threads_Handler::get_queries_backends_bytes_recv() { q+=__sync_fetch_and_add(&thr->status_variables.queries_backends_bytes_recv,0); } } - const auto& curValue { this->status_variables.p_queries_backends_bytes_recv->Value() }; - this->status_variables.p_queries_backends_bytes_recv->Increment(q - curValue); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::queries_backends_bytes_recv]->Value() }; + this->status_variables.p_counter_array[p_th_counter::queries_backends_bytes_recv]->Increment(q - cur_val); return q; } @@ -6200,8 +5899,8 @@ unsigned long long MySQL_Threads_Handler::get_queries_backends_bytes_sent() { q+=__sync_fetch_and_add(&thr->status_variables.queries_backends_bytes_sent,0); } } - const auto& curValue { this->status_variables.p_queries_backends_bytes_sent->Value() }; - this->status_variables.p_queries_backends_bytes_sent->Increment(q - curValue); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::queries_frontends_bytes_sent]->Value() }; + this->status_variables.p_counter_array[p_th_counter::queries_frontends_bytes_sent]->Increment(q - cur_val); return q; } @@ -6216,8 +5915,8 @@ unsigned long long MySQL_Threads_Handler::get_queries_frontends_bytes_recv() { q+=__sync_fetch_and_add(&thr->status_variables.queries_frontends_bytes_recv,0); } } - const auto& curValue { this->status_variables.p_queries_frontends_bytes_recv->Value() }; - this->status_variables.p_queries_frontends_bytes_recv->Increment(q - curValue); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::queries_frontends_bytes_recv]->Value() }; + this->status_variables.p_counter_array[p_th_counter::queries_frontends_bytes_recv]->Increment(q - cur_val); return q; } @@ -6232,8 +5931,8 @@ unsigned long long MySQL_Threads_Handler::get_queries_frontends_bytes_sent() { q+=__sync_fetch_and_add(&thr->status_variables.queries_frontends_bytes_sent,0); } } - const auto& curValue { this->status_variables.p_queries_frontends_bytes_sent->Value() }; - this->status_variables.p_queries_frontends_bytes_sent->Increment(q - curValue); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::queries_frontends_bytes_sent]->Value() }; + this->status_variables.p_counter_array[p_th_counter::queries_frontends_bytes_sent]->Increment(q - cur_val); return q; } @@ -6248,7 +5947,7 @@ unsigned int MySQL_Threads_Handler::get_active_transations() { q+=__sync_fetch_and_add(&thr->status_variables.active_transactions,0); } } - this->status_variables.p_active_transations->Set(q); + this->status_variables.p_gauge_array[p_th_gauge::active_transactions]->Set(q); return q; } @@ -6264,7 +5963,7 @@ unsigned int MySQL_Threads_Handler::get_non_idle_client_connections() { q+=__sync_fetch_and_add(&thr->mysql_sessions->len,0); } } - status_variables.p_non_idle_client_connections->Set(q); + this->status_variables.p_gauge_array[p_th_gauge::client_connections_non_idle]->Set(q); return q; } @@ -6280,8 +5979,8 @@ unsigned long long MySQL_Threads_Handler::get_query_processor_time() { q+=__sync_fetch_and_add(&thr->status_variables.query_processor_time,0); } } - const auto& cur_val { status_variables.p_query_processor_time->Value() }; - status_variables.p_query_processor_time->Increment(q - cur_val); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::query_processor_time_nsec]->Value() }; + this->status_variables.p_counter_array[p_th_counter::query_processor_time_nsec]->Increment(q - cur_val); return q; } @@ -6296,8 +5995,8 @@ unsigned long long MySQL_Threads_Handler::get_backend_query_time() { q+=__sync_fetch_and_add(&thr->status_variables.backend_query_time,0); } } - const auto& cur_val { status_variables.p_backend_query_time->Value() }; - status_variables.p_backend_query_time->Increment(q - cur_val); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::backend_query_time_nsec]->Value() }; + this->status_variables.p_counter_array[p_th_counter::backend_query_time_nsec]->Increment(q - cur_val); return q; } @@ -6312,7 +6011,8 @@ unsigned long long MySQL_Threads_Handler::get_mysql_backend_buffers_bytes() { q+=__sync_fetch_and_add(&thr->status_variables.mysql_backend_buffers_bytes,0); } } - status_variables.p_mysql_backend_buffers_bytes->Set(q); + const auto& cur_val { this->status_variables.p_counter_array[p_th_gauge::mysql_backend_buffers_bytes]->Value() }; + this->status_variables.p_counter_array[p_th_gauge::mysql_backend_buffers_bytes]->Increment(q - cur_val); return q; } @@ -6337,7 +6037,7 @@ unsigned long long MySQL_Threads_Handler::get_mysql_frontend_buffers_bytes() { } } #endif // IDLE_THREADS - status_variables.p_mysql_frontend_buffers_bytes->Set(q); + this->status_variables.p_counter_array[p_th_gauge::mysql_frontend_buffers_bytes]->Increment(q); return q; } @@ -6360,7 +6060,7 @@ unsigned long long MySQL_Threads_Handler::get_mysql_session_internal_bytes() { } #endif // IDLE_THREADS } - status_variables.p_mysql_session_internal_bytes->Set(q); + this->status_variables.p_gauge_array[p_th_gauge::mysql_session_internal_bytes]->Set(q); return q; } @@ -6576,8 +6276,8 @@ unsigned long long MySQL_Threads_Handler::get_ConnPool_get_conn_latency_awarenes q+=__sync_fetch_and_add(&thr->status_variables.ConnPool_get_conn_latency_awareness,0); } } - const auto& cur_val { status_variables.p_ConnPool_get_conn_latency_awareness->Value() }; - status_variables.p_ConnPool_get_conn_latency_awareness->Increment(q - cur_val); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::connpool_get_conn_latency_awareness]->Value() }; + this->status_variables.p_counter_array[p_th_counter::connpool_get_conn_latency_awareness]->Increment(q - cur_val); return q; } @@ -6592,8 +6292,8 @@ unsigned long long MySQL_Threads_Handler::get_ConnPool_get_conn_immediate() { q+=__sync_fetch_and_add(&thr->status_variables.ConnPool_get_conn_immediate,0); } } - const auto& cur_val { status_variables.p_ConnPool_get_conn_immediate->Value() }; - status_variables.p_ConnPool_get_conn_immediate->Increment(q - cur_val); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::connpool_get_conn_immediate]->Value() }; + this->status_variables.p_counter_array[p_th_counter::connpool_get_conn_immediate]->Increment(q - cur_val); return q; } @@ -6608,8 +6308,8 @@ unsigned long long MySQL_Threads_Handler::get_ConnPool_get_conn_success() { q+=__sync_fetch_and_add(&thr->status_variables.ConnPool_get_conn_success,0); } } - const auto& cur_val { status_variables.p_ConnPool_get_conn_success->Value() }; - status_variables.p_ConnPool_get_conn_success->Increment(q - cur_val); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::connpool_get_conn_success]->Value() }; + this->status_variables.p_counter_array[p_th_counter::connpool_get_conn_success]->Increment(q - cur_val); return q; } @@ -6624,8 +6324,8 @@ unsigned long long MySQL_Threads_Handler::get_ConnPool_get_conn_failure() { q+=__sync_fetch_and_add(&thr->status_variables.ConnPool_get_conn_failure,0); } } - const auto& cur_val { status_variables.p_ConnPool_get_conn_failure->Value() }; - status_variables.p_ConnPool_get_conn_failure->Increment(q - cur_val); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::connpool_get_conn_failure]->Value() }; + this->status_variables.p_counter_array[p_th_counter::connpool_get_conn_failure]->Increment(q - cur_val); return q; } @@ -6640,8 +6340,8 @@ unsigned long long MySQL_Threads_Handler::get_generated_pkt_err() { q+=__sync_fetch_and_add(&thr->status_variables.generated_pkt_err,0); } } - const auto& cur_val { status_variables.p_generated_error_packets->Value() }; - status_variables.p_generated_error_packets->Increment(q - cur_val); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::generated_error_packets]->Value() }; + this->status_variables.p_counter_array[p_th_counter::generated_error_packets]->Increment(q - cur_val); return q; } @@ -6656,8 +6356,8 @@ unsigned long long MySQL_Threads_Handler::get_backend_lagging_during_query() { q+=__sync_fetch_and_add(&thr->status_variables.backend_lagging_during_query,0); } } - const auto& cur_val { status_variables.p_backend_lagging_during_query->Value() }; - status_variables.p_backend_lagging_during_query->Increment(q - cur_val); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::backend_lagging_during_query]->Value() }; + this->status_variables.p_counter_array[p_th_counter::backend_lagging_during_query]->Increment(q - cur_val); return q; } @@ -6672,8 +6372,8 @@ unsigned long long MySQL_Threads_Handler::get_backend_offline_during_query() { q+=__sync_fetch_and_add(&thr->status_variables.backend_offline_during_query,0); } } - const auto& cur_val { status_variables.p_backend_offline_during_query->Value() }; - status_variables.p_backend_offline_during_query->Increment(q - cur_val); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::backend_offline_during_query]->Value() }; + this->status_variables.p_counter_array[p_th_counter::backend_offline_during_query]->Increment(q - cur_val); return q; } @@ -6688,8 +6388,8 @@ unsigned long long MySQL_Threads_Handler::get_queries_with_max_lag_ms() { q+=__sync_fetch_and_add(&thr->status_variables.queries_with_max_lag_ms,0); } } - const auto& cur_val { status_variables.p_queries_with_max_lag_ms->Value() }; - status_variables.p_queries_with_max_lag_ms->Increment(q - cur_val); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::queries_with_max_lag_ms]->Value() }; + this->status_variables.p_counter_array[p_th_counter::queries_with_max_lag_ms]->Increment(q - cur_val); return q; } @@ -6704,8 +6404,8 @@ unsigned long long MySQL_Threads_Handler::get_queries_with_max_lag_ms__delayed() q+=__sync_fetch_and_add(&thr->status_variables.queries_with_max_lag_ms__delayed,0); } } - const auto& cur_val { status_variables.p_queries_with_max_lag_ms__delayed->Value() }; - status_variables.p_queries_with_max_lag_ms__delayed->Increment(q - cur_val); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::queries_with_max_lag_ms__delayed]->Value() }; + this->status_variables.p_counter_array[p_th_counter::queries_with_max_lag_ms__delayed]->Increment(q - cur_val); return q; } @@ -6720,8 +6420,10 @@ unsigned long long MySQL_Threads_Handler::get_queries_with_max_lag_ms__total_wai q+=__sync_fetch_and_add(&thr->status_variables.queries_with_max_lag_ms__total_wait_time_us,0); } } - const auto& cur_val { status_variables.p_queries_with_max_lag_ms__total_wait_time_us->Value() }; - status_variables.p_queries_with_max_lag_ms__total_wait_time_us->Increment(q - cur_val); + const auto& cur_val { + this->status_variables.p_counter_array[p_th_counter::queries_with_max_lag_ms__total_wait_time_us]->Value() + }; + this->status_variables.p_counter_array[p_th_counter::queries_with_max_lag_ms__total_wait_time_us]->Increment(q - cur_val); return q; } @@ -6736,8 +6438,8 @@ unsigned long long MySQL_Threads_Handler::get_max_connect_timeout() { q+=__sync_fetch_and_add(&thr->status_variables.max_connect_timeout_err,0); } } - const auto& cur_val { status_variables.p_max_connect_timeout->Value() }; - status_variables.p_max_connect_timeout->Increment(q - cur_val); + const auto& cur_val { this->status_variables.p_counter_array[p_th_counter::max_connect_timeouts]->Value() }; + this->status_variables.p_counter_array[p_th_counter::max_connect_timeouts]->Increment(q - cur_val); return q; } @@ -6752,6 +6454,11 @@ unsigned long long MySQL_Threads_Handler::get_hostgroup_locked() { q+=__sync_fetch_and_add(&thr->status_variables.hostgroup_locked,0); } } + const auto& cur_val { + this->status_variables.p_counter_array[p_th_counter::client_connections_hostgroup_locked]->Value() + }; + this->status_variables.p_counter_array[p_th_counter::client_connections_hostgroup_locked]->Increment(q - cur_val); + return q; } @@ -6765,6 +6472,11 @@ unsigned long long MySQL_Threads_Handler::get_hostgroup_locked_set_cmds() { q+=__sync_fetch_and_add(&thr->status_variables.hostgroup_locked_set_cmds,0); } } + const auto& cur_val { + this->status_variables.p_counter_array[p_th_counter::hostgroup_locked_set_cmds]->Value() + }; + this->status_variables.p_counter_array[p_th_counter::hostgroup_locked_set_cmds]->Increment(q - cur_val); + return q; } @@ -6778,6 +6490,11 @@ unsigned long long MySQL_Threads_Handler::get_hostgroup_locked_queries() { q+=__sync_fetch_and_add(&thr->status_variables.hostgroup_locked_queries,0); } } + const auto& cur_val { + this->status_variables.p_counter_array[p_th_counter::hostgroup_locked_queries]->Value() + }; + this->status_variables.p_counter_array[p_th_counter::hostgroup_locked_queries]->Increment(q - cur_val); + return q; } @@ -6791,8 +6508,10 @@ unsigned long long MySQL_Threads_Handler::get_unexpected_com_quit() { q+=__sync_fetch_and_add(&thr->status_variables.unexpected_com_quit,0); } } - const auto& cur_val { status_variables.p_mysql_unexpected_frontend_com_quit->Value() }; - status_variables.p_mysql_unexpected_frontend_com_quit->Increment(q - cur_val); + const auto& cur_val { + this->status_variables.p_counter_array[p_th_counter::mysql_unexpected_frontend_com_quit]->Value() + }; + this->status_variables.p_counter_array[p_th_counter::mysql_unexpected_frontend_com_quit]->Increment(q - cur_val); return q; } @@ -6807,8 +6526,10 @@ unsigned long long MySQL_Threads_Handler::get_unexpected_packet() { q+=__sync_fetch_and_add(&thr->status_variables.unexpected_packet,0); } } - const auto& cur_val { status_variables.p_mysql_unexpected_frontend_packets->Value() }; - status_variables.p_mysql_unexpected_frontend_packets->Increment(q - cur_val); + const auto& cur_val { + this->status_variables.p_counter_array[p_th_counter::mysql_unexpected_frontend_packets]->Value() + }; + this->status_variables.p_counter_array[p_th_counter::mysql_unexpected_frontend_packets]->Increment(q - cur_val); return q; } @@ -6823,8 +6544,10 @@ unsigned long long MySQL_Threads_Handler::get_automatic_detected_sqli() { q+=__sync_fetch_and_add(&thr->status_variables.automatic_detected_sqli,0); } } - const auto& cur_val { status_variables.p_automatic_detected_sqli->Value() }; - status_variables.p_automatic_detected_sqli->Increment(q - cur_val); + const auto& cur_val { + this->status_variables.p_counter_array[p_th_counter::automatic_detected_sql_injection]->Value() + }; + this->status_variables.p_counter_array[p_th_counter::mysql_unexpected_frontend_packets]->Increment(q - cur_val); return q; } @@ -6839,8 +6562,10 @@ unsigned long long MySQL_Threads_Handler::get_whitelisted_sqli_fingerprint() { q+=__sync_fetch_and_add(&thr->status_variables.whitelisted_sqli_fingerprint,0); } } - const auto& cur_val { status_variables.p_whitelisted_sqli_fingerprint->Value() }; - status_variables.p_whitelisted_sqli_fingerprint->Increment(q - cur_val); + const auto& cur_val { + this->status_variables.p_counter_array[p_th_counter::whitelisted_sqli_fingerprint]->Value() + }; + this->status_variables.p_counter_array[p_th_counter::whitelisted_sqli_fingerprint]->Increment(q - cur_val); return q; } @@ -6855,8 +6580,10 @@ unsigned long long MySQL_Threads_Handler::get_aws_aurora_replicas_skipped_during q+=__sync_fetch_and_add(&thr->status_variables.aws_aurora_replicas_skipped_during_query,0); } } - const auto& cur_val { status_variables.p_aws_aurora_replicas_skipped_during_query->Value() }; - status_variables.p_aws_aurora_replicas_skipped_during_query->Increment(q - cur_val); + const auto& cur_val { + this->status_variables.p_counter_array[p_th_counter::aws_aurora_replicas_skipped_during_query]->Value() + }; + this->status_variables.p_counter_array[p_th_counter::aws_aurora_replicas_skipped_during_query]->Increment(q - cur_val); return q; } @@ -6871,8 +6598,10 @@ unsigned long long MySQL_Threads_Handler::get_killed_connections() { q+=__sync_fetch_and_add(&thr->status_variables.killed_connections,0); } } - const auto& cur_val { status_variables.p_killed_connections->Value() }; - status_variables.p_killed_connections->Increment(q - cur_val); + const auto& cur_val { + this->status_variables.p_counter_array[p_th_counter::mysql_killed_backend_connections]->Value() + }; + this->status_variables.p_counter_array[p_th_counter::mysql_killed_backend_connections]->Increment(q - cur_val); return q; } @@ -6887,8 +6616,10 @@ unsigned long long MySQL_Threads_Handler::get_killed_queries() { q+=__sync_fetch_and_add(&thr->status_variables.killed_queries,0); } } - const auto& cur_val { status_variables.p_killed_queries->Value() }; - status_variables.p_killed_queries->Increment(q - cur_val); + const auto& cur_val { + this->status_variables.p_counter_array[p_th_counter::mysql_killed_backend_queries]->Value() + }; + this->status_variables.p_counter_array[p_th_counter::mysql_killed_backend_queries]->Increment(q - cur_val); return q; }