Replaced 'hostgroups_manager' prometheus metrics with new array based impl

pull/2676/head
Javier Jaramago Fernández 6 years ago
parent 073337c716
commit c48b109019

@ -263,6 +263,367 @@ class AWS_Aurora_Info {
bool update(int r, int _port, char *_end_addr, int maxl, int al, int minl, int lnc, int ci, int ct, bool _a, int wiar, int nrw, char *c);
~AWS_Aurora_Info();
};
struct p_hg_counter {
enum metric {
servers_table_version = 0,
server_connections_created,
server_connections_delayed,
server_connections_aborted,
client_connections_created,
client_connections_aborted,
com_autocommit,
com_autocommit_filtered,
com_rollback,
com_rollback_filtered,
com_backend_change_user,
com_backend_init_db,
// TODO: https://sysown-team.monday.com/boards/484798975/pulses/529413331
com_backend_set_names,
com_frontend_init_db,
com_frontend_set_names,
com_frontend_use_db,
com_commit_cnt,
com_commit_cnt_filtered,
selects_for_update__autocommit0,
access_denied_wrong_password,
access_denied_max_connections,
access_denied_max_user_connections,
myhgm_myconnpoll_get,
myhgm_myconnpoll_get_ok,
myhgm_myconnpoll_push,
myhgm_myconnpoll_reset,
myhgm_myconnpoll_destroy,
__size
};
};
struct p_hg_gauge {
enum metric {
server_connections_connected = 0,
client_connections_connected,
__size
};
};
struct p_hg_dyn_counter {
enum metric {
conn_pool_bytes_data_recv = 0,
conn_pool_bytes_data_sent,
connection_pool_conn_err,
connection_pool_conn_ok,
connection_pool_queries,
gtid_executed,
__size
};
};
struct p_hg_dyn_gauge {
enum metric {
connection_pool_conn_free = 0,
connection_pool_conn_used,
connection_pool_latency_us,
connection_pool_status,
__size
};
};
using active_flag = bool;
using metric_name = std::string;
using metric_help = std::string;
using metric_tags = std::map<std::string, std::string>;
struct hg_metrics_map_idx {
enum index {
counters = 0,
gauges,
dyn_counters,
dyn_gauges,
};
};
const static std::tuple<
std::vector<
std::tuple<
p_hg_counter::metric,
metric_name,
metric_help,
metric_tags
>
>,
std::vector<
std::tuple<
p_hg_gauge::metric,
metric_name,
metric_help,
metric_tags
>
>,
std::vector<
std::tuple<
p_hg_dyn_counter::metric,
metric_name,
metric_help,
metric_tags
>
>,
std::vector<
std::tuple<
p_hg_dyn_gauge::metric,
metric_name,
metric_help,
metric_tags
>
>
>
hg_metrics_map {
{
{
p_hg_counter::servers_table_version,
"proxysql_servers_table_version",
"",
{}
},
{
p_hg_counter::server_connections_created,
"proxysql_server_connections_created",
"",
{}
},
{
p_hg_counter::server_connections_delayed,
"proxysql_server_connections_delayed",
"",
{}
},
{
p_hg_counter::server_connections_aborted,
"proxysql_server_connections_aborted",
"",
{}
},
{
p_hg_counter::client_connections_created,
"proxysql_client_connections_created",
"",
{}
},
{
p_hg_counter::client_connections_aborted,
"proxysql_client_connections_aborted",
"",
{}
},
{
p_hg_counter::com_autocommit,
"proxysql_com_autocommit",
"",
{}
},
{
p_hg_counter::com_autocommit_filtered,
"proxysql_com_autocommit_filtered",
"",
{}
},
{
p_hg_counter::com_rollback,
"proxysql_com_rollback",
"",
{}
},
{
p_hg_counter::com_rollback_filtered,
"proxysql_com_rollback_filtered",
"",
{}
},
{
p_hg_counter::com_backend_change_user,
"proxysql_com_backend_change_user",
"",
{}
},
{
p_hg_counter::com_backend_init_db,
"proxysql_com_backend_init_db",
"",
{}
},
{
p_hg_counter::com_frontend_init_db,
"proxysql_com_frontend_init_db",
"",
{}
},
{
p_hg_counter::com_frontend_set_names,
"proxysql_com_frontend_set_names",
"",
{}
},
{
p_hg_counter::com_frontend_use_db,
"proxysql_com_frontend_use_db",
"",
{}
},
{
p_hg_counter::com_commit_cnt,
"proxysql_com_commit_cnt",
"",
{}
},
{
p_hg_counter::com_commit_cnt_filtered,
"proxysql_com_commit_cnt_filtered",
"",
{}
},
{
p_hg_counter::com_commit_cnt_filtered,
"proxysql_com_commit_cnt_filtered",
"",
{}
},
{
p_hg_counter::selects_for_update__autocommit0,
"proxysql_selects_for_update__autocommit0",
"",
{}
},
{
p_hg_counter::access_denied_wrong_password,
"proxysql_access_denied_wrong_password",
"",
{}
},
{
p_hg_counter::access_denied_max_connections,
"proxysql_access_denied_max_connections",
"",
{}
},
{
p_hg_counter::access_denied_max_user_connections,
"proxysql_access_denied_max_user_connections",
"",
{}
},
{
p_hg_counter::myhgm_myconnpoll_get,
"proxysql_myhgm_myconnpoll_get",
"",
{}
},
{
p_hg_counter::myhgm_myconnpoll_get_ok,
"proxysql_myhgm_myconnpoll_get_ok",
"",
{}
},
{
p_hg_counter::myhgm_myconnpoll_push,
"proxysql_myhgm_myconnpoll_push",
"",
{}
},
{
p_hg_counter::myhgm_myconnpoll_reset,
"proxysql_myhgm_myconnpoll_reset",
"",
{}
},
{
p_hg_counter::myhgm_myconnpoll_destroy,
"proxysql_myhgm_myconnpoll_destroy",
"",
{}
}
},
// prometheus gauges
{
{
p_hg_gauge::server_connections_connected,
"proxysql_server_connections_connected",
"Backend connections that are currently connected.",
{}
},
{
p_hg_gauge::client_connections_connected,
"proxysql_client_connections_connected",
"Client connections that are currently connected.",
{}
}
},
// prometheus dynamic counters
{
// connection_pool
{
p_hg_dyn_counter::conn_pool_bytes_data_recv,
"proxysql_connection_pool_bytes_data_recv",
"The amount of data received from the backend, excluding metadata.",
{}
},
{
p_hg_dyn_counter::conn_pool_bytes_data_sent,
"proxysql_connection_pool_bytes_data_sent",
"The amount of data sent to the backend, excluding metadata.",
{}
},
{
p_hg_dyn_counter::connection_pool_conn_err,
"proxysql_connection_pool_conn_err",
"How many connections weren't established successfully.",
{}
},
{
p_hg_dyn_counter::connection_pool_conn_ok,
"proxysql_connection_pool_conn_ok",
"How many connections were established successfully.",
{}
},
{
p_hg_dyn_counter::connection_pool_queries,
"proxysql_connection_pool_conn_queries",
"The number of queries routed towards this particular backend server.",
{}
},
// gtid
{
p_hg_dyn_counter::gtid_executed,
"proxysql_gtid_executed",
"Tracks the number of executed gtid per host and port.",
{}
},
},
// prometheus dynamic counters
{
{
p_hg_dyn_gauge::connection_pool_conn_free,
"proxysql_connection_pool_conn_free",
"How many connections are currently free.",
{}
},
{
p_hg_dyn_gauge::connection_pool_conn_used,
"proxysql_connection_pool_conn_used",
"How many connections are currently used by ProxySQL for sending queries to the backend server.",
{}
},
{
p_hg_dyn_gauge::connection_pool_latency_us,
"proxysql_connection_pool_conn_latency_us",
"The currently ping time in microseconds, as reported from Monitor.",
{}
},
{
p_hg_dyn_gauge::connection_pool_status,
"proxysql_connection_pool_conn_status",
"The status of the backend server (1 - ONLINE, 2 - SHUNNED, 3 - OFFLINE_SOFT, 4 - OFFLINE_HARD).",
{}
}
}
};
class MySQL_HostGroups_Manager {
private:
@ -315,6 +676,23 @@ class MySQL_HostGroups_Manager {
pthread_mutex_t mysql_errors_mutex;
umap_mysql_errors mysql_errors_umap;
/**
* @brief Initalizes the prometheus counters specified in hg_metrics_map.
*/
void init_prometheus_counters();
/**
* @brief Initalizes the prometheus gauges specified in hg_metrics_map.
*/
void init_prometheus_gauges();
/**
* @brief Initalizes the prometheus dynamic counters specified in hg_metrics_map.
*/
void init_prometheus_dyn_counters();
/**
* @brief Initalizes the prometheus dynamic gauges specified in hg_metrics_map.
*/
void init_prometheus_dyn_gauges();
public:
pthread_rwlock_t gtid_rwlock;
std::unordered_map <string, GTID_Server_Data *> gtid_map;
@ -360,46 +738,13 @@ class MySQL_HostGroups_Manager {
/// Prometheus Metrics ///
//////////////////////////////////////////////////////
/// Prometheus client metrics
prometheus::Counter* p_client_connections_created { nullptr };
prometheus::Counter* p_client_connections_aborted { nullptr };
prometheus::Gauge* p_client_connections { nullptr };
/// Prometheus server metrics
prometheus::Counter* p_servers_table_version { nullptr };
prometheus::Counter* p_server_connections_aborted { nullptr };
prometheus::Counter* p_server_connections_created { nullptr };
prometheus::Counter* p_server_connections_delayed { nullptr };
prometheus::Gauge* p_server_connections_connected { nullptr };
/// Prometheus access metrics
prometheus::Counter* p_access_denied_wrong_password { nullptr };
prometheus::Counter* p_access_denied_max_connections { nullptr };
prometheus::Counter* p_access_denied_max_user_connections { nullptr };
/// Prometheus backend metrics
prometheus::Counter* p_backend_change_user { nullptr };
prometheus::Counter* p_backend_init_db { nullptr };
prometheus::Counter* p_backend_set_names { nullptr };
/// Prometheus frontend metrics
prometheus::Counter* p_frontend_init_db { nullptr };
prometheus::Counter* p_frontend_set_names { nullptr };
prometheus::Counter* p_frontend_use_db { nullptr };
/// Prometheus ** metrics
prometheus::Counter* p_autocommit_cnt { nullptr };
prometheus::Counter* p_commit_cnt { nullptr };
prometheus::Counter* p_rollback_cnt { nullptr };
prometheus::Counter* p_autocommit_cnt_filtered { nullptr };
prometheus::Counter* p_commit_cnt_filtered { nullptr };
prometheus::Counter* p_rollback_cnt_filtered { nullptr };
prometheus::Counter* p_select_for_update_or_equivalent { nullptr };
/// Prometheus myconnpoll metrics
prometheus::Counter* p_myconnpoll_get { nullptr };
prometheus::Counter* p_myconnpoll_get_ok { nullptr };
prometheus::Counter* p_myconnpoll_push { nullptr };
prometheus::Counter* p_myconnpoll_reset { nullptr };
prometheus::Counter* p_myconnpoll_destroy { nullptr };
/// Prometheus metrics arrays
std::array<prometheus::Counter*, p_hg_counter::__size> p_counter_array {};
std::array<prometheus::Gauge*, p_hg_gauge::__size> p_gauge_array {};
// Prometheus dyn_metrics families arrays
std::array<prometheus::Family<prometheus::Counter>*, p_hg_dyn_counter::__size> p_dyn_counter_array {};
std::array<prometheus::Family<prometheus::Gauge>*, p_hg_dyn_gauge::__size> p_dyn_gauge_array {};
/// Prometheus connection_pool metrics
std::map<std::string, prometheus::Counter*> p_conn_pool_bytes_data_recv_map {};

@ -1,5 +1,7 @@
#include "MySQL_HostGroups_Manager.h"
#include "prometheus/counter.h"
#include "prometheus/detail/builder.h"
#include "prometheus/family.h"
#include "prometheus/gauge.h"
#include "proxysql.h"
#include "cpp.h"
@ -860,7 +862,7 @@ void MySrvC::connect_error(int err_num) {
// as a single connection failure won't make a significant difference
__sync_fetch_and_add(&connect_ERR,1);
__sync_fetch_and_add(&MyHGM->status.server_connections_aborted,1);
MyHGM->status.p_server_connections_aborted->Increment();
MyHGM->status.p_counter_array[p_hg_counter::server_connections_aborted]->Increment();
if (err_num >= 1048 && err_num <= 1052)
return;
if (err_num >= 1054 && err_num <= 1075)
@ -949,6 +951,122 @@ MyHGC::~MyHGC() {
delete mysrvs;
}
void MySQL_HostGroups_Manager::init_prometheus_counters() {
for (const auto& metric : std::get<hg_metrics_map_idx::counters>(hg_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<prometheus::Counter>* 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.p_counter_array[tg_metric] =
std::addressof(metric_family->Add(metric_tags));
}
}
void MySQL_HostGroups_Manager::init_prometheus_gauges() {
for (const auto& metric : std::get<hg_metrics_map_idx::gauges>(hg_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<prometheus::Gauge>* 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.p_gauge_array[tg_metric] =
std::addressof(metric_family->Add(metric_tags));
}
}
void MySQL_HostGroups_Manager::init_prometheus_dyn_counters() {
for (const auto& metric : std::get<hg_metrics_map_idx::dyn_counters>(hg_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) };
prometheus::Family<prometheus::Counter>* 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.p_dyn_counter_array[tg_metric] = metric_family;
}
}
void MySQL_HostGroups_Manager::init_prometheus_dyn_gauges() {
for (const auto& metric : std::get<hg_metrics_map_idx::dyn_gauges>(hg_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) };
prometheus::Family<prometheus::Gauge>* 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.p_dyn_gauge_array[tg_metric] = metric_family;
}
}
MySQL_HostGroups_Manager::MySQL_HostGroups_Manager() {
pthread_mutex_init(&ev_loop_mutex, NULL);
status.client_connections=0;
@ -1028,244 +1146,10 @@ MySQL_HostGroups_Manager::MySQL_HostGroups_Manager() {
pthread_mutex_init(&mysql_errors_mutex, NULL);
// Initialize prometheus metrics
// server_* metrics
auto& servers_table_version {
prometheus::BuildCounter()
.Name("proxysql_servers_table_version")
.Register(*GloVars.prometheus_registry)
};
this->status.p_servers_table_version =
std::addressof(servers_table_version.Add({}));
auto& server_connections_connected {
prometheus::BuildGauge()
.Name("proxysql_server_connections_connected")
.Register(*GloVars.prometheus_registry)
};
this->status.p_server_connections_connected =
std::addressof(server_connections_connected.Add({}));
auto& server_connections_created {
prometheus::BuildCounter()
.Name("proxysql_server_connections_created")
.Register(*GloVars.prometheus_registry)
};
this->status.p_server_connections_created =
std::addressof(server_connections_created.Add({}));
auto& server_connections_delayed {
prometheus::BuildCounter()
.Name("proxysql_server_connections_delayed")
.Register(*GloVars.prometheus_registry)
};
this->status.p_server_connections_delayed =
std::addressof(server_connections_delayed.Add({}));
auto& server_connections_aborted {
prometheus::BuildCounter()
.Name("proxysql_server_connections_aborted")
.Register(*GloVars.prometheus_registry)
};
this->status.p_server_connections_aborted =
std::addressof(server_connections_aborted.Add({}));
// client_connections_* metrics
auto& client_connections_created {
prometheus::BuildCounter()
.Name("proxysql_client_connections_created")
.Register(*GloVars.prometheus_registry)
};
this->status.p_client_connections_created =
std::addressof(client_connections_created.Add({}));
auto& client_connections_aborted {
prometheus::BuildCounter()
.Name("proxysql_client_connections_aborted")
.Register(*GloVars.prometheus_registry)
};
this->status.p_client_connections_aborted =
std::addressof(client_connections_aborted.Add({}));
// TODO: Check type of this one
auto& client_connections_connected {
prometheus::BuildGauge()
.Name("proxysql_client_connections_connected")
.Register(*GloVars.prometheus_registry)
};
this->status.p_client_connections =
std::addressof(client_connections_connected.Add({}));
// com_* counters
auto& com_autocommit {
prometheus::BuildCounter()
.Name("proxysql_com_autocommit")
.Register(*GloVars.prometheus_registry)
};
this->status.p_autocommit_cnt =
std::addressof(com_autocommit.Add({}));
auto& com_autocommit_filtered {
prometheus::BuildCounter()
.Name("proxysql_com_autocommit_filtered")
.Register(*GloVars.prometheus_registry)
};
this->status.p_autocommit_cnt_filtered =
std::addressof(com_autocommit_filtered.Add({}));
auto& com_rollback {
prometheus::BuildCounter()
.Name("proxysql_com_rollback")
.Register(*GloVars.prometheus_registry)
};
this->status.p_rollback_cnt =
std::addressof(com_rollback.Add({}));
auto& com_rollback_filtered {
prometheus::BuildCounter()
.Name("proxysql_com_rollback_filtered")
.Register(*GloVars.prometheus_registry)
};
this->status.p_rollback_cnt_filtered =
std::addressof(com_rollback_filtered.Add({}));
auto& com_backend_change_user {
prometheus::BuildCounter()
.Name("proxysql_com_backend_change_user")
.Register(*GloVars.prometheus_registry)
};
this->status.p_backend_change_user =
std::addressof(com_backend_change_user.Add({}));
auto& com_backend_init_db {
prometheus::BuildCounter()
.Name("proxysql_com_backend_init_db")
.Register(*GloVars.prometheus_registry)
};
this->status.p_backend_init_db =
std::addressof(com_backend_init_db.Add({}));
auto& com_backend_set_names {
prometheus::BuildCounter()
.Name("proxysql_com_backend_set_names")
.Register(*GloVars.prometheus_registry)
};
this->status.p_backend_set_names =
std::addressof(com_backend_set_names.Add({}));
auto& com_frontend_init_db {
prometheus::BuildCounter()
.Name("proxysql_com_frontend_init_db")
.Register(*GloVars.prometheus_registry)
};
this->status.p_frontend_init_db =
std::addressof(com_frontend_init_db.Add({}));
auto& com_frontend_set_names {
prometheus::BuildCounter()
.Name("proxysql_com_frontend_set_names")
.Register(*GloVars.prometheus_registry)
};
this->status.p_frontend_set_names =
std::addressof(com_frontend_set_names.Add({}));
auto& com_frontend_use_db {
prometheus::BuildCounter()
.Name("proxysql_com_frontend_use_db")
.Register(*GloVars.prometheus_registry)
};
this->status.p_frontend_use_db =
std::addressof(com_frontend_use_db.Add({}));
auto& com_commit_cnt {
prometheus::BuildCounter()
.Name("proxysql_com_commit_cnt")
.Register(*GloVars.prometheus_registry)
};
this->status.p_commit_cnt =
std::addressof(com_commit_cnt.Add({}));
auto& com_commit_cnt_filtered {
prometheus::BuildCounter()
.Name("proxysql_com_commit_cnt_filtered")
.Register(*GloVars.prometheus_registry)
};
this->status.p_commit_cnt_filtered =
std::addressof(com_commit_cnt_filtered.Add({}));
// TODO: Check name
auto& select_for_update_or_equivalent {
prometheus::BuildCounter()
.Name("proxysql_selects_for_update__autocommit0")
.Register(*GloVars.prometheus_registry)
};
this->status.p_select_for_update_or_equivalent =
std::addressof(select_for_update_or_equivalent.Add({}));
// Access_* errors
auto& access_denied_wrong_password {
prometheus::BuildCounter()
.Name("proxysql_access_denied_wrong_password")
.Register(*GloVars.prometheus_registry)
};
this->status.p_access_denied_wrong_password =
std::addressof(access_denied_wrong_password.Add({}));
auto& access_denied_max_connections {
prometheus::BuildCounter()
.Name("proxysql_access_denied_max_connections")
.Register(*GloVars.prometheus_registry)
};
this->status.p_access_denied_max_connections =
std::addressof(access_denied_max_connections.Add({}));
auto& access_denied_max_user_connections {
prometheus::BuildCounter()
.Name("proxysql_access_denied_max_user_connections")
.Register(*GloVars.prometheus_registry)
};
this->status.p_access_denied_max_user_connections =
std::addressof(access_denied_max_user_connections.Add({}));
auto& myconnpoll_get {
prometheus::BuildCounter()
.Name("proxysql_myhgm_myconnpoll_get")
.Register(*GloVars.prometheus_registry)
};
this->status.p_myconnpoll_get =
std::addressof(myconnpoll_get.Add({}));
auto& myconnpoll_get_ok {
prometheus::BuildCounter()
.Name("proxysql_myhgm_myconnpoll_get_ok")
.Register(*GloVars.prometheus_registry)
};
this->status.p_myconnpoll_get_ok =
std::addressof(myconnpoll_get_ok.Add({}));
auto& myconnpoll_push {
prometheus::BuildCounter()
.Name("proxysql_myhgm_myconnpoll_push")
.Register(*GloVars.prometheus_registry)
};
this->status.p_myconnpoll_push =
std::addressof(myconnpoll_push.Add({}));
auto& myconnpoll_reset {
prometheus::BuildCounter()
.Name("proxysql_myhgm_myconnpoll_reset")
.Register(*GloVars.prometheus_registry)
};
this->status.p_myconnpoll_reset =
std::addressof(myconnpoll_reset.Add({}));
auto& myconnpoll_destroy {
prometheus::BuildCounter()
.Name("proxysql_myhgm_myconnpoll_destroy")
.Register(*GloVars.prometheus_registry)
};
this->status.p_myconnpoll_destroy =
std::addressof(myconnpoll_destroy.Add({}));
init_prometheus_counters();
init_prometheus_gauges();
init_prometheus_dyn_counters();
init_prometheus_dyn_gauges();
}
void MySQL_HostGroups_Manager::init() {
@ -1866,7 +1750,7 @@ bool MySQL_HostGroups_Manager::commit() {
ev_async_send(gtid_ev_loop, gtid_ev_async);
__sync_fetch_and_add(&status.servers_table_version,1);
this->status.p_servers_table_version->Increment(1);
this->status.p_counter_array[p_hg_counter::servers_table_version]->Increment();
pthread_cond_broadcast(&status.servers_table_version_cond);
pthread_mutex_unlock(&status.servers_table_version_lock);
wrunlock();
@ -2990,7 +2874,7 @@ MySQL_Connection * MySrvConnList::get_random_MyConn(MySQL_Session *sess, bool ff
conn = new MySQL_Connection();
conn->parent=mysrvc;
__sync_fetch_and_add(&MyHGM->status.server_connections_created, 1);
MyHGM->status.p_server_connections_created->Increment();
MyHGM->status.p_counter_array[p_hg_counter::server_connections_created]->Increment();
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 7, "Returning MySQL Connection %p, server %s:%d\n", conn, conn->parent->address, conn->parent->port);
} else {
// we may consider creating a new connection
@ -3000,7 +2884,7 @@ MySQL_Connection * MySrvConnList::get_random_MyConn(MySQL_Session *sess, bool ff
conn = new MySQL_Connection();
conn->parent=mysrvc;
__sync_fetch_and_add(&MyHGM->status.server_connections_created, 1);
MyHGM->status.p_server_connections_created->Increment();
MyHGM->status.p_counter_array[p_hg_counter::server_connections_created]->Increment();
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 7, "Returning MySQL Connection %p, server %s:%d\n", conn, conn->parent->address, conn->parent->port);
} else {
conn=(MySQL_Connection *)conns->remove_index_fast(i);
@ -3023,13 +2907,13 @@ MySQL_Connection * MySrvConnList::get_random_MyConn(MySQL_Session *sess, bool ff
_myhgc->new_connections_now++;
if (_myhgc->new_connections_now > (unsigned int) mysql_thread___throttle_connections_per_sec_to_hostgroup) {
__sync_fetch_and_add(&MyHGM->status.server_connections_delayed, 1);
MyHGM->status.p_server_connections_delayed->Increment();
MyHGM->status.p_counter_array[p_hg_counter::server_connections_delayed]->Increment();
return NULL;
} else {
conn = new MySQL_Connection();
conn->parent=mysrvc;
__sync_fetch_and_add(&MyHGM->status.server_connections_created, 1);
MyHGM->status.p_server_connections_created->Increment();
MyHGM->status.p_counter_array[p_hg_counter::server_connections_created]->Increment();
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 7, "Returning MySQL Connection %p, server %s:%d\n", conn, conn->parent->address, conn->parent->port);
return conn;
}
@ -3426,17 +3310,13 @@ void MySQL_HostGroups_Manager::p_update_connection_pool() {
const auto& cur_val { recv_counter_id->second->Value() };
recv_counter_id->second->Increment(mysrvc->bytes_recv - cur_val);
} else {
const std::string name { "proxysql_connection_pool_bytes_data_recv" };
auto& conn_pool_bytes_data_recv {
prometheus::BuildCounter()
.Name(name)
.Help("The amount of data received from the backend, excluding metadata.")
.Register(*GloVars.prometheus_registry)
this->status.p_dyn_counter_array[p_hg_dyn_counter::conn_pool_bytes_data_recv]
};
this->status.p_conn_pool_bytes_data_recv_map.insert(
{
endpoint_id,
std::addressof(conn_pool_bytes_data_recv.Add({
std::addressof(conn_pool_bytes_data_recv->Add({
{"endpoint", endpoint_addr + ":" + endpoint_port},
{"hostgroup", hostgroup_id }
}))
@ -3450,17 +3330,13 @@ void MySQL_HostGroups_Manager::p_update_connection_pool() {
const auto& cur_val { sent_counter_id->second->Value() };
sent_counter_id->second->Increment(mysrvc->bytes_sent - cur_val);
} else {
const std::string name { "proxysql_connection_pool_bytes_data_sent" };
auto& conn_pool_bytes_data_recv {
prometheus::BuildCounter()
.Name(name)
.Help("The amount of data sent to the backend, excluding metadata.")
.Register(*GloVars.prometheus_registry)
auto& conn_pool_bytes_data_sent {
this->status.p_dyn_counter_array[p_hg_dyn_counter::conn_pool_bytes_data_sent]
};
this->status.p_conn_pool_bytes_data_sent_map.insert(
{
endpoint_id,
std::addressof(conn_pool_bytes_data_recv.Add({
std::addressof(conn_pool_bytes_data_sent->Add({
{"endpoint", endpoint_addr + ":" + endpoint_port},
{"hostgroup", hostgroup_id }
}))
@ -3474,17 +3350,13 @@ void MySQL_HostGroups_Manager::p_update_connection_pool() {
const auto& cur_val { con_err_counter_id->second->Value() };
con_err_counter_id->second->Increment(mysrvc->connect_ERR - cur_val);
} else {
const std::string name { "proxysql_connection_pool_conn_err" };
auto& connection_pool_conn_err {
prometheus::BuildCounter()
.Name(name)
.Help("How many connections weren't established successfully.")
.Register(*GloVars.prometheus_registry)
this->status.p_dyn_counter_array[p_hg_dyn_counter::connection_pool_conn_err]
};
this->status.p_connection_pool_conn_err_map.insert(
{
endpoint_id,
std::addressof(connection_pool_conn_err.Add({
std::addressof(connection_pool_conn_err->Add({
{"endpoint", endpoint_addr + ":" + endpoint_port},
{"hostgroup", hostgroup_id }
}))
@ -3497,17 +3369,13 @@ void MySQL_HostGroups_Manager::p_update_connection_pool() {
if (con_free_counter_id != this->status.p_connection_pool_conn_free_map.end()) {
con_free_counter_id->second->Set(mysrvc->ConnectionsFree->conns_length());
} else {
const std::string name { "proxysql_connection_pool_conn_free" };
auto& connection_pool_conn_free {
prometheus::BuildGauge()
.Name(name)
.Help("How many connections are currently free.")
.Register(*GloVars.prometheus_registry)
this->status.p_dyn_gauge_array[p_hg_dyn_gauge::connection_pool_conn_free]
};
this->status.p_connection_pool_conn_free_map.insert(
{
endpoint_id,
std::addressof(connection_pool_conn_free.Add({
std::addressof(connection_pool_conn_free->Add({
{"endpoint", endpoint_addr + ":" + endpoint_port},
{"hostgroup", hostgroup_id }
}))
@ -3521,16 +3389,13 @@ void MySQL_HostGroups_Manager::p_update_connection_pool() {
const auto& cur_val { conn_pool_conn_ok->second->Value() };
conn_pool_conn_ok->second->Increment(mysrvc->connect_OK - cur_val);
} else {
const std::string name { "proxysql_connection_pool_conn_ok" };
auto& connection_pool_conn_ok {
prometheus::BuildCounter()
.Name(name)
.Register(*GloVars.prometheus_registry)
this->status.p_dyn_counter_array[p_hg_dyn_counter::connection_pool_conn_ok]
};
this->status.p_connection_pool_conn_ok_map.insert(
{
endpoint_id,
std::addressof(connection_pool_conn_ok.Add({
std::addressof(connection_pool_conn_ok->Add({
{"endpoint", endpoint_addr + ":" + endpoint_port},
{"hostgroup", hostgroup_id }
}))
@ -3543,16 +3408,13 @@ void MySQL_HostGroups_Manager::p_update_connection_pool() {
if (conn_pool_conn_used != this->status.p_connection_pool_conn_used_map.end()) {
conn_pool_conn_used->second->Set(mysrvc->ConnectionsUsed->conns_length());
} else {
const std::string name { "proxysql_connection_pool_conn_used" };
auto& connection_pool_conn_used {
prometheus::BuildGauge()
.Name(name)
.Register(*GloVars.prometheus_registry)
this->status.p_dyn_gauge_array[p_hg_dyn_gauge::connection_pool_conn_used]
};
this->status.p_connection_pool_conn_used_map.insert(
{
endpoint_id,
std::addressof(connection_pool_conn_used.Add({
std::addressof(connection_pool_conn_used->Add({
{"endpoint", endpoint_addr + ":" + endpoint_port},
{"hostgroup", hostgroup_id }
}))
@ -3565,17 +3427,13 @@ void MySQL_HostGroups_Manager::p_update_connection_pool() {
if (conn_pool_conn_latency_us != this->status.p_connection_pool_latency_us_map.end()) {
conn_pool_conn_latency_us->second->Set(mysrvc->current_latency_us);
} else {
const std::string name { "proxysql_connection_pool_conn_latency_us" };
auto& connection_pool_conn_latency_us {
prometheus::BuildGauge()
.Name(name)
.Help("The currently ping time in microseconds, as reported from Monitor.")
.Register(*GloVars.prometheus_registry)
this->status.p_dyn_gauge_array[p_hg_dyn_gauge::connection_pool_latency_us]
};
this->status.p_connection_pool_latency_us_map.insert(
{
endpoint_id,
std::addressof(connection_pool_conn_latency_us.Add({
std::addressof(connection_pool_conn_latency_us->Add({
{"endpoint", endpoint_addr + ":" + endpoint_port},
{"hostgroup", hostgroup_id }
}))
@ -3589,17 +3447,13 @@ void MySQL_HostGroups_Manager::p_update_connection_pool() {
const auto& cur_val { conn_pool_conn_queries->second->Value() };
conn_pool_conn_queries->second->Increment(mysrvc->queries_sent - cur_val);
} else {
const std::string name { "proxysql_connection_pool_conn_queries" };
auto& connection_pool_conn_queries {
prometheus::BuildCounter()
.Name(name)
.Help("The number of queries routed towards this particular backend server.")
.Register(*GloVars.prometheus_registry)
this->status.p_dyn_counter_array[p_hg_dyn_counter::connection_pool_conn_ok]
};
this->status.p_connection_pool_queries_map.insert(
{
endpoint_id,
std::addressof(connection_pool_conn_queries.Add({
std::addressof(connection_pool_conn_queries->Add({
{"endpoint", endpoint_addr + ":" + endpoint_port},
{"hostgroup", hostgroup_id }
}))
@ -3612,17 +3466,13 @@ void MySQL_HostGroups_Manager::p_update_connection_pool() {
if (conn_pool_conn_status != this->status.p_connection_pool_status_map.end()) {
conn_pool_conn_status->second->Set(mysrvc->status + 1);
} else {
const std::string name { "proxysql_connection_pool_conn_status" };
auto& connection_pool_conn_status {
prometheus::BuildGauge()
.Name(name)
.Help("The status of the backend server (1 - ONLINE, 2 - SHUNNED, 3 - OFFLINE_SOFT, 4 - OFFLINE_HARD).")
.Register(*GloVars.prometheus_registry)
this->status.p_dyn_gauge_array[p_hg_dyn_gauge::connection_pool_status]
};
this->status.p_connection_pool_status_map.insert(
{
endpoint_id,
std::addressof(connection_pool_conn_status.Add({
std::addressof(connection_pool_conn_status->Add({
{"endpoint", endpoint_addr + ":" + endpoint_port},
{"hostgroup", hostgroup_id }
}))
@ -4143,20 +3993,30 @@ void MySQL_HostGroups_Manager::set_server_current_latency_us(char *hostname, int
}
void MySQL_HostGroups_Manager::p_update_myconnpoll() {
const auto& cur_myconnpoll_get { this->status.p_myconnpoll_get->Value() };
this->status.p_myconnpoll_get->Increment(status.myconnpoll_get - cur_myconnpoll_get);
const auto& cur_myconnpoll_get {
this->status.p_counter_array[p_hg_counter::myhgm_myconnpoll_get]->Value()
};
this->status.p_counter_array[p_hg_counter::myhgm_myconnpoll_get]->Increment(status.myconnpoll_get - cur_myconnpoll_get);
const auto& cur_myconnpoll_get_ok { this->status.p_myconnpoll_get_ok->Value() };
this->status.p_myconnpoll_get_ok->Increment(status.myconnpoll_get_ok - cur_myconnpoll_get_ok);
const auto& cur_myconnpoll_get_ok {
this->status.p_counter_array[p_hg_counter::myhgm_myconnpoll_get_ok]->Value()
};
this->status.p_counter_array[p_hg_counter::myhgm_myconnpoll_get_ok]->Increment(status.myconnpoll_get_ok - cur_myconnpoll_get_ok);
const auto& cur_myconnpoll_push { this->status.p_myconnpoll_push->Value() };
this->status.p_myconnpoll_push->Increment(status.myconnpoll_push - cur_myconnpoll_push);
const auto& cur_myconnpoll_push {
this->status.p_counter_array[p_hg_counter::myhgm_myconnpoll_push]->Value()
};
this->status.p_counter_array[p_hg_counter::myhgm_myconnpoll_push]->Increment(status.myconnpoll_push - cur_myconnpoll_push);
const auto& cur_myconnpoll_reset { this->status.p_myconnpoll_reset->Value() };
this->status.p_myconnpoll_reset->Increment(status.myconnpoll_reset - cur_myconnpoll_reset);
const auto& cur_myconnpoll_reset {
this->status.p_counter_array[p_hg_counter::myhgm_myconnpoll_reset]->Value()
};
this->status.p_counter_array[p_hg_counter::myhgm_myconnpoll_reset]->Increment(status.myconnpoll_reset - cur_myconnpoll_reset);
const auto& cur_myconnpoll_destroy { this->status.p_myconnpoll_destroy->Value() };
this->status.p_myconnpoll_destroy->Increment(status.myconnpoll_destroy - cur_myconnpoll_destroy);
const auto& cur_myconnpoll_destroy {
this->status.p_counter_array[p_hg_counter::myhgm_myconnpoll_destroy]->Value()
};
this->status.p_counter_array[p_hg_counter::myhgm_myconnpoll_destroy]->Increment(status.myconnpoll_destroy - cur_myconnpoll_destroy);
}
SQLite3_result * MySQL_HostGroups_Manager::SQL3_Get_ConnPool_Stats() {
@ -5457,13 +5317,10 @@ void MySQL_HostGroups_Manager::p_update_mysql_gtid_executed() {
if (gitd_id_counter == this->status.p_gtid_executed_map.end()) {
auto& gitd_counter {
prometheus::BuildCounter()
.Name("proxysql_gtid_executed")
.Help("Tracks the number of executed gtid per host and port.")
.Register(*GloVars.prometheus_registry)
this->status.p_dyn_counter_array[p_hg_dyn_counter::gtid_executed]
};
gtid_counter = std::addressof(gitd_counter.Add({
gtid_counter = std::addressof(gitd_counter->Add({
{ "hostname", address },
{ "port", port },
}));

@ -170,14 +170,14 @@ MySQL_STMT_Global_info::MySQL_STMT_Global_info(uint64_t id, unsigned int h,
p += ql - 11;
if (strncasecmp(p, " FOR UPDATE", 11) == 0) { // is a SELECT FOR UPDATE
__sync_fetch_and_add(&MyHGM->status.select_for_update_or_equivalent, 1);
MyHGM->status.p_select_for_update_or_equivalent->Increment();
MyHGM->status.p_counter_array[p_hg_counter::selects_for_update__autocommit0]->Increment();
goto __exit_MySQL_STMT_Global_info___search_select;
}
p = q;
p += ql-10;
if (strncasecmp(p, " FOR SHARE", 10) == 0) { // is a SELECT FOR SHARE
__sync_fetch_and_add(&MyHGM->status.select_for_update_or_equivalent, 1);
MyHGM->status.p_select_for_update_or_equivalent->Increment();
MyHGM->status.p_counter_array[p_hg_counter::selects_for_update__autocommit0]->Increment();
goto __exit_MySQL_STMT_Global_info___search_select;
}
if (ql >= 25) {
@ -185,7 +185,7 @@ MySQL_STMT_Global_info::MySQL_STMT_Global_info(uint64_t id, unsigned int h,
p += ql-19;
if (strncasecmp(p, " LOCK IN SHARE MODE", 19) == 0) { // is a SELECT LOCK IN SHARE MODE
__sync_fetch_and_add(&MyHGM->status.select_for_update_or_equivalent, 1);
MyHGM->status.p_select_for_update_or_equivalent->Increment();
MyHGM->status.p_counter_array[p_hg_counter::selects_for_update__autocommit0]->Increment();
goto __exit_MySQL_STMT_Global_info___search_select;
}
p = q;
@ -193,7 +193,7 @@ MySQL_STMT_Global_info::MySQL_STMT_Global_info(uint64_t id, unsigned int h,
if (strncasecmp(p," NOWAIT",7)==0) {
// let simplify. If NOWAIT is used, we assume FOR UPDATE|SHARE is used
__sync_fetch_and_add(&MyHGM->status.select_for_update_or_equivalent, 1);
MyHGM->status.p_select_for_update_or_equivalent->Increment();
MyHGM->status.p_counter_array[p_hg_counter::selects_for_update__autocommit0]->Increment();
goto __exit_MySQL_STMT_Global_info___search_select;
/*
if (strcasestr(q," FOR UPDATE ")) {
@ -211,7 +211,7 @@ MySQL_STMT_Global_info::MySQL_STMT_Global_info(uint64_t id, unsigned int h,
if (strncasecmp(p," SKIP LOCKED",12)==0) {
// let simplify. If SKIP LOCKED is used, we assume FOR UPDATE|SHARE is used
__sync_fetch_and_add(&MyHGM->status.select_for_update_or_equivalent, 1);
MyHGM->status.p_select_for_update_or_equivalent->Increment();
MyHGM->status.p_counter_array[p_hg_counter::selects_for_update__autocommit0]->Increment();
goto __exit_MySQL_STMT_Global_info___search_select;
/*
if (strcasestr(q," FOR UPDATE ")==NULL) {
@ -237,12 +237,12 @@ MySQL_STMT_Global_info::MySQL_STMT_Global_info(uint64_t id, unsigned int h,
if (strcasestr(buf," FOR ")) {
if (strcasestr(buf," FOR UPDATE ")) {
__sync_fetch_and_add(&MyHGM->status.select_for_update_or_equivalent, 1);
MyHGM->status.p_select_for_update_or_equivalent->Increment();
MyHGM->status.p_counter_array[p_hg_counter::selects_for_update__autocommit0]->Increment();
goto __exit_MySQL_STMT_Global_info___search_select;
}
if (strcasestr(buf," FOR SHARE ")) {
__sync_fetch_and_add(&MyHGM->status.select_for_update_or_equivalent, 1);
MyHGM->status.p_select_for_update_or_equivalent->Increment();
MyHGM->status.p_counter_array[p_hg_counter::selects_for_update__autocommit0]->Increment();
goto __exit_MySQL_STMT_Global_info___search_select;
}
}

@ -1,3 +1,4 @@
#include "MySQL_HostGroups_Manager.h"
#include "proxysql.h"
#include "cpp.h"
#include "re2/re2.h"
@ -327,14 +328,14 @@ bool Query_Info::is_select_NOT_for_update() {
p+=ql-11;
if (strncasecmp(p," FOR UPDATE",11)==0) {
__sync_fetch_and_add(&MyHGM->status.select_for_update_or_equivalent, 1);
MyHGM->status.p_select_for_update_or_equivalent->Increment();
MyHGM->status.p_counter_array[p_hg_counter::selects_for_update__autocommit0]->Increment();
return false;
}
p=QP;
p+=ql-10;
if (strncasecmp(p," FOR SHARE",10)==0) {
__sync_fetch_and_add(&MyHGM->status.select_for_update_or_equivalent, 1);
MyHGM->status.p_select_for_update_or_equivalent->Increment();
MyHGM->status.p_counter_array[p_hg_counter::selects_for_update__autocommit0]->Increment();
return false;
}
if (ql>=25) {
@ -342,7 +343,7 @@ bool Query_Info::is_select_NOT_for_update() {
p+=ql-19;
if (strncasecmp(p," LOCK IN SHARE MODE",19)==0) {
__sync_fetch_and_add(&MyHGM->status.select_for_update_or_equivalent, 1);
MyHGM->status.p_select_for_update_or_equivalent->Increment();
MyHGM->status.p_counter_array[p_hg_counter::selects_for_update__autocommit0]->Increment();
return false;
}
p=QP;
@ -350,7 +351,7 @@ bool Query_Info::is_select_NOT_for_update() {
if (strncasecmp(p," NOWAIT",7)==0) {
// let simplify. If NOWAIT is used, we assume FOR UPDATE|SHARE is used
__sync_fetch_and_add(&MyHGM->status.select_for_update_or_equivalent, 1);
MyHGM->status.p_select_for_update_or_equivalent->Increment();
MyHGM->status.p_counter_array[p_hg_counter::selects_for_update__autocommit0]->Increment();
return false;
/*
if (strcasestr(QP," FOR UPDATE ")==NULL) {
@ -368,7 +369,7 @@ bool Query_Info::is_select_NOT_for_update() {
if (strncasecmp(p," SKIP LOCKED",12)==0) {
// let simplify. If SKIP LOCKED is used, we assume FOR UPDATE|SHARE is used
__sync_fetch_and_add(&MyHGM->status.select_for_update_or_equivalent, 1);
MyHGM->status.p_select_for_update_or_equivalent->Increment();
MyHGM->status.p_counter_array[p_hg_counter::selects_for_update__autocommit0]->Increment();
return false;
/*
if (strcasestr(QP," FOR UPDATE ")) {
@ -394,12 +395,12 @@ bool Query_Info::is_select_NOT_for_update() {
if (strcasestr(buf," FOR ")) {
if (strcasestr(buf," FOR UPDATE ")) {
__sync_fetch_and_add(&MyHGM->status.select_for_update_or_equivalent, 1);
MyHGM->status.p_select_for_update_or_equivalent->Increment();
MyHGM->status.p_counter_array[p_hg_counter::selects_for_update__autocommit0]->Increment();
return false;
}
if (strcasestr(buf," FOR SHARE ")) {
__sync_fetch_and_add(&MyHGM->status.select_for_update_or_equivalent, 1);
MyHGM->status.p_select_for_update_or_equivalent->Increment();
MyHGM->status.p_counter_array[p_hg_counter::selects_for_update__autocommit0]->Increment();
return false;
}
}
@ -574,7 +575,7 @@ MySQL_Session::~MySQL_Session() {
delete command_counters;
if (session_type==PROXYSQL_SESSION_MYSQL && connections_handler==false && mirror==false) {
__sync_fetch_and_sub(&MyHGM->status.client_connections,1);
MyHGM->status.p_client_connections->Decrement();
MyHGM->status.p_gauge_array[p_hg_gauge::client_connections_connected]->Decrement();
}
assert(qpo);
delete qpo;
@ -742,14 +743,14 @@ bool MySQL_Session::handler_CommitRollback(PtrSize_t *pkt) {
if (c=='c' || c=='C') {
if (strncasecmp((char *)"commit",(char *)pkt->ptr+5,6)==0) {
__sync_fetch_and_add(&MyHGM->status.commit_cnt, 1);
MyHGM->status.p_commit_cnt->Increment();
MyHGM->status.p_counter_array[p_hg_counter::com_commit_cnt]->Increment();
ret=true;
}
} else {
if (c=='r' || c=='R') {
if ( strncasecmp((char *)"rollback",(char *)pkt->ptr+5,8)==0 ) {
__sync_fetch_and_add(&MyHGM->status.rollback_cnt, 1);
MyHGM->status.p_rollback_cnt->Increment();
MyHGM->status.p_counter_array[p_hg_counter::com_rollback]->Increment();
ret=true;
}
}
@ -776,10 +777,10 @@ bool MySQL_Session::handler_CommitRollback(PtrSize_t *pkt) {
l_free(pkt->size,pkt->ptr);
if (c=='c' || c=='C') {
__sync_fetch_and_add(&MyHGM->status.commit_cnt_filtered, 1);
MyHGM->status.p_commit_cnt_filtered->Increment();
MyHGM->status.p_counter_array[p_hg_counter::com_commit_cnt_filtered]->Increment();
} else {
__sync_fetch_and_add(&MyHGM->status.rollback_cnt_filtered, 1);
MyHGM->status.p_rollback_cnt_filtered->Increment();
MyHGM->status.p_counter_array[p_hg_counter::com_rollback_filtered]->Increment();
}
return true;
}
@ -872,7 +873,7 @@ bool MySQL_Session::handler_SetAutocommit(PtrSize_t *pkt) {
proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 5, "Setting autocommit to = %d\n", fd);
#endif
__sync_fetch_and_add(&MyHGM->status.autocommit_cnt, 1);
MyHGM->status.p_autocommit_cnt->Increment();
MyHGM->status.p_counter_array[p_hg_counter::com_autocommit]->Increment();
// we immediately process the number of transactions
unsigned int nTrx=NumActiveTransactions();
if (fd==1 && autocommit==true) {
@ -917,7 +918,7 @@ __ret_autocommit_OK:
}
l_free(pkt->size,pkt->ptr);
__sync_fetch_and_add(&MyHGM->status.autocommit_cnt_filtered, 1);
MyHGM->status.p_autocommit_cnt_filtered->Increment();
MyHGM->status.p_counter_array[p_hg_counter::com_autocommit_filtered]->Increment();
free(_new_pkt.ptr);
return true;
}
@ -1318,7 +1319,7 @@ bool MySQL_Session::handler_special_queries(PtrSize_t *pkt) {
}
l_free(pkt->size,pkt->ptr);
__sync_fetch_and_add(&MyHGM->status.frontend_set_names, 1);
MyHGM->status.p_frontend_set_names->Increment();
MyHGM->status.p_counter_array[p_hg_counter::com_frontend_set_names]->Increment();
return true;
}
}
@ -1502,7 +1503,7 @@ int MySQL_Session::handler_again___status_RESETTING_CONNECTION() {
int rc=myconn->async_change_user(myds->revents);
if (rc==0) {
__sync_fetch_and_add(&MyHGM->status.backend_change_user, 1);
MyHGM->status.p_backend_change_user->Increment();
MyHGM->status.p_counter_array[p_hg_counter::com_backend_change_user]->Increment();
//myds->myconn->userinfo->set(client_myds->myconn->userinfo);
myds->myconn->reset();
myconn->async_state_machine=ASYNC_IDLE;
@ -2356,7 +2357,7 @@ bool MySQL_Session::handler_again___status_CHANGING_SCHEMA(int *_rc) {
int rc=myconn->async_select_db(myds->revents);
if (rc==0) {
__sync_fetch_and_add(&MyHGM->status.backend_init_db, 1);
MyHGM->status.p_backend_init_db->Increment();
MyHGM->status.p_counter_array[p_hg_counter::com_backend_init_db]->Increment();
myds->myconn->userinfo->set(client_myds->myconn->userinfo);
myds->DSS = STATE_MARIADB_GENERIC;
st=previous_status.top();
@ -2578,7 +2579,7 @@ bool MySQL_Session::handler_again___status_CHANGING_USER_SERVER(int *_rc) {
int rc=myconn->async_change_user(myds->revents);
if (rc==0) {
__sync_fetch_and_add(&MyHGM->status.backend_change_user, 1);
MyHGM->status.p_backend_change_user->Increment();
MyHGM->status.p_counter_array[p_hg_counter::com_backend_change_user]->Increment();
myds->myconn->userinfo->set(client_myds->myconn->userinfo);
myds->myconn->reset();
st=previous_status.top();
@ -4279,7 +4280,7 @@ void MySQL_Session::handler___status_CHANGING_USER_CLIENT___STATE_CLIENT_HANDSHA
GloMyLogger->log_audit_entry(PROXYSQL_MYSQL_CHANGE_USER_ERR, this, NULL);
free(_s);
__sync_fetch_and_add(&MyHGM->status.access_denied_wrong_password, 1);
MyHGM->status.p_access_denied_wrong_password->Increment();
MyHGM->status.p_counter_array[p_hg_counter::access_denied_wrong_password]->Increment();
}
}
@ -4434,10 +4435,10 @@ void MySQL_Session::handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE(
proxy_warning("mysql-max_connections reached. Returning 'Too many connections'\n");
GloMyLogger->log_audit_entry(PROXYSQL_MYSQL_AUTH_ERR, this, NULL, (char *)"mysql-max_connections reached");
__sync_fetch_and_add(&MyHGM->status.access_denied_max_connections, 1);
MyHGM->status.p_access_denied_max_connections->Increment();
MyHGM->status.p_counter_array[p_hg_counter::access_denied_max_connections]->Increment();
} else { // see issue #794
__sync_fetch_and_add(&MyHGM->status.access_denied_max_user_connections, 1);
MyHGM->status.p_access_denied_max_user_connections->Increment();
MyHGM->status.p_counter_array[p_hg_counter::access_denied_max_user_connections]->Increment();
proxy_debug(PROXY_DEBUG_MYSQL_CONNECTION, 5, "Session=%p , DS=%p . User '%s' has exceeded the 'max_user_connections' resource (current value: %d)\n", this, client_myds, client_myds->myconn->userinfo->username, used_users);
char *a=(char *)"User '%s' has exceeded the 'max_user_connections' resource (current value: %d)";
char *b=(char *)malloc(strlen(a)+strlen(client_myds->myconn->userinfo->username)+16);
@ -4448,7 +4449,7 @@ void MySQL_Session::handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE(
free(b);
}
__sync_add_and_fetch(&MyHGM->status.client_connections_aborted,1);
MyHGM->status.p_client_connections_aborted->Increment();
MyHGM->status.p_counter_array[p_hg_counter::client_connections_aborted]->Increment();
client_myds->DSS=STATE_SLEEP;
} else {
if (
@ -4532,10 +4533,10 @@ void MySQL_Session::handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE(
proxy_error("ProxySQL Error: Access denied for user '%s' (using password: %s). SSL is required", client_myds->myconn->userinfo->username, (client_myds->myconn->userinfo->password ? "YES" : "NO"));
proxy_debug(PROXY_DEBUG_MYSQL_CONNECTION,8,"Session=%p , DS=%p . Access denied for user '%s' (using password: %s). SSL is required\n", this, client_myds, client_myds->myconn->userinfo->username, (client_myds->myconn->userinfo->password ? "YES" : "NO"));
__sync_add_and_fetch(&MyHGM->status.client_connections_aborted,1);
MyHGM->status.p_client_connections_aborted->Increment();
MyHGM->status.p_counter_array[p_hg_counter::client_connections_aborted]->Increment();
free(_s);
__sync_fetch_and_add(&MyHGM->status.access_denied_wrong_password, 1);
MyHGM->status.p_access_denied_wrong_password->Increment();
MyHGM->status.p_counter_array[p_hg_counter::access_denied_wrong_password]->Increment();
} else {
// we are good!
//client_myds->myprot.generate_pkt_OK(true,NULL,NULL, (is_encrypted ? 3 : 2), 0,0,0,0,NULL);
@ -4616,11 +4617,11 @@ void MySQL_Session::handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE(
proxy_error("ProxySQL Error: Access denied for user '%s'@'%s' (using password: %s)\n", client_myds->myconn->userinfo->username, client_addr, (client_myds->myconn->userinfo->password ? "YES" : "NO"));
free(_s);
__sync_fetch_and_add(&MyHGM->status.access_denied_wrong_password, 1);
MyHGM->status.p_access_denied_wrong_password->Increment();
MyHGM->status.p_counter_array[p_hg_counter::access_denied_wrong_password]->Increment();
}
GloMyLogger->log_audit_entry(PROXYSQL_MYSQL_AUTH_ERR, this, NULL);
__sync_add_and_fetch(&MyHGM->status.client_connections_aborted,1);
MyHGM->status.p_client_connections_aborted->Increment();
MyHGM->status.p_counter_array[p_hg_counter::client_connections_created]->Increment();
client_myds->DSS=STATE_SLEEP;
}
}
@ -4735,7 +4736,7 @@ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
proxy_debug(PROXY_DEBUG_MYSQL_COM, 5, "Got COM_INIT_DB packet\n");
if (session_type == PROXYSQL_SESSION_MYSQL) {
__sync_fetch_and_add(&MyHGM->status.frontend_init_db, 1);
MyHGM->status.p_frontend_init_db->Increment();
MyHGM->status.p_counter_array[p_hg_counter::com_frontend_init_db]->Increment();
client_myds->myconn->userinfo->set_schemaname((char *)pkt->ptr+sizeof(mysql_hdr)+1,pkt->size-sizeof(mysql_hdr)-1);
l_free(pkt->size,pkt->ptr);
client_myds->setDSS_STATE_QUERY_SENT_NET();
@ -4763,7 +4764,7 @@ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
proxy_debug(PROXY_DEBUG_MYSQL_COM, 5, "Got COM_QUERY with USE dbname\n");
if (session_type == PROXYSQL_SESSION_MYSQL) {
__sync_fetch_and_add(&MyHGM->status.frontend_use_db, 1);
MyHGM->status.p_frontend_use_db->Increment();
MyHGM->status.p_counter_array[p_hg_counter::com_frontend_use_db]->Increment();
char *schemaname=strndup((char *)pkt->ptr+sizeof(mysql_hdr)+5,pkt->size-sizeof(mysql_hdr)-5);
char *schemanameptr=trim_spaces_and_quotes_in_place(schemaname);
/*
@ -5096,7 +5097,7 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
if (__tmp_autocommit >= 0 && autocommit_handled==false) {
int fd = __tmp_autocommit;
__sync_fetch_and_add(&MyHGM->status.autocommit_cnt, 1);
MyHGM->status.p_autocommit_cnt->Increment();
MyHGM->status.p_counter_array[p_hg_counter::com_autocommit]->Increment();
// we immediately process the number of transactions
unsigned int nTrx=NumActiveTransactions();
if (fd==1 && autocommit==true) {
@ -5732,7 +5733,7 @@ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
client_myds->myprot.generate_pkt_ERR(true,NULL,NULL,2,1045,(char *)"28000", _s, true);
free(_s);
__sync_fetch_and_add(&MyHGM->status.access_denied_wrong_password, 1);
MyHGM->status.p_access_denied_wrong_password->Increment();
MyHGM->status.p_counter_array[p_hg_counter::access_denied_wrong_password]->Increment();
}
} else {
//FIXME: send an error message saying "not supported" or disconnect

@ -1,4 +1,5 @@
//#define __CLASS_STANDARD_MYSQL_THREAD_H
#include "MySQL_HostGroups_Manager.h"
#define MYSQL_THREAD_IMPLEMENTATION
#include "proxysql.h"
#include "cpp.h"
@ -5005,8 +5006,8 @@ void MySQL_Thread::listener_handle_new_connection(MySQL_Data_Stream *myds, unsig
sess->max_connections_reached=true;
}
// Update metrics
MyHGM->status.p_client_connections_created->Increment();
MyHGM->status.p_client_connections->Increment();
MyHGM->status.p_counter_array[p_hg_counter::client_connections_created]->Increment();
MyHGM->status.p_gauge_array[p_hg_gauge::client_connections_connected]->Increment();
sess->client_myds->client_addrlen=addrlen;
sess->client_myds->client_addr=addr;

@ -351,7 +351,7 @@ MySQL_Connection::~MySQL_Connection() {
// always decrease the counter
if (ret_mysql) {
__sync_fetch_and_sub(&MyHGM->status.server_connections_connected,1);
MyHGM->status.p_server_connections_connected->Decrement();
MyHGM->status.p_gauge_array[p_hg_gauge::server_connections_connected]->Decrement();
if (query.stmt_result) {
if (query.stmt_result->handle) {
query.stmt_result->handle->status = MYSQL_STATUS_READY; // avoid calling mthd_my_skip_result()
@ -915,7 +915,7 @@ handler_again:
break;
case ASYNC_CONNECT_SUCCESSFUL:
__sync_fetch_and_add(&MyHGM->status.server_connections_connected,1);
MyHGM->status.p_server_connections_connected->Increment();
MyHGM->status.p_gauge_array[p_hg_gauge::server_connections_connected]->Increment();
__sync_fetch_and_add(&parent->connect_OK,1);
options.client_flag = mysql->client_flag;
//assert(mysql->net.vio->async_context);

Loading…
Cancel
Save