|
|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
#include <thread>
|
|
|
|
|
#include "proxysql.h"
|
|
|
|
|
#include "cpp.h"
|
|
|
|
|
|
|
|
|
|
@ -15,7 +16,6 @@ extern MySQL_Threads_Handler *GloMTH;
|
|
|
|
|
MySQL_Monitor::MySQL_Monitor() {
|
|
|
|
|
|
|
|
|
|
shutdown=false;
|
|
|
|
|
|
|
|
|
|
// create new SQLite datatabase
|
|
|
|
|
monitordb = new SQLite3DB();
|
|
|
|
|
monitordb->open((char *)"file:mem_monitordb?mode=memory&cache=shared", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX);
|
|
|
|
|
@ -30,11 +30,6 @@ MySQL_Monitor::MySQL_Monitor() {
|
|
|
|
|
// create monitoring tables
|
|
|
|
|
check_and_build_standard_tables(monitordb, tables_defs_monitor);
|
|
|
|
|
|
|
|
|
|
// initialize the MySQL Thread (note: this is not a real thread, just the structures associated with it)
|
|
|
|
|
mysql_thr = new MySQL_Thread();
|
|
|
|
|
mysql_thr->curtime=monotonic_time();
|
|
|
|
|
MySQL_Monitor__thread_MySQL_Thread_Variables_version=GloMTH->get_global_version();
|
|
|
|
|
mysql_thr->refresh_variables();
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@ -42,7 +37,7 @@ MySQL_Monitor::~MySQL_Monitor() {
|
|
|
|
|
drop_tables_defs(tables_defs_monitor);
|
|
|
|
|
delete tables_defs_monitor;
|
|
|
|
|
delete monitordb;
|
|
|
|
|
delete mysql_thr;
|
|
|
|
|
//delete mysql_thr;
|
|
|
|
|
fprintf(stderr,"MySQL_Monitor destroyed\n");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@ -84,9 +79,57 @@ void MySQL_Monitor::check_and_build_standard_tables(SQLite3DB *db, std::vector<t
|
|
|
|
|
db->execute("PRAGMA foreign_keys = ON");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void * MySQL_Monitor::run() {
|
|
|
|
|
|
|
|
|
|
void * MySQL_Monitor::monitor_connect() {
|
|
|
|
|
// initialize the MySQL Thread (note: this is not a real thread, just the structures associated with it)
|
|
|
|
|
unsigned int MySQL_Monitor__thread_MySQL_Thread_Variables_version;
|
|
|
|
|
MySQL_Thread * mysql_thr = new MySQL_Thread();
|
|
|
|
|
mysql_thr->curtime=monotonic_time();
|
|
|
|
|
MySQL_Monitor__thread_MySQL_Thread_Variables_version=GloMTH->get_global_version();
|
|
|
|
|
mysql_thr->refresh_variables();
|
|
|
|
|
while (shutdown==false) {
|
|
|
|
|
unsigned int glover=GloMTH->get_global_version();
|
|
|
|
|
if (MySQL_Monitor__thread_MySQL_Thread_Variables_version < glover ) {
|
|
|
|
|
MySQL_Monitor__thread_MySQL_Thread_Variables_version=glover;
|
|
|
|
|
mysql_thr->refresh_variables();
|
|
|
|
|
fprintf(stderr,"MySQL_Monitor - CONNECT - refreshing variables\n");
|
|
|
|
|
}
|
|
|
|
|
fprintf(stderr,"MySQL_Monitor - CONNECT\n");
|
|
|
|
|
usleep(1000000);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void * MySQL_Monitor::monitor_ping() {
|
|
|
|
|
// initialize the MySQL Thread (note: this is not a real thread, just the structures associated with it)
|
|
|
|
|
unsigned int MySQL_Monitor__thread_MySQL_Thread_Variables_version;
|
|
|
|
|
MySQL_Thread * mysql_thr = new MySQL_Thread();
|
|
|
|
|
mysql_thr->curtime=monotonic_time();
|
|
|
|
|
MySQL_Monitor__thread_MySQL_Thread_Variables_version=GloMTH->get_global_version();
|
|
|
|
|
mysql_thr->refresh_variables();
|
|
|
|
|
while (shutdown==false) {
|
|
|
|
|
unsigned int glover=GloMTH->get_global_version();
|
|
|
|
|
if (MySQL_Monitor__thread_MySQL_Thread_Variables_version < glover ) {
|
|
|
|
|
MySQL_Monitor__thread_MySQL_Thread_Variables_version=glover;
|
|
|
|
|
mysql_thr->refresh_variables();
|
|
|
|
|
fprintf(stderr,"MySQL_Monitor - PING - refreshing variables\n");
|
|
|
|
|
}
|
|
|
|
|
fprintf(stderr,"MySQL_Monitor - PING\n");
|
|
|
|
|
usleep(1000000);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void * MySQL_Monitor::run() {
|
|
|
|
|
// initialize the MySQL Thread (note: this is not a real thread, just the structures associated with it)
|
|
|
|
|
unsigned int MySQL_Monitor__thread_MySQL_Thread_Variables_version;
|
|
|
|
|
MySQL_Thread * mysql_thr = new MySQL_Thread();
|
|
|
|
|
mysql_thr->curtime=monotonic_time();
|
|
|
|
|
MySQL_Monitor__thread_MySQL_Thread_Variables_version=GloMTH->get_global_version();
|
|
|
|
|
mysql_thr->refresh_variables();
|
|
|
|
|
std::thread * monitor_connect_thread = new std::thread(&MySQL_Monitor::monitor_connect,this);
|
|
|
|
|
std::thread * monitor_ping_thread = new std::thread(&MySQL_Monitor::monitor_ping,this);
|
|
|
|
|
while (shutdown==false) {
|
|
|
|
|
unsigned int glover=GloMTH->get_global_version();
|
|
|
|
|
if (MySQL_Monitor__thread_MySQL_Thread_Variables_version < glover ) {
|
|
|
|
|
MySQL_Monitor__thread_MySQL_Thread_Variables_version=glover;
|
|
|
|
|
@ -94,6 +137,9 @@ void * MySQL_Monitor::run() {
|
|
|
|
|
fprintf(stderr,"MySQL_Monitor refreshing variables\n");
|
|
|
|
|
}
|
|
|
|
|
fprintf(stderr,"MySQL_Monitor\n");
|
|
|
|
|
usleep(1000000);
|
|
|
|
|
}
|
|
|
|
|
monitor_connect_thread->join();
|
|
|
|
|
monitor_ping_thread->join();
|
|
|
|
|
return NULL;
|
|
|
|
|
};
|
|
|
|
|
|