2 * collectd - src/mysql.c
3 * Copyright (C) 2006-2010 Florian octo Forster
4 * Copyright (C) 2008 Mirko Buffoni
5 * Copyright (C) 2009 Doug MacEachern
6 * Copyright (C) 2009 Sebastian tokkee Harl
7 * Copyright (C) 2009 Rodolphe QuiƩdeville
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; only version 2 of the License is applicable.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 * Florian octo Forster <octo at collectd.org>
24 * Mirko Buffoni <briareos at eswat.org>
25 * Doug MacEachern <dougm at hyperic.com>
26 * Sebastian tokkee Harl <sh at tokkee.org>
27 * Rodolphe QuiƩdeville <rquiedeville at bearstech.com>
33 #include "configfile.h"
37 #elif defined(HAVE_MYSQL_MYSQL_H)
38 #include <mysql/mysql.h>
41 struct mysql_database_s /* {{{ */
58 _Bool slave_io_running;
59 _Bool slave_sql_running;
64 typedef struct mysql_database_s mysql_database_t; /* }}} */
66 static int mysql_read (user_data_t *ud);
68 static void mysql_database_free (void *arg) /* {{{ */
72 DEBUG ("mysql plugin: mysql_database_free (arg = %p);", arg);
80 mysql_close (db->con);
90 } /* }}} void mysql_database_free */
92 /* Configuration handling functions {{{
95 * <Database "plugin_instance1">
102 static int mysql_config_database (oconfig_item_t *ci) /* {{{ */
104 mysql_database_t *db;
108 if ((ci->values_num != 1)
109 || (ci->values[0].type != OCONFIG_TYPE_STRING))
111 WARNING ("mysql plugin: The `Database' block "
112 "needs exactly one string argument.");
116 db = calloc (1, sizeof (*db));
119 ERROR ("mysql plugin: calloc failed.");
123 /* initialize all the pointers */
133 /* trigger a notification, if it's not running */
134 db->slave_io_running = 1;
135 db->slave_sql_running = 1;
137 status = cf_util_get_string (ci, &db->instance);
143 assert (db->instance != NULL);
145 /* Fill the `mysql_database_t' structure.. */
146 for (i = 0; i < ci->children_num; i++)
148 oconfig_item_t *child = ci->children + i;
150 if (strcasecmp ("Alias", child->key) == 0)
151 status = cf_util_get_string (child, &db->alias);
152 else if (strcasecmp ("Host", child->key) == 0)
153 status = cf_util_get_string (child, &db->host);
154 else if (strcasecmp ("User", child->key) == 0)
155 status = cf_util_get_string (child, &db->user);
156 else if (strcasecmp ("Password", child->key) == 0)
157 status = cf_util_get_string (child, &db->pass);
158 else if (strcasecmp ("Port", child->key) == 0)
160 status = cf_util_get_port_number (child);
167 else if (strcasecmp ("Socket", child->key) == 0)
168 status = cf_util_get_string (child, &db->socket);
169 else if (strcasecmp ("Database", child->key) == 0)
170 status = cf_util_get_string (child, &db->database);
171 else if (strcasecmp ("ConnectTimeout", child->key) == 0)
172 status = cf_util_get_int (child, &db->timeout);
173 else if (strcasecmp ("MasterStats", child->key) == 0)
174 status = cf_util_get_boolean (child, &db->master_stats);
175 else if (strcasecmp ("SlaveStats", child->key) == 0)
176 status = cf_util_get_boolean (child, &db->slave_stats);
177 else if (strcasecmp ("SlaveNotifications", child->key) == 0)
178 status = cf_util_get_boolean (child, &db->slave_notif);
179 else if (strcasecmp ("InnodbStats", child->key) == 0)
180 status = cf_util_get_boolean (child, &db->innodb_stats);
183 WARNING ("mysql plugin: Option `%s' not allowed here.", child->key);
191 /* If all went well, register this database for reading */
194 user_data_t ud = { 0 };
195 char cb_name[DATA_MAX_NAME_LEN];
197 DEBUG ("mysql plugin: Registering new read callback: %s",
198 (db->database != NULL) ? db->database : "<default>");
200 ud.data = (void *) db;
201 ud.free_func = mysql_database_free;
203 if (db->instance != NULL)
204 ssnprintf (cb_name, sizeof (cb_name), "mysql-%s",
207 sstrncpy (cb_name, "mysql", sizeof (cb_name));
209 plugin_register_complex_read (/* group = */ NULL, cb_name,
211 /* interval = */ 0, &ud);
215 mysql_database_free (db);
220 } /* }}} int mysql_config_database */
222 static int mysql_config (oconfig_item_t *ci) /* {{{ */
229 /* Fill the `mysql_database_t' structure.. */
230 for (i = 0; i < ci->children_num; i++)
232 oconfig_item_t *child = ci->children + i;
234 if (strcasecmp ("Database", child->key) == 0)
235 mysql_config_database (child);
237 WARNING ("mysql plugin: Option \"%s\" not allowed here.",
242 } /* }}} int mysql_config */
244 /* }}} End of configuration handling functions */
246 static MYSQL *getconnection (mysql_database_t *db)
248 if (db->is_connected)
252 status = mysql_ping (db->con);
256 WARNING ("mysql plugin: Lost connection to instance \"%s\": %s",
257 db->instance, mysql_error (db->con));
259 db->is_connected = 0;
263 db->con = mysql_init (NULL);
266 ERROR ("mysql plugin: mysql_init failed: %s",
267 mysql_error (db->con));
272 /* Configure TCP connect timeout (default: 0) */
273 db->con->options.connect_timeout = db->timeout;
275 if (mysql_real_connect (db->con, db->host, db->user, db->pass,
276 db->database, db->port, db->socket, 0) == NULL)
278 ERROR ("mysql plugin: Failed to connect to database %s "
280 (db->database != NULL) ? db->database : "<none>",
281 (db->host != NULL) ? db->host : "localhost",
282 mysql_error (db->con));
286 INFO ("mysql plugin: Successfully connected to database %s "
287 "at server %s (server version: %s, protocol version: %d)",
288 (db->database != NULL) ? db->database : "<none>",
289 mysql_get_host_info (db->con),
290 mysql_get_server_info (db->con),
291 mysql_get_proto_info (db->con));
293 db->is_connected = 1;
295 } /* static MYSQL *getconnection (mysql_database_t *db) */
297 static void set_host (mysql_database_t *db, char *buf, size_t buflen)
300 sstrncpy (buf, db->alias, buflen);
301 else if ((db->host == NULL)
302 || (strcmp ("", db->host) == 0)
303 || (strcmp ("127.0.0.1", db->host) == 0)
304 || (strcmp ("localhost", db->host) == 0))
305 sstrncpy (buf, hostname_g, buflen);
307 sstrncpy (buf, db->host, buflen);
308 } /* void set_host */
310 static void submit (const char *type, const char *type_instance,
311 value_t *values, size_t values_len, mysql_database_t *db)
313 value_list_t vl = VALUE_LIST_INIT;
316 vl.values_len = values_len;
318 set_host (db, vl.host, sizeof (vl.host));
320 sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin));
322 /* Assured by "mysql_config_database" */
323 assert (db->instance != NULL);
324 sstrncpy (vl.plugin_instance, db->instance, sizeof (vl.plugin_instance));
326 sstrncpy (vl.type, type, sizeof (vl.type));
327 if (type_instance != NULL)
328 sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
330 plugin_dispatch_values (&vl);
333 static void counter_submit (const char *type, const char *type_instance,
334 derive_t value, mysql_database_t *db)
338 values[0].derive = value;
339 submit (type, type_instance, values, STATIC_ARRAY_SIZE (values), db);
340 } /* void counter_submit */
342 static void gauge_submit (const char *type, const char *type_instance,
343 gauge_t value, mysql_database_t *db)
347 values[0].gauge = value;
348 submit (type, type_instance, values, STATIC_ARRAY_SIZE (values), db);
349 } /* void gauge_submit */
351 static void derive_submit (const char *type, const char *type_instance,
352 derive_t value, mysql_database_t *db)
356 values[0].derive = value;
357 submit (type, type_instance, values, STATIC_ARRAY_SIZE (values), db);
358 } /* void derive_submit */
360 static void traffic_submit (derive_t rx, derive_t tx, mysql_database_t *db)
364 values[0].derive = rx;
365 values[1].derive = tx;
367 submit ("mysql_octets", NULL, values, STATIC_ARRAY_SIZE (values), db);
368 } /* void traffic_submit */
370 static MYSQL_RES *exec_query (MYSQL *con, const char *query)
374 int query_len = strlen (query);
376 if (mysql_real_query (con, query, query_len))
378 ERROR ("mysql plugin: Failed to execute query: %s",
380 INFO ("mysql plugin: SQL query was: %s", query);
384 res = mysql_store_result (con);
387 ERROR ("mysql plugin: Failed to store query result: %s",
389 INFO ("mysql plugin: SQL query was: %s", query);
396 static int mysql_read_master_stats (mysql_database_t *db, MYSQL *con)
403 unsigned long long position;
405 query = "SHOW MASTER STATUS";
407 res = exec_query (con, query);
411 row = mysql_fetch_row (res);
414 ERROR ("mysql plugin: Failed to get master statistics: "
415 "`%s' did not return any rows.", query);
416 mysql_free_result (res);
420 field_num = mysql_num_fields (res);
423 ERROR ("mysql plugin: Failed to get master statistics: "
424 "`%s' returned less than two columns.", query);
425 mysql_free_result (res);
429 position = atoll (row[1]);
430 counter_submit ("mysql_log_position", "master-bin", position, db);
432 row = mysql_fetch_row (res);
434 WARNING ("mysql plugin: `%s' returned more than one row - "
435 "ignoring further results.", query);
437 mysql_free_result (res);
440 } /* mysql_read_master_stats */
442 static int mysql_read_slave_stats (mysql_database_t *db, MYSQL *con)
450 /* WTF? libmysqlclient does not seem to provide any means to
451 * translate a column name to a column index ... :-/ */
452 const int READ_MASTER_LOG_POS_IDX = 6;
453 const int SLAVE_IO_RUNNING_IDX = 10;
454 const int SLAVE_SQL_RUNNING_IDX = 11;
455 const int EXEC_MASTER_LOG_POS_IDX = 21;
456 const int SECONDS_BEHIND_MASTER_IDX = 32;
458 query = "SHOW SLAVE STATUS";
460 res = exec_query (con, query);
464 row = mysql_fetch_row (res);
467 ERROR ("mysql plugin: Failed to get slave statistics: "
468 "`%s' did not return any rows.", query);
469 mysql_free_result (res);
473 field_num = mysql_num_fields (res);
476 ERROR ("mysql plugin: Failed to get slave statistics: "
477 "`%s' returned less than 33 columns.", query);
478 mysql_free_result (res);
484 unsigned long long counter;
487 counter = atoll (row[READ_MASTER_LOG_POS_IDX]);
488 counter_submit ("mysql_log_position", "slave-read", counter, db);
490 counter = atoll (row[EXEC_MASTER_LOG_POS_IDX]);
491 counter_submit ("mysql_log_position", "slave-exec", counter, db);
493 if (row[SECONDS_BEHIND_MASTER_IDX] != NULL)
495 gauge = atof (row[SECONDS_BEHIND_MASTER_IDX]);
496 gauge_submit ("time_offset", NULL, gauge, db);
502 notification_t n = { 0, cdtime (), "", "",
503 "mysql", "", "time_offset", "", NULL };
507 io = row[SLAVE_IO_RUNNING_IDX];
508 sql = row[SLAVE_SQL_RUNNING_IDX];
510 set_host (db, n.host, sizeof (n.host));
512 /* Assured by "mysql_config_database" */
513 assert (db->instance != NULL);
514 sstrncpy (n.plugin_instance, db->instance, sizeof (n.plugin_instance));
516 if (((io == NULL) || (strcasecmp (io, "yes") != 0))
517 && (db->slave_io_running))
519 n.severity = NOTIF_WARNING;
520 ssnprintf (n.message, sizeof (n.message),
521 "slave I/O thread not started or not connected to master");
522 plugin_dispatch_notification (&n);
523 db->slave_io_running = 0;
525 else if (((io != NULL) && (strcasecmp (io, "yes") == 0))
526 && (! db->slave_io_running))
528 n.severity = NOTIF_OKAY;
529 ssnprintf (n.message, sizeof (n.message),
530 "slave I/O thread started and connected to master");
531 plugin_dispatch_notification (&n);
532 db->slave_io_running = 1;
535 if (((sql == NULL) || (strcasecmp (sql, "yes") != 0))
536 && (db->slave_sql_running))
538 n.severity = NOTIF_WARNING;
539 ssnprintf (n.message, sizeof (n.message),
540 "slave SQL thread not started");
541 plugin_dispatch_notification (&n);
542 db->slave_sql_running = 0;
544 else if (((sql != NULL) && (strcasecmp (sql, "yes") == 0))
545 && (! db->slave_sql_running))
547 n.severity = NOTIF_OKAY;
548 ssnprintf (n.message, sizeof (n.message),
549 "slave SQL thread started");
550 plugin_dispatch_notification (&n);
551 db->slave_sql_running = 1;
555 row = mysql_fetch_row (res);
557 WARNING ("mysql plugin: `%s' returned more than one row - "
558 "ignoring further results.", query);
560 mysql_free_result (res);
563 } /* mysql_read_slave_stats */
565 static int mysql_read_innodb_stats (mysql_database_t *db, MYSQL *con)
576 { "metadata_mem_pool_size", "bytes", DS_TYPE_GAUGE },
577 { "lock_deadlocks", "mysql_locks", DS_TYPE_DERIVE },
578 { "lock_timeouts", "mysql_locks", DS_TYPE_DERIVE },
579 { "lock_row_lock_current_waits", "mysql_locks", DS_TYPE_DERIVE },
580 { "buffer_pool_size", "bytes", DS_TYPE_GAUGE },
582 { "buffer_pool_reads", "operations", DS_TYPE_DERIVE },
583 { "buffer_pool_read_requests", "operations", DS_TYPE_DERIVE },
584 { "buffer_pool_write_requests", "operations", DS_TYPE_DERIVE },
585 { "buffer_pool_wait_free", "operations", DS_TYPE_DERIVE },
586 { "buffer_pool_read_ahead", "operations", DS_TYPE_DERIVE },
587 { "buffer_pool_read_ahead_evicted", "operations", DS_TYPE_DERIVE },
589 { "buffer_pool_pages_total", "gauge", DS_TYPE_GAUGE },
590 { "buffer_pool_pages_misc", "gauge", DS_TYPE_GAUGE },
591 { "buffer_pool_pages_data", "gauge", DS_TYPE_GAUGE },
592 { "buffer_pool_bytes_data", "gauge", DS_TYPE_GAUGE },
593 { "buffer_pool_pages_dirty", "gauge", DS_TYPE_GAUGE },
594 { "buffer_pool_bytes_dirty", "gauge", DS_TYPE_GAUGE },
595 { "buffer_pool_pages_free", "gauge", DS_TYPE_GAUGE },
597 { "buffer_pages_created", "operations", DS_TYPE_DERIVE },
598 { "buffer_pages_written", "operations", DS_TYPE_DERIVE },
599 { "buffer_pages_read", "operations", DS_TYPE_DERIVE },
600 { "buffer_data_reads", "operations", DS_TYPE_DERIVE },
601 { "buffer_data_written", "operations", DS_TYPE_DERIVE },
603 { "os_data_reads", "operations", DS_TYPE_DERIVE },
604 { "os_data_writes", "operations", DS_TYPE_DERIVE },
605 { "os_data_fsyncs", "operations", DS_TYPE_DERIVE },
606 { "os_log_bytes_written", "operations", DS_TYPE_DERIVE },
607 { "os_log_fsyncs", "operations", DS_TYPE_DERIVE },
608 { "os_log_pending_fsyncs", "operations", DS_TYPE_DERIVE },
609 { "os_log_pending_writes", "operations", DS_TYPE_DERIVE },
611 { "trx_rseg_history_len", "gauge", DS_TYPE_GAUGE },
613 { "log_waits", "operations", DS_TYPE_DERIVE },
614 { "log_write_requests", "operations", DS_TYPE_DERIVE },
615 { "log_writes", "operations", DS_TYPE_DERIVE },
616 { "adaptive_hash_searches", "operations", DS_TYPE_DERIVE },
618 { "file_num_open_files", "gauge", DS_TYPE_GAUGE },
620 { "ibuf_merges_insert", "operations", DS_TYPE_DERIVE },
621 { "ibuf_merges_delete_mark", "operations", DS_TYPE_DERIVE },
622 { "ibuf_merges_delete", "operations", DS_TYPE_DERIVE },
623 { "ibuf_merges_discard_insert", "operations", DS_TYPE_DERIVE },
624 { "ibuf_merges_discard_delete_mark", "operations", DS_TYPE_DERIVE },
625 { "ibuf_merges_discard_delete", "operations", DS_TYPE_DERIVE },
626 { "ibuf_merges_discard_merges", "operations", DS_TYPE_DERIVE },
627 { "ibuf_size", "bytes", DS_TYPE_GAUGE },
629 { "innodb_activity_count", "gauge", DS_TYPE_GAUGE },
630 { "innodb_dblwr_writes", "operations", DS_TYPE_DERIVE },
631 { "innodb_dblwr_pages_written", "operations", DS_TYPE_DERIVE },
632 { "innodb_dblwr_page_size", "gauge", DS_TYPE_GAUGE },
634 { "innodb_rwlock_s_spin_waits", "operations", DS_TYPE_DERIVE },
635 { "innodb_rwlock_x_spin_waits", "operations", DS_TYPE_DERIVE },
636 { "innodb_rwlock_s_spin_rounds", "operations", DS_TYPE_DERIVE },
637 { "innodb_rwlock_x_spin_rounds", "operations", DS_TYPE_DERIVE },
638 { "innodb_rwlock_s_os_waits", "operations", DS_TYPE_DERIVE },
639 { "innodb_rwlock_x_os_waits", "operations", DS_TYPE_DERIVE },
641 { "dml_reads", "operations", DS_TYPE_DERIVE },
642 { "dml_inserts", "operations", DS_TYPE_DERIVE },
643 { "dml_deletes", "operations", DS_TYPE_DERIVE },
644 { "dml_updates", "operations", DS_TYPE_DERIVE },
649 query = "SELECT name, count, type FROM information_schema.innodb_metrics WHERE status = 'enabled'";
651 res = exec_query (con, query);
655 while ((row = mysql_fetch_row (res)))
659 unsigned long long val;
662 val = atoll (row[1]);
664 for (i = 0; metrics[i].key != NULL && strcmp(metrics[i].key, key) != 0; i++)
667 if (metrics[i].key == NULL)
670 switch (metrics[i].ds_type) {
671 case DS_TYPE_COUNTER:
672 counter_submit(metrics[i].type, key, (counter_t)val, db);
675 gauge_submit(metrics[i].type, key, (gauge_t)val, db);
678 derive_submit(metrics[i].type, key, (derive_t)val, db);
683 mysql_free_result(res);
687 static int mysql_read (user_data_t *ud)
689 mysql_database_t *db;
695 derive_t qcache_hits = 0;
696 derive_t qcache_inserts = 0;
697 derive_t qcache_not_cached = 0;
698 derive_t qcache_lowmem_prunes = 0;
699 gauge_t qcache_queries_in_cache = NAN;
701 gauge_t threads_running = NAN;
702 gauge_t threads_connected = NAN;
703 gauge_t threads_cached = NAN;
704 derive_t threads_created = 0;
706 unsigned long long traffic_incoming = 0ULL;
707 unsigned long long traffic_outgoing = 0ULL;
708 unsigned long mysql_version = 0ULL;
710 if ((ud == NULL) || (ud->data == NULL))
712 ERROR ("mysql plugin: mysql_database_read: Invalid user data.");
716 db = (mysql_database_t *) ud->data;
718 /* An error message will have been printed in this case */
719 if ((con = getconnection (db)) == NULL)
722 mysql_version = mysql_get_server_version(con);
724 query = "SHOW STATUS";
725 if (mysql_version >= 50002)
726 query = "SHOW GLOBAL STATUS";
728 res = exec_query (con, query);
732 while ((row = mysql_fetch_row (res)))
735 unsigned long long val;
738 val = atoll (row[1]);
740 if (strncmp (key, "Com_",
741 strlen ("Com_")) == 0)
746 /* Ignore `prepared statements' */
747 if (strncmp (key, "Com_stmt_", strlen ("Com_stmt_")) != 0)
748 counter_submit ("mysql_commands",
749 key + strlen ("Com_"),
752 else if (strncmp (key, "Handler_",
753 strlen ("Handler_")) == 0)
758 counter_submit ("mysql_handler",
759 key + strlen ("Handler_"),
762 else if (strncmp (key, "Qcache_",
763 strlen ("Qcache_")) == 0)
765 if (strcmp (key, "Qcache_hits") == 0)
766 qcache_hits = (derive_t) val;
767 else if (strcmp (key, "Qcache_inserts") == 0)
768 qcache_inserts = (derive_t) val;
769 else if (strcmp (key, "Qcache_not_cached") == 0)
770 qcache_not_cached = (derive_t) val;
771 else if (strcmp (key, "Qcache_lowmem_prunes") == 0)
772 qcache_lowmem_prunes = (derive_t) val;
773 else if (strcmp (key, "Qcache_queries_in_cache") == 0)
774 qcache_queries_in_cache = (gauge_t) val;
776 else if (strncmp (key, "Bytes_",
777 strlen ("Bytes_")) == 0)
779 if (strcmp (key, "Bytes_received") == 0)
780 traffic_incoming += val;
781 else if (strcmp (key, "Bytes_sent") == 0)
782 traffic_outgoing += val;
784 else if (strncmp (key, "Threads_",
785 strlen ("Threads_")) == 0)
787 if (strcmp (key, "Threads_running") == 0)
788 threads_running = (gauge_t) val;
789 else if (strcmp (key, "Threads_connected") == 0)
790 threads_connected = (gauge_t) val;
791 else if (strcmp (key, "Threads_cached") == 0)
792 threads_cached = (gauge_t) val;
793 else if (strcmp (key, "Threads_created") == 0)
794 threads_created = (derive_t) val;
796 else if (strncmp (key, "Table_locks_",
797 strlen ("Table_locks_")) == 0)
799 counter_submit ("mysql_locks",
800 key + strlen ("Table_locks_"),
803 else if (db->innodb_stats && strncmp (key, "Innodb_", strlen ("Innodb_")) == 0)
806 if (strcmp (key, "Innodb_buffer_pool_pages_data") == 0)
807 gauge_submit ("mysql_bpool_pages", "data", val, db);
808 else if (strcmp (key, "Innodb_buffer_pool_pages_dirty") == 0)
809 gauge_submit ("mysql_bpool_pages", "dirty", val, db);
810 else if (strcmp (key, "Innodb_buffer_pool_pages_flushed") == 0)
811 counter_submit ("mysql_bpool_counters", "pages_flushed", val, db);
812 else if (strcmp (key, "Innodb_buffer_pool_pages_free") == 0)
813 gauge_submit ("mysql_bpool_pages", "free", val, db);
814 else if (strcmp (key, "Innodb_buffer_pool_pages_misc") == 0)
815 gauge_submit ("mysql_bpool_pages", "misc", val, db);
816 else if (strcmp (key, "Innodb_buffer_pool_pages_total") == 0)
817 gauge_submit ("mysql_bpool_pages", "total", val, db);
818 else if (strcmp (key, "Innodb_buffer_pool_read_ahead_rnd") == 0)
819 counter_submit ("mysql_bpool_counters", "read_ahead_rnd", val, db);
820 else if (strcmp (key, "Innodb_buffer_pool_read_ahead") == 0)
821 counter_submit ("mysql_bpool_counters", "read_ahead", val, db);
822 else if (strcmp (key, "Innodb_buffer_pool_read_ahead_evicted") == 0)
823 counter_submit ("mysql_bpool_counters", "read_ahead_evicted", val, db);
824 else if (strcmp (key, "Innodb_buffer_pool_read_requests") == 0)
825 counter_submit ("mysql_bpool_counters", "read_requests", val, db);
826 else if (strcmp (key, "Innodb_buffer_pool_reads") == 0)
827 counter_submit ("mysql_bpool_counters", "reads", val, db);
828 else if (strcmp (key, "Innodb_buffer_pool_write_requests") == 0)
829 counter_submit ("mysql_bpool_counters", "write_requests", val, db);
830 else if (strcmp (key, "Innodb_buffer_pool_bytes_data") == 0)
831 gauge_submit ("mysql_bpool_bytes", "data", val, db);
832 else if (strcmp (key, "Innodb_buffer_pool_bytes_dirty") == 0)
833 gauge_submit ("mysql_bpool_bytes", "dirty", val, db);
836 if (strcmp (key, "Innodb_data_fsyncs") == 0)
837 counter_submit ("mysql_innodb_data", "fsyncs", val, db);
838 else if (strcmp (key, "Innodb_data_read") == 0)
839 counter_submit ("mysql_innodb_data", "read", val, db);
840 else if (strcmp (key, "Innodb_data_reads") == 0)
841 counter_submit ("mysql_innodb_data", "reads", val, db);
842 else if (strcmp (key, "Innodb_data_writes") == 0)
843 counter_submit ("mysql_innodb_data", "writes", val, db);
844 else if (strcmp (key, "Innodb_data_written") == 0)
845 counter_submit ("mysql_innodb_data", "written", val, db);
848 else if (strcmp (key, "Innodb_dblwr_writes") == 0)
849 counter_submit ("mysql_innodb_dblwr", "writes", val, db);
850 else if (strcmp (key, "Innodb_dblwr_pages_written") == 0)
851 counter_submit ("mysql_innodb_dblwr", "written", val, db);
854 else if (strcmp (key, "Innodb_log_waits") == 0)
855 counter_submit ("mysql_innodb_log", "waits", val, db);
856 else if (strcmp (key, "Innodb_log_write_requests") == 0)
857 counter_submit ("mysql_innodb_log", "write_requests", val, db);
858 else if (strcmp (key, "Innodb_log_writes") == 0)
859 counter_submit ("mysql_innodb_log", "writes", val, db);
860 else if (strcmp (key, "Innodb_os_log_fsyncs") == 0)
861 counter_submit ("mysql_innodb_log", "fsyncs", val, db);
862 else if (strcmp (key, "Innodb_os_log_written") == 0)
863 counter_submit ("mysql_innodb_log", "written", val, db);
866 else if (strcmp (key, "Innodb_pages_created") == 0)
867 counter_submit ("mysql_innodb_pages", "created", val, db);
868 else if (strcmp (key, "Innodb_pages_read") == 0)
869 counter_submit ("mysql_innodb_pages", "read", val, db);
870 else if (strcmp (key, "Innodb_pages_written") == 0)
871 counter_submit ("mysql_innodb_pages", "written", val, db);
874 else if (strcmp (key, "Innodb_row_lock_time") == 0)
875 counter_submit ("mysql_innodb_row_lock", "time", val, db);
876 else if (strcmp (key, "Innodb_row_lock_waits") == 0)
877 counter_submit ("mysql_innodb_row_lock", "waits", val, db);
880 else if (strcmp (key, "Innodb_rows_deleted") == 0)
881 counter_submit ("mysql_innodb_rows", "deleted", val, db);
882 else if (strcmp (key, "Innodb_rows_inserted") == 0)
883 counter_submit ("mysql_innodb_rows", "inserted", val, db);
884 else if (strcmp (key, "Innodb_rows_read") == 0)
885 counter_submit ("mysql_innodb_rows", "read", val, db);
886 else if (strcmp (key, "Innodb_rows_updated") == 0)
887 counter_submit ("mysql_innodb_rows", "updated", val, db);
889 else if (strncmp (key, "Select_", strlen ("Select_")) == 0)
891 counter_submit ("mysql_select", key + strlen ("Select_"),
894 else if (strncmp (key, "Sort_", strlen ("Sort_")) == 0)
896 if (strcmp (key, "Sort_merge_passes") == 0)
897 counter_submit ("mysql_sort_merge_passes", NULL, val, db);
898 else if (strcmp (key, "Sort_rows") == 0)
899 counter_submit ("mysql_sort_rows", NULL, val, db);
900 else if (strcmp (key, "Sort_range") == 0)
901 counter_submit ("mysql_sort", "range", val, db);
902 else if (strcmp (key, "Sort_scan") == 0)
903 counter_submit ("mysql_sort", "scan", val, db);
906 else if (strncmp (key, "Slow_queries", strlen ("Slow_queries")) == 0)
908 counter_submit ("mysql_slow_queries", NULL , val, db);
911 mysql_free_result (res); res = NULL;
913 if ((qcache_hits != 0)
914 || (qcache_inserts != 0)
915 || (qcache_not_cached != 0)
916 || (qcache_lowmem_prunes != 0))
918 derive_submit ("cache_result", "qcache-hits",
920 derive_submit ("cache_result", "qcache-inserts",
922 derive_submit ("cache_result", "qcache-not_cached",
923 qcache_not_cached, db);
924 derive_submit ("cache_result", "qcache-prunes",
925 qcache_lowmem_prunes, db);
927 gauge_submit ("cache_size", "qcache",
928 qcache_queries_in_cache, db);
931 if (threads_created != 0)
933 gauge_submit ("threads", "running",
934 threads_running, db);
935 gauge_submit ("threads", "connected",
936 threads_connected, db);
937 gauge_submit ("threads", "cached",
940 derive_submit ("total_threads", "created",
941 threads_created, db);
944 traffic_submit (traffic_incoming, traffic_outgoing, db);
946 if (mysql_version >= 50600 && db->innodb_stats)
947 mysql_read_innodb_stats (db, con);
949 if (db->master_stats)
950 mysql_read_master_stats (db, con);
952 if ((db->slave_stats) || (db->slave_notif))
953 mysql_read_slave_stats (db, con);
956 } /* int mysql_read */
958 void module_register (void)
960 plugin_register_complex_config ("mysql", mysql_config);
961 } /* void module_register */