summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Laszlo <tim.laszlo@gmail.com>2012-08-06 16:15:35 (GMT)
committerHolger Weiss <holger@zedat.fu-berlin.de>2013-08-18 16:38:10 (GMT)
commitc8d8b584475692d0e325e3f6658a0d3e5d464d4a (patch)
treee7b224f2fb10cab45f99ad21bcb670f57a8cc0b2
parent1627cdb46af9c7b179e82eb4b5bb0097250ff033 (diff)
downloadmonitoring-plugins-c8d8b584475692d0e325e3f6658a0d3e5d464d4a.tar.gz
check_mysql: add perfromance metrics for all checks
-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 eaad709..212910d 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -62,6 +62,29 @@ int verbose = 0;
62static double warning_time = 0; 62static double warning_time = 0;
63static double critical_time = 0; 63static double critical_time = 0;
64 64
65#define LENGTH_METRIC_UNIT 7
66static const char *metric_unit[LENGTH_METRIC_UNIT] = {
67 "Connections",
68 "Open_files",
69 "Open_tables",
70 "Qcache_free_memory",
71 "Qcache_queries_in_cache",
72 "Threads_connected",
73 "Threads_running"
74};
75
76#define LENGTH_METRIC_COUNTER 8
77static const char *metric_counter[LENGTH_METRIC_COUNTER] = {
78 "Qcache_hits",
79 "Qcache_inserts",
80 "Qcache_lowmem_prunes",
81 "Qcache_not_cached",
82 "Queries",
83 "Questions",
84 "Table_locks_waited",
85 "Uptime"
86};
87
65thresholds *my_threshold = NULL; 88thresholds *my_threshold = NULL;
66 89
67int process_arguments (int, char **); 90int process_arguments (int, char **);
@@ -82,7 +105,9 @@ main (int argc, char **argv)
82 char *result = NULL; 105 char *result = NULL;
83 char *error = NULL; 106 char *error = NULL;
84 char slaveresult[SLAVERESULTSIZE]; 107 char slaveresult[SLAVERESULTSIZE];
85 char* slaveperfdata = NULL; 108 char* perf;
109
110 perf = strdup ("");
86 111
87 setlocale (LC_ALL, ""); 112 setlocale (LC_ALL, "");
88 bindtextdomain (PACKAGE, LOCALEDIR); 113 bindtextdomain (PACKAGE, LOCALEDIR);
@@ -130,6 +155,34 @@ main (int argc, char **argv)
130 die (STATE_CRITICAL, "%s\n", mysql_error (&mysql)); 155 die (STATE_CRITICAL, "%s\n", mysql_error (&mysql));
131 } 156 }
132 157
158 /* try to fetch some perf data */
159 if (mysql_query (&mysql, "show global status") == 0) {
160 if ( (res = mysql_store_result (&mysql)) == NULL) {
161 error = strdup(mysql_error(&mysql));
162 mysql_close (&mysql);
163 die (STATE_CRITICAL, _("status store_result error: %s\n"), error);
164 }
165
166 while ( (row = mysql_fetch_row (res)) != NULL) {
167 int i;
168
169 for(i = 0; i < LENGTH_METRIC_UNIT - 1; i++) {
170 if (strcmp(row[0], metric_unit[i]) == 0) {
171 xasprintf(&perf, "%s %s", perf, perfdata(metric_unit[i],
172 atol(row[1]), "", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0));
173 continue;
174 }
175 }
176 for(i = 0; i < LENGTH_METRIC_COUNTER - 1; i++) {
177 if (strcmp(row[0], metric_counter[i]) == 0) {
178 xasprintf(&perf, "%s %s", perf, perfdata(metric_counter[i],
179 atol(row[1]), "c", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0));
180 continue;
181 }
182 }
183 }
184 }
185
133 if(check_slave) { 186 if(check_slave) {
134 /* check the slave status */ 187 /* check the slave status */
135 if (mysql_query (&mysql, "show slave status") != 0) { 188 if (mysql_query (&mysql, "show slave status") != 0) {
@@ -222,17 +275,17 @@ main (int argc, char **argv)
222 275
223 status = get_status(value, my_threshold); 276 status = get_status(value, my_threshold);
224 277
225 slaveperfdata = fperfdata ("seconds behind master", value, "s", 278 xasprintf (&perf, "%s %s", perf, fperfdata ("seconds behind master", value, "s",
226 TRUE, (double) warning_time, 279 TRUE, (double) warning_time,
227 TRUE, (double) critical_time, 280 TRUE, (double) critical_time,
228 FALSE, 0, 281 FALSE, 0,
229 FALSE, 0); 282 FALSE, 0));
230 283
231 if (status == STATE_WARNING) { 284 if (status == STATE_WARNING) {
232 printf("SLOW_SLAVE %s: %s|%s\n", _("WARNING"), slaveresult, slaveperfdata); 285 printf("SLOW_SLAVE %s: %s|%s\n", _("WARNING"), slaveresult, perf);
233 exit(STATE_WARNING); 286 exit(STATE_WARNING);
234 } else if (status == STATE_CRITICAL) { 287 } else if (status == STATE_CRITICAL) {
235 printf("SLOW_SLAVE %s: %s|%s\n", _("CRITICAL"), slaveresult, slaveperfdata); 288 printf("SLOW_SLAVE %s: %s|%s\n", _("CRITICAL"), slaveresult, perf);
236 exit(STATE_CRITICAL); 289 exit(STATE_CRITICAL);
237 } 290 }
238 } 291 }
@@ -246,12 +299,10 @@ main (int argc, char **argv)
246 mysql_close (&mysql); 299 mysql_close (&mysql);
247 300
248 /* print out the result of stats */ 301 /* print out the result of stats */
249 if (check_slave && slaveperfdata) { 302 if (check_slave) {
250 printf ("%s %s|%s\n", result, slaveresult, slaveperfdata); 303 printf ("%s %s|%s\n", result, slaveresult, perf);
251 } else if (check_slave) {
252 printf ("%s %s\n", result, slaveresult);
253 } else { 304 } else {
254 printf ("%s\n", result); 305 printf ("%s|%s\n", result, perf);
255 } 306 }
256 307
257 return STATE_OK; 308 return STATE_OK;