From fae283cf7ee4a4fe3e38611182f4891c55d22d64 Mon Sep 17 00:00:00 2001 From: Rahim Kanji Date: Thu, 11 Dec 2025 01:31:32 +0500 Subject: [PATCH] Add SSL and non-SSL connection OK metrics for PostgreSQL monitor connections Adds two new metrics, ssl_connections_OK and non_ssl_connections_OK, to improve visibility into PostgreSQL monitor connection status. --- include/PgSQL_Monitor.hpp | 2 ++ lib/PgSQL_Monitor.cpp | 7 +++++++ lib/PgSQL_Thread.cpp | 12 ++++++++++++ 3 files changed, 21 insertions(+) diff --git a/include/PgSQL_Monitor.hpp b/include/PgSQL_Monitor.hpp index bd5a3b7b7..70b6281db 100644 --- a/include/PgSQL_Monitor.hpp +++ b/include/PgSQL_Monitor.hpp @@ -39,6 +39,8 @@ struct PgSQL_Monitor { uint64_t ping_check_OK { 0 }; uint64_t readonly_check_ERR { 0 }; uint64_t readonly_check_OK { 0 }; + uint64_t ssl_connections_OK { 0 }; + uint64_t non_ssl_connections_OK { 0 }; /////////////////////////////////////////////////////////////////////////// std::vector tables_defs_monitor { diff --git a/lib/PgSQL_Monitor.cpp b/lib/PgSQL_Monitor.cpp index f465cf362..8088abc51 100644 --- a/lib/PgSQL_Monitor.cpp +++ b/lib/PgSQL_Monitor.cpp @@ -637,6 +637,13 @@ pair handle_async_connect_cont(state_t& st, short revent) { case PGRES_POLLING_OK: pgconn.state = ASYNC_ST::ASYNC_CONNECT_END; + // connection successful, update SSL stats + if (PQsslInUse(pgconn.conn)) { + __sync_fetch_and_add(&GloPgMon->ssl_connections_OK, 1); + } else { + __sync_fetch_and_add(&GloPgMon->non_ssl_connections_OK, 1); + } + if (st.task.type == task_type_t::connect) { st.task.end = monotonic_time(); } else if (st.task.type == task_type_t::ping) { diff --git a/lib/PgSQL_Thread.cpp b/lib/PgSQL_Thread.cpp index d1084d557..3e45ce974 100644 --- a/lib/PgSQL_Thread.cpp +++ b/lib/PgSQL_Thread.cpp @@ -4482,6 +4482,18 @@ SQLite3_result* PgSQL_Threads_Handler::SQL3_GlobalStatus(bool _memory) { pta[1] = buf; result->add_row(pta); } + { + pta[0] = (char*)"PgSQL_Monitor_ssl_connections_OK"; + sprintf(buf, "%lu", GloPgMon->ssl_connections_OK); + pta[1] = buf; + result->add_row(pta); + } + { + pta[0] = (char*)"PgSQL_Monitor_non_ssl_connections_OK"; + sprintf(buf, "%lu", GloPgMon->non_ssl_connections_OK); + pta[1] = buf; + result->add_row(pta); + } /* { pta[0] = (char*)"MySQL_Monitor_replication_lag_check_OK";