mirror of https://github.com/sysown/proxysql
commit
78c32c6fba
@ -0,0 +1 @@
|
||||
libmicrohttpd-0.9.55
|
||||
Binary file not shown.
@ -0,0 +1,27 @@
|
||||
#ifndef CLASS_PROXYSQL_HTTP_SERVER_H
|
||||
#define CLASS_PROXYSQL_HTTP_SERVER_H
|
||||
#include "proxysql.h"
|
||||
#include "cpp.h"
|
||||
#include <string>
|
||||
|
||||
#define ProxySQL_HTTP_Server_Rate_Limit 100
|
||||
|
||||
class ProxySQL_HTTP_Server {
|
||||
unsigned int page_sec;
|
||||
time_t cur_time;
|
||||
public:
|
||||
struct {
|
||||
} variables;
|
||||
ProxySQL_HTTP_Server();
|
||||
~ProxySQL_HTTP_Server();
|
||||
void init();
|
||||
int handler(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **ptr);
|
||||
void print_version();
|
||||
std::string * generate_header(char *);
|
||||
std::string * generate_canvas(char *);
|
||||
std::string * generate_chart(char *chart_name, char *ts, int nsets, char **dname, char **llabel, char **values);
|
||||
char *extract_values(SQLite3_result *result, int idx, bool relative, double mult=1);
|
||||
char *extract_ts(SQLite3_result *result, bool relative);
|
||||
};
|
||||
|
||||
#endif /* CLASS_PROXYSQL_HTTP_SERVER */
|
||||
@ -0,0 +1,63 @@
|
||||
#ifndef CLASS_PROXYSQL_STATISTICS_H
|
||||
#define CLASS_PROXYSQL_STATISTICS_H
|
||||
#include "proxysql.h"
|
||||
#include "cpp.h"
|
||||
//#include "thread.h"
|
||||
//#include "wqueue.h"
|
||||
|
||||
|
||||
#define STATSDB_SQLITE_TABLE_MYSQL_CONNECTIONS "CREATE TABLE mysql_connections (timestamp INT NOT NULL, Client_Connections_aborted INT NOT NULL, Client_Connections_connected INT NOT NULL, Client_Connections_created INT NOT NULL, Server_Connections_aborted INT NOT NULL, Server_Connections_connected INT NOT NULL, Server_Connections_created INT NOT NULL, ConnPool_get_conn_failure INT NOT NULL, ConnPool_get_conn_immediate INT NOT NULL, ConnPool_get_conn_success INT NOT NULL, Questions INT NOT NULL, Slow_queries INT NOT NULL, PRIMARY KEY (timestamp))"
|
||||
|
||||
#define STATSDB_SQLITE_TABLE_SYSTEM_CPU "CREATE TABLE system_cpu (timestamp INT NOT NULL, tms_utime INT NOT NULL, tms_stime INT NOT NULL, PRIMARY KEY (timestamp))"
|
||||
|
||||
#define STATSDB_SQLITE_TABLE_SYSTEM_MEMORY "CREATE TABLE system_memory (timestamp INT NOT NULL, allocated INT NOT NULL, resident INT NOT NULL, active INT NOT NULL, mapped INT NOT NULL, metadata INT NOT NULL, retained INT NOT NULL, PRIMARY KEY (timestamp))"
|
||||
|
||||
#define STATSDB_SQLITE_TABLE_MYSQL_CONNECTIONS_HOUR "CREATE TABLE mysql_connections_hour (timestamp INT NOT NULL, Client_Connections_aborted INT NOT NULL, Client_Connections_connected INT NOT NULL, Client_Connections_created INT NOT NULL, Server_Connections_aborted INT NOT NULL, Server_Connections_connected INT NOT NULL, Server_Connections_created INT NOT NULL, ConnPool_get_conn_failure INT NOT NULL, ConnPool_get_conn_immediate INT NOT NULL, ConnPool_get_conn_success INT NOT NULL, Questions INT NOT NULL, Slow_queries INT NOT NULL, PRIMARY KEY (timestamp))"
|
||||
|
||||
#define STATSDB_SQLITE_TABLE_SYSTEM_CPU_HOUR "CREATE TABLE system_cpu_hour (timestamp INT NOT NULL, tms_utime INT NOT NULL, tms_stime INT NOT NULL, PRIMARY KEY (timestamp))"
|
||||
|
||||
#define STATSDB_SQLITE_TABLE_SYSTEM_MEMORY_HOUR "CREATE TABLE system_memory_hour (timestamp INT NOT NULL, allocated INT NOT NULL, resident INT NOT NULL, active INT NOT NULL, mapped INT NOT NULL, metadata INT NOT NULL, retained INT NOT NULL, PRIMARY KEY (timestamp))"
|
||||
|
||||
#define STATSDB_SQLITE_TABLE_MYSQL_CONNECTIONS_DAY "CREATE TABLE mysql_connections_day (timestamp INT NOT NULL, Client_Connections_aborted INT NOT NULL, Client_Connections_connected INT NOT NULL, Client_Connections_created INT NOT NULL, Server_Connections_aborted INT NOT NULL, Server_Connections_connected INT NOT NULL, Server_Connections_created INT NOT NULL, ConnPool_get_conn_failure INT NOT NULL, ConnPool_get_conn_immediate INT NOT NULL, ConnPool_get_conn_success INT NOT NULL, Questions INT NOT NULL, Slow_queries INT NOT NULL, PRIMARY KEY (timestamp))"
|
||||
|
||||
#define STATSDB_SQLITE_TABLE_SYSTEM_CPU_DAY "CREATE TABLE system_cpu_day (timestamp INT NOT NULL, tms_utime INT NOT NULL, tms_stime INT NOT NULL, PRIMARY KEY (timestamp))"
|
||||
|
||||
#define STATSDB_SQLITE_TABLE_SYSTEM_MEMORY_DAY "CREATE TABLE system_memory_day (timestamp INT NOT NULL, allocated INT NOT NULL, resident INT NOT NULL, active INT NOT NULL, mapped INT NOT NULL, metadata INT NOT NULL, retained INT NOT NULL, PRIMARY KEY (timestamp))"
|
||||
|
||||
|
||||
class ProxySQL_Statistics {
|
||||
SQLite3DB *statsdb_mem; // internal statistics DB
|
||||
std::vector<table_def_t *> *tables_defs_statsdb_mem;
|
||||
std::vector<table_def_t *> *tables_defs_statsdb_disk;
|
||||
// this is copied from ProxySQL Admin
|
||||
void insert_into_tables_defs(std::vector<table_def_t *> *, const char *table_name, const char *table_def);
|
||||
void drop_tables_defs(std::vector<table_def_t *> *tables_defs);
|
||||
void check_and_build_standard_tables(SQLite3DB *db, std::vector<table_def_t *> *tables_defs);
|
||||
unsigned long long next_timer_MySQL_Threads_Handler;
|
||||
unsigned long long next_timer_system_cpu;
|
||||
unsigned long long next_timer_system_memory;
|
||||
public:
|
||||
struct {
|
||||
int stats_mysql_connection_pool;
|
||||
int stats_mysql_connections;
|
||||
int stats_mysql_query_cache;
|
||||
int stats_system_cpu;
|
||||
int stats_system_memory;
|
||||
} variables;
|
||||
ProxySQL_Statistics();
|
||||
~ProxySQL_Statistics();
|
||||
SQLite3DB *statsdb_disk; // internal statistics DB
|
||||
void init();
|
||||
void print_version();
|
||||
bool MySQL_Threads_Handler_timetoget(unsigned long long);
|
||||
bool system_cpu_timetoget(unsigned long long);
|
||||
bool system_memory_timetoget(unsigned long long);
|
||||
void MySQL_Threads_Handler_sets(SQLite3_result *);
|
||||
void system_cpu_sets();
|
||||
void system_memory_sets();
|
||||
SQLite3_result * get_mysql_metrics();
|
||||
SQLite3_result * get_system_cpu_metrics();
|
||||
SQLite3_result * get_system_memory_metrics();
|
||||
};
|
||||
|
||||
#endif /* CLASS_PROXYSQL_STATISTICS_H */
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,435 @@
|
||||
#include <iostream> // std::cout
|
||||
#include <algorithm> // std::sort
|
||||
#include <vector> // std::vector
|
||||
#include "re2/re2.h"
|
||||
#include "re2/regexp.h"
|
||||
#include "proxysql.h"
|
||||
#include "cpp.h"
|
||||
|
||||
#include <search.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <resolv.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <pthread.h>
|
||||
#include "SpookyV2.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#include "platform.h"
|
||||
#include "microhttpd.h"
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DEB "_DEBUG"
|
||||
#else
|
||||
#define DEB ""
|
||||
#endif /* DEBUG */
|
||||
#define PROXYSQL_HTTP_SERVER_VERSION "1.4.1031" DEB
|
||||
|
||||
|
||||
//extern struct MHD_Daemon *Admin_HTTP_Server;
|
||||
|
||||
extern ProxySQL_Statistics *GloProxyStats;
|
||||
|
||||
extern char * Chart_bundle_js_c;
|
||||
#define RATE_LIMIT_PAGE "<html><head><title>Rate Limit Page</title></head><body>Rate Limit Reached</body></html>"
|
||||
|
||||
|
||||
|
||||
char * ProxySQL_HTTP_Server::extract_values(SQLite3_result *result, int idx, bool relative, double mult) {
|
||||
string s = "[";
|
||||
int i;
|
||||
for ( i= (relative ? 1 : 0) ; i < result->rows_count ; i++) {
|
||||
SQLite3_row *r1 = ( relative ? result->rows[i-1] : NULL );
|
||||
SQLite3_row *r2 = result->rows[i];
|
||||
double v;
|
||||
if (relative) {
|
||||
double d2 = atol(r2->fields[idx]);
|
||||
double d1 = atol(r1->fields[idx]);
|
||||
double diff = (atol(r2->fields[1])-atol(r1->fields[1]));
|
||||
v = (d2-d1)/diff;
|
||||
} else {
|
||||
v = atol(r2->fields[idx]);
|
||||
}
|
||||
v *= mult;
|
||||
if (v<0) v=0;
|
||||
s.append(std::to_string(v));
|
||||
if (i != result->rows_count-1) {
|
||||
s.append(", ");
|
||||
}
|
||||
}
|
||||
s.append("];");
|
||||
char *ret=strdup(s.c_str());
|
||||
return ret;
|
||||
}
|
||||
|
||||
char * ProxySQL_HTTP_Server::extract_ts(SQLite3_result *result, bool relative) {
|
||||
string s = "[";
|
||||
int i;
|
||||
for ( i= (relative ? 1 : 0) ; i < result->rows_count ; i++) {
|
||||
SQLite3_row *r2 = result->rows[i];
|
||||
s.append("\"");
|
||||
s.append(r2->fields[0]);
|
||||
s.append("\"");
|
||||
if (i != result->rows_count-1) {
|
||||
s.append(", ");
|
||||
}
|
||||
}
|
||||
s.append("];");
|
||||
char *ret=strdup(s.c_str());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void ProxySQL_HTTP_Server::init() {
|
||||
}
|
||||
|
||||
void ProxySQL_HTTP_Server::print_version() {
|
||||
fprintf(stderr,"Standard ProxySQL HTTP Server Handler rev. %s -- %s -- %s\n", PROXYSQL_HTTP_SERVER_VERSION, __FILE__, __TIMESTAMP__);
|
||||
}
|
||||
|
||||
#define EMPTY_PAGE "<html><head><title>File not found</title></head><body>File not found<br/><a href=\"/\">Go back home</a></body></html>"
|
||||
|
||||
int ProxySQL_HTTP_Server::handler(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **ptr) {
|
||||
|
||||
struct MHD_Response *response;
|
||||
int ret;
|
||||
char *valmetric = NULL;
|
||||
char *valinterval = NULL;
|
||||
char *valunit = NULL;
|
||||
|
||||
time_t now = time(NULL);
|
||||
if (now != cur_time) {
|
||||
page_sec = 0;
|
||||
cur_time = now;
|
||||
}
|
||||
page_sec++;
|
||||
if (page_sec > ProxySQL_HTTP_Server_Rate_Limit) {
|
||||
response = MHD_create_response_from_buffer(strlen(RATE_LIMIT_PAGE), (void *) RATE_LIMIT_PAGE, MHD_RESPMEM_PERSISTENT);
|
||||
ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
|
||||
MHD_destroy_response (response);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (0 != strcmp (method, "GET"))
|
||||
return MHD_NO; /* unexpected method */
|
||||
// if (&aptr != *ptr) {
|
||||
// /* do never respond on first call */
|
||||
// *ptr = &aptr;
|
||||
// return MHD_YES;
|
||||
// }
|
||||
// *ptr = NULL; /* reset when done */
|
||||
|
||||
if (strcmp(url,"/stats")==0) {
|
||||
valmetric = (char *)MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, (char *)"metric");
|
||||
valinterval = (char *)MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, (char *)"points");
|
||||
valunit = (char *)MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, (char *)"unit");
|
||||
if (valmetric == NULL) {
|
||||
response = MHD_create_response_from_buffer (strlen (EMPTY_PAGE), (void *) EMPTY_PAGE, MHD_RESPMEM_PERSISTENT);
|
||||
ret = MHD_queue_response (connection, MHD_HTTP_NOT_FOUND, response);
|
||||
MHD_destroy_response (response);
|
||||
return ret;
|
||||
}
|
||||
if (valunit == NULL) {
|
||||
valunit = (char *)"second";
|
||||
}
|
||||
if ( (strcmp(valunit,"second")) && (strcmp(valunit,"hour")) && (strcmp(valunit,"day")) ) {
|
||||
response = MHD_create_response_from_buffer (strlen (EMPTY_PAGE), (void *) EMPTY_PAGE, MHD_RESPMEM_PERSISTENT);
|
||||
ret = MHD_queue_response (connection, MHD_HTTP_NOT_FOUND, response);
|
||||
MHD_destroy_response (response);
|
||||
return ret;
|
||||
}
|
||||
if (valinterval == NULL) {
|
||||
if ((strcmp(valunit,(char *)"second") == 0)) {
|
||||
valinterval = (char *)"14400";
|
||||
}
|
||||
if ((strcmp(valunit,(char *)"hour") == 0)) {
|
||||
valinterval = (char *)"720";
|
||||
}
|
||||
if ((strcmp(valunit,"day") == 0)) {
|
||||
valinterval = (char *)"365";
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(valmetric,"system")==0) {
|
||||
string *s = generate_header((char *)"ProxySQL Graphs");
|
||||
string *s1 = generate_canvas((char *)"myChart1");
|
||||
s->append(s1->c_str());
|
||||
s1 = generate_canvas((char *)"myChart2");
|
||||
s->append(s1->c_str());
|
||||
s1 = generate_canvas((char *)"myChart3");
|
||||
s->append(s1->c_str());
|
||||
s1 = generate_canvas((char *)"myChart4");
|
||||
s->append(s1->c_str());
|
||||
SQLite3_result *cpu_sqlite = GloProxyStats->get_system_cpu_metrics();
|
||||
SQLite3_result *memory_sqlite = GloProxyStats->get_system_memory_metrics();
|
||||
//SQLite3_result *mysql_metrics_sqlite = GloProxyStats->get_mysql_metrics();
|
||||
char **nm = NULL;
|
||||
char **nl = NULL;
|
||||
char **nv = NULL;
|
||||
char *ts = NULL;
|
||||
|
||||
nm = (char **)malloc(sizeof(char *)*2);
|
||||
nm[0] = (char *)"utime";
|
||||
nm[1] = (char *)"stime";
|
||||
nl = (char **)malloc(sizeof(char *)*2);
|
||||
nl[0] = (char *)"User Time";
|
||||
nl[1] = (char *)"System Time";
|
||||
nv = (char **)malloc(sizeof(char *)*2);
|
||||
nv[0] = extract_values(cpu_sqlite,2,true,(double)1/sysconf(_SC_CLK_TCK));
|
||||
nv[1] = extract_values(cpu_sqlite,3,true,(double)1/sysconf(_SC_CLK_TCK));
|
||||
ts = extract_ts(cpu_sqlite,true);
|
||||
s1 = generate_chart((char *)"myChart1",ts,2,nm,nl,nv);
|
||||
s->append(s1->c_str());
|
||||
free(nm);
|
||||
free(nl);
|
||||
free(nv[0]);
|
||||
free(nv[1]);
|
||||
free(nv);
|
||||
free(ts);
|
||||
|
||||
|
||||
nm = (char **)malloc(sizeof(char *)*5);
|
||||
nm[0] = (char *)"allocated";
|
||||
nm[1] = (char *)"resident";
|
||||
nm[2] = (char *)"active";
|
||||
nm[3] = (char *)"mapped";
|
||||
nm[4] = (char *)"metadata";
|
||||
nl = (char **)malloc(sizeof(char *)*5);
|
||||
nl[0] = (char *)"Allocated";
|
||||
nl[1] = (char *)"Resident";
|
||||
nl[2] = (char *)"Active";
|
||||
nl[3] = (char *)"Mapped";
|
||||
nl[4] = (char *)"Metadata";
|
||||
nv = (char **)malloc(sizeof(char *)*5);
|
||||
nv[0] = extract_values(memory_sqlite,2,false);
|
||||
nv[1] = extract_values(memory_sqlite,3,false);
|
||||
nv[2] = extract_values(memory_sqlite,4,false);
|
||||
nv[3] = extract_values(memory_sqlite,5,false);
|
||||
nv[4] = extract_values(memory_sqlite,6,false);
|
||||
ts = extract_ts(cpu_sqlite,true);
|
||||
s1 = generate_chart((char *)"myChart2",ts,5,nm,nl,nv);
|
||||
s->append(s1->c_str());
|
||||
free(nm);
|
||||
free(nl);
|
||||
free(nv[0]);
|
||||
free(nv[1]);
|
||||
free(nv[2]);
|
||||
free(nv[3]);
|
||||
free(nv[4]);
|
||||
free(nv);
|
||||
free(ts);
|
||||
|
||||
s->append("</body></html>");
|
||||
response = MHD_create_response_from_buffer(s->length(), (void *) s->c_str(), MHD_RESPMEM_PERSISTENT);
|
||||
ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
|
||||
MHD_destroy_response (response);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (strcmp(valmetric,"mysql")==0) {
|
||||
string *s = generate_header((char *)"ProxySQL Graphs");
|
||||
string *s1 = generate_canvas((char *)"myChart1");
|
||||
s->append(s1->c_str());
|
||||
s1 = generate_canvas((char *)"myChart2");
|
||||
s->append(s1->c_str());
|
||||
s1 = generate_canvas((char *)"myChart3");
|
||||
s->append(s1->c_str());
|
||||
s1 = generate_canvas((char *)"myChart4");
|
||||
s->append(s1->c_str());
|
||||
//SQLite3_result *cpu_sqlite = GloProxyStats->get_system_cpu_metrics();
|
||||
//SQLite3_result *memory_sqlite = GloProxyStats->get_system_memory_metrics();
|
||||
SQLite3_result *mysql_metrics_sqlite = GloProxyStats->get_mysql_metrics();
|
||||
char **nm = NULL;
|
||||
char **nl = NULL;
|
||||
char **nv = NULL;
|
||||
char *ts = NULL;
|
||||
|
||||
//Client_Connections_aborted, Client_Connections_connected, Client_Connections_created, Server_Connections_aborted, Server_Connections_connected, Server_Connections_created, ConnPool_get_conn_immediate, ConnPool_get_conn_success, Questions
|
||||
|
||||
nm = (char **)malloc(sizeof(char *)*6);
|
||||
nm[0] = (char *)"Client_Connections_aborted";
|
||||
nm[1] = (char *)"Client_Connections_connected";
|
||||
nm[2] = (char *)"Client_Connections_created";
|
||||
nm[3] = (char *)"Server_Connections_aborted";
|
||||
nm[4] = (char *)"Server_Connections_connected";
|
||||
nm[5] = (char *)"Server_Connections_created";
|
||||
nl = (char **)malloc(sizeof(char *)*6);
|
||||
nl[0] = (char *)"Client Connections aborted";
|
||||
nl[1] = (char *)"Client Connections connected";
|
||||
nl[2] = (char *)"Client Connections created";
|
||||
nl[3] = (char *)"Server Connections aborted";
|
||||
nl[4] = (char *)"Server Connections connected";
|
||||
nl[5] = (char *)"Server Connections created";
|
||||
nv = (char **)malloc(sizeof(char *)*6);
|
||||
nv[0] = extract_values(mysql_metrics_sqlite,2,true,(double)1);
|
||||
nv[1] = extract_values(mysql_metrics_sqlite,3,false,(double)1);
|
||||
nv[2] = extract_values(mysql_metrics_sqlite,4,true,(double)1);
|
||||
nv[3] = extract_values(mysql_metrics_sqlite,5,true,(double)1);
|
||||
nv[4] = extract_values(mysql_metrics_sqlite,6,false,(double)1);
|
||||
nv[5] = extract_values(mysql_metrics_sqlite,7,true,(double)1);
|
||||
ts = extract_ts(mysql_metrics_sqlite,true);
|
||||
s1 = generate_chart((char *)"myChart1",ts,6,nm,nl,nv);
|
||||
s->append(s1->c_str());
|
||||
free(nm);
|
||||
free(nl);
|
||||
for (int aa=0 ; aa<6 ; aa++) {
|
||||
free(nv[aa]);
|
||||
}
|
||||
free(nv);
|
||||
free(ts);
|
||||
|
||||
|
||||
nm = (char **)malloc(sizeof(char *)*4);
|
||||
nm[0] = (char *)"ConnPool_get_conn_failure";
|
||||
nm[1] = (char *)"ConnPool_get_conn_immediate";
|
||||
nm[2] = (char *)"ConnPool_get_conn_success";
|
||||
nm[3] = (char *)"Questions";
|
||||
nl = (char **)malloc(sizeof(char *)*4);
|
||||
nl[0] = (char *)"ConnPool failure";
|
||||
nl[1] = (char *)"ConnPool immediate";
|
||||
nl[2] = (char *)"ConnPool success";
|
||||
nl[3] = (char *)"Questions";
|
||||
nv = (char **)malloc(sizeof(char *)*4);
|
||||
nv[0] = extract_values(mysql_metrics_sqlite,8,true);
|
||||
nv[1] = extract_values(mysql_metrics_sqlite,9,true);
|
||||
nv[2] = extract_values(mysql_metrics_sqlite,10,true);
|
||||
nv[3] = extract_values(mysql_metrics_sqlite,11,true);
|
||||
ts = extract_ts(mysql_metrics_sqlite,true);
|
||||
s1 = generate_chart((char *)"myChart2",ts,4,nm,nl,nv);
|
||||
s->append(s1->c_str());
|
||||
free(nm);
|
||||
free(nl);
|
||||
for (int aa=0 ; aa<4 ; aa++) {
|
||||
free(nv[aa]);
|
||||
}
|
||||
free(nv);
|
||||
free(ts);
|
||||
|
||||
s->append("</body></html>");
|
||||
response = MHD_create_response_from_buffer(s->length(), (void *) s->c_str(), MHD_RESPMEM_MUST_COPY);
|
||||
ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
|
||||
MHD_destroy_response (response);
|
||||
delete s;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(url,"/Chart.bundle.js")==0) {
|
||||
response = MHD_create_response_from_buffer(strlen(Chart_bundle_js_c), Chart_bundle_js_c, MHD_RESPMEM_PERSISTENT);
|
||||
ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
|
||||
MHD_destroy_response (response);
|
||||
return ret;
|
||||
}
|
||||
response = MHD_create_response_from_buffer (strlen (EMPTY_PAGE), (void *) EMPTY_PAGE, MHD_RESPMEM_PERSISTENT);
|
||||
ret = MHD_queue_response (connection, MHD_HTTP_NOT_FOUND, response);
|
||||
MHD_destroy_response (response);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
string * ProxySQL_HTTP_Server::generate_header(char *s) {
|
||||
string *a = new string();
|
||||
a->append("<head>\n<title>");
|
||||
a->append(s);
|
||||
a->append("</title>\n<script src=\"/Chart.bundle.js\"></script>\n</head>\n<body>\n");
|
||||
return a;
|
||||
}
|
||||
|
||||
string * ProxySQL_HTTP_Server::generate_canvas(char *s) {
|
||||
string *a = new string();
|
||||
a->append("<div class=\"wrapper\" style=\"width: 700px; height: 300px\"><canvas id=\"");
|
||||
a->append(s);
|
||||
a->append("\" width=\"650\" height=\"280\"></canvas></div>\n");
|
||||
return a;
|
||||
}
|
||||
ProxySQL_HTTP_Server::ProxySQL_HTTP_Server() {
|
||||
page_sec = 0;
|
||||
cur_time = time(NULL);
|
||||
}
|
||||
|
||||
ProxySQL_HTTP_Server::~ProxySQL_HTTP_Server() {
|
||||
}
|
||||
|
||||
string * ProxySQL_HTTP_Server::generate_chart(char *chart_name, char *ts, int nsets, char **dname, char **llabel, char **values) {
|
||||
char *h=(char *)"0123456789abcdef";
|
||||
string *ret= new string();
|
||||
int i;
|
||||
ret->append("<script>\n");
|
||||
ret->append("var ts = ");
|
||||
ret->append(ts);
|
||||
ret->append("\n");
|
||||
for (i=0;i<nsets;i++) {
|
||||
ret->append("var ");
|
||||
ret->append(dname[i]);
|
||||
ret->append(" = ");
|
||||
ret->append(values[i]);
|
||||
ret->append("\n");
|
||||
}
|
||||
ret->append("var ctx = document.getElementById(\"");
|
||||
ret->append(chart_name);
|
||||
ret->append("\");\nvar ");
|
||||
ret->append(chart_name);
|
||||
ret->append(" = new Chart(ctx, { \n");
|
||||
ret->append("type: 'line', \n");
|
||||
ret->append(" data: { \n");
|
||||
ret->append(" labels: ts,\n");
|
||||
ret->append(" datasets: [ \n");
|
||||
for (i=0;i<nsets;i++) {
|
||||
ret->append(" {\n");
|
||||
ret->append(" data: "); ret->append(dname[i]); ret->append(",\n");
|
||||
ret->append(" label: \""); ret->append(llabel[i]); ret->append("\",\n");
|
||||
int j;
|
||||
char pal[7];
|
||||
for (j=0; j<6; j++) { pal[j]=h[rand()%16]; }
|
||||
pal[6]='\0';
|
||||
ret->append(" borderColor: \"#"); ret->append(pal); ret->append("\",\n");
|
||||
ret->append(" fill: false\n");
|
||||
ret->append(" }");
|
||||
if (i<nsets-1) {
|
||||
ret->append(",");
|
||||
}
|
||||
ret->append("\n");
|
||||
}
|
||||
ret->append(" ]\n");
|
||||
ret->append(" }\n");
|
||||
ret->append("});\n");
|
||||
ret->append("</script>\n");
|
||||
return ret;
|
||||
|
||||
}
|
||||
/*
|
||||
<script>\n";
|
||||
|
||||
|
||||
char *script5 = "\
|
||||
var ctx = document.getElementById(\"myChart1\"); var myChart1 = new Chart(ctx, { \n\
|
||||
type: 'line', \n\
|
||||
data: { \n\
|
||||
labels: ts, \n\
|
||||
datasets: [ \n\
|
||||
{ \n\
|
||||
data: utime, \n\
|
||||
label: \"User Time\", \n\
|
||||
borderColor: \"#3e95cd\", \n\
|
||||
fill: false \n\
|
||||
}, \n\
|
||||
{ \n\
|
||||
data: stime, \n\
|
||||
label: \"System Time\", \n\
|
||||
borderColor: \"#8e5ea2\", \n\
|
||||
fill: false \n\
|
||||
} \n\
|
||||
] \n\
|
||||
} \n\
|
||||
});\n";
|
||||
|
||||
*/
|
||||
@ -0,0 +1,436 @@
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
//#include <thread>
|
||||
#include "proxysql.h"
|
||||
#include "cpp.h"
|
||||
|
||||
//#include "thread.h"
|
||||
//#include "wqueue.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DEB "_DEBUG"
|
||||
#else
|
||||
#define DEB ""
|
||||
#endif /* DEBUG */
|
||||
#define PROXYSQL_STATISTICS_VERSION "1.4.1027" DEB
|
||||
|
||||
extern ProxySQL_Admin *GloAdmin;
|
||||
extern MySQL_Threads_Handler *GloMTH;
|
||||
|
||||
|
||||
#define SAFE_SQLITE3_STEP(_stmt) do {\
|
||||
do {\
|
||||
rc=sqlite3_step(_stmt);\
|
||||
if (rc!=SQLITE_DONE) {\
|
||||
assert(rc==SQLITE_LOCKED)\
|
||||
usleep(100);\
|
||||
}\
|
||||
} while (rc!=SQLITE_DONE );\
|
||||
} while (0)
|
||||
|
||||
#define SAFE_SQLITE3_STEP2(_stmt) do {\
|
||||
do {\
|
||||
rc=sqlite3_step(_stmt);\
|
||||
if (rc==SQLITE_LOCKED || rc==SQLITE_BUSY) {\
|
||||
usleep(100);\
|
||||
}\
|
||||
} while (rc==SQLITE_LOCKED || rc==SQLITE_BUSY);\
|
||||
} while (0)
|
||||
|
||||
|
||||
ProxySQL_Statistics::ProxySQL_Statistics() {
|
||||
statsdb_mem = new SQLite3DB();
|
||||
statsdb_mem->open((char *)"file:statsdb_mem?mode=memory&cache=shared", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX);
|
||||
// statsdb_disk = GloAdmin->statsdb_disk;
|
||||
statsdb_disk = new SQLite3DB();
|
||||
// char *dbname = (char *)malloc(strlen(GloVars.statsdb_disk)+50);
|
||||
// sprintf(dbname,"file:%s?cache=shared",GloVars.statsdb_disk);
|
||||
statsdb_disk->open((char *)GloVars.statsdb_disk, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX );
|
||||
// statsdb_disk->open((char *)GloVars.statsdb_disk, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_NOMUTEX);
|
||||
// statsdb_disk->open(dbname, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_NOMUTEX);
|
||||
// free(dbname);
|
||||
statsdb_disk->execute("PRAGMA synchronous=0");
|
||||
|
||||
next_timer_MySQL_Threads_Handler = 0;
|
||||
next_timer_system_cpu = 0;
|
||||
next_timer_system_memory = 0;
|
||||
}
|
||||
|
||||
ProxySQL_Statistics::~ProxySQL_Statistics() {
|
||||
drop_tables_defs(tables_defs_statsdb_mem);
|
||||
delete tables_defs_statsdb_mem;
|
||||
drop_tables_defs(tables_defs_statsdb_disk);
|
||||
delete tables_defs_statsdb_disk;
|
||||
delete statsdb_mem;
|
||||
// delete statsdb_disk;
|
||||
}
|
||||
|
||||
void ProxySQL_Statistics::init() {
|
||||
|
||||
tables_defs_statsdb_mem = new std::vector<table_def_t *>;
|
||||
tables_defs_statsdb_disk = new std::vector<table_def_t *>;
|
||||
insert_into_tables_defs(tables_defs_statsdb_mem,"mysql_connections", STATSDB_SQLITE_TABLE_MYSQL_CONNECTIONS);
|
||||
insert_into_tables_defs(tables_defs_statsdb_disk,"mysql_connections", STATSDB_SQLITE_TABLE_MYSQL_CONNECTIONS);
|
||||
insert_into_tables_defs(tables_defs_statsdb_disk,"system_cpu", STATSDB_SQLITE_TABLE_SYSTEM_CPU);
|
||||
insert_into_tables_defs(tables_defs_statsdb_disk,"system_memory", STATSDB_SQLITE_TABLE_SYSTEM_MEMORY);
|
||||
insert_into_tables_defs(tables_defs_statsdb_disk,"mysql_connections_hour", STATSDB_SQLITE_TABLE_MYSQL_CONNECTIONS_HOUR);
|
||||
insert_into_tables_defs(tables_defs_statsdb_disk,"system_cpu_hour", STATSDB_SQLITE_TABLE_SYSTEM_CPU_HOUR);
|
||||
insert_into_tables_defs(tables_defs_statsdb_disk,"system_memory_hour", STATSDB_SQLITE_TABLE_SYSTEM_MEMORY_HOUR);
|
||||
insert_into_tables_defs(tables_defs_statsdb_disk,"mysql_connections_day", STATSDB_SQLITE_TABLE_MYSQL_CONNECTIONS_DAY);
|
||||
insert_into_tables_defs(tables_defs_statsdb_disk,"system_cpu_day", STATSDB_SQLITE_TABLE_SYSTEM_CPU_DAY);
|
||||
insert_into_tables_defs(tables_defs_statsdb_disk,"system_memory_day", STATSDB_SQLITE_TABLE_SYSTEM_MEMORY_DAY);
|
||||
|
||||
check_and_build_standard_tables(statsdb_mem, tables_defs_statsdb_disk);
|
||||
check_and_build_standard_tables(statsdb_disk, tables_defs_statsdb_disk);
|
||||
}
|
||||
|
||||
void ProxySQL_Statistics::print_version() {
|
||||
fprintf(stderr,"Standard ProxySQL Statistics rev. %s -- %s -- %s\n", PROXYSQL_STATISTICS_VERSION, __FILE__, __TIMESTAMP__);
|
||||
}
|
||||
|
||||
|
||||
void ProxySQL_Statistics::check_and_build_standard_tables(SQLite3DB *db, std::vector<table_def_t *> *tables_defs) {
|
||||
table_def_t *td;
|
||||
db->execute("PRAGMA foreign_keys = OFF");
|
||||
for (std::vector<table_def_t *>::iterator it=tables_defs->begin(); it!=tables_defs->end(); ++it) {
|
||||
td=*it;
|
||||
db->check_and_build_table(td->table_name, td->table_def);
|
||||
}
|
||||
db->execute("PRAGMA foreign_keys = ON");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ProxySQL_Statistics::insert_into_tables_defs(std::vector<table_def_t *> *tables_defs, const char *table_name, const char *table_def) {
|
||||
table_def_t *td = new table_def_t;
|
||||
td->table_name=strdup(table_name);
|
||||
td->table_def=strdup(table_def);
|
||||
tables_defs->push_back(td);
|
||||
}
|
||||
|
||||
void ProxySQL_Statistics::drop_tables_defs(std::vector<table_def_t *> *tables_defs) {
|
||||
table_def_t *td;
|
||||
while (!tables_defs->empty()) {
|
||||
td=tables_defs->back();
|
||||
free(td->table_name);
|
||||
td->table_name=NULL;
|
||||
free(td->table_def);
|
||||
td->table_def=NULL;
|
||||
tables_defs->pop_back();
|
||||
delete td;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ProxySQL_Statistics::MySQL_Threads_Handler_timetoget(unsigned long long curtime) {
|
||||
unsigned int i = (unsigned int)variables.stats_mysql_connections;
|
||||
if (i) {
|
||||
if (
|
||||
( curtime > next_timer_MySQL_Threads_Handler )
|
||||
||
|
||||
( curtime + i*1000*1000 < next_timer_MySQL_Threads_Handler )
|
||||
) {
|
||||
next_timer_MySQL_Threads_Handler = curtime/1000/1000 + i;
|
||||
next_timer_MySQL_Threads_Handler = next_timer_MySQL_Threads_Handler * 1000 * 1000;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ProxySQL_Statistics::system_cpu_timetoget(unsigned long long curtime) {
|
||||
unsigned int i = (unsigned int)variables.stats_system_cpu;
|
||||
if (i) {
|
||||
if (
|
||||
( curtime > next_timer_system_cpu )
|
||||
||
|
||||
( curtime + i*1000*1000 < next_timer_system_cpu )
|
||||
) {
|
||||
next_timer_system_cpu = curtime/1000/1000 + i;
|
||||
next_timer_system_cpu = next_timer_system_cpu * 1000 * 1000;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ProxySQL_Statistics::system_memory_timetoget(unsigned long long curtime) {
|
||||
unsigned int i = (unsigned int)variables.stats_system_memory;
|
||||
if (i) {
|
||||
if (
|
||||
( curtime > next_timer_system_memory )
|
||||
||
|
||||
( curtime + i*1000*1000 < next_timer_system_memory )
|
||||
) {
|
||||
next_timer_system_memory = curtime/1000/1000 + i;
|
||||
next_timer_system_memory = next_timer_system_memory * 1000 * 1000;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
SQLite3_result * ProxySQL_Statistics::get_mysql_metrics() {
|
||||
SQLite3_result *resultset = NULL;
|
||||
int cols;
|
||||
int affected_rows;
|
||||
char *error = NULL;
|
||||
char *query = (char *)"SELECT * FROM (SELECT SUBSTR(FROM_UNIXTIME(timestamp),0,20) ts, timestamp, Client_Connections_aborted, Client_Connections_connected, Client_Connections_created, Server_Connections_aborted, Server_Connections_connected, Server_Connections_created, ConnPool_get_conn_failure, ConnPool_get_conn_immediate, ConnPool_get_conn_success, Questions FROM mysql_connections ORDER BY timestamp DESC LIMIT 100) t ORDER BY ts";
|
||||
statsdb_disk->execute_statement(query, &error , &cols , &affected_rows , &resultset);
|
||||
if (error) {
|
||||
if (resultset) {
|
||||
delete resultset;
|
||||
resultset = NULL;
|
||||
}
|
||||
free(error);
|
||||
}
|
||||
return resultset;
|
||||
}
|
||||
|
||||
SQLite3_result * ProxySQL_Statistics::get_system_memory_metrics() {
|
||||
SQLite3_result *resultset = NULL;
|
||||
int cols;
|
||||
int affected_rows;
|
||||
char *error = NULL;
|
||||
char *query = (char *)"SELECT * FROM (SELECT SUBSTR(FROM_UNIXTIME(timestamp),0,20) ts, timestamp, allocated, resident, active, mapped, metadata, retained FROM system_memory ORDER BY timestamp DESC LIMIT 100) t ORDER BY ts";
|
||||
statsdb_disk->execute_statement(query, &error , &cols , &affected_rows , &resultset);
|
||||
if (error) {
|
||||
if (resultset) {
|
||||
delete resultset;
|
||||
resultset = NULL;
|
||||
}
|
||||
free(error);
|
||||
}
|
||||
return resultset;
|
||||
}
|
||||
|
||||
SQLite3_result * ProxySQL_Statistics::get_system_cpu_metrics() {
|
||||
SQLite3_result *resultset = NULL;
|
||||
int cols;
|
||||
int affected_rows;
|
||||
char *error = NULL;
|
||||
char *query = (char *)"SELECT * FROM (SELECT SUBSTR(FROM_UNIXTIME(timestamp),0,20) ts, timestamp, tms_utime, tms_stime FROM system_cpu ORDER BY timestamp DESC LIMIT 100) t ORDER BY ts";
|
||||
statsdb_disk->execute_statement(query, &error , &cols , &affected_rows , &resultset);
|
||||
if (error) {
|
||||
if (resultset) {
|
||||
delete resultset;
|
||||
resultset = NULL;
|
||||
}
|
||||
free(error);
|
||||
}
|
||||
return resultset;
|
||||
}
|
||||
|
||||
void ProxySQL_Statistics::system_cpu_sets() {
|
||||
int rc;
|
||||
struct tms buf;
|
||||
if (times(&buf) > -1) {
|
||||
sqlite3 *mydb3=statsdb_disk->get_db();
|
||||
sqlite3_stmt *statement1=NULL;
|
||||
char *query1=NULL;
|
||||
query1=(char *)"INSERT INTO system_cpu VALUES (?1, ?2, ?3)";
|
||||
rc=sqlite3_prepare_v2(mydb3, query1, -1, &statement1, 0);
|
||||
|
||||
time_t ts = time(NULL);
|
||||
|
||||
rc = sqlite3_bind_int64(statement1, 1, ts); assert(rc==SQLITE_OK);
|
||||
rc = sqlite3_bind_int64(statement1, 2, buf.tms_utime); assert(rc==SQLITE_OK);
|
||||
rc = sqlite3_bind_int64(statement1, 3, buf.tms_stime); assert(rc==SQLITE_OK);
|
||||
|
||||
assert(rc==SQLITE_OK);
|
||||
SAFE_SQLITE3_STEP2(statement1);
|
||||
rc=sqlite3_clear_bindings(statement1); assert(rc==SQLITE_OK);
|
||||
rc=sqlite3_reset(statement1);
|
||||
sqlite3_finalize(statement1);
|
||||
|
||||
SQLite3_result *resultset = NULL;
|
||||
int cols;
|
||||
int affected_rows;
|
||||
char *error = NULL;
|
||||
char *query = (char *)"SELECT MAX(timestamp) FROM system_cpu";
|
||||
statsdb_disk->execute_statement(query, &error , &cols , &affected_rows , &resultset);
|
||||
if (error) {
|
||||
if (resultset) {
|
||||
delete resultset;
|
||||
resultset = NULL;
|
||||
}
|
||||
free(error);
|
||||
} else {
|
||||
char buf[256];
|
||||
if (resultset->rows_count == 0) {
|
||||
sprintf(buf,"INSERT INTO system_cpu_hour SELECT timestamp/3600 , SUM(tms_utime), SUM(tms_stime) FROM system_cpu WHERE timestamp < %ld GROUP BY timestamp/3600", (ts/3600)*3600);
|
||||
statsdb_disk->execute(buf);
|
||||
} else {
|
||||
SQLite3_row *r = resultset->rows[0];
|
||||
time_t t = atol(r->fields[0]);
|
||||
if (ts >= t + 3600) {
|
||||
sprintf(buf,"INSERT INTO system_cpu_hour SELECT timestamp/3600 , SUM(tms_utime), SUM(tms_stime) FROM system_cpu WHERE timestamp >= %ld AND timestamp < %ld GROUP BY timestamp/3600", t+3600 , (ts/3600)*3600);
|
||||
statsdb_disk->execute(buf);
|
||||
}
|
||||
}
|
||||
delete resultset;
|
||||
resultset = NULL;
|
||||
sprintf(buf,"DELETE FROM system_cpu WHERE timestamp < %ld", ts - 3600*24*7);
|
||||
statsdb_disk->execute(buf);
|
||||
sprintf(buf,"DELETE FROM system_cpu_hour WHERE timestamp < %ld", ts - 3600*24*365);
|
||||
statsdb_disk->execute(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProxySQL_Statistics::system_memory_sets() {
|
||||
int rc;
|
||||
struct tms buf;
|
||||
if (times(&buf) > -1) {
|
||||
sqlite3 *mydb3=statsdb_disk->get_db();
|
||||
sqlite3_stmt *statement1=NULL;
|
||||
char *query1=NULL;
|
||||
query1=(char *)"INSERT INTO system_memory VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)";
|
||||
rc=sqlite3_prepare_v2(mydb3, query1, -1, &statement1, 0);
|
||||
|
||||
time_t ts = time(NULL);
|
||||
|
||||
size_t allocated = 0, resident = 0, active = 0, mapped = 0 , metadata = 0, retained = 0 , sz = sizeof(size_t);
|
||||
mallctl("stats.resident", &resident, &sz, NULL, 0);
|
||||
mallctl("stats.active", &active, &sz, NULL, 0);
|
||||
mallctl("stats.allocated", &allocated, &sz, NULL, 0);
|
||||
mallctl("stats.mapped", &mapped, &sz, NULL, 0);
|
||||
mallctl("stats.metadata", &metadata, &sz, NULL, 0);
|
||||
mallctl("stats.retained", &retained, &sz, NULL, 0);
|
||||
|
||||
|
||||
rc = sqlite3_bind_int64(statement1, 1, ts); assert(rc==SQLITE_OK);
|
||||
rc = sqlite3_bind_int64(statement1, 2, allocated); assert(rc==SQLITE_OK);
|
||||
rc = sqlite3_bind_int64(statement1, 3, resident); assert(rc==SQLITE_OK);
|
||||
rc = sqlite3_bind_int64(statement1, 4, active); assert(rc==SQLITE_OK);
|
||||
rc = sqlite3_bind_int64(statement1, 5, mapped); assert(rc==SQLITE_OK);
|
||||
rc = sqlite3_bind_int64(statement1, 6, metadata); assert(rc==SQLITE_OK);
|
||||
rc = sqlite3_bind_int64(statement1, 7, retained); assert(rc==SQLITE_OK);
|
||||
|
||||
assert(rc==SQLITE_OK);
|
||||
SAFE_SQLITE3_STEP2(statement1);
|
||||
rc=sqlite3_clear_bindings(statement1); assert(rc==SQLITE_OK);
|
||||
rc=sqlite3_reset(statement1);
|
||||
sqlite3_finalize(statement1);
|
||||
|
||||
SQLite3_result *resultset = NULL;
|
||||
int cols;
|
||||
int affected_rows;
|
||||
char *error = NULL;
|
||||
char *query = (char *)"SELECT MAX(timestamp) FROM system_memory";
|
||||
statsdb_disk->execute_statement(query, &error , &cols , &affected_rows , &resultset);
|
||||
if (error) {
|
||||
if (resultset) {
|
||||
delete resultset;
|
||||
resultset = NULL;
|
||||
}
|
||||
free(error);
|
||||
} else {
|
||||
char buf[256];
|
||||
if (resultset->rows_count == 0) {
|
||||
sprintf(buf,"INSERT INTO system_memory_hour SELECT timestamp/3600 , AVG(allocated), AVG(resident), AVG(active), AVG(mapped), AVG(metadata), AVG(retained) FROM system_memory WHERE timestamp < %ld GROUP BY timestamp/3600", (ts/3600)*3600);
|
||||
statsdb_disk->execute(buf);
|
||||
} else {
|
||||
SQLite3_row *r = resultset->rows[0];
|
||||
time_t t = atol(r->fields[0]);
|
||||
if (ts >= t + 3600) {
|
||||
sprintf(buf,"INSERT INTO system_memory_hour SELECT timestamp/3600 , AVG(allocated), AVG(resident), AVG(active), AVG(mapped), AVG(metadata), AVG(retained) FROM system_memory WHERE timestamp >= %ld AND timestamp < %ld GROUP BY timestamp/3600", t+3600 , (ts/3600)*3600);
|
||||
statsdb_disk->execute(buf);
|
||||
}
|
||||
}
|
||||
delete resultset;
|
||||
resultset = NULL;
|
||||
sprintf(buf,"DELETE FROM system_memory WHERE timestamp < %ld", ts - 3600*24*7);
|
||||
statsdb_disk->execute(buf);
|
||||
sprintf(buf,"DELETE FROM system_memory_hour WHERE timestamp < %ld", ts - 3600*24*365);
|
||||
statsdb_disk->execute(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProxySQL_Statistics::MySQL_Threads_Handler_sets(SQLite3_result *resultset) {
|
||||
int rc;
|
||||
if (resultset == NULL)
|
||||
return;
|
||||
sqlite3 *mydb3=statsdb_disk->get_db();
|
||||
sqlite3_stmt *statement1=NULL;
|
||||
//sqlite3_stmt *statement2=NULL;
|
||||
//sqlite3_stmt *statement3=NULL;
|
||||
char *query1=NULL;
|
||||
//char *query2=NULL;
|
||||
//char *query3=NULL;
|
||||
query1=(char *)"INSERT INTO mysql_connections VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12)";
|
||||
rc=sqlite3_prepare_v2(mydb3, query1, -1, &statement1, 0);
|
||||
assert(rc==SQLITE_OK);
|
||||
//rc=sqlite3_prepare_v2(mydb3, query2, -1, &statement2, 0);
|
||||
//assert(rc==SQLITE_OK);
|
||||
//rc=sqlite3_prepare_v2(mydb3, query3, -1, &statement3, 0);
|
||||
//assert(rc==SQLITE_OK);
|
||||
|
||||
|
||||
int mysql_connections_values[12];
|
||||
for (int i=0; i<12; i++) {
|
||||
mysql_connections_values[i]=0;
|
||||
}
|
||||
mysql_connections_values[0] = time(NULL);
|
||||
|
||||
for (std::vector<SQLite3_row *>::iterator it = resultset->rows.begin() ; it != resultset->rows.end(); ++it) {
|
||||
SQLite3_row *r1=*it;
|
||||
if (!strcasecmp(r1->fields[0],"Client_Connections_aborted")) {
|
||||
mysql_connections_values[1]=atoi(r1->fields[1]);
|
||||
continue;
|
||||
}
|
||||
if (!strcasecmp(r1->fields[0],"Client_Connections_connected")) {
|
||||
mysql_connections_values[2]=atoi(r1->fields[1]);
|
||||
continue;
|
||||
}
|
||||
if (!strcasecmp(r1->fields[0],"Client_Connections_created")) {
|
||||
mysql_connections_values[3]=atoi(r1->fields[1]);
|
||||
continue;
|
||||
}
|
||||
if (!strcasecmp(r1->fields[0],"Server_Connections_aborted")) {
|
||||
mysql_connections_values[4]=atoi(r1->fields[1]);
|
||||
continue;
|
||||
}
|
||||
if (!strcasecmp(r1->fields[0],"Server_Connections_connected")) {
|
||||
mysql_connections_values[5]=atoi(r1->fields[1]);
|
||||
continue;
|
||||
}
|
||||
if (!strcasecmp(r1->fields[0],"Server_Connections_created")) {
|
||||
mysql_connections_values[6]=atoi(r1->fields[1]);
|
||||
continue;
|
||||
}
|
||||
if (!strcasecmp(r1->fields[0],"ConnPool_get_conn_failure")) {
|
||||
mysql_connections_values[7]=atoi(r1->fields[1]);
|
||||
continue;
|
||||
}
|
||||
if (!strcasecmp(r1->fields[0],"ConnPool_get_conn_immediate")) {
|
||||
mysql_connections_values[8]=atoi(r1->fields[1]);
|
||||
continue;
|
||||
}
|
||||
if (!strcasecmp(r1->fields[0],"ConnPool_get_conn_success")) {
|
||||
mysql_connections_values[9]=atoi(r1->fields[1]);
|
||||
continue;
|
||||
}
|
||||
if (!strcasecmp(r1->fields[0],"Questions")) {
|
||||
mysql_connections_values[10]=atoi(r1->fields[1]);
|
||||
continue;
|
||||
}
|
||||
if (!strcasecmp(r1->fields[0],"Slow_queries")) {
|
||||
mysql_connections_values[11]=atoi(r1->fields[1]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0; i<12; i++) {
|
||||
rc=sqlite3_bind_int64(statement1, i+1, mysql_connections_values[i]); assert(rc==SQLITE_OK);
|
||||
}
|
||||
|
||||
SAFE_SQLITE3_STEP2(statement1);
|
||||
rc=sqlite3_clear_bindings(statement1); assert(rc==SQLITE_OK);
|
||||
rc=sqlite3_reset(statement1); //assert(rc==SQLITE_OK);
|
||||
sqlite3_finalize(statement1);
|
||||
}
|
||||
Loading…
Reference in new issue