Merge remote-tracking branch 'github/pr/1085'
authorFlorian Forster <octo@collectd.org>
Tue, 16 Jun 2015 18:38:38 +0000 (20:38 +0200)
committerFlorian Forster <octo@collectd.org>
Tue, 16 Jun 2015 18:38:38 +0000 (20:38 +0200)
22 files changed:
configure.ac
src/collectd.conf.pod
src/collectdctl.c
src/collectdmon.c
src/cpu.c
src/daemon/Makefile.am
src/daemon/collectd.c
src/daemon/configfile.c
src/disk.c
src/liboconfig/Makefile.am
src/processes.c
src/smart.c
src/statsd.c
src/swap.c
src/tail.c
src/tail_csv.c
src/tcpconns.c
src/users.c
src/utils_dns.c
src/vmem.c
src/write_redis.c
src/zone.c

index f713ce1..4e88a26 100644 (file)
@@ -113,7 +113,20 @@ if test "x$ac_system" = "xSolaris"
 then
        AC_DEFINE(_POSIX_PTHREAD_SEMANTICS, 1, [Define to enforce POSIX thread semantics under Solaris.])
        AC_DEFINE(_REENTRANT,               1, [Define to enable reentrancy interfaces.])
+
+       AC_MSG_CHECKING([whether compiler builds 64bit binaries])
+       AC_PREPROC_IFELSE([AC_LANG_PROGRAM([
+                          #ifndef _LP64
+                          # error "Compiler not in 64bit mode."
+                          #endif
+                          ])],
+                          [AC_MSG_RESULT([yes])],
+                          [
+                           AC_MSG_RESULT([no])
+                           AC_MSG_NOTICE([Solaris detected. Please consider building a 64-bit binary.])
+                          ])
 fi
+
 if test "x$ac_system" = "xAIX"
 then
        AC_DEFINE(_THREAD_SAFE_ERRNO, 1, [Define to use the thread-safe version of errno under AIX.])
@@ -285,6 +298,54 @@ AC_CHECK_HEADERS(netinet/udp.h, [], [],
 #endif
 ])
 
+have_ip6_ext="no"
+AC_CHECK_TYPES([struct ip6_ext], [have_ip6_ext="yes"], [have_ip6_ext="no"],
+[#if HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#if HAVE_NETINET_IN_SYSTM_H
+# include <netinet/in_systm.h>
+#endif
+#if HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+#if HAVE_NETINET_IP6_H
+# include <netinet/ip6.h>
+#endif
+])
+
+if test "x$have_ip6_ext" = "xno"; then
+       SAVE_CFLAGS="$CFLAGS"
+       CFLAGS="$CFLAGS -DSOLARIS2=8"
+
+       AC_CHECK_TYPES([struct ip6_ext],
+                      [have_ip6_ext="yes, with -DSOLARIS2=8"],
+                      [have_ip6_ext="no"],
+[#if HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#if HAVE_NETINET_IN_SYSTM_H
+# include <netinet/in_systm.h>
+#endif
+#if HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+#if HAVE_NETINET_IP6_H
+# include <netinet/ip6.h>
+#endif
+])
+
+       if test "x$have_ip6_ext" = "xno"; then
+               CFLAGS="$SAVE_CFLAGS"
+       fi
+fi
+
 # For cpu modules
 AC_CHECK_HEADERS(sys/dkstat.h)
 if test "x$ac_system" = "xDarwin"
@@ -376,18 +437,6 @@ AC_CHECK_HEADERS(sys/swap.h vm/anon.h, [], [have_sys_swap_h="no"],
 #endif
 ])
 
-if test "x$have_sys_swap_h$ac_system" = "xnoSolaris"
-then
-       hint_64=""
-       if test "x$GCC" = "xyes"
-       then
-               hint_64="CFLAGS='-m64'"
-       else
-               hint_64="CFLAGS='-xarch=v9'"
-       fi
-       AC_MSG_NOTICE([Solaris detected and sys/swap.h not usable. Try building a 64-bit binary ($hint_64 ./configure).])
-fi
-
 # For load module
 # For the processes plugin
 # For users module
@@ -595,14 +644,14 @@ AC_CHECK_HEADERS(asm/msr-index.h, [have_asm_msrindex_h="yes"])
 
 if test "x$have_asm_msrindex_h" = "xyes"
 then
-  AC_CACHE_CHECK([whether asm/msr-index.h has MSR_CORE_C3_RESIDENCY],
+  AC_CACHE_CHECK([whether asm/msr-index.h has MSR_PKG_C10_RESIDENCY],
                  [c_cv_have_usable_asm_msrindex_h],
                  AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
 [[[
 #include<asm/msr-index.h>
 ]]],
 [[[
-int y = MSR_CORE_C3_RESIDENCY;
+int y = MSR_PKG_C10_RESIDENCY;
 return(y);
 ]]]
   )],
index d713667..f5e9d27 100644 (file)
@@ -1565,7 +1565,7 @@ setting accordingly to prevent this from blocking other plugins.
 =head2 Plugin C<curl_json>
 
 The B<curl_json plugin> collects values from JSON data to be parsed by
-B<libyajl> (L<http://www.lloydforge.org/projects/yajl/>) retrieved via
+B<libyajl> (L<https://lloyd.github.io/yajl/>) retrieved via
 either B<libcurl> (L<http://curl.haxx.se/>) or read directly from a
 unix socket. The former can be used, for example, to collect values
 from CouchDB documents (which are stored JSON notation), and the
index 2329285..8357ce8 100644 (file)
@@ -98,7 +98,7 @@ static void exit_usage (const char *name, int status) {
       "Hostname defaults to the local hostname if omitted (e.g., uptime/uptime).\n"
       "No error is returned if the specified identifier does not exist.\n"
 
-      "\n"PACKAGE" "VERSION", http://collectd.org/\n"
+      "\n"PACKAGE_NAME" "PACKAGE_VERSION", http://collectd.org/\n"
       "by Florian octo Forster <octo@collectd.org>\n"
       "for contributions see `AUTHORS'\n"
       , name);
index c3f9525..6c50cf1 100644 (file)
@@ -80,7 +80,7 @@ static void exit_usage (char *name)
 
                        "\nFor <collectd options> see collectd.conf(5).\n"
 
-                       "\n"PACKAGE" "VERSION", http://collectd.org/\n"
+                       "\n"PACKAGE_NAME" "PACKAGE_VERSION", http://collectd.org/\n"
                        "by Florian octo Forster <octo@collectd.org>\n"
                        "for contributions see `AUTHORS'\n", name);
        exit (0);
index 57af2dd..2a2a4a9 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -582,16 +582,16 @@ static int cpu_read (void)
                        continue;
                }
 
-               if (cpu_info_len < COLLECTD_CPU_STATE_MAX)
+               if (cpu_info_len < CPU_STATE_MAX)
                {
                        ERROR ("cpu plugin: processor_info returned only %i elements..", cpu_info_len);
                        continue;
                }
 
-               cpu_stage (cpu, COLLECTD_CPU_STATE_USER,   (derive_t) cpu_info.cpu_ticks[COLLECTD_CPU_STATE_USER],   now);
-               cpu_stage (cpu, COLLECTD_CPU_STATE_NICE,   (derive_t) cpu_info.cpu_ticks[COLLECTD_CPU_STATE_NICE],   now);
-               cpu_stage (cpu, COLLECTD_CPU_STATE_SYSTEM, (derive_t) cpu_info.cpu_ticks[COLLECTD_CPU_STATE_SYSTEM], now);
-               cpu_stage (cpu, COLLECTD_CPU_STATE_IDLE,   (derive_t) cpu_info.cpu_ticks[COLLECTD_CPU_STATE_IDLE],   now);
+               cpu_stage (cpu, COLLECTD_CPU_STATE_USER,   (derive_t) cpu_info.cpu_ticks[CPU_STATE_USER],   now);
+               cpu_stage (cpu, COLLECTD_CPU_STATE_NICE,   (derive_t) cpu_info.cpu_ticks[CPU_STATE_NICE],   now);
+               cpu_stage (cpu, COLLECTD_CPU_STATE_SYSTEM, (derive_t) cpu_info.cpu_ticks[CPU_STATE_SYSTEM], now);
+               cpu_stage (cpu, COLLECTD_CPU_STATE_IDLE,   (derive_t) cpu_info.cpu_ticks[CPU_STATE_IDLE],   now);
        }
 /* }}} #endif PROCESSOR_CPU_LOAD_INFO */
 
index 7f826e3..00a8fd7 100644 (file)
@@ -13,6 +13,30 @@ endif
 AM_CPPFLAGS += -DPLUGINDIR='"${pkglibdir}"'
 AM_CPPFLAGS += -DPKGDATADIR='"${pkgdatadir}"'
 
+# Link to these libraries..
+COMMON_LIBS =
+if BUILD_WITH_LIBRT
+COMMON_LIBS += -lrt
+endif
+if BUILD_WITH_LIBPOSIX4
+COMMON_LIBS += -lposix4
+endif
+if BUILD_WITH_LIBSOCKET
+COMMON_LIBS += -lsocket
+endif
+if BUILD_WITH_LIBRESOLV
+COMMON_LIBS += -lresolv
+endif
+if BUILD_WITH_LIBPTHREAD
+COMMON_LIBS += -lpthread
+endif
+if BUILD_WITH_LIBKSTAT
+COMMON_LIBS += -lkstat
+endif
+if BUILD_WITH_LIBDEVINFO
+COMMON_LIBS += -ldevinfo
+endif
+
 AUTOMAKE_OPTIONS = subdir-objects
 
 sbin_PROGRAMS = collectd
@@ -48,35 +72,9 @@ collectd_SOURCES = collectd.c collectd.h \
 collectd_CPPFLAGS =  $(AM_CPPFLAGS) $(LTDLINCL)
 collectd_CFLAGS = $(AM_CFLAGS)
 collectd_LDFLAGS = -export-dynamic
-collectd_LDADD = libavltree.la libcommon.la libheap.la -lm
+collectd_LDADD = libavltree.la libcommon.la libheap.la -lm $(COMMON_LIBS)
 collectd_DEPENDENCIES =
 
-# Link to these libraries..
-if BUILD_WITH_LIBRT
-collectd_LDADD += -lrt
-endif
-if BUILD_WITH_LIBPOSIX4
-collectd_LDADD += -lposix4
-endif
-if BUILD_WITH_LIBSOCKET
-collectd_LDADD += -lsocket
-endif
-if BUILD_WITH_LIBRESOLV
-collectd_LDADD += -lresolv
-endif
-if BUILD_WITH_LIBPTHREAD
-collectd_LDADD += -lpthread
-endif
-if BUILD_WITH_LIBKSTAT
-collectd_LDADD += -lkstat
-endif
-if BUILD_WITH_LIBDEVINFO
-collectd_LDADD += -ldevinfo
-endif
-if BUILD_AIX
-collectd_LDFLAGS += -Wl,-bexpall,-brtllib
-endif
-
 # The daemon needs to call sg_init, so we need to link it against libstatgrab,
 # too. -octo
 if BUILD_WITH_LIBSTATGRAB
@@ -95,10 +93,10 @@ check_PROGRAMS = test_common test_utils_avltree test_utils_heap
 TESTS = test_common test_utils_avltree test_utils_heap
 
 test_common_SOURCES = common_test.c ../testing.h
-test_common_LDADD = libcommon.la libplugin_mock.la
+test_common_LDADD = libcommon.la libplugin_mock.la $(COMMON_LIBS)
 
 test_utils_avltree_SOURCES = utils_avltree_test.c ../testing.h
-test_utils_avltree_LDADD = libavltree.la
+test_utils_avltree_LDADD = libavltree.la $(COMMON_LIBS)
 
 test_utils_heap_SOURCES = utils_heap_test.c ../testing.h
-test_utils_heap_LDADD = libheap.la
+test_utils_heap_LDADD = libheap.la $(COMMON_LIBS)
index 1b9c374..a708665 100644 (file)
@@ -270,7 +270,7 @@ static void update_kstat (void)
  */
 static void exit_usage (int status)
 {
-       printf ("Usage: "PACKAGE" [OPTIONS]\n\n"
+       printf ("Usage: "PACKAGE_NAME" [OPTIONS]\n\n"
 
                        "Available options:\n"
                        "  General:\n"
@@ -289,7 +289,7 @@ static void exit_usage (int status)
                        "  PID file          "PIDFILE"\n"
                        "  Plugin directory  "PLUGINDIR"\n"
                        "  Data directory    "PKGLOCALSTATEDIR"\n"
-                       "\n"PACKAGE" "VERSION", http://collectd.org/\n"
+                       "\n"PACKAGE_NAME" "PACKAGE_VERSION", http://collectd.org/\n"
                        "by Florian octo Forster <octo@collectd.org>\n"
                        "for contributions see `AUTHORS'\n");
        exit (status);
index 244124d..da7ed5f 100644 (file)
@@ -402,9 +402,19 @@ static int dispatch_block_plugin (oconfig_item_t *ci)
 
        if (IS_TRUE (global_option_get ("AutoLoadPlugin")))
        {
+               plugin_ctx_t ctx;
+               plugin_ctx_t old_ctx;
                int status;
 
+               /* default to the global interval set before loading this plugin */
+               memset (&ctx, 0, sizeof (ctx));
+               ctx.interval = cf_get_default_interval ();
+
+               old_ctx = plugin_set_ctx (ctx);
                status = plugin_load (name, /* flags = */ 0);
+               /* reset to the "global" context */
+               plugin_set_ctx (old_ctx);
+
                if (status != 0)
                {
                        ERROR ("Automatically loading plugin \"%s\" failed "
index 8830403..1c3dd98 100644 (file)
@@ -395,169 +395,112 @@ static int disk_read (void)
        io_registry_entry_t     disk;
        io_registry_entry_t     disk_child;
        io_iterator_t           disk_list;
-       CFDictionaryRef         props_dict;
+       CFMutableDictionaryRef  props_dict, child_dict;
        CFDictionaryRef         stats_dict;
-       CFDictionaryRef         child_dict;
        CFStringRef             tmp_cf_string_ref;
        kern_return_t           status;
 
-       signed long long read_ops;
-       signed long long read_byt;
-       signed long long read_tme;
-       signed long long write_ops;
-       signed long long write_byt;
-       signed long long write_tme;
+       signed long long read_ops, read_byt, read_tme;
+       signed long long write_ops, write_byt, write_tme;
 
-       int  disk_major;
-       int  disk_minor;
+       int  disk_major, disk_minor;
        char disk_name[DATA_MAX_NAME_LEN];
-       char disk_name_bsd[DATA_MAX_NAME_LEN];
+       char child_disk_name_bsd[DATA_MAX_NAME_LEN], props_disk_name_bsd[DATA_MAX_NAME_LEN];
 
        /* Get the list of all disk objects. */
-       if (IOServiceGetMatchingServices (io_master_port,
-                               IOServiceMatching (kIOBlockStorageDriverClass),
-                               &disk_list) != kIOReturnSuccess)
-       {
+       if (IOServiceGetMatchingServices (io_master_port, IOServiceMatching (kIOBlockStorageDriverClass), &disk_list) != kIOReturnSuccess) {
                ERROR ("disk plugin: IOServiceGetMatchingServices failed.");
                return (-1);
        }
 
-       while ((disk = IOIteratorNext (disk_list)) != 0)
-       {
+       while ((disk = IOIteratorNext (disk_list)) != 0) {
                props_dict = NULL;
                stats_dict = NULL;
                child_dict = NULL;
 
-               /* `disk_child' must be released */
-               if ((status = IORegistryEntryGetChildEntry (disk, kIOServicePlane, &disk_child))
-                               != kIOReturnSuccess)
-               {
-                       /* This fails for example for DVD/CD drives.. */
+               /* get child of disk entry and corresponding property dictionary */
+               if ((status = IORegistryEntryGetChildEntry (disk, kIOServicePlane, &disk_child)) != kIOReturnSuccess) {
+                       /* This fails for example for DVD/CD drives, which we want to ignore anyway */
                        DEBUG ("IORegistryEntryGetChildEntry (disk) failed: 0x%08x", status);
                        IOObjectRelease (disk);
                        continue;
                }
-
-               /* We create `props_dict' => we need to release it later */
-               if (IORegistryEntryCreateCFProperties (disk,
-                                       (CFMutableDictionaryRef *) &props_dict,
-                                       kCFAllocatorDefault,
-                                       kNilOptions)
-                               != kIOReturnSuccess)
-               {
-                       ERROR ("disk-plugin: IORegistryEntryCreateCFProperties failed.");
+               if (IORegistryEntryCreateCFProperties (disk_child, (CFMutableDictionaryRef *) &child_dict, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess || child_dict == NULL) {
+                       ERROR ("disk plugin: IORegistryEntryCreateCFProperties (disk_child) failed.");
                        IOObjectRelease (disk_child);
                        IOObjectRelease (disk);
                        continue;
                }
 
-               if (props_dict == NULL)
-               {
-                       DEBUG ("IORegistryEntryCreateCFProperties (disk) failed.");
-                       IOObjectRelease (disk_child);
-                       IOObjectRelease (disk);
-                       continue;
+               /* extract name and major/minor numbers */
+               memset (child_disk_name_bsd, 0, sizeof (child_disk_name_bsd));
+               tmp_cf_string_ref = (CFStringRef) CFDictionaryGetValue (child_dict, CFSTR(kIOBSDNameKey));
+               if (tmp_cf_string_ref) {
+                       assert (CFGetTypeID (tmp_cf_string_ref) == CFStringGetTypeID ());
+                       CFStringGetCString (tmp_cf_string_ref, child_disk_name_bsd, sizeof (child_disk_name_bsd), kCFStringEncodingUTF8);
                }
+               disk_major = (int) dict_get_value (child_dict, kIOBSDMajorKey);
+               disk_minor = (int) dict_get_value (child_dict, kIOBSDMinorKey);
+               DEBUG ("disk plugin: child_disk_name_bsd=\"%s\" major=%d minor=%d", child_disk_name_bsd, disk_major, disk_minor);
+               CFRelease (child_dict);
+               IOObjectRelease (disk_child);
 
-               /* tmp_cf_string_ref doesn't need to be released. */
-               tmp_cf_string_ref = (CFStringRef) CFDictionaryGetValue (props_dict,
-                               CFSTR(kIOBSDNameKey));
-               if (!tmp_cf_string_ref)
-               {
-                       DEBUG ("disk plugin: CFDictionaryGetValue("
-                                       "kIOBSDNameKey) failed.");
-                       CFRelease (props_dict);
-                       IOObjectRelease (disk_child);
+               /* get property dictionary of the disk entry itself */
+               if (IORegistryEntryCreateCFProperties (disk, (CFMutableDictionaryRef *) &props_dict, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess || props_dict == NULL) {
+                       ERROR ("disk-plugin: IORegistryEntryCreateCFProperties failed.");
                        IOObjectRelease (disk);
                        continue;
                }
-               assert (CFGetTypeID (tmp_cf_string_ref) == CFStringGetTypeID ());
 
-               memset (disk_name_bsd, 0, sizeof (disk_name_bsd));
-               CFStringGetCString (tmp_cf_string_ref,
-                               disk_name_bsd, sizeof (disk_name_bsd),
-                               kCFStringEncodingUTF8);
-               if (disk_name_bsd[0] == 0)
-               {
-                       ERROR ("disk plugin: CFStringGetCString() failed.");
-                       CFRelease (props_dict);
-                       IOObjectRelease (disk_child);
-                       IOObjectRelease (disk);
-                       continue;
+               /* extract name and stats dictionary */
+               memset (props_disk_name_bsd, 0, sizeof (props_disk_name_bsd));
+               tmp_cf_string_ref = (CFStringRef) CFDictionaryGetValue (props_dict, CFSTR(kIOBSDNameKey));
+               if (tmp_cf_string_ref) {
+                       assert (CFGetTypeID (tmp_cf_string_ref) == CFStringGetTypeID ());
+                       CFStringGetCString (tmp_cf_string_ref, props_disk_name_bsd, sizeof (props_disk_name_bsd), kCFStringEncodingUTF8);
                }
-               DEBUG ("disk plugin: disk_name_bsd = \"%s\"", disk_name_bsd);
-
-               stats_dict = (CFDictionaryRef) CFDictionaryGetValue (props_dict,
-                               CFSTR (kIOBlockStorageDriverStatisticsKey));
-
-               if (stats_dict == NULL)
-               {
-                       DEBUG ("disk plugin: CFDictionaryGetValue ("
-                                       "%s) failed.",
-                                       kIOBlockStorageDriverStatisticsKey);
+               stats_dict = (CFDictionaryRef) CFDictionaryGetValue (props_dict, CFSTR (kIOBlockStorageDriverStatisticsKey));
+               if (stats_dict == NULL) {
+                       ERROR ("disk plugin: CFDictionaryGetValue (%s) failed.", kIOBlockStorageDriverStatisticsKey);
                        CFRelease (props_dict);
-                       IOObjectRelease (disk_child);
                        IOObjectRelease (disk);
                        continue;
                }
-
-               if (IORegistryEntryCreateCFProperties (disk_child,
-                                       (CFMutableDictionaryRef *) &child_dict,
-                                       kCFAllocatorDefault,
-                                       kNilOptions)
-                               != kIOReturnSuccess)
-               {
-                       DEBUG ("disk plugin: IORegistryEntryCreateCFProperties ("
-                                       "disk_child) failed.");
-                       IOObjectRelease (disk_child);
-                       CFRelease (props_dict);
-                       IOObjectRelease (disk);
-                       continue;
+               DEBUG ("disk plugin: props_disk_name_bsd=\"%s\"", props_disk_name_bsd);
+
+               /* choose name */
+               if (use_bsd_name) {
+                       if (child_disk_name_bsd[0] != 0)
+                               sstrncpy (disk_name, child_disk_name_bsd, sizeof (disk_name));
+                       else if (props_disk_name_bsd[0] != 0)
+                               sstrncpy (disk_name, props_disk_name_bsd, sizeof (disk_name));
+                       else {
+                               ERROR ("disk plugin: can't find bsd disk name.");
+                               ssnprintf (disk_name, sizeof (disk_name), "%i-%i", disk_major, disk_minor);
+                       }
                }
-
-               /* kIOBSDNameKey */
-               disk_major = (int) dict_get_value (child_dict,
-                               kIOBSDMajorKey);
-               disk_minor = (int) dict_get_value (child_dict,
-                               kIOBSDMinorKey);
-               read_ops  = dict_get_value (stats_dict,
-                               kIOBlockStorageDriverStatisticsReadsKey);
-               read_byt  = dict_get_value (stats_dict,
-                               kIOBlockStorageDriverStatisticsBytesReadKey);
-               read_tme  = dict_get_value (stats_dict,
-                               kIOBlockStorageDriverStatisticsTotalReadTimeKey);
-               write_ops = dict_get_value (stats_dict,
-                               kIOBlockStorageDriverStatisticsWritesKey);
-               write_byt = dict_get_value (stats_dict,
-                               kIOBlockStorageDriverStatisticsBytesWrittenKey);
-               /* This property describes the number of nanoseconds spent
-                * performing writes since the block storage driver was
-                * instantiated. It is one of the statistic entries listed
-                * under the top-level kIOBlockStorageDriverStatisticsKey
-                * property table. It has an OSNumber value. */
-               write_tme = dict_get_value (stats_dict,
-                               kIOBlockStorageDriverStatisticsTotalWriteTimeKey);
-
-               if (use_bsd_name)
-                       sstrncpy (disk_name, disk_name_bsd, sizeof (disk_name));
                else
-                       ssnprintf (disk_name, sizeof (disk_name), "%i-%i",
-                                       disk_major, disk_minor);
-               DEBUG ("disk plugin: disk_name = \"%s\"", disk_name);
+                       ssnprintf (disk_name, sizeof (disk_name), "%i-%i", disk_major, disk_minor);
+
+               /* extract the stats */
+               read_ops  = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsReadsKey);
+               read_byt  = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsBytesReadKey);
+               read_tme  = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsTotalReadTimeKey);
+               write_ops = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsWritesKey);
+               write_byt = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsBytesWrittenKey);
+               write_tme = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsTotalWriteTimeKey);
+               CFRelease (props_dict);
+               IOObjectRelease (disk);
 
+               /* and submit */
+               DEBUG ("disk plugin: disk_name = \"%s\"", disk_name);
                if ((read_byt != -1LL) || (write_byt != -1LL))
                        disk_submit (disk_name, "disk_octets", read_byt, write_byt);
                if ((read_ops != -1LL) || (write_ops != -1LL))
                        disk_submit (disk_name, "disk_ops", read_ops, write_ops);
                if ((read_tme != -1LL) || (write_tme != -1LL))
-                       disk_submit (disk_name, "disk_time",
-                                       read_tme / 1000,
-                                       write_tme / 1000);
+                       disk_submit (disk_name, "disk_time", read_tme / 1000, write_tme / 1000);
 
-               CFRelease (child_dict);
-               IOObjectRelease (disk_child);
-               CFRelease (props_dict);
-               IOObjectRelease (disk);
        }
        IOObjectRelease (disk_list);
 /* #endif HAVE_IOKIT_IOKITLIB_H */
index c3de92c..b5162cc 100644 (file)
@@ -6,5 +6,5 @@ AM_YFLAGS = -d
 
 noinst_LTLIBRARIES = liboconfig.la
 
-liboconfig_la_LDFLAGS = -version-info 0:0:0 $(LEXLIB)
+liboconfig_la_LDFLAGS = -avoid-version $(LEXLIB)
 liboconfig_la_SOURCES = oconfig.c oconfig.h aux_types.h scanner.l parser.y
index a6c5096..4e0aa78 100644 (file)
@@ -1849,6 +1849,7 @@ static int ps_read (void)
                        continue;
                }
 
+               memset (&pse, 0, sizeof (pse));
                pse.id       = pid;
                pse.age      = 0;
 
@@ -2126,6 +2127,7 @@ static int ps_read (void)
                                }
                        } /* if (process has argument list) */
 
+                       memset (&pse, 0, sizeof (pse));
                        pse.id       = procs[i].p_pid;
                        pse.age      = 0;
 
@@ -2155,6 +2157,9 @@ static int ps_read (void)
                        pse.io_syscr = -1;
                        pse.io_syscw = -1;
 
+                       pse.cswitch_vol = -1;
+                       pse.cswitch_invol = -1;
+
                        ps_list_add (procs[i].p_comm, have_cmdline ? cmdline : NULL, &pse);
                } /* if ((proc_ptr == NULL) || (proc_ptr->p_pid != procs[i].p_pid)) */
 
@@ -2370,6 +2375,7 @@ static int ps_read (void)
                        continue;
                }
 
+               memset (&pse, 0, sizeof (pse));
                pse.id = pid;
                pse.age = 0;
 
@@ -2396,6 +2402,9 @@ static int ps_read (void)
                pse.io_syscr = ps.io_syscr;
                pse.io_syscw = ps.io_syscw;
 
+               pse.cswitch_vol = -1;
+               pse.cswitch_invol = -1;
+
                switch (state)
                {
                        case 'R': running++;  break;
index 3b113bd..2207bd6 100644 (file)
@@ -253,6 +253,7 @@ static int smart_read (void)
 
     /* Query status with libatasmart */
     smart_handle_disk (devpath);
+    udev_device_unref (dev);
   }
 
   udev_enumerate_unref (enumerate);
index 0885e23..5b0bdd6 100644 (file)
@@ -195,6 +195,35 @@ static int statsd_metric_add (char const *name, double delta, /* {{{ */
   return (0);
 } /* }}} int statsd_metric_add */
 
+static void statsd_metric_free (statsd_metric_t *metric) /* {{{ */
+{
+  if (metric == NULL)
+    return;
+
+  if (metric->latency != NULL)
+  {
+    latency_counter_destroy (metric->latency);
+    metric->latency = NULL;
+  }
+
+  if (metric->set != NULL)
+  {
+    void *key;
+    void *value;
+
+    while (c_avl_pick (metric->set, &key, &value) == 0)
+    {
+      sfree (key);
+      assert (value == NULL);
+    }
+
+    c_avl_destroy (metric->set);
+    metric->set = NULL;
+  }
+
+  sfree (metric);
+} /* }}} void statsd_metric_free */
+
 static int statsd_parse_value (char const *str, value_t *ret_value) /* {{{ */
 {
   char *endptr = NULL;
@@ -753,39 +782,42 @@ static int statsd_metric_submit_unsafe (char const *name, /* {{{ */
   else if (metric->type == STATSD_TIMER)
   {
     size_t i;
+    _Bool have_events = (metric->updates_num > 0);
 
-    if (metric->updates_num == 0)
-      return (0);
-
+    /* Make sure all timer metrics share the *same* timestamp. */
     vl.time = cdtime ();
 
     ssnprintf (vl.type_instance, sizeof (vl.type_instance),
         "%s-average", name);
-    values[0].gauge = CDTIME_T_TO_DOUBLE (
-        latency_counter_get_average (metric->latency));
+    values[0].gauge = have_events
+      ? CDTIME_T_TO_DOUBLE (latency_counter_get_average (metric->latency))
+      : NAN;
     plugin_dispatch_values (&vl);
 
     if (conf_timer_lower) {
       ssnprintf (vl.type_instance, sizeof (vl.type_instance),
           "%s-lower", name);
-      values[0].gauge = CDTIME_T_TO_DOUBLE (
-          latency_counter_get_min (metric->latency));
+      values[0].gauge = have_events
+        ? CDTIME_T_TO_DOUBLE (latency_counter_get_min (metric->latency))
+        : NAN;
       plugin_dispatch_values (&vl);
     }
 
     if (conf_timer_upper) {
       ssnprintf (vl.type_instance, sizeof (vl.type_instance),
           "%s-upper", name);
-      values[0].gauge = CDTIME_T_TO_DOUBLE (
-          latency_counter_get_max (metric->latency));
+      values[0].gauge = have_events
+        ? CDTIME_T_TO_DOUBLE (latency_counter_get_max (metric->latency))
+        : NAN;
       plugin_dispatch_values (&vl);
     }
 
     if (conf_timer_sum) {
       ssnprintf (vl.type_instance, sizeof (vl.type_instance),
           "%s-sum", name);
-      values[0].gauge = CDTIME_T_TO_DOUBLE (
-          latency_counter_get_sum (metric->latency));
+      values[0].gauge = have_events
+        ? CDTIME_T_TO_DOUBLE (latency_counter_get_sum (metric->latency))
+        : NAN;
       plugin_dispatch_values (&vl);
     }
 
@@ -793,9 +825,9 @@ static int statsd_metric_submit_unsafe (char const *name, /* {{{ */
     {
       ssnprintf (vl.type_instance, sizeof (vl.type_instance),
           "%s-percentile-%.0f", name, conf_timer_percentile[i]);
-      values[0].gauge = CDTIME_T_TO_DOUBLE (
-          latency_counter_get_percentile (
-            metric->latency, conf_timer_percentile[i]));
+      values[0].gauge = have_events
+        ? CDTIME_T_TO_DOUBLE (latency_counter_get_percentile (metric->latency, conf_timer_percentile[i]))
+        : NAN;
       plugin_dispatch_values (&vl);
     }
 
@@ -882,7 +914,7 @@ static int statsd_read (void) /* {{{ */
     }
 
     sfree (name);
-    sfree (metric);
+    statsd_metric_free (metric);
   }
 
   pthread_mutex_unlock (&metrics_lock);
index a8276c7..cfde4ea 100644 (file)
@@ -281,7 +281,8 @@ static int swap_read_separate (void) /* {{{ */
                if (total < used)
                        continue;
 
-               swap_submit_usage (path, used, total - used, NULL, NAN);
+               swap_submit_usage (path, used * 1024.0, (total - used) * 1024.0,
+                               NULL, NAN);
        }
 
        fclose (fh);
@@ -340,8 +341,9 @@ static int swap_read_combined (void) /* {{{ */
        if (swap_used < 0.0)
                return (EINVAL);
 
-       swap_submit_usage (NULL, swap_used, swap_free,
-                       isnan (swap_cached) ? NULL : "cached", swap_cached);
+       swap_submit_usage (NULL, swap_used * 1024.0, swap_free * 1024.0,
+                       isnan (swap_cached) ? NULL : "cached",
+                       isnan (swap_cached) ? NAN : swap_cached * 1024.0);
        return (0);
 } /* }}} int swap_read_combined */
 
index 9ff0d0b..480715f 100644 (file)
@@ -341,6 +341,8 @@ static int ctail_init (void)
     return (-1);
   }
 
+  memset(&ud, '\0', sizeof(ud));
+
   for (i = 0; i < tail_match_list_num; i++)
   {
     ud.data = (void *)tail_match_list[i];
index 61eeee3..41ed980 100644 (file)
@@ -106,7 +106,10 @@ static int tcsv_read_metric (instance_definition_t *id,
     if (md->data_source_type == -1)
         return (EINVAL);
 
-    if ((md->value_from >= fields_num) || (id->time_from >= fields_num))
+    if (md->value_from >= fields_num)
+        return (EINVAL);
+
+    if (id->time_from >= 0 && (id->time_from >= fields_num))
         return (EINVAL);
 
     t = 0;
@@ -374,37 +377,42 @@ static void tcsv_instance_definition_destroy(void *arg){
     sfree(id);
 }
 
-static int tcsv_config_add_instance_collect(instance_definition_t *id, oconfig_item_t *ci){
+static int tcsv_config_add_instance_collect(instance_definition_t *id, oconfig_item_t *ci) {
     metric_definition_t *metric;
+    metric_definition_t **metric_list;
+    size_t metric_list_size;
     int i;
 
-    if (ci->values_num < 1){
+    if (ci->values_num < 1) {
         WARNING("tail_csv plugin: The `Collect' config option needs at least one argument.");
         return (-1);
     }
 
-    /* Verify string arguments */
-    for (i = 0; i < ci->values_num; ++i)
-        if (ci->values[i].type != OCONFIG_TYPE_STRING){
+    metric_list_size = id->metric_list_len + (size_t) ci->values_num;
+    metric_list = realloc (id->metric_list, sizeof (*id->metric_list) * metric_list_size);
+    if (metric_list == NULL)
+        return (-1);
+    id->metric_list = metric_list;
+
+    for (i = 0; i < ci->values_num; i++) {
+        char *metric_name;
+
+        if (ci->values[i].type != OCONFIG_TYPE_STRING) {
             WARNING("tail_csv plugin: All arguments to `Collect' must be strings.");
-            return (-1);
+            continue;
         }
+        metric_name = ci->values[i].value.string;
 
-    id->metric_list = (metric_definition_t **)malloc(sizeof(metric_definition_t *) * ci->values_num);
-    if (id->metric_list == NULL)
-        return (-1);
-
-    for (i = 0; i < ci->values_num; ++i){
         for (metric = metric_head; metric != NULL; metric = metric->next)
-            if (strcasecmp(ci->values[i].value.string, metric->name) == 0)
+            if (strcasecmp(metric_name, metric->name) == 0)
                 break;
 
-        if (metric == NULL){
-            WARNING("tail_csv plugin: `Collect' argument not found `%s'.", ci->values[i].value.string);
-            return (-1);
+        if (metric == NULL) {
+            WARNING ("tail_csv plugin: `Collect' argument not found `%s'.", metric_name);
+            continue;
         }
 
-        id->metric_list[i] = metric;
+        id->metric_list[id->metric_list_len] = metric;
         id->metric_list_len++;
     }
 
index 0236c9d..b6a3fdd 100644 (file)
@@ -419,18 +419,18 @@ static void conn_reset_port_entry (void)
     /* If this entry was created while reading the files (ant not when handling
      * the configuration) remove it now. */
     if ((pe->flags & (PORT_COLLECT_LOCAL
-           | PORT_COLLECT_REMOTE
-           | PORT_IS_LISTENING)) == 0)
+            | PORT_COLLECT_REMOTE
+            | PORT_IS_LISTENING)) == 0)
     {
       port_entry_t *next = pe->next;
 
       DEBUG ("tcpconns plugin: Removing temporary entry "
-         "for listening port %"PRIu16, pe->port);
+          "for listening port %"PRIu16, pe->port);
 
       if (prev == NULL)
-       port_list_head = next;
+        port_list_head = next;
       else
-       prev->next = next;
+        prev->next = next;
 
       sfree (pe);
       pe = next;
@@ -442,6 +442,7 @@ static void conn_reset_port_entry (void)
     memset (pe->count_remote, '\0', sizeof (pe->count_remote));
     pe->flags &= ~PORT_IS_LISTENING;
 
+    prev = pe;
     pe = pe->next;
   }
 } /* void conn_reset_port_entry */
index 10f34ee..139c976 100644 (file)
@@ -40,9 +40,6 @@
 #elif HAVE_UTMP_H
 # include <utmp.h>
 /* #endif HAVE_UTMP_H */
-
-#else
-# error "No applicable input method."
 #endif
 
 static void users_submit (gauge_t value)
index eefde96..6abfde1 100644 (file)
 # error "`struct udphdr' is unusable."
 #endif
 
+#if HAVE_NETINET_IP6_H && HAVE_STRUCT_IP6_EXT
+# define HAVE_IPV6 1
+#endif
+
 #include "utils_dns.h"
 
 /*
@@ -445,7 +449,7 @@ handle_udp(const struct udphdr *udp, int len)
     return 1;
 }
 
-#if HAVE_NETINET_IP6_H
+#if HAVE_IPV6
 static int
 handle_ipv6 (struct ip6_hdr *ipv6, int len)
 {
@@ -514,16 +518,16 @@ handle_ipv6 (struct ip6_hdr *ipv6, int len)
 
     return (1); /* Success */
 } /* int handle_ipv6 */
-/* #endif HAVE_NETINET_IP6_H */
+/* #endif HAVE_IPV6 */
 
-#else /* if !HAVE_NETINET_IP6_H */
+#else /* if !HAVE_IPV6 */
 static int
 handle_ipv6 (__attribute__((unused)) void *pkg,
        __attribute__((unused)) int len)
 {
     return (0);
 }
-#endif /* !HAVE_NETINET_IP6_H */
+#endif /* !HAVE_IPV6 */
 
 static int
 handle_ip(const struct ip *ip, int len)
index c3ccbe6..5e609e6 100644 (file)
@@ -155,8 +155,16 @@ static int vmem_read (void)
     if (strncmp ("nr_", key, strlen ("nr_")) == 0)
     {
       char *inst = key + strlen ("nr_");
-      value_t value = { .gauge = gauge };
-      submit_one (NULL, "vmpage_number", inst, value);
+      if (strcmp(inst, "dirtied") == 0 || strcmp(inst, "written") == 0)
+      {
+        value_t value = { .derive = counter };
+        submit_one (NULL, "vmpage_action", inst, value);
+      }
+      else
+      {
+        value_t value = { .gauge = gauge };
+        submit_one (NULL, "vmpage_number", inst, value);
+      }
     }
 
     /* 
index 22e30ab..02663c6 100644 (file)
@@ -106,7 +106,10 @@ static int wr_write (const data_set_t *ds, /* {{{ */
 
 #undef APPEND
 
+  status = format_values (value_ptr, value_size, ds, vl, /* store rates = */ 0);
   pthread_mutex_lock (&node->lock);
+  if (status != 0)
+    return (status);
 
   if (node->conn == NULL)
   {
index cb3869d..15eae6a 100644 (file)
  *   Dagobert Michelsen (forward-porting)
  **/
 
-#define _BSD_SOURCE
+#if HAVE_CONFIG_H
+# include "config.h"
+# undef HAVE_CONFIG_H
+#endif
+/* avoid procfs.h error "Cannot use procfs in the large file compilation environment" */
+#if !defined(_LP64) && _FILE_OFFSET_BITS == 64
+#  undef _FILE_OFFSET_BITS
+#  undef _LARGEFILE64_SOURCE
+#endif
 
 #include "collectd.h"
 #include "common.h"
@@ -60,20 +68,24 @@ zone_compare(const zoneid_t *a, const zoneid_t *b)
 }
 
 static int
-zone_read_procfile(char *pidstr, char *file, void *buf, size_t bufsize)
+zone_read_procfile(char const *pidstr, char const *name, void *buf, size_t bufsize)
 {
        int fd;
 
        char procfile[MAX_PROCFS_PATH];
-       (void)snprintf(procfile, sizeof(procfile), "/proc/%s/%s", pidstr, file);
+       (void)snprintf(procfile, sizeof(procfile), "/proc/%s/%s", pidstr, name);
        if ((fd = open(procfile, O_RDONLY)) == -1) {
                return (1);
        }
 
-       if (pread(fd, buf, bufsize, 0) != bufsize) {
+       if (sread(fd, buf, bufsize) != 0) {
+               char errbuf[1024];
+               ERROR ("zone plugin: Reading \"%s\" failed: %s", procfile,
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
                close(fd);
                return (1);
        }
+
        close(fd);
        return (0);
 }
@@ -143,7 +155,6 @@ zone_submit_values(c_avl_tree_t *tree)
 static c_avl_tree_t *
 zone_scandir(DIR *procdir)
 {
-       char         *pidstr;
        pid_t         pid;
        dirent_t     *direntp;
        psinfo_t      psinfo;
@@ -157,15 +168,17 @@ zone_scandir(DIR *procdir)
 
        rewinddir(procdir);
        while ((direntp = readdir(procdir))) {
-               pidstr = direntp->d_name;
+               char const *pidstr = direntp->d_name;
                if (pidstr[0] == '.')   /* skip "." and ".."  */
                        continue;
+
                pid = atoi(pidstr);
                if (pid == 0 || pid == 2 || pid == 3)
                        continue;       /* skip sched, pageout and fsflush */
-               if (zone_read_procfile(pidstr, "psinfo", &psinfo, 
-                                 sizeof(psinfo_t)) != 0)
+
+               if (zone_read_procfile(pidstr, "psinfo", &psinfo, sizeof(psinfo_t)) != 0)
                        continue;
+
                stats = zone_find_stats(tree, psinfo.pr_zoneid);
                if( stats ) {
                        stats->pctcpu += psinfo.pr_pctcpu;
@@ -175,7 +188,6 @@ zone_scandir(DIR *procdir)
        return(tree);
 }
 
-
 static int zone_read (void)
 {
        DIR          *procdir;