diff options
author | Sven Nierlein <sven@nierlein.de> | 2017-03-14 22:49:05 (GMT) |
---|---|---|
committer | Sven Nierlein <sven@nierlein.de> | 2018-10-22 14:28:51 (GMT) |
commit | b5fd0d1a17571cf16e788f1e99e8e1061dafe81e (patch) | |
tree | 536bad0b280a5ae762c3b2263fe8b578aca68fe4 | |
parent | 16121a9b5526aa751f77a2d5ec3f15755f99b291 (diff) | |
download | monitoring-plugins-b5fd0d1a17571cf16e788f1e99e8e1061dafe81e.tar.gz |
check_curl: implement extended performance data
Signed-off-by: Sven Nierlein <sven@nierlein.de>
-rw-r--r-- | plugins/check_curl.c | 48 |
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; | |||
97 | thresholds *thlds; | 97 | thresholds *thlds; |
98 | char user_agent[DEFAULT_BUFFER_SIZE]; | 98 | char user_agent[DEFAULT_BUFFER_SIZE]; |
99 | int verbose = 0; | 99 | int verbose = 0; |
100 | int show_extended_perfdata = FALSE; | ||
100 | char *http_method = NULL; | 101 | char *http_method = NULL; |
101 | CURL *curl; | 102 | CURL *curl; |
102 | struct curl_slist *header_list = NULL; | 103 | struct curl_slist *header_list = NULL; |
@@ -108,6 +109,10 @@ struct curl_slist *http_opt_headers = NULL; | |||
108 | long code; | 109 | long code; |
109 | long socket_timeout = DEFAULT_SOCKET_TIMEOUT; | 110 | long socket_timeout = DEFAULT_SOCKET_TIMEOUT; |
110 | double total_time; | 111 | double total_time; |
112 | double time_connect; | ||
113 | double time_appconnect; | ||
114 | double time_headers; | ||
115 | double time_firstbyte; | ||
111 | char errbuf[CURL_ERROR_SIZE+1]; | 116 | char errbuf[CURL_ERROR_SIZE+1]; |
112 | CURLcode res; | 117 | CURLcode res; |
113 | char url[DEFAULT_BUFFER_SIZE]; | 118 | char url[DEFAULT_BUFFER_SIZE]; |
@@ -136,6 +141,7 @@ void curlhelp_freebuffer (curlhelp_curlbuf*); | |||
136 | 141 | ||
137 | int curlhelp_parse_statusline (const char*, curlhelp_statusline *); | 142 | int curlhelp_parse_statusline (const char*, curlhelp_statusline *); |
138 | void curlhelp_free_statusline (curlhelp_statusline *); | 143 | void curlhelp_free_statusline (curlhelp_statusline *); |
144 | char *perfd_time_ssl (double microsec); | ||
139 | 145 | ||
140 | void remove_newlines (char *); | 146 | void remove_newlines (char *); |
141 | void test_file (char *); | 147 | void 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 | |||
1057 | char *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 | } | ||