summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorDanijel Tasov <data@consol.de>2022-12-21 14:48:11 +0100
committerSven Nierlein <sven@nierlein.org>2022-12-22 10:15:59 +0100
commit763862a61cf5a7ba1a10f607022aac2434c79f57 (patch)
tree6cbc44a7254eabd8919f4dba23a61458068f55b4 /plugins
parent0551151a578dd5da1dbf0ae2e5c5224c491bf0c9 (diff)
downloadmonitoring-plugins-763862a61cf5a7ba1a10f607022aac2434c79f57.tar.gz
make check_http faster with larger files
The current implementation becomes exponentially slower with growing response size. See also: https://github.com/nagios-plugins/nagios-plugins/blob/release-2.4.2/plugins/check_http.c#L1199-L1204 Test: $ mkdir web $ nohup python3 -m http.server -d web 5080 & $ perl -E 'say "0123456789" for (1..2_000_000)' >| web/file.txt $ ./check_http.orig -t 200 -v -I localhost -p 5080 -u /file.txt > test1.txt real 0m26.893s user 0m12.661s sys 0m14.221s $ time ./check_http -t 200 -v -I localhost -p 5080 -u /file.txt > test2.txt real 0m0.038s user 0m0.011s sys 0m0.027s $ diff -u test[12].txt --- test1.txt 2022-12-21 14:58:28.720260811 +0100 +++ test2.txt 2022-12-21 14:58:42.640008604 +0100 @@ -7,7 +7,7 @@ STATUS: HTTP/1.0 200 OK **** HEADER **** Server: SimpleHTTP/0.6 Python/3.9.2 -Date: Wed, 21 Dec 2022 13:58:01 GMT +Date: Wed, 21 Dec 2022 13:58:42 GMT Content-type: text/plain Content-Length: 22000000 Last-Modified: Wed, 21 Dec 2022 13:57:58 GMT @@ -2000013,4 +2000013,4 @@ 0123456789 0123456789 -HTTP OK: HTTP/1.0 200 OK - 22000191 bytes in 26.860 second response time |time=26.860182s;;;0.000000;200.000000 size=22000191B;;;0; +HTTP OK: HTTP/1.0 200 OK - 22000191 bytes in 0.016 second response time |time=0.016412s;;;0.000000;200.000000 size=22000191B;;;0;
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_http.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 41d47816..1835a2d0 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -1095,9 +1095,14 @@ check_http (void)
1095 *pos = ' '; 1095 *pos = ' ';
1096 } 1096 }
1097 buffer[i] = '\0'; 1097 buffer[i] = '\0';
1098 xasprintf (&full_page_new, "%s%s", full_page, buffer); 1098
1099 free (full_page); 1099 if ((full_page_new = realloc(full_page, pagesize + i + 1)) == NULL)
1100 die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate memory for full_page\n"));
1101
1102 memmove(&full_page_new[pagesize], buffer, i + 1);
1103
1100 full_page = full_page_new; 1104 full_page = full_page_new;
1105
1101 pagesize += i; 1106 pagesize += i;
1102 1107
1103 if (no_body && document_headers_done (full_page)) { 1108 if (no_body && document_headers_done (full_page)) {