X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fmysql.c;h=aafd4dbdb662de7a96d2678b181f73ec71218850;hp=40707be364f8e0818decb3fbff5ad527a8f55a85;hb=48efd3deb4c9139fd060ff3d289896e9031bcc7c;hpb=7b0628b4f4688d48d89f94ca381ca6340da05b37 diff --git a/src/mysql.c b/src/mysql.c index 40707be3..aafd4dbd 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -29,8 +29,8 @@ #include "collectd.h" -#include "common.h" #include "plugin.h" +#include "utils/common/common.h" #ifdef HAVE_MYSQL_H #include @@ -218,14 +218,15 @@ static int mysql_config_database(oconfig_item_t *ci) /* {{{ */ (db->database != NULL) ? db->database : ""); if (db->instance != NULL) - snprintf(cb_name, sizeof(cb_name), "mysql-%s", db->instance); + ssnprintf(cb_name, sizeof(cb_name), "mysql-%s", db->instance); else sstrncpy(cb_name, "mysql", sizeof(cb_name)); plugin_register_complex_read( /* group = */ NULL, cb_name, mysql_read, /* interval = */ 0, &(user_data_t){ - .data = db, .free_func = mysql_database_free, + .data = db, + .free_func = mysql_database_free, }); } else { mysql_database_free(db); @@ -354,7 +355,8 @@ static void derive_submit(const char *type, const char *type_instance, static void traffic_submit(derive_t rx, derive_t tx, mysql_database_t *db) { value_t values[] = { - {.derive = rx}, {.derive = tx}, + {.derive = rx}, + {.derive = tx}, }; submit("mysql_octets", NULL, values, STATIC_ARRAY_SIZE(values), db); @@ -363,7 +365,7 @@ static void traffic_submit(derive_t rx, derive_t tx, mysql_database_t *db) { static MYSQL_RES *exec_query(MYSQL *con, const char *query) { MYSQL_RES *res; - int query_len = strlen(query); + size_t query_len = strlen(query); if (mysql_real_query(con, query, query_len)) { ERROR("mysql plugin: Failed to execute query: %s", mysql_error(con)); @@ -500,15 +502,15 @@ static int mysql_read_slave_stats(mysql_database_t *db, MYSQL *con) { if (((io == NULL) || (strcasecmp(io, "yes") != 0)) && (db->slave_io_running)) { n.severity = NOTIF_WARNING; - snprintf(n.message, sizeof(n.message), - "slave I/O thread not started or not connected to master"); + ssnprintf(n.message, sizeof(n.message), + "slave I/O thread not started or not connected to master"); plugin_dispatch_notification(&n); db->slave_io_running = false; } else if (((io != NULL) && (strcasecmp(io, "yes") == 0)) && (!db->slave_io_running)) { n.severity = NOTIF_OKAY; - snprintf(n.message, sizeof(n.message), - "slave I/O thread started and connected to master"); + ssnprintf(n.message, sizeof(n.message), + "slave I/O thread started and connected to master"); plugin_dispatch_notification(&n); db->slave_io_running = true; } @@ -516,13 +518,13 @@ static int mysql_read_slave_stats(mysql_database_t *db, MYSQL *con) { if (((sql == NULL) || (strcasecmp(sql, "yes") != 0)) && (db->slave_sql_running)) { n.severity = NOTIF_WARNING; - snprintf(n.message, sizeof(n.message), "slave SQL thread not started"); + ssnprintf(n.message, sizeof(n.message), "slave SQL thread not started"); plugin_dispatch_notification(&n); db->slave_sql_running = false; } else if (((sql != NULL) && (strcasecmp(sql, "yes") == 0)) && (!db->slave_sql_running)) { n.severity = NOTIF_OKAY; - snprintf(n.message, sizeof(n.message), "slave SQL thread started"); + ssnprintf(n.message, sizeof(n.message), "slave SQL thread started"); plugin_dispatch_notification(&n); db->slave_sql_running = true; } @@ -905,6 +907,8 @@ static int mysql_read(user_data_t *ud) { } else if (strncmp(key, "Slow_queries", strlen("Slow_queries")) == 0) { derive_submit("mysql_slow_queries", NULL, val, db); + } else if (strcmp(key, "Uptime") == 0) { + gauge_submit("uptime", NULL, val, db); } } mysql_free_result(res);