New table stats_mysql_connection_pool_reset #753

v1.4.0
René Cannaò 9 years ago
parent 7ad748d847
commit 817cda3f12

@ -227,7 +227,7 @@ class MySQL_HostGroups_Manager {
void drop_all_idle_connections();
int get_multiple_idle_connections(int, unsigned long long, MySQL_Connection **, int);
SQLite3_result * SQL3_Connection_Pool();
SQLite3_result * SQL3_Connection_Pool(bool _reset);
void push_MyConn_to_pool(MySQL_Connection *, bool _lock=true);
void push_MyConn_to_pool_array(MySQL_Connection **);

@ -182,7 +182,7 @@ class ProxySQL_Admin {
//void stats___mysql_query_digests_reset();
void stats___mysql_commands_counters();
void stats___mysql_processlist();
void stats___mysql_connection_pool();
void stats___mysql_connection_pool(bool _reset);
void stats___mysql_global();
void stats___mysql_users();

@ -1379,7 +1379,7 @@ void MySQL_HostGroups_Manager::set_incoming_group_replication_hostgroups(SQLite3
incoming_group_replication_hostgroups=s;
}
SQLite3_result * MySQL_HostGroups_Manager::SQL3_Connection_Pool() {
SQLite3_result * MySQL_HostGroups_Manager::SQL3_Connection_Pool(bool _reset) {
const int colnum=12;
proxy_debug(PROXY_DEBUG_MYSQL_CONNECTION, 4, "Dumping Connection Pool\n");
SQLite3_result *result=new SQLite3_result(colnum);
@ -1446,14 +1446,29 @@ SQLite3_result * MySQL_HostGroups_Manager::SQL3_Connection_Pool() {
pta[5]=strdup(buf);
sprintf(buf,"%u", mysrvc->connect_OK);
pta[6]=strdup(buf);
if (_reset) {
mysrvc->connect_OK=0;
}
sprintf(buf,"%u", mysrvc->connect_ERR);
pta[7]=strdup(buf);
if (_reset) {
mysrvc->connect_ERR=0;
}
sprintf(buf,"%llu", mysrvc->queries_sent);
pta[8]=strdup(buf);
if (_reset) {
mysrvc->queries_sent=0;
}
sprintf(buf,"%llu", mysrvc->bytes_sent);
pta[9]=strdup(buf);
if (_reset) {
mysrvc->bytes_sent=0;
}
sprintf(buf,"%llu", mysrvc->bytes_recv);
pta[10]=strdup(buf);
if (_reset) {
mysrvc->bytes_recv=0;
}
sprintf(buf,"%u", mysrvc->current_latency_us);
pta[11]=strdup(buf);
result->add_row(pta);

@ -194,6 +194,8 @@ pthread_mutex_t admin_mutex = PTHREAD_MUTEX_INITIALIZER;
#define STATS_SQLITE_TABLE_MYSQL_PROCESSLIST "CREATE TABLE stats_mysql_processlist (ThreadID INT NOT NULL , SessionID INTEGER PRIMARY KEY , user VARCHAR , db VARCHAR , cli_host VARCHAR , cli_port VARCHAR , hostgroup VARCHAR , l_srv_host VARCHAR , l_srv_port VARCHAR , srv_host VARCHAR , srv_port VARCHAR , command VARCHAR , time_ms INT NOT NULL , info VARCHAR)"
#define STATS_SQLITE_TABLE_MYSQL_CONNECTION_POOL "CREATE TABLE stats_mysql_connection_pool (hostgroup VARCHAR , srv_host VARCHAR , srv_port VARCHAR , status VARCHAR , ConnUsed INT , ConnFree INT , ConnOK INT , ConnERR INT , Queries INT , Bytes_data_sent INT , Bytes_data_recv INT , Latency_us INT)"
#define STATS_SQLITE_TABLE_MYSQL_CONNECTION_POOL_RESET "CREATE TABLE stats_mysql_connection_pool_reset (hostgroup VARCHAR , srv_host VARCHAR , srv_port VARCHAR , status VARCHAR , ConnUsed INT , ConnFree INT , ConnOK INT , ConnERR INT , Queries INT , Bytes_data_sent INT , Bytes_data_recv INT , Latency_us INT)"
#define STATS_SQLITE_TABLE_MYSQL_QUERY_DIGEST "CREATE TABLE stats_mysql_query_digest (hostgroup INT , schemaname VARCHAR NOT NULL , username VARCHAR NOT NULL , digest VARCHAR NOT NULL , digest_text VARCHAR NOT NULL , count_star INTEGER NOT NULL , first_seen INTEGER NOT NULL , last_seen INTEGER NOT NULL , sum_time INTEGER NOT NULL , min_time INTEGER NOT NULL , max_time INTEGER NOT NULL , PRIMARY KEY(hostgroup, schemaname, username, digest))"
#define STATS_SQLITE_TABLE_MYSQL_QUERY_DIGEST_RESET "CREATE TABLE stats_mysql_query_digest_reset (hostgroup INT , schemaname VARCHAR NOT NULL , username VARCHAR NOT NULL , digest VARCHAR NOT NULL , digest_text VARCHAR NOT NULL , count_star INTEGER NOT NULL , first_seen INTEGER NOT NULL , last_seen INTEGER NOT NULL , sum_time INTEGER NOT NULL , min_time INTEGER NOT NULL , max_time INTEGER NOT NULL , PRIMARY KEY(hostgroup, schemaname, username, digest))"
@ -1244,6 +1246,7 @@ void ProxySQL_Admin::GenericRefreshStatistics(const char *query_no_space, unsign
bool refresh=false;
bool stats_mysql_processlist=false;
bool stats_mysql_connection_pool=false;
bool stats_mysql_connection_pool_reset=false;
bool stats_mysql_query_digest=false;
bool stats_mysql_query_digest_reset=false;
bool stats_mysql_global=false;
@ -1271,8 +1274,13 @@ void ProxySQL_Admin::GenericRefreshStatistics(const char *query_no_space, unsign
{ stats_mysql_query_digest_reset=true; refresh=true; }
if (strstr(query_no_space,"stats_mysql_global"))
{ stats_mysql_global=true; refresh=true; }
if (strstr(query_no_space,"stats_mysql_connection_pool"))
{ stats_mysql_connection_pool=true; refresh=true; }
if (strstr(query_no_space,"stats_mysql_connection_pool_reset"))
{
stats_mysql_connection_pool_reset=true; refresh=true;
} else {
if (strstr(query_no_space,"stats_mysql_connection_pool"))
{ stats_mysql_connection_pool=true; refresh=true; }
}
if (strstr(query_no_space,"stats_mysql_commands_counters"))
{ stats_mysql_commands_counters=true; refresh=true; }
if (strstr(query_no_space,"stats_mysql_query_rules"))
@ -1316,8 +1324,12 @@ void ProxySQL_Admin::GenericRefreshStatistics(const char *query_no_space, unsign
stats___mysql_query_digests(false);
if (stats_mysql_query_digest_reset)
stats___mysql_query_digests(true);
if (stats_mysql_connection_pool)
stats___mysql_connection_pool();
if (stats_mysql_connection_pool_reset) {
stats___mysql_connection_pool(true);
} else {
if (stats_mysql_connection_pool)
stats___mysql_connection_pool(false);
}
if (stats_mysql_global)
stats___mysql_global();
if (stats_mysql_query_rules)
@ -2545,6 +2557,7 @@ bool ProxySQL_Admin::init() {
insert_into_tables_defs(tables_defs_stats,"stats_mysql_commands_counters", STATS_SQLITE_TABLE_MYSQL_COMMANDS_COUNTERS);
insert_into_tables_defs(tables_defs_stats,"stats_mysql_processlist", STATS_SQLITE_TABLE_MYSQL_PROCESSLIST);
insert_into_tables_defs(tables_defs_stats,"stats_mysql_connection_pool", STATS_SQLITE_TABLE_MYSQL_CONNECTION_POOL);
insert_into_tables_defs(tables_defs_stats,"stats_mysql_connection_pool_reset", STATS_SQLITE_TABLE_MYSQL_CONNECTION_POOL_RESET);
insert_into_tables_defs(tables_defs_stats,"stats_mysql_query_digest", STATS_SQLITE_TABLE_MYSQL_QUERY_DIGEST);
insert_into_tables_defs(tables_defs_stats,"stats_mysql_query_digest_reset", STATS_SQLITE_TABLE_MYSQL_QUERY_DIGEST_RESET);
insert_into_tables_defs(tables_defs_stats,"stats_mysql_global", STATS_SQLITE_TABLE_MYSQL_GLOBAL);
@ -3301,10 +3314,10 @@ void ProxySQL_Admin::stats___mysql_processlist() {
delete resultset;
}
void ProxySQL_Admin::stats___mysql_connection_pool() {
void ProxySQL_Admin::stats___mysql_connection_pool(bool _reset) {
if (!MyHGM) return;
SQLite3_result * resultset=MyHGM->SQL3_Connection_Pool();
SQLite3_result * resultset=MyHGM->SQL3_Connection_Pool(_reset);
if (resultset==NULL) return;
statsdb->execute("BEGIN");
statsdb->execute("DELETE FROM stats_mysql_connection_pool");
@ -3320,6 +3333,10 @@ void ProxySQL_Admin::stats___mysql_connection_pool() {
statsdb->execute(query);
free(query);
}
if (_reset) {
statsdb->execute("DELETE FROM stats_mysql_connection_pool_reset");
statsdb->execute("INSERT INTO stats_mysql_connection_pool_reset SELECT * FROM stats_mysql_connection_pool");
}
statsdb->execute("COMMIT");
delete resultset;
}

Loading…
Cancel
Save