Added new 'prometheus_memory_metrics_interval' admin variable

pull/2676/head
Javier Jaramago Fernández 6 years ago
parent dbbfc397a6
commit 225c253607

@ -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<prometheus::Counter*, p_admin_counter::__size> p_counter_array {};
std::array<prometheus::Gauge*, p_admin_gauge::__size> p_gauge_array {};

@ -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);

Loading…
Cancel
Save