X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmysql.c;h=1bc0fdf77b8e4429090d292e7ccc77f54667cc33;hb=f8e1e81d433c5b4e06792c2617abf0e6ec9e76d9;hp=4c94732b6bcfde5af52d7bc609f36e484aceca9e;hpb=aacc2e30f17fa2e47ac8d2531ac69bb748304296;p=collectd.git diff --git a/src/mysql.c b/src/mysql.c index 4c94732b..1bc0fdf7 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -28,6 +28,7 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" #include "configfile.h" @@ -71,7 +72,7 @@ static void mysql_database_free (void *arg) /* {{{ */ DEBUG ("mysql plugin: mysql_database_free (arg = %p);", arg); - db = (mysql_database_t *) arg; + db = arg; if (db == NULL) return; @@ -103,7 +104,6 @@ static int mysql_config_database (oconfig_item_t *ci) /* {{{ */ { mysql_database_t *db; int status = 0; - int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) @@ -143,7 +143,7 @@ static int mysql_config_database (oconfig_item_t *ci) /* {{{ */ assert (db->instance != NULL); /* Fill the `mysql_database_t' structure.. */ - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -191,13 +191,12 @@ static int mysql_config_database (oconfig_item_t *ci) /* {{{ */ /* If all went well, register this database for reading */ if (status == 0) { - user_data_t ud; + user_data_t ud = { 0 }; char cb_name[DATA_MAX_NAME_LEN]; DEBUG ("mysql plugin: Registering new read callback: %s", (db->database != NULL) ? db->database : ""); - memset (&ud, 0, sizeof (ud)); ud.data = (void *) db; ud.free_func = mysql_database_free; @@ -222,13 +221,11 @@ static int mysql_config_database (oconfig_item_t *ci) /* {{{ */ static int mysql_config (oconfig_item_t *ci) /* {{{ */ { - int i; - if (ci == NULL) return (EINVAL); /* Fill the `mysql_database_t' structure.. */ - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -738,7 +735,7 @@ static int mysql_read (user_data_t *ud) key = row[0]; val = atoll (row[1]); - if (strncmp (key, "Com_", + if (strncmp (key, "Com_", strlen ("Com_")) == 0) { if (val == 0ULL) @@ -746,18 +743,18 @@ static int mysql_read (user_data_t *ud) /* Ignore `prepared statements' */ if (strncmp (key, "Com_stmt_", strlen ("Com_stmt_")) != 0) - counter_submit ("mysql_commands", - key + strlen ("Com_"), + counter_submit ("mysql_commands", + key + strlen ("Com_"), val, db); } - else if (strncmp (key, "Handler_", + else if (strncmp (key, "Handler_", strlen ("Handler_")) == 0) { if (val == 0ULL) continue; - counter_submit ("mysql_handler", - key + strlen ("Handler_"), + counter_submit ("mysql_handler", + key + strlen ("Handler_"), val, db); } else if (strncmp (key, "Qcache_", @@ -774,7 +771,7 @@ static int mysql_read (user_data_t *ud) else if (strcmp (key, "Qcache_queries_in_cache") == 0) qcache_queries_in_cache = (gauge_t) val; } - else if (strncmp (key, "Bytes_", + else if (strncmp (key, "Bytes_", strlen ("Bytes_")) == 0) { if (strcmp (key, "Bytes_received") == 0) @@ -782,7 +779,7 @@ static int mysql_read (user_data_t *ud) else if (strcmp (key, "Bytes_sent") == 0) traffic_outgoing += val; } - else if (strncmp (key, "Threads_", + else if (strncmp (key, "Threads_", strlen ("Threads_")) == 0) { if (strcmp (key, "Threads_running") == 0) @@ -902,7 +899,11 @@ static int mysql_read (user_data_t *ud) counter_submit ("mysql_sort", "range", val, db); else if (strcmp (key, "Sort_scan") == 0) counter_submit ("mysql_sort", "scan", val, db); - + + } + else if (strncmp (key, "Slow_queries", strlen ("Slow_queries")) == 0) + { + counter_submit ("mysql_slow_queries", NULL , val, db); } } mysql_free_result (res); res = NULL;