X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fmysql.c;h=caebdf31f3d0f3e1156398cc9768863f4b4738d5;hb=fd909f8965b2b6714dc1da328c77f3681c04af5e;hp=ac65f75a30ebf6b54d3b1158ea03b500387437f7;hpb=70a3ff972ec2f3980a28438cf4fc0a459a594b02;p=collectd.git diff --git a/src/mysql.c b/src/mysql.c index ac65f75a..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.. */ @@ -60,43 +56,43 @@ static char *traffic_file = "traffic-mysql.rrd"; static char *commands_ds_def[] = { - "DS:value:COUNTER:25:0:U", + "DS:value:COUNTER:"COLLECTD_HEARTBEAT":0:U", NULL }; static int commands_ds_num = 1; static char *handler_ds_def[] = { - "DS:value:COUNTER:25:0:U", + "DS:value:COUNTER:"COLLECTD_HEARTBEAT":0:U", NULL }; static int handler_ds_num = 1; static char *qcache_ds_def[] = { - "DS:hits:COUNTER:25:0:U", - "DS:inserts:COUNTER:25:0:U", - "DS:not_cached:COUNTER:25:0:U", - "DS:lowmem_prunes:COUNTER:25:0:U", - "DS:queries_in_cache:GAUGE:25:0:U", + "DS:hits:COUNTER:"COLLECTD_HEARTBEAT":0:U", + "DS:inserts:COUNTER:"COLLECTD_HEARTBEAT":0:U", + "DS:not_cached:COUNTER:"COLLECTD_HEARTBEAT":0:U", + "DS:lowmem_prunes:COUNTER:"COLLECTD_HEARTBEAT":0:U", + "DS:queries_in_cache:GAUGE:"COLLECTD_HEARTBEAT":0:U", NULL }; static int qcache_ds_num = 5; static char *threads_ds_def[] = { - "DS:running:GAUGE:25:0:U", - "DS:connected:GAUGE:25:0:U", - "DS:cached:GAUGE:25:0:U", - "DS:created:COUNTER:25:0:U", + "DS:running:GAUGE:"COLLECTD_HEARTBEAT":0:U", + "DS:connected:GAUGE:"COLLECTD_HEARTBEAT":0:U", + "DS:cached:GAUGE:"COLLECTD_HEARTBEAT":0:U", + "DS:created:COUNTER:"COLLECTD_HEARTBEAT":0:U", NULL }; static int threads_ds_num = 4; static char *traffic_ds_def[] = { - "DS:incoming:COUNTER:25:0:U", - "DS:outgoing:COUNTER:25:0:U", + "DS:incoming:COUNTER:"COLLECTD_HEARTBEAT":0:U", + "DS:outgoing:COUNTER:"COLLECTD_HEARTBEAT":0:U", NULL }; static int traffic_ds_num = 2; @@ -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))