summaryrefslogtreecommitdiffstats
path: root/plugins/check_mysql.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_mysql.c')
-rw-r--r--plugins/check_mysql.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index 0cba50e6..5b9a4fec 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -34,7 +34,7 @@ const char *progname = "check_mysql";
34const char *copyright = "1999-2011"; 34const char *copyright = "1999-2011";
35const char *email = "devel@monitoring-plugins.org"; 35const char *email = "devel@monitoring-plugins.org";
36 36
37#define SLAVERESULTSIZE 70 37#define SLAVERESULTSIZE 96
38 38
39#include "common.h" 39#include "common.h"
40#include "utils.h" 40#include "utils.h"
@@ -89,6 +89,8 @@ static const char *metric_counter[LENGTH_METRIC_COUNTER] = {
89 "Uptime" 89 "Uptime"
90}; 90};
91 91
92#define MYSQLDUMP_THREADS_QUERY "SELECT COUNT(1) mysqldumpThreads FROM information_schema.processlist WHERE info LIKE 'SELECT /*!40001 SQL_NO_CACHE */%'"
93
92thresholds *my_threshold = NULL; 94thresholds *my_threshold = NULL;
93 95
94int process_arguments (int, char **); 96int process_arguments (int, char **);
@@ -275,11 +277,29 @@ main (int argc, char **argv)
275 /* Save slave status in slaveresult */ 277 /* Save slave status in slaveresult */
276 snprintf (slaveresult, SLAVERESULTSIZE, "Slave IO: %s Slave SQL: %s Seconds Behind Master: %s", row[slave_io_field], row[slave_sql_field], seconds_behind_field!=-1?row[seconds_behind_field]:"Unknown"); 278 snprintf (slaveresult, SLAVERESULTSIZE, "Slave IO: %s Slave SQL: %s Seconds Behind Master: %s", row[slave_io_field], row[slave_sql_field], seconds_behind_field!=-1?row[seconds_behind_field]:"Unknown");
277 279
278 /* Raise critical error if SQL THREAD or IO THREAD are stopped */ 280 /* Raise critical error if SQL THREAD or IO THREAD are stopped, but only if there are no mysqldump threads running */
279 if (strcmp (row[slave_io_field], "Yes") != 0 || strcmp (row[slave_sql_field], "Yes") != 0) { 281 if (strcmp (row[slave_io_field], "Yes") != 0 || strcmp (row[slave_sql_field], "Yes") != 0) {
280 mysql_free_result (res); 282 MYSQL_RES *res_mysqldump;
281 mysql_close (&mysql); 283 MYSQL_ROW row_mysqldump;
282 die (STATE_CRITICAL, "%s\n", slaveresult); 284 unsigned int mysqldump_threads = 0;
285
286 if (mysql_query (&mysql, MYSQLDUMP_THREADS_QUERY) == 0) {
287 /* store the result */
288 if ( (res_mysqldump = mysql_store_result (&mysql)) != NULL) {
289 if (mysql_num_rows(res_mysqldump) == 1) {
290 if ( (row_mysqldump = mysql_fetch_row (res_mysqldump)) != NULL) {
291 mysqldump_threads = atoi(row_mysqldump[0]);
292 }
293 }
294 /* free the result */
295 mysql_free_result (res_mysqldump);
296 }
297 }
298 if (mysqldump_threads == 0) {
299 die (STATE_CRITICAL, "%s\n", slaveresult);
300 } else {
301 strlcat (slaveresult, " Mysqldump: in progress", SLAVERESULTSIZE);
302 }
283 } 303 }
284 304
285 if (verbose >=3) { 305 if (verbose >=3) {
@@ -291,7 +311,7 @@ main (int argc, char **argv)
291 } 311 }
292 312
293 /* Check Seconds Behind against threshold */ 313 /* Check Seconds Behind against threshold */
294 if ((seconds_behind_field != -1) && (strcmp (row[seconds_behind_field], "NULL") != 0)) { 314 if ((seconds_behind_field != -1) && (row[seconds_behind_field] != NULL && strcmp (row[seconds_behind_field], "NULL") != 0)) {
295 double value = atof(row[seconds_behind_field]); 315 double value = atof(row[seconds_behind_field]);
296 int status; 316 int status;
297 317