Merge branch 'collectd-5.2'
authorFlorian Forster <octo@collectd.org>
Sun, 3 Feb 2013 10:39:50 +0000 (11:39 +0100)
committerFlorian Forster <octo@collectd.org>
Sun, 3 Feb 2013 10:39:50 +0000 (11:39 +0100)
1  2 
configure.in
src/Makefile.am
src/postgresql.c
src/write_graphite.c

diff --combined configure.in
@@@ -24,7 -24,7 +24,7 @@@ m4_ifdef([LT_PACKAGE_VERSION]
        ]
  )
  
- AM_INIT_AUTOMAKE(dist-bzip2)
+ AM_INIT_AUTOMAKE([tar-pax dist-bzip2])
  AC_LANG(C)
  
  AC_PREFIX_DEFAULT("/opt/collectd")
@@@ -128,7 -128,7 +128,7 @@@ AC_HEADER_SYS_WAI
  AC_HEADER_DIRENT
  AC_HEADER_STDBOOL
  
 -AC_CHECK_HEADERS(stdio.h errno.h math.h stdarg.h syslog.h fcntl.h signal.h assert.h sys/types.h sys/socket.h sys/select.h poll.h netdb.h arpa/inet.h sys/resource.h sys/param.h kstat.h regex.h sys/ioctl.h endian.h sys/isa_defs.h)
 +AC_CHECK_HEADERS(stdio.h errno.h math.h stdarg.h syslog.h fcntl.h signal.h assert.h sys/types.h sys/socket.h sys/select.h poll.h netdb.h arpa/inet.h sys/resource.h sys/param.h kstat.h regex.h sys/ioctl.h endian.h sys/isa_defs.h fnmatch.h libgen.h)
  
  # For ping library
  AC_CHECK_HEADERS(netinet/in_systm.h, [], [],
@@@ -270,19 -270,7 +270,19 @@@ if test "x$ac_system" = "xDarwin
  then
        AC_CHECK_HEADERS(mach/mach_init.h mach/host_priv.h mach/mach_error.h mach/mach_host.h mach/mach_port.h mach/mach_types.h mach/message.h mach/processor_set.h mach/processor.h mach/processor_info.h mach/task.h mach/thread_act.h mach/vm_region.h mach/vm_map.h mach/vm_prot.h mach/vm_statistics.h mach/kern_return.h)
        AC_CHECK_HEADERS(CoreFoundation/CoreFoundation.h IOKit/IOKitLib.h IOKit/IOTypes.h IOKit/ps/IOPSKeys.h IOKit/IOBSD.h IOKit/storage/IOBlockStorageDriver.h)
 +      # For the battery plugin
 +      AC_CHECK_HEADERS(IOKit/ps/IOPowerSources.h, [], [],
 +[
 +#if HAVE_IOKIT_IOKITLIB_H
 +#  include <IOKit/IOKitLib.h>
 +#endif
 +#if HAVE_IOKIT_IOTYPES_H
 +#  include <IOKit/IOTypes.h>
 +#endif
 +])
 +
  fi
 +
  AC_CHECK_HEADERS(sys/sysctl.h, [], [],
  [
  #if HAVE_SYS_TYPES_H
@@@ -310,7 -298,7 +310,7 @@@ els
  fi
  
  # For hddtemp module
 -AC_CHECK_HEADERS(linux/major.h libgen.h)
 +AC_CHECK_HEADERS(linux/major.h)
  
  # For md module (Linux only)
  if test "x$ac_system" = "xLinux"
@@@ -327,6 -315,17 +327,6 @@@ els
        have_linux_raid_md_u_h="no"
  fi
  
 -# For the battery plugin
 -AC_CHECK_HEADERS(IOKit/ps/IOPowerSources.h, [], [],
 -[
 -#if HAVE_IOKIT_IOKITLIB_H
 -#  include <IOKit/IOKitLib.h>
 -#endif
 -#if HAVE_IOKIT_IOTYPES_H
 -#  include <IOKit/IOTypes.h>
 -#endif
 -])
 -
  # For the swap module
  have_linux_wireless_h="no"
  if test "x$ac_system" = "xLinux"
@@@ -537,7 -536,20 +537,20 @@@ AC_CHECK_HEADERS(netinet/if_ether.h, []
  AC_CHECK_HEADERS(netinet/ip_compat.h)
  
  have_net_pfvar_h="no"
- AC_CHECK_HEADERS(net/pfvar.h, [have_net_pfvar_h="yes"])
+ AC_CHECK_HEADERS(net/pfvar.h,
+                [have_net_pfvar_h="yes"],
+                [have_net_pfvar_h="no"],
+ [
+ #if HAVE_SYS_IOCTL_H
+ # include <sys/ioctl.h>
+ #endif
+ #if HAVE_SYS_SOCKET_H
+ # include <sys/socket.h>
+ #endif
+ #if HAVE_NET_IF_H
+ # include <net/if.h>
+ #endif
+ ])
  
  # For the multimeter plugin
  have_termios_h="no"
@@@ -4965,9 -4977,8 +4978,9 @@@ AC_PLUGIN([vserver],     [$plugin_vserv
  AC_PLUGIN([wireless],    [$plugin_wireless],   [Wireless statistics])
  AC_PLUGIN([write_graphite], [yes],             [Graphite / Carbon output plugin])
  AC_PLUGIN([write_http],  [$with_libcurl],      [HTTP output plugin])
 -AC_PLUGIN([write_redis], [$with_libcredis],    [Redis output plugin])
  AC_PLUGIN([write_mongodb], [$with_libmongoc],  [MongoDB output plugin])
 +AC_PLUGIN([write_redis], [$with_libcredis],    [Redis output plugin])
 +AC_PLUGIN([write_riemann], [$have_protoc_c],   [Riemann output plugin])
  AC_PLUGIN([xmms],        [$with_libxmms],      [XMMS statistics])
  AC_PLUGIN([zfs_arc],     [$plugin_zfs_arc],    [ZFS ARC statistics])
  
@@@ -5299,9 -5310,8 +5312,9 @@@ Configuration
      wireless  . . . . . . $enable_wireless
      write_graphite  . . . $enable_write_graphite
      write_http  . . . . . $enable_write_http
 -    write_redis . . . . . $enable_write_redis
      write_mongodb . . . . $enable_write_mongodb
 +    write_redis . . . . . $enable_write_redis
 +    write_riemann . . . . $enable_write_riemann
      xmms  . . . . . . . . $enable_xmms
      zfs_arc . . . . . . . $enable_zfs_arc
  
diff --combined src/Makefile.am
@@@ -1339,17 -1339,6 +1339,17 @@@ collectd_LDADD += "-dlopen" write_redis
  collectd_DEPENDENCIES += write_redis.la
  endif
  
 +if BUILD_PLUGIN_WRITE_RIEMANN
 +BUILT_SOURCES += riemann.pb-c.c riemann.pb-c.h
 +CLEANFILES += riemann.pb-c.c riemann.pb-c.h
 +pkglib_LTLIBRARIES += write_riemann.la
 +write_riemann_la_SOURCES = write_riemann.c riemann.pb-c.c
 +write_riemann_la_LDFLAGS = -module -avoid-version
 +write_riemann_la_LIBADD = -lprotobuf-c
 +collectd_LDADD += "-dlopen" write_riemann.la
 +collectd_DEPENDENCIES += write_riemann.la
 +endif
 +
  if BUILD_PLUGIN_XMMS
  pkglib_LTLIBRARIES += xmms.la
  xmms_la_SOURCES = xmms.c
@@@ -1390,7 -1379,7 +1390,7 @@@ dist_man_MANS = collectd.1 
  
  #collectd_1_SOURCES = collectd.pod
  
 -EXTRA_DIST = types.db pinba.proto
 +EXTRA_DIST = types.db pinba.proto riemann.proto
  
  EXTRA_DIST +=   collectd.conf.pod \
                collectd-email.pod \
        fi
  
  pinba.pb-c.c pinba.pb-c.h: pinba.proto
-       protoc-c --c_out . pinba.proto
+       protoc-c -I$(srcdir) --c_out . $(srcdir)/pinba.proto
  
 +riemann.pb-c.c riemann.pb-c.h: riemann.proto
 +      protoc-c --c_out . riemann.proto
 +
  install-exec-hook:
        $(mkinstalldirs) $(DESTDIR)$(sysconfdir)
        if test -e $(DESTDIR)$(sysconfdir)/collectd.conf; \
diff --combined src/postgresql.c
@@@ -170,14 -170,14 +170,14 @@@ static char *def_queries[] = 
  };
  static int def_queries_num = STATIC_ARRAY_SIZE (def_queries);
  
- static c_psql_database_t *databases     = NULL;
- static size_t             databases_num = 0;
+ static c_psql_database_t **databases     = NULL;
+ static size_t              databases_num = 0;
  
- static udb_query_t      **queries       = NULL;
- static size_t             queries_num   = 0;
+ static udb_query_t       **queries       = NULL;
+ static size_t              queries_num   = 0;
  
- static c_psql_writer_t   *writers       = NULL;
- static size_t             writers_num   = 0;
+ static c_psql_writer_t    *writers       = NULL;
+ static size_t              writers_num   = 0;
  
  static int c_psql_begin (c_psql_database_t *db)
  {
@@@ -220,17 -220,25 +220,25 @@@ static int c_psql_commit (c_psql_databa
  
  static c_psql_database_t *c_psql_database_new (const char *name)
  {
-       c_psql_database_t *db;
+       c_psql_database_t **tmp;
+       c_psql_database_t  *db;
  
-       db = (c_psql_database_t *)realloc (databases,
-                       (databases_num + 1) * sizeof (*db));
+       db = (c_psql_database_t *)malloc (sizeof(*db));
        if (NULL == db) {
                log_err ("Out of memory.");
                return NULL;
        }
  
-       databases = db;
-       db = databases + databases_num;
+       tmp = (c_psql_database_t **)realloc (databases,
+                       (databases_num + 1) * sizeof (*databases));
+       if (NULL == tmp) {
+               log_err ("Out of memory.");
+               sfree (db);
+               return NULL;
+       }
+       databases = tmp;
+       databases[databases_num] = db;
        ++databases_num;
  
        db->conn = NULL;
@@@ -324,7 -332,9 +332,9 @@@ static void c_psql_database_delete (voi
        sfree (db->service);
  
        /* don't care about freeing or reordering the 'databases' array
-        * this is done in 'shutdown' */
+        * this is done in 'shutdown'; also, don't free the database instance
+        * object just to make sure that in case anybody accesses it before
+        * shutdown won't segfault */
        return;
  } /* c_psql_database_delete */
  
@@@ -371,6 -381,9 +381,6 @@@ static int c_psql_check_connection (c_p
                c_psql_connect (db);
        }
  
 -      /* "ping" */
 -      PQclear (PQexec (db->conn, "SELECT 42;"));
 -
        if (CONNECTION_OK != PQstatus (db->conn)) {
                PQreset (db->conn);
  
@@@ -511,12 -524,6 +521,12 @@@ static int c_psql_exec_query (c_psql_da
        if (PGRES_TUPLES_OK != PQresultStatus (res)) {
                pthread_mutex_lock (&db->db_lock);
  
 +              if ((CONNECTION_OK != PQstatus (db->conn))
 +                              && (0 == c_psql_check_connection (db))) {
 +                      PQclear (res);
 +                      return c_psql_exec_query (db, q, prep_area);
 +              }
 +
                log_err ("Failed to execute SQL query: %s",
                                PQerrorMessage (db->conn));
                log_info ("SQL query was: %s",
@@@ -959,17 -966,17 +969,17 @@@ static int c_psql_flush (cdtime_t timeo
                __attribute__((unused)) const char *ident,
                user_data_t *ud)
  {
-       c_psql_database_t *dbs = databases;
+       c_psql_database_t **dbs = databases;
        size_t dbs_num = databases_num;
        size_t i;
  
        if ((ud != NULL) && (ud->data != NULL)) {
-               dbs = ud->data;
+               dbs = (void *)&ud->data;
                dbs_num = 1;
        }
  
        for (i = 0; i < dbs_num; ++i) {
-               c_psql_database_t *db = dbs + i;
+               c_psql_database_t *db = dbs[i];
  
                /* don't commit if the timeout is larger than the regular commit
                 * interval as in that case all requested data has already been
@@@ -989,7 -996,7 +999,7 @@@ static int c_psql_shutdown (void
        plugin_unregister_read_group ("postgresql");
  
        for (i = 0; i < databases_num; ++i) {
-               c_psql_database_t *db = databases + i;
+               c_psql_database_t *db = databases[i];
  
                if (db->writers_num > 0) {
                        char cb_name[DATA_MAX_NAME_LEN];
                        plugin_unregister_flush (cb_name);
                        plugin_unregister_write (cb_name);
                }
+               sfree (db);
        }
  
        udb_query_free (queries, queries_num);
diff --combined src/write_graphite.c
@@@ -4,7 -4,7 +4,7 @@@
   * Copyright (C) 2011       Scott Sanders
   * Copyright (C) 2009       Paul Sadauskas
   * Copyright (C) 2009       Doug MacEachern
-  * Copyright (C) 2007-2012  Florian octo Forster
+  * Copyright (C) 2007-2013  Florian octo Forster
   *
   * 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
@@@ -46,6 -46,7 +46,7 @@@
  #include "configfile.h"
  
  #include "utils_cache.h"
+ #include "utils_complain.h"
  #include "utils_parse_option.h"
  #include "utils_format_graphite.h"
  
@@@ -79,17 -80,13 +80,15 @@@ struct wg_callbac
  {
      int      sock_fd;
  
 +    char    *name;
 +
      char    *node;
      char    *service;
      char    *prefix;
      char    *postfix;
      char     escape_char;
  
-     _Bool    store_rates;
-     _Bool    separate_instances;
-     _Bool    always_append_ds;
+     unsigned int format_flags;
  
      char     send_buf[WG_SEND_BUF_SIZE];
      size_t   send_buf_free;
@@@ -97,6 -94,7 +96,7 @@@
      cdtime_t send_buf_init_time;
  
      pthread_mutex_t send_lock;
+     c_complain_t init_complaint;
  };
  
  
@@@ -218,12 -216,19 +218,19 @@@ static int wg_callback_init (struct wg_
      if (cb->sock_fd < 0)
      {
          char errbuf[1024];
-         ERROR ("write_graphite plugin: Connecting to %s:%s failed. "
+         c_complain (LOG_ERR, &cb->init_complaint,
+                 "write_graphite plugin: Connecting to %s:%s failed. "
                  "The last error was: %s", node, service,
                  sstrerror (errno, errbuf, sizeof (errbuf)));
          close (cb->sock_fd);
          return (-1);
      }
+     else
+     {
+         c_release (LOG_INFO, &cb->init_complaint,
+                 "write_graphite plugin: Successfully connected to %s:%s.",
+                 node, service);
+     }
  
      wg_reset_buffer (cb);
  
@@@ -246,7 -251,6 +253,7 @@@ static void wg_callback_free (void *dat
      close(cb->sock_fd);
      cb->sock_fd = -1;
  
 +    sfree(cb->name);
      sfree(cb->node);
      sfree(cb->service);
      sfree(cb->prefix);
@@@ -276,7 -280,7 +283,7 @@@ static int wg_flush (cdtime_t timeout
          status = wg_callback_init (cb);
          if (status != 0)
          {
-             ERROR ("write_graphite plugin: wg_callback_init failed.");
+             /* An error message has already been printed. */
              pthread_mutex_unlock (&cb->send_lock);
              return (-1);
          }
@@@ -302,7 -306,7 +309,7 @@@ static int wg_send_message (char const 
          status = wg_callback_init (cb);
          if (status != 0)
          {
-             ERROR ("write_graphite plugin: wg_callback_init failed.");
+             /* An error message has already been printed. */
              pthread_mutex_unlock (&cb->send_lock);
              return (-1);
          }
  static int wg_write_messages (const data_set_t *ds, const value_list_t *vl,
          struct wg_callback *cb)
  {
-     char buffer[4096];
+     char buffer[WG_SEND_BUF_SIZE];
      int status;
  
      if (0 != strcmp (ds->type, vl->type))
  
      memset (buffer, 0, sizeof (buffer));
      status = format_graphite (buffer, sizeof (buffer), ds, vl,
-             cb->prefix, cb->postfix, cb->escape_char, cb->store_rates);
+             cb->prefix, cb->postfix, cb->escape_char, cb->format_flags);
      if (status != 0) /* error message has been printed already. */
          return (status);
  
+     /* Send the message to graphite */
      wg_send_message (buffer, cb);
      if (status != 0)
      {
-         ERROR ("write_graphite plugin: wg_send_message failed "
-                 "with status %i.", status);
+         /* An error message has already been printed. */
          return (status);
      }
  
@@@ -417,7 -421,7 +424,7 @@@ static int config_set_char (char *dest
      return (0);
  }
  
 -static int wg_config_carbon (oconfig_item_t *ci)
 +static int wg_config_node (oconfig_item_t *ci)
  {
      struct wg_callback *cb;
      user_data_t user_data;
      }
      memset (cb, 0, sizeof (*cb));
      cb->sock_fd = -1;
 +    cb->name = NULL;
      cb->node = NULL;
      cb->service = NULL;
      cb->prefix = NULL;
      cb->postfix = NULL;
      cb->escape_char = WG_DEFAULT_ESCAPE;
-     cb->store_rates = 1;
+     cb->format_flags = GRAPHITE_STORE_RATES;
  
 +    /* FIXME: Legacy configuration syntax. */
 +    if (strcasecmp ("Carbon", ci->key) != 0)
 +    {
 +        int status = cf_util_get_string (ci, &cb->name);
 +        if (status != 0)
 +        {
 +            wg_callback_free (cb);
 +            return (status);
 +        }
 +    }
 +
      pthread_mutex_init (&cb->send_lock, /* attr = */ NULL);
+     C_COMPLAIN_INIT (&cb->init_complaint);
  
      for (i = 0; i < ci->children_num; i++)
      {
          else if (strcasecmp ("Postfix", child->key) == 0)
              cf_util_get_string (child, &cb->postfix);
          else if (strcasecmp ("StoreRates", child->key) == 0)
-             cf_util_get_boolean (child, &cb->store_rates);
+             cf_util_get_flag (child, &cb->format_flags,
+                     GRAPHITE_STORE_RATES);
          else if (strcasecmp ("SeparateInstances", child->key) == 0)
-             cf_util_get_boolean (child, &cb->separate_instances);
+             cf_util_get_flag (child, &cb->format_flags,
+                     GRAPHITE_SEPARATE_INSTANCES);
          else if (strcasecmp ("AlwaysAppendDS", child->key) == 0)
-             cf_util_get_boolean (child, &cb->always_append_ds);
+             cf_util_get_flag (child, &cb->format_flags,
+                     GRAPHITE_ALWAYS_APPEND_DS);
          else if (strcasecmp ("EscapeCharacter", child->key) == 0)
              config_set_char (&cb->escape_char, child);
          else
          }
      }
  
 -    ssnprintf (callback_name, sizeof (callback_name), "write_graphite/%s/%s",
 -            cb->node != NULL ? cb->node : WG_DEFAULT_NODE,
 -            cb->service != NULL ? cb->service : WG_DEFAULT_SERVICE);
 +    /* FIXME: Legacy configuration syntax. */
 +    if (cb->name == NULL)
 +        ssnprintf (callback_name, sizeof (callback_name), "write_graphite/%s/%s",
 +                cb->node != NULL ? cb->node : WG_DEFAULT_NODE,
 +                cb->service != NULL ? cb->service : WG_DEFAULT_SERVICE);
 +    else
 +        ssnprintf (callback_name, sizeof (callback_name), "write_graphite/%s",
 +                cb->name);
  
      memset (&user_data, 0, sizeof (user_data));
      user_data.data = cb;
@@@ -508,11 -499,8 +519,11 @@@ static int wg_config (oconfig_item_t *c
      {
          oconfig_item_t *child = ci->children + i;
  
 -        if (strcasecmp ("Carbon", child->key) == 0)
 -            wg_config_carbon (child);
 +        if (strcasecmp ("Node", child->key) == 0)
 +            wg_config_node (child);
 +        /* FIXME: Remove this legacy mode in version 6. */
 +        else if (strcasecmp ("Carbon", child->key) == 0)
 +            wg_config_node (child);
          else
          {
              ERROR ("write_graphite plugin: Invalid configuration "