X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmysql.c;h=9b8d6cf3aba8c97117f50e7c934fd008f44b8b33;hb=73a6f82a63747f088352a61e201beac2d185b2ac;hp=029796e6c5045852f56a9fd60c39f36a517ce5d0;hpb=1ebf2f31bd2e080e6f42de640f0a3899a61501c0;p=collectd.git diff --git a/src/mysql.c b/src/mysql.c index 029796e6..9b8d6cf3 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -113,13 +113,12 @@ static int mysql_config_database (oconfig_item_t *ci) /* {{{ */ return (-1); } - db = malloc (sizeof (*db)); + db = calloc (1, sizeof (*db)); if (db == NULL) { - ERROR ("mysql plugin: malloc failed."); + ERROR ("mysql plugin: calloc failed."); return (-1); } - memset (db, 0, sizeof (*db)); /* initialize all the pointers */ db->alias = NULL; @@ -739,7 +738,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) @@ -747,18 +746,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_", @@ -775,7 +774,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) @@ -783,7 +782,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) @@ -903,7 +902,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;