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 void mysql_read_default_options(struct st_mysql_options *options,
69 const char *filename,const char *group);
71 static void mysql_database_free (void *arg) /* {{{ */
75 DEBUG ("mysql plugin: mysql_database_free (arg = %p);", arg);
77 db = (mysql_database_t *) arg;
83 mysql_close (db->con);
93 } /* }}} void mysql_database_free */
95 /* Configuration handling functions {{{
98 * <Database "plugin_instance1">
105 static int mysql_config_database (oconfig_item_t *ci) /* {{{ */
107 mysql_database_t *db;
111 if ((ci->values_num != 1)
112 || (ci->values[0].type != OCONFIG_TYPE_STRING))
114 WARNING ("mysql plugin: The `Database' block "
115 "needs exactly one string argument.");
119 db = (mysql_database_t *) malloc (sizeof (*db));
122 ERROR ("mysql plugin: malloc failed.");
125 memset (db, 0, sizeof (*db));
127 /* initialize all the pointers */
137 /* trigger a notification, if it's not running */
138 db->slave_io_running = 1;
139 db->slave_sql_running = 1;
141 status = cf_util_get_string (ci, &db->instance);
147 assert (db->instance != NULL);
149 /* Fill the `mysql_database_t' structure.. */
150 for (i = 0; i < ci->children_num; i++)
152 oconfig_item_t *child = ci->children + i;
154 if (strcasecmp ("Alias", child->key) == 0)
155 status = cf_util_get_string (child, &db->alias);
156 else if (strcasecmp ("Host", child->key) == 0)
157 status = cf_util_get_string (child, &db->host);
158 else if (strcasecmp ("User", child->key) == 0)
159 status = cf_util_get_string (child, &db->user);
160 else if (strcasecmp ("Password", child->key) == 0)
161 status = cf_util_get_string (child, &db->pass);
162 else if (strcasecmp ("Port", child->key) == 0)
164 status = cf_util_get_port_number (child);
171 else if (strcasecmp ("Socket", child->key) == 0)
172 status = cf_util_get_string (child, &db->socket);
173 else if (strcasecmp ("Database", child->key) == 0)
174 status = cf_util_get_string (child, &db->database);
175 else if (strcasecmp ("ConnectTimeout", child->key) == 0)
176 status = cf_util_get_int (child, &db->timeout);
177 else if (strcasecmp ("MasterStats", child->key) == 0)
178 status = cf_util_get_boolean (child, &db->master_stats);
179 else if (strcasecmp ("SlaveStats", child->key) == 0)
180 status = cf_util_get_boolean (child, &db->slave_stats);
181 else if (strcasecmp ("SlaveNotifications", child->key) == 0)
182 status = cf_util_get_boolean (child, &db->slave_notif);
183 else if (strcasecmp ("InnodbStats", child->key) == 0)
184 status = cf_util_get_boolean (child, &db->innodb_stats);
187 WARNING ("mysql plugin: Option `%s' not allowed here.", child->key);
195 /* If all went well, register this database for reading */
199 char cb_name[DATA_MAX_NAME_LEN];
201 DEBUG ("mysql plugin: Registering new read callback: %s",
202 (db->database != NULL) ? db->database : "<default>");
204 memset (&ud, 0, sizeof (ud));
205 ud.data = (void *) db;
206 ud.free_func = mysql_database_free;
208 if (db->instance != NULL)
209 ssnprintf (cb_name, sizeof (cb_name), "mysql-%s",
212 sstrncpy (cb_name, "mysql", sizeof (cb_name));
214 plugin_register_complex_read (/* group = */ NULL, cb_name,
216 /* interval = */ 0, &ud);
220 mysql_database_free (db);
225 } /* }}} int mysql_config_database */
227 static int mysql_config (oconfig_item_t *ci) /* {{{ */
234 /* Fill the `mysql_database_t' structure.. */
235 for (i = 0; i < ci->children_num; i++)
237 oconfig_item_t *child = ci->children + i;
239 if (strcasecmp ("Database", child->key) == 0)
240 mysql_config_database (child);
242 WARNING ("mysql plugin: Option \"%s\" not allowed here.",
247 } /* }}} int mysql_config */
249 /* }}} End of configuration handling functions */
251 static MYSQL *getconnection (mysql_database_t *db)
253 if (db->is_connected)
257 status = mysql_ping (db->con);
261 WARNING ("mysql plugin: Lost connection to instance \"%s\": %s",
262 db->instance, mysql_error (db->con));
264 db->is_connected = 0;
268 db->con = mysql_init (NULL);
271 ERROR ("mysql plugin: mysql_init failed: %s",
272 mysql_error (db->con));
277 /* Configure TCP connect timeout (default: 0) */
278 db->con->options.connect_timeout = db->timeout;
280 if (mysql_real_connect (db->con, db->host, db->user, db->pass,
281 db->database, db->port, db->socket, 0) == NULL)
283 ERROR ("mysql plugin: Failed to connect to database %s "
285 (db->database != NULL) ? db->database : "<none>",
286 (db->host != NULL) ? db->host : "localhost",
287 mysql_error (db->con));
291 INFO ("mysql plugin: Successfully connected to database %s "
292 "at server %s (server version: %s, protocol version: %d)",
293 (db->database != NULL) ? db->database : "<none>",
294 mysql_get_host_info (db->con),
295 mysql_get_server_info (db->con),
296 mysql_get_proto_info (db->con));
298 db->is_connected = 1;
300 } /* static MYSQL *getconnection (mysql_database_t *db) */
302 static void set_host (mysql_database_t *db, char *buf, size_t buflen)
305 sstrncpy (buf, db->alias, buflen);
306 else if ((db->host == NULL)
307 || (strcmp ("", db->host) == 0)
308 || (strcmp ("127.0.0.1", db->host) == 0)
309 || (strcmp ("localhost", db->host) == 0))
310 sstrncpy (buf, hostname_g, buflen);
312 sstrncpy (buf, db->host, buflen);
313 } /* void set_host */
315 static void submit (const char *type, const char *type_instance,
316 value_t *values, size_t values_len, mysql_database_t *db)
318 value_list_t vl = VALUE_LIST_INIT;
321 vl.values_len = values_len;
323 set_host (db, vl.host, sizeof (vl.host));
325 sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin));
327 /* Assured by "mysql_config_database" */
328 assert (db->instance != NULL);
329 sstrncpy (vl.plugin_instance, db->instance, sizeof (vl.plugin_instance));
331 sstrncpy (vl.type, type, sizeof (vl.type));
332 if (type_instance != NULL)
333 sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
335 plugin_dispatch_values (&vl);
338 static void counter_submit (const char *type, const char *type_instance,
339 derive_t value, mysql_database_t *db)
343 values[0].derive = value;
344 submit (type, type_instance, values, STATIC_ARRAY_SIZE (values), db);
345 } /* void counter_submit */
347 static void gauge_submit (const char *type, const char *type_instance,
348 gauge_t value, mysql_database_t *db)
352 values[0].gauge = value;
353 submit (type, type_instance, values, STATIC_ARRAY_SIZE (values), db);
354 } /* void gauge_submit */
356 static void derive_submit (const char *type, const char *type_instance,
357 derive_t value, mysql_database_t *db)
361 values[0].derive = value;
362 submit (type, type_instance, values, STATIC_ARRAY_SIZE (values), db);
363 } /* void derive_submit */
365 static void traffic_submit (derive_t rx, derive_t tx, mysql_database_t *db)
369 values[0].derive = rx;
370 values[1].derive = tx;
372 submit ("mysql_octets", NULL, values, STATIC_ARRAY_SIZE (values), db);
373 } /* void traffic_submit */
375 static MYSQL_RES *exec_query (MYSQL *con, const char *query)
379 int query_len = strlen (query);
381 if (mysql_real_query (con, query, query_len))
383 ERROR ("mysql plugin: Failed to execute query: %s",
385 INFO ("mysql plugin: SQL query was: %s", query);
389 res = mysql_store_result (con);
392 ERROR ("mysql plugin: Failed to store query result: %s",
394 INFO ("mysql plugin: SQL query was: %s", query);
401 static int mysql_read_master_stats (mysql_database_t *db, MYSQL *con)
408 unsigned long long position;
410 query = "SHOW MASTER STATUS";
412 res = exec_query (con, query);
416 row = mysql_fetch_row (res);
419 ERROR ("mysql plugin: Failed to get master statistics: "
420 "`%s' did not return any rows.", query);
421 mysql_free_result (res);
425 field_num = mysql_num_fields (res);
428 ERROR ("mysql plugin: Failed to get master statistics: "
429 "`%s' returned less than two columns.", query);
430 mysql_free_result (res);
434 position = atoll (row[1]);
435 counter_submit ("mysql_log_position", "master-bin", position, db);
437 row = mysql_fetch_row (res);
439 WARNING ("mysql plugin: `%s' returned more than one row - "
440 "ignoring further results.", query);
442 mysql_free_result (res);
445 } /* mysql_read_master_stats */
447 static int mysql_read_slave_stats (mysql_database_t *db, MYSQL *con)
455 /* WTF? libmysqlclient does not seem to provide any means to
456 * translate a column name to a column index ... :-/ */
457 const int READ_MASTER_LOG_POS_IDX = 6;
458 const int SLAVE_IO_RUNNING_IDX = 10;
459 const int SLAVE_SQL_RUNNING_IDX = 11;
460 const int EXEC_MASTER_LOG_POS_IDX = 21;
461 const int SECONDS_BEHIND_MASTER_IDX = 32;
463 query = "SHOW SLAVE STATUS";
465 res = exec_query (con, query);
469 row = mysql_fetch_row (res);
472 ERROR ("mysql plugin: Failed to get slave statistics: "
473 "`%s' did not return any rows.", query);
474 mysql_free_result (res);
478 field_num = mysql_num_fields (res);
481 ERROR ("mysql plugin: Failed to get slave statistics: "
482 "`%s' returned less than 33 columns.", query);
483 mysql_free_result (res);
489 unsigned long long counter;
492 counter = atoll (row[READ_MASTER_LOG_POS_IDX]);
493 counter_submit ("mysql_log_position", "slave-read", counter, db);
495 counter = atoll (row[EXEC_MASTER_LOG_POS_IDX]);
496 counter_submit ("mysql_log_position", "slave-exec", counter, db);
498 if (row[SECONDS_BEHIND_MASTER_IDX] != NULL)
500 gauge = atof (row[SECONDS_BEHIND_MASTER_IDX]);
501 gauge_submit ("time_offset", NULL, gauge, db);
507 notification_t n = { 0, cdtime (), "", "",
508 "mysql", "", "time_offset", "", NULL };
512 io = row[SLAVE_IO_RUNNING_IDX];
513 sql = row[SLAVE_SQL_RUNNING_IDX];
515 set_host (db, n.host, sizeof (n.host));
517 /* Assured by "mysql_config_database" */
518 assert (db->instance != NULL);
519 sstrncpy (n.plugin_instance, db->instance, sizeof (n.plugin_instance));
521 if (((io == NULL) || (strcasecmp (io, "yes") != 0))
522 && (db->slave_io_running))
524 n.severity = NOTIF_WARNING;
525 ssnprintf (n.message, sizeof (n.message),
526 "slave I/O thread not started or not connected to master");
527 plugin_dispatch_notification (&n);
528 db->slave_io_running = 0;
530 else if (((io != NULL) && (strcasecmp (io, "yes") == 0))
531 && (! db->slave_io_running))
533 n.severity = NOTIF_OKAY;
534 ssnprintf (n.message, sizeof (n.message),
535 "slave I/O thread started and connected to master");
536 plugin_dispatch_notification (&n);
537 db->slave_io_running = 1;
540 if (((sql == NULL) || (strcasecmp (sql, "yes") != 0))
541 && (db->slave_sql_running))
543 n.severity = NOTIF_WARNING;
544 ssnprintf (n.message, sizeof (n.message),
545 "slave SQL thread not started");
546 plugin_dispatch_notification (&n);
547 db->slave_sql_running = 0;
549 else if (((sql != NULL) && (strcasecmp (sql, "yes") == 0))
550 && (! db->slave_sql_running))
552 n.severity = NOTIF_OKAY;
553 ssnprintf (n.message, sizeof (n.message),
554 "slave SQL thread started");
555 plugin_dispatch_notification (&n);
556 db->slave_sql_running = 1;
560 row = mysql_fetch_row (res);
562 WARNING ("mysql plugin: `%s' returned more than one row - "
563 "ignoring further results.", query);
565 mysql_free_result (res);
568 } /* mysql_read_slave_stats */
570 static int mysql_read_innodb_stats (mysql_database_t *db, MYSQL *con)
581 { "metadata_mem_pool_size", "bytes", DS_TYPE_GAUGE },
582 { "lock_deadlocks", "mysql_locks", DS_TYPE_DERIVE },
583 { "lock_timeouts", "mysql_locks", DS_TYPE_DERIVE },
584 { "lock_row_lock_current_waits", "mysql_locks", DS_TYPE_DERIVE },
585 { "buffer_pool_size", "bytes", DS_TYPE_GAUGE },
587 { "buffer_pool_reads", "operations", DS_TYPE_DERIVE },
588 { "buffer_pool_read_requests", "operations", DS_TYPE_DERIVE },
589 { "buffer_pool_write_requests", "operations", DS_TYPE_DERIVE },
590 { "buffer_pool_wait_free", "operations", DS_TYPE_DERIVE },
591 { "buffer_pool_read_ahead", "operations", DS_TYPE_DERIVE },
592 { "buffer_pool_read_ahead_evicted", "operations", DS_TYPE_DERIVE },
594 { "buffer_pool_pages_total", "gauge", DS_TYPE_GAUGE },
595 { "buffer_pool_pages_misc", "gauge", DS_TYPE_GAUGE },
596 { "buffer_pool_pages_data", "gauge", DS_TYPE_GAUGE },
597 { "buffer_pool_bytes_data", "gauge", DS_TYPE_GAUGE },
598 { "buffer_pool_pages_dirty", "gauge", DS_TYPE_GAUGE },
599 { "buffer_pool_bytes_dirty", "gauge", DS_TYPE_GAUGE },
600 { "buffer_pool_pages_free", "gauge", DS_TYPE_GAUGE },
602 { "buffer_pages_created", "operations", DS_TYPE_DERIVE },
603 { "buffer_pages_written", "operations", DS_TYPE_DERIVE },
604 { "buffer_pages_read", "operations", DS_TYPE_DERIVE },
605 { "buffer_data_reads", "operations", DS_TYPE_DERIVE },
606 { "buffer_data_written", "operations", DS_TYPE_DERIVE },
608 { "os_data_reads", "operations", DS_TYPE_DERIVE },
609 { "os_data_writes", "operations", DS_TYPE_DERIVE },
610 { "os_data_fsyncs", "operations", DS_TYPE_DERIVE },
611 { "os_log_bytes_written", "operations", DS_TYPE_DERIVE },
612 { "os_log_fsyncs", "operations", DS_TYPE_DERIVE },
613 { "os_log_pending_fsyncs", "operations", DS_TYPE_DERIVE },
614 { "os_log_pending_writes", "operations", DS_TYPE_DERIVE },
616 { "trx_rseg_history_len", "gauge", DS_TYPE_GAUGE },
618 { "log_waits", "operations", DS_TYPE_DERIVE },
619 { "log_write_requests", "operations", DS_TYPE_DERIVE },
620 { "log_writes", "operations", DS_TYPE_DERIVE },
621 { "adaptive_hash_searches", "operations", DS_TYPE_DERIVE },
623 { "file_num_open_files", "gauge", DS_TYPE_GAUGE },
625 { "ibuf_merges_insert", "operations", DS_TYPE_DERIVE },
626 { "ibuf_merges_delete_mark", "operations", DS_TYPE_DERIVE },
627 { "ibuf_merges_delete", "operations", DS_TYPE_DERIVE },
628 { "ibuf_merges_discard_insert", "operations", DS_TYPE_DERIVE },
629 { "ibuf_merges_discard_delete_mark","operations", DS_TYPE_DERIVE },
630 { "ibuf_merges_discard_delete", "operations", DS_TYPE_DERIVE },
631 { "ibuf_merges_discard_merges", "operations", DS_TYPE_DERIVE },
632 { "ibuf_size", "bytes", DS_TYPE_GAUGE },
634 { "innodb_activity_count", "gauge", DS_TYPE_GAUGE },
635 { "innodb_dblwr_writes", "operations", DS_TYPE_DERIVE },
636 { "innodb_dblwr_pages_written", "operations", DS_TYPE_DERIVE },
637 { "innodb_dblwr_page_size", "gauge", DS_TYPE_GAUGE },
639 { "innodb_rwlock_s_spin_waits", "operations", DS_TYPE_DERIVE },
640 { "innodb_rwlock_x_spin_waits", "operations", DS_TYPE_DERIVE },
641 { "innodb_rwlock_s_spin_rounds", "operations", DS_TYPE_DERIVE },
642 { "innodb_rwlock_x_spin_rounds", "operations", DS_TYPE_DERIVE },
643 { "innodb_rwlock_s_os_waits", "operations", DS_TYPE_DERIVE },
644 { "innodb_rwlock_x_os_waits", "operations", DS_TYPE_DERIVE },
646 { "dml_reads", "operations", DS_TYPE_DERIVE },
647 { "dml_inserts", "operations", DS_TYPE_DERIVE },
648 { "dml_deletes", "operations", DS_TYPE_DERIVE },
649 { "dml_updates", "operations", DS_TYPE_DERIVE },
654 query = "SELECT name, count, type FROM information_schema.innodb_metrics WHERE status = 'enabled'";
656 res = exec_query (con, query);
660 while ((row = mysql_fetch_row (res)))
664 unsigned long long val;
667 val = atoll (row[1]);
670 metrics[i].key != NULL && strcmp(metrics[i].key, key) != 0;
674 if (metrics[i].key == NULL)
677 switch (metrics[i].ds_type) {
678 case DS_TYPE_COUNTER:
679 counter_submit(metrics[i].type, key, (counter_t)val, db);
682 gauge_submit(metrics[i].type, key, (gauge_t)val, db);
685 derive_submit(metrics[i].type, key, (derive_t)val, db);
690 mysql_free_result(res);
694 static int mysql_read (user_data_t *ud)
696 mysql_database_t *db;
702 derive_t qcache_hits = 0;
703 derive_t qcache_inserts = 0;
704 derive_t qcache_not_cached = 0;
705 derive_t qcache_lowmem_prunes = 0;
706 gauge_t qcache_queries_in_cache = NAN;
708 gauge_t threads_running = NAN;
709 gauge_t threads_connected = NAN;
710 gauge_t threads_cached = NAN;
711 derive_t threads_created = 0;
713 unsigned long long traffic_incoming = 0ULL;
714 unsigned long long traffic_outgoing = 0ULL;
715 unsigned long mysql_version = 0ULL;
717 if ((ud == NULL) || (ud->data == NULL))
719 ERROR ("mysql plugin: mysql_database_read: Invalid user data.");
723 db = (mysql_database_t *) ud->data;
725 /* An error message will have been printed in this case */
726 if ((con = getconnection (db)) == NULL)
729 mysql_version = mysql_get_server_version(con);
731 query = "SHOW STATUS";
732 if (mysql_version >= 50002)
733 query = "SHOW GLOBAL STATUS";
735 res = exec_query (con, query);
739 while ((row = mysql_fetch_row (res)))
742 unsigned long long val;
745 val = atoll (row[1]);
747 if (strncmp (key, "Com_",
748 strlen ("Com_")) == 0)
753 /* Ignore `prepared statements' */
754 if (strncmp (key, "Com_stmt_", strlen ("Com_stmt_")) != 0)
755 counter_submit ("mysql_commands",
756 key + strlen ("Com_"),
759 else if (strncmp (key, "Handler_",
760 strlen ("Handler_")) == 0)
765 counter_submit ("mysql_handler",
766 key + strlen ("Handler_"),
769 else if (strncmp (key, "Qcache_",
770 strlen ("Qcache_")) == 0)
772 if (strcmp (key, "Qcache_hits") == 0)
773 qcache_hits = (derive_t) val;
774 else if (strcmp (key, "Qcache_inserts") == 0)
775 qcache_inserts = (derive_t) val;
776 else if (strcmp (key, "Qcache_not_cached") == 0)
777 qcache_not_cached = (derive_t) val;
778 else if (strcmp (key, "Qcache_lowmem_prunes") == 0)
779 qcache_lowmem_prunes = (derive_t) val;
780 else if (strcmp (key, "Qcache_queries_in_cache") == 0)
781 qcache_queries_in_cache = (gauge_t) val;
783 else if (strncmp (key, "Bytes_",
784 strlen ("Bytes_")) == 0)
786 if (strcmp (key, "Bytes_received") == 0)
787 traffic_incoming += val;
788 else if (strcmp (key, "Bytes_sent") == 0)
789 traffic_outgoing += val;
791 else if (strncmp (key, "Threads_",
792 strlen ("Threads_")) == 0)
794 if (strcmp (key, "Threads_running") == 0)
795 threads_running = (gauge_t) val;
796 else if (strcmp (key, "Threads_connected") == 0)
797 threads_connected = (gauge_t) val;
798 else if (strcmp (key, "Threads_cached") == 0)
799 threads_cached = (gauge_t) val;
800 else if (strcmp (key, "Threads_created") == 0)
801 threads_created = (derive_t) val;
803 else if (strncmp (key, "Table_locks_",
804 strlen ("Table_locks_")) == 0)
806 counter_submit ("mysql_locks",
807 key + strlen ("Table_locks_"),
810 else if (db->innodb_stats && strncmp (key, "Innodb_", strlen ("Innodb_")) == 0)
813 if (strcmp (key, "Innodb_buffer_pool_pages_data") == 0)
814 gauge_submit ("mysql_bpool_pages", "data", val, db);
815 else if (strcmp (key, "Innodb_buffer_pool_pages_dirty") == 0)
816 gauge_submit ("mysql_bpool_pages", "dirty", val, db);
817 else if (strcmp (key, "Innodb_buffer_pool_pages_flushed") == 0)
818 counter_submit ("mysql_bpool_counters", "pages_flushed", val, db);
819 else if (strcmp (key, "Innodb_buffer_pool_pages_free") == 0)
820 gauge_submit ("mysql_bpool_pages", "free", val, db);
821 else if (strcmp (key, "Innodb_buffer_pool_pages_misc") == 0)
822 gauge_submit ("mysql_bpool_pages", "misc", val, db);
823 else if (strcmp (key, "Innodb_buffer_pool_pages_total") == 0)
824 gauge_submit ("mysql_bpool_pages", "total", val, db);
825 else if (strcmp (key, "Innodb_buffer_pool_read_ahead_rnd") == 0)
826 counter_submit ("mysql_bpool_counters", "read_ahead_rnd", val, db);
827 else if (strcmp (key, "Innodb_buffer_pool_read_ahead") == 0)
828 counter_submit ("mysql_bpool_counters", "read_ahead", val, db);
829 else if (strcmp (key, "Innodb_buffer_pool_read_ahead_evicted") == 0)
830 counter_submit ("mysql_bpool_counters", "read_ahead_evicted", val, db);
831 else if (strcmp (key, "Innodb_buffer_pool_read_requests") == 0)
832 counter_submit ("mysql_bpool_counters", "read_requests", val, db);
833 else if (strcmp (key, "Innodb_buffer_pool_reads") == 0)
834 counter_submit ("mysql_bpool_counters", "reads", val, db);
835 else if (strcmp (key, "Innodb_buffer_pool_write_requests") == 0)
836 counter_submit ("mysql_bpool_counters", "write_requests", val, db);
837 else if (strcmp (key, "Innodb_buffer_pool_bytes_data") == 0)
838 gauge_submit ("mysql_bpool_bytes", "data", val, db);
839 else if (strcmp (key, "Innodb_buffer_pool_bytes_dirty") == 0)
840 gauge_submit ("mysql_bpool_bytes", "dirty", val, db);
843 if (strcmp (key, "Innodb_data_fsyncs") == 0)
844 counter_submit ("mysql_innodb_data", "fsyncs", val, db);
845 else if (strcmp (key, "Innodb_data_read") == 0)
846 counter_submit ("mysql_innodb_data", "read", val, db);
847 else if (strcmp (key, "Innodb_data_reads") == 0)
848 counter_submit ("mysql_innodb_data", "reads", val, db);
849 else if (strcmp (key, "Innodb_data_writes") == 0)
850 counter_submit ("mysql_innodb_data", "writes", val, db);
851 else if (strcmp (key, "Innodb_data_written") == 0)
852 counter_submit ("mysql_innodb_data", "written", val, db);
855 else if (strcmp (key, "Innodb_dblwr_writes") == 0)
856 counter_submit ("mysql_innodb_dblwr", "writes", val, db);
857 else if (strcmp (key, "Innodb_dblwr_pages_written") == 0)
858 counter_submit ("mysql_innodb_dblwr", "written", val, db);
861 else if (strcmp (key, "Innodb_log_waits") == 0)
862 counter_submit ("mysql_innodb_log", "waits", val, db);
863 else if (strcmp (key, "Innodb_log_write_requests") == 0)
864 counter_submit ("mysql_innodb_log", "write_requests", val, db);
865 else if (strcmp (key, "Innodb_log_writes") == 0)
866 counter_submit ("mysql_innodb_log", "writes", val, db);
867 else if (strcmp (key, "Innodb_os_log_fsyncs") == 0)
868 counter_submit ("mysql_innodb_log", "fsyncs", val, db);
869 else if (strcmp (key, "Innodb_os_log_written") == 0)
870 counter_submit ("mysql_innodb_log", "written", val, db);
873 else if (strcmp (key, "Innodb_pages_created") == 0)
874 counter_submit ("mysql_innodb_pages", "created", val, db);
875 else if (strcmp (key, "Innodb_pages_read") == 0)
876 counter_submit ("mysql_innodb_pages", "read", val, db);
877 else if (strcmp (key, "Innodb_pages_written") == 0)
878 counter_submit ("mysql_innodb_pages", "written", val, db);
881 else if (strcmp (key, "Innodb_row_lock_time") == 0)
882 counter_submit ("mysql_innodb_row_lock", "time", val, db);
883 else if (strcmp (key, "Innodb_row_lock_waits") == 0)
884 counter_submit ("mysql_innodb_row_lock", "waits", val, db);
887 else if (strcmp (key, "Innodb_rows_deleted") == 0)
888 counter_submit ("mysql_innodb_rows", "deleted", val, db);
889 else if (strcmp (key, "Innodb_rows_inserted") == 0)
890 counter_submit ("mysql_innodb_rows", "inserted", val, db);
891 else if (strcmp (key, "Innodb_rows_read") == 0)
892 counter_submit ("mysql_innodb_rows", "read", val, db);
893 else if (strcmp (key, "Innodb_rows_updated") == 0)
894 counter_submit ("mysql_innodb_rows", "updated", val, db);
896 else if (strncmp (key, "Select_", strlen ("Select_")) == 0)
898 counter_submit ("mysql_select", key + strlen ("Select_"),
901 else if (strncmp (key, "Sort_", strlen ("Sort_")) == 0)
903 counter_submit ("mysql_sort", key + strlen ("Sort_"),
907 mysql_free_result (res); res = NULL;
909 if ((qcache_hits != 0)
910 || (qcache_inserts != 0)
911 || (qcache_not_cached != 0)
912 || (qcache_lowmem_prunes != 0))
914 derive_submit ("cache_result", "qcache-hits",
916 derive_submit ("cache_result", "qcache-inserts",
918 derive_submit ("cache_result", "qcache-not_cached",
919 qcache_not_cached, db);
920 derive_submit ("cache_result", "qcache-prunes",
921 qcache_lowmem_prunes, db);
923 gauge_submit ("cache_size", "qcache",
924 qcache_queries_in_cache, db);
927 if (threads_created != 0)
929 gauge_submit ("threads", "running",
930 threads_running, db);
931 gauge_submit ("threads", "connected",
932 threads_connected, db);
933 gauge_submit ("threads", "cached",
936 derive_submit ("total_threads", "created",
937 threads_created, db);
940 traffic_submit (traffic_incoming, traffic_outgoing, db);
942 if (mysql_version >= 50600 && db->innodb_stats)
943 mysql_read_innodb_stats (db, con);
945 if (db->master_stats)
946 mysql_read_master_stats (db, con);
948 if ((db->slave_stats) || (db->slave_notif))
949 mysql_read_slave_stats (db, con);
952 } /* int mysql_read */
954 void module_register (void)
956 plugin_register_complex_config ("mysql", mysql_config);
957 } /* void module_register */