From: Florian Forster Date: Sat, 6 Sep 2014 09:27:56 +0000 (+0200) Subject: Merge branch 'collectd-5.3' into collectd-5.4 X-Git-Tag: collectd-5.4.2~18 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=21077b074c468a41dbd60baad691ebc7f2991d43;hp=-c;p=collectd.git Merge branch 'collectd-5.3' into collectd-5.4 Conflicts: src/curl.c --- 21077b074c468a41dbd60baad691ebc7f2991d43 diff --combined src/curl.c index 1f78f821,0d4677fd..52653fb0 --- a/src/curl.c +++ b/src/curl.c @@@ -26,7 -26,6 +26,7 @@@ #include "plugin.h" #include "configfile.h" #include "utils_match.h" +#include "utils_time.h" #include @@@ -64,7 -63,6 +64,7 @@@ struct web_page_s /* {{{ * struct curl_slist *headers; char *post_body; _Bool response_time; + _Bool response_code; CURL *curl; char curl_errbuf[CURL_ERROR_SIZE]; @@@ -91,7 -89,7 +91,7 @@@ static size_t cc_curl_callback (void *b { web_page_t *wp; size_t len; - + len = size * nmemb; if (len <= 0) return (len); @@@ -429,7 -427,6 +429,7 @@@ static int cc_config_add_page (oconfig_ page->verify_peer = 1; page->verify_host = 1; page->response_time = 0; + page->response_code = 0; page->instance = strdup (ci->values[0].value.string); if (page->instance == NULL) @@@ -457,8 -454,6 +457,8 @@@ status = cf_util_get_boolean (child, &page->verify_host); else if (strcasecmp ("MeasureResponseTime", child->key) == 0) status = cf_util_get_boolean (child, &page->response_time); + else if (strcasecmp ("MeasureResponseCode", child->key) == 0) + status = cf_util_get_boolean (child, &page->response_code); else if (strcasecmp ("CACert", child->key) == 0) status = cf_util_get_string (child, &page->cacert); else if (strcasecmp ("Match", child->key) == 0) @@@ -487,12 -482,11 +487,12 @@@ status = -1; } - if (page->matches == NULL && !page->response_time) + if (page->matches == NULL && !page->response_time && !page->response_code) { assert (page->instance != NULL); WARNING ("curl plugin: No (valid) `Match' block " - "or MeasureResponseTime within `Page' block `%s'.", page->instance); + "or MeasureResponseTime or MeasureResponseCode within " + "`Page' block `%s'.", page->instance); status = -1; } @@@ -593,30 -587,12 +593,30 @@@ static void cc_submit (const web_page_ plugin_dispatch_values (&vl); } /* }}} void cc_submit */ -static void cc_submit_response_time (const web_page_t *wp, double seconds) /* {{{ */ +static void cc_submit_response_code (const web_page_t *wp, long code) /* {{{ */ { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = seconds; + values[0].gauge = code; + + vl.values = values; + vl.values_len = 1; + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "curl", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, wp->instance, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, "response_code", sizeof (vl.type)); + + plugin_dispatch_values (&vl); +} /* }}} void cc_submit_response_code */ + +static void cc_submit_response_time (const web_page_t *wp, /* {{{ */ + cdtime_t response_time) +{ + value_t values[1]; + value_list_t vl = VALUE_LIST_INIT; + + values[0].gauge = CDTIME_T_TO_DOUBLE (response_time); vl.values = values; vl.values_len = 1; @@@ -632,10 -608,10 +632,10 @@@ static int cc_read_page (web_page_t *wp { web_match_t *wm; int status; - struct timeval start, end; + cdtime_t start = 0; if (wp->response_time) - gettimeofday (&start, NULL); + start = cdtime (); wp->buffer_fill = 0; status = curl_easy_perform (wp->curl); @@@ -647,18 -623,12 +647,18 @@@ } if (wp->response_time) + cc_submit_response_time (wp, cdtime() - start); + + if(wp->response_code) { - double secs = 0; - gettimeofday (&end, NULL); - secs += end.tv_sec - start.tv_sec; - secs += (end.tv_usec - start.tv_usec) / 1000000.0; - cc_submit_response_time (wp, secs); + long response_code = 0; + status = curl_easy_getinfo(wp->curl, CURLINFO_RESPONSE_CODE, &response_code); + if(status != CURLE_OK) { + ERROR ("curl plugin: Fetching response code failed with staus %i: %s", + status, wp->curl_errbuf); + } else { + cc_submit_response_code(wp, response_code); + } } for (wm = wp->matches; wm != NULL; wm = wm->next) @@@ -680,6 -650,7 +680,7 @@@ } cc_submit (wp, wm, mv); + match_value_reset (mv); } /* for (wm = wp->matches; wm != NULL; wm = wm->next) */ return (0);