Merge branch 'collectd-5.7'
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Sat, 17 Dec 2016 17:56:47 +0000 (18:56 +0100)
committerRuben Kerkhof <ruben@rubenkerkhof.com>
Sat, 17 Dec 2016 17:56:47 +0000 (18:56 +0100)
1  2 
README
src/Makefile.am
src/email.c
src/target_set.c
src/utils_cmd_getthreshold.c
src/write_prometheus.c

diff --combined README
--- 1/README
--- 2/README
+++ b/README
@@@ -500,6 -500,10 +500,10 @@@ Feature
      - write_mongodb
        Sends data to MongoDB, a NoSQL database.
  
+     - write_prometheus
+       Publish values using an embedded HTTP server, in a format compatible
+       with Prometheus' collectd_exporter.
      - write_redis
        Sends the values to a Redis key-value database server.
  
@@@ -746,6 -750,10 +750,6 @@@ Prerequisite
      Used by the `gps' plugin.
      <http://developer.berlios.de/projects/gpsd/>
  
 -  * libhal (optional)
 -    If present, the `uuid' plugin will check for UUID from HAL.
 -    <http://hal.freedesktop.org/>
 -
    * libi2c-dev (optional)
      Used for the plugin `barometer', provides just the i2c-dev.h header file
      for user space i2c development.
      Used by the `memcachec' plugin to connect to a memcache daemon.
      <http://tangent.org/552/libmemcached.html>
  
+   * libmicrohttpd (optional)
+     Used by the write_prometheus plugin to run an http daemon.
+     <http://www.gnu.org/software/libmicrohttpd/>
    * libmnl (optional)
      Used by the `netlink' plugin.
      <http://www.netfilter.org/projects/libmnl/>
@@@ -969,6 -981,7 +977,6 @@@ To generate the `configure` script, you
  - flex
  - bison
  - libtool
 -- libtool-ltdl
  - pkg-config
  
  The `build.sh' script takes no arguments.
diff --combined src/Makefile.am
@@@ -1,4 -1,8 +1,4 @@@
 -SUBDIRS = libcollectdclient
 -if BUILD_WITH_OWN_LIBOCONFIG
 -SUBDIRS += liboconfig
 -endif
 -SUBDIRS += daemon
 +SUBDIRS = libcollectdclient liboconfig daemon
  
  PLUGIN_LDFLAGS = -module -avoid-version -export-symbols-regex '\<module_register\>'
  
@@@ -376,7 -380,6 +376,7 @@@ if BUILD_PLUGIN_DIS
  pkglib_LTLIBRARIES += disk.la
  disk_la_SOURCES = disk.c
  disk_la_CFLAGS = $(AM_CFLAGS)
 +disk_la_CPPFLAGS = $(AM_CPPFLAGS)
  disk_la_LDFLAGS = $(PLUGIN_LDFLAGS)
  disk_la_LIBADD =
  if BUILD_WITH_LIBKSTAT
@@@ -393,7 -396,7 +393,7 @@@ disk_la_CFLAGS += $(BUILD_WITH_LIBSTATG
  disk_la_LIBADD += $(BUILD_WITH_LIBSTATGRAB_LDFLAGS)
  endif
  if BUILD_WITH_LIBUDEV
 -disk_la_CFLAGS += $(BUILD_WITH_LIBUDEV_CFLAGS)
 +disk_la_CPPFLAGS += $(BUILD_WITH_LIBUDEV_CPPFLAGS)
  disk_la_LDFLAGS += $(BUILD_WITH_LIBUDEV_LDFLAGS)
  disk_la_LIBADD += $(BUILD_WITH_LIBUDEV_LIBS)
  endif
@@@ -408,9 -411,8 +408,9 @@@ endi
  if BUILD_PLUGIN_DNS
  pkglib_LTLIBRARIES += dns.la
  dns_la_SOURCES = dns.c utils_dns.c utils_dns.h
 -dns_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 -dns_la_LIBADD = -lpcap
 +dns_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBPCAP_CPPFLAGS)
 +dns_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBPCAP_LDFLAGS)
 +dns_la_LIBADD = $(BUILD_WITH_LIBPCAP_LIBS)
  endif
  
  if BUILD_PLUGIN_DPDKSTAT
@@@ -442,7 -444,8 +442,8 @@@ endi
  if BUILD_PLUGIN_EXEC
  pkglib_LTLIBRARIES += exec.la
  exec_la_SOURCES = exec.c
- exec_la_LDFLAGS = $(PLUGIN_LDFLAGS) libcmds.la
+ exec_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+ exec_la_LIBADD = libcmds.la
  endif
  
  if BUILD_PLUGIN_ETHSTAT
@@@ -721,9 -724,9 +722,9 @@@ endi
  if BUILD_PLUGIN_MIC
  pkglib_LTLIBRARIES += mic.la
  mic_la_SOURCES = mic.c
 -mic_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_MIC_LIBPATH)
 -mic_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_MIC_CPPFLAGS)
 -mic_la_LIBADD = $(BUILD_WITH_MIC_LDADD)
 +mic_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_MIC_CPPFLAGS)
 +mic_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_MIC_LDFLAGS)
 +mic_la_LIBADD = $(BUILD_WITH_MIC_LIBS)
  endif
  
  if BUILD_PLUGIN_MODBUS
@@@ -820,9 -823,8 +821,9 @@@ endi
  if BUILD_PLUGIN_NOTIFY_EMAIL
  pkglib_LTLIBRARIES += notify_email.la
  notify_email_la_SOURCES = notify_email.c
 -notify_email_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 -notify_email_la_LIBADD = -lesmtp -lssl -lcrypto
 +notify_email_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBESMTP_CPPFLAGS)
 +notify_email_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBESMTP_LDFLAGS)
 +notify_email_la_LIBADD = $(BUILD_WITH_LIBESMTP_LIBS)
  endif
  
  if BUILD_PLUGIN_NOTIFY_NAGIOS
@@@ -909,6 -911,11 +910,6 @@@ perl_la_CPPFLAGS += -D_GNU_SOURC
  perl_la_CFLAGS  = $(AM_CFLAGS) \
                $(PERL_CFLAGS) \
                -DXS_VERSION=\"$(VERSION)\" -DVERSION=\"$(VERSION)\"
 -# Work-around for issues #41 and #42 - Perl 5.10 incorrectly introduced
 -# __attribute__nonnull__(3) for Perl_load_module().
 -if HAVE_BROKEN_PERL_LOAD_MODULE
 -perl_la_CFLAGS += -Wno-nonnull
 -endif
  perl_la_LDFLAGS = $(PLUGIN_LDFLAGS) \
                $(PERL_LDFLAGS)
  perl_la_LIBADD = $(PERL_LIBS)
@@@ -944,7 -951,7 +945,7 @@@ postgresql_la_SOURCES = postgresql.c 
  postgresql_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBPQ_CPPFLAGS)
  postgresql_la_LDFLAGS = $(PLUGIN_LDFLAGS) \
                $(BUILD_WITH_LIBPQ_LDFLAGS)
 -postgresql_la_LIBADD = -lpq
 +postgresql_la_LIBADD = $(BUILD_WITH_LIBPQ_LIBS)
  endif
  
  if BUILD_PLUGIN_POWERDNS
@@@ -1022,9 -1029,9 +1023,9 @@@ endi
  if BUILD_PLUGIN_SENSORS
  pkglib_LTLIBRARIES += sensors.la
  sensors_la_SOURCES = sensors.c
 -sensors_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBSENSORS_CFLAGS)
 +sensors_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBSENSORS_CPPFLAGS)
  sensors_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBSENSORS_LDFLAGS)
 -sensors_la_LIBADD = -lsensors
 +sensors_la_LIBADD = $(BUILD_WITH_LIBSENSORS_LIBS)
  endif
  
  if BUILD_PLUGIN_SERIAL
@@@ -1045,7 -1052,7 +1046,7 @@@ if BUILD_PLUGIN_SMAR
  if BUILD_WITH_LIBUDEV
  pkglib_LTLIBRARIES += smart.la
  smart_la_SOURCES = smart.c
 -smart_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBATASMART_CPPFLAGS) $(BUILD_WITH_LIBUDEV_CFLAGS)
 +smart_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBATASMART_CPPFLAGS) $(BUILD_WITH_LIBUDEV_CPPFLAGS)
  smart_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBATASMART_LDFLAGS) $(BUILD_WITH_LIBUDEV_LDFLAGS)
  smart_la_LIBADD = $(BUILD_WITH_LIBATASMART_LIBS) $(BUILD_WITH_LIBUDEV_LIBS)
  endif
@@@ -1211,7 -1218,8 +1212,8 @@@ endi
  if BUILD_PLUGIN_UNIXSOCK
  pkglib_LTLIBRARIES += unixsock.la
  unixsock_la_SOURCES = unixsock.c
- unixsock_la_LDFLAGS = $(PLUGIN_LDFLAGS) libcmds.la
+ unixsock_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+ unixsock_la_LIBADD =  libcmds.la
  endif
  
  if BUILD_PLUGIN_UPTIME
@@@ -1243,6 -1251,8 +1245,6 @@@ endi
  if BUILD_PLUGIN_UUID
  pkglib_LTLIBRARIES += uuid.la
  uuid_la_SOURCES = uuid.c
 -uuid_la_CFLAGS  = $(AM_CFLAGS) $(BUILD_WITH_LIBHAL_CFLAGS)
 -uuid_la_LIBADD  = $(BUILD_WITH_LIBHAL_LIBS)
  uuid_la_LDFLAGS = $(PLUGIN_LDFLAGS)
  endif
  
@@@ -1261,19 -1271,6 +1263,19 @@@ virt_la_CFLAGS = $(AM_CFLAGS) 
                $(BUILD_WITH_LIBVIRT_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
  virt_la_LIBADD = $(BUILD_WITH_LIBVIRT_LIBS) $(BUILD_WITH_LIBXML2_LIBS)
  virt_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 +
 +# TODO: enable once we support only modern libvirts which depends on libnl-3
 +# the libvirt on wheezy is linked in libnl v1, and there is a small leak here,
 +# triggered by the library initialization. There are no means to avoid it,
 +# and libvirt switched to libnl3 anyway
 +#test_plugin_virt_SOURCES = virt_test.c
 +#test_plugin_virt_CPPFLAGS = $(AM_CPPFLAGS) \
 +#             $(BUILD_WITH_LIBVIRT_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
 +#test_plugin_virt_LDFLAGS = $(PLUGIN_LDFLAGS)
 +#test_plugin_virt_LDADD = daemon/libplugin_mock.la \
 +#             $(BUILD_WITH_LIBVIRT_LIBS) $(BUILD_WITH_LIBXML2_LIBS)
 +#check_PROGRAMS += test_plugin_virt
 +#TESTS += test_plugin_virt
  endif
  
  if BUILD_PLUGIN_VMEM
diff --combined src/email.c
@@@ -361,8 -361,6 +361,6 @@@ static void *collect(void *arg) 
  } /* static void *collect (void *) */
  
  static void *open_connection(void __attribute__((unused)) * arg) {
-   struct sockaddr_un addr;
    const char *path = (NULL == sock_file) ? SOCK_PATH : sock_file;
    const char *group = (NULL == sock_group) ? COLLECTD_GRP_NAME : sock_group;
  
      pthread_exit((void *)1);
    }
  
-   addr.sun_family = AF_UNIX;
+   struct sockaddr_un addr = {
+     .sun_family = AF_UNIX
+   };
    sstrncpy(addr.sun_path, path, (size_t)(UNIX_PATH_MAX - 1));
  
    errno = 0;
@@@ -719,3 -719,5 +719,3 @@@ void module_register(void) 
    plugin_register_read("email", email_read);
    plugin_register_shutdown("email", email_shutdown);
  } /* void module_register */
 -
 -/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
diff --combined src/target_set.c
@@@ -183,8 -183,11 +183,11 @@@ static void ts_subst(char *dest, size_
    REPLACE_FIELD("%{type_instance}", vl->type_instance);
  
    if (vl->meta != NULL) {
-     char **meta_toc;
+     char **meta_toc = NULL;
      int meta_entries = meta_data_toc(vl->meta, &meta_toc);
+     if (meta_entries <= 0)
+       return;
      for (int i = 0; i < meta_entries; i++) {
        char meta_name[DATA_MAX_NAME_LEN];
        char *value_str;
@@@ -358,6 -361,7 +361,7 @@@ static int ts_invoke(const data_set_t *
          ERROR("Target `set': Unable to get replacement metadata value `%s'.",
                key);
          strarray_free(meta_toc, (size_t)meta_entries);
+         meta_data_destroy(new_meta);
          return (status);
        }
  
        if (status) {
          ERROR("Target `set': Unable to set metadata value `%s'.", key);
          strarray_free(meta_toc, (size_t)meta_entries);
+         meta_data_destroy(new_meta);
          return (status);
        }
      }
@@@ -415,3 -420,5 +420,3 @@@ void module_register(void) 
    tproc.invoke = ts_invoke;
    fc_register_target("set", tproc);
  } /* module_register */
 -
 -/* vim: set sw=2 sts=2 tw=78 et fdm=marker : */
@@@ -155,46 -155,31 +155,29 @@@ int handle_getthreshold(FILE *fh, char 
    print_to_socket(fh, "%zu Threshold found\n", i);
  
    if (threshold.host[0] != 0)
-     print_to_socket(fh, "Host: %s\n", threshold.host) if (
-         threshold.plugin[0] !=
-         0) print_to_socket(fh, "Plugin: %s\n",
-                            threshold.plugin) if (threshold.plugin_instance[0] !=
-                                                  0)
-         print_to_socket(fh, "Plugin Instance: %s\n",
-                         threshold.plugin_instance) if (threshold.type[0] != 0)
-             print_to_socket(fh, "Type: %s\n", threshold.type) if (
-                 threshold.type_instance[0] !=
-                 0) print_to_socket(fh, "Type Instance: %s\n",
-                                    threshold
-                                        .type_instance) if (threshold.data_source
-                                                                [0] != 0)
-                 print_to_socket(
-                     fh, "Data Source: %s\n",
-                     threshold.data_source) if (!isnan(threshold.warning_min))
-                     print_to_socket(
-                         fh, "Warning Min: %g\n",
-                         threshold
-                             .warning_min) if (!isnan(threshold.warning_max))
-                         print_to_socket(
-                             fh, "Warning Max: %g\n",
-                             threshold
-                                 .warning_max) if (!isnan(threshold.failure_min))
-                             print_to_socket(
-                                 fh, "Failure Min: %g\n",
-                                 threshold
-                                     .failure_min) if (!isnan(threshold
-                                                                  .failure_max))
-                                 print_to_socket(
-                                     fh, "Failure Max: %g\n",
-                                     threshold.failure_max) if (threshold
-                                                                    .hysteresis >
-                                                                0.0)
-                                     print_to_socket(
-                                         fh, "Hysteresis: %g\n",
-                                         threshold.hysteresis) if (threshold
-                                                                       .hits > 1)
-                                         print_to_socket(fh, "Hits: %i\n",
-                                                         threshold.hits)
-                                             return (0);
+     print_to_socket(fh, "Host: %s\n", threshold.host);
+   if (threshold.plugin[0] != 0)
+     print_to_socket(fh, "Plugin: %s\n", threshold.plugin);
+   if (threshold.plugin_instance[0] != 0)
+     print_to_socket(fh, "Plugin Instance: %s\n", threshold.plugin_instance);
+   if (threshold.type[0] != 0)
+     print_to_socket(fh, "Type: %s\n", threshold.type);
+   if (threshold.type_instance[0] != 0)
+     print_to_socket(fh, "Type Instance: %s\n", threshold.type_instance);
+   if (threshold.data_source[0] != 0)
+     print_to_socket(fh, "Data Source: %s\n", threshold.data_source);
+   if (!isnan(threshold.warning_min))
+     print_to_socket(fh, "Warning Min: %g\n", threshold.warning_min);
+   if (!isnan(threshold.warning_max))
+     print_to_socket(fh, "Warning Max: %g\n", threshold.warning_max);
+   if (!isnan(threshold.failure_min))
+     print_to_socket(fh, "Failure Min: %g\n", threshold.failure_min);
+   if (!isnan(threshold.failure_max))
+     print_to_socket(fh, "Failure Max: %g\n", threshold.failure_max);
+   if (threshold.hysteresis > 0.0)
+     print_to_socket(fh, "Hysteresis: %g\n", threshold.hysteresis);
+   if (threshold.hits > 1)
+     print_to_socket(fh, "Hits: %i\n", threshold.hits);
+   return (0);
  } /* int handle_getthreshold */
 -
 -/* vim: set sw=2 sts=2 ts=8 et : */
diff --combined src/write_prometheus.c
@@@ -694,8 -694,10 +694,10 @@@ metric_family_get(data_set_t const *ds
      return fam;
    }
  
-   if (!allocate)
+   if (!allocate) {
+     sfree(name);
      return NULL;
+   }
  
    fam = metric_family_create(name, ds, vl, ds_index);
    if (fam == NULL) {
@@@ -868,3 -870,5 +870,3 @@@ void module_register() 
                            /* user data = */ NULL);
    plugin_register_shutdown("write_prometheus", prom_shutdown);
  }
 -
 -/* vim: set sw=2 sts=2 et fdm=marker : */