aboutsummaryrefslogtreecommitdiff
path: root/plugins/check_mysql.c
diff options
context:
space:
mode:
authorGravatar Tim Laszlo <tim.laszlo@gmail.com> 2012-08-06 11:15:35 -0500
committerGravatar Holger Weiss <holger@zedat.fu-berlin.de> 2013-08-18 18:38:10 +0200
commitc8d8b584475692d0e325e3f6658a0d3e5d464d4a (patch)
treee7b224f2fb10cab45f99ad21bcb670f57a8cc0b2 /plugins/check_mysql.c
parent1627cdb46af9c7b179e82eb4b5bb0097250ff033 (diff)
downloadmonitoring-plugins-c8d8b584475692d0e325e3f6658a0d3e5d464d4a.tar.gz
check_mysql: add perfromance metrics for all checks
Diffstat (limited to 'plugins/check_mysql.c')
-rw-r--r--plugins/check_mysql.c71
1 files changed, 61 insertions, 10 deletions
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index eaad709f..212910d4 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -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;