0f8d5a64d04bd637d007fdca5a4baf8e15e47654
1 /**
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
8 *
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.
12 *
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.
17 *
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
21 *
22 * Authors:
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>
28 **/
30 #include "collectd.h"
31 #include "common.h"
32 #include "plugin.h"
33 #include "configfile.h"
35 #ifdef HAVE_MYSQL_H
36 #include <mysql.h>
37 #elif defined(HAVE_MYSQL_MYSQL_H)
38 #include <mysql/mysql.h>
39 #endif
41 /* TODO: Understand `Select_*' and possibly do that stuff as well.. */
43 struct mysql_database_s /* {{{ */
44 {
45 char *instance;
46 char *alias;
47 char *host;
48 char *user;
49 char *pass;
50 char *database;
51 char *socket;
52 int port;
53 int timeout;
55 _Bool master_stats;
56 _Bool slave_stats;
57 _Bool innodb_stats;
59 _Bool slave_notif;
60 _Bool slave_io_running;
61 _Bool slave_sql_running;
63 MYSQL *con;
64 _Bool is_connected;
65 };
66 typedef struct mysql_database_s mysql_database_t; /* }}} */
68 static int mysql_read (user_data_t *ud);
70 void mysql_read_default_options(struct st_mysql_options *options,
71 const char *filename,const char *group);
73 static void mysql_database_free (void *arg) /* {{{ */
74 {
75 mysql_database_t *db;
77 DEBUG ("mysql plugin: mysql_database_free (arg = %p);", arg);
79 db = (mysql_database_t *) arg;
81 if (db == NULL)
82 return;
84 if (db->con != NULL)
85 mysql_close (db->con);
87 sfree (db->alias);
88 sfree (db->host);
89 sfree (db->user);
90 sfree (db->pass);
91 sfree (db->socket);
92 sfree (db->instance);
93 sfree (db->database);
94 sfree (db);
95 } /* }}} void mysql_database_free */
97 /* Configuration handling functions {{{
98 *
99 * <Plugin mysql>
100 * <Database "plugin_instance1">
101 * Host "localhost"
102 * Port 22000
103 * ...
104 * </Database>
105 * </Plugin>
106 */
107 static int mysql_config_database (oconfig_item_t *ci) /* {{{ */
108 {
109 mysql_database_t *db;
110 int status = 0;
111 int i;
113 if ((ci->values_num != 1)
114 || (ci->values[0].type != OCONFIG_TYPE_STRING))
115 {
116 WARNING ("mysql plugin: The `Database' block "
117 "needs exactly one string argument.");
118 return (-1);
119 }
121 db = (mysql_database_t *) malloc (sizeof (*db));
122 if (db == NULL)
123 {
124 ERROR ("mysql plugin: malloc failed.");
125 return (-1);
126 }
127 memset (db, 0, sizeof (*db));
129 /* initialize all the pointers */
130 db->alias = NULL;
131 db->host = NULL;
132 db->user = NULL;
133 db->pass = NULL;
134 db->database = NULL;
135 db->socket = NULL;
136 db->con = NULL;
137 db->timeout = 0;
139 /* trigger a notification, if it's not running */
140 db->slave_io_running = 1;
141 db->slave_sql_running = 1;
143 status = cf_util_get_string (ci, &db->instance);
144 if (status != 0)
145 {
146 sfree (db);
147 return (status);
148 }
149 assert (db->instance != NULL);
151 /* Fill the `mysql_database_t' structure.. */
152 for (i = 0; i < ci->children_num; i++)
153 {
154 oconfig_item_t *child = ci->children + i;
156 if (strcasecmp ("Alias", child->key) == 0)
157 status = cf_util_get_string (child, &db->alias);
158 else if (strcasecmp ("Host", child->key) == 0)
159 status = cf_util_get_string (child, &db->host);
160 else if (strcasecmp ("User", child->key) == 0)
161 status = cf_util_get_string (child, &db->user);
162 else if (strcasecmp ("Password", child->key) == 0)
163 status = cf_util_get_string (child, &db->pass);
164 else if (strcasecmp ("Port", child->key) == 0)
165 {
166 status = cf_util_get_port_number (child);
167 if (status > 0)
168 {
169 db->port = status;
170 status = 0;
171 }
172 }
173 else if (strcasecmp ("Socket", child->key) == 0)
174 status = cf_util_get_string (child, &db->socket);
175 else if (strcasecmp ("Database", child->key) == 0)
176 status = cf_util_get_string (child, &db->database);
177 else if (strcasecmp ("ConnectTimeout", child->key) == 0)
178 status = cf_util_get_int (child, &db->timeout);
179 else if (strcasecmp ("MasterStats", child->key) == 0)
180 status = cf_util_get_boolean (child, &db->master_stats);
181 else if (strcasecmp ("SlaveStats", child->key) == 0)
182 status = cf_util_get_boolean (child, &db->slave_stats);
183 else if (strcasecmp ("SlaveNotifications", child->key) == 0)
184 status = cf_util_get_boolean (child, &db->slave_notif);
185 else if (strcasecmp ("InnodbStats", child->key) == 0)
186 status = cf_util_get_boolean (child, &db->innodb_stats);
187 else
188 {
189 WARNING ("mysql plugin: Option `%s' not allowed here.", child->key);
190 status = -1;
191 }
193 if (status != 0)
194 break;
195 }
197 /* If all went well, register this database for reading */
198 if (status == 0)
199 {
200 user_data_t ud;
201 char cb_name[DATA_MAX_NAME_LEN];
203 DEBUG ("mysql plugin: Registering new read callback: %s",
204 (db->database != NULL) ? db->database : "<default>");
206 memset (&ud, 0, sizeof (ud));
207 ud.data = (void *) db;
208 ud.free_func = mysql_database_free;
210 if (db->instance != NULL)
211 ssnprintf (cb_name, sizeof (cb_name), "mysql-%s",
212 db->instance);
213 else
214 sstrncpy (cb_name, "mysql", sizeof (cb_name));
216 plugin_register_complex_read (/* group = */ NULL, cb_name,
217 mysql_read,
218 /* interval = */ NULL, &ud);
219 }
220 else
221 {
222 mysql_database_free (db);
223 return (-1);
224 }
226 return (0);
227 } /* }}} int mysql_config_database */
229 static int mysql_config (oconfig_item_t *ci) /* {{{ */
230 {
231 int i;
233 if (ci == NULL)
234 return (EINVAL);
236 /* Fill the `mysql_database_t' structure.. */
237 for (i = 0; i < ci->children_num; i++)
238 {
239 oconfig_item_t *child = ci->children + i;
241 if (strcasecmp ("Database", child->key) == 0)
242 mysql_config_database (child);
243 else
244 WARNING ("mysql plugin: Option \"%s\" not allowed here.",
245 child->key);
246 }
248 return (0);
249 } /* }}} int mysql_config */
251 /* }}} End of configuration handling functions */
253 static MYSQL *getconnection (mysql_database_t *db)
254 {
255 if (db->is_connected)
256 {
257 int status;
259 status = mysql_ping (db->con);
260 if (status == 0)
261 return (db->con);
263 WARNING ("mysql plugin: Lost connection to instance \"%s\": %s",
264 db->instance, mysql_error (db->con));
265 }
266 db->is_connected = 0;
268 if (db->con == NULL)
269 {
270 db->con = mysql_init (NULL);
271 if (db->con == NULL)
272 {
273 ERROR ("mysql plugin: mysql_init failed: %s",
274 mysql_error (db->con));
275 return (NULL);
276 }
277 }
279 /* Configure TCP connect timeout (default: 0) */
280 db->con->options.connect_timeout = db->timeout;
282 if (mysql_real_connect (db->con, db->host, db->user, db->pass,
283 db->database, db->port, db->socket, 0) == NULL)
284 {
285 ERROR ("mysql plugin: Failed to connect to database %s "
286 "at server %s: %s",
287 (db->database != NULL) ? db->database : "<none>",
288 (db->host != NULL) ? db->host : "localhost",
289 mysql_error (db->con));
290 return (NULL);
291 }
293 INFO ("mysql plugin: Successfully connected to database %s "
294 "at server %s (server version: %s, protocol version: %d)",
295 (db->database != NULL) ? db->database : "<none>",
296 mysql_get_host_info (db->con),
297 mysql_get_server_info (db->con),
298 mysql_get_proto_info (db->con));
300 db->is_connected = 1;
301 return (db->con);
302 } /* static MYSQL *getconnection (mysql_database_t *db) */
304 static void set_host (mysql_database_t *db, char *buf, size_t buflen)
305 {
306 if (db->alias)
307 sstrncpy (buf, db->alias, buflen);
308 else if ((db->host == NULL)
309 || (strcmp ("", db->host) == 0)
310 || (strcmp ("127.0.0.1", db->host) == 0)
311 || (strcmp ("localhost", db->host) == 0))
312 sstrncpy (buf, hostname_g, buflen);
313 else
314 sstrncpy (buf, db->host, buflen);
315 } /* void set_host */
317 static void submit (const char *type, const char *type_instance,
318 value_t *values, size_t values_len, mysql_database_t *db)
319 {
320 value_list_t vl = VALUE_LIST_INIT;
322 vl.values = values;
323 vl.values_len = values_len;
325 set_host (db, vl.host, sizeof (vl.host));
327 sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin));
329 /* Assured by "mysql_config_database" */
330 assert (db->instance != NULL);
331 sstrncpy (vl.plugin_instance, db->instance, sizeof (vl.plugin_instance));
333 sstrncpy (vl.type, type, sizeof (vl.type));
334 if (type_instance != NULL)
335 sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
337 plugin_dispatch_values (&vl);
338 } /* submit */
340 static void counter_submit (const char *type, const char *type_instance,
341 derive_t value, mysql_database_t *db)
342 {
343 value_t values[1];
345 values[0].derive = value;
346 submit (type, type_instance, values, STATIC_ARRAY_SIZE (values), db);
347 } /* void counter_submit */
349 static void gauge_submit (const char *type, const char *type_instance,
350 gauge_t value, mysql_database_t *db)
351 {
352 value_t values[1];
354 values[0].gauge = value;
355 submit (type, type_instance, values, STATIC_ARRAY_SIZE (values), db);
356 } /* void gauge_submit */
358 static void derive_submit (const char *type, const char *type_instance,
359 derive_t value, mysql_database_t *db)
360 {
361 value_t values[1];
363 values[0].derive = value;
364 submit (type, type_instance, values, STATIC_ARRAY_SIZE (values), db);
365 } /* void derive_submit */
367 static void traffic_submit (derive_t rx, derive_t tx, mysql_database_t *db)
368 {
369 value_t values[2];
371 values[0].derive = rx;
372 values[1].derive = tx;
374 submit ("mysql_octets", NULL, values, STATIC_ARRAY_SIZE (values), db);
375 } /* void traffic_submit */
377 static MYSQL_RES *exec_query (MYSQL *con, const char *query)
378 {
379 MYSQL_RES *res;
381 int query_len = strlen (query);
383 if (mysql_real_query (con, query, query_len))
384 {
385 ERROR ("mysql plugin: Failed to execute query: %s",
386 mysql_error (con));
387 INFO ("mysql plugin: SQL query was: %s", query);
388 return (NULL);
389 }
391 res = mysql_store_result (con);
392 if (res == NULL)
393 {
394 ERROR ("mysql plugin: Failed to store query result: %s",
395 mysql_error (con));
396 INFO ("mysql plugin: SQL query was: %s", query);
397 return (NULL);
398 }
400 return (res);
401 } /* exec_query */
403 static int mysql_read_master_stats (mysql_database_t *db, MYSQL *con)
404 {
405 MYSQL_RES *res;
406 MYSQL_ROW row;
408 char *query;
409 int field_num;
410 unsigned long long position;
412 query = "SHOW MASTER STATUS";
414 res = exec_query (con, query);
415 if (res == NULL)
416 return (-1);
418 row = mysql_fetch_row (res);
419 if (row == NULL)
420 {
421 ERROR ("mysql plugin: Failed to get master statistics: "
422 "`%s' did not return any rows.", query);
423 mysql_free_result (res);
424 return (-1);
425 }
427 field_num = mysql_num_fields (res);
428 if (field_num < 2)
429 {
430 ERROR ("mysql plugin: Failed to get master statistics: "
431 "`%s' returned less than two columns.", query);
432 mysql_free_result (res);
433 return (-1);
434 }
436 position = atoll (row[1]);
437 counter_submit ("mysql_log_position", "master-bin", position, db);
439 row = mysql_fetch_row (res);
440 if (row != NULL)
441 WARNING ("mysql plugin: `%s' returned more than one row - "
442 "ignoring further results.", query);
444 mysql_free_result (res);
446 return (0);
447 } /* mysql_read_master_stats */
449 static int mysql_read_slave_stats (mysql_database_t *db, MYSQL *con)
450 {
451 MYSQL_RES *res;
452 MYSQL_ROW row;
454 char *query;
455 int field_num;
457 /* WTF? libmysqlclient does not seem to provide any means to
458 * translate a column name to a column index ... :-/ */
459 const int READ_MASTER_LOG_POS_IDX = 6;
460 const int SLAVE_IO_RUNNING_IDX = 10;
461 const int SLAVE_SQL_RUNNING_IDX = 11;
462 const int EXEC_MASTER_LOG_POS_IDX = 21;
463 const int SECONDS_BEHIND_MASTER_IDX = 32;
465 query = "SHOW SLAVE STATUS";
467 res = exec_query (con, query);
468 if (res == NULL)
469 return (-1);
471 row = mysql_fetch_row (res);
472 if (row == NULL)
473 {
474 ERROR ("mysql plugin: Failed to get slave statistics: "
475 "`%s' did not return any rows.", query);
476 mysql_free_result (res);
477 return (-1);
478 }
480 field_num = mysql_num_fields (res);
481 if (field_num < 33)
482 {
483 ERROR ("mysql plugin: Failed to get slave statistics: "
484 "`%s' returned less than 33 columns.", query);
485 mysql_free_result (res);
486 return (-1);
487 }
489 if (db->slave_stats)
490 {
491 unsigned long long counter;
492 double gauge;
494 counter = atoll (row[READ_MASTER_LOG_POS_IDX]);
495 counter_submit ("mysql_log_position", "slave-read", counter, db);
497 counter = atoll (row[EXEC_MASTER_LOG_POS_IDX]);
498 counter_submit ("mysql_log_position", "slave-exec", counter, db);
500 if (row[SECONDS_BEHIND_MASTER_IDX] != NULL)
501 {
502 gauge = atof (row[SECONDS_BEHIND_MASTER_IDX]);
503 gauge_submit ("time_offset", NULL, gauge, db);
504 }
505 }
507 if (db->slave_notif)
508 {
509 notification_t n = { 0, cdtime (), "", "",
510 "mysql", "", "time_offset", "", NULL };
512 char *io, *sql;
514 io = row[SLAVE_IO_RUNNING_IDX];
515 sql = row[SLAVE_SQL_RUNNING_IDX];
517 set_host (db, n.host, sizeof (n.host));
519 /* Assured by "mysql_config_database" */
520 assert (db->instance != NULL);
521 sstrncpy (n.plugin_instance, db->instance, sizeof (n.plugin_instance));
523 if (((io == NULL) || (strcasecmp (io, "yes") != 0))
524 && (db->slave_io_running))
525 {
526 n.severity = NOTIF_WARNING;
527 ssnprintf (n.message, sizeof (n.message),
528 "slave I/O thread not started or not connected to master");
529 plugin_dispatch_notification (&n);
530 db->slave_io_running = 0;
531 }
532 else if (((io != NULL) && (strcasecmp (io, "yes") == 0))
533 && (! db->slave_io_running))
534 {
535 n.severity = NOTIF_OKAY;
536 ssnprintf (n.message, sizeof (n.message),
537 "slave I/O thread started and connected to master");
538 plugin_dispatch_notification (&n);
539 db->slave_io_running = 1;
540 }
542 if (((sql == NULL) || (strcasecmp (sql, "yes") != 0))
543 && (db->slave_sql_running))
544 {
545 n.severity = NOTIF_WARNING;
546 ssnprintf (n.message, sizeof (n.message),
547 "slave SQL thread not started");
548 plugin_dispatch_notification (&n);
549 db->slave_sql_running = 0;
550 }
551 else if (((sql != NULL) && (strcasecmp (sql, "yes") == 0))
552 && (! db->slave_sql_running))
553 {
554 n.severity = NOTIF_OKAY;
555 ssnprintf (n.message, sizeof (n.message),
556 "slave SQL thread started");
557 plugin_dispatch_notification (&n);
558 db->slave_sql_running = 1;
559 }
560 }
562 row = mysql_fetch_row (res);
563 if (row != NULL)
564 WARNING ("mysql plugin: `%s' returned more than one row - "
565 "ignoring further results.", query);
567 mysql_free_result (res);
569 return (0);
570 } /* mysql_read_slave_stats */
572 static int mysql_read (user_data_t *ud)
573 {
574 mysql_database_t *db;
575 MYSQL *con;
576 MYSQL_RES *res;
577 MYSQL_ROW row;
578 char *query;
580 derive_t qcache_hits = 0;
581 derive_t qcache_inserts = 0;
582 derive_t qcache_not_cached = 0;
583 derive_t qcache_lowmem_prunes = 0;
584 gauge_t qcache_queries_in_cache = NAN;
586 gauge_t threads_running = NAN;
587 gauge_t threads_connected = NAN;
588 gauge_t threads_cached = NAN;
589 derive_t threads_created = 0;
591 unsigned long long traffic_incoming = 0ULL;
592 unsigned long long traffic_outgoing = 0ULL;
594 if ((ud == NULL) || (ud->data == NULL))
595 {
596 ERROR ("mysql plugin: mysql_database_read: Invalid user data.");
597 return (-1);
598 }
600 db = (mysql_database_t *) ud->data;
602 /* An error message will have been printed in this case */
603 if ((con = getconnection (db)) == NULL)
604 return (-1);
606 query = "SHOW STATUS";
607 if (mysql_get_server_version (con) >= 50002)
608 query = "SHOW GLOBAL STATUS";
610 res = exec_query (con, query);
611 if (res == NULL)
612 return (-1);
614 while ((row = mysql_fetch_row (res)))
615 {
616 char *key;
617 unsigned long long val;
619 key = row[0];
620 val = atoll (row[1]);
622 if (strncmp (key, "Com_",
623 strlen ("Com_")) == 0)
624 {
625 if (val == 0ULL)
626 continue;
628 /* Ignore `prepared statements' */
629 if (strncmp (key, "Com_stmt_", strlen ("Com_stmt_")) != 0)
630 counter_submit ("mysql_commands",
631 key + strlen ("Com_"),
632 val, db);
633 }
634 else if (strncmp (key, "Handler_",
635 strlen ("Handler_")) == 0)
636 {
637 if (val == 0ULL)
638 continue;
640 counter_submit ("mysql_handler",
641 key + strlen ("Handler_"),
642 val, db);
643 }
644 else if (strncmp (key, "Qcache_",
645 strlen ("Qcache_")) == 0)
646 {
647 if (strcmp (key, "Qcache_hits") == 0)
648 qcache_hits = (derive_t) val;
649 else if (strcmp (key, "Qcache_inserts") == 0)
650 qcache_inserts = (derive_t) val;
651 else if (strcmp (key, "Qcache_not_cached") == 0)
652 qcache_not_cached = (derive_t) val;
653 else if (strcmp (key, "Qcache_lowmem_prunes") == 0)
654 qcache_lowmem_prunes = (derive_t) val;
655 else if (strcmp (key, "Qcache_queries_in_cache") == 0)
656 qcache_queries_in_cache = (gauge_t) val;
657 }
658 else if (strncmp (key, "Bytes_",
659 strlen ("Bytes_")) == 0)
660 {
661 if (strcmp (key, "Bytes_received") == 0)
662 traffic_incoming += val;
663 else if (strcmp (key, "Bytes_sent") == 0)
664 traffic_outgoing += val;
665 }
666 else if (strncmp (key, "Threads_",
667 strlen ("Threads_")) == 0)
668 {
669 if (strcmp (key, "Threads_running") == 0)
670 threads_running = (gauge_t) val;
671 else if (strcmp (key, "Threads_connected") == 0)
672 threads_connected = (gauge_t) val;
673 else if (strcmp (key, "Threads_cached") == 0)
674 threads_cached = (gauge_t) val;
675 else if (strcmp (key, "Threads_created") == 0)
676 threads_created = (derive_t) val;
677 }
678 else if (strncmp (key, "Table_locks_",
679 strlen ("Table_locks_")) == 0)
680 {
681 counter_submit ("mysql_locks",
682 key + strlen ("Table_locks_"),
683 val, db);
684 }
685 else if (db->innodb_stats && strncmp (key, "Innodb_", strlen ("Innodb_")) == 0)
686 {
687 /* buffer pool */
688 if (strcmp (key, "Innodb_buffer_pool_pages_data") == 0)
689 gauge_submit ("mysql_bpool_pages", "data", val, db);
690 else if (strcmp (key, "Innodb_buffer_pool_pages_dirty") == 0)
691 gauge_submit ("mysql_bpool_pages", "dirty", val, db);
692 else if (strcmp (key, "Innodb_buffer_pool_pages_flushed") == 0)
693 counter_submit ("mysql_bpool_counters", "flushed", val, db);
694 else if (strcmp (key, "Innodb_buffer_pool_pages_free") == 0)
695 gauge_submit ("mysql_bpool_pages", "free", val, db);
696 else if (strcmp (key, "Innodb_buffer_pool_pages_misc") == 0)
697 gauge_submit ("mysql_bpool_pages", "misc", val, db);
698 else if (strcmp (key, "Innodb_buffer_pool_pages_total") == 0)
699 gauge_submit ("mysql_bpool_pages", "total", val, db);
700 else if (strcmp (key, "Innodb_buffer_pool_read_ahead_rnd") == 0)
701 counter_submit ("mysql_bpool_counters", "read_ahead_rnd", val, db);
702 else if (strcmp (key, "Innodb_buffer_pool_read_ahead") == 0)
703 counter_submit ("mysql_bpool_counters", "read_ahead", val, db);
704 else if (strcmp (key, "Innodb_buffer_pool_read_ahead_evicted") == 0)
705 counter_submit ("mysql_bpool_counters", "read_ahead_evicted", val, db);
706 else if (strcmp (key, "Innodb_buffer_pool_read_requests") == 0)
707 counter_submit ("mysql_bpool_counters", "read_requests", val, db);
708 else if (strcmp (key, "Innodb_buffer_pool_reads") == 0)
709 counter_submit ("mysql_bpool_counters", "reads", val, db);
710 else if (strcmp (key, "Innodb_buffer_pool_write_requests") == 0)
711 counter_submit ("mysql_bpool_counters", "write_requests", val, db);
713 /* data */
714 if (strcmp (key, "Innodb_data_fsyncs") == 0)
715 counter_submit ("mysql_innodb_data", "fsyncs", val, db);
716 else if (strcmp (key, "Innodb_data_read") == 0)
717 counter_submit ("mysql_innodb_data", "read", val, db);
718 else if (strcmp (key, "Innodb_data_reads") == 0)
719 counter_submit ("mysql_innodb_data", "reads", val, db);
720 else if (strcmp (key, "Innodb_data_writes") == 0)
721 counter_submit ("mysql_bpool_counters", "writes", val, db);
722 else if (strcmp (key, "Innodb_data_written") == 0)
723 counter_submit ("mysql_innodb_data", "written", val, db);
725 /* double write */
726 else if (strcmp (key, "Innodb_dblwr_writes") == 0)
727 counter_submit ("mysql_innodb_dblwr", "writes", val, db);
728 else if (strcmp (key, "Innodb_dblwr_pages_written") == 0)
729 counter_submit ("mysql_innodb_dblwr", "written", val, db);
731 /* rows */
732 else if (strcmp (key, "Innodb_rows_deleted") == 0)
733 counter_submit ("mysql_innodb_rows", "deleted", val, db);
734 else if (strcmp (key, "Innodb_rows_inserted") == 0)
735 counter_submit ("mysql_innodb_rows", "inserted", val, db);
736 else if (strcmp (key, "Innodb_rows_read") == 0)
737 counter_submit ("mysql_innodb_rows", "read", val, db);
738 else if (strcmp (key, "Innodb_rows_updated") == 0)
739 counter_submit ("mysql_innodb_rows", "updated", val, db);
740 }
741 else if (strncmp (key, "Select_",
742 strlen ("Select_")) == 0)
743 {
744 counter_submit ("mysql_select",
745 key + strlen ("Select_"),
746 val, db);
747 }
748 else if (strncmp (key, "Sort_",
749 strlen ("Sort_")) == 0)
750 {
751 counter_submit ("mysql_sort",
752 key + strlen ("Sort_"),
753 val, db);
754 }
755 }
756 mysql_free_result (res); res = NULL;
758 if ((qcache_hits != 0)
759 || (qcache_inserts != 0)
760 || (qcache_not_cached != 0)
761 || (qcache_lowmem_prunes != 0))
762 {
763 derive_submit ("cache_result", "qcache-hits",
764 qcache_hits, db);
765 derive_submit ("cache_result", "qcache-inserts",
766 qcache_inserts, db);
767 derive_submit ("cache_result", "qcache-not_cached",
768 qcache_not_cached, db);
769 derive_submit ("cache_result", "qcache-prunes",
770 qcache_lowmem_prunes, db);
772 gauge_submit ("cache_size", "qcache",
773 qcache_queries_in_cache, db);
774 }
776 if (threads_created != 0)
777 {
778 gauge_submit ("threads", "running",
779 threads_running, db);
780 gauge_submit ("threads", "connected",
781 threads_connected, db);
782 gauge_submit ("threads", "cached",
783 threads_cached, db);
785 derive_submit ("total_threads", "created",
786 threads_created, db);
787 }
789 traffic_submit (traffic_incoming, traffic_outgoing, db);
791 if (db->master_stats)
792 mysql_read_master_stats (db, con);
794 if ((db->slave_stats) || (db->slave_notif))
795 mysql_read_slave_stats (db, con);
797 return (0);
798 } /* int mysql_read */
800 void module_register (void)
801 {
802 plugin_register_complex_config ("mysql", mysql_config);
803 } /* void module_register */