Merge branch 'collectd-4.5'
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Fri, 3 Oct 2008 11:35:56 +0000 (13:35 +0200)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Fri, 3 Oct 2008 11:35:56 +0000 (13:35 +0200)
1  2 
src/collectd.conf.pod
src/plugin.c
src/snmp.c

diff --combined src/collectd.conf.pod
@@@ -1472,9 -1472,9 +1472,9 @@@ In this case please file a bug report w
  =item B<Socket> I<Path>
  
  Configures the path to the UNIX domain socket to be used when connecting to the
- daemon. By default C</var/run/pdns.controlsocket> will be used for an
- authoritative server and C</var/run/pdns_recursor.controlsocket> will be used
- for the recursor.
+ daemon. By default C<${localstatedir}/run/pdns.controlsocket> will be used for
+ an authoritative server and C<${localstatedir}/run/pdns_recursor.controlsocket>
will be used for the recursor.
  
  =back
  
@@@ -1500,56 -1500,6 +1500,56 @@@ and minor and major pagefaults
  
  =back
  
 +=head2 Plugin C<rrdcached>
 +
 +The C<rrdcached> plugin uses the RRDTool accelerator daemon, L<rrdcached(1)>,
 +to store values to RRD files in an efficient manner. The combination of the
 +C<rrdcached> B<plugin> and the C<rrdcached> B<daemon> is very similar to the
 +way the C<rrdtool> plugin works (see below). The added abstraction layer
 +provides a number of benefits, though: Because the cache is not within
 +C<collectd> anymore, it does not need to be flushed when C<collectd> is to be
 +restarted. This results in much shorter (if any) gaps in graphs, especially
 +under heavy load. Also, the C<rrdtool> command line utility is aware of the
 +daemon so that it can flush values to disk automatically when needed. This
 +allows to integrate automated flushing of values into graphing solutions much
 +more easily.
 +
 +There are disadvantages, though: The daemon may reside on a different host, so
 +it may not be possible for C<collectd> to create the appropriate RRD files
 +anymore. And even if C<rrdcached> runs on the same host, it may run in a
 +different base directory, so relative paths may do weird stuff if you're not
 +careful.
 +
 +So the B<recommended configuration> is to let C<collectd> and C<rrdcached> run
 +on the same host, communicating via a UNIX domain socket. The B<DataDir>
 +setting should be set to an absolute path, so that a changed base directory
 +does not result in RRD files being createdE<nbsp>/ expected in the wrong place.
 +
 +=over 4
 +
 +=item B<DaemonAddress> I<Address>
 +
 +Address of the daemon as understood by the C<rrdc_connect> function of the RRD
 +library. See L<rrdcached(1)> for details. Example:
 +
 +  <Plugin "rrdcached">
 +    DaemonAddress "unix:/var/run/rrdcached.sock"
 +  </Plugin>
 +
 +=item B<DataDir> I<Directory>
 +
 +Set the base directory in which the RRD files reside. If this is a relative
 +path, it is relative to the working base directory of the C<rrdcached> daemon!
 +Use of an absolute path is recommended.
 +
 +=item B<CreateFiles> B<true>|B<false>
 +
 +Enables or disables the creation of RRD files. If the daemon is not running
 +locally, or B<DataDir> is set to a relative path, this will not work as
 +expected. Default is B<true>.
 +
 +=back
 +
  =head2 Plugin C<rrdtool>
  
  You can use the settings B<StepSize>, B<HeartBeat>, B<RRARows>, and B<XFF> to
@@@ -1633,8 -1583,8 +1633,8 @@@ When collecting many statistics with co
  will run serious performance problems. The B<CacheFlush> setting and the
  internal update queue assert that collectd continues to work just fine even
  under heavy load, but the system may become very unresponsive and slow. This is
- a problem especially if create graphs from the RRD files on the same machine,
- for example using the C<graph.cgi> script included in the
+ a problem especially if you create graphs from the RRD files on the same
machine, for example using the C<graph.cgi> script included in the
  C<contrib/collection3/> directory.
  
  This setting is designed for very large setups. Setting this option to a value
diff --combined src/plugin.c
@@@ -718,7 -718,7 +718,7 @@@ void plugin_shutdown_all (void
  
  int plugin_dispatch_values (value_list_t *vl)
  {
 -      static c_complain_t no_write_complaint = C_COMPLAIN_INIT;
 +      static c_complain_t no_write_complaint = C_COMPLAIN_INIT_STATIC;
  
        int (*callback) (const data_set_t *, const value_list_t *);
        data_set_t *ds;
@@@ -830,7 -830,7 +830,7 @@@ int plugin_dispatch_notification (cons
  
  void plugin_log (int level, const char *format, ...)
  {
-       char msg[512];
+       char msg[1024];
        va_list ap;
  
        void (*callback) (int, const char *);
  #endif
  
        va_start (ap, format);
-       vsnprintf (msg, 512, format, ap);
-       msg[511] = '\0';
+       vsnprintf (msg, sizeof (msg), format, ap);
+       msg[sizeof (msg) - 1] = '\0';
        va_end (ap);
  
        le = llist_head (list_log);
diff --combined src/snmp.c
@@@ -22,7 -22,6 +22,7 @@@
  #include "collectd.h"
  #include "common.h"
  #include "plugin.h"
 +#include "utils_complain.h"
  
  #include <pthread.h>
  
@@@ -68,7 -67,6 +68,7 @@@ struct host_definition_
    char *community;
    int version;
    void *sess_handle;
 +  c_complain_t complaint;
    uint32_t interval;
    time_t next_update;
    data_definition_t **data_list;
@@@ -553,7 -551,6 +553,7 @@@ static int csnmp_config_add_host (oconf
      return (-1);
    memset (hd, '\0', sizeof (host_definition_t));
    hd->version = 2;
 +  C_COMPLAIN_INIT (&hd->complaint);
  
    hd->name = strdup (ci->values[0].value.string);
    if (hd->name == NULL)
@@@ -732,22 -729,41 +732,41 @@@ static value_t csnmp_value_list_to_valu
  
    if (vl->type == ASN_OCTET_STR)
    {
-     char *string;
      char *endptr;
  
-     string = (char *) vl->val.string;
      endptr = NULL;
-     if (string != NULL)
+     if (vl->val.string != NULL)
      {
+       char string[64];
+       size_t string_length;
+       string_length = sizeof (string) - 1;
+       if (vl->val_len < string_length)
+       string_length = vl->val_len;
+       /* The strings we get from the Net-SNMP library may not be null
+        * terminated. That is why we're using `membpy' here and not `strcpy'.
+        * `string_length' is set to `vl->val_len' which holds the length of the
+        * string.  -octo */
+       memcpy (string, vl->val.string, string_length);
+       string[string_length] = 0;
        if (type == DS_TYPE_COUNTER)
+       {
        ret.counter = (counter_t) strtoll (string, &endptr, /* base = */ 0);
+       DEBUG ("snmp plugin: csnmp_value_list_to_value: String to counter: %s -> %llu",
+           string, (unsigned long long) ret.counter);
+       }
        else if (type == DS_TYPE_GAUGE)
+       {
        ret.gauge = (gauge_t) strtod (string, &endptr);
+       DEBUG ("snmp plugin: csnmp_value_list_to_value: String to gauge: %s -> %g",
+           string, (double) ret.gauge);
+       }
      }
  
      /* Check if an error occurred */
-     if ((string == NULL) || (endptr == string))
+     if ((vl->val.string == NULL) || (endptr == (char *) vl->val.string))
      {
        if (type == DS_TYPE_COUNTER)
        ret.counter = 0;
@@@ -1130,9 -1146,7 +1149,9 @@@ static int csnmp_read_table (host_defin
        char *errstr = NULL;
  
        snmp_sess_error (host->sess_handle, NULL, NULL, &errstr);
 -      ERROR ("snmp plugin: host %s: snmp_sess_synch_response failed: %s",
 +
 +      c_complain (LOG_ERR, &host->complaint,
 +        "snmp plugin: host %s: snmp_sess_synch_response failed: %s",
          host->name, (errstr == NULL) ? "Unknown problem" : errstr);
  
        if (res != NULL)
      }
      status = 0;
      assert (res != NULL);
 +    c_release (LOG_INFO, &host->complaint,
 +      "snmp plugin: host %s: snmp_sess_synch_response successful.",
 +      host->name);
  
      vb = res->variables;
      if (vb == NULL)