|
|
@@ -62,6 +62,29 @@ int verbose = 0;
|
|
|
static double warning_time = 0;
|
|
|
static double critical_time = 0;
|
|
|
|
|
|
+#define LENGTH_METRIC_UNIT 7
|
|
|
+static const char *metric_unit[LENGTH_METRIC_UNIT] = {
|
|
|
+ "Connections",
|
|
|
+ "Open_files",
|
|
|
+ "Open_tables",
|
|
|
+ "Qcache_free_memory",
|
|
|
+ "Qcache_queries_in_cache",
|
|
|
+ "Threads_connected",
|
|
|
+ "Threads_running"
|
|
|
+};
|
|
|
+
|
|
|
+#define LENGTH_METRIC_COUNTER 8
|
|
|
+static const char *metric_counter[LENGTH_METRIC_COUNTER] = {
|
|
|
+ "Qcache_hits",
|
|
|
+ "Qcache_inserts",
|
|
|
+ "Qcache_lowmem_prunes",
|
|
|
+ "Qcache_not_cached",
|
|
|
+ "Queries",
|
|
|
+ "Questions",
|
|
|
+ "Table_locks_waited",
|
|
|
+ "Uptime"
|
|
|
+};
|
|
|
+
|
|
|
thresholds *my_threshold = NULL;
|
|
|
|
|
|
int process_arguments (int, char **);
|
|
|
@@ -82,7 +105,9 @@ main (int argc, char **argv)
|
|
|
char *result = NULL;
|
|
|
char *error = NULL;
|
|
|
char slaveresult[SLAVERESULTSIZE];
|
|
|
- char* slaveperfdata = NULL;
|
|
|
+ char* perf;
|
|
|
+
|
|
|
+ perf = strdup ("");
|
|
|
|
|
|
setlocale (LC_ALL, "");
|
|
|
bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
@@ -130,6 +155,34 @@ main (int argc, char **argv)
|
|
|
die (STATE_CRITICAL, "%s\n", mysql_error (&mysql));
|
|
|
}
|
|
|
|
|
|
+ /* try to fetch some perf data */
|
|
|
+ if (mysql_query (&mysql, "show global status") == 0) {
|
|
|
+ if ( (res = mysql_store_result (&mysql)) == NULL) {
|
|
|
+ error = strdup(mysql_error(&mysql));
|
|
|
+ mysql_close (&mysql);
|
|
|
+ die (STATE_CRITICAL, _("status store_result error: %s\n"), error);
|
|
|
+ }
|
|
|
+
|
|
|
+ while ( (row = mysql_fetch_row (res)) != NULL) {
|
|
|
+ int i;
|
|
|
+
|
|
|
+ for(i = 0; i < LENGTH_METRIC_UNIT - 1; i++) {
|
|
|
+ if (strcmp(row[0], metric_unit[i]) == 0) {
|
|
|
+ xasprintf(&perf, "%s %s", perf, perfdata(metric_unit[i],
|
|
|
+ atol(row[1]), "", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(i = 0; i < LENGTH_METRIC_COUNTER - 1; i++) {
|
|
|
+ if (strcmp(row[0], metric_counter[i]) == 0) {
|
|
|
+ xasprintf(&perf, "%s %s", perf, perfdata(metric_counter[i],
|
|
|
+ atol(row[1]), "c", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if(check_slave) {
|
|
|
/* check the slave status */
|
|
|
if (mysql_query (&mysql, "show slave status") != 0) {
|
|
|
@@ -222,17 +275,17 @@ main (int argc, char **argv)
|
|
|
|
|
|
status = get_status(value, my_threshold);
|
|
|
|
|
|
- slaveperfdata = fperfdata ("seconds behind master", value, "s",
|
|
|
+ xasprintf (&perf, "%s %s", perf, fperfdata ("seconds behind master", value, "s",
|
|
|
TRUE, (double) warning_time,
|
|
|
TRUE, (double) critical_time,
|
|
|
FALSE, 0,
|
|
|
- FALSE, 0);
|
|
|
+ FALSE, 0));
|
|
|
|
|
|
if (status == STATE_WARNING) {
|
|
|
- printf("SLOW_SLAVE %s: %s|%s\n", _("WARNING"), slaveresult, slaveperfdata);
|
|
|
+ printf("SLOW_SLAVE %s: %s|%s\n", _("WARNING"), slaveresult, perf);
|
|
|
exit(STATE_WARNING);
|
|
|
} else if (status == STATE_CRITICAL) {
|
|
|
- printf("SLOW_SLAVE %s: %s|%s\n", _("CRITICAL"), slaveresult, slaveperfdata);
|
|
|
+ printf("SLOW_SLAVE %s: %s|%s\n", _("CRITICAL"), slaveresult, perf);
|
|
|
exit(STATE_CRITICAL);
|
|
|
}
|
|
|
}
|
|
|
@@ -246,12 +299,10 @@ main (int argc, char **argv)
|
|
|
mysql_close (&mysql);
|
|
|
|
|
|
/* print out the result of stats */
|
|
|
- if (check_slave && slaveperfdata) {
|
|
|
- printf ("%s %s|%s\n", result, slaveresult, slaveperfdata);
|
|
|
- } else if (check_slave) {
|
|
|
- printf ("%s %s\n", result, slaveresult);
|
|
|
+ if (check_slave) {
|
|
|
+ printf ("%s %s|%s\n", result, slaveresult, perf);
|
|
|
} else {
|
|
|
- printf ("%s\n", result);
|
|
|
+ printf ("%s|%s\n", result, perf);
|
|
|
}
|
|
|
|
|
|
return STATE_OK;
|