Merge branch 'collectd-5.5'
authorMarc Fournier <marc.fournier@camptocamp.com>
Mon, 3 Aug 2015 21:29:16 +0000 (23:29 +0200)
committerMarc Fournier <marc.fournier@camptocamp.com>
Mon, 3 Aug 2015 21:29:16 +0000 (23:29 +0200)
1  2 
configure.ac
src/daemon/plugin.c
src/modbus.c
src/varnish.c

diff --combined configure.ac
@@@ -90,12 -90,12 +90,12 @@@ case $host_os i
  esac
  AC_MSG_RESULT([$ac_system])
  
- AM_CONDITIONAL([BUILD_LINUX],[test "x$x$ac_system" = "xLinux"])
- AM_CONDITIONAL([BUILD_SOLARIS],[test "x$x$ac_system" = "xSolaris"])
- AM_CONDITIONAL([BUILD_DARWIN],[test "x$x$ac_system" = "xDarwin"])
- AM_CONDITIONAL([BUILD_OPENBSD],[test "x$x$ac_system" = "xOpenBSD"])
- AM_CONDITIONAL([BUILD_AIX],[test "x$x$ac_system" = "xAIX"])
- AM_CONDITIONAL([BUILD_FREEBSD],[test "x$x$ac_system" = "xFreeBSD"])
+ AM_CONDITIONAL([BUILD_LINUX],[test "x$ac_system" = "xLinux"])
+ AM_CONDITIONAL([BUILD_SOLARIS],[test "x$ac_system" = "xSolaris"])
+ AM_CONDITIONAL([BUILD_DARWIN],[test "x$ac_system" = "xDarwin"])
+ AM_CONDITIONAL([BUILD_OPENBSD],[test "x$ac_system" = "xOpenBSD"])
+ AM_CONDITIONAL([BUILD_AIX],[test "x$ac_system" = "xAIX"])
+ AM_CONDITIONAL([BUILD_FREEBSD],[test "x$ac_system" = "xFreeBSD"])
  
  if test "x$ac_system" = "xLinux"
  then
@@@ -2562,7 -2562,7 +2562,7 @@@ the
        SAVE_CPPFLAGS="$CPPFLAGS"
        CPPFLAGS="$CPPFLAGS $with_libmodbus_cflags"
  
-       AC_CHECK_HEADERS(modbus/modbus.h, [], [with_libmodbus="no (modbus/modbus.h not found)"])
+       AC_CHECK_HEADERS(modbus.h, [], [with_libmodbus="no (modbus.h not found)"])
  
        CPPFLAGS="$SAVE_CPPFLAGS"
  fi
  AM_CONDITIONAL(BUILD_WITH_LIBMONGOC, test "x$with_libmongoc" = "xyes")
  # }}}
  
 +# --with-libmosquitto {{{
 +with_libmosquitto_cppflags=""
 +with_libmosquitto_libs="-lmosquitto"
 +AC_ARG_WITH(libmosquitto, [AS_HELP_STRING([--with-libmosquitto@<:@=PREFIX@:>@], [Path to libmosquitto.])],
 +[
 +      if test "x$withval" != "xno" && test "x$withval" != "xyes"
 +      then
 +              with_libmosquitto_cppflags="-I$withval/include"
 +              with_libmosquitto_libs="-L$withval/lib -lmosquitto"
 +              with_libmosquitto="yes"
 +      else
 +              with_libmosquitto="$withval"
 +      fi
 +],
 +[
 +      with_libmosquitto="yes"
 +])
 +if test "x$with_libmosquitto" = "xyes"
 +then
 +      SAVE_CPPFLAGS="$CPPFLAGS"
 +      CPPFLAGS="$with_libmosquitto_cppflags"
 +
 +      AC_CHECK_HEADERS(mosquitto.h, [with_libmosquitto="yes"], [with_libmosquitto="no (mosquitto.h not found)"])
 +
 +      CPPFLAGS="$SAVE_CPPFLAGS"
 +fi
 +if test "x$with_libmosquitto" = "xyes"
 +then
 +      SAVE_LDFLAGS="$LDFLAGS"
 +      SAVE_CPPFLAGS="$CPPFLAGS"
 +      LDFLAGS="$with_libmosquitto_libs"
 +      CPPFLAGS="$with_libmosquitto_cppflags"
 +
 +      AC_CHECK_LIB(mosquitto, mosquitto_connect, [with_libmosquitto="yes"], [with_libmosquitto="no (libmosquitto not found)"])
 +
 +      LDFLAGS="$SAVE_LDFLAGS"
 +      CPPFLAGS="$SAVE_CPPFLAGS"
 +fi
 +if test "x$with_libmosquitto" = "xyes"
 +then
 +      BUILD_WITH_LIBMOSQUITTO_CPPFLAGS="$with_libmosquitto_cppflags"
 +      BUILD_WITH_LIBMOSQUITTO_LIBS="$with_libmosquitto_libs"
 +      AC_SUBST(BUILD_WITH_LIBMOSQUITTO_CPPFLAGS)
 +      AC_SUBST(BUILD_WITH_LIBMOSQUITTO_LIBS)
 +fi
 +# }}}
 +
  # --with-libmysql {{{
  with_mysql_config="mysql_config"
  with_mysql_cflags=""
  # }}} --with-python
  
  # --with-librabbitmq {{{
- with_librabbitmq_cppflags=""
- with_librabbitmq_ldflags=""
+ with_librabbitmq_cppflags="-I/usr/local/include"
+ with_librabbitmq_ldflags="-L/usr/local/lib"
  AC_ARG_WITH(librabbitmq, [AS_HELP_STRING([--with-librabbitmq@<:@=PREFIX@:>@], [Path to librabbitmq.])],
  [
        if test "x$withval" != "xno" && test "x$withval" != "xyes"
  
        CPPFLAGS="$CPPFLAGS $with_libvarnish_cflags"
  
-       AC_CHECK_HEADERS(varnish/vapi/vsc.h,
+       AC_CHECK_HEADERS(vapi/vsc.h,
                [AC_DEFINE([HAVE_VARNISH_V4], [1], [Varnish 4 API support])],
-               [AC_CHECK_HEADERS(varnish/vsc.h,
+               [AC_CHECK_HEADERS(vsc.h,
                        [AC_DEFINE([HAVE_VARNISH_V3], [1], [Varnish 3 API support])],
-                       [AC_CHECK_HEADERS(varnish/varnishapi.h,
+                       [AC_CHECK_HEADERS(varnishapi.h,
                                [AC_DEFINE([HAVE_VARNISH_V2], [1], [Varnish 2 API support])],
                                [with_libvarnish="no (found none of the varnish header files)"])])])
  
@@@ -5290,7 -5243,6 +5290,7 @@@ plugin_vmem="no
  plugin_vserver="no"
  plugin_wireless="no"
  plugin_zfs_arc="no"
 +plugin_zone="no"
  plugin_zookeeper="no"
  
  # Linux
  
  if test "x$ac_system" = "xAIX"
  then
-         plugin_tcpconns="yes"
-         plugin_ipc="yes"
+       plugin_tcpconns="yes"
+       plugin_ipc="yes"
  fi
  
  # FreeBSD
  
  if test "x$ac_system" = "xFreeBSD"
  then
-         plugin_zfs_arc="yes"
+       plugin_zfs_arc="yes"
  fi
  
  
@@@ -5388,7 -5340,6 +5388,7 @@@ the
        plugin_processes="yes"
        plugin_uptime="yes"
        plugin_zfs_arc="yes"
 +      plugin_zone="yes"
  fi
  
  if test "x$with_devinfo$with_kstat" = "xyesyes"
@@@ -5679,7 -5630,6 +5679,7 @@@ AC_PLUGIN([memcached],   [yes]
  AC_PLUGIN([memory],      [$plugin_memory],     [Memory usage])
  AC_PLUGIN([mic],         [$with_mic],          [Intel Many Integrated Core stats])
  AC_PLUGIN([modbus],      [$with_libmodbus],    [Modbus plugin])
 +AC_PLUGIN([mqtt],        [$with_libmosquitto], [MQTT output plugin])
  AC_PLUGIN([multimeter],  [$plugin_multimeter], [Read multimeter values])
  AC_PLUGIN([mysql],       [$with_libmysql],     [MySQL statistics])
  AC_PLUGIN([netapp],      [$with_libnetapp],    [NetApp plugin])
@@@ -5755,7 -5705,6 +5755,7 @@@ AC_PLUGIN([write_sensu], [yes]
  AC_PLUGIN([write_tsdb],  [yes],                [TSDB output plugin])
  AC_PLUGIN([xmms],        [$with_libxmms],      [XMMS statistics])
  AC_PLUGIN([zfs_arc],     [$plugin_zfs_arc],    [ZFS ARC statistics])
 +AC_PLUGIN([zone],        [$plugin_zone],       [Solaris container statistics])
  AC_PLUGIN([zookeeper],   [yes],              [Zookeeper statistics])
  
  dnl Default configuration file
@@@ -5960,7 -5909,6 +5960,7 @@@ Configuration
      libmnl  . . . . . . . $with_libmnl
      libmodbus . . . . . . $with_libmodbus
      libmongoc . . . . . . $with_libmongoc
 +    libmosquitto  . . . . $with_libmosquitto
      libmysql  . . . . . . $with_libmysql
      libnetapp . . . . . . $with_libnetapp
      libnetsnmp  . . . . . $with_libnetsnmp
      memory  . . . . . . . $enable_memory
      mic . . . . . . . . . $enable_mic
      modbus  . . . . . . . $enable_modbus
 +    mqtt  . . . . . . . . $enable_mqtt
      multimeter  . . . . . $enable_multimeter
      mysql . . . . . . . . $enable_mysql
      netapp  . . . . . . . $enable_netapp
      write_tsdb  . . . . . $enable_write_tsdb
      xmms  . . . . . . . . $enable_xmms
      zfs_arc . . . . . . . $enable_zfs_arc
 +    zone  . . . . . . . . $enable_zone
      zookeeper . . . . . . $enable_zookeeper
  
  EOF
diff --combined src/daemon/plugin.c
@@@ -80,12 -80,6 +80,12 @@@ struct write_queue_
        write_queue_t *next;
  };
  
 +struct flush_callback_s {
 +      char *name;
 +      cdtime_t timeout;
 +};
 +typedef struct flush_callback_s flush_callback_t;
 +
  /*
   * Private variables
   */
@@@ -241,13 -235,13 +241,13 @@@ static void destroy_read_heap (void) /
  
        while (42)
        {
-               callback_func_t *cf;
+               read_func_t *rf;
  
-               cf = c_heap_get_root (read_heap);
-               if (cf == NULL)
+               rf = c_heap_get_root (read_heap);
+               if (rf == NULL)
                        break;
-               destroy_callback (cf);
+               sfree (rf->rf_name);
+               destroy_callback ((callback_func_t *) rf);
        }
  
        c_heap_destroy (read_heap);
@@@ -889,7 -883,7 +889,7 @@@ static void start_write_threads (size_
  static void stop_write_threads (void) /* {{{ */
  {
        write_queue_t *q;
 -      int i;
 +      size_t i;
  
        if (write_threads == NULL)
                return;
  
        if (i > 0)
        {
 -              WARNING ("plugin: %i value list%s left after shutting down "
 +              WARNING ("plugin: %zu value list%s left after shutting down "
                                "the write threads.",
                                i, (i == 1) ? " was" : "s were");
        }
@@@ -1253,7 -1247,7 +1253,7 @@@ int plugin_register_read (const char *n
  
  int plugin_register_complex_read (const char *group, const char *name,
                plugin_read_cb callback,
 -              const struct timespec *interval,
 +              cdtime_t interval,
                user_data_t *user_data)
  {
        read_func_t *rf;
                rf->rf_group[0] = '\0';
        rf->rf_name = strdup (name);
        rf->rf_type = RF_COMPLEX;
 -      if (interval != NULL)
 -              rf->rf_interval = TIMESPEC_TO_CDTIME_T (interval);
 -      else
 -              rf->rf_interval = plugin_get_interval ();
 +      rf->rf_interval = (interval != 0) ? interval : plugin_get_interval ();
  
        /* Set user data */
        if (user_data == NULL)
@@@ -1305,105 -1302,11 +1305,105 @@@ int plugin_register_write (const char *
                                (void *) callback, ud));
  } /* int plugin_register_write */
  
 +static int plugin_flush_timeout_callback (user_data_t *ud)
 +{
 +      flush_callback_t *cb = ud->data;
 +
 +      return plugin_flush (cb->name, cb->timeout, /* identifier = */ NULL);
 +} /* static int plugin_flush_callback */
 +
 +static void plugin_flush_timeout_callback_free (void *data)
 +{
 +      flush_callback_t *cb = data;
 +
 +      if (cb == NULL) return;
 +
 +      sfree(cb->name);
 +      sfree(cb);
 +} /* static void plugin_flush_callback_free */
 +
 +static char *plugin_flush_callback_name (const char *name)
 +{
 +      char *flush_prefix = "flush/";
 +      size_t prefix_size;
 +      char *flush_name;
 +      size_t name_size;
 +
 +      prefix_size = strlen(flush_prefix);
 +      name_size = strlen(name);
 +
 +      flush_name = malloc (sizeof(char) * (name_size + prefix_size + 1));
 +      if (flush_name == NULL)
 +      {
 +              ERROR ("plugin_flush_callback_name: malloc failed.");
 +              return (NULL);
 +      }
 +
 +      sstrncpy (flush_name, flush_prefix, prefix_size + 1);
 +      sstrncpy (flush_name + prefix_size, name, name_size + 1);
 +
 +      return flush_name;
 +} /* static char *plugin_flush_callback_name */
 +
  int plugin_register_flush (const char *name,
                plugin_flush_cb callback, user_data_t *ud)
  {
 -      return (create_register_callback (&list_flush, name,
 -                              (void *) callback, ud));
 +      int status;
 +      plugin_ctx_t ctx = plugin_get_ctx ();
 +
 +      status = create_register_callback (&list_flush, name,
 +              (void *) callback, ud);
 +      if (status != 0)
 +              return status;
 +
 +      if (ctx.flush_interval != 0)
 +      {
 +              char *flush_name;
 +              user_data_t ud;
 +              flush_callback_t *cb;
 +
 +              flush_name = plugin_flush_callback_name (name);
 +              if (flush_name == NULL)
 +                      return (-1);
 +
 +              cb = malloc(sizeof(flush_callback_t));
 +              if (cb == NULL)
 +              {
 +                      ERROR ("plugin_register_flush: malloc failed.");
 +                      sfree(flush_name);
 +                      return (-1);
 +              }
 +
 +              cb->name = strdup (name);
 +              if (cb->name == NULL)
 +              {
 +                      ERROR ("plugin_register_flush: strdup failed.");
 +                      sfree(cb);
 +                      sfree(flush_name);
 +                      return (-1);
 +              }
 +              cb->timeout = ctx.flush_timeout;
 +
 +              ud.data = cb;
 +              ud.free_func = plugin_flush_timeout_callback_free;
 +
 +              status = plugin_register_complex_read (
 +                      /* group     = */ "flush",
 +                      /* name      = */ flush_name,
 +                      /* callback  = */ plugin_flush_timeout_callback,
 +                      /* interval  = */ ctx.flush_interval,
 +                      /* user data = */ &ud);
 +
 +              sfree(flush_name);
 +              if (status != 0)
 +              {
 +                      sfree(cb->name);
 +                      sfree(cb);
 +                      return status;
 +              }
 +      }
 +
 +      return 0;
  } /* int plugin_register_flush */
  
  int plugin_register_missing (const char *name,
@@@ -1444,7 -1347,7 +1444,7 @@@ static void plugin_free_data_sets (void
  int plugin_register_data_set (const data_set_t *ds)
  {
        data_set_t *ds_copy;
 -      int i;
 +      size_t i;
  
        if ((data_sets != NULL)
                        && (c_avl_get (data_sets, ds->type, NULL) == 0))
@@@ -1622,21 -1525,7 +1622,21 @@@ int plugin_unregister_write (const cha
  
  int plugin_unregister_flush (const char *name)
  {
 -      return (plugin_unregister (list_flush, name));
 +      plugin_ctx_t ctx = plugin_get_ctx ();
 +
 +      if (ctx.flush_interval != 0)
 +      {
 +              char *flush_name;
 +
 +              flush_name = plugin_flush_callback_name (name);
 +              if (flush_name != NULL)
 +              {
 +                      plugin_unregister_read(flush_name);
 +                      sfree(flush_name);
 +              }
 +      }
 +
 +      return plugin_unregister (list_flush, name);
  }
  
  int plugin_unregister_missing (const char *name)
@@@ -2142,8 -2031,8 +2142,8 @@@ static int plugin_dispatch_values_inter
        if (ds->ds_num != vl->values_len)
        {
                ERROR ("plugin_dispatch_values: ds->type = %s: "
 -                              "(ds->ds_num = %i) != "
 -                              "(vl->values_len = %i)",
 +                              "(ds->ds_num = %zu) != "
 +                              "(vl->values_len = %zu)",
                                ds->type, ds->ds_num, vl->values_len);
                return (-1);
        }
diff --combined src/modbus.c
@@@ -27,7 -27,7 +27,7 @@@
  
  #include <netdb.h>
  
- #include <modbus/modbus.h>
+ #include <modbus.h>
  
  #ifndef LIBMODBUS_VERSION_CHECK
  /* Assume version 2.0.3 */
@@@ -440,7 -440,7 +440,7 @@@ static int mb_read_data (mb_host_t *hos
  
    if (ds->ds_num != 1)
    {
 -    ERROR ("Modbus plugin: The type \"%s\" has %i data sources. "
 +    ERROR ("Modbus plugin: The type \"%s\" has %zu data sources. "
          "I can only handle data sets with only one data source.",
          data->type, ds->ds_num);
      return (-1);
@@@ -1014,15 -1014,18 +1014,15 @@@ static int mb_config_add_host (oconfig_
    {
      user_data_t ud;
      char name[1024];
 -    struct timespec interval = { 0, 0 };
  
      ud.data = host;
      ud.free_func = host_free;
  
      ssnprintf (name, sizeof (name), "modbus-%s", host->host);
  
 -    CDTIME_T_TO_TIMESPEC (host->interval, &interval);
 -
      plugin_register_complex_read (/* group = */ NULL, name,
          /* callback = */ mb_read,
 -        /* interval = */ (host->interval > 0) ? &interval : NULL,
 +        /* interval = */ host->interval,
          &ud);
    }
    else
diff --combined src/varnish.c
  #include "configfile.h"
  
  #if HAVE_VARNISH_V4
- #include <varnish/vapi/vsm.h>
- #include <varnish/vapi/vsc.h>
+ #include <vapi/vsm.h>
+ #include <vapi/vsc.h>
  typedef struct VSC_C_main c_varnish_stats_t;
  #endif
  
  #if HAVE_VARNISH_V3
- #include <varnish/varnishapi.h>
- #include <varnish/vsc.h>
+ #include <varnishapi.h>
+ #include <vsc.h>
  typedef struct VSC_C_main c_varnish_stats_t;
  #endif
  
  #if HAVE_VARNISH_V2
- #include <varnish/varnishapi.h>
+ #include <varnishapi.h>
  typedef struct varnish_stats c_varnish_stats_t;
  #endif
  
@@@ -749,7 -749,7 +749,7 @@@ static int varnish_init (void) /* {{{ *
        plugin_register_complex_read (/* group = */ "varnish",
                        /* name      = */ "varnish/localhost",
                        /* callback  = */ varnish_read,
 -                      /* interval  = */ NULL,
 +                      /* interval  = */ 0,
                        /* user data = */ &ud);
  
        return (0);
@@@ -911,7 -911,7 +911,7 @@@ static int varnish_config_instance (con
        plugin_register_complex_read (/* group = */ "varnish",
                        /* name      = */ callback_name,
                        /* callback  = */ varnish_read,
 -                      /* interval  = */ NULL,
 +                      /* interval  = */ 0,
                        /* user data = */ &ud);
  
        have_instance = 1;