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>
37 #elif defined(HAVE_MYSQL_MYSQL_H)
38 #include <mysql/mysql.h>
41 struct mysql_database_s /* {{{ */
50 /* mysql_ssl_set params */
67 _Bool slave_io_running;
68 _Bool slave_sql_running;
73 typedef struct mysql_database_s mysql_database_t; /* }}} */
75 static int mysql_read (user_data_t *ud);
77 static void mysql_database_free (void *arg) /* {{{ */
81 DEBUG ("mysql plugin: mysql_database_free (arg = %p);", arg);
89 mysql_close (db->con);
104 } /* }}} void mysql_database_free */
106 /* Configuration handling functions {{{
109 * <Database "plugin_instance1">
116 static int mysql_config_database (oconfig_item_t *ci) /* {{{ */
118 mysql_database_t *db;
121 if ((ci->values_num != 1)
122 || (ci->values[0].type != OCONFIG_TYPE_STRING))
124 WARNING ("mysql plugin: The `Database' block "
125 "needs exactly one string argument.");
129 db = calloc (1, sizeof (*db));
132 ERROR ("mysql plugin: calloc failed.");
136 /* initialize all the pointers */
152 /* trigger a notification, if it's not running */
153 db->slave_io_running = 1;
154 db->slave_sql_running = 1;
156 status = cf_util_get_string (ci, &db->instance);
162 assert (db->instance != NULL);
164 /* Fill the `mysql_database_t' structure.. */
165 for (int i = 0; i < ci->children_num; i++)
167 oconfig_item_t *child = ci->children + i;
169 if (strcasecmp ("Alias", child->key) == 0)
170 status = cf_util_get_string (child, &db->alias);
171 else if (strcasecmp ("Host", child->key) == 0)
172 status = cf_util_get_string (child, &db->host);
173 else if (strcasecmp ("User", child->key) == 0)
174 status = cf_util_get_string (child, &db->user);
175 else if (strcasecmp ("Password", child->key) == 0)
176 status = cf_util_get_string (child, &db->pass);
177 else if (strcasecmp ("Port", child->key) == 0)
179 status = cf_util_get_port_number (child);
186 else if (strcasecmp ("Socket", child->key) == 0)
187 status = cf_util_get_string (child, &db->socket);
188 else if (strcasecmp ("Database", child->key) == 0)
189 status = cf_util_get_string (child, &db->database);
190 else if (strcasecmp ("SSLKey", child->key) == 0)
191 status = cf_util_get_string (child, &db->key);
192 else if (strcasecmp ("SSLCert", child->key) == 0)
193 status = cf_util_get_string (child, &db->cert);
194 else if (strcasecmp ("SSLCA", child->key) == 0)
195 status = cf_util_get_string (child, &db->ca);
196 else if (strcasecmp ("SSLCAPath", child->key) == 0)
197 status = cf_util_get_string (child, &db->capath);
198 else if (strcasecmp ("SSLCipher", child->key) == 0)
199 status = cf_util_get_string (child, &db->cipher);
200 else if (strcasecmp ("ConnectTimeout", child->key) == 0)
201 status = cf_util_get_int (child, &db->timeout);
202 else if (strcasecmp ("MasterStats", child->key) == 0)
203 status = cf_util_get_boolean (child, &db->master_stats);
204 else if (strcasecmp ("SlaveStats", child->key) == 0)
205 status = cf_util_get_boolean (child, &db->slave_stats);
206 else if (strcasecmp ("SlaveNotifications", child->key) == 0)
207 status = cf_util_get_boolean (child, &db->slave_notif);
208 else if (strcasecmp ("InnodbStats", child->key) == 0)
209 status = cf_util_get_boolean (child, &db->innodb_stats);
210 else if (strcasecmp ("WsrepStats", child->key) == 0)
211 status = cf_util_get_boolean (child, &db->wsrep_stats);
214 WARNING ("mysql plugin: Option `%s' not allowed here.", child->key);
222 /* If all went well, register this database for reading */
225 char cb_name[DATA_MAX_NAME_LEN];
227 DEBUG ("mysql plugin: Registering new read callback: %s",
228 (db->database != NULL) ? db->database : "<default>");
230 if (db->instance != NULL)
231 ssnprintf (cb_name, sizeof (cb_name), "mysql-%s",
234 sstrncpy (cb_name, "mysql", sizeof (cb_name));
236 plugin_register_complex_read (/* group = */ NULL, cb_name,
237 mysql_read, /* interval = */ 0, &(user_data_t) {
239 .free_func = mysql_database_free,
244 mysql_database_free (db);
249 } /* }}} int mysql_config_database */
251 static int mysql_config (oconfig_item_t *ci) /* {{{ */
256 /* Fill the `mysql_database_t' structure.. */
257 for (int i = 0; i < ci->children_num; i++)
259 oconfig_item_t *child = ci->children + i;
261 if (strcasecmp ("Database", child->key) == 0)
262 mysql_config_database (child);
264 WARNING ("mysql plugin: Option \"%s\" not allowed here.",
269 } /* }}} int mysql_config */
271 /* }}} End of configuration handling functions */
273 static MYSQL *getconnection (mysql_database_t *db)
277 if (db->is_connected)
281 status = mysql_ping (db->con);
285 WARNING ("mysql plugin: Lost connection to instance \"%s\": %s",
286 db->instance, mysql_error (db->con));
288 db->is_connected = 0;
292 db->con = mysql_init (NULL);
295 ERROR ("mysql plugin: mysql_init failed: %s",
296 mysql_error (db->con));
301 /* Configure TCP connect timeout (default: 0) */
302 db->con->options.connect_timeout = db->timeout;
304 mysql_ssl_set (db->con, db->key, db->cert, db->ca, db->capath, db->cipher);
306 if (mysql_real_connect (db->con, db->host, db->user, db->pass,
307 db->database, db->port, db->socket, 0) == NULL)
309 ERROR ("mysql plugin: Failed to connect to database %s "
311 (db->database != NULL) ? db->database : "<none>",
312 (db->host != NULL) ? db->host : "localhost",
313 mysql_error (db->con));
317 cipher = mysql_get_ssl_cipher (db->con);
319 INFO ("mysql plugin: Successfully connected to database %s "
320 "at server %s with cipher %s "
321 "(server version: %s, protocol version: %d) ",
322 (db->database != NULL) ? db->database : "<none>",
323 mysql_get_host_info (db->con),
324 (cipher != NULL) ? cipher : "<none>",
325 mysql_get_server_info (db->con),
326 mysql_get_proto_info (db->con));
328 db->is_connected = 1;
330 } /* static MYSQL *getconnection (mysql_database_t *db) */
332 static void set_host (mysql_database_t *db, char *buf, size_t buflen)
335 sstrncpy (buf, db->alias, buflen);
336 else if ((db->host == NULL)
337 || (strcmp ("", db->host) == 0)
338 || (strcmp ("127.0.0.1", db->host) == 0)
339 || (strcmp ("localhost", db->host) == 0))
340 sstrncpy (buf, hostname_g, buflen);
342 sstrncpy (buf, db->host, buflen);
343 } /* void set_host */
345 static void submit (const char *type, const char *type_instance,
346 value_t *values, size_t values_len, mysql_database_t *db)
348 value_list_t vl = VALUE_LIST_INIT;
351 vl.values_len = values_len;
353 set_host (db, vl.host, sizeof (vl.host));
355 sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin));
357 /* Assured by "mysql_config_database" */
358 assert (db->instance != NULL);
359 sstrncpy (vl.plugin_instance, db->instance, sizeof (vl.plugin_instance));
361 sstrncpy (vl.type, type, sizeof (vl.type));
362 if (type_instance != NULL)
363 sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
365 plugin_dispatch_values (&vl);
368 static void gauge_submit (const char *type, const char *type_instance,
369 gauge_t value, mysql_database_t *db)
371 submit (type, type_instance, &(value_t) { .gauge = value }, 1, db);
372 } /* void gauge_submit */
374 static void derive_submit (const char *type, const char *type_instance,
375 derive_t value, mysql_database_t *db)
377 submit (type, type_instance, &(value_t) { .derive = value }, 1, db);
378 } /* void derive_submit */
380 static void traffic_submit (derive_t rx, derive_t tx, mysql_database_t *db)
387 submit ("mysql_octets", NULL, values, STATIC_ARRAY_SIZE (values), db);
388 } /* void traffic_submit */
390 static MYSQL_RES *exec_query (MYSQL *con, const char *query)
394 int query_len = strlen (query);
396 if (mysql_real_query (con, query, query_len))
398 ERROR ("mysql plugin: Failed to execute query: %s",
400 INFO ("mysql plugin: SQL query was: %s", query);
404 res = mysql_store_result (con);
407 ERROR ("mysql plugin: Failed to store query result: %s",
409 INFO ("mysql plugin: SQL query was: %s", query);
416 static int mysql_read_master_stats (mysql_database_t *db, MYSQL *con)
423 unsigned long long position;
425 query = "SHOW MASTER STATUS";
427 res = exec_query (con, query);
431 row = mysql_fetch_row (res);
434 ERROR ("mysql plugin: Failed to get master statistics: "
435 "`%s' did not return any rows.", query);
436 mysql_free_result (res);
440 field_num = mysql_num_fields (res);
443 ERROR ("mysql plugin: Failed to get master statistics: "
444 "`%s' returned less than two columns.", query);
445 mysql_free_result (res);
449 position = atoll (row[1]);
450 derive_submit ("mysql_log_position", "master-bin", position, db);
452 row = mysql_fetch_row (res);
454 WARNING ("mysql plugin: `%s' returned more than one row - "
455 "ignoring further results.", query);
457 mysql_free_result (res);
460 } /* mysql_read_master_stats */
462 static int mysql_read_slave_stats (mysql_database_t *db, MYSQL *con)
470 /* WTF? libmysqlclient does not seem to provide any means to
471 * translate a column name to a column index ... :-/ */
472 const int READ_MASTER_LOG_POS_IDX = 6;
473 const int SLAVE_IO_RUNNING_IDX = 10;
474 const int SLAVE_SQL_RUNNING_IDX = 11;
475 const int EXEC_MASTER_LOG_POS_IDX = 21;
476 const int SECONDS_BEHIND_MASTER_IDX = 32;
478 query = "SHOW SLAVE STATUS";
480 res = exec_query (con, query);
484 row = mysql_fetch_row (res);
487 ERROR ("mysql plugin: Failed to get slave statistics: "
488 "`%s' did not return any rows.", query);
489 mysql_free_result (res);
493 field_num = mysql_num_fields (res);
496 ERROR ("mysql plugin: Failed to get slave statistics: "
497 "`%s' returned less than 33 columns.", query);
498 mysql_free_result (res);
504 unsigned long long counter;
507 counter = atoll (row[READ_MASTER_LOG_POS_IDX]);
508 derive_submit ("mysql_log_position", "slave-read", counter, db);
510 counter = atoll (row[EXEC_MASTER_LOG_POS_IDX]);
511 derive_submit ("mysql_log_position", "slave-exec", counter, db);
513 if (row[SECONDS_BEHIND_MASTER_IDX] != NULL)
515 gauge = atof (row[SECONDS_BEHIND_MASTER_IDX]);
516 gauge_submit ("time_offset", NULL, gauge, db);
522 notification_t n = { 0, cdtime (), "", "",
523 "mysql", "", "time_offset", "", NULL };
527 io = row[SLAVE_IO_RUNNING_IDX];
528 sql = row[SLAVE_SQL_RUNNING_IDX];
530 set_host (db, n.host, sizeof (n.host));
532 /* Assured by "mysql_config_database" */
533 assert (db->instance != NULL);
534 sstrncpy (n.plugin_instance, db->instance, sizeof (n.plugin_instance));
536 if (((io == NULL) || (strcasecmp (io, "yes") != 0))
537 && (db->slave_io_running))
539 n.severity = NOTIF_WARNING;
540 ssnprintf (n.message, sizeof (n.message),
541 "slave I/O thread not started or not connected to master");
542 plugin_dispatch_notification (&n);
543 db->slave_io_running = 0;
545 else if (((io != NULL) && (strcasecmp (io, "yes") == 0))
546 && (! db->slave_io_running))
548 n.severity = NOTIF_OKAY;
549 ssnprintf (n.message, sizeof (n.message),
550 "slave I/O thread started and connected to master");
551 plugin_dispatch_notification (&n);
552 db->slave_io_running = 1;
555 if (((sql == NULL) || (strcasecmp (sql, "yes") != 0))
556 && (db->slave_sql_running))
558 n.severity = NOTIF_WARNING;
559 ssnprintf (n.message, sizeof (n.message),
560 "slave SQL thread not started");
561 plugin_dispatch_notification (&n);
562 db->slave_sql_running = 0;
564 else if (((sql != NULL) && (strcasecmp (sql, "yes") == 0))
565 && (! db->slave_sql_running))
567 n.severity = NOTIF_OKAY;
568 ssnprintf (n.message, sizeof (n.message),
569 "slave SQL thread started");
570 plugin_dispatch_notification (&n);
571 db->slave_sql_running = 1;
575 row = mysql_fetch_row (res);
577 WARNING ("mysql plugin: `%s' returned more than one row - "
578 "ignoring further results.", query);
580 mysql_free_result (res);
583 } /* mysql_read_slave_stats */
585 static int mysql_read_innodb_stats (mysql_database_t *db, MYSQL *con)
596 { "metadata_mem_pool_size", "bytes", DS_TYPE_GAUGE },
597 { "lock_deadlocks", "mysql_locks", DS_TYPE_DERIVE },
598 { "lock_timeouts", "mysql_locks", DS_TYPE_DERIVE },
599 { "lock_row_lock_current_waits", "mysql_locks", DS_TYPE_DERIVE },
600 { "buffer_pool_size", "bytes", DS_TYPE_GAUGE },
602 { "os_log_bytes_written", "operations", DS_TYPE_DERIVE },
603 { "os_log_pending_fsyncs", "operations", DS_TYPE_DERIVE },
604 { "os_log_pending_writes", "operations", DS_TYPE_DERIVE },
606 { "trx_rseg_history_len", "gauge", DS_TYPE_GAUGE },
608 { "adaptive_hash_searches", "operations", DS_TYPE_DERIVE },
610 { "file_num_open_files", "gauge", DS_TYPE_GAUGE },
612 { "ibuf_merges_insert", "operations", DS_TYPE_DERIVE },
613 { "ibuf_merges_delete_mark", "operations", DS_TYPE_DERIVE },
614 { "ibuf_merges_delete", "operations", DS_TYPE_DERIVE },
615 { "ibuf_merges_discard_insert", "operations", DS_TYPE_DERIVE },
616 { "ibuf_merges_discard_delete_mark", "operations", DS_TYPE_DERIVE },
617 { "ibuf_merges_discard_delete", "operations", DS_TYPE_DERIVE },
618 { "ibuf_merges_discard_merges", "operations", DS_TYPE_DERIVE },
619 { "ibuf_size", "bytes", DS_TYPE_GAUGE },
621 { "innodb_activity_count", "gauge", DS_TYPE_GAUGE },
623 { "innodb_rwlock_s_spin_waits", "operations", DS_TYPE_DERIVE },
624 { "innodb_rwlock_x_spin_waits", "operations", DS_TYPE_DERIVE },
625 { "innodb_rwlock_s_spin_rounds", "operations", DS_TYPE_DERIVE },
626 { "innodb_rwlock_x_spin_rounds", "operations", DS_TYPE_DERIVE },
627 { "innodb_rwlock_s_os_waits", "operations", DS_TYPE_DERIVE },
628 { "innodb_rwlock_x_os_waits", "operations", DS_TYPE_DERIVE },
630 { "dml_reads", "operations", DS_TYPE_DERIVE },
631 { "dml_inserts", "operations", DS_TYPE_DERIVE },
632 { "dml_deletes", "operations", DS_TYPE_DERIVE },
633 { "dml_updates", "operations", DS_TYPE_DERIVE },
638 query = "SELECT name, count, type FROM information_schema.innodb_metrics WHERE status = 'enabled'";
640 res = exec_query (con, query);
644 while ((row = mysql_fetch_row (res)))
648 unsigned long long val;
651 val = atoll (row[1]);
653 for (i = 0; metrics[i].key != NULL && strcmp(metrics[i].key, key) != 0; i++)
656 if (metrics[i].key == NULL)
659 switch (metrics[i].ds_type) {
660 case DS_TYPE_COUNTER:
661 derive_submit(metrics[i].type, key, (counter_t)val, db);
664 gauge_submit(metrics[i].type, key, (gauge_t)val, db);
667 derive_submit(metrics[i].type, key, (derive_t)val, db);
672 mysql_free_result(res);
676 static int mysql_read_wsrep_stats (mysql_database_t *db, MYSQL *con)
688 { "wsrep_apply_oooe", "operations", DS_TYPE_DERIVE },
689 { "wsrep_apply_oool", "operations", DS_TYPE_DERIVE },
690 { "wsrep_causal_reads", "operations", DS_TYPE_DERIVE },
691 { "wsrep_commit_oooe", "operations", DS_TYPE_DERIVE },
692 { "wsrep_commit_oool", "operations", DS_TYPE_DERIVE },
693 { "wsrep_flow_control_recv", "operations", DS_TYPE_DERIVE },
694 { "wsrep_flow_control_sent", "operations", DS_TYPE_DERIVE },
695 { "wsrep_flow_control_paused", "operations", DS_TYPE_DERIVE },
696 { "wsrep_local_bf_aborts", "operations", DS_TYPE_DERIVE },
697 { "wsrep_local_cert_failures", "operations", DS_TYPE_DERIVE },
698 { "wsrep_local_commits", "operations", DS_TYPE_DERIVE },
699 { "wsrep_local_replays", "operations", DS_TYPE_DERIVE },
700 { "wsrep_received", "operations", DS_TYPE_DERIVE },
701 { "wsrep_replicated", "operations", DS_TYPE_DERIVE },
703 { "wsrep_received_bytes", "total_bytes", DS_TYPE_DERIVE },
704 { "wsrep_replicated_bytes", "total_bytes", DS_TYPE_DERIVE },
706 { "wsrep_apply_window", "gauge", DS_TYPE_GAUGE },
707 { "wsrep_commit_window", "gauge", DS_TYPE_GAUGE },
709 { "wsrep_cluster_size", "gauge", DS_TYPE_GAUGE },
710 { "wsrep_cert_deps_distance", "gauge", DS_TYPE_GAUGE },
712 { "wsrep_local_recv_queue", "queue_length", DS_TYPE_GAUGE },
713 { "wsrep_local_send_queue", "queue_length", DS_TYPE_GAUGE },
719 query = "SHOW GLOBAL STATUS LIKE 'wsrep_%'";
721 res = exec_query (con, query);
725 row = mysql_fetch_row (res);
728 ERROR ("mysql plugin: Failed to get wsrep statistics: "
729 "`%s' did not return any rows.", query);
730 mysql_free_result (res);
734 while ((row = mysql_fetch_row (res)))
738 unsigned long long val;
741 val = atoll (row[1]);
743 for (i = 0; metrics[i].key != NULL && strcmp(metrics[i].key, key) != 0; i++)
746 if (metrics[i].key == NULL)
749 switch (metrics[i].ds_type) {
751 gauge_submit(metrics[i].type, key, (gauge_t)val, db);
754 derive_submit(metrics[i].type, key, (derive_t)val, db);
759 mysql_free_result(res);
761 } /* mysql_read_wsrep_stats */
763 static int mysql_read (user_data_t *ud)
765 mysql_database_t *db;
771 derive_t qcache_hits = 0;
772 derive_t qcache_inserts = 0;
773 derive_t qcache_not_cached = 0;
774 derive_t qcache_lowmem_prunes = 0;
775 gauge_t qcache_queries_in_cache = NAN;
777 gauge_t threads_running = NAN;
778 gauge_t threads_connected = NAN;
779 gauge_t threads_cached = NAN;
780 derive_t threads_created = 0;
782 unsigned long long traffic_incoming = 0ULL;
783 unsigned long long traffic_outgoing = 0ULL;
784 unsigned long mysql_version = 0ULL;
786 if ((ud == NULL) || (ud->data == NULL))
788 ERROR ("mysql plugin: mysql_database_read: Invalid user data.");
792 db = (mysql_database_t *) ud->data;
794 /* An error message will have been printed in this case */
795 if ((con = getconnection (db)) == NULL)
798 mysql_version = mysql_get_server_version(con);
800 query = "SHOW STATUS";
801 if (mysql_version >= 50002)
802 query = "SHOW GLOBAL STATUS";
804 res = exec_query (con, query);
808 while ((row = mysql_fetch_row (res)))
811 unsigned long long val;
814 val = atoll (row[1]);
816 if (strncmp (key, "Com_",
817 strlen ("Com_")) == 0)
822 /* Ignore `prepared statements' */
823 if (strncmp (key, "Com_stmt_", strlen ("Com_stmt_")) != 0)
824 derive_submit ("mysql_commands",
825 key + strlen ("Com_"),
828 else if (strncmp (key, "Handler_",
829 strlen ("Handler_")) == 0)
834 derive_submit ("mysql_handler",
835 key + strlen ("Handler_"),
838 else if (strncmp (key, "Qcache_",
839 strlen ("Qcache_")) == 0)
841 if (strcmp (key, "Qcache_hits") == 0)
842 qcache_hits = (derive_t) val;
843 else if (strcmp (key, "Qcache_inserts") == 0)
844 qcache_inserts = (derive_t) val;
845 else if (strcmp (key, "Qcache_not_cached") == 0)
846 qcache_not_cached = (derive_t) val;
847 else if (strcmp (key, "Qcache_lowmem_prunes") == 0)
848 qcache_lowmem_prunes = (derive_t) val;
849 else if (strcmp (key, "Qcache_queries_in_cache") == 0)
850 qcache_queries_in_cache = (gauge_t) val;
852 else if (strncmp (key, "Bytes_",
853 strlen ("Bytes_")) == 0)
855 if (strcmp (key, "Bytes_received") == 0)
856 traffic_incoming += val;
857 else if (strcmp (key, "Bytes_sent") == 0)
858 traffic_outgoing += val;
860 else if (strncmp (key, "Threads_",
861 strlen ("Threads_")) == 0)
863 if (strcmp (key, "Threads_running") == 0)
864 threads_running = (gauge_t) val;
865 else if (strcmp (key, "Threads_connected") == 0)
866 threads_connected = (gauge_t) val;
867 else if (strcmp (key, "Threads_cached") == 0)
868 threads_cached = (gauge_t) val;
869 else if (strcmp (key, "Threads_created") == 0)
870 threads_created = (derive_t) val;
872 else if (strncmp (key, "Table_locks_",
873 strlen ("Table_locks_")) == 0)
875 derive_submit ("mysql_locks",
876 key + strlen ("Table_locks_"),
879 else if (db->innodb_stats && strncmp (key, "Innodb_", strlen ("Innodb_")) == 0)
882 if (strcmp (key, "Innodb_buffer_pool_pages_data") == 0)
883 gauge_submit ("mysql_bpool_pages", "data", val, db);
884 else if (strcmp (key, "Innodb_buffer_pool_pages_dirty") == 0)
885 gauge_submit ("mysql_bpool_pages", "dirty", val, db);
886 else if (strcmp (key, "Innodb_buffer_pool_pages_flushed") == 0)
887 derive_submit ("mysql_bpool_counters", "pages_flushed", val, db);
888 else if (strcmp (key, "Innodb_buffer_pool_pages_free") == 0)
889 gauge_submit ("mysql_bpool_pages", "free", val, db);
890 else if (strcmp (key, "Innodb_buffer_pool_pages_misc") == 0)
891 gauge_submit ("mysql_bpool_pages", "misc", val, db);
892 else if (strcmp (key, "Innodb_buffer_pool_pages_total") == 0)
893 gauge_submit ("mysql_bpool_pages", "total", val, db);
894 else if (strcmp (key, "Innodb_buffer_pool_read_ahead_rnd") == 0)
895 derive_submit ("mysql_bpool_counters", "read_ahead_rnd", val, db);
896 else if (strcmp (key, "Innodb_buffer_pool_read_ahead") == 0)
897 derive_submit ("mysql_bpool_counters", "read_ahead", val, db);
898 else if (strcmp (key, "Innodb_buffer_pool_read_ahead_evicted") == 0)
899 derive_submit ("mysql_bpool_counters", "read_ahead_evicted", val, db);
900 else if (strcmp (key, "Innodb_buffer_pool_read_requests") == 0)
901 derive_submit ("mysql_bpool_counters", "read_requests", val, db);
902 else if (strcmp (key, "Innodb_buffer_pool_reads") == 0)
903 derive_submit ("mysql_bpool_counters", "reads", val, db);
904 else if (strcmp (key, "Innodb_buffer_pool_wait_free") == 0)
905 derive_submit ("mysql_bpool_counters", "wait_free", val, db);
906 else if (strcmp (key, "Innodb_buffer_pool_write_requests") == 0)
907 derive_submit ("mysql_bpool_counters", "write_requests", val, db);
908 else if (strcmp (key, "Innodb_buffer_pool_bytes_data") == 0)
909 gauge_submit ("mysql_bpool_bytes", "data", val, db);
910 else if (strcmp (key, "Innodb_buffer_pool_bytes_dirty") == 0)
911 gauge_submit ("mysql_bpool_bytes", "dirty", val, db);
914 if (strcmp (key, "Innodb_data_fsyncs") == 0)
915 derive_submit ("mysql_innodb_data", "fsyncs", val, db);
916 else if (strcmp (key, "Innodb_data_read") == 0)
917 derive_submit ("mysql_innodb_data", "read", val, db);
918 else if (strcmp (key, "Innodb_data_reads") == 0)
919 derive_submit ("mysql_innodb_data", "reads", val, db);
920 else if (strcmp (key, "Innodb_data_writes") == 0)
921 derive_submit ("mysql_innodb_data", "writes", val, db);
922 else if (strcmp (key, "Innodb_data_written") == 0)
923 derive_submit ("mysql_innodb_data", "written", val, db);
926 else if (strcmp (key, "Innodb_dblwr_writes") == 0)
927 derive_submit ("mysql_innodb_dblwr", "writes", val, db);
928 else if (strcmp (key, "Innodb_dblwr_pages_written") == 0)
929 derive_submit ("mysql_innodb_dblwr", "written", val, db);
930 else if (strcmp (key, "Innodb_dblwr_page_size") == 0)
931 gauge_submit ("mysql_innodb_dblwr", "page_size", val, db);
934 else if (strcmp (key, "Innodb_log_waits") == 0)
935 derive_submit ("mysql_innodb_log", "waits", val, db);
936 else if (strcmp (key, "Innodb_log_write_requests") == 0)
937 derive_submit ("mysql_innodb_log", "write_requests", val, db);
938 else if (strcmp (key, "Innodb_log_writes") == 0)
939 derive_submit ("mysql_innodb_log", "writes", val, db);
940 else if (strcmp (key, "Innodb_os_log_fsyncs") == 0)
941 derive_submit ("mysql_innodb_log", "fsyncs", val, db);
942 else if (strcmp (key, "Innodb_os_log_written") == 0)
943 derive_submit ("mysql_innodb_log", "written", val, db);
946 else if (strcmp (key, "Innodb_pages_created") == 0)
947 derive_submit ("mysql_innodb_pages", "created", val, db);
948 else if (strcmp (key, "Innodb_pages_read") == 0)
949 derive_submit ("mysql_innodb_pages", "read", val, db);
950 else if (strcmp (key, "Innodb_pages_written") == 0)
951 derive_submit ("mysql_innodb_pages", "written", val, db);
954 else if (strcmp (key, "Innodb_row_lock_time") == 0)
955 derive_submit ("mysql_innodb_row_lock", "time", val, db);
956 else if (strcmp (key, "Innodb_row_lock_waits") == 0)
957 derive_submit ("mysql_innodb_row_lock", "waits", val, db);
960 else if (strcmp (key, "Innodb_rows_deleted") == 0)
961 derive_submit ("mysql_innodb_rows", "deleted", val, db);
962 else if (strcmp (key, "Innodb_rows_inserted") == 0)
963 derive_submit ("mysql_innodb_rows", "inserted", val, db);
964 else if (strcmp (key, "Innodb_rows_read") == 0)
965 derive_submit ("mysql_innodb_rows", "read", val, db);
966 else if (strcmp (key, "Innodb_rows_updated") == 0)
967 derive_submit ("mysql_innodb_rows", "updated", val, db);
969 else if (strncmp (key, "Select_", strlen ("Select_")) == 0)
971 derive_submit ("mysql_select", key + strlen ("Select_"),
974 else if (strncmp (key, "Sort_", strlen ("Sort_")) == 0)
976 if (strcmp (key, "Sort_merge_passes") == 0)
977 derive_submit ("mysql_sort_merge_passes", NULL, val, db);
978 else if (strcmp (key, "Sort_rows") == 0)
979 derive_submit ("mysql_sort_rows", NULL, val, db);
980 else if (strcmp (key, "Sort_range") == 0)
981 derive_submit ("mysql_sort", "range", val, db);
982 else if (strcmp (key, "Sort_scan") == 0)
983 derive_submit ("mysql_sort", "scan", val, db);
986 else if (strncmp (key, "Slow_queries", strlen ("Slow_queries")) == 0)
988 derive_submit ("mysql_slow_queries", NULL , val, db);
991 mysql_free_result (res); res = NULL;
993 if ((qcache_hits != 0)
994 || (qcache_inserts != 0)
995 || (qcache_not_cached != 0)
996 || (qcache_lowmem_prunes != 0))
998 derive_submit ("cache_result", "qcache-hits",
1000 derive_submit ("cache_result", "qcache-inserts",
1001 qcache_inserts, db);
1002 derive_submit ("cache_result", "qcache-not_cached",
1003 qcache_not_cached, db);
1004 derive_submit ("cache_result", "qcache-prunes",
1005 qcache_lowmem_prunes, db);
1007 gauge_submit ("cache_size", "qcache",
1008 qcache_queries_in_cache, db);
1011 if (threads_created != 0)
1013 gauge_submit ("threads", "running",
1014 threads_running, db);
1015 gauge_submit ("threads", "connected",
1016 threads_connected, db);
1017 gauge_submit ("threads", "cached",
1018 threads_cached, db);
1020 derive_submit ("total_threads", "created",
1021 threads_created, db);
1024 traffic_submit (traffic_incoming, traffic_outgoing, db);
1026 if (mysql_version >= 50600 && db->innodb_stats)
1027 mysql_read_innodb_stats (db, con);
1029 if (db->master_stats)
1030 mysql_read_master_stats (db, con);
1032 if ((db->slave_stats) || (db->slave_notif))
1033 mysql_read_slave_stats (db, con);
1035 if (db->wsrep_stats)
1036 mysql_read_wsrep_stats (db, con);
1039 } /* int mysql_read */
1041 void module_register (void)
1043 plugin_register_complex_config ("mysql", mysql_config);
1044 } /* void module_register */