Merge remote branch 'origin/ff/modbus'
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Mon, 7 Feb 2011 07:46:04 +0000 (08:46 +0100)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Mon, 7 Feb 2011 07:46:04 +0000 (08:46 +0100)
20 files changed:
ChangeLog
configure.in
src/collectd.conf.in
src/collectd.conf.pod
src/common.c
src/configfile.c
src/configfile.h
src/dns.c
src/libcollectdclient/client.c
src/modbus.c
src/mysql.c
src/plugin.c
src/plugin.h
src/rrdcached.c
src/swap.c
src/teamspeak2.c
src/types.db
src/types_list.c
src/utils_dns.c
src/varnish.c

index 4f3b558..95a3e71 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -42,6 +42,8 @@ yyyy-mm-dd, Version 5.0.0
        * lpar plugin: New plugins for "logical partitions", a virtualization
          technique of POWER CPUs. Thanks to AurĂ©lien Reynaud for his code and
          patience.
+       * modbus plugin: Support for libmodbus 2.9.2 has been added and the
+         license has been changes to LGPLv2.1.
        * mysql plugin: Backwards compatibility code has been removed. The
          data sets used have been improved.
        * network plugin: The default buffer size has been increased to
index f6bb58b..8db24ca 100644 (file)
@@ -1407,7 +1407,7 @@ then
        fi
        AC_CHECK_HEADERS(credis.h,
        [with_libcredis="yes"],
-       [with_libcredis="no ('credis.h' not found)"])
+       [with_libcredis="no (credis.h not found)"])
 fi
 if test "x$with_libcredis" = "xyes"
 then
@@ -2129,7 +2129,7 @@ then
        $PKG_CONFIG --exists 'modbus' 2>/dev/null
        if test $? -ne 0
        then
-               with_libmodbus="no (pkg-config doesn't know library)"
+               with_libmodbus="no (pkg-config doesn't know modbus)"
        fi
 fi
 if test "x$with_libmodbus" = "xuse_pkgconfig"
@@ -2594,7 +2594,7 @@ then
        fi
        AC_CHECK_HEADERS(oping.h,
        [with_liboping="yes"],
-       [with_liboping="no ('oping.h' not found)"])
+       [with_liboping="no (oping.h not found)"])
 fi
 if test "x$with_liboping" = "xyes"
 then
@@ -2765,7 +2765,8 @@ then
 fi
 if test "x$with_libpcap" = "xyes"
 then
-       AC_CHECK_HEADERS(pcap-bpf.h)
+       AC_CHECK_HEADERS(pcap-bpf.h,,
+                        [with_libpcap="no (pcap-bpf.h not found)"])
 fi
 AM_CONDITIONAL(BUILD_WITH_LIBPCAP, test "x$with_libpcap" = "xyes")
 # }}}
@@ -3282,7 +3283,7 @@ then
        fi
        AC_CHECK_HEADERS(routeros_api.h,
        [with_librouteros="yes"],
-       [with_librouteros="no ('routeros_api.h' not found)"])
+       [with_librouteros="no (routeros_api.h not found)"])
 fi
 if test "x$with_librouteros" = "xyes"
 then
@@ -3481,7 +3482,7 @@ then
     if test "$?" != "0"
     then
       with_libstatgrab_pkg_config="no"
-      with_libstatgrab="no ($PKG_CONFIG doesn't know libstatgrab)"
+      with_libstatgrab="no (pkg-config doesn't know libstatgrab)"
       temp_result="not found"
     fi
     AC_MSG_RESULT([$temp_result])
@@ -3701,7 +3702,7 @@ then
        $PKG_CONFIG --exists 'libupsclient' 2>/dev/null
        if test $? -ne 0
        then
-               with_libupsclient="no (pkg-config doesn't know library)"
+               with_libupsclient="no (pkg-config doesn't know libupsclient)"
        fi
 fi
 if test "x$with_libupsclient" = "xuse_pkgconfig"
@@ -3926,7 +3927,7 @@ then
        $PKG_CONFIG --exists 'varnishapi' 2>/dev/null
        if test $? -ne 0
        then
-               with_libvarnish="no (pkg-config doesn't know library)"
+               with_libvarnish="no (pkg-config doesn't know varnishapi)"
        fi
 fi
 if test "x$with_libvarnish" = "xuse_pkgconfig"
@@ -3996,7 +3997,7 @@ then
        then
                with_libxml2="yes"
        else
-               with_libxml2="no (pkg-config doesn't know library)"
+               with_libxml2="no (pkg-config doesn't know libxml-2.0)"
        fi
 
        pkg-config --exists libvirt 2>/dev/null
@@ -4004,7 +4005,7 @@ then
        then
                with_libvirt="yes"
        else
-               with_libvirt="no (pkg-config doesn't know library)"
+               with_libvirt="no (pkg-config doesn't know libvirt)"
        fi
 fi
 if test "x$with_libxml2" = "xyes"
@@ -4121,7 +4122,7 @@ then
        $PKG_CONFIG --exists OpenIPMIpthread 2>/dev/null
        if test "$?" != "0"
        then
-               with_libopenipmipthread="no ($PKG_CONFIG doesn't know OpenIPMIpthread)"
+               with_libopenipmipthread="no (pkg-config doesn't know OpenIPMIpthread)"
        fi
        AC_MSG_RESULT([$with_libopenipmipthread])
 fi
@@ -4182,7 +4183,11 @@ fi
 
 PKG_CHECK_MODULES([LIBNOTIFY], [libnotify],
                [with_libnotify="yes"],
-               [with_libnotify="no ($LIBNOTIFY_PKG_ERRORS)"])
+               [if test "x$LIBNOTIFY_PKG_ERRORS" = "x"; then
+                        with_libnotify="no"
+                else
+                        with_libnotify="no ($LIBNOTIFY_PKG_ERRORS)"
+                fi])
 
 # Check for enabled/disabled features
 #
@@ -4469,8 +4474,11 @@ if test "x$have_sysctl" = "xyes"
 then
        plugin_cpu="yes"
        plugin_memory="yes"
-       plugin_swap="yes"
        plugin_uptime="yes"
+       if test "x$ac_system" = "xDarwin"
+       then
+               plugin_swap="yes"
+       fi
 fi
 if test "x$have_sysctlbyname" = "xyes"
 then
@@ -4562,7 +4570,7 @@ then
        plugin_swap="yes"
 fi
 
-if test "x$have_swapctl" = "xyes"
+if test "x$have_swapctl" = "xyes" && test "x$c_cv_have_swapctl_two_args" = "xyes"
 then
        plugin_swap="yes"
 fi
index 32a7582..94cf2a9 100644 (file)
 #<Plugin hddtemp>
 #  Host "127.0.0.1"
 #  Port "7634"
-#
-#  #----------------------------------------------------------------#
-#  # `TranslateDevicename' enables backwards compatibility behavior #
-#  # and is enabled by default. Setting this option to `false' is   #
-#  # highly recommended.                                            #
-#  #----------------------------------------------------------------#
-#  TranslateDevicename false
 #</Plugin>
 
 #<Plugin interface>
 #   </Host>
 #</Plugin>
 
+#<Plugin "swap">
+#      ReportByDevice false
+#</Plugin>
+
 #<Plugin "table">
 #      <Table "/proc/slabinfo">
 #              Instance "slabinfo"
index e91730e..ed979c4 100644 (file)
@@ -4172,19 +4172,19 @@ L<collectd-snmp(5)>. Please see there for details.
 =head2 Plugin C<swap>
 
 The I<Swap plugin> collects information about used and available swap space. On
-I<Solaris>, the following options are available:
+I<Linux> and I<Solaris>, the following options are available:
 
 =over 4
 
 =item B<ReportByDevice> B<false>|B<true>
 
-Configures how to report physical swap devices. If set to B<false> is used (the
+Configures how to report physical swap devices. If set to B<false> (the
 default), the summary over all swap devices is reported only, i.e. the globally
 used and available space over all devices. If B<true> is configured, the used
 and available space of each device will be reported separately.
 
-This option is only available if the I<Swap plugin> can use the L<swapctl(2)>
-mechanism under I<Solaris>.
+This option is only available if the I<Swap plugin> can read C</proc/swaps>
+(under Linux) or use the L<swapctl(2)> mechanism (under I<Solaris>).
 
 =back
 
index 142d797..6fdb441 100644 (file)
 # include <math.h>
 #endif
 
-/* for ntohl and htonl */
-#if HAVE_ARPA_INET_H
-# include <arpa/inet.h>
-#endif
-
 /* for getaddrinfo */
 #include <sys/types.h>
 #include <sys/socket.h>
 # include <netinet/in.h>
 #endif
 
+/* for ntohl and htonl */
+#if HAVE_ARPA_INET_H
+# include <arpa/inet.h>
+#endif
+
 #ifdef HAVE_LIBKSTAT
 extern kstat_ctl_t *kc;
 #endif
index 33a7c20..7c8347b 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * collectd - src/configfile.c
- * Copyright (C) 2005-2010  Florian octo Forster
+ * Copyright (C) 2005-2011  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
@@ -17,7 +17,7 @@
  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  *   Sebastian tokkee Harl <sh at tokkee.org>
  **/
 
@@ -1058,19 +1058,40 @@ int cf_util_get_flag (const oconfig_item_t *ci, /* {{{ */
        return (0);
 } /* }}} int cf_util_get_flag */
 
-/* Assures that the config option is a string. The string is then converted to
- * a port number using `service_name_to_port_number' and returned. Returns the
- * port number in the range [1-65535] or less than zero upon failure. */
+/* Assures that the config option is a string or a number if the correct range
+ * of 1-65535. The string is then converted to a port number using
+ * `service_name_to_port_number' and returned.
+ * Returns the port number in the range [1-65535] or less than zero upon
+ * failure. */
 int cf_util_get_port_number (const oconfig_item_t *ci) /* {{{ */
 {
-       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
+       int tmp;
+
+       if ((ci->values_num != 1)
+                       || ((ci->values[0].type != OCONFIG_TYPE_STRING)
+                               && (ci->values[0].type != OCONFIG_TYPE_NUMBER)))
        {
-               ERROR ("cf_util_get_port_number: The %s option requires "
+               ERROR ("cf_util_get_port_number: The \"%s\" option requires "
                                "exactly one string argument.", ci->key);
                return (-1);
        }
 
-       return (service_name_to_port_number (ci->values[0].value.string));
+       if (ci->values[0].type == OCONFIG_TYPE_STRING)
+               return (service_name_to_port_number (ci->values[0].value.string));
+
+       assert (ci->values[0].type == OCONFIG_TYPE_NUMBER);
+       tmp = (int) (ci->values[0].value.number + 0.5);
+       if ((tmp < 1) || (tmp > 65535))
+       {
+               ERROR ("cf_util_get_port_number: The \"%s\" option requires "
+                               "a service name or a port number. The number "
+                               "you specified, %i, is not in the valid "
+                               "range of 1-65535.",
+                               ci->key, tmp);
+               return (-1);
+       }
+
+       return (tmp);
 } /* }}} int cf_util_get_port_number */
 
 int cf_util_get_cdtime (const oconfig_item_t *ci, cdtime_t *ret_value) /* {{{ */
index 65b1efc..e63a0ea 100644 (file)
@@ -2,7 +2,7 @@
 #define CONFIGFILE_H
 /**
  * collectd - src/configfile.h
- * Copyright (C) 2005-2010  Florian octo Forster
+ * Copyright (C) 2005-2011  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
@@ -19,7 +19,7 @@
  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
@@ -109,9 +109,11 @@ int cf_util_get_boolean (const oconfig_item_t *ci, _Bool *ret_bool);
 int cf_util_get_flag (const oconfig_item_t *ci,
                unsigned int *ret_value, unsigned int flag);
 
-/* Assures that the config option is a string. The string is then converted to
- * a port number using `service_name_to_port_number' and returned. Returns the
- * port number in the range [1-65535] or less than zero upon failure. */
+/* Assures that the config option is a string or a number if the correct range
+ * of 1-65535. The string is then converted to a port number using
+ * `service_name_to_port_number' and returned.
+ * Returns the port number in the range [1-65535] or less than zero upon
+ * failure. */
 int cf_util_get_port_number (const oconfig_item_t *ci);
 
 int cf_util_get_cdtime (const oconfig_item_t *ci, cdtime_t *ret_value);
index 09082fc..95797f5 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -33,9 +33,7 @@
 #include <poll.h>
 
 #include <pcap.h>
-#if HAVE_PCAP_BPF_H
-# include <pcap-bpf.h>
-#endif
+#include <pcap-bpf.h>
 
 /*
  * Private data types
index 75ac7b6..3eb0d05 100644 (file)
@@ -164,27 +164,14 @@ static int lcc_set_errno (lcc_connection_t *c, int err) /* {{{ */
   return (0);
 } /* }}} int lcc_set_errno */
 
-/* lcc_strdup: Since `strdup' is an XSI extension, we provide our own version
- * here. */
-__attribute__((malloc, nonnull (1)))
-static char *lcc_strdup (const char *str) /* {{{ */
-{
-  size_t strsize;
-  char *ret;
-
-  strsize = strlen (str) + 1;
-  ret = (char *) malloc (strsize);
-  if (ret != NULL)
-    memcpy (ret, str, strsize);
-  return (ret);
-} /* }}} char *lcc_strdup */
-
-__attribute__((nonnull (1, 2)))
 static char *lcc_strescape (char *dest, const char *src, size_t dest_size) /* {{{ */
 {
   size_t dest_pos;
   size_t src_pos;
 
+  if ((dest == NULL) || (src == NULL))
+    return (NULL);
+
   dest_pos = 0;
   src_pos = 0;
 
@@ -338,7 +325,7 @@ static int lcc_receive (lcc_connection_t *c, /* {{{ */
     lcc_chomp (buffer);
     LCC_DEBUG ("receive: <-- %s\n", buffer);
 
-    res.lines[i] = lcc_strdup (buffer);
+    res.lines[i] = strdup (buffer);
     if (res.lines[i] == NULL)
     {
       lcc_set_errno (c, ENOMEM);
@@ -733,7 +720,7 @@ int lcc_getval (lcc_connection_t *c, lcc_identifier_t *ident, /* {{{ */
 
     if (values_names != NULL)
     {
-      values_names[i] = lcc_strdup (key);
+      values_names[i] = strdup (key);
       if (values_names[i] == NULL)
         BAIL_OUT (ENOMEM);
     }
@@ -1013,7 +1000,7 @@ int lcc_string_to_identifier (lcc_connection_t *c, /* {{{ */
   char *type;
   char *type_instance;
 
-  string_copy = lcc_strdup (string);
+  string_copy = strdup (string);
   if (string_copy == NULL)
   {
     lcc_set_errno (c, ENOMEM);
index a14cced..19848b0 100644 (file)
@@ -3,17 +3,18 @@
  * Copyright (C) 2010,2011  noris network AG
  *
  * 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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; only version 2.1 of the License is
+ * applicable.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
  * Authors:
  *   Florian Forster <octo at noris.net>
index f4ad01c..cae6760 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * collectd - src/mysql.c
- * Copyright (C) 2006-2009  Florian octo Forster
+ * Copyright (C) 2006-2010  Florian octo Forster
  * Copyright (C) 2008       Mirko Buffoni
  * Copyright (C) 2009       Doug MacEachern
  * Copyright (C) 2009       Sebastian tokkee Harl
@@ -20,7 +20,7 @@
  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  *   Mirko Buffoni <briareos at eswat.org>
  *   Doug MacEachern <dougm at hyperic.com>
  *   Sebastian tokkee Harl <sh at tokkee.org>
index 0f360c0..9ecee5c 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * collectd - src/plugin.c
- * Copyright (C) 2005-2010  Florian octo Forster
+ * Copyright (C) 2005-2011  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
@@ -728,6 +728,17 @@ static int plugin_insert_read (read_func_t *rf)
                }
        }
 
+       le = llist_search (read_list, rf->rf_name);
+       if (le != NULL)
+       {
+               pthread_mutex_unlock (&read_lock);
+               WARNING ("The read function \"%s\" is already registered. "
+                               "Check for duplicate \"LoadPlugin\" lines "
+                               "in your configuration!",
+                               rf->rf_name);
+               return (EINVAL);
+       }
+
        le = llentry_create (rf->rf_name, rf);
        if (le == NULL)
        {
@@ -756,14 +767,13 @@ int plugin_register_read (const char *name,
                int (*callback) (void))
 {
        read_func_t *rf;
+       int status;
 
-       rf = (read_func_t *) malloc (sizeof (read_func_t));
+       rf = malloc (sizeof (*rf));
        if (rf == NULL)
        {
-               char errbuf[1024];
-               ERROR ("plugin_register_read: malloc failed: %s",
-                               sstrerror (errno, errbuf, sizeof (errbuf)));
-               return (-1);
+               ERROR ("plugin_register_read: malloc failed.");
+               return (ENOMEM);
        }
 
        memset (rf, 0, sizeof (read_func_t));
@@ -777,7 +787,11 @@ int plugin_register_read (const char *name,
        rf->rf_interval.tv_nsec = 0;
        rf->rf_effective_interval = rf->rf_interval;
 
-       return (plugin_insert_read (rf));
+       status = plugin_insert_read (rf);
+       if (status != 0)
+               sfree (rf);
+
+       return (status);
 } /* int plugin_register_read */
 
 int plugin_register_complex_read (const char *group, const char *name,
@@ -786,12 +800,13 @@ int plugin_register_complex_read (const char *group, const char *name,
                user_data_t *user_data)
 {
        read_func_t *rf;
+       int status;
 
-       rf = (read_func_t *) malloc (sizeof (read_func_t));
+       rf = malloc (sizeof (*rf));
        if (rf == NULL)
        {
                ERROR ("plugin_register_complex_read: malloc failed.");
-               return (-1);
+               return (ENOMEM);
        }
 
        memset (rf, 0, sizeof (read_func_t));
@@ -819,7 +834,11 @@ int plugin_register_complex_read (const char *group, const char *name,
                rf->rf_udata = *user_data;
        }
 
-       return (plugin_insert_read (rf));
+       status = plugin_insert_read (rf);
+       if (status != 0)
+               sfree (rf);
+
+       return (status);
 } /* int plugin_register_complex_read */
 
 int plugin_register_write (const char *name,
index 937eebe..4d5201b 100644 (file)
@@ -269,6 +269,8 @@ int plugin_register_init (const char *name,
                plugin_init_cb callback);
 int plugin_register_read (const char *name,
                int (*callback) (void));
+/* "user_data" will be freed automatically, unless
+ * "plugin_register_complex_read" returns an error (non-zero). */
 int plugin_register_complex_read (const char *group, const char *name,
                plugin_read_cb callback,
                const struct timespec *interval,
index fb7eb79..3099421 100644 (file)
@@ -328,7 +328,7 @@ static int rc_init (void)
 static int rc_write (const data_set_t *ds, const value_list_t *vl,
     user_data_t __attribute__((unused)) *user_data)
 {
-  char filename[512];
+  char filename[PATH_MAX];
   char values[512];
   char *values_array[2];
   int status;
@@ -406,6 +406,41 @@ static int rc_write (const data_set_t *ds, const value_list_t *vl,
   return (0);
 } /* int rc_write */
 
+static int rc_flush (__attribute__((unused)) cdtime_t timeout, /* {{{ */
+    const char *identifier,
+    __attribute__((unused)) user_data_t *ud)
+{
+  char filename[PATH_MAX + 1];
+  int status;
+
+  if (identifier == NULL)
+    return (EINVAL);
+
+  if (datadir != NULL)
+    ssnprintf (filename, sizeof (filename), "%s/%s.rrd", datadir, identifier);
+  else
+    ssnprintf (filename, sizeof (filename), "%s.rrd", identifier);
+
+  status = rrdc_connect (daemon_address);
+  if (status != 0)
+  {
+    ERROR ("rrdcached plugin: rrdc_connect (%s) failed with status %i.",
+        daemon_address, status);
+    return (-1);
+  }
+
+  status = rrdc_flush (filename);
+  if (status != 0)
+  {
+    ERROR ("rrdcached plugin: rrdc_flush (%s) failed with status %i.",
+        filename, status);
+    return (-1);
+  }
+  DEBUG ("rrdcached plugin: rrdc_flush (%s): Success.", filename);
+
+  return (0);
+} /* }}} int rc_flush */
+
 static int rc_shutdown (void)
 {
   rrdc_disconnect ();
@@ -418,6 +453,7 @@ void module_register (void)
       config_keys, config_keys_num);
   plugin_register_init ("rrdcached", rc_init);
   plugin_register_write ("rrdcached", rc_write, /* user_data = */ NULL);
+  plugin_register_flush ("rrdcached", rc_flush, /* user_data = */ NULL);
   plugin_register_shutdown ("rrdcached", rc_shutdown);
 } /* void module_register */
 
index 629d1a1..a20087d 100644 (file)
 #define MAX(x,y) ((x) > (y) ? (x) : (y))
 
 #if KERNEL_LINUX
+# define SWAP_HAVE_CONFIG 1
 /* No global variables */
 /* #endif KERNEL_LINUX */
 
 #elif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS
+# define SWAP_HAVE_CONFIG 1
 static derive_t pagesize;
-
-static const char *config_keys[] =
-{
-       "ReportByDevice"
-};
-static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
-
-static _Bool report_by_device = 0;
 /* #endif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS */
 
 #elif defined(VM_SWAPUSAGE)
@@ -107,7 +101,34 @@ static perfstat_memory_total_t pmemory;
 # error "No applicable input method."
 #endif /* HAVE_LIBSTATGRAB */
 
-static int swap_init (void)
+#if SWAP_HAVE_CONFIG
+static const char *config_keys[] =
+{
+       "ReportByDevice"
+};
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+
+static _Bool report_by_device = 0;
+
+static int swap_config (const char *key, const char *value) /* {{{ */
+{
+       if (strcasecmp ("ReportByDevice", key) == 0)
+       {
+               if (IS_TRUE (value))
+                       report_by_device = 1;
+               else
+                       report_by_device = 0;
+       }
+       else
+       {
+               return (-1);
+       }
+
+       return (0);
+} /* }}} int swap_config */
+#endif /* SWAP_HAVE_CONFIG */
+
+static int swap_init (void) /* {{{ */
 {
 #if KERNEL_LINUX
        /* No init stuff */
@@ -152,102 +173,189 @@ static int swap_init (void)
 #endif /* HAVE_PERFSTAT */
 
        return (0);
-}
+} /* }}} int swap_init */
 
-static void swap_submit_inst (const char *plugin_instance, /* {{{ */
-               const char *type_instance, derive_t value, unsigned type)
+static void swap_submit (const char *plugin_instance, /* {{{ */
+               const char *type, const char *type_instance,
+               value_t value)
 {
-       value_t values[1];
        value_list_t vl = VALUE_LIST_INIT;
 
-       switch (type)
-       {
-               case DS_TYPE_GAUGE:
-                       values[0].gauge = (gauge_t) value;
-                       sstrncpy (vl.type, "swap", sizeof (vl.type));
-                       break;
-               case DS_TYPE_DERIVE:
-                       values[0].derive = value;
-                       sstrncpy (vl.type, "swap_io", sizeof (vl.type));
-                       break;
-               default:
-                       ERROR ("swap plugin: swap_submit called with wrong"
-                               " type");
-       }
+       assert (type != NULL);
 
-       vl.values = values;
+       vl.values = &value;
        vl.values_len = 1;
        sstrncpy (vl.host, hostname_g, sizeof (vl.host));
        sstrncpy (vl.plugin, "swap", sizeof (vl.plugin));
        if (plugin_instance != NULL)
                sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
-       sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+       sstrncpy (vl.type, type, sizeof (vl.type));
+       if (type_instance != NULL)
+               sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
 
        plugin_dispatch_values (&vl);
 } /* }}} void swap_submit_inst */
 
-static void swap_submit (const char *type_instance, derive_t value, unsigned type)
+static void swap_submit_gauge (const char *plugin_instance, /* {{{ */
+               const char *type_instance, gauge_t value)
+{
+       value_t v;
+
+       v.gauge = value;
+       swap_submit (plugin_instance, "swap", type_instance, v);
+} /* }}} void swap_submit_gauge */
+
+static void swap_submit_derive (const char *plugin_instance, /* {{{ */
+               const char *type_instance, derive_t value)
 {
-       swap_submit_inst (/* plugin instance = */ NULL,
-                       type_instance, value, type);
-}
+       value_t v;
+
+       v.derive = value;
+       swap_submit (plugin_instance, "swap_io", type_instance, v);
+} /* }}} void swap_submit_derive */
+
 
 #if KERNEL_LINUX
-static int swap_read (void) /* {{{ */
+static int swap_read_separate (void) /* {{{ */
 {
        FILE *fh;
        char buffer[1024];
 
-       char *fields[8];
-       int numfields;
+       fh = fopen ("/proc/swaps", "r");
+       if (fh == NULL)
+       {
+               char errbuf[1024];
+               WARNING ("swap plugin: fopen (/proc/swaps) failed: %s",
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
+               return (-1);
+       }
+
+       while (fgets (buffer, sizeof (buffer), fh) != NULL)
+       {
+               char *fields[8];
+               int numfields;
+               char *endptr;
+
+               char path[PATH_MAX];
+               gauge_t size;
+               gauge_t used;
+               gauge_t free;
+
+               numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
+               if (numfields != 5)
+                       continue;
+
+               sstrncpy (path, fields[0], sizeof (path));
+               escape_slashes (path, sizeof (path));
+
+               errno = 0;
+               endptr = NULL;
+               size = strtod (fields[2], &endptr);
+               if ((endptr == fields[2]) || (errno != 0))
+                       continue;
+
+               errno = 0;
+               endptr = NULL;
+               used = strtod (fields[3], &endptr);
+               if ((endptr == fields[3]) || (errno != 0))
+                       continue;
+
+               if (size < used)
+                       continue;
+
+               free = size - used;
+
+               swap_submit_gauge (path, "used", used);
+               swap_submit_gauge (path, "free", free);
+       }
 
-       _Bool old_kernel=0;
+       fclose (fh);
 
-       derive_t swap_used   = 0;
-       derive_t swap_cached = 0;
-       derive_t swap_free   = 0;
-       derive_t swap_total  = 0;
-       derive_t swap_in     = 0;
-       derive_t swap_out    = 0;
+       return (0);
+} /* }}} int swap_read_separate */
 
-       if ((fh = fopen ("/proc/meminfo", "r")) == NULL)
+static int swap_read_combined (void) /* {{{ */
+{
+       FILE *fh;
+       char buffer[1024];
+
+       uint8_t have_data = 0;
+       gauge_t swap_used   = 0.0;
+       gauge_t swap_cached = 0.0;
+       gauge_t swap_free   = 0.0;
+       gauge_t swap_total  = 0.0;
+
+       fh = fopen ("/proc/meminfo", "r");
+       if (fh == NULL)
        {
                char errbuf[1024];
-               WARNING ("memory: fopen: %s",
+               WARNING ("swap plugin: fopen (/proc/meminfo) failed: %s",
                                sstrerror (errno, errbuf, sizeof (errbuf)));
                return (-1);
        }
 
        while (fgets (buffer, sizeof (buffer), fh) != NULL)
        {
+               char *fields[8];
+               int numfields;
+
                numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
                if (numfields < 2)
                        continue;
 
                if (strcasecmp (fields[0], "SwapTotal:") == 0)
-                       strtoderive (fields[1], &swap_total);
+               {
+                       swap_total = strtod (fields[1], /* endptr = */ NULL);
+                       have_data |= 0x01;
+               }
                else if (strcasecmp (fields[0], "SwapFree:") == 0)
-                       strtoderive (fields[1], &swap_free);
+               {
+                       swap_free = strtod (fields[1], /* endptr = */ NULL);
+                       have_data |= 0x02;
+               }
                else if (strcasecmp (fields[0], "SwapCached:") == 0)
-                       strtoderive (fields[1], &swap_cached);
+               {
+                       swap_cached = strtod (fields[1], /* endptr = */ NULL);
+                       have_data |= 0x04;
+               }
        }
 
-       if (fclose (fh))
-       {
-               char errbuf[1024];
-               WARNING ("memory: fclose: %s",
-                               sstrerror (errno, errbuf, sizeof (errbuf)));
-       }
+       fclose (fh);
 
-       if ((swap_total == 0LL) || ((swap_free + swap_cached) > swap_total))
-               return (-1);
+       if (have_data != 0x07)
+               return (ENOENT);
+
+       if (isnan (swap_total)
+                       || (swap_total <= 0.0)
+                       || ((swap_free + swap_cached) > swap_total))
+               return (EINVAL);
 
        swap_used = swap_total - (swap_free + swap_cached);
 
-       if ((fh = fopen ("/proc/vmstat", "r")) == NULL)
+       swap_submit_gauge (NULL, "used",   1024.0 * swap_used);
+       swap_submit_gauge (NULL, "free",   1024.0 * swap_free);
+       swap_submit_gauge (NULL, "cached", 1024.0 * swap_cached);
+
+       return (0);
+} /* }}} int swap_read_combined */
+
+static int swap_read_io (void) /* {{{ */
+{
+       FILE *fh;
+       char buffer[1024];
+
+       _Bool old_kernel = 0;
+
+       uint8_t have_data = 0;
+       derive_t swap_in  = 0;
+       derive_t swap_out = 0;
+
+       fh = fopen ("/proc/vmstat", "r");
+       if (fh == NULL)
        {
-               // /proc/vmstat does not exist in kernels <2.6
-               if ((fh = fopen ("/proc/stat", "r")) == NULL )
+               /* /proc/vmstat does not exist in kernels <2.6 */
+               fh = fopen ("/proc/stat", "r");
+               if (fh == NULL)
                {
                        char errbuf[1024];
                        WARNING ("swap: fopen: %s",
@@ -260,6 +368,9 @@ static int swap_read (void) /* {{{ */
 
        while (fgets (buffer, sizeof (buffer), fh) != NULL)
        {
+               char *fields[8];
+               int numfields;
+
                numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
 
                if (!old_kernel)
@@ -268,9 +379,15 @@ static int swap_read (void) /* {{{ */
                                continue;
 
                        if (strcasecmp ("pswpin", fields[0]) == 0)
+                       {
                                strtoderive (fields[1], &swap_in);
+                               have_data |= 0x01;
+                       }
                        else if (strcasecmp ("pswpout", fields[0]) == 0)
+                       {
                                strtoderive (fields[1], &swap_out);
+                               have_data |= 0x02;
+                       }
                }
                else /* if (old_kernel) */
                {
@@ -285,18 +402,25 @@ static int swap_read (void) /* {{{ */
                }
        } /* while (fgets) */
 
-       if (fclose (fh))
-       {
-               char errbuf[1024];
-               WARNING ("swap: fclose: %s",
-                               sstrerror (errno, errbuf, sizeof (errbuf)));
-       }
+       fclose (fh);
+
+       if (have_data != 0x03)
+               return (ENOENT);
+
+       swap_submit_derive (NULL, "in",  swap_in);
+       swap_submit_derive (NULL, "out", swap_out);
+
+       return (0);
+} /* }}} int swap_read_io */
 
-       swap_submit ("used",   1024 * swap_used,   DS_TYPE_GAUGE);
-       swap_submit ("free",   1024 * swap_free,   DS_TYPE_GAUGE);
-       swap_submit ("cached", 1024 * swap_cached, DS_TYPE_GAUGE);
-       swap_submit ("in",  swap_in,  DS_TYPE_DERIVE);
-       swap_submit ("out", swap_out, DS_TYPE_DERIVE);
+static int swap_read (void) /* {{{ */
+{
+       if (report_by_device)
+               swap_read_separate ();
+       else
+               swap_read_combined ();
+
+       swap_read_io ();
 
        return (0);
 } /* }}} int swap_read */
@@ -355,9 +479,9 @@ static int swap_read_kstat (void) /* {{{ */
                        * pagesize);
        swap_avail  = (derive_t) ((ai.ani_max - ai.ani_resv) * pagesize);
 
-       swap_submit ("used", swap_alloc, DS_TYPE_GAUGE);
-       swap_submit ("free", swap_avail, DS_TYPE_GAUGE);
-       swap_submit ("reserved", swap_resv, DS_TYPE_GAUGE);
+       swap_submit_gauge (NULL, "used", swap_alloc);
+       swap_submit_gauge (NULL, "free", swap_avail);
+       swap_submit_gauge (NULL, "reserved", swap_resv);
 
        return (0);
 } /* }}} int swap_read_kstat */
@@ -454,25 +578,11 @@ static int swap_read (void) /* {{{ */
                        continue;
                }
 
-               /* Okay, using "/" as swap device would be super-weird, but
-                * we'll handle it anyway to cover all cases. */
-               if (strcmp ("/", s->swt_ent[i].ste_path) == 0)
-                       sstrncpy (path, "root", sizeof (path));
-               else
-               {
-                       int j;
-
-                       s->swt_ent[i].ste_path[PATH_MAX - 1] = 0;
-                       /* Don't copy the leading slash */
-                       sstrncpy (path, &s->swt_ent[i].ste_path[1], sizeof (path));
-                       /* Convert slashes to dashes, just like the "df" plugin. */
-                       for (j = 0; path[j] != 0; j++)
-                               if (path[j] == '/')
-                                       path[j] = '-';
-               }
+               sstrncpy (path, s->swt_ent[i].ste_path, sizeof (path));
+               escape_slashes (path, sizeof (path));
 
-               swap_submit_inst (path, "used", this_total - this_avail, DS_TYPE_GAUGE);
-               swap_submit_inst (path, "free", this_avail, DS_TYPE_GAUGE);
+               swap_submit_gauge (path, "used", (gauge_t) (this_total - this_avail));
+               swap_submit_gauge (path, "free", (gauge_t) this_avail);
         } /* for (swap_num) */
 
         if (total < avail)
@@ -489,32 +599,14 @@ static int swap_read (void) /* {{{ */
         * values have already been dispatched from within the loop. */
        if (!report_by_device)
        {
-               swap_submit ("used", total - avail, DS_TYPE_GAUGE);
-               swap_submit ("free", avail, DS_TYPE_GAUGE);
+               swap_submit_gauge (NULL, "used", (gauge_t) (total - avail));
+               swap_submit_gauge (NULL, "free", (gauge_t) avail);
        }
 
        sfree (s_paths);
         sfree (s);
        return (0);
 } /* }}} int swap_read */
-
-/* Configuration: Present when swapctl or both methods are available. */
-static int swap_config (const char *key, const char *value) /* {{{ */
-{
-       if (strcasecmp ("ReportByDevice", key) == 0)
-       {
-               if (IS_TRUE (value))
-                       report_by_device = 1;
-               else
-                       report_by_device = 0;
-       }
-       else
-       {
-               return (-1);
-       }
-
-       return (0);
-} /* }}} int swap_config */
 /* #endif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS */
 
 #elif HAVE_SWAPCTL && HAVE_SWAPCTL_THREE_ARGS
@@ -579,8 +671,8 @@ static int swap_read (void) /* {{{ */
                return (-1);
        }
 
-       swap_submit ("used", used, DS_TYPE_GAUGE);
-       swap_submit ("free", total - used, DS_TYPE_GAUGE);
+       swap_submit_gauge (NULL, "used", (gauge_t) used);
+       swap_submit_gauge (NULL, "free", (gauge_t) (total - used));
 
        sfree (swap_entries);
 
@@ -606,8 +698,8 @@ static int swap_read (void) /* {{{ */
                return (-1);
 
        /* The returned values are bytes. */
-       swap_submit ("used", (derive_t) sw_usage.xsu_used, DS_TYPE_GAUGE);
-       swap_submit ("free", (derive_t) sw_usage.xsu_avail, DS_TYPE_GAUGE);
+       swap_submit_gauge (NULL, "used", (gauge_t) sw_usage.xsu_used);
+       swap_submit_gauge (NULL, "free", (gauge_t) sw_usage.xsu_avail);
 
        return (0);
 } /* }}} int swap_read */
@@ -639,8 +731,8 @@ static int swap_read (void) /* {{{ */
 
        free = total - used;
 
-       swap_submit ("used", used, DS_TYPE_GAUGE);
-       swap_submit ("free", free, DS_TYPE_GAUGE);
+       swap_submit_gauge (NULL, "used", (gauge_t) used);
+       swap_submit_gauge (NULL, "free", (gauge_t) free);
 
        return (0);
 } /* }}} int swap_read */
@@ -656,8 +748,8 @@ static int swap_read (void) /* {{{ */
        if (swap == NULL)
                return (-1);
 
-       swap_submit ("used", (derive_t) swap->used, DS_TYPE_GAUGE);
-       swap_submit ("free", (derive_t) swap->free, DS_TYPE_GAUGE);
+       swap_submit_gauge (NULL, "used", (gauge_t) swap->used);
+       swap_submit_gauge (NULL, "free", (gauge_t) swap->free);
 
        return (0);
 } /* }}} int swap_read */
@@ -673,8 +765,8 @@ static int swap_read (void) /* {{{ */
                         sstrerror (errno, errbuf, sizeof (errbuf)));
                 return (-1);
         }
-       swap_submit ("used", (derive_t) (pmemory.pgsp_total - pmemory.pgsp_free) * pagesize, DS_TYPE_GAUGE);
-       swap_submit ("free", (derive_t) pmemory.pgsp_free * pagesize , DS_TYPE_GAUGE);
+       swap_submit_gauge (NULL, "used", (gauge_t) (pmemory.pgsp_total - pmemory.pgsp_free) * pagesize);
+       swap_submit_gauge (NULL, "free", (gauge_t) pmemory.pgsp_free * pagesize );
 
        return (0);
 } /* }}} int swap_read */
@@ -682,7 +774,7 @@ static int swap_read (void) /* {{{ */
 
 void module_register (void)
 {
-#if HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS
+#if SWAP_HAVE_CONFIG
        plugin_register_config ("swap", swap_config, config_keys, config_keys_num);
 #endif
        plugin_register_init ("swap", swap_init);
index 7528406..a78e700 100644 (file)
@@ -25,8 +25,8 @@
 #include "common.h"
 #include "plugin.h"
 
-#include <arpa/inet.h>
 #include <netinet/in.h>
+#include <arpa/inet.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netdb.h>
index 6d0b57a..e6345ab 100644 (file)
@@ -4,11 +4,6 @@ apache_connections     value:GAUGE:0:65535
 apache_idle_workers    value:GAUGE:0:65535
 apache_requests                value:DERIVE:0:U
 apache_scoreboard      value:GAUGE:0:65535
-arc_counts             demand_data:DERIVE:0:U, demand_metadata:DERIVE:0:U, prefetch_data:DERIVE:0:U, prefetch_metadata:DERIVE:0:U
-arc_l2_bytes           read:DERIVE:0:U, write:DERIVE:0:U
-arc_l2_size            value:GAUGE:0:U
-arc_ratio              value:GAUGE:0:U
-arc_size               current:GAUGE:0:U, target:GAUGE:0:U, minlimit:GAUGE:0:U, maxlimit:GAUGE:0:U
 ath_nodes              value:GAUGE:0:65535
 ath_stat               value:DERIVE:0:U
 bitrate                        value:GAUGE:0:4294967295
@@ -179,3 +174,14 @@ voltage                    value:GAUGE:U:U
 vs_memory              value:GAUGE:0:9223372036854775807
 vs_processes           value:GAUGE:0:65535
 vs_threads             value:GAUGE:0:65535
+#
+# Legacy types
+# (required for the v5 upgrade target)
+#
+arc_counts             demand_data:COUNTER:0:U, demand_metadata:COUNTER:0:U, prefetch_data:COUNTER:0:U, prefetch_metadata:COUNTER:0:U
+arc_l2_bytes           read:COUNTER:0:U, write:COUNTER:0:U
+arc_l2_size            value:GAUGE:0:U
+arc_ratio              value:GAUGE:0:U
+arc_size               current:GAUGE:0:U, target:GAUGE:0:U, minlimit:GAUGE:0:U, maxlimit:GAUGE:0:U
+mysql_qcache           hits:COUNTER:0:U, inserts:COUNTER:0:U, not_cached:COUNTER:0:U, lowmem_prunes:COUNTER:0:U, queries_in_cache:GAUGE:0:U
+mysql_threads          running:GAUGE:0:U, connected:GAUGE:0:U, cached:GAUGE:0:U, created:COUNTER:0:U
index 4971417..10cb4f2 100644 (file)
@@ -102,6 +102,10 @@ static void parse_line (char *buf)
   if (fields_num < 2)
     return;
 
+  /* Ignore lines which begin with a hash sign. */
+  if (fields[0][0] == '#')
+    return;
+
   ds = (data_set_t *) malloc (sizeof (data_set_t));
   if (ds == NULL)
     return;
index 22c9b95..d1c8d5d 100644 (file)
@@ -441,6 +441,7 @@ handle_udp(const struct udphdr *udp, int len)
     return 1;
 }
 
+#if HAVE_NETINET_IP6_H
 static int
 handle_ipv6 (struct ip6_hdr *ipv6, int len)
 {
@@ -512,6 +513,16 @@ handle_ipv6 (struct ip6_hdr *ipv6, int len)
 
     return (1); /* Success */
 } /* int handle_ipv6 */
+/* #endif HAVE_NETINET_IP6_H */
+
+#else /* if !HAVE_NETINET_IP6_H */
+static int
+handle_ipv6 (__attribute__((unused)) void *pkg,
+       __attribute__((unused)) int len)
+{
+    return (0);
+}
+#endif /* !HAVE_NETINET_IP6_H */
 
 static int
 handle_ip(const struct ip *ip, int len)
@@ -522,7 +533,7 @@ handle_ip(const struct ip *ip, int len)
     struct in6_addr d_addr;
 
     if (ip->ip_v == 6)
-       return (handle_ipv6 ((struct ip6_hdr *) ip, len));
+       return (handle_ipv6 ((void *) ip, len));
 
     in6_addr_from_buffer (&s_addr, &ip->ip_src.s_addr, sizeof (ip->ip_src.s_addr), AF_INET);
     in6_addr_from_buffer (&d_addr, &ip->ip_dst.s_addr, sizeof (ip->ip_dst.s_addr), AF_INET);
@@ -620,7 +631,7 @@ handle_ether(const u_char * pkt, int len)
        return 0;
     memcpy(buf, pkt, len);
     if (ETHERTYPE_IPV6 == etype)
-       return (handle_ipv6 ((struct ip6_hdr *) buf, len));
+       return (handle_ipv6 ((void *) buf, len));
     else
        return handle_ip((struct ip *) buf, len);
 }
@@ -653,7 +664,7 @@ handle_linux_sll (const u_char *pkt, int len)
        return 0;
 
     if (ETHERTYPE_IPV6 == etype)
-       return (handle_ipv6 ((struct ip6_hdr *) pkt, len));
+       return (handle_ipv6 ((void *) pkt, len));
     else
        return handle_ip((struct ip *) pkt, len);
 }
index 6bf2db7..859df21 100644 (file)
@@ -307,9 +307,9 @@ static void varnish_monitor (const user_config_t *conf, struct varnish_stats *VS
                /* outstanding allocations */
                varnish_submit_gauge (conf->instance,  "sm", "requests", "outstanding", VSL_stats->sm_nobj);
                /* bytes allocated */
-               varnish_submit_gauge (conf->instance,  "sm", "bytes", "allocated",      VSL_stats->sm_balloc);
+               varnish_submit_gauge (conf->instance,  "sm", "total_bytes", "allocated",      VSL_stats->sm_balloc);
                /* bytes free */
-               varnish_submit_gauge (conf->instance,  "sm", "bytes", "free",           VSL_stats->sm_bfree);
+               varnish_submit_gauge (conf->instance,  "sm", "total_bytes", "free",           VSL_stats->sm_bfree);
        }
 
        if (conf->collect_sma)
@@ -321,9 +321,9 @@ static void varnish_monitor (const user_config_t *conf, struct varnish_stats *VS
                /* SMA outstanding bytes */
                varnish_submit_gauge (conf->instance,  "sma", "bytes", "outstanding",    VSL_stats->sma_nbytes);
                /* SMA bytes allocated */
-               varnish_submit_gauge (conf->instance,  "sma", "bytes", "allocated",      VSL_stats->sma_balloc);
+               varnish_submit_gauge (conf->instance,  "sma", "total_bytes", "allocated",      VSL_stats->sma_balloc);
                /* SMA bytes free */
-               varnish_submit_gauge (conf->instance,  "sma", "bytes", "free" ,          VSL_stats->sma_bfree);
+               varnish_submit_gauge (conf->instance,  "sma", "total_bytes", "free" ,          VSL_stats->sma_bfree);
        }
 
        if (conf->collect_sms)
@@ -335,9 +335,9 @@ static void varnish_monitor (const user_config_t *conf, struct varnish_stats *VS
                /* SMS outstanding bytes */
                varnish_submit_gauge (conf->instance,  "sms", "bytes", "outstanding",        VSL_stats->sms_nbytes);
                /* SMS bytes allocated */
-               varnish_submit_gauge (conf->instance,  "sms", "bytes", "allocated",          VSL_stats->sms_balloc);
+               varnish_submit_gauge (conf->instance,  "sms", "total_bytes", "allocated",          VSL_stats->sms_balloc);
                /* SMS bytes freed */
-               varnish_submit_gauge (conf->instance,  "sms", "bytes", "free",               VSL_stats->sms_bfree);
+               varnish_submit_gauge (conf->instance,  "sms", "total_bytes", "free",               VSL_stats->sms_bfree);
        }
 
        if (conf->collect_totals)