diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-10-18 03:48:53 +0000 |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-10-18 03:48:53 +0000 |
commit | b8554503be5d86b46e3e6d43aa40e23570f8ef59 (patch) | |
tree | 3d4841734a6bdb20b577372e18b0c607008be21a | |
parent | 5c93a3f1164325ab586ee0b1fe04e947a5411407 (diff) | |
download | monitoring-plugins-b8554503be5d86b46e3e6d43aa40e23570f8ef59.tar.gz |
millisecond timing
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@139 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r-- | plugins/check_tcp.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index 140915ab..2822940e 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c | |||
@@ -83,10 +83,11 @@ int warn_codes_count = 0; | |||
83 | char **crit_codes = NULL; | 83 | char **crit_codes = NULL; |
84 | int crit_codes_count = 0; | 84 | int crit_codes_count = 0; |
85 | int delay = 0; | 85 | int delay = 0; |
86 | int warning_time = 0; | 86 | double warning_time = 0; |
87 | int check_warning_time = FALSE; | 87 | int check_warning_time = FALSE; |
88 | int critical_time = 0; | 88 | double critical_time = 0; |
89 | int check_critical_time = FALSE; | 89 | int check_critical_time = FALSE; |
90 | double elapsed_time = 0; | ||
90 | int verbose = FALSE; | 91 | int verbose = FALSE; |
91 | int use_ssl = FALSE; | 92 | int use_ssl = FALSE; |
92 | int sd; | 93 | int sd; |
@@ -100,6 +101,7 @@ main (int argc, char **argv) | |||
100 | char *status = NULL; | 101 | char *status = NULL; |
101 | char *output = NULL; | 102 | char *output = NULL; |
102 | char *ptr = NULL; | 103 | char *ptr = NULL; |
104 | struct timeval tv; | ||
103 | 105 | ||
104 | if (strstr (argv[0], "check_udp")) { | 106 | if (strstr (argv[0], "check_udp")) { |
105 | PROGNAME = strscpy (PROGNAME, "check_udp"); | 107 | PROGNAME = strscpy (PROGNAME, "check_udp"); |
@@ -205,7 +207,7 @@ main (int argc, char **argv) | |||
205 | alarm (socket_timeout); | 207 | alarm (socket_timeout); |
206 | 208 | ||
207 | /* try to connect to the host at the given port number */ | 209 | /* try to connect to the host at the given port number */ |
208 | time (&start_time); | 210 | gettimeofday (&tv, NULL); |
209 | #ifdef HAVE_SSL | 211 | #ifdef HAVE_SSL |
210 | if (use_ssl) | 212 | if (use_ssl) |
211 | result = connect_SSL (); | 213 | result = connect_SSL (); |
@@ -233,7 +235,7 @@ main (int argc, char **argv) | |||
233 | } | 235 | } |
234 | 236 | ||
235 | if (delay > 0) { | 237 | if (delay > 0) { |
236 | start_time = start_time + delay; | 238 | tv.tv_sec += delay; |
237 | sleep (delay); | 239 | sleep (delay); |
238 | } | 240 | } |
239 | 241 | ||
@@ -287,25 +289,25 @@ main (int argc, char **argv) | |||
287 | /* close the connection */ | 289 | /* close the connection */ |
288 | close (sd); | 290 | close (sd); |
289 | 291 | ||
290 | time (&end_time); | 292 | elapsed_time = delta_time (tv); |
291 | 293 | ||
292 | if (check_critical_time == TRUE && (end_time - start_time) > critical_time) | 294 | if (check_critical_time == TRUE && elapsed_time > critical_time) |
293 | result = STATE_CRITICAL; | 295 | result = STATE_CRITICAL; |
294 | else if (check_warning_time == TRUE | 296 | else if (check_warning_time == TRUE && elapsed_time > warning_time) |
295 | && (end_time - start_time) > warning_time) result = STATE_WARNING; | 297 | result = STATE_WARNING; |
296 | 298 | ||
297 | /* reset the alarm */ | 299 | /* reset the alarm */ |
298 | alarm (0); | 300 | alarm (0); |
299 | 301 | ||
300 | printf | 302 | printf |
301 | ("%s %s - %d second response time on port %d", | 303 | ("%s %s - %7.3f second response time on port %d", |
302 | SERVICE, | 304 | SERVICE, |
303 | state_text (result), (int) (end_time - start_time), server_port); | 305 | state_text (result), elapsed_time, server_port); |
304 | 306 | ||
305 | if (status) | 307 | if (status) |
306 | printf (" [%s]", status); | 308 | printf (" [%s]", status); |
307 | 309 | ||
308 | printf ("|time=%d\n", (int) (end_time - start_time)); | 310 | printf ("|time=%7.3f\n", elapsed_time); |
309 | 311 | ||
310 | return result; | 312 | return result; |
311 | } | 313 | } |
@@ -398,13 +400,13 @@ process_arguments (int argc, char **argv) | |||
398 | case 'c': /* critical */ | 400 | case 'c': /* critical */ |
399 | if (!is_intnonneg (optarg)) | 401 | if (!is_intnonneg (optarg)) |
400 | usage ("Critical threshold must be a nonnegative integer\n"); | 402 | usage ("Critical threshold must be a nonnegative integer\n"); |
401 | critical_time = atoi (optarg); | 403 | critical_time = strtod (optarg, NULL); |
402 | check_critical_time = TRUE; | 404 | check_critical_time = TRUE; |
403 | break; | 405 | break; |
404 | case 'w': /* warning */ | 406 | case 'w': /* warning */ |
405 | if (!is_intnonneg (optarg)) | 407 | if (!is_intnonneg (optarg)) |
406 | usage ("Warning threshold must be a nonnegative integer\n"); | 408 | usage ("Warning threshold must be a nonnegative integer\n"); |
407 | warning_time = atoi (optarg); | 409 | warning_time = strtod (optarg, NULL); |
408 | check_warning_time = TRUE; | 410 | check_warning_time = TRUE; |
409 | break; | 411 | break; |
410 | case 'C': | 412 | case 'C': |
@@ -499,9 +501,9 @@ print_help (void) | |||
499 | " String to expect in server response" | 501 | " String to expect in server response" |
500 | " -W, --wait=INTEGER\n" | 502 | " -W, --wait=INTEGER\n" |
501 | " Seconds to wait between sending string and polling for response\n" | 503 | " Seconds to wait between sending string and polling for response\n" |
502 | " -w, --warning=INTEGER\n" | 504 | " -w, --warning=DOUBLE\n" |
503 | " Response time to result in warning status (seconds)\n" | 505 | " Response time to result in warning status (seconds)\n" |
504 | " -c, --critical=INTEGER\n" | 506 | " -c, --critical=DOUBLE\n" |
505 | " Response time to result in critical status (seconds)\n" | 507 | " Response time to result in critical status (seconds)\n" |
506 | " -t, --timeout=INTEGER\n" | 508 | " -t, --timeout=INTEGER\n" |
507 | " Seconds before connection times out (default: %d)\n" | 509 | " Seconds before connection times out (default: %d)\n" |