[nagiosplug] check_mysql: when checking slave thread add ...

Nagios Plugin Development nagios-plugins at users.sourceforge.net
Sun Aug 18 18:50:14 CEST 2013


    Module: nagiosplug
    Branch: master
    Commit: 1627cdb46af9c7b179e82eb4b5bb0097250ff033
    Author: Tim Laszlo <tim.laszlo at gmail.com>
 Committer: Holger Weiss <holger at zedat.fu-berlin.de>
      Date: Fri Aug  3 15:12:55 2012 -0500
       URL: http://nagiosplug.git.sf.net/git/gitweb.cgi?p=nagiosplug/nagiosplug;a=commit;h=1627cdb

check_mysql: when checking slave thread add performance data for seconds behind master

---

 plugins/check_mysql.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index ad3d86f..eaad709 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -59,6 +59,9 @@ unsigned int db_port = MYSQL_PORT;
 int check_slave = 0, warn_sec = 0, crit_sec = 0;
 int verbose = 0;
 
+static double warning_time = 0;
+static double critical_time = 0;
+
 thresholds *my_threshold = NULL;
 
 int process_arguments (int, char **);
@@ -79,6 +82,7 @@ main (int argc, char **argv)
 	char *result = NULL;
 	char *error = NULL;
 	char slaveresult[SLAVERESULTSIZE];
+	char* slaveperfdata = NULL;
 
 	setlocale (LC_ALL, "");
 	bindtextdomain (PACKAGE, LOCALEDIR);
@@ -218,11 +222,17 @@ main (int argc, char **argv)
 
 				status = get_status(value, my_threshold);
 
+				slaveperfdata = fperfdata ("seconds behind master", value, "s",
+        	                        TRUE, (double) warning_time,
+                	                TRUE, (double) critical_time,
+                        	        FALSE, 0,
+                                	FALSE, 0);
+
 				if (status == STATE_WARNING) {
-					printf("SLOW_SLAVE %s: %s\n", _("WARNING"), slaveresult);
+					printf("SLOW_SLAVE %s: %s|%s\n", _("WARNING"), slaveresult, slaveperfdata);
 					exit(STATE_WARNING);
 				} else if (status == STATE_CRITICAL) {
-					printf("SLOW_SLAVE %s: %s\n", _("CRITICAL"), slaveresult);
+					printf("SLOW_SLAVE %s: %s|%s\n", _("CRITICAL"), slaveresult, slaveperfdata);
 					exit(STATE_CRITICAL);
 				}
 			}
@@ -236,7 +246,9 @@ main (int argc, char **argv)
 	mysql_close (&mysql);
 
 	/* print out the result of stats */
-	if (check_slave) {
+	if (check_slave && slaveperfdata) {
+		printf ("%s %s|%s\n", result, slaveresult, slaveperfdata);
+	} else if (check_slave) {
 		printf ("%s %s\n", result, slaveresult);
 	} else {
 		printf ("%s\n", result);
@@ -339,9 +351,11 @@ process_arguments (int argc, char **argv)
 			break;
 		case 'w':
 			warning = optarg;
+			warning_time = strtod (warning, NULL);
 			break;
 		case 'c':
 			critical = optarg;
+			critical_time = strtod (critical, NULL);
 			break;
 		case 'V':									/* version */
 			print_revision (progname, NP_VERSION);





More information about the Commits mailing list