X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcurl.c;h=bc11c28afdaf149154e1f2bf83fd333769f4c6c1;hb=ab9fd6d9336a623b7feb73e284cbd072496de102;hp=a43e7ed9000781b16390dfb024ce270858b64b86;hpb=e21d0408e4e4001b8c66bb1ea7d41b890100d0f5;p=collectd.git diff --git a/src/curl.c b/src/curl.c index a43e7ed9..bc11c28a 100644 --- a/src/curl.c +++ b/src/curl.c @@ -1,6 +1,7 @@ /** * collectd - src/curl.c * Copyright (C) 2006-2009 Florian octo Forster + * Copyright (C) 2009 Aman Gupta * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -17,6 +18,7 @@ * * Authors: * Florian octo Forster + * Aman Gupta **/ #include "collectd.h" @@ -57,6 +59,7 @@ struct web_page_s /* {{{ */ int verify_peer; int verify_host; char *cacert; + int response_time; CURL *curl; char curl_errbuf[CURL_ERROR_SIZE]; @@ -424,6 +427,7 @@ static int cc_config_add_page (oconfig_item_t *ci) /* {{{ */ page->pass = NULL; page->verify_peer = 1; page->verify_host = 1; + page->response_time = 0; page->instance = strdup (ci->values[0].value.string); if (page->instance == NULL) @@ -449,6 +453,8 @@ static int cc_config_add_page (oconfig_item_t *ci) /* {{{ */ status = cc_config_set_boolean ("VerifyPeer", &page->verify_peer, child); else if (strcasecmp ("VerifyHost", child->key) == 0) status = cc_config_set_boolean ("VerifyHost", &page->verify_host, child); + else if (strcasecmp ("MeasureResponseTime", child->key) == 0) + status = cc_config_set_boolean (child->key, &page->response_time, child); else if (strcasecmp ("CACert", child->key) == 0) status = cc_config_add_string ("CACert", &page->cacert, child); else if (strcasecmp ("Match", child->key) == 0) @@ -473,11 +479,11 @@ static int cc_config_add_page (oconfig_item_t *ci) /* {{{ */ status = -1; } - if (page->matches == NULL) + if (page->matches == NULL && !page->response_time) { assert (page->instance != NULL); WARNING ("curl plugin: No (valid) `Match' block " - "within `Page' block `%s'.", page->instance); + "or MeasureResponseTime within `Page' block `%s'.", page->instance); status = -1; } @@ -577,10 +583,32 @@ static void cc_submit (const web_page_t *wp, const web_match_t *wm, /* {{{ */ plugin_dispatch_values (&vl); } /* }}} void cc_submit */ +static void cc_submit_response_time (const web_page_t *wp, double seconds) /* {{{ */ +{ + value_t values[1]; + value_list_t vl = VALUE_LIST_INIT; + + values[0].gauge = seconds; + + vl.values = values; + vl.values_len = 1; + vl.time = time (NULL); + 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_time", sizeof (vl.type)); + + plugin_dispatch_values (&vl); +} /* }}} void cc_submit_response_time */ + static int cc_read_page (web_page_t *wp) /* {{{ */ { web_match_t *wm; int status; + struct timeval start, end; + + if (wp->response_time) + gettimeofday (&start, NULL); wp->buffer_fill = 0; status = curl_easy_perform (wp->curl); @@ -591,6 +619,15 @@ static int cc_read_page (web_page_t *wp) /* {{{ */ return (-1); } + if (wp->response_time) + { + 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); + } + for (wm = wp->matches; wm != NULL; wm = wm->next) { cu_match_value_t *mv;