#ifndef __CLASS_PROXYSQL_ADMIN_H #define __CLASS_PROXYSQL_ADMIN_H #include "prometheus/exposer.h" #include "prometheus/counter.h" #include "prometheus/gauge.h" //#include "query_processor.h" #include "proxy_defines.h" #include "proxysql.h" #include "cpp.h" #include #include #include #include "ProxySQL_RESTAPI_Server.hpp" #include "proxysql_typedefs.h" #define PROCESSLIST_MAX_QUERY_LEN_DEFAULT 2 * 1024 * 1024 // 2 MiB #define PROCESSLIST_MAX_QUERY_LEN_MIN 1 * 1024 // 1 KiB #define PROCESSLIST_MAX_QUERY_LEN_MAX 32 * 1024 * 1024 // 32 MiB typedef struct { uint32_t hash; uint32_t key; } t_symstruct; class ProxySQL_Config; class ProxySQL_Restapi; enum SERVER_TYPE { SERVER_TYPE_MYSQL, SERVER_TYPE_PGSQL }; class Scheduler_Row { public: unsigned int id; bool is_active; unsigned int interval_ms; unsigned long long last; unsigned long long next; char *filename; char **args; char *comment; Scheduler_Row(unsigned int _id, bool _is_active, unsigned int _in, char *_f, char *a1, char *a2, char *a3, char *a4, char *a5, char *_comment); ~Scheduler_Row(); }; class ProxySQL_External_Scheduler { private: unsigned long long next_run; public: unsigned int last_version; unsigned int version; #ifdef PA_PTHREAD_MUTEX pthread_rwlock_t rwlock; #else rwlock_t rwlock; #endif std::vector Scheduler_Rows; ProxySQL_External_Scheduler(); ~ProxySQL_External_Scheduler(); unsigned long long run_once(); void update_table(SQLite3_result *result); }; struct p_admin_counter { enum metric { uptime = 0, jemalloc_allocated, __size }; }; struct p_admin_gauge { enum metric { // memory metrics connpool_memory_bytes = 0, sqlite3_memory_bytes, jemalloc_resident, jemalloc_active, jemalloc_mapped, jemalloc_metadata, jemalloc_retained, query_digest_memory_bytes, auth_memory_bytes, mysql_query_rules_memory_bytes, mysql_firewall_users_table, mysql_firewall_users_config, mysql_firewall_rules_table, mysql_firewall_rules_config, stack_memory_mysql_threads, stack_memory_admin_threads, stack_memory_cluster_threads, prepare_stmt_metadata_memory_bytes, prepare_stmt_backend_memory_bytes, // stmt metrics stmt_client_active_total, stmt_client_active_unique, stmt_server_active_total, stmt_server_active_unique, stmt_max_stmt_id, stmt_cached, fds_in_use, version_info, mysql_listener_paused, pgsql_listener_paused, __size }; }; struct p_admin_dyn_counter { enum metric { __size }; }; struct p_admin_dyn_gauge { enum metric { proxysql_servers_clients_status_last_seen_at = 0, __size }; }; struct admin_metrics_map_idx { enum index { counters = 0, gauges, dyn_counters, dyn_gauges }; }; /** * @brief Holds the retrieved info from the bootstrapping server. * @details Used during ProxySQL_Admin initialization. */ struct bootstrap_info_t { uint32_t server_language; std::string server_version; MYSQL_RES* servers; MYSQL_RES* users; std::string mon_user; std::string mon_pass; bool rand_gen_user; ~bootstrap_info_t(); }; // ProxySQL_Admin shared variables extern int admin__web_verbosity; struct incoming_servers_t { SQLite3_result* incoming_mysql_servers_v2 = NULL; SQLite3_result* incoming_replication_hostgroups = NULL; SQLite3_result* incoming_group_replication_hostgroups = NULL; SQLite3_result* incoming_galera_hostgroups = NULL; SQLite3_result* incoming_aurora_hostgroups = NULL; SQLite3_result* incoming_hostgroup_attributes = NULL; SQLite3_result* incoming_mysql_servers_ssl_params = NULL; SQLite3_result* runtime_mysql_servers = NULL; incoming_servers_t(); incoming_servers_t(SQLite3_result*, SQLite3_result*, SQLite3_result*, SQLite3_result*, SQLite3_result*, SQLite3_result*, SQLite3_result*, SQLite3_result*); }; // Separate structs for runtime mysql server and mysql server v2 to avoid human error struct runtime_mysql_servers_checksum_t { std::string value; time_t epoch; runtime_mysql_servers_checksum_t(); runtime_mysql_servers_checksum_t(const std::string& value, time_t epoch); }; struct mysql_servers_v2_checksum_t { std::string value; time_t epoch; mysql_servers_v2_checksum_t(); mysql_servers_v2_checksum_t(const std::string& value, time_t epoch); }; // struct peer_runtime_mysql_servers_t { SQLite3_result* resultset { nullptr }; runtime_mysql_servers_checksum_t checksum {}; peer_runtime_mysql_servers_t(); peer_runtime_mysql_servers_t(SQLite3_result*, const runtime_mysql_servers_checksum_t&); }; struct peer_mysql_servers_v2_t { SQLite3_result* resultset { nullptr }; mysql_servers_v2_checksum_t checksum {}; peer_mysql_servers_v2_t(); peer_mysql_servers_v2_t(SQLite3_result*, const mysql_servers_v2_checksum_t&); }; struct incoming_pgsql_servers_t { SQLite3_result* incoming_pgsql_servers_v2 = NULL; SQLite3_result* incoming_replication_hostgroups = NULL; SQLite3_result* incoming_hostgroup_attributes = NULL; SQLite3_result* runtime_pgsql_servers = NULL; incoming_pgsql_servers_t(); incoming_pgsql_servers_t(SQLite3_result*, SQLite3_result*, SQLite3_result*, SQLite3_result*); }; // Separate structs for runtime pgsql server and pgsql server v2 to avoid human error struct runtime_pgsql_servers_checksum_t { std::string value; time_t epoch; runtime_pgsql_servers_checksum_t(); runtime_pgsql_servers_checksum_t(const std::string& value, time_t epoch); }; struct pgsql_servers_v2_checksum_t { std::string value; time_t epoch; pgsql_servers_v2_checksum_t(); pgsql_servers_v2_checksum_t(const std::string& value, time_t epoch); }; // struct peer_runtime_pgsql_servers_t { SQLite3_result* resultset{ nullptr }; runtime_pgsql_servers_checksum_t checksum{}; peer_runtime_pgsql_servers_t(); peer_runtime_pgsql_servers_t(SQLite3_result*, const runtime_pgsql_servers_checksum_t&); }; struct peer_pgsql_servers_v2_t { SQLite3_result* resultset{ nullptr }; pgsql_servers_v2_checksum_t checksum{}; peer_pgsql_servers_v2_t(); peer_pgsql_servers_v2_t(SQLite3_result*, const pgsql_servers_v2_checksum_t&); }; struct processlist_config_t { #ifdef IDLE_THREADS bool show_idle_session; #endif int show_extended; int max_query_length; }; class ProxySQL_Admin { private: volatile int main_shutdown; std::vector *tables_defs_admin; std::vector *tables_defs_stats; std::vector *tables_defs_config; pthread_t admin_thr; int main_poll_nfds; struct pollfd *main_poll_fds; int *main_callback_func; bool registered_prometheus_collectable; #ifdef PA_PTHREAD_MUTEX pthread_rwlock_t rwlock; #else rwlock_t rwlock; #endif #ifdef PA_PTHREAD_MUTEX pthread_mutex_t mysql_servers_lock; #else rwlock_t mysql_servers_rwlock; #endif #ifdef PA_PTHREAD_MUTEX pthread_mutex_t pgsql_servers_lock; #else rwlock_t pgsql_servers_rwlock; #endif prometheus::SerialExposer serial_exposer; std::mutex proxysql_servers_mutex; void wrlock(); void wrunlock(); struct { char *admin_credentials; char *stats_credentials; int refresh_interval; char *mysql_ifaces; char *pgsql_ifaces; char *telnet_admin_ifaces; char *telnet_stats_ifaces; bool admin_read_only; // bool hash_passwords; bool vacuum_stats; char * admin_version; char * cluster_username; char * cluster_password; int cluster_check_interval_ms; int cluster_check_status_frequency; int cluster_mysql_query_rules_diffs_before_sync; int cluster_mysql_servers_diffs_before_sync; int cluster_mysql_users_diffs_before_sync; int cluster_proxysql_servers_diffs_before_sync; int cluster_mysql_variables_diffs_before_sync; int cluster_admin_variables_diffs_before_sync; int cluster_ldap_variables_diffs_before_sync; int cluster_mysql_servers_sync_algorithm; bool cluster_mysql_query_rules_save_to_disk; bool cluster_mysql_servers_save_to_disk; bool cluster_mysql_users_save_to_disk; bool cluster_proxysql_servers_save_to_disk; bool cluster_mysql_variables_save_to_disk; bool cluster_admin_variables_save_to_disk; bool cluster_ldap_variables_save_to_disk; int stats_mysql_connection_pool; int stats_mysql_connections; int stats_mysql_query_cache; int stats_mysql_query_digest_to_disk; int stats_mysql_eventslog_sync_buffer_to_disk; int stats_system_cpu; int stats_system_memory; bool restapi_enabled; bool restapi_enabled_old; int restapi_port; int restapi_port_old; bool web_enabled; bool web_enabled_old; int web_verbosity; int web_port; int web_port_old; int p_memory_metrics_interval; #ifdef DEBUG bool debug; #endif /* DEBUG */ int coredump_generation_interval_ms; int coredump_generation_threshold; /** * @brief Path to the SSL/TLS key log file for decrypting traffic * * When set, ProxySQL writes TLS secrets to this file in NSS Key Log Format. * This allows tools like Wireshark to decrypt SSL/TLS traffic for debugging. * * Format: "