From: Marc Fournier Date: Sat, 4 Apr 2015 20:28:47 +0000 (+0200) Subject: nginx: Add support for specifying a connection timeout X-Git-Tag: collectd-5.5.0~56^2~3 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=293ef78a6140221ccf524d4e52a0f475f027815a;p=collectd.git nginx: Add support for specifying a connection timeout --- diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 652e3f4b..991a8032 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -4114,6 +4114,12 @@ File that holds one or more SSL certificates. If you want to use HTTPS you will possibly need this option. What CA certificates come bundled with C and are checked by default depends on the distribution you use. +=item B I + +The B option sets the overall timeout for HTTP requests, in +milliseconds. By default, the configured B is used to set the +timeout. + =back =head2 Plugin C diff --git a/src/nginx.c b/src/nginx.c index b0daa05b..edb55b9e 100644 --- a/src/nginx.c +++ b/src/nginx.c @@ -39,6 +39,7 @@ static char *pass = NULL; static char *verify_peer = NULL; static char *verify_host = NULL; static char *cacert = NULL; +static char *timeout = NULL; static CURL *curl = NULL; @@ -53,7 +54,8 @@ static const char *config_keys[] = "Password", "VerifyPeer", "VerifyHost", - "CACert" + "CACert", + "Timeout" }; static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); @@ -107,6 +109,8 @@ static int config (const char *key, const char *value) return (config_set (&verify_host, value)); else if (strcasecmp (key, "cacert") == 0) return (config_set (&cacert, value)); + else if (strcasecmp (key, "timeout") == 0) + return (config_set (&timeout, value)); else return (-1); } /* int config */ @@ -177,6 +181,16 @@ static int init (void) curl_easy_setopt (curl, CURLOPT_CAINFO, cacert); } + if (timeout != NULL) + { + curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, atoi(timeout)); + } + else + { + curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, + CDTIME_T_TO_MS(plugin_get_interval())); + } + return (0); } /* void init */