X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmysql.c;h=a2394137532d8fe54560eb1bc69a30d99b6357d5;hb=a8c59c6d75efe3656b2f019ddefb2ce6cb2cbb2e;hp=029796e6c5045852f56a9fd60c39f36a517ce5d0;hpb=1ebf2f31bd2e080e6f42de640f0a3899a61501c0;p=collectd.git diff --git a/src/mysql.c b/src/mysql.c index 029796e6..a2394137 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,7 @@ 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); - + } } mysql_free_result (res); res = NULL;