diff --git a/include/proxysql_admin.h b/include/proxysql_admin.h index 2d02f2da8..75152c4ae 100644 --- a/include/proxysql_admin.h +++ b/include/proxysql_admin.h @@ -892,5 +892,12 @@ class ProxySQL_Admin { // FLUSH LOGS void flush_logs(); + +#ifdef DEBUG + // FLUSH STATS + void flush_stats(); // Reset all statistics + void flush_mysql_stats(); // Reset MySQL statistics only + void flush_pgsql_stats(); // Reset PostgreSQL statistics only +#endif // DEBUG }; #endif /* __CLASS_PROXYSQL_ADMIN_H */ diff --git a/lib/Admin_Handler.cpp b/lib/Admin_Handler.cpp index 8d2f2f01d..064eb52cc 100644 --- a/lib/Admin_Handler.cpp +++ b/lib/Admin_Handler.cpp @@ -808,6 +808,32 @@ bool admin_handler_command_proxysql(char *query_no_space, unsigned int query_no_ return false; } +#ifdef DEBUG + if (query_no_space_length == strlen("PROXYSQL FLUSH STATS") && !strncasecmp("PROXYSQL FLUSH STATS", query_no_space, query_no_space_length)) { + proxy_info("Received PROXYSQL FLUSH STATS command\n"); + ProxySQL_Admin *SPA = (ProxySQL_Admin *)pa; + SPA->flush_stats(); + SPA->send_ok_msg_to_client(sess, NULL, 0, query_no_space); + return false; + } + + if (query_no_space_length == strlen("PROXYSQL FLUSH MYSQL STATS") && !strncasecmp("PROXYSQL FLUSH MYSQL STATS", query_no_space, query_no_space_length)) { + proxy_info("Received PROXYSQL FLUSH MYSQL STATS command\n"); + ProxySQL_Admin *SPA = (ProxySQL_Admin *)pa; + SPA->flush_mysql_stats(); + SPA->send_ok_msg_to_client(sess, NULL, 0, query_no_space); + return false; + } + + if (query_no_space_length == strlen("PROXYSQL FLUSH PGSQL STATS") && !strncasecmp("PROXYSQL FLUSH PGSQL STATS", query_no_space, query_no_space_length)) { + proxy_info("Received PROXYSQL FLUSH PGSQL STATS command\n"); + ProxySQL_Admin *SPA = (ProxySQL_Admin *)pa; + SPA->flush_pgsql_stats(); + SPA->send_ok_msg_to_client(sess, NULL, 0, query_no_space); + return false; + } +#endif // DEBUG + if (strcasecmp("PROXYSQL RELOAD TLS",query_no_space) == 0) { proxy_info("Received %s command\n", query_no_space); ProxySQL_Admin *SPA=(ProxySQL_Admin *)pa; diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index 215d326af..4b08581f9 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -1116,6 +1116,47 @@ void ProxySQL_Admin::flush_logs() { proxy_debug(PROXY_DEBUG_ADMIN, 1, "Running PROXYSQL FLUSH LOGS\n"); } +#ifdef DEBUG +void ProxySQL_Admin::flush_stats() { + flush_mysql_stats(); + flush_pgsql_stats(); +} + +void ProxySQL_Admin::flush_mysql_stats() { + if (!GloMyQPro || !GloMTH || !MyHGM) { + proxy_info("MySQL statistics flush skipped: MySQL modules not initialized\n"); + return; + } + // Reset MySQL query digest statistics + stats___mysql_query_digests_v2(true, false, false); + // Reset MySQL error statistics + stats___mysql_errors(true); + // Reset MySQL connection pool statistics + stats___mysql_connection_pool(true); + // Reset MySQL client host cache + stats___mysql_client_host_cache(true); + + proxy_info("MySQL statistics flushed successfully\n"); +} + +void ProxySQL_Admin::flush_pgsql_stats() { + if (!GloPgQPro || !GloPTH || !PgHGM) { + proxy_info("PgSQL statistics flush skipped: PgSQL modules not initialized\n"); + return; + } + // Reset PostgreSQL query digest statistics + stats___pgsql_query_digests_v2(true, false, false); + // Reset PostgreSQL error statistics + stats___pgsql_errors(true); + // Reset PostgreSQL connection pool statistics + stats___pgsql_connection_pool(true); + // Reset PostgreSQL client host cache + stats___pgsql_client_host_cache(true); + + proxy_info("PgSQL statistics flushed successfully\n"); +} +#endif // DEBUG + // Explicitly instantiate the required template class and member functions // NOTE: send_ok_msg_to_client and send_error_msg_to_client instantiations moved to after definitions (near line 5730) template int ProxySQL_Admin::FlushDigestTableToDisk<(SERVER_TYPE)0>(SQLite3DB*); diff --git a/test/tap/tests/admin_various_commands2-t.cpp b/test/tap/tests/admin_various_commands2-t.cpp index a412abc27..658a7cc3a 100644 --- a/test/tap/tests/admin_various_commands2-t.cpp +++ b/test/tap/tests/admin_various_commands2-t.cpp @@ -27,6 +27,9 @@ std::vector queries = { "PROXYSQL FLUSH LOGS", "PROXYSQL FLUSH QUERY CACHE", "PROXYSQL FLUSH CONFIGDB", + "PROXYSQL FLUSH STATS", + "PROXYSQL FLUSH MYSQL STATS", + "PROXYSQL FLUSH PGSQL STATS", "PROXYSQLTEST 21", "PROXYSQLTEST 21 10", "PROXYSQLTEST 41",