X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmysql.c;h=1c009a07e56c3631446ff5fe2fa9f3b8d60743f7;hb=bc7992ed0693313a2b1fe282a5bf23f1cc9f8e42;hp=4e72b5bf8989669cafb724ce011cc8b0a28cc2ee;hpb=68ab7da7a51018a00e6e03347182b988a30296a7;p=collectd.git diff --git a/src/mysql.c b/src/mysql.c index 4e72b5bf..1c009a07 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -38,14 +38,18 @@ static const char *config_keys[] = "User", "Password", "Database", + "Port", + "Socket", NULL }; -static int config_keys_num = 4; +static int config_keys_num = 6; static char *host = "localhost"; static char *user; static char *pass; static char *db = NULL; +static char *socket = NULL; +static int port = 0; static MYSQL *getconnection (void) { @@ -88,7 +92,7 @@ static MYSQL *getconnection (void) return (NULL); } - if (mysql_real_connect (con, host, user, pass, db, 0, NULL, 0) == NULL) + if (mysql_real_connect (con, host, user, pass, db, port, socket, 0) == NULL) { ERROR ("mysql_real_connect failed: %s", mysql_error (con)); state = 0; @@ -113,9 +117,36 @@ static int config (const char *key, const char *value) return ((pass = strdup (value)) == NULL ? 1 : 0); else if (strcasecmp (key, "database") == 0) return ((db = strdup (value)) == NULL ? 1 : 0); + else if (strcasecmp (key, "socket") == 0) + return ((socket = strdup (value)) == NULL ? 1 : 0); + else if (strcasecmp (key, "port") == 0) + { + char *endptr = NULL; + int temp; + + errno = 0; + temp = strtol (value, &endptr, 0); + if ((errno != 0) || (value == endptr)) + { + ERROR ("mysql plugin: Invalid \"Port\" argument: %s", + value); + port = 0; + return (1); + } + else if ((temp < 0) || (temp >= 65535)) + { + ERROR ("mysql plugin: Port number out of range: %i", + temp); + port = 0; + return (1); + } + + port = temp; + return (0); + } else return (-1); -} +} /* int config */ static void counter_submit (const char *type, const char *type_instance, counter_t value) @@ -127,7 +158,6 @@ static void counter_submit (const char *type, const char *type_instance, vl.values = values; vl.values_len = 1; - vl.time = time (NULL); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin)); sstrncpy (vl.type, type, sizeof (vl.type)); @@ -151,7 +181,6 @@ static void qcache_submit (counter_t hits, counter_t inserts, vl.values = values; vl.values_len = 5; - vl.time = time (NULL); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin)); sstrncpy (vl.type, "mysql_qcache", sizeof (vl.type)); @@ -172,7 +201,6 @@ static void threads_submit (gauge_t running, gauge_t connected, gauge_t cached, vl.values = values; vl.values_len = 4; - vl.time = time (NULL); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin)); sstrncpy (vl.type, "mysql_threads", sizeof (vl.type)); @@ -190,7 +218,6 @@ static void traffic_submit (counter_t rx, counter_t tx) vl.values = values; vl.values_len = 2; - vl.time = time (NULL); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin)); sstrncpy (vl.type, "mysql_octets", sizeof (vl.type));