projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge upstream, address conflict in src/utils/cmds/cmds_test.c
[collectd.git]
/
src
/
mysql.c
diff --git
a/src/mysql.c
b/src/mysql.c
index
7fe6d76
..
7ba10f6
100644
(file)
--- a/
src/mysql.c
+++ b/
src/mysql.c
@@
-29,8
+29,8
@@
#include "collectd.h"
#include "collectd.h"
-#include "common.h"
#include "plugin.h"
#include "plugin.h"
+#include "utils/common/common.h"
#ifdef HAVE_MYSQL_H
#include <mysql.h>
#ifdef HAVE_MYSQL_H
#include <mysql.h>
@@
-58,17
+58,17
@@
struct mysql_database_s /* {{{ */
int port;
int timeout;
int port;
int timeout;
-
_B
ool master_stats;
-
_B
ool slave_stats;
-
_B
ool innodb_stats;
-
_B
ool wsrep_stats;
+
b
ool master_stats;
+
b
ool slave_stats;
+
b
ool innodb_stats;
+
b
ool wsrep_stats;
-
_B
ool slave_notif;
-
_B
ool slave_io_running;
-
_B
ool slave_sql_running;
+
b
ool slave_notif;
+
b
ool slave_io_running;
+
b
ool slave_sql_running;
MYSQL *con;
MYSQL *con;
-
_B
ool is_connected;
+
b
ool is_connected;
};
typedef struct mysql_database_s mysql_database_t; /* }}} */
};
typedef struct mysql_database_s mysql_database_t; /* }}} */
@@
-147,8
+147,8
@@
static int mysql_config_database(oconfig_item_t *ci) /* {{{ */
db->timeout = 0;
/* trigger a notification, if it's not running */
db->timeout = 0;
/* trigger a notification, if it's not running */
- db->slave_io_running =
1
;
- db->slave_sql_running =
1
;
+ db->slave_io_running =
true
;
+ db->slave_sql_running =
true
;
status = cf_util_get_string(ci, &db->instance);
if (status != 0) {
status = cf_util_get_string(ci, &db->instance);
if (status != 0) {
@@
-218,7
+218,7
@@
static int mysql_config_database(oconfig_item_t *ci) /* {{{ */
(db->database != NULL) ? db->database : "<default>");
if (db->instance != NULL)
(db->database != NULL) ? db->database : "<default>");
if (db->instance != NULL)
- snprintf(cb_name, sizeof(cb_name), "mysql-%s", db->instance);
+ s
s
nprintf(cb_name, sizeof(cb_name), "mysql-%s", db->instance);
else
sstrncpy(cb_name, "mysql", sizeof(cb_name));
else
sstrncpy(cb_name, "mysql", sizeof(cb_name));
@@
-268,14
+268,18
@@
static MYSQL *getconnection(mysql_database_t *db) {
WARNING("mysql plugin: Lost connection to instance \"%s\": %s",
db->instance, mysql_error(db->con));
}
WARNING("mysql plugin: Lost connection to instance \"%s\": %s",
db->instance, mysql_error(db->con));
}
- db->is_connected =
0
;
+ db->is_connected =
false
;
+ /* Close the old connection before initializing a new one. */
+ if (db->con != NULL) {
+ mysql_close(db->con);
+ db->con = NULL;
+ }
+
+ db->con = mysql_init(NULL);
if (db->con == NULL) {
if (db->con == NULL) {
- db->con = mysql_init(NULL);
- if (db->con == NULL) {
- ERROR("mysql plugin: mysql_init failed: %s", mysql_error(db->con));
- return NULL;
- }
+ ERROR("mysql plugin: mysql_init failed: %s", mysql_error(db->con));
+ return NULL;
}
/* Configure TCP connect timeout (default: 0) */
}
/* Configure TCP connect timeout (default: 0) */
@@
-301,7
+305,7
@@
static MYSQL *getconnection(mysql_database_t *db) {
mysql_get_host_info(db->con), (cipher != NULL) ? cipher : "<none>",
mysql_get_server_info(db->con), mysql_get_proto_info(db->con));
mysql_get_host_info(db->con), (cipher != NULL) ? cipher : "<none>",
mysql_get_server_info(db->con), mysql_get_proto_info(db->con));
- db->is_connected =
1
;
+ db->is_connected =
true
;
return db->con;
} /* static MYSQL *getconnection (mysql_database_t *db) */
return db->con;
} /* static MYSQL *getconnection (mysql_database_t *db) */
@@
-359,7
+363,7
@@
static void traffic_submit(derive_t rx, derive_t tx, mysql_database_t *db) {
static MYSQL_RES *exec_query(MYSQL *con, const char *query) {
MYSQL_RES *res;
static MYSQL_RES *exec_query(MYSQL *con, const char *query) {
MYSQL_RES *res;
-
in
t query_len = strlen(query);
+
size_
t query_len = strlen(query);
if (mysql_real_query(con, query, query_len)) {
ERROR("mysql plugin: Failed to execute query: %s", mysql_error(con));
if (mysql_real_query(con, query, query_len)) {
ERROR("mysql plugin: Failed to execute query: %s", mysql_error(con));
@@
-496,31
+500,31
@@
static int mysql_read_slave_stats(mysql_database_t *db, MYSQL *con) {
if (((io == NULL) || (strcasecmp(io, "yes") != 0)) &&
(db->slave_io_running)) {
n.severity = NOTIF_WARNING;
if (((io == NULL) || (strcasecmp(io, "yes") != 0)) &&
(db->slave_io_running)) {
n.severity = NOTIF_WARNING;
- snprintf(n.message, sizeof(n.message),
- "slave I/O thread not started or not connected to master");
+ s
s
nprintf(n.message, sizeof(n.message),
+
"slave I/O thread not started or not connected to master");
plugin_dispatch_notification(&n);
plugin_dispatch_notification(&n);
- db->slave_io_running =
0
;
+ db->slave_io_running =
false
;
} else if (((io != NULL) && (strcasecmp(io, "yes") == 0)) &&
(!db->slave_io_running)) {
n.severity = NOTIF_OKAY;
} else if (((io != NULL) && (strcasecmp(io, "yes") == 0)) &&
(!db->slave_io_running)) {
n.severity = NOTIF_OKAY;
- snprintf(n.message, sizeof(n.message),
- "slave I/O thread started and connected to master");
+ s
s
nprintf(n.message, sizeof(n.message),
+
"slave I/O thread started and connected to master");
plugin_dispatch_notification(&n);
plugin_dispatch_notification(&n);
- db->slave_io_running =
1
;
+ db->slave_io_running =
true
;
}
if (((sql == NULL) || (strcasecmp(sql, "yes") != 0)) &&
(db->slave_sql_running)) {
n.severity = NOTIF_WARNING;
}
if (((sql == NULL) || (strcasecmp(sql, "yes") != 0)) &&
(db->slave_sql_running)) {
n.severity = NOTIF_WARNING;
- snprintf(n.message, sizeof(n.message), "slave SQL thread not started");
+ s
s
nprintf(n.message, sizeof(n.message), "slave SQL thread not started");
plugin_dispatch_notification(&n);
plugin_dispatch_notification(&n);
- db->slave_sql_running =
0
;
+ db->slave_sql_running =
false
;
} else if (((sql != NULL) && (strcasecmp(sql, "yes") == 0)) &&
(!db->slave_sql_running)) {
n.severity = NOTIF_OKAY;
} else if (((sql != NULL) && (strcasecmp(sql, "yes") == 0)) &&
(!db->slave_sql_running)) {
n.severity = NOTIF_OKAY;
- snprintf(n.message, sizeof(n.message), "slave SQL thread started");
+ s
s
nprintf(n.message, sizeof(n.message), "slave SQL thread started");
plugin_dispatch_notification(&n);
plugin_dispatch_notification(&n);
- db->slave_sql_running =
1
;
+ db->slave_sql_running =
true
;
}
}
}
}
@@
-901,6
+905,8
@@
static int mysql_read(user_data_t *ud) {
} else if (strncmp(key, "Slow_queries", strlen("Slow_queries")) == 0) {
derive_submit("mysql_slow_queries", NULL, val, db);
} else if (strncmp(key, "Slow_queries", strlen("Slow_queries")) == 0) {
derive_submit("mysql_slow_queries", NULL, val, db);
+ } else if (strcmp(key, "Uptime") == 0) {
+ gauge_submit("uptime", NULL, val, db);
}
}
mysql_free_result(res);
}
}
mysql_free_result(res);