Export MySQL_Logger metrics

v2.x-logging_mem_2
René Cannaò 1 year ago
parent 6a8fb6cdab
commit 1ff3974e30

@ -1367,14 +1367,14 @@ int MySQL_Logger::processEvents(SQLite3DB * statsdb , SQLite3DB * statsdb_disk)
delete event;
}
size_t ret = events.size();
#if 1 // FIXME: TEMPORARY , TO REMOVE
#if 0
std::cerr << "Circular:" << endl;
std::cerr << " EventsAddedCount: " << MyLogCB->getEventsAddedCount() << endl;
std::cerr << " EventsDroppedCount: " << MyLogCB->getEventsDroppedCount() << endl;
std::cerr << " Size: " << MyLogCB->size() << endl;
std::cerr << "memoryCopy: Count: " << metrics.memoryCopyCount << " , TimeUs: " << metrics.totalMemoryCopyTimeMicros << endl;
std::cerr << "diskCopy: Count: " << metrics.diskCopyCount << " , TimeUs: " << metrics.totalDiskCopyTimeMicros << endl;
#endif // 1 , FIXME: TEMPORARY , TO REMOVE
#endif // 0
return ret;
}

@ -9932,6 +9932,17 @@ void ProxySQL_Admin::stats___mysql_global() {
statsdb->execute(query);
free(query);
}
if (GloMyLogger != nullptr) {
const string prefix = "MySQL_Logger-";
std::unordered_map<std::string, unsigned long long> metrics = GloMyLogger->getAllMetrics();
for (std::unordered_map<std::string, unsigned long long>::iterator it = metrics.begin(); it != metrics.end(); it++) {
unsigned int l = strlen(a) + prefix.length() + it->first.length() + 32;
char *query = (char *)malloc(l);
sprintf(query, a, string(prefix + it->first).c_str(),std::to_string(it->second).c_str());
statsdb->execute(query);
free(query);
}
}
statsdb->execute("COMMIT");
}

@ -0,0 +1,73 @@
/**
* @file test_empty_schemaname-t.cpp
* @brief Simple test checking that empty schemaname are properly handled by ProxySQL.
*/
#include "mysql.h"
#include "tap.h"
#include "command_line.h"
#include "utils.h"
uint32_t EXECUTIONS = 1000;
int main(int argc, char** argv) {
plan(1);
CommandLine cl;
if (cl.getEnv()) {
diag("Failed to get the required environmental variables.");
return EXIT_FAILURE;
}
for (uint32_t i = 0; i < EXECUTIONS; i++) {
{
MYSQL* proxy = mysql_init(NULL);
if (!mysql_real_connect(proxy, cl.host, "sbtest", "sbtest", "sbtest", cl.port, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy));
return EXIT_FAILURE;
}
mysql_query(proxy, "DO 1");
mysql_query(proxy, "USE ``");
mysql_query(proxy, "USE `` ");
mysql_query(proxy, "USE `` ");
mysql_query(proxy, "DO 1");
/*
mysql_close(proxy);
}
{
MYSQL* proxy = mysql_init(NULL);
if (!mysql_real_connect(proxy, cl.host, "sbtest", "sbtest", "` `", cl.port, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy));
return EXIT_FAILURE;
}
mysql_query(proxy, "DO 1");
*/
mysql_close(proxy);
}
}
/*
int exp_myerr = 1065;
int act_myerr = 0;
for (uint32_t i = 0; i < EXECUTIONS; i++) {
mysql_query(proxy, "");
act_myerr = mysql_errno(proxy);
if (exp_myerr != act_myerr) {
break;
}
}
ok(
exp_myerr == act_myerr, "MySQL error equals expected - exp_err: '%d', act_err: '%d' error: `%s`",
exp_myerr, act_myerr, mysql_error(proxy)
);
*/
//mysql_close(proxy);
return exit_status();
}
Loading…
Cancel
Save