summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Nierlein <sven@nierlein.de>2017-03-14 22:49:05 (GMT)
committerSven Nierlein <sven@nierlein.de>2018-10-22 14:28:51 (GMT)
commitb5fd0d1a17571cf16e788f1e99e8e1061dafe81e (patch)
tree536bad0b280a5ae762c3b2263fe8b578aca68fe4
parent16121a9b5526aa751f77a2d5ec3f15755f99b291 (diff)
downloadmonitoring-plugins-b5fd0d1a17571cf16e788f1e99e8e1061dafe81e.tar.gz
check_curl: implement extended performance data
Signed-off-by: Sven Nierlein <sven@nierlein.de>
-rw-r--r--plugins/check_curl.c48
1 files changed, 40 insertions, 8 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index e14fb19..064fb16 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -97,6 +97,7 @@ int days_till_exp_warn, days_till_exp_crit;
97thresholds *thlds; 97thresholds *thlds;
98char user_agent[DEFAULT_BUFFER_SIZE]; 98char user_agent[DEFAULT_BUFFER_SIZE];
99int verbose = 0; 99int verbose = 0;
100int show_extended_perfdata = FALSE;
100char *http_method = NULL; 101char *http_method = NULL;
101CURL *curl; 102CURL *curl;
102struct curl_slist *header_list = NULL; 103struct curl_slist *header_list = NULL;
@@ -108,6 +109,10 @@ struct curl_slist *http_opt_headers = NULL;
108long code; 109long code;
109long socket_timeout = DEFAULT_SOCKET_TIMEOUT; 110long socket_timeout = DEFAULT_SOCKET_TIMEOUT;
110double total_time; 111double total_time;
112double time_connect;
113double time_appconnect;
114double time_headers;
115double time_firstbyte;
111char errbuf[CURL_ERROR_SIZE+1]; 116char errbuf[CURL_ERROR_SIZE+1];
112CURLcode res; 117CURLcode res;
113char url[DEFAULT_BUFFER_SIZE]; 118char url[DEFAULT_BUFFER_SIZE];
@@ -136,6 +141,7 @@ void curlhelp_freebuffer (curlhelp_curlbuf*);
136 141
137int curlhelp_parse_statusline (const char*, curlhelp_statusline *); 142int curlhelp_parse_statusline (const char*, curlhelp_statusline *);
138void curlhelp_free_statusline (curlhelp_statusline *); 143void curlhelp_free_statusline (curlhelp_statusline *);
144char *perfd_time_ssl (double microsec);
139 145
140void remove_newlines (char *); 146void remove_newlines (char *);
141void test_file (char *); 147void test_file (char *);
@@ -342,13 +348,30 @@ check_http (void)
342 * performance data to the answer always 348 * performance data to the answer always
343 */ 349 */
344 curl_easy_getinfo (curl, CURLINFO_TOTAL_TIME, &total_time); 350 curl_easy_getinfo (curl, CURLINFO_TOTAL_TIME, &total_time);
345 snprintf (perfstring, DEFAULT_BUFFER_SIZE, "time=%.6gs;%.6g;%.6g;%.6g size=%dB;;;0", 351 if(show_extended_perfdata) {
346 total_time, 352 curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &time_connect);
347 0.0, 0.0, 353 curl_easy_getinfo(curl, CURLINFO_APPCONNECT_TIME, &time_appconnect);
348 ( warning_thresholds != NULL ) ? (double)thlds->warning->end : 0.0, 354 curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME, &time_headers);
349 critical_thresholds != NULL ? (double)thlds->critical->end : 0.0, 355 curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME, &time_firstbyte);
350 0.0, 356 snprintf(perfstring, DEFAULT_BUFFER_SIZE, "time=%.6gs;%.6g;%.6g;; size=%dB;;; time_connect=%.6gs;;;; %s time_headers=%.6gs;;;; time_firstbyte=%.6gs;;;; time_transfer=%.6gs;;;;",
351 (int)body_buf.buflen); 357 total_time,
358 warning_thresholds != NULL ? (double)thlds->warning->end : 0.0,
359 critical_thresholds != NULL ? (double)thlds->critical->end : 0.0,
360 (int)body_buf.buflen,
361 time_connect,
362 use_ssl == TRUE ? perfd_time_ssl(time_appconnect-time_connect) : "",
363 (time_headers - time_appconnect),
364 (time_firstbyte - time_headers),
365 (total_time-time_firstbyte)
366 );
367 } else {
368 snprintf(perfstring, DEFAULT_BUFFER_SIZE, "time=%.6gs;%.6g;%.6g;; size=%dB;;;",
369 total_time,
370 warning_thresholds != NULL ? (double)thlds->warning->end : 0.0,
371 critical_thresholds != NULL ? (double)thlds->critical->end : 0.0,
372 (int)body_buf.buflen);
373 }
374
352 375
353 /* return a CRITICAL status if we couldn't read any data */ 376 /* return a CRITICAL status if we couldn't read any data */
354 if (strlen(header_buf.buf) == 0 && strlen(body_buf.buf) == 0) 377 if (strlen(header_buf.buf) == 0 && strlen(body_buf.buf) == 0)
@@ -497,6 +520,7 @@ process_arguments (int argc, char **argv)
497 {"useragent", required_argument, 0, 'A'}, 520 {"useragent", required_argument, 0, 'A'},
498 {"invert-regex", no_argument, NULL, INVERT_REGEX}, 521 {"invert-regex", no_argument, NULL, INVERT_REGEX},
499 {"header", required_argument, 0, 'k'}, 522 {"header", required_argument, 0, 'k'},
523 {"extended-perfdata", no_argument, 0, 'E'},
500 {0, 0, 0, 0} 524 {0, 0, 0, 0}
501 }; 525 };
502 526
@@ -504,7 +528,7 @@ process_arguments (int argc, char **argv)
504 return ERROR; 528 return ERROR;
505 529
506 while (1) { 530 while (1) {
507 c = getopt_long (argc, argv, "Vvht:c:w:A:k:H:j:I:a:p:s:r:u:f:C:J:K:S::", longopts, &option); 531 c = getopt_long (argc, argv, "Vvht:c:w:A:k:H:j:I:a:p:s:r:u:f:C:J:K:S::E", longopts, &option);
508 if (c == -1 || c == EOF || c == 1) 532 if (c == -1 || c == EOF || c == 1)
509 break; 533 break;
510 534
@@ -671,6 +695,9 @@ process_arguments (int argc, char **argv)
671 case INVERT_REGEX: 695 case INVERT_REGEX:
672 invert_regex = 1; 696 invert_regex = 1;
673 break; 697 break;
698 case 'E': /* show extended perfdata */
699 show_extended_perfdata = TRUE;
700 break;
674 case '?': 701 case '?':
675 /* print short usage statement if args not parsable */ 702 /* print short usage statement if args not parsable */
676 usage5 (); 703 usage5 ();
@@ -1026,3 +1053,8 @@ remove_newlines (char *s)
1026 if (*p == '\r' || *p == '\n') 1053 if (*p == '\r' || *p == '\n')
1027 *p = ' '; 1054 *p = ' ';
1028} 1055}
1056
1057char *perfd_time_ssl (double elapsed_time_ssl)
1058{
1059 return fperfdata ("time_ssl", elapsed_time_ssl, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0);
1060}