From 225c2536077e90bcd7b90e9e5079ff67e6b77bcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Thu, 23 Apr 2020 01:04:45 +0200 Subject: [PATCH] Added new 'prometheus_memory_metrics_interval' admin variable --- include/proxysql_admin.h | 3 +++ lib/ProxySQL_Admin.cpp | 26 +++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/proxysql_admin.h b/include/proxysql_admin.h index 564b40635..f6479ff99 100644 --- a/include/proxysql_admin.h +++ b/include/proxysql_admin.h @@ -165,11 +165,14 @@ class ProxySQL_Admin { bool web_enabled_old; int web_port; int web_port_old; + int p_memory_metrics_interval; #ifdef DEBUG bool debug; #endif /* DEBUG */ } variables; + unsigned long long last_p_memory_metrics_ts; + struct { std::array p_counter_array {}; std::array p_gauge_array {}; diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index 1a72c10db..3c2f858a1 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -535,6 +535,7 @@ static char * admin_variables_names[]= { (char *)"restapi_port", (char *)"web_enabled", (char *)"web_port", + (char *)"prometheus_memory_metrics_interval", #ifdef DEBUG (char *)"debug", #endif /* DEBUG */ @@ -5028,10 +5029,12 @@ ProxySQL_Admin::ProxySQL_Admin() : variables.web_enabled_old = false; variables.web_port = 6080; variables.web_port_old = variables.web_port; - + variables.p_memory_metrics_interval = 61; #ifdef DEBUG variables.debug=GloVars.global.gdbg; #endif /* DEBUG */ + + last_p_memory_metrics_ts = 0; // create the scheduler scheduler=new ProxySQL_External_Scheduler(); @@ -6607,6 +6610,10 @@ char * ProxySQL_Admin::get_variable(char *name) { sprintf(intbuf,"%d",variables.web_port); return strdup(intbuf); } + if (!strcasecmp(name,"prometheus_memory_metrics_interval")) { + sprintf(intbuf, "%d", variables.p_memory_metrics_interval); + return strdup(intbuf); + } #ifdef DEBUG if (!strcasecmp(name,"debug")) { return strdup((variables.debug ? "true" : "false")); @@ -7202,6 +7209,15 @@ bool ProxySQL_Admin::set_variable(char *name, char *value) { // this is the pub } return false; } + if (!strcasecmp(name,"prometheus_memory_metrics_interval")) { + const auto fval = atoi(value); + if (fval > 0 && fval < 7*24*3600) { + variables.p_memory_metrics_interval = fval; + return true; + } else { + return false; + } + } #ifdef DEBUG if (!strcasecmp(name,"debug")) { if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) { @@ -7236,6 +7252,14 @@ void ProxySQL_Admin::p_update_metrics() { void ProxySQL_Admin::p_stats___memory_metrics() { if (!GloMTH) return; + // Check that last execution is older than the specified interval + unsigned long long new_ts = monotonic_time() / 1000 / 1000; + if (new_ts < last_p_memory_metrics_ts + variables.p_memory_metrics_interval) { + return; + } + // Update the 'memory_metrics' last exec timestamp + last_p_memory_metrics_ts = new_ts; + // proxysql_connpool_memory_bytes metric const auto connpool_mem = MyHGM->Get_Memory_Stats(); this->metrics.p_gauge_array[p_admin_gauge::connpool_memory_bytes]->Set(connpool_mem);