Merge remote-tracking branch 'origin/pr/993'
authorMarc Fournier <marc.fournier@camptocamp.com>
Wed, 8 Apr 2015 22:08:21 +0000 (00:08 +0200)
committerMarc Fournier <marc.fournier@camptocamp.com>
Wed, 8 Apr 2015 22:08:21 +0000 (00:08 +0200)
1  2 
src/bind.c
src/collectd.conf.pod

diff --combined src/bind.c
@@@ -109,6 -109,7 +109,7 @@@ static int global_server_stats     = 1
  static int global_zone_maint_stats = 1;
  static int global_resolver_stats   = 0;
  static int global_memory_stats     = 1;
+ static int timeout                 = -1;
  
  static cb_view_t *views = NULL;
  static size_t     views_num = 0;
@@@ -369,11 -370,9 +370,11 @@@ static int bind_xml_read_derive (xmlDo
    {
      ERROR ("bind plugin: Parsing string \"%s\" to derive value failed.",
          str_ptr);
 +    xmlFree(str_ptr);
      return (-1);
    }
  
 +  xmlFree(str_ptr);
    *ret_value = value.derive;
    return (0);
  } /* }}} int bind_xml_read_derive */
@@@ -716,40 -715,25 +717,40 @@@ static int bind_xml_stats_handle_zone (
    int i;
    size_t j;
  
 -  path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
 -  if (path_obj == NULL)
 +  if (version >= 3)
    {
 -    ERROR ("bind plugin: xmlXPathEvalExpression failed.");
 -    return (-1);
 +    char *n = (char *) xmlGetProp (node, BAD_CAST "name");
 +    char *c = (char *) xmlGetProp (node, BAD_CAST "rdataclass");
 +    if (n && c)
 +    {
 +      zone_name = (char *) xmlMalloc(strlen(n) + strlen(c) + 2);
 +      snprintf(zone_name, strlen(n) + strlen(c) + 2, "%s/%s", n, c);
 +    }
 +    xmlFree(n);
 +    xmlFree(c);
    }
 -
 -  for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
 +  else
    {
 -    zone_name = (char *) xmlNodeListGetString (doc,
 -        path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
 -    if (zone_name != NULL)
 -      break;
 +    path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
 +    if (path_obj == NULL)
 +    {
 +      ERROR ("bind plugin: xmlXPathEvalExpression failed.");
 +      return (-1);
 +    }
 +
 +    for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
 +    {
 +      zone_name = (char *) xmlNodeListGetString (doc,
 +          path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
 +      if (zone_name != NULL)
 +        break;
 +    }
 +    xmlXPathFreeObject (path_obj);
    }
  
    if (zone_name == NULL)
    {
      ERROR ("bind plugin: Could not determine zone name.");
 -    xmlXPathFreeObject (path_obj);
      return (-1);
    }
  
    zone_name = NULL;
  
    if (j >= views->zones_num)
 -  {
 -    xmlXPathFreeObject (path_obj);
      return (0);
 -  }
  
    zone_name = view->zones[j];
  
      ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-zone-%s",
          view->name, zone_name);
  
 -    bind_parse_generic_value_list (/* xpath = */ "counters",
 +    if (version == 3)
 +    {
 +      list_info_ptr_t list_info =
 +      {
 +        plugin_instance,
 +        /* type = */ "dns_qtype"
 +      };
 +      bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='rcode']",
          /* callback = */ bind_xml_table_callback,
          /* user_data = */ &table_ptr,
          doc, path_ctx, current_time, DS_TYPE_COUNTER);
 +      bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='qtype']",
 +        /* callback = */ bind_xml_list_callback,
 +        /* user_data = */ &list_info,
 +        doc, path_ctx, current_time, DS_TYPE_COUNTER);
 +    }
 +    else
 +    {
 +      bind_parse_generic_value_list (/* xpath = */ "counters",
 +          /* callback = */ bind_xml_table_callback,
 +          /* user_data = */ &table_ptr,
 +          doc, path_ctx, current_time, DS_TYPE_COUNTER);
 +    }
    } /* }}} */
  
 -  xmlXPathFreeObject (path_obj);
 -
    return (0);
  } /* }}} int bind_xml_stats_handle_zone */
  
@@@ -999,7 -969,8 +1000,7 @@@ static int bind_xml_stats_handle_view (
          doc, path_ctx, current_time, DS_TYPE_GAUGE);
    } /* }}} */
  
 -  // v3 does not provide per-zone stats any more
 -  if (version < 3 && view->zones_num > 0)
 +  if (view->zones_num > 0)
      bind_xml_stats_search_zones (version, doc, path_ctx, node, view,
          current_time);
  
@@@ -1725,6 -1696,8 +1726,8 @@@ static int bind_config (oconfig_item_t 
        bind_config_add_view (child);
      else if (strcasecmp ("ParseTime", child->key) == 0)
        cf_util_get_boolean (child, &config_parse_time);
+     else if (strcasecmp ("Timeout", child->key) == 0)
+       cf_util_get_int (child, &timeout);
      else
      {
        WARNING ("bind plugin: Unknown configuration option "
@@@ -1754,6 -1727,9 +1757,9 @@@ static int bind_init (void) /* {{{ *
    curl_easy_setopt (curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL);
    curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L);
    curl_easy_setopt (curl, CURLOPT_MAXREDIRS, 50L);
+   curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, (timeout >= 0) ?
+       (long) timeout : CDTIME_T_TO_MS(plugin_get_interval()));
  
    return (0);
  } /* }}} int bind_init */
diff --combined src/collectd.conf.pod
@@@ -775,6 -775,12 +775,12 @@@ File that holds one or more SSL certifi
  possibly need this option. What CA certificates come bundled with C<libcurl>
  and are checked by default depends on the distribution you use.
  
+ =item B<Timeout> I<Milliseconds>
+ The B<Timeout> option sets the overall timeout for HTTP requests to B<URL>, in
+ milliseconds. By default, the configured B<Interval> is used to set the
+ timeout.
  =back
  
  =head2 Plugin C<apcups>
@@@ -863,32 -869,24 +869,38 @@@ File that holds one or more SSL certifi
  possibly need this option. What CA certificates come bundled with C<libcurl>
  and are checked by default depends on the distribution you use.
  
+ =item B<Timeout> I<Milliseconds>
+ The B<Timeout> option sets the overall timeout for HTTP requests to B<URL>, in
+ milliseconds. By default, the configured B<Interval> is used to set the
+ timeout.
  =back
  
  =head2 Plugin C<barometer>
  
 -This plugin reads absolute air pressure using digital barometer sensor MPL115A2
 -or MPL3115 from Freescale (sensor attached to any I2C bus available in
 -the computer, for HW details see
 -I<http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPL115A> or
 -I<http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPL3115A2>).
 -The sensor type - one fo these two - is detected automatically by the plugin
 -and indicated in the plugin_instance (typically you will see subdirectory
 -"barometer-mpl115" or "barometer-mpl3115").
 +This plugin reads absolute air pressure using digital barometer sensor on a I2C
 +bus. Supported sensors are:
 +
 +=over 5
 +
 +=item I<MPL115A2> from Freescale,
 +see L<http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPL115A>.
 +
 +
 +=item I<MPL3115> from Freescale
 +see L<http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPL3115A2>.
 +
 +
 +=item I<BMP085> from Bosch Sensortec
 +
 +=back
 +
 +The sensor type - one of the above - is detected automatically by the plugin
 +and indicated in the plugin_instance (you will see subdirectory
 +"barometer-mpl115" or "barometer-mpl3115", or "barometer-bmp085"). The order of
 +detection is BMP085 -> MPL3115 -> MPL115A2, the first one found will be used
 +(only one sensor can be used by the plugin).
  
  The plugin provides absolute barometric pressure, air pressure reduced to sea
  level (several possible approximations) and as an auxiliary value also internal
@@@ -899,11 -897,11 +911,11 @@@ It was developed and tested under Linu
  the standard Linux i2c-dev interface (the particular bus driver has to
  support the SM Bus command subset).
  
 -The reduction or normalization to mean sea level pressure requires (depedning on
 -selected method/approximation) also altitude and reference to temperature sensor(s).
 -When multiple temperature sensors are configured the minumum of their values is
 -always used (expecting that the warmer ones are affected by e.g. direct sun light
 -at that moment).
 +The reduction or normalization to mean sea level pressure requires (depending
 +on selected method/approximation) also altitude and reference to temperature
 +sensor(s).  When multiple temperature sensors are configured the minumum of
 +their values is always used (expecting that the warmer ones are affected by
 +e.g. direct sun light at that moment).
  
  Synopsis:
  
  
  =item B<Device> I<device>
  
 -Device name of the I2C bus to which the sensor is connected. Note that typically
 -you need to have loaded the i2c-dev module.
 +The only mandatory configuration parameter.
 +
 +Device name of the I2C bus to which the sensor is connected. Note that
 +typically you need to have loaded the i2c-dev module.
  Using i2c-tools you can check/list i2c buses available on your system by:
  
    i2cdetect -l
@@@ -938,69 -934,52 +950,69 @@@ connected and detected on address 0x60
  
  =item B<Oversampling> I<value>
  
 -For MPL115 this is the size of the averaging window. To filter out sensor noise
 -a simple averaging using floating window of configurable size is used. The plugin
 -will use average of the last C<value> measurements (value of 1 means no averaging).
 -Minimal size is 1, maximal 1024.
 +Optional parameter controlling the oversampling/accuracy. Default value
 +is 1 providing fastest and least accurate reading.
  
 -For MPL3115 this is the oversampling value. The actual oversampling is performed
 -by the sensor and the higher value the higher accuracy and longer conversion time
 -(although nothing to worry about in the collectd context). Supported values are:
 -1, 2, 4, 8, 16, 32, 64 and 128. Any other value is adjusted by the plugin to
 -the closest supported one. Default is 128.
 +For I<MPL115> this is the size of the averaging window. To filter out sensor
 +noise a simple averaging using floating window of this configurable size is
 +used. The plugin will use average of the last C<value> measurements (value of 1
 +means no averaging).  Minimal size is 1, maximal 1024.
 +
 +For I<MPL3115> this is the oversampling value. The actual oversampling is
 +performed by the sensor and the higher value the higher accuracy and longer
 +conversion time (although nothing to worry about in the collectd context).
 +Supported values are: 1, 2, 4, 8, 16, 32, 64 and 128. Any other value is
 +adjusted by the plugin to the closest supported one.
 +
 +For I<BMP085> this is the oversampling value. The actual oversampling is
 +performed by the sensor and the higher value the higher accuracy and longer
 +conversion time (although nothing to worry about in the collectd context).
 +Supported values are: 1, 2, 4, 8. Any other value is adjusted by the plugin to
 +the closest supported one.
  
  =item B<PressureOffset> I<offset>
  
 -You can further calibrate the sensor by supplying pressure and/or temperature offsets.
 -This is added to the measured/caclulated value (i.e. if the measured value is too high
 -then use negative offset).
 +Optional parameter for MPL3115 only.
 +
 +You can further calibrate the sensor by supplying pressure and/or temperature
 +offsets.  This is added to the measured/caclulated value (i.e. if the measured
 +value is too high then use negative offset).
  In hPa, default is 0.0.
  
  =item B<TemperatureOffset> I<offset>
  
 -You can further calibrate the sensor by supplying pressure and/or temperature offsets.
 -This is added to the measured/caclulated value (i.e. if the measured value is too high
 -then use negative offset).
 +Optional parameter for MPL3115 only.
 +
 +You can further calibrate the sensor by supplying pressure and/or temperature
 +offsets.  This is added to the measured/caclulated value (i.e. if the measured
 +value is too high then use negative offset).
  In C, default is 0.0.
  
  =item B<Normalization> I<method>
  
 -Normalization method - what approximation/model is used to compute mean sea
 +Optional parameter, default value is 0.
 +
 +Normalization method - what approximation/model is used to compute the mean sea
  level pressure from the air absolute pressure.
  
  Supported values of the C<method> (integer between from 0 to 2) are:
  
  =over 5
  
 -=item B<0> - no conversion, absolute pressrure is simply copied over. For this method you
 +=item B<0> - no conversion, absolute pressure is simply copied over. For this method you
         do not need to configure C<Altitude> or C<TemperatureSensor>.
  
  =item B<1> - international formula for conversion ,
 -See I<http://en.wikipedia.org/wiki/Atmospheric_pressure#Altitude_atmospheric_pressure_variation>.
 -For this method you have to configure C<Altitude> but do not need C<TemperatureSensor>
 -(uses fixed global temperature average instead).
 +See
 +L<http://en.wikipedia.org/wiki/Atmospheric_pressure#Altitude_atmospheric_pressure_variation>.
 +For this method you have to configure C<Altitude> but do not need
 +C<TemperatureSensor> (uses fixed global temperature average instead).
  
  =item B<2> - formula as recommended by the Deutsche Wetterdienst (German
  Meteorological Service).
 -See I<http://de.wikipedia.org/wiki/Barometrische_H%C3%B6henformel#Theorie>
 -For this method you have to configure both  C<Altitude> and C<TemperatureSensor>.
 +See L<http://de.wikipedia.org/wiki/Barometrische_H%C3%B6henformel#Theorie>
 +For this method you have to configure both  C<Altitude> and
 +C<TemperatureSensor>.
  
  =back
  
@@@ -1011,15 -990,15 +1023,15 @@@ The altitude (in meters) of the locatio
  
  =item B<TemperatureSensor> I<reference>
  
 -Temperature sensor which should be used as a reference when normalizing the pressure.
 -When specified more sensors a minumum is found and uses each time.
 -The temperature reading directly from this pressure sensor/plugin
 -is typically not suitable as the pressure sensor
 -will be probably inside while we want outside temperature.
 -The collectd reference name is something like
 +Temperature sensor(s) which should be used as a reference when normalizing the
 +pressure using C<Normalization> method 2.
 +When specified more sensors a minumum is found and used each time.  The
 +temperature reading directly from this pressure sensor/plugin is typically not
 +suitable as the pressure sensor will be probably inside while we want outside
 +temperature.  The collectd reference name is something like
  <hostname>/<plugin_name>-<plugin_instance>/<type>-<type_instance>
 -(<type_instance> is usually omitted when there is just single value type).
 -Or you can figure it out from the path of the output data files.
 +(<type_instance> is usually omitted when there is just single value type). Or
 +you can figure it out from the path of the output data files.
  
  =back
  
@@@ -1160,6 -1139,12 +1172,12 @@@ Collect global memory statistics
  
  Default: Enabled.
  
+ =item B<Timeout> I<Milliseconds>
+ The B<Timeout> option sets the overall timeout for HTTP requests to B<URL>, in
+ milliseconds. By default, the configured B<Interval> is used to set the
+ timeout.
  =item B<View> I<Name>
  
  Collect statistics about a specific I<"view">. BIND can behave different,
@@@ -1488,6 -1473,10 +1506,10 @@@ C<application/x-www-form-urlencoded>)
  Measure response time for the request. If this setting is enabled, B<Match>
  blocks (see below) are optional. Disabled by default.
  
+ Beware that requests will get aborted if they take too long to complete. Adjust
+ B<Timeout> accordingly if you expect B<MeasureResponseTime> to report such slow
+ requests.
  =item B<MeasureResponseCode> B<true>|B<false>
  
  Measure response code for the request. If this setting is enabled, B<Match>
@@@ -1502,6 -1491,18 +1524,18 @@@ plugin below on how matches are defined
  B<MeasureResponseCode> options are set to B<true>, B<Match> blocks are
  optional.
  
+ =item B<Timeout> I<Milliseconds>
+ The B<Timeout> option sets the overall timeout for HTTP requests to B<URL>, in
+ milliseconds. By default, the configured B<Interval> is used to set the
+ timeout. Prior to version 5.5.0, there was no timeout and requests could hang
+ indefinitely. This legacy behaviour can be achieved by setting the value of
+ B<Timeout> to 0.
+ If B<Timeout> is 0 or bigger than the B<Interval>, keep in mind that each slow
+ network connection will stall one read thread. Adjust the B<ReadThreads> global
+ setting accordingly to prevent this from blocking other plugins.
  =back
  
  =head2 Plugin C<curl_json>
@@@ -1588,6 -1589,8 +1622,8 @@@ URL. By default the global B<Interval> 
  
  =item B<Post> I<Body>
  
+ =item B<Timeout> I<Milliseconds>
  These options behave exactly equivalent to the appropriate options of the
  I<cURL> plugin. Please see there for a detailed description.
  
@@@ -1688,6 -1691,8 +1724,8 @@@ Examples
  
  =item B<Post> I<Body>
  
+ =item B<Timeout> I<Milliseconds>
  These options behave exactly equivalent to the appropriate options of the
  I<cURL plugin>. Please see there for a detailed description.
  
@@@ -4115,6 -4120,12 +4153,12 @@@ File that holds one or more SSL certifi
  possibly need this option. What CA certificates come bundled with C<libcurl>
  and are checked by default depends on the distribution you use.
  
+ =item B<Timeout> I<Milliseconds>
+ The B<Timeout> option sets the overall timeout for HTTP requests to B<URL>, in
+ milliseconds. By default, the configured B<Interval> is used to set the
+ timeout.
  =back
  
  =head2 Plugin C<notify_desktop>
@@@ -7171,26 -7182,6 +7215,26 @@@ are available on the server side. I<Byt
  exceed the size of an C<int>, i.e. 2E<nbsp>GByte.
  Defaults to C<4096>.
  
 +=item B<LowSpeedLimit> I<Bytes per Second>
 +
 +Sets the minimal transfer rate in I<Bytes per Second> below which the
 +connection with the HTTP server will be considered too slow and aborted. All
 +the data submitted over this connection will probably be lost. Defaults to 0,
 +which means no minimum transfer rate is enforced.
 +
 +=item B<Timeout> I<Timeout>
 +
 +Sets the maximum time in milliseconds given for HTTP POST operations to
 +complete. When this limit is reached, the POST operation will be aborted, and
 +all the data in the current send buffer will probably be lost. Defaults to 0,
 +which means the connection never times out.
 +
 +The C<write_http> plugin regularly submits the collected values to the HTTP
 +server. How frequently this happens depends on how much data you are collecting
 +and the size of B<BufferSize>. The optimal value to set B<Timeout> to is
 +slightly below this interval, which you can estimate by monitoring the network
 +traffic between collectd and the HTTP server.
 +
  =back
  
  =head2 Plugin C<write_kafka>