X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmysql.c;h=caebdf31f3d0f3e1156398cc9768863f4b4738d5;hb=0c1205256d8b5096045f5cfe54cae9937c8c7980;hp=9a1398694b3ac1476ad94401d94373bc3839a5f7;hpb=c87194194948fec81eb7ead8b7d9615efc7778e1;p=collectd.git diff --git a/src/mysql.c b/src/mysql.c index 9a139869..caebdf31 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -44,10 +44,6 @@ static char *user; static char *pass; static char *db = NULL; -#if MYSQL_HAVE_READ -static char init_suceeded = 0; -#endif - /* TODO * understand `Select_*' and possibly do that stuff as well.. */ @@ -117,6 +113,11 @@ static MYSQL *getconnection (void) static MYSQL *con; static int state; + static int wait_for = 0; + static int wait_increase = 60; + + int step; + if (state != 0) { int err; @@ -132,6 +133,19 @@ static MYSQL *getconnection (void) } } + step = atoi (COLLECTD_STEP); + + if (wait_for > 0) + { + wait_for -= step; + return (NULL); + } + + wait_for = wait_increase; + wait_increase *= 2; + if (wait_increase > 86400) + wait_increase = 86400; + if ((con = mysql_init (con)) == NULL) { syslog (LOG_ERR, "mysql_init failed: %s", mysql_error (con)); @@ -148,6 +162,8 @@ static MYSQL *getconnection (void) else { state = 1; + wait_for = 0; + wait_increase = 60; return (con); } } /* static MYSQL *getconnection (void) */ @@ -155,16 +171,6 @@ static MYSQL *getconnection (void) static void init (void) { -#if MYSQL_HAVE_READ - if (getconnection () != NULL) - init_suceeded = 1; - else - { - syslog (LOG_ERR, "The `mysql' plugin will be disabled because `init' failed to connect to `%s'", host); - init_suceeded = 0; - } -#endif /* MYSQL_HAVE_READ */ - return; } @@ -358,14 +364,14 @@ static void mysql_read (void) unsigned long long traffic_incoming = 0ULL; unsigned long long traffic_outgoing = 0ULL; - if (init_suceeded == 0) - return; - /* An error message will have been printed in this case */ if ((con = getconnection ()) == NULL) return; query = "SHOW STATUS"; + if (mysql_get_server_version (con) >= 50002) + query = "SHOW GLOBAL STATUS"; + query_len = strlen (query); if (mysql_real_query (con, query, query_len))