summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3ecbbe9)
raw | patch | inline | side by side (parent: 3ecbbe9)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Mon, 5 Jul 2010 08:12:32 +0000 (10:12 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Mon, 5 Jul 2010 08:12:32 +0000 (10:12 +0200) |
src/collectd.conf.pod | patch | blob | history | |
src/mysql.c | patch | blob | history |
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 1d479b5a045ca2c9d224b3fc3ac460f52ad43b7d..44c000f9e360e922e5ea495cfd256f7e075b3c05 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
The C<mysql plugin> requires B<mysqlclient> to be installed. It connects to
one or more databases when started and keeps the connection up as long as
possible. When the connection is interrupted for whatever reason it will try
-to re-connect. The plugin will complaint loudly in case anything goes wrong.
+to re-connect. The plugin will complain loudly in case anything goes wrong.
This plugin issues the MySQL C<SHOW STATUS> / C<SHOW GLOBAL STATUS> command
and collects information about MySQL network traffic, executed statements,
diff --git a/src/mysql.c b/src/mysql.c
index c7b796b18d79d5c92dcc34cacba287c4a0db26ea..cd34d7fcbea2a4d8e0d9a39926544ed65a8bf27e 100644 (file)
--- a/src/mysql.c
+++ b/src/mysql.c
char *socket;
int port;
- int master_stats;
- int slave_stats;
+ _Bool master_stats;
+ _Bool slave_stats;
- int slave_notif;
- int slave_io_running;
- int slave_sql_running;
+ _Bool slave_notif;
+ _Bool slave_io_running;
+ _Bool slave_sql_running;
MYSQL *con;
int state;
* </Database>
* </Plugin>
*/
-
-static int mysql_config_set_string (char **ret_string, /* {{{ */
- oconfig_item_t *ci)
-{
- char *string;
-
- if ((ci->values_num != 1)
- || (ci->values[0].type != OCONFIG_TYPE_STRING))
- {
- WARNING ("mysql plugin: The `%s' config option "
- "needs exactly one string argument.", ci->key);
- return (-1);
- }
-
- string = strdup (ci->values[0].value.string);
- if (string == NULL)
- {
- ERROR ("mysql plugin: strdup failed.");
- return (-1);
- }
-
- if (*ret_string != NULL)
- free (*ret_string);
- *ret_string = string;
-
- return (0);
-} /* }}} int mysql_config_set_string */
-
-static int mysql_config_set_int (int *ret_int, /* {{{ */
- oconfig_item_t *ci)
-{
- if ((ci->values_num != 1)
- || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
- {
- WARNING ("mysql plugin: The `%s' config option "
- "needs exactly one string argument.", ci->key);
- return (-1);
- }
-
- *ret_int = ci->values[0].value.number;
-
- return (0);
-} /* }}} int mysql_config_set_int */
-
-static int mysql_config_set_boolean (int *ret_boolean, /* {{{ */
- oconfig_item_t *ci)
-{
- int status = 0;
-
- if (ci->values_num != 1)
- status = -1;
-
- if (status == 0)
- {
- if (ci->values[0].type == OCONFIG_TYPE_BOOLEAN)
- *ret_boolean = ci->values[0].value.boolean;
- else if (ci->values[0].type == OCONFIG_TYPE_STRING)
- {
- if (IS_TRUE (ci->values[0].value.string))
- *ret_boolean = 1;
- else if (IS_FALSE (ci->values[0].value.string))
- *ret_boolean = 0;
- else
- status = -1;
- }
- else
- status = -1;
- }
-
- if (status != 0)
- {
- WARNING ("mysql plugin: The `%s' config option "
- "needs exactly one boolean argument.", ci->key);
- return (-1);
- }
- return (0);
-} /* }}} mysql_config_set_boolean */
-
-static int mysql_config (oconfig_item_t *ci) /* {{{ */
+static int mysql_config_database (oconfig_item_t *ci) /* {{{ */
{
mysql_database_t *db;
- int plugin_block;
int status = 0;
int i;
db->slave_io_running = 1;
db->slave_sql_running = 1;
- plugin_block = 1;
- if (strcasecmp ("Plugin", ci->key) == 0)
- {
- db->instance = NULL;
- }
- else if (strcasecmp ("Database", ci->key) == 0)
- {
- plugin_block = 0;
- status = mysql_config_set_string (&db->instance, ci);
- if (status != 0)
- {
- sfree (db);
- return (status);
- }
- assert (db->instance != NULL);
- }
- else
+ status = cf_util_get_string (ci, &db->instance);
+ if (status != 0)
{
- ERROR ("mysql plugin: mysql_config: "
- "Invalid key: %s", ci->key);
- return (-1);
+ sfree (db);
+ return (status);
}
+ assert (db->instance != NULL);
/* Fill the `mysql_database_t' structure.. */
for (i = 0; i < ci->children_num; i++)
oconfig_item_t *child = ci->children + i;
if (strcasecmp ("Host", child->key) == 0)
- status = mysql_config_set_string (&db->host, child);
+ status = cf_util_get_string (child, &db->host);
else if (strcasecmp ("User", child->key) == 0)
- status = mysql_config_set_string (&db->user, child);
+ status = cf_util_get_string (child, &db->user);
else if (strcasecmp ("Password", child->key) == 0)
- status = mysql_config_set_string (&db->pass, child);
+ status = cf_util_get_string (child, &db->pass);
else if (strcasecmp ("Port", child->key) == 0)
- status = mysql_config_set_int (&db->port, child);
- else if (strcasecmp ("Socket", child->key) == 0)
- status = mysql_config_set_string (&db->socket, child);
- /* Check if we're currently handling the `Plugin' block. If so,
- * handle `Database' _blocks_, too. */
- else if ((plugin_block != 0)
- && (strcasecmp ("Database", child->key) == 0)
- && (child->children != NULL))
{
- /* If `plugin_block > 1', there has been at least one
- * `Database' block */
- plugin_block++;
- status = mysql_config (child);
+ status = cf_util_get_port_number (child);
+ if (status > 0)
+ {
+ db->port = status;
+ status = 0;
+ }
}
- /* Now handle ordinary `Database' options (without children) */
- else if ((strcasecmp ("Database", child->key) == 0)
- && (child->children == NULL))
- status = mysql_config_set_string (&db->database, child);
+ else if (strcasecmp ("Socket", child->key) == 0)
+ status = cf_util_get_string (child, &db->socket);
+ else if (strcasecmp ("Database", child->key) == 0)
+ status = cf_util_get_string (child, &db->database);
else if (strcasecmp ("MasterStats", child->key) == 0)
- status = mysql_config_set_boolean (&db->master_stats, child);
+ status = cf_util_get_boolean (child, &db->master_stats);
else if (strcasecmp ("SlaveStats", child->key) == 0)
- status = mysql_config_set_boolean (&db->slave_stats, child);
+ status = cf_util_get_boolean (child, &db->slave_stats);
else if (strcasecmp ("SlaveNotifications", child->key) == 0)
- status = mysql_config_set_boolean (&db->slave_notif, child);
+ status = cf_util_get_boolean (child, &db->slave_notif);
else
{
WARNING ("mysql plugin: Option `%s' not allowed here.", child->key);
break;
}
- /* Check if there were any `Database' blocks. */
- if (plugin_block > 1)
- {
- /* There were connection blocks. Don't use any legacy stuff. */
- if ((db->host != NULL)
- || (db->user != NULL)
- || (db->pass != NULL)
- || (db->database != NULL)
- || (db->socket != NULL)
- || (db->port != 0))
- {
- WARNING ("mysql plugin: At least one <Database> "
- "block has been found. The legacy "
- "configuration will be ignored.");
- }
- mysql_database_free (db);
- return (0);
- }
- else if (plugin_block != 0)
- {
- WARNING ("mysql plugin: You're using the legacy "
- "configuration options. Please consider "
- "updating your configuration!");
- }
-
- /* Check that all necessary options have been given. */
- while (status == 0)
- {
- /* Zero is allowed and automatically handled by
- * `mysql_real_connect'. */
- if ((db->port < 0) || (db->port > 65535))
- {
- ERROR ("mysql plugin: Database %s: Port number out "
- "of range: %i",
- (db->instance != NULL)
- ? db->instance
- : "<legacy>",
- db->port);
- status = -1;
- }
- break;
- } /* while (status == 0) */
-
/* If all went well, register this database for reading */
if (status == 0)
{
return (-1);
}
+ return (0);
+} /* }}} int mysql_config_database */
+
+static int mysql_config (oconfig_item_t *ci) /* {{{ */
+{
+ int i;
+
+ if (ci == NULL)
+ return (EINVAL);
+
+ /* Fill the `mysql_database_t' structure.. */
+ for (i = 0; i < ci->children_num; i++)
+ {
+ oconfig_item_t *child = ci->children + i;
+
+ if (strcasecmp ("Database", child->key) == 0)
+ mysql_config_database (child);
+ else
+ WARNING ("mysql plugin: Option \"%s\" not allowed here.",
+ child->key);
+ }
+
return (0);
} /* }}} int mysql_config */