From eab412546b56eb19e1f7364524107319356464cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Thu, 9 Apr 2020 17:18:33 +0200 Subject: [PATCH] Changed previous metrics definitions and added updating --- include/MySQL_Monitor.hpp | 3 +- lib/MySQL_Monitor.cpp | 125 ++++++++++++++++++++++++++++++++------ 2 files changed, 109 insertions(+), 19 deletions(-) diff --git a/include/MySQL_Monitor.hpp b/include/MySQL_Monitor.hpp index 9bc6f5af0..79b1b0531 100644 --- a/include/MySQL_Monitor.hpp +++ b/include/MySQL_Monitor.hpp @@ -1,6 +1,6 @@ #ifndef __CLASS_MYSQL_MONITOR_H #define __CLASS_MYSQL_MONITOR_H -#include "prometheus/gauge.h" + #include "proxysql.h" #include "cpp.h" #include "thread.h" @@ -272,6 +272,7 @@ class MySQL_Monitor { prometheus::Counter* p_replication_lag_check_OK { nullptr }; prometheus::Counter* p_replication_lag_check_ERR { nullptr }; } metrics; + void p_update_metrics(); std::unique_ptr> queue; MySQL_Monitor_Connection_Pool *My_Conn_Pool; bool shutdown; diff --git a/lib/MySQL_Monitor.cpp b/lib/MySQL_Monitor.cpp index 0d5b02567..3d7924cd2 100644 --- a/lib/MySQL_Monitor.cpp +++ b/lib/MySQL_Monitor.cpp @@ -10,6 +10,8 @@ #include #include #include +#include +#include "MySQL_Monitor.hpp" #include "proxysql.h" #include "cpp.h" @@ -609,37 +611,96 @@ MySQL_Monitor::MySQL_Monitor() { } */ - // Create and register prometheus metrics families - auto& new_gauge_family { + // Initialize prometheus metrics + auto& mysql_monitor_workers { prometheus::BuildGauge() - .Name("MySQL_Monitor_Gauges") + .Name("proxysql_mysql_monitor_workers") .Register(*GloVars.prometheus_registry) }; - auto& new_counter_family { - prometheus::BuildCounter() - .Name("MySQL_Monitor_Counters") + this->metrics.p_num_threads = + std::addressof(mysql_monitor_workers.Add({})); + + auto& mysql_monitor_workers_aux { + prometheus::BuildGauge() + .Name("proxysql_mysql_monitor_workers_aux") .Register(*GloVars.prometheus_registry) }; - - // Initialize prometheus metrics - this->metrics.p_num_threads = - std::addressof(new_gauge_family.Add({{ "id", "MySQL_Monitor_Workers" }})); this->metrics.p_aux_threads = - std::addressof(new_gauge_family.Add({{ "id", "MySQL_Monitor_Workers_Aux" }})); + std::addressof(mysql_monitor_workers_aux.Add({})); + + auto& mysql_monitor_workers_started { + prometheus::BuildCounter() + .Name("proxysql_mysql_monitor_workers_started") + .Register(*GloVars.prometheus_registry) + }; this->metrics.p_started_threads = - std::addressof(new_counter_family.Add({{ "id", "MySQL_Monitor_Workers_Started" }})); + std::addressof(mysql_monitor_workers_started.Add({})); + + // TODO: Check unit + auto& mysql_monitor_connect_check_ok { + prometheus::BuildCounter() + .Name("proxysql_mysql_monitor_connect_check_ok") + .Register(*GloVars.prometheus_registry) + }; this->metrics.p_connect_check_OK = - std::addressof(new_counter_family.Add({{ "id", "MySQL_Monitor_connect_check_OK" }})); + std::addressof(mysql_monitor_connect_check_ok.Add({})); + + auto& mysql_monitor_connect_check_err { + prometheus::BuildCounter() + .Name("proxysql_mysql_monitor_connect_check_err") + .Register(*GloVars.prometheus_registry) + }; this->metrics.p_connect_check_ERR = - std::addressof(new_counter_family.Add({{ "id", "MySQL_Monitor_connect_check_ERR" }})); + std::addressof(mysql_monitor_connect_check_err.Add({})); + + auto& mysql_monitor_ping_check_ok { + prometheus::BuildCounter() + .Name("proxysql_mysql_monitor_ping_check_ok") + .Register(*GloVars.prometheus_registry) + }; this->metrics.p_ping_check_OK = - std::addressof(new_counter_family.Add({{ "id", "MySQL_Monitor_ping_check_OK" }})); + std::addressof(mysql_monitor_ping_check_ok.Add({})); + + auto& mysql_monitor_ping_check_err { + prometheus::BuildCounter() + .Name("proxysql_mysql_monitor_ping_check_err") + .Register(*GloVars.prometheus_registry) + }; this->metrics.p_ping_check_ERR = - std::addressof(new_counter_family.Add({{ "id", "MySQL_Monitor_ping_check_ERR" }})); + std::addressof(mysql_monitor_ping_check_err.Add({})); + + auto& mysql_monitor_read_only_check_ok { + prometheus::BuildCounter() + .Name("proxysql_mysql_monitor_read_only_check_ok") + .Register(*GloVars.prometheus_registry) + }; + this->metrics.p_read_only_check_OK = + std::addressof(mysql_monitor_read_only_check_ok.Add({})); + + auto& mysql_monitor_read_only_check_err { + prometheus::BuildCounter() + .Name("proxysql_mysql_monitor_read_only_check_err") + .Register(*GloVars.prometheus_registry) + }; + this->metrics.p_read_only_check_ERR = + std::addressof(mysql_monitor_read_only_check_err.Add({})); + + auto& mysql_monitor_replication_lag_check_ok { + prometheus::BuildCounter() + .Name("proxysql_mysql_monitor_replication_lag_check_ok") + .Register(*GloVars.prometheus_registry) + }; this->metrics.p_replication_lag_check_OK = - std::addressof(new_counter_family.Add({{ "id", "MySQL_Monitor_read_only_check_OK" }})); + std::addressof(mysql_monitor_replication_lag_check_ok.Add({})); + + auto& mysql_monitor_replication_lag_check_err { + prometheus::BuildCounter() + .Name("proxysql_mysql_monitor_replication_lag_check_err") + .Register(*GloVars.prometheus_registry) + }; this->metrics.p_replication_lag_check_ERR = - std::addressof(new_counter_family.Add({{ "id", "MySQL_Monitor_read_only_check_ERR" }})); + std::addressof(mysql_monitor_replication_lag_check_err.Add({})); + }; MySQL_Monitor::~MySQL_Monitor() { @@ -669,6 +730,34 @@ MySQL_Monitor::~MySQL_Monitor() { AWS_Aurora_Hosts_Map.clear(); }; +void MySQL_Monitor::p_update_metrics() { + if (GloMyMon) { + this->metrics.p_num_threads->Set(GloMyMon->num_threads); + this->metrics.p_aux_threads->Set(GloMyMon->aux_threads); + const auto& cur_started_threads { this->metrics.p_started_threads->Value() }; + this->metrics.p_started_threads->Increment(GloMyMon->started_threads - cur_started_threads); + + const auto& cur_connect_ok { this->metrics.p_connect_check_OK->Value() }; + this->metrics.p_connect_check_OK->Increment(GloMyMon->connect_check_OK - cur_connect_ok); + const auto& cur_connect_err { this->metrics.p_connect_check_ERR->Value() }; + this->metrics.p_connect_check_ERR->Increment(GloMyMon->connect_check_ERR - cur_connect_err); + + const auto& cur_ping_check_ok { this->metrics.p_ping_check_OK->Value() }; + this->metrics.p_ping_check_OK->Increment(GloMyMon->ping_check_OK - cur_ping_check_ok); + const auto& cur_ping_check_err { this->metrics.p_ping_check_ERR->Value() }; + this->metrics.p_ping_check_ERR->Increment(GloMyMon->ping_check_ERR - cur_ping_check_err); + + const auto& cur_read_only_check_ok { this->metrics.p_read_only_check_OK->Value() }; + this->metrics.p_read_only_check_OK->Increment(GloMyMon->read_only_check_OK - cur_read_only_check_ok); + const auto& cur_read_only_check_err { this->metrics.p_read_only_check_ERR->Value() }; + this->metrics.p_read_only_check_ERR->Increment(GloMyMon->read_only_check_ERR - cur_read_only_check_err); + + const auto& cur_replication_lag_check_ok { this->metrics.p_replication_lag_check_OK->Value() }; + this->metrics.p_replication_lag_check_OK->Increment(GloMyMon->replication_lag_check_OK - cur_replication_lag_check_ok); + const auto& cur_replication_lag_check_err { this->metrics.p_replication_lag_check_ERR->Value() }; + this->metrics.p_replication_lag_check_ERR->Increment(GloMyMon->replication_lag_check_ERR - cur_replication_lag_check_err); + } +} void MySQL_Monitor::print_version() { fprintf(stderr,"Standard MySQL Monitor (StdMyMon) rev. %s -- %s -- %s\n", MYSQL_MONITOR_VERSION, __FILE__, __TIMESTAMP__);