Merge branch 'collectd-5.4'
authorFlorian Forster <octo@collectd.org>
Mon, 18 Aug 2014 07:50:34 +0000 (09:50 +0200)
committerFlorian Forster <octo@collectd.org>
Mon, 18 Aug 2014 07:50:34 +0000 (09:50 +0200)
Conflicts:
configure.ac
src/curl_json.c
src/lvm.c
src/write_riemann.c

240 files changed:
.gitignore
AUTHORS
ChangeLog
Makefile.am
README
bindings/java/org/collectd/api/Collectd.java
bindings/java/org/collectd/api/CollectdConfigInterface.java
bindings/java/org/collectd/api/CollectdFlushInterface.java
bindings/java/org/collectd/api/CollectdInitInterface.java
bindings/java/org/collectd/api/CollectdLogInterface.java
bindings/java/org/collectd/api/CollectdMatchFactoryInterface.java
bindings/java/org/collectd/api/CollectdMatchInterface.java
bindings/java/org/collectd/api/CollectdNotificationInterface.java
bindings/java/org/collectd/api/CollectdReadInterface.java
bindings/java/org/collectd/api/CollectdShutdownInterface.java
bindings/java/org/collectd/api/CollectdTargetFactoryInterface.java
bindings/java/org/collectd/api/CollectdTargetInterface.java
bindings/java/org/collectd/api/CollectdWriteInterface.java
bindings/java/org/collectd/api/DataSet.java
bindings/java/org/collectd/api/OConfigItem.java
bindings/java/org/collectd/api/OConfigValue.java
bindings/java/org/collectd/java/GenericJMX.java
bindings/java/org/collectd/java/GenericJMXConfConnection.java
bindings/java/org/collectd/java/GenericJMXConfMBean.java
bindings/java/org/collectd/java/GenericJMXConfValue.java
bindings/java/org/collectd/java/JMXMemory.java
bindings/perl/lib/Collectd/Plugins/OpenVZ.pm
bindings/perl/lib/Collectd/Unixsock.pm
configure.ac
contrib/collection.cgi
contrib/collection3/lib/Collectd/Config.pm
contrib/collection3/lib/Collectd/Graph/Config.pm
contrib/collection3/lib/Collectd/Graph/TypeLoader.pm
contrib/examples/myplugin.c
contrib/php-collection/graph.php
contrib/postgresql/collectd_insert.sql
contrib/redhat/collectd.spec
src/Makefile.am
src/amqp.c
src/apache.c
src/apcups.c
src/apple_sensors.c
src/ascent.c
src/barometer.c [new file with mode: 0644]
src/battery.c
src/bind.c
src/cgroups.c
src/collectd-email.pod
src/collectd-exec.pod
src/collectd-java.pod
src/collectd-nagios.c
src/collectd-nagios.pod
src/collectd-perl.pod
src/collectd-python.pod
src/collectd-snmp.pod
src/collectd-tg.c
src/collectd-unixsock.pod
src/collectd.c
src/collectd.conf.in
src/collectd.conf.pod
src/collectd.h
src/collectd.pod
src/collectdctl.c
src/collectdctl.pod
src/collectdmon.c
src/collectdmon.pod
src/common.c
src/common.h
src/configfile.c
src/configfile.h
src/conntrack.c
src/cpu.c
src/cpython.h
src/csv.c
src/curl.c
src/curl_json.c
src/curl_xml.c
src/dbi.c
src/df.c
src/disk.c
src/drbd.c [new file with mode: 0644]
src/email.c
src/entropy.c
src/exec.c
src/filecount.c
src/filter_chain.c
src/filter_chain.h
src/gmond.c
src/hddtemp.c
src/interface.c
src/ipmi.c
src/java.c
src/libcollectdclient/client.c
src/libcollectdclient/collectd/network.h
src/libcollectdclient/network.c
src/liboconfig/oconfig.c
src/liboconfig/oconfig.h
src/liboconfig/parser.y
src/liboconfig/scanner.l
src/libvirt.c
src/load.c
src/log_logstash.c [new file with mode: 0644]
src/logfile.c
src/lvm.c
src/match_empty_counter.c
src/match_hashed.c
src/match_regex.c
src/match_timediff.c
src/match_value.c
src/mbmon.c
src/memcachec.c
src/memcached.c
src/memory.c
src/meta_data.c
src/meta_data.h
src/mysql.c
src/netlink.c
src/network.c
src/network.h
src/nginx.c
src/notify_desktop.c
src/ntpd.c
src/numa.c
src/nut.c
src/olsrd.c
src/onewire.c
src/openvpn.c
src/perl.c
src/pf.c
src/pinba.c
src/ping.c
src/plugin.c
src/plugin.h
src/postgresql.c
src/powerdns.c
src/processes.c
src/protocols.c
src/redis.c
src/routeros.c
src/rrdcached.c
src/sensors.c
src/serial.c
src/sigrok.c
src/snmp.c
src/statsd.c
src/swap.c
src/syslog.c
src/table.c
src/tail.c
src/target_notification.c
src/target_replace.c
src/target_scale.c
src/target_set.c
src/target_v5upgrade.c
src/tcpconns.c
src/teamspeak2.c
src/tests/common_test.c [new file with mode: 0644]
src/tests/macros.h [new file with mode: 0644]
src/tests/mock/plugin.c [new file with mode: 0644]
src/tests/mock/utils_cache.c [new file with mode: 0644]
src/tests/mock/utils_time.c [new file with mode: 0644]
src/tests/test_common.c [new file with mode: 0644]
src/tests/test_utils_avltree.c [new file with mode: 0644]
src/tests/test_utils_heap.c [new file with mode: 0644]
src/tests/test_utils_mount.c [new file with mode: 0644]
src/tests/test_utils_vl_lookup.c [new file with mode: 0644]
src/threshold.c
src/types.db
src/types.db.pod
src/types_list.c
src/types_list.h
src/unixsock.c
src/uptime.c
src/users.c
src/utils_avltree.c
src/utils_avltree.h
src/utils_cache.c
src/utils_cache.h
src/utils_cmd_flush.c
src/utils_cmd_flush.h
src/utils_cmd_getthreshold.c
src/utils_cmd_getthreshold.h
src/utils_cmd_getval.c
src/utils_cmd_getval.h
src/utils_cmd_listval.c
src/utils_cmd_listval.h
src/utils_cmd_putnotif.c
src/utils_cmd_putnotif.h
src/utils_cmd_putval.c
src/utils_cmd_putval.h
src/utils_complain.c
src/utils_complain.h
src/utils_crc32.c [new file with mode: 0644]
src/utils_crc32.h [new file with mode: 0644]
src/utils_db_query.c
src/utils_db_query.h
src/utils_dns.c
src/utils_dns.h
src/utils_fbhash.c
src/utils_fbhash.h
src/utils_format_json.c
src/utils_format_json.h
src/utils_heap.c
src/utils_heap.h
src/utils_ignorelist.c
src/utils_latency.c
src/utils_latency.h
src/utils_llist.c
src/utils_llist.h
src/utils_match.c
src/utils_match.h
src/utils_mount.h
src/utils_parse_option.c
src/utils_parse_option.h
src/utils_rrdcreate.c
src/utils_rrdcreate.h
src/utils_subst.c
src/utils_subst.h
src/utils_tail.c
src/utils_tail.h
src/utils_tail_match.c
src/utils_tail_match.h
src/utils_threshold.c [new file with mode: 0644]
src/utils_threshold.h [new file with mode: 0644]
src/utils_time.c
src/utils_time.h
src/utils_vl_lookup.c
src/utils_vl_lookup.h
src/utils_vl_lookup_test.c [deleted file]
src/vmem.c
src/vserver.c
src/wireless.c
src/write_http.c
src/write_kafka.c [new file with mode: 0644]
src/write_redis.c
src/write_riemann.c
src/write_riemann_threshold.c [new file with mode: 0644]
src/write_tsdb.c [new file with mode: 0644]
src/xmms.c
version-gen.sh

index 7c7c848..1929b28 100644 (file)
@@ -38,7 +38,9 @@ src/collectdctl
 src/collectdmon
 src/*.1
 src/*.5
+src/.pod2man.tmp.*
 src/libcollectdclient/collectd/lcc_features.h
+src/utils_vl_lookup_test
 
 # patch stuff
 *.rej
@@ -62,6 +64,7 @@ bindings/.perl-directory-stamp
 bindings/perl/Collectd/pm_to_blib
 bindings/perl/blib/
 bindings/perl/pm_to_blib
+bindings/buildperl
 
 # java stuff
 bindings/java/java-build-stamp
@@ -76,3 +79,6 @@ src/tags
 
 # backup stuff
 *~
+# tests stuff
+src/tests/.deps/
+src/tests/mock/.deps/
diff --git a/AUTHORS b/AUTHORS
index 31d132f..d5dff3d 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -47,9 +47,15 @@ Aurélien Reynaud <collectd at wattapower.net>
  - LPAR plugin.
  - Various fixes for AIX, HP-UX and Solaris.
 
+Benjamin Gilbert <bgilbert at cs.cmu.edu>
+ - Improvements to the LVM plugin.
+
 Bert Vermeulen <bert at biot.com>
  - sigrok plugin
 
+Brett Hawn <bhawn at llnw.com>
+ - write_tsdb plugin for http://opentsdb.net/
+
 Bruno Prémont <bonbons at linux-vserver.org>
  - BIND plugin.
  - Many bugreports and -fixes in various plugins,
@@ -109,6 +115,9 @@ J. Javier Maestro <jjmaestro at ieee.org>
 Jérôme Renard <jerome.renard at gmail.com>
  - varnish plugin.
 
+Kevin Bowling <kbowling at llnw.com>
+ - write_tsdb plugin for http://opentsdb.net/
+
 Kris Nielander <nielander at fox-it.com>
  - tail_csv plugin.
 
@@ -195,6 +204,10 @@ Phoenix Kayo <kayo.k11.4 at gmail.com>
 Pierre-Yves Ritschard <pyr at spootnik.org>
  - Write-Riemann plugin.
  - Write-Graphite plugin: Notification support.
+ - Write-Kafka plugin.
+ - Log-Logstash plugin.
+ - Normalization in the CPU plugin.
+ - Relative values in the Load plugin.
 
 Piotr Hosowicz <the55 at wp.pl>
  - SMF manifest for collectd.
@@ -231,6 +244,9 @@ Sven Trenkel <collectd at semidefinite.de>
  - netapp plugin.
  - python plugin.
 
+Tim Laszlo <tim.laszlo at gmail.com>
+ - drbd plugin
+
 Thomas Meson <zllak at hycik.org>
  - Graphite support for the AMQP plugin.
 
index a2c46f0..8112afa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 
 2008-07-15, Version 4.4.2
        * build system: Use pkg-config to detect the upsclient library.
-       * collectd: Try even harder to determine the endianess of the
+       * collectd: Try even harder to determine the endianness of the
          architecture collectd is being built on.
        * disk plugin: Fix for Linux 2.4: A wrong field was used as the name
          of disks.
 2008-08-30, Version 4.3.4
        * Build system: Improved detection of and linking with the statgrab
          library.
-       * collectd: Portability fixes, especially to determine endianess more
+       * collectd: Portability fixes, especially to determine endianness more
          reliable.
        * Various plugins: Fix format strings.
        * disk plugin: A fix for giving disks under Linux 2.4 the right names
index 5267123..35f24cb 100644 (file)
@@ -2,7 +2,7 @@ ACLOCAL_AMFLAGS = -I libltdl/m4
 
 SUBDIRS = libltdl src bindings .
 
-INCLUDES = $(LTDLINCL)
+AM_CPPFLAGS = $(LTDLINCL)
 
 EXTRA_DIST = contrib version-gen.sh
 
diff --git a/README b/README
index c0d7036..cd58142 100644 (file)
--- a/README
+++ b/README
@@ -32,6 +32,11 @@ Features
     - ascent
       Statistics about Ascent, a free server for the game `World of Warcraft'.
 
+    - barometer
+      Using digital barometer sensor MPL115A2 or MPL3115 from Freescale
+      provides absolute barometric pressure, air pressure reduced to sea level
+      and temperature.
+
     - battery
       Batterycharge, -current and voltage of ACPI and PMU based laptop
       batteries.
@@ -82,6 +87,9 @@ Features
       DNS traffic: Query types, response codes, opcodes and traffic/octets
       transfered.
 
+    - drbd
+      Collect individual drbd resource statistics.
+
     - email
       Email statistics: Count, traffic, spam scores and checks.
       See collectd-email(5).
@@ -293,6 +301,10 @@ Features
       network devices such as switches, routers, thermometers, rack monitoring
       servers, etc. See collectd-snmp(5).
 
+    - statsd
+      Acts as a StatsD server, reading values sent over the network from StatsD
+      clients and calculating rates and other aggregates out of these values.
+
     - swap
       Pages swapped out onto harddisk or whatever is called `swap' by the OS..
 
@@ -399,11 +411,18 @@ Features
       can be configured to avoid logging send errors (especially useful when
       using UDP).
 
+    - write_tsdb
+      Sends data OpenTSDB, a scalable no master, no shared state time series
+      database.
+
     - write_http
       Sends the values collected by collectd to a web-server using HTTP POST
       requests. The transmitted data is either in a form understood by the
       Exec plugin or formatted in JSON.
 
+    - write_kafka
+      Sends data to Apache Kafka, a distributed queue.
+
     - write_mongodb
       Sends data to MongoDB, a NoSQL database.
 
@@ -417,7 +436,7 @@ Features
     plugins keep up informed about what's going on:
 
     - logfile
-      Writes logmessages to a file or STDOUT/STDERR.
+      Writes log messages to a file or STDOUT/STDERR.
 
     - perl
       Log messages are propagated to plugins written in Perl as well.
@@ -430,6 +449,9 @@ Features
     - syslog
       Logs to the standard UNIX logging mechanism, syslog.
 
+    - log_logstash
+      Writes log messages formatted as logstash JSON events.
+
   * Notifications can be handled by the following plugins:
 
     - notify_desktop
@@ -565,7 +587,7 @@ Prerequisites
 
   * A POSIX-threads (pthread) implementation.
     Since gathering some statistics is slow (network connections, slow devices,
-    etc) the collectd is parallelized. The POSIX threads interface is being
+    etc) collectd is parallelized. The POSIX threads interface is being
     used and should be found in various implementations for hopefully all
     platforms.
 
@@ -586,12 +608,12 @@ Prerequisites
     Used by the `oracle' plugin.
 
   * libcredis (optional)
-    Used by the redis plugin. Please note that you require a 0.2.2 version
+    Used by the `redis' plugin. Please note that you require a 0.2.2 version
     or higher. <http://code.google.com/p/credis/>
 
   * libcurl (optional)
-    If you want to use the `apache', `ascent', `curl', `nginx', or `write_http'
-    plugin.
+    If you want to use the `apache', `ascent', `bind', `curl', `curl_json',
+    `curl_xml', `nginx', or `write_http' plugin.
     <http://curl.haxx.se/>
 
   * libdbi (optional)
@@ -611,25 +633,27 @@ Prerequisites
     <http://www.gnupg.org/>
 
   * libhal (optional)
-    If present, the uuid plugin will check for UUID from HAL.
+    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.
+
   * libiptc (optional)
     For querying iptables counters.
     <http://netfilter.org/>
 
-    If not found on the system, a version shipped with this distribution can
-    be used. It requires some Linux headers in /usr/include/linux. You can
-    force the build system to use the shipped version by specifying
-      --with-libiptc=shipped
-    when running the configure script.
-
   * libjvm (optional)
     Library that encapsulates the `Java Virtual Machine' (JVM). This library is
-    used by the Java plugin to execute Java bytecode. See “Configuring with
+    used by the `java' plugin to execute Java bytecode. See “Configuring with
     libjvm” below.
     <http://openjdk.java.net/> (and others)
 
+  * liblvm2 (optional)
+    Used by the `lvm' plugin.
+    <ftp://sources.redhat.com/pub/lvm2/>
+
   * libmemcached (optional)
     Used by the `memcachec' plugin to connect to a memcache daemon.
     <http://tangent.org/552/libmemcached.html>
@@ -639,8 +663,8 @@ Prerequisites
     <http://www.netfilter.org/projects/libmnl/>
 
   * libmodbus (optional)
-    Used by the “modbus” plugin to communicate with Modbus/TCP devices. The
-    “modbus” plugin works with version 2.0.3 of the library – due to frequent
+    Used by the `modbus' plugin to communicate with Modbus/TCP devices. The
+    `modbus' plugin works with version 2.0.3 of the library – due to frequent
     API changes other versions may or may not compile cleanly.
     <http://www.libmodbus.org/>
 
@@ -649,7 +673,7 @@ Prerequisites
     <http://dev.mysql.com/>
 
   * libnetapp (optional)
-    Required for the “netapp” plugin.
+    Required for the `netapp' plugin.
     This library is part of the “Manage ONTAP SDK” published by NetApp.
 
   * libnetsnmp (optional)
@@ -660,9 +684,13 @@ Prerequisites
     For the `notify_desktop' plugin.
     <http://www.galago-project.org/>
 
+  * libopenipmi (optional)
+    Used by the `ipmi' plugin to prove IPMI devices.
+    <http://openipmi.sourceforge.net/>
+
   * liboping (optional)
     Used by the `ping' plugin to send and receive ICMP packets.
-    <http://verplant.org/liboping/>
+    <http://octo.it/liboping/>
 
   * libowcapi (optional)
     Used by the `onewire' plugin to read values from onewire sensors (or the
@@ -687,7 +715,8 @@ Prerequisites
 
   * libprotobuf-c, protoc-c (optional)
     Used by the `pinba' plugin to generate a parser for the network packets
-    sent by the Pinba PHP extension.
+    sent by the Pinba PHP extension, and by the `write_riemann' plugin to
+    generate events to be sent to a Riemann server.
     <http://code.google.com/p/protobuf-c/>
 
   * libpython (optional)
@@ -696,12 +725,17 @@ Prerequisites
     <http://www.python.org/>
 
   * librabbitmq (optional; also called “rabbitmq-c”)
-    Used by the AMQP plugin for AMQP connections, for example to RabbitMQ.
+    Used by the `amqp' plugin for AMQP connections, for example to RabbitMQ.
     <http://hg.rabbitmq.com/rabbitmq-c/>
 
+  * librdkafka (optional; also called “rdkafka”)
+    Used by the `write_kafka' plugin for producing messages and sending them
+    to a Kafka broker.
+    <https://github.com/edenhill/librdkafka>
+
   * librouteros (optional)
     Used by the `routeros' plugin to connect to a device running `RouterOS'.
-    <http://verplant.org/librouteros/>
+    <http://octo.it/librouteros/>
 
   * librrd (optional)
     Used by the `rrdtool' and `rrdcached' plugins. The latter requires RRDtool
@@ -718,7 +752,7 @@ Prerequisites
     <http://www.lm-sensors.org/>
 
   * libsigrok (optional)
-    Used by the sigrok plugin. In addition, libsigrok depends on glib,
+    Used by the `sigrok' plugin. In addition, libsigrok depends on glib,
     libzip, and optionally (depending on which drivers are enabled) on
     libusb, libftdi and libudev.
 
@@ -728,7 +762,7 @@ Prerequisites
     <http://www.i-scream.org/libstatgrab/>
 
   * libtokyotyrant (optional)
-    Used by the tokyotyrant plugin.
+    Used by the `tokyotyrant' plugin.
     <http://1978th.net/tokyotyrant/>
 
   * libupsclient/nut (optional)
@@ -740,18 +774,21 @@ Prerequisites
     <http://libvirt.org/>
 
   * libxml2 (optional)
-    Parse XML data. This is needed for the `ascent' and `libvirt' plugins.
+    Parse XML data. This is needed for the `ascent', `bind', `curl_xml' and
+    `libvirt' plugins.
     <http://xmlsoft.org/>
 
   * libxmms (optional)
     <http://www.xmms.org/>
 
   * libyajl (optional)
-    Parse JSON data. This is needed for the `curl_json' plugin.
+    Parse JSON data. This is needed for the `curl_json' and `log_logstash'
+    plugins.
     <http://github.com/lloyd/yajl>
 
   * libvarnish (optional)
-     Fetches statistics from a Varnish instance. This is needed for the Varnish plugin
+     Fetches statistics from a Varnish instance. This is needed for the
+     `varnish' plugin.
      <http://varnish-cache.org>
 
 Configuring / Compiling / Installing
@@ -857,7 +894,7 @@ Contact
 
   For questions, bug reports, development information and basically all other
   concerns please send an email to collectd's mailing list at
-  <collectd at verplant.org>.
+  <list at collectd.org>.
 
   For live discussion and more personal contact visit us in IRC, we're in
   channel #collectd on freenode.
@@ -866,7 +903,7 @@ Contact
 Author
 ------
 
-  Florian octo Forster <octo at verplant.org>,
+  Florian octo Forster <octo at collectd.org>,
   Sebastian tokkee Harl <sh at tokkee.org>,
   and many contributors (see `AUTHORS').
 
index 84e6592..450f87a 100644 (file)
@@ -1,22 +1,27 @@
-/*
- * collectd/java - org/collectd/api/Collectd.java
- * Copyright (C) 2009  Florian octo Forster
+/**
+ * collectd - bindings/java/org/collectd/api/Collectd.java
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 package org.collectd.api;
@@ -28,7 +33,7 @@ package org.collectd.api;
  * object of this class (in fact, you can't). Just call these functions
  * directly.
  *
- * @author Florian Forster &lt;octo at verplant.org&gt;
+ * @author Florian Forster &lt;octo at collectd.org&gt;
  */
 public class Collectd
 {
@@ -252,6 +257,13 @@ public class Collectd
   native private static void log (int severity, String message);
 
   /**
+   * Yield contents of collectd/src/collectd.h:hostname_g
+   *
+   * @return The hostname as set in the collectd configuration.
+   */
+  native public static java.lang.String getHostname ();
+
+  /**
    * Prints an error message.
    */
   public static void logError (String message)
index 060f944..4b66097 100644 (file)
@@ -1,22 +1,27 @@
-/*
- * collectd/java - org/collectd/api/CollectdConfigInterface.java
- * Copyright (C) 2009  Florian octo Forster
+/**
+ * collectd - bindings/java/org/collectd/api/CollectdConfigInterface.java
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 package org.collectd.api;
@@ -24,7 +29,7 @@ package org.collectd.api;
 /**
  * Interface for objects implementing a config method.
  *
- * @author Florian Forster &lt;octo at verplant.org&gt;
+ * @author Florian Forster &lt;octo at collectd.org&gt;
  * @see Collectd#registerConfig(String, CollectdConfigInterface)
  */
 public interface CollectdConfigInterface
index 410c61c..ea7bd64 100644 (file)
@@ -1,22 +1,27 @@
-/*
- * collectd/java - org/collectd/api/CollectdFlushInterface.java
- * Copyright (C) 2009  Florian octo Forster
+/**
+ * collectd - bindings/java/org/collectd/api/CollectdFlushInterface.java
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 package org.collectd.api;
@@ -24,7 +29,7 @@ package org.collectd.api;
 /**
  * Interface for objects implementing a flush method.
  *
- * @author Florian Forster &lt;octo at verplant.org&gt;
+ * @author Florian Forster &lt;octo at collectd.org&gt;
  * @see Collectd#registerFlush
  */
 public interface CollectdFlushInterface
index fbfd306..545f41e 100644 (file)
@@ -1,22 +1,27 @@
-/*
- * collectd/java - org/collectd/api/CollectdInitInterface.java
- * Copyright (C) 2009  Florian octo Forster
+/**
+ * collectd - bindings/java/org/collectd/api/CollectdInitInterface.java
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 package org.collectd.api;
@@ -24,7 +29,7 @@ package org.collectd.api;
 /**
  * Interface for objects implementing an init method.
  *
- * @author Florian Forster &lt;octo at verplant.org&gt;
+ * @author Florian Forster &lt;octo at collectd.org&gt;
  * @see Collectd#registerInit
  */
 public interface CollectdInitInterface
index ba0350a..a516df5 100644 (file)
@@ -1,22 +1,27 @@
-/*
- * collectd/java - org/collectd/api/CollectdLogInterface.java
- * Copyright (C) 2009  Florian octo Forster
+/**
+ * collectd - bindings/java/org/collectd/api/CollectdLogInterface.java
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 package org.collectd.api;
@@ -24,7 +29,7 @@ package org.collectd.api;
 /**
  * Interface for objects implementing a log method.
  *
- * @author Florian Forster &lt;octo at verplant.org&gt;
+ * @author Florian Forster &lt;octo at collectd.org&gt;
  * @see Collectd#registerLog
  */
 public interface CollectdLogInterface
index 7b1c71a..b19c779 100644 (file)
@@ -1,22 +1,27 @@
-/*
- * collectd/java - org/collectd/api/CollectdMatchFactoryInterface.java
- * Copyright (C) 2009  Florian octo Forster
+/**
+ * collectd - bindings/java/org/collectd/api/CollectdMatchFactoryInterface.java
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 package org.collectd.api;
@@ -27,7 +32,7 @@ package org.collectd.api;
  * Objects implementing this interface are used to create objects implementing
  * the CollectdMatchInterface interface.
  *
- * @author Florian Forster &lt;octo at verplant.org&gt;
+ * @author Florian Forster &lt;octo at collectd.org&gt;
  * @see CollectdMatchInterface
  * @see Collectd#registerMatch
  */
index cc8a99e..20a03d2 100644 (file)
@@ -1,22 +1,27 @@
-/*
- * collectd/java - org/collectd/api/CollectdMatchInterface.java
- * Copyright (C) 2009  Florian octo Forster
+/**
+ * collectd - bindings/java/org/collectd/api/CollectdMatchInterface.java
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 package org.collectd.api;
@@ -28,7 +33,7 @@ package org.collectd.api;
  * CollectdMatchFactoryInterface interface. They are not instantiated by the
  * daemon directly!
  *
- * @author Florian Forster &lt;octo at verplant.org&gt;
+ * @author Florian Forster &lt;octo at collectd.org&gt;
  * @see CollectdMatchFactoryInterface
  * @see Collectd#registerMatch
  */
index d278fe2..ddff6cd 100644 (file)
@@ -1,22 +1,27 @@
-/*
- * collectd/java - org/collectd/api/CollectdNotificationInterface.java
- * Copyright (C) 2009  Florian octo Forster
+/**
+ * collectd - bindings/java/org/collectd/api/CollectdNotificationInterface.java
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 package org.collectd.api;
@@ -24,7 +29,7 @@ package org.collectd.api;
 /**
  * Interface for objects implementing a notification method.
  *
- * @author Florian Forster &lt;octo at verplant.org&gt;
+ * @author Florian Forster &lt;octo at collectd.org&gt;
  * @see Collectd#registerNotification
  */
 public interface CollectdNotificationInterface
index 67f1898..996841a 100644 (file)
@@ -1,22 +1,27 @@
-/*
- * collectd/java - org/collectd/api/CollectdReadInterface.java
- * Copyright (C) 2009  Florian octo Forster
+/**
+ * collectd - bindings/java/org/collectd/api/CollectdReadInterface.java
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 package org.collectd.api;
@@ -27,7 +32,7 @@ package org.collectd.api;
  * Objects implementing this interface can be registered with the daemon. Their
  * read method is then called periodically to acquire and submit values.
  *
- * @author Florian Forster &lt;octo at verplant.org&gt;
+ * @author Florian Forster &lt;octo at collectd.org&gt;
  * @see Collectd#registerRead
  */
 public interface CollectdReadInterface
index 108c54e..e496d3c 100644 (file)
@@ -1,22 +1,27 @@
-/*
- * collectd/java - org/collectd/api/CollectdShutdownInterface.java
- * Copyright (C) 2009  Florian octo Forster
+/**
+ * collectd - bindings/java/org/collectd/api/CollectdShutdownInterface.java
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 package org.collectd.api;
@@ -24,7 +29,7 @@ package org.collectd.api;
 /**
  * Interface for objects implementing a shutdown method.
  *
- * @author Florian Forster &lt;octo at verplant.org&gt;
+ * @author Florian Forster &lt;octo at collectd.org&gt;
  * @see Collectd#registerShutdown
  */
 public interface CollectdShutdownInterface
index 65f6181..b4c2321 100644 (file)
@@ -1,22 +1,27 @@
-/*
- * collectd/java - org/collectd/api/CollectdTargetFactoryInterface.java
- * Copyright (C) 2009  Florian octo Forster
+/**
+ * collectd - bindings/java/org/collectd/api/CollectdTargetFactoryInterface.java
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 package org.collectd.api;
@@ -27,7 +32,7 @@ package org.collectd.api;
  * Objects implementing this interface are used to create objects implementing
  * the CollectdTargetInterface interface.
  *
- * @author Florian Forster &lt;octo at verplant.org&gt;
+ * @author Florian Forster &lt;octo at collectd.org&gt;
  * @see CollectdTargetInterface
  * @see Collectd#registerTarget
  */
index 74412a3..1f5ece1 100644 (file)
@@ -1,22 +1,27 @@
-/*
- * collectd/java - org/collectd/api/CollectdTargetInterface.java
- * Copyright (C) 2009  Florian octo Forster
+/**
+ * collectd - bindings/java/org/collectd/api/CollectdTargetInterface.java
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 package org.collectd.api;
@@ -28,7 +33,7 @@ package org.collectd.api;
  * CollectdTargetFactoryInterface interface. They are not instantiated by the
  * daemon directly!
  *
- * @author Florian Forster &lt;octo at verplant.org&gt;
+ * @author Florian Forster &lt;octo at collectd.org&gt;
  * @see CollectdTargetFactoryInterface
  * @see Collectd#registerTarget
  */
index 28e0230..f95169a 100644 (file)
@@ -1,22 +1,27 @@
-/*
- * collectd/java - org/collectd/api/CollectdWriteInterface.java
- * Copyright (C) 2009  Florian octo Forster
+/**
+ * collectd - bindings/java/org/collectd/api/CollectdWriteInterface.java
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 package org.collectd.api;
@@ -24,7 +29,7 @@ package org.collectd.api;
 /**
  * Interface for objects implementing a write method.
  *
- * @author Florian Forster &lt;octo at verplant.org&gt;
+ * @author Florian Forster &lt;octo at collectd.org&gt;
  * @see Collectd#registerWrite
  */
 public interface CollectdWriteInterface
index 9823073..3cba5eb 100644 (file)
@@ -1,22 +1,27 @@
-/*
- * collectd/java - org/collectd/api/OConfigItem.java
- * Copyright (C) 2009  Florian octo Forster
+/**
+ * collectd - bindings/java/org/collectd/api/DataSet.java
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 package org.collectd.api;
@@ -27,7 +32,7 @@ import java.util.ArrayList;
 /**
  * Java representation of collectd/src/plugin.h:data_set_t structure.
  *
- * @author Florian Forster &lt;octo at verplant.org&gt;
+ * @author Florian Forster &lt;octo at collectd.org&gt;
  */
 public class DataSet
 {
index 4c6a778..08d8b70 100644 (file)
@@ -1,22 +1,27 @@
-/*
- * collectd/java - org/collectd/api/OConfigItem.java
- * Copyright (C) 2009  Florian octo Forster
+/**
+ * collectd - bindings/java/org/collectd/api/OConfigItem.java
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 package org.collectd.api;
@@ -27,7 +32,7 @@ import java.util.ArrayList;
 /**
  * Java representation of collectd/src/liboconfig/oconfig.h:oconfig_item_t structure.
  *
- * @author Florian Forster &lt;octo at verplant.org&gt;
+ * @author Florian Forster &lt;octo at collectd.org&gt;
  */
 public class OConfigItem
 {
index 1ebafff..0a33773 100644 (file)
@@ -1,22 +1,27 @@
-/*
- * collectd/java - org/collectd/api/OConfigValue.java
- * Copyright (C) 2009  Florian octo Forster
+/**
+ * collectd - bindings/java/org/collectd/api/OConfigValue.java
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 package org.collectd.api;
@@ -24,7 +29,7 @@ package org.collectd.api;
 /**
  * Java representation of collectd/src/liboconfig/oconfig.h:oconfig_value_t structure.
  *
- * @author Florian Forster &lt;octo at verplant.org&gt;
+ * @author Florian Forster &lt;octo at collectd.org&gt;
  */
 public class OConfigValue
 {
index 319615c..a678d5f 100644 (file)
@@ -1,22 +1,27 @@
-/*
- * collectd/java - org/collectd/java/GenericJMX.java
- * Copyright (C) 2009  Florian octo Forster
+/**
+ * collectd - bindings/java/org/collectd/java/GenericJMX.java
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 package org.collectd.java;
index 7fad08f..8f1b991 100644 (file)
@@ -1,19 +1,24 @@
-/*
- * collectd/java - org/collectd/java/GenericJMXConfConnection.java
+/**
+ * collectd - bindings/java/org/collectd/java/GenericJMXConfConnection.java
  * Copyright (C) 2009-2012  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <octo at collectd.org>
@@ -86,15 +91,7 @@ class GenericJMXConfConnection
       return (this._host);
     }
 
-    try
-    {
-      InetAddress localHost = InetAddress.getLocalHost();
-      return (localHost.getHostName ());
-    }
-    catch (UnknownHostException e)
-    {
-      return ("localhost");
-    }
+    return Collectd.getHostname();
   } /* }}} String getHost */
 
 private void connect () /* {{{ */
@@ -118,6 +115,7 @@ private void connect () /* {{{ */
 
     environment = new HashMap ();
     environment.put (JMXConnector.CREDENTIALS, credentials);
+    environment.put(JMXConnectorFactory.PROTOCOL_PROVIDER_CLASS_LOADER, this.getClass().getClassLoader());
   }
 
   try
index b1fbfb3..64a53ac 100644 (file)
@@ -1,22 +1,27 @@
-/*
- * collectd/java - org/collectd/java/GenericJMXConfMBean.java
+/**
+ * collectd - bindings/java/org/collectd/java/GenericJMXConfMBean.java
  * Copyright (C) 2009,2010  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 package org.collectd.java;
index 9fb0fc2..4b42c91 100644 (file)
@@ -1,22 +1,27 @@
-/*
- * collectd/java - org/collectd/java/GenericJMXConfValue.java
- * Copyright (C) 2009  Florian octo Forster
+/**
+ * collectd - bindings/java/org/collectd/java/GenericJMXConfValue.java
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 package org.collectd.java;
index 6e6a2fb..050d893 100644 (file)
@@ -1,22 +1,27 @@
-/*
- * collectd/java - org/collectd/java/JMXMemory.java
- * Copyright (C) 2009  Florian octo Forster
+/**
+ * collectd - bindings/java/org/collectd/java/JMXMemory.java
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 package org.collectd.java;
index ea3cee9..4c7c3fe 100644 (file)
@@ -27,162 +27,219 @@ use warnings;
 
 use Collectd qw( :all );
 
-my @cpu_instances = ('user', 'nice', 'system', 'idle', 'wait', 'interrupt', 'softirq', 'steal');
-my @if_instances = ('if_octets', 'if_packets', 'if_errors');
 my $vzctl = '/usr/sbin/vzctl';
 my $vzlist = '/usr/sbin/vzlist';
 
-my $last_stat = {};
+# Since OpenVZ is container based, all guests see all the host's CPUs,
+# and would report the same data. So we disable CPU by default.
+my $enable_interface = 1;
+my $enable_cpu       = 0;
+my $enable_df        = 1;
+my $enable_load      = 1;
+my $enable_processes = 1;
+my $enable_users     = 1;
 
-sub openvz_read
-{
-    my %v = (time => time(), interval => plugin_get_interval());
-    my (@veids, $veid, $name, $key, $val, $i, @lines, @parts, @counters);
+# We probably don't care about loopback transfer
+my @ignored_interfaces = ( "lo" );
 
-    @veids = map { s/ //g; $_; } split(/\n/, `$vzlist -Ho veid`);
+sub interface_read {
+    my ($veid, $name) = @_;
+    my @rx_fields = qw(if_octets if_packets if_errors drop fifo frame compressed multicast);
+    my @tx_fields = qw(if_octets if_packets if_errors drop fifo frame compressed);
+    my %v = _build_report_hash($name);
 
-    foreach $veid (@veids)
-    {
-        ($name = `$vzlist -Ho name $veid`) =~ s/^\s*(.*?)\s*$/$1/;
-        $name = $veid if ($name =~ /^-$/);
+    my @lines = `$vzctl exec $veid cat /proc/net/dev`;
 
-        $v{'host'} = $name;
+    for my $line (@lines) {
+        # skip explanatory text
+        next if $line !~ /:/;
 
-        #####################################################################
-        # interface
+        $line =~ s/^\s+|\s+$//g;
 
-        $v{'plugin'} = 'interface';
-        delete $v{'plugin_instance'};
+        my ($iface, %rx, %tx);
 
-        @lines = split(/\n/, `$vzctl exec $veid cat /proc/net/dev`);
-        foreach (@lines)
-        {
-            next if (!/:/);                
+        # read /proc/net/dev fields
+        ($iface, @rx{@rx_fields}, @tx{@tx_fields}) = split /[: ]+/, $line;
 
-            @parts = split(/:/);
-            ($key = $parts[0]) =~ s/^\s*(.*?)\s*$/$1/;
-            ($val = $parts[1]) =~ s/^\s*(.*?)\s*$/$1/;
-            @counters = split(/ +/, $val);
+        # Skip this interface if it is in the ignored list
+        next if grep { $iface eq $_ } @ignored_interfaces;
 
-            $v{'type_instance'} = $key;
-            for ($key = 0; $key <= $#if_instances; ++$key)
-            {
-                $v{'type'} = $if_instances[$key];
-                $v{'values'} = [ $counters[$key], $counters[$key + 8] ];
-                plugin_dispatch_values(\%v);
-            }
+        for my $instance (qw(if_octets if_packets if_errors)) {
+            plugin_dispatch_values({
+                'plugin'          => 'interface',
+                'plugin_instance' => $iface,
+                'type'            => $instance,
+                'values'          => [ $rx{$instance}, $tx{$instance} ],
+                %v,
+            });
         }
+    }
+}
 
-        #####################################################################
-        # cpu
-
-        $v{'plugin'} = 'cpu';
-        $v{'type'} = 'cpu';
-
-        $i = 0;
-        @lines = split(/\n/, `$vzctl exec $veid cat /proc/stat`);
-        foreach (@lines)
-        {
-            next if (!/^cpu[0-9]/);
-
-            @counters = split(/ +/);
-            shift(@counters);
-
-            # Remove once OpenVZ bug 1376 is resolved
-            if (48485 == $counters[3])
-            {
-                $counters[3] = $last_stat->{"$veid-$i-idle"};
-                $counters[4] = $last_stat->{"$veid-$i-wait"};
-            }
-            else
-            {
-                $last_stat->{"$veid-$i-idle"} = $counters[3];
-                $last_stat->{"$veid-$i-wait"} = $counters[4];
-            }
-
-            $v{'plugin_instance'} = $i++;
-            for ($key = 0; $key <= $#counters; ++$key)
-            {
-                $v{'type_instance'} = $cpu_instances[$key];
-                $v{'values'} = [ $counters[$key] ];
-                plugin_dispatch_values(\%v);
-            }
+sub cpu_read {
+    my $veid = shift;
+    my $name = shift;
+    my ($key, $val, $i, @lines, @counters);
+    my @cpu_instances = ('user', 'nice', 'system', 'idle', 'wait', 'interrupt', 'softirq', 'steal');
+    my $last_stat = {};
+    my %v = _build_report_hash($name);
+
+    $v{'plugin'} = 'cpu';
+    $v{'type'} = 'cpu';
+
+    $i = 0;
+    @lines = split(/\n/, `$vzctl exec $veid cat /proc/stat`);
+    foreach (@lines) {
+        next if (!/^cpu[0-9]/);
+
+        @counters = split(/ +/);
+        shift(@counters);
+
+        # Remove once OpenVZ bug 1376 is resolved
+        if (48485 == $counters[3]) {
+            $counters[3] = $last_stat->{"$veid-$i-idle"};
+            $counters[4] = $last_stat->{"$veid-$i-wait"};
+        }
+        else {
+            $last_stat->{"$veid-$i-idle"} = $counters[3];
+            $last_stat->{"$veid-$i-wait"} = $counters[4];
         }
 
-        #####################################################################
-        # df
+        $v{'plugin_instance'} = $i++;
+        for ($key = 0; $key <= $#counters; ++$key) {
+            $v{'type_instance'} = $cpu_instances[$key];
+            $v{'values'} = [ $counters[$key] ];
+            plugin_dispatch_values(\%v);
+    }
+}
+}
 
-        $v{'plugin'} = 'df';
-        delete $v{'plugin_instance'};
-        $v{'type'} = 'df';
+sub df_read {
+    my $veid = shift;
+    my $name = shift;
+    my ($key, $val, @lines, @parts);
+    my %v = _build_report_hash($name);
 
-        $val = join(' ', map { (split)[1] } split(/\n/, `$vzctl exec $veid cat /proc/mounts`));
-        @lines = split(/\n/, `$vzctl exec $veid stat -tf $val`);
-        foreach (@lines)
-        {
-            @parts = split(/ /);
-            next if (0 == $parts[7]);
+    $v{'plugin'} = 'df';
+    delete $v{'plugin_instance'};
+    $v{'type'} = 'df';
 
-            $val = substr($parts[0], 1);
-            $val = 'root' if ($val =~ /^$/);
-            $val =~ s#/#-#g;
+    $val = join(' ', map { (split)[1] } split(/\n/, `$vzctl exec $veid cat /proc/mounts`));
+    @lines = split(/\n/, `$vzctl exec $veid stat -tf $val`);
+    foreach (@lines) {
+        @parts = split(/ /);
+        next if (0 == $parts[7]);
 
-            $v{'type_instance'} = $val;
-            $v{'values'} = [ $parts[5] * ($parts[6] - $parts[7]), $parts[5] * $parts[7] ];
-            plugin_dispatch_values(\%v);
-        }
+        $val = substr($parts[0], 1);
+        $val = 'root' if ($val =~ /^$/);
+        $val =~ s#/#-#g;
+
+        $v{'type_instance'} = $val;
+        $v{'values'} = [ $parts[5] * ($parts[6] - $parts[7]), $parts[5] * $parts[7] ];
+        plugin_dispatch_values(\%v);
+}
+}
 
-        #####################################################################
-        # load
+sub load_read {
+    my $veid = shift;
+    my $name = shift;
+    my ($key, $val, @lines, @parts);
+    my %v = _build_report_hash($name);
 
-        $v{'plugin'} = 'load';
-        delete $v{'plugin_instance'};
-        $v{'type'} = 'load';
-        delete $v{'type_instance'};
+    $v{'plugin'} = 'load';
+    delete $v{'plugin_instance'};
+    $v{'type'} = 'load';
+    delete $v{'type_instance'};
 
-        @parts = split(/ +/, `$vzctl exec $veid cat /proc/loadavg`);
-        $v{'values'} = [ $parts[0], $parts[1], $parts[2] ];
+    @parts = split(/ +/, `$vzctl exec $veid cat /proc/loadavg`);
+    $v{'values'} = [ $parts[0], $parts[1], $parts[2] ];
+    plugin_dispatch_values(\%v);
+}
+
+sub processes_read {
+    my $veid = shift;
+    my $name = shift;
+    my ($key, $val, @lines);
+    my %v = _build_report_hash($name);
+
+    my $ps_states = { 'paging' => 0, 'blocked' => 0, 'zombies' => 0, 'stopped' => 0,
+        'running' => 0, 'sleeping' => 0 };
+    my $state_map = { 'R' => 'running', 'S' => 'sleeping', 'D' => 'blocked',
+        'Z' => 'zombies', 'T' => 'stopped', 'W' => 'paging' };
+
+    $v{'plugin'} = 'processes';
+    delete $v{'plugin_instance'};
+    $v{'type'} = 'ps_state';
+
+    @lines = map { (split)[2] } split(/\n/, `$vzctl exec $veid cat '/proc/[0-9]*/stat'`);
+    foreach $key (@lines) {
+        ++$ps_states->{$state_map->{$key}};
+    }
+
+    foreach $key (keys %{$ps_states}) {
+        $v{'type_instance'} = $key;
+        $v{'values'} = [ $ps_states->{$key} ];
         plugin_dispatch_values(\%v);
+}
+}
 
-        #####################################################################
-        # processes
+sub users_read {
+    my $veid = shift;
+    my $name = shift;
+    my ($key, $val, @lines);
+    my %v = _build_report_hash($name);
 
-        my $ps_states = { 'paging' => 0, 'blocked' => 0, 'zombies' => 0, 'stopped' => 0,
-            'running' => 0, 'sleeping' => 0 };
-        my $state_map = { 'R' => 'running', 'S' => 'sleeping', 'D' => 'blocked',
-            'Z' => 'zombies', 'T' => 'stopped', 'W' => 'paging' };
+    $v{'plugin'} = 'users';
+    delete $v{'plugin_instance'};
+    $v{'type'} = 'users';
+    delete $v{'type_instance'};
 
-        $v{'plugin'} = 'processes';
-        delete $v{'plugin_instance'};
-        $v{'type'} = 'ps_state';
+    @lines = split(/\n/, `$vzctl exec $veid w -h`);
+    $v{'values'} = [ scalar(@lines) ];
+    plugin_dispatch_values(\%v);
+}
+
+sub _build_report_hash {
+    my $name = shift;
+    return (time => time(), interval => plugin_get_interval(), host => $name);
+}
 
-        @lines = map { (split)[2] } split(/\n/, `$vzctl exec $veid cat '/proc/[0-9]*/stat'`);
-        foreach $key (@lines)
-        {
-            ++$ps_states->{$state_map->{$key}};
+sub openvz_read {
+    my (@veids, $veid, $name);
+
+    @veids = map { s/ //g; $_; } split(/\n/, `$vzlist -Ho veid`);
+
+    foreach $veid (@veids) {
+        ($name = `$vzlist -Ho name $veid`) =~ s/^\s*(.*?)\s*$/$1/;
+        ($name = `$vzlist -Ho hostname $veid`) =~ s/^\s*(.*?)\s*$/$1/ if($name =~ /^-$/);
+        $name = $veid if ($name =~ /^-$/);
+
+        if($enable_interface) {
+            interface_read($veid, $name);
         }
 
-        foreach $key (keys %{$ps_states})
-        {
-            $v{'type_instance'} = $key;
-            $v{'values'} = [ $ps_states->{$key} ];
-            plugin_dispatch_values(\%v);
+        if($enable_cpu) {
+            cpu_read($veid, $name);
         }
 
-        #####################################################################
-        # users
+        if($enable_df) {
+            df_read($veid, $name);
+        }
 
-        $v{'plugin'} = 'users';
-        delete $v{'plugin_instance'};
-        $v{'type'} = 'users';
-        delete $v{'type_instance'};
+        if($enable_load) {
+            load_read($veid, $name);
+        }
 
-        @lines = split(/\n/, `$vzctl exec $veid w -h`);
-        $v{'values'} = [ scalar(@lines) ];
-        plugin_dispatch_values(\%v);
-    }
+        if($enable_processes) {
+            processes_read($veid, $name);
+        }
 
-    return 1;
+        if($enable_users) {
+            users_read($veid, $name);
+        }
+
+        return 1;
+    }
 }
 
 plugin_register(TYPE_READ, 'OpenVZ', 'openvz_read');
index 199a47c..2b3d8f5 100644 (file)
@@ -1,22 +1,27 @@
 #
-# collectd - Collectd::Unixsock
+# collectd - bindings/buildperl/Collectd/Unixsock.pm
 # Copyright (C) 2007,2008  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
-# Free Software Foundation; only version 2 of the License is applicable.
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
 #
-# 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.
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
 #
-# 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
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
 #
-# Author:
-#   Florian octo Forster <octo at verplant.org>
+# Authors:
+#   Florian Forster <octo at collectd.org>
 #
 
 package Collectd::Unixsock;
@@ -649,7 +654,7 @@ L<collectd-unixsock(5)>
 
 =head1 AUTHOR
 
-Florian octo Forster E<lt>octo@verplant.orgE<gt>
+Florian octo Forster E<lt>octo@collectd.orgE<gt>
 
 =cut
 
index d38cbb5..0df5678 100644 (file)
@@ -993,7 +993,7 @@ if test "x$fp_layout_type" = "xunknown"; then
        uint8_t c[8];
        double d;
 
-       d = 8.642135e130; 
+       d = 8.642135e130;
        memcpy ((void *) &i0, (void *) &d, 8);
 
        i1 = i0;
@@ -1048,7 +1048,7 @@ if test "x$fp_layout_type" = "xunknown"; then
        uint8_t c[8];
        double d;
 
-       d = 8.642135e130; 
+       d = 8.642135e130;
        memcpy ((void *) &i0, (void *) &d, 8);
 
        i1 = endianflip (i0);
@@ -1097,7 +1097,7 @@ if test "x$fp_layout_type" = "xunknown"; then
        uint8_t c[8];
        double d;
 
-       d = 8.642135e130; 
+       d = 8.642135e130;
        memcpy ((void *) &i0, (void *) &d, 8);
 
        i1 = intswap (i0);
@@ -1134,6 +1134,17 @@ else
   AC_MSG_ERROR([Didn't find out how doubles are stored in memory. Sorry.])
 fi; fi; fi
 
+# --with-useragent {{{
+AC_ARG_WITH(useragent, [AS_HELP_STRING([--with-useragent@<:@=AGENT@:>@], [User agent to use on http requests])],
+[
+    if test "x$withval" != "xno" && test "x$withval" != "xyes"
+    then
+        AC_DEFINE_UNQUOTED(COLLECTD_USERAGENT, ["$withval"], [User agent for http requests])
+    fi
+])
+
+# }}}
+
 have_getfsstat="no"
 AC_CHECK_FUNCS(getfsstat, [have_getfsstat="yes"])
 have_getvfsstat="no"
@@ -1235,7 +1246,7 @@ AC_CACHE_CHECK([if have htonll defined],
     )],
     [c_cv_have_htonll="yes"],
     [c_cv_have_htonll="no"]
-       )
+  )
 )
 if test "x$c_cv_have_htonll" = "xyes"
 then
@@ -1389,7 +1400,7 @@ collectd additional packages:])
 
 AM_CONDITIONAL([BUILD_FREEBSD],[test "x$x$ac_system" = "xFreeBSD"])
 
-AM_CONDITIONAL([BUILD_AIX],[test "x$x$ac_system" = "xAIX"]) 
+AM_CONDITIONAL([BUILD_AIX],[test "x$x$ac_system" = "xAIX"])
 
 if test "x$ac_system" = "xAIX"
 then
@@ -1719,6 +1730,7 @@ then
        LDFLAGS="$LDFLAGS $with_libdbi_ldflags"
 
        AC_CHECK_LIB(dbi, dbi_initialize, [with_libdbi="yes"], [with_libdbi="no (Symbol 'dbi_initialize' not found)"])
+       AC_CHECK_LIB(dbi, dbi_driver_open_r, [with_libdbi_r="yes"], [with_libdbi_r="no"])
 
        CPPFLAGS="$SAVE_CPPFLAGS"
        LDFLAGS="$SAVE_LDFLAGS"
@@ -1731,6 +1743,11 @@ then
        AC_SUBST(BUILD_WITH_LIBDBI_CPPFLAGS)
        AC_SUBST(BUILD_WITH_LIBDBI_LDFLAGS)
        AC_SUBST(BUILD_WITH_LIBDBI_LIBS)
+
+  if test "x$with_libdbi_r" = "xyes"
+  then
+               AC_DEFINE(HAVE_LIBDBI_R, 1, [Define if reentrant dbi facility is present and usable.])
+  fi
 fi
 AM_CONDITIONAL(BUILD_WITH_LIBDBI, test "x$with_libdbi" = "xyes")
 # }}}
@@ -1949,10 +1966,7 @@ AM_CONDITIONAL(BUILD_WITH_LIBGCRYPT, test "x$with_libgcrypt" = "xyes")
 # --with-libiptc {{{
 AC_ARG_WITH(libiptc, [AS_HELP_STRING([--with-libiptc@<:@=PREFIX@:>@], [Path to libiptc.])],
 [
-       if test "x$withval" = "xshipped"
-       then
-               with_libiptc="own"
-       else if test "x$withval" = "xyes"
+       if test "x$withval" = "xyes"
        then
                with_libiptc="pkgconfig"
        else if test "x$withval" = "xno"
@@ -1962,7 +1976,7 @@ AC_ARG_WITH(libiptc, [AS_HELP_STRING([--with-libiptc@<:@=PREFIX@:>@], [Path to l
                with_libiptc="yes"
                with_libiptc_cflags="-I$withval/include"
                with_libiptc_libs="-L$withval/lib"
-       fi; fi; fi
+       fi; fi
 ],
 [
        if test "x$ac_system" = "xLinux"
@@ -2034,28 +2048,6 @@ fi
 
 CPPFLAGS="$SAVE_CPPFLAGS"
 
-if test "x$with_libiptc" = "xown"
-then
-       with_libiptc_cflags=""
-       with_libiptc_libs=""
-fi
-if test "x$with_libiptc" = "xown"
-then
-       AC_CHECK_HEADERS(linux/netfilter_ipv4/ip_tables.h linux/netfilter_ipv6/ip6_tables.h linux/netfilter/x_tables.h, [],
-       [
-               with_libiptc="no (Linux iptables headers not found)"
-       ],
-       [
-#include "$srcdir/src/owniptc/ipt_kernel_headers.h"
-       ])
-fi
-AM_CONDITIONAL(BUILD_WITH_OWN_LIBIPTC, test "x$with_libiptc" = "xown")
-if test "x$with_libiptc" = "xown"
-then
-       AC_DEFINE(OWN_LIBIPTC, 1, [Define to 1 if we use the shipped iptc library.])
-       with_libiptc="yes"
-fi
-
 AM_CONDITIONAL(BUILD_WITH_LIBIPTC, test "x$with_libiptc" = "xyes")
 if test "x$with_libiptc" = "xyes"
 then
@@ -2269,7 +2261,7 @@ then
         CPPFLAGS="$CPPFLAGS $with_liblvm2app_cppflags"
         LDFLAGS="$LDFLAGS $with_liblvm2app_ldflags"
 
-        AC_CHECK_LIB(lvm2app, lvm_init, [with_liblvm2app="yes"], [with_liblvm2app="no (Symbol 'lvm_init' not found)"])
+        AC_CHECK_LIB(lvm2app, lvm_lv_get_property, [with_liblvm2app="yes"], [with_liblvm2app="no (Symbol 'lvm_lv_get_property' not found)"])
 
         CPPFLAGS="$SAVE_CPPFLAGS"
         LDFLAGS="$SAVE_LDFLAGS"
@@ -2671,6 +2663,15 @@ return (retval);
 fi
 if test "x$with_libmnl" = "xyes"
 then
+       AC_CHECK_MEMBERS([struct rtnl_link_stats64.tx_window_errors],
+       [AC_DEFINE(HAVE_RTNL_LINK_STATS64, 1, [Define if struct rtnl_link_stats64 exists and is usable.])],
+       [],
+       [
+       #include <linux/if_link.h>
+       ])
+fi
+if test "x$with_libmnl" = "xyes"
+then
        AC_CHECK_LIB(mnl, mnl_nlmsg_get_payload,
                     [with_libmnl="yes"],
                     [with_libmnl="no (symbol 'mnl_nlmsg_get_payload' not found)"],
@@ -2794,7 +2795,7 @@ then
        else
                SAVE_CPPFLAGS="$CPPFLAGS"
                CPPFLAGS="$CPPFLAGS $with_snmp_cflags"
-               
+
                AC_CHECK_HEADERS(net-snmp/net-snmp-config.h, [], [with_libnetsnmp="no (net-snmp/net-snmp-config.h not found)"])
 
                CPPFLAGS="$SAVE_CPPFLAGS"
@@ -3021,7 +3022,7 @@ if test "x$with_libowcapi" = "xyes"
 then
        SAVE_CPPFLAGS="$CPPFLAGS"
        CPPFLAGS="$with_libowcapi_cppflags"
-       
+
        AC_CHECK_HEADERS(owcapi.h, [with_libowcapi="yes"], [with_libowcapi="no (owcapi.h not found)"])
 
        CPPFLAGS="$SAVE_CPPFLAGS"
@@ -3032,7 +3033,7 @@ then
        SAVE_CPPFLAGS="$CPPFLAGS"
        LDFLAGS="$with_libowcapi_libs"
        CPPFLAGS="$with_libowcapi_cppflags"
-       
+
        AC_CHECK_LIB(owcapi, OW_get, [with_libowcapi="yes"], [with_libowcapi="no (libowcapi not found)"])
 
        LDFLAGS="$SAVE_LDFLAGS"
@@ -3632,6 +3633,59 @@ then
 fi
 # }}}
 
+# --with-librdkafka {{{
+AC_ARG_WITH(librdkafka, [AS_HELP_STRING([--with-librdkafka@<:@=PREFIX@:>@], [Path to librdkafka.])],
+[
+  if test "x$withval" = "xno" && test "x$withval" != "xyes"
+  then
+    with_librdkafka_cppflags="-I$withval/include"
+    with_librdkafka_ldflags="-L$withval/lib"
+    with_librdkafka="yes"
+  else
+    with_librdkafka="$withval"
+  fi
+],
+[
+  with_librdkafka="yes"
+])
+SAVE_CPPFLAGS="$CPPFLAGS"
+SAVE_LDFLAGS="$LDFLAGS"
+
+if test "x$with_librdkafka" = "xyes"
+then
+       AC_CHECK_HEADERS(librdkafka/rdkafka.h, [with_librdkafka="yes"], [with_librdkafka="no (librdkafka/rdkafka.h not found)"])
+fi
+
+if test "x$with_librdkafka" = "xyes"
+then
+       AC_CHECK_LIB(rdkafka, rd_kafka_new, [with_librdkafka="yes"], [with_librdkafka="no (Symbol 'rd_kafka_new' not found)"])
+  AC_CHECK_LIB(rdkafka, rd_kafka_conf_set_log_cb, [with_librdkafka_log_cb="yes"], [with_librdkafka_log_cb="no"])
+  AC_CHECK_LIB(rdkafka, rd_kafka_conf_set_logger, [with_librdkafka_logger="yes"], [with_librdkafka_logger="no"])
+fi
+if test "x$with_librdkafka" = "xyes"
+then
+       BUILD_WITH_LIBRDKAFKA_CPPFLAGS="$with_librdkafka_cppflags"
+       BUILD_WITH_LIBRDKAFKA_LDFLAGS="$with_librdkafka_ldflags"
+       BUILD_WITH_LIBRDKAFKA_LIBS="-lrdkafka"
+       AC_SUBST(BUILD_WITH_LIBRDKAFKA_CPPFLAGS)
+       AC_SUBST(BUILD_WITH_LIBRDKAFKA_LDFLAGS)
+       AC_SUBST(BUILD_WITH_LIBRDKAFKA_LIBS)
+       AC_DEFINE(HAVE_LIBRDKAFKA, 1, [Define if librdkafka is present and usable.])
+  if test "x$with_librdkafka_log_cb" = "xyes"
+  then
+        AC_DEFINE(HAVE_LIBRDKAFKA_LOG_CB, 1, [Define if librdkafka log facility is present and usable.])
+  fi
+  if test "x$with_librdkafka_logger" = "xyes"
+  then
+        AC_DEFINE(HAVE_LIBRDKAFKA_LOGGER, 1, [Define if librdkafka log facility is present and usable.])
+  fi
+fi
+CPPFLAGS="$SAVE_CPPFLAGS"
+LDFLAGS="$SAVE_LDFLAGS"
+AM_CONDITIONAL(BUILD_WITH_LIBRDKAFKA, test "x$with_librdkafka" = "xyes")
+
+# }}}
+
 # --with-librouteros {{{
 AC_ARG_WITH(librouteros, [AS_HELP_STRING([--with-librouteros@<:@=PREFIX@:>@], [Path to librouteros.])],
 [
@@ -4076,7 +4130,7 @@ CPPFLAGS="$SAVE_CPPFLAGS"
 LDFLAGS="$SAVE_LDFLAGS"
 
 if test "x$with_libtokyotyrant" = "xyes"
-then 
+then
   BUILD_WITH_LIBTOKYOTYRANT_CPPFLAGS="$with_libtokyotyrant_cppflags"
   BUILD_WITH_LIBTOKYOTYRANT_LDFLAGS="$with_libtokyotyrant_ldflags"
   BUILD_WITH_LIBTOKYOTYRANT_LIBS="$with_libtokyotyrant_libs"
@@ -4087,6 +4141,67 @@ fi
 AM_CONDITIONAL(BUILD_WITH_LIBTOKYOTYRANT, test "x$with_libtokyotyrant" = "xyes")
 # }}}
 
+# --with-libudev {{{
+with_libudev_cflags=""
+with_libudev_ldflags=""
+AC_ARG_WITH(libudev, [AS_HELP_STRING([--with-libudev@<:@=PREFIX@:>@], [Path to libudev.])],
+[
+       if test "x$withval" = "xno"
+       then
+               with_libudev="no"
+       else
+               with_libudev="yes"
+               if test "x$withval" != "xyes"
+               then
+                       with_libudev_cflags="-I$withval/include"
+                       with_libudev_ldflags="-L$withval/lib"
+                       with_libudev="yes"
+               fi
+       fi
+],
+[
+       if test "x$ac_system" = "xLinux"
+       then
+               with_libudev="yes"
+       else
+               with_libudev="no (Linux only library)"
+       fi
+])
+if test "x$with_libudev" = "xyes"
+then
+       SAVE_CPPFLAGS="$CPPFLAGS"
+       CPPFLAGS="$CPPFLAGS $with_libudev_cflags"
+
+       AC_CHECK_HEADERS(libudev.h, [], [with_libudev="no (libudev.h not found)"])
+
+       CPPFLAGS="$SAVE_CPPFLAGS"
+fi
+if test "x$with_libudev" = "xyes"
+then
+       SAVE_CPPFLAGS="$CPPFLAGS"
+       SAVE_LDFLAGS="$LDFLAGS"
+       CPPFLAGS="$CPPFLAGS $with_libudev_cflags"
+       LDFLAGS="$LDFLAGS $with_libudev_ldflags"
+
+       AC_CHECK_LIB(udev, udev_new,
+       [
+               AC_DEFINE(HAVE_LIBUDEV, 1, [Define to 1 if you have the udev library (-ludev).])
+       ],
+       [with_libudev="no (libudev not found)"])
+
+       CPPFLAGS="$SAVE_CPPFLAGS"
+       LDFLAGS="$SAVE_LDFLAGS"
+fi
+if test "x$with_libudev" = "xyes"
+then
+       BUILD_WITH_LIBUDEV_CFLAGS="$with_libudev_cflags"
+       BUILD_WITH_LIBUDEV_LDFLAGS="$with_libudev_ldflags"
+       AC_SUBST(BUILD_WITH_LIBUDEV_CFLAGS)
+       AC_SUBST(BUILD_WITH_LIBUDEV_LDFLAGS)
+fi
+AM_CONDITIONAL(BUILD_WITH_LIBUDEV, test "x$with_libudev" = "xyes")
+# }}}
+
 # --with-libupsclient {{{
 with_libupsclient_config=""
 with_libupsclient_cflags=""
@@ -4823,6 +4938,7 @@ dependency_warning="no"
 dependency_error="no"
 
 plugin_ascent="no"
+plugin_barometer="no"
 plugin_battery="no"
 plugin_bind="no"
 plugin_cgroups="no"
@@ -4834,6 +4950,7 @@ plugin_curl_json="no"
 plugin_curl_xml="no"
 plugin_df="no"
 plugin_disk="no"
+plugin_drbd="no"
 plugin_entropy="no"
 plugin_ethstat="no"
 plugin_fscache="no"
@@ -4843,6 +4960,7 @@ plugin_ipvs="no"
 plugin_irq="no"
 plugin_libvirt="no"
 plugin_load="no"
+plugin_log_logstash="no"
 plugin_memory="no"
 plugin_multimeter="no"
 plugin_nfs="no"
@@ -4873,6 +4991,7 @@ then
        plugin_cpu="yes"
        plugin_cpufreq="yes"
        plugin_disk="yes"
+       plugin_drbd="yes"
        plugin_entropy="yes"
        plugin_fscache="yes"
        plugin_interface="yes"
@@ -4960,6 +5079,23 @@ then
        plugin_tape="yes"
 fi
 
+# libi2c-dev
+with_libi2c="no"
+if test "x$ac_system" = "xLinux"
+then
+AC_CHECK_DECL(i2c_smbus_read_i2c_block_data,
+       [with_libi2c="yes"],
+       [with_libi2c="no (symbol i2c_smbus_read_i2c_block_data not found - have you installed libi2c-dev ?)"],
+       [[#include <stdlib.h>
+       #include <linux/i2c-dev.h>]])
+fi
+
+if test "x$with_libi2c" = "xyes"
+then
+       plugin_barometer="yes"
+fi
+
+
 # libstatgrab
 if test "x$with_libstatgrab" = "xyes"
 then
@@ -5073,6 +5209,11 @@ then
        plugin_load="yes"
 fi
 
+if test "x$with_libyajl" = "xyes"
+then
+       plugin_log_logstash="yes"
+fi
+
 if test "x$c_cv_have_libperl$c_cv_have_perl_ithreads" = "xyesyes"
 then
        plugin_perl="yes"
@@ -5086,7 +5227,10 @@ fi
 
 if test "x$have_termios_h" = "xyes"
 then
-       plugin_multimeter="yes"
+       if test "x$ac_system" != "xAIX"
+       then
+               plugin_multimeter="yes"
+       fi
        plugin_ted="yes"
 fi
 
@@ -5151,6 +5295,7 @@ AC_PLUGIN([apcups],      [yes],                [Statistics of UPSes by APC])
 AC_PLUGIN([apple_sensors], [$with_libiokit],   [Apple's hardware sensors])
 AC_PLUGIN([aquaero],     [$with_libaquaero5],  [Aquaero's hardware sensors])
 AC_PLUGIN([ascent],      [$plugin_ascent],     [AscentEmu player statistics])
+AC_PLUGIN([barometer],   [$plugin_barometer],  [Barometer sensor on I2C])
 AC_PLUGIN([battery],     [$plugin_battery],    [Battery statistics])
 AC_PLUGIN([bind],        [$plugin_bind],       [ISC Bind nameserver statistics])
 AC_PLUGIN([conntrack],   [$plugin_conntrack],  [nf_conntrack statistics])
@@ -5165,6 +5310,7 @@ AC_PLUGIN([cgroups],     [$plugin_cgroups],    [CGroups CPU usage accounting])
 AC_PLUGIN([dbi],         [$with_libdbi],       [General database statistics])
 AC_PLUGIN([df],          [$plugin_df],         [Filesystem usage statistics])
 AC_PLUGIN([disk],        [$plugin_disk],       [Disk usage statistics])
+AC_PLUGIN([drbd],        [$plugin_drbd],       [DRBD statistics])
 AC_PLUGIN([dns],         [$with_libpcap],      [DNS traffic analysis])
 AC_PLUGIN([email],       [yes],                [EMail statistics])
 AC_PLUGIN([entropy],     [$plugin_entropy],    [Entropy statistics])
@@ -5183,6 +5329,7 @@ AC_PLUGIN([java],        [$with_java],         [Embed the Java Virtual Machine])
 AC_PLUGIN([libvirt],     [$plugin_libvirt],    [Virtual machine statistics])
 AC_PLUGIN([load],        [$plugin_load],       [System load])
 AC_PLUGIN([logfile],     [yes],                [File logging plugin])
+AC_PLUGIN([log_logstash], [$plugin_log_logstash], [Logstash json_event compatible logging])
 AC_PLUGIN([lpar],        [$with_perfstat],     [AIX logical partitions statistics])
 AC_PLUGIN([lvm],         [$with_liblvm2app],   [LVM statistics])
 AC_PLUGIN([madwifi],     [$have_linux_wireless_h], [Madwifi wireless statistics])
@@ -5260,9 +5407,11 @@ AC_PLUGIN([vserver],     [$plugin_vserver],    [Linux VServer statistics])
 AC_PLUGIN([wireless],    [$plugin_wireless],   [Wireless statistics])
 AC_PLUGIN([write_graphite], [yes],             [Graphite / Carbon output plugin])
 AC_PLUGIN([write_http],  [$with_libcurl],      [HTTP output plugin])
+AC_PLUGIN([write_kafka],  [$with_librdkafka],  [Kafka output plugin])
 AC_PLUGIN([write_mongodb], [$with_libmongoc],  [MongoDB output plugin])
 AC_PLUGIN([write_redis], [$with_libcredis],    [Redis output plugin])
 AC_PLUGIN([write_riemann], [$have_protoc_c],   [Riemann output plugin])
+AC_PLUGIN([write_tsdb],  [yes],                [TSDB output plugin])
 AC_PLUGIN([xmms],        [$with_libxmms],      [XMMS statistics])
 AC_PLUGIN([zfs_arc],     [$plugin_zfs_arc],    [ZFS ARC statistics])
 
@@ -5270,6 +5419,7 @@ dnl Default configuration file
 # Load either syslog or logfile
 LOAD_PLUGIN_SYSLOG=""
 LOAD_PLUGIN_LOGFILE=""
+LOAD_PLUGIN_LOG_LOGSTASH=""
 
 AC_MSG_CHECKING([which default log plugin to load])
 default_log_plugin="none"
@@ -5291,10 +5441,20 @@ then
 else
        LOAD_PLUGIN_LOGFILE="##"
 fi
+
+if test "x$enable_log_logstash" = "xyes"
+then
+  LOAD_PLUGIN_LOG_LOGSTASH="#"
+else
+  LOAD_PLUGIN_LOG_LOGSTASH="##"
+fi
+
+
 AC_MSG_RESULT([$default_log_plugin])
 
 AC_SUBST(LOAD_PLUGIN_SYSLOG)
 AC_SUBST(LOAD_PLUGIN_LOGFILE)
+AC_SUBST(LOAD_PLUGIN_LOG_LOGSTASH)
 
 DEFAULT_LOG_LEVEL="info"
 if test "x$enable_debug" = "xyes"
@@ -5443,11 +5603,13 @@ Configuration:
     libesmtp  . . . . . . $with_libesmtp
     libganglia  . . . . . $with_libganglia
     libgcrypt . . . . . . $with_libgcrypt
+    libi2c-dev  . . . . . $with_libi2c
     libiokit  . . . . . . $with_libiokit
     libiptc . . . . . . . $with_libiptc
     libjvm  . . . . . . . $with_java
     libkstat  . . . . . . $with_kstat
     libkvm  . . . . . . . $with_libkvm
+    liblvm2app  . . . . . $with_liblvm2app
     libmemcached  . . . . $with_libmemcached
     libmnl  . . . . . . . $with_libmnl
     libmodbus . . . . . . $with_libmodbus
@@ -5464,12 +5626,14 @@ Configuration:
     libpq . . . . . . . . $with_libpq
     libpthread  . . . . . $with_libpthread
     librabbitmq . . . . . $with_librabbitmq
+    librdkafka  . . . . . $with_librdkafka
     librouteros . . . . . $with_librouteros
     librrd  . . . . . . . $with_librrd
     libsensors  . . . . . $with_libsensors
     libsigrok   . . . . . $with_libsigrok
     libstatgrab . . . . . $with_libstatgrab
     libtokyotyrant  . . . $with_libtokyotyrant
+    libudev . . . . . . . $with_libudev
     libupsclient  . . . . $with_libupsclient
     libvarnish  . . . . . $with_libvarnish
     libvirt . . . . . . . $with_libvirt
@@ -5496,6 +5660,7 @@ Configuration:
     aquaero . . . . . . . $enable_aquaero
     apple_sensors . . . . $enable_apple_sensors
     ascent  . . . . . . . $enable_ascent
+    barometer . . . . . . $enable_barometer
     battery . . . . . . . $enable_battery
     bind  . . . . . . . . $enable_bind
     conntrack . . . . . . $enable_conntrack
@@ -5511,6 +5676,7 @@ Configuration:
     df  . . . . . . . . . $enable_df
     disk  . . . . . . . . $enable_disk
     dns . . . . . . . . . $enable_dns
+    drbd  . . . . . . . . $enable_drbd
     email . . . . . . . . $enable_email
     entropy . . . . . . . $enable_entropy
     ethstat . . . . . . . $enable_ethstat
@@ -5529,6 +5695,7 @@ Configuration:
     load  . . . . . . . . $enable_load
     logfile . . . . . . . $enable_logfile
     lpar  . . . . . . . . $enable_lpar
+    log_logstash  . . . . $enable_log_logstash
     lvm . . . . . . . . . $enable_lvm
     madwifi . . . . . . . $enable_madwifi
     match_empty_counter . $enable_match_empty_counter
@@ -5604,9 +5771,11 @@ Configuration:
     wireless  . . . . . . $enable_wireless
     write_graphite  . . . $enable_write_graphite
     write_http  . . . . . $enable_write_http
+    write_kafka . . . . . $enable_write_kafka
     write_mongodb . . . . $enable_write_mongodb
     write_redis . . . . . $enable_write_redis
     write_riemann . . . . $enable_write_riemann
+    write_tsdb  . . . . . $enable_write_tsdb
     xmms  . . . . . . . . $enable_xmms
     zfs_arc . . . . . . . $enable_zfs_arc
 
index af64fb1..5ff259f 100755 (executable)
@@ -1,4 +1,25 @@
 #!/usr/bin/perl
+# Copyright (c) 2006-2010 Florian Forster <octo at collectd.org>
+# Copyright (c) 2006-2008 Sebastian Harl <sh at tokkee.org>
+# Copyright (c) 2008      Mirko Buffoni <briareos at eswat.org>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
 
 use strict;
 use warnings;
@@ -507,6 +528,7 @@ sub _custom_sort_arrayref
 {
   my $array_ref = shift;
   my $array_sort = shift;
+  my $unknown_first = shift || 0;
 
   my %elements = map { $_ => 1 } (@$array_ref);
   splice (@$array_ref, 0);
@@ -517,7 +539,12 @@ sub _custom_sort_arrayref
     push (@$array_ref, $_);
     delete ($elements{$_});
   }
-  push (@$array_ref, sort (keys %elements));
+  if ($unknown_first) {
+    unshift (@$array_ref, sort (keys %elements));
+  }
+  else {
+    push (@$array_ref, sort (keys %elements));
+  }
 } # _custom_sort_arrayref
 
 sub action_show_host
@@ -957,9 +984,9 @@ sub load_graph_definitions
 
   $GraphDefs =
   {
-    apache_bytes => ['DEF:min_raw={file}:count:MIN',
-    'DEF:avg_raw={file}:count:AVERAGE',
-    'DEF:max_raw={file}:count:MAX',
+    apache_bytes => ['DEF:min_raw={file}:value:MIN',
+    'DEF:avg_raw={file}:value:AVERAGE',
+    'DEF:max_raw={file}:value:MAX',
     'CDEF:min=min_raw,8,*',
     'CDEF:avg=avg_raw,8,*',
     'CDEF:max=max_raw,8,*',
@@ -976,9 +1003,9 @@ sub load_graph_definitions
     'GPRINT:avg:LAST:%5.1lf%s Last',
     'GPRINT:avg_sum:LAST:(ca. %5.1lf%sB Total)\l'
     ],
-   apache_connections => ['DEF:min={file}:count:MIN',
-    'DEF:avg={file}:count:AVERAGE',
-    'DEF:max={file}:count:MAX',
+   apache_connections => ['DEF:min={file}:value:MIN',
+    'DEF:avg={file}:value:AVERAGE',
+    'DEF:max={file}:value:MAX',
     "AREA:max#$HalfBlue",
     "AREA:min#$Canvas",
     "LINE1:avg#$FullBlue:Connections",
@@ -987,9 +1014,9 @@ sub load_graph_definitions
     'GPRINT:max:MAX:%6.2lf Max,',
     'GPRINT:avg:LAST:%6.2lf Last'
     ],
-    apache_idle_workers => ['DEF:min={file}:count:MIN',
-    'DEF:avg={file}:count:AVERAGE',
-    'DEF:max={file}:count:MAX',
+    apache_idle_workers => ['DEF:min={file}:value:MIN',
+    'DEF:avg={file}:value:AVERAGE',
+    'DEF:max={file}:value:MAX',
     "AREA:max#$HalfBlue",
     "AREA:min#$Canvas",
     "LINE1:avg#$FullBlue:Idle Workers",
@@ -998,9 +1025,9 @@ sub load_graph_definitions
     'GPRINT:max:MAX:%6.2lf Max,',
     'GPRINT:avg:LAST:%6.2lf Last'
     ],
-    apache_requests => ['DEF:min={file}:count:MIN',
-    'DEF:avg={file}:count:AVERAGE',
-    'DEF:max={file}:count:MAX',
+    apache_requests => ['DEF:min={file}:value:MIN',
+    'DEF:avg={file}:value:AVERAGE',
+    'DEF:max={file}:value:MAX',
     "AREA:max#$HalfBlue",
     "AREA:min#$Canvas",
     "LINE1:avg#$FullBlue:Requests/s",
@@ -1009,9 +1036,9 @@ sub load_graph_definitions
     'GPRINT:max:MAX:%6.2lf Max,',
     'GPRINT:avg:LAST:%6.2lf Last'
     ],
-    apache_scoreboard => ['DEF:min={file}:count:MIN',
-    'DEF:avg={file}:count:AVERAGE',
-    'DEF:max={file}:count:MAX',
+    apache_scoreboard => ['DEF:min={file}:value:MIN',
+    'DEF:avg={file}:value:AVERAGE',
+    'DEF:max={file}:value:MAX',
     "AREA:max#$HalfBlue",
     "AREA:min#$Canvas",
     "LINE1:avg#$FullBlue:Processes",
@@ -2676,6 +2703,7 @@ sub load_graph_definitions
   $GraphDefs->{'virt_cpu_total'} = $GraphDefs->{'virt_cpu_total'};
 
   $MetaGraphDefs->{'cpu'} = \&meta_graph_cpu;
+  $MetaGraphDefs->{'df_complex'} = \&meta_graph_df;
   $MetaGraphDefs->{'dns_qtype'} = \&meta_graph_dns;
   $MetaGraphDefs->{'dns_rcode'} = \&meta_graph_dns;
   $MetaGraphDefs->{'if_rx_errors'} = \&meta_graph_if_rx_errors;
@@ -2858,6 +2886,73 @@ sub meta_graph_cpu
   return (meta_graph_generic_stack ($opts, $sources));
 } # meta_graph_cpu
 
+sub meta_graph_df
+{
+  confess ("Wrong number of arguments") if (@_ != 5);
+
+  my $host = shift;
+  my $plugin = shift;
+  my $plugin_instance = shift;
+  my $type = shift;
+  my $type_instances = shift;
+
+  my $opts = {};
+  my $sources = [];
+
+  my $prefix = "$host/$plugin"
+  . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type";
+
+  $opts->{'title'} = "Disk usage $prefix";
+
+  $opts->{'number_format'} = '%5.1lf%s';
+  $opts->{'rrd_opts'} = ['-l', 0, '-b', '1024', '-v', 'Bytes'];
+
+  my @files = ();
+
+  $opts->{'colors'} =
+  {
+    'used'              => 'ff0000',
+    'snap_normal_used'  => 'c10640',
+    'snap_reserve_used' => '820c81',
+    'snap_reserved'     => 'f15aef',
+    'reserved'          => 'ffb000',
+    'free'              => '00ff00',
+    'sis_saved'         => '00e0e0',
+    'dedup_saved'       => '00c1c1',
+    'compression_saved' => '00a2a2'
+  };
+
+  # LVM uses LV names as type-instance; they should sort first
+  _custom_sort_arrayref ($type_instances,
+    [qw(compression_saved dedup_saved sis_saved free reserved snap_reserved
+      snap_reserve_used snap_normal_used used)], 1);
+
+  for (@$type_instances)
+  {
+    my $inst = $_;
+    my $file = '';
+
+    for (@DataDirs)
+    {
+      if (-e "$_/$prefix-$inst.rrd")
+      {
+       $file = "$_/$prefix-$inst.rrd";
+       last;
+      }
+    }
+    confess ("No file found for $prefix") if ($file eq '');
+
+    push (@$sources,
+      {
+       name => $inst,
+       file => $file
+      }
+    );
+  } # for (@$type_instances)
+
+  return (meta_graph_generic_stack ($opts, $sources));
+} # meta_graph_df
+
 sub meta_graph_dns
 {
   confess ("Wrong number of arguments") if (@_ != 5);
index d20be35..a376002 100644 (file)
@@ -44,7 +44,7 @@ return (1);
 =item B<gc_read_config> (I<$file>)
 
 Reads the configuration from the file located at I<$file>. Returns B<true> when
-successfull and B<false> otherwise.
+successful and B<false> otherwise.
 
 =cut
 
index 42582a7..36f8706 100644 (file)
@@ -43,7 +43,7 @@ return (1);
 =item B<gc_read_config> (I<$file>)
 
 Reads the configuration from the file located at I<$file>. Returns B<true> when
-successfull and B<false> otherwise.
+successful and B<false> otherwise.
 
 =cut
 
index 5a0b522..3d6f61e 100644 (file)
@@ -59,7 +59,7 @@ sub _create_object
   my $module = shift;
   my $obj;
 
-  # Surpress warnings and error messages caused by the eval.
+  # Suppress warnings and error messages caused by the eval.
   local $SIG{__WARN__} = sub { return (1); print STDERR "WARNING: " . join (', ', @_) . "\n"; };
   local $SIG{__DIE__}  = sub { return (1); print STDERR "FATAL: "   . join (', ', @_) . "\n"; };
 
index f68cc1a..9539062 100644 (file)
@@ -100,14 +100,16 @@ static int my_read (void)
        vl.time       = time (NULL);
        sstrncpy (vl.host, hostname_g, sizeof (vl.host));
        sstrncpy (vl.plugin, "myplugin", sizeof (vl.plugin));
+
+       /* it is strongly recommended to use a type defined in the types.db file
+        * instead of a custom type */
+       sstrncpy (vl.type, "myplugin", sizeof (vl.plugin));
        /* optionally set vl.plugin_instance and vl.type_instance to reasonable
         * values (default: "") */
 
        /* dispatch the values to collectd which passes them on to all registered
-        * write functions - the first argument is used to lookup the data set
-        * definition (it is strongly recommended to use a type defined in the
-        * types.db file) */
-       plugin_dispatch_values ("myplugin", &vl);
+        * write functions */
+       plugin_dispatch_values (&vl);
 
        /* A return value != 0 indicates an error and the plugin will be skipped
         * for an increasing amount of time. */
@@ -117,7 +119,8 @@ static int my_read (void)
 /*
  * This function is called after values have been dispatched to collectd.
  */
-static int my_write (const data_set_t *ds, const value_list_t *vl)
+static int my_write (const data_set_t *ds, const value_list_t *vl,
+               user_data_t *ud)
 {
        char name[1024] = "";
        int i = 0;
@@ -151,7 +154,7 @@ static int my_write (const data_set_t *ds, const value_list_t *vl)
 /*
  * This function is called when plugin_log () has been used.
  */
-static void my_log (int severity, const char *msg)
+static void my_log (int severity, const char *msg, user_data_t *ud)
 {
        printf ("LOG: %i - %s\n", severity, msg);
        return;
@@ -160,7 +163,7 @@ static void my_log (int severity, const char *msg)
 /*
  * This function is called when plugin_dispatch_notification () has been used.
  */
-static int my_notify (const notification_t *notif)
+static int my_notify (const notification_t *notif, user_data_t *ud)
 {
        char time_str[32] = "";
        struct tm *tm = NULL;
@@ -210,12 +213,13 @@ static int my_shutdown (void)
  */
 void module_register (void)
 {
-       plugin_register_log ("myplugin", my_log);
-       plugin_register_notification ("myplugin", my_notify);
+       plugin_register_log ("myplugin", my_log, /* user data */ NULL);
+       plugin_register_notification ("myplugin", my_notify,
+                       /* user data */ NULL);
        plugin_register_data_set (&ds);
        plugin_register_read ("myplugin", my_read);
        plugin_register_init ("myplugin", my_init);
-       plugin_register_write ("myplugin", my_write);
+       plugin_register_write ("myplugin", my_write, /* user data */ NULL);
        plugin_register_shutdown ("myplugin", my_shutdown);
     return;
 } /* void module_register (void) */
index b9fefa6..fdfcbaa 100644 (file)
@@ -86,7 +86,7 @@ function error($code, $code_msg, $title, $msg) {
        imagestring($png, 4, ceil(($w-strlen($title)*imagefontwidth(4)) / 2), 10, $title, $c_txt);
        imagestring($png, 5, 60, 35, sprintf('%s [%d]', $code_msg, $code), $c_etxt);
        if (function_exists('imagettfbbox') && is_file($config['error_font'])) {
-               // Detailled error message
+               // Detailed error message
                $fmt_msg = makeTextBlock($msg, $errorfont, 10, $w-86);
                $fmtbox  = imagettfbbox(12, 0, $errorfont, $fmt_msg);
                imagettftext($png, 10, 0, 55, 35+3+imagefontwidth(5)-$fmtbox[7]+$fmtbox[1], $c_txt, $errorfont, $fmt_msg);
index 00c5519..bee182c 100644 (file)
@@ -33,8 +33,8 @@
 -- and 'values' to store the value-list identifier and the actual values
 -- respectively.
 --
--- The 'values' table is partitioned to improve performance and maintainance.
--- Please note that additional maintainance scripts are required in order to
+-- The 'values' table is partitioned to improve performance and maintenance.
+-- Please note that additional maintenance scripts are required in order to
 -- keep the setup running -- see the comments below for details.
 --
 -- The function 'collectd_insert' may be used to actually insert values
index 43704c4..9facca8 100644 (file)
@@ -2072,7 +2072,7 @@ fi
 * Sat Nov 17 2012 Ruben Kerkhof <ruben@tilaa.nl> 5.1.0-2
 - Move perl stuff to perl_vendorlib
 - Replace hardcoded paths with macros
-- Remove unneccesary Requires
+- Remove unnecessary Requires
 - Removed .a and .la files
 - Some other small cleanups
 
@@ -2080,7 +2080,7 @@ fi
 - New upstream version
 - Changes to support 5.1.0
 - Enabled all buildable plugins based on libraries available on EL6 + EPEL
-- All plugins requiring external libraries are now shipped in seperate
+- All plugins requiring external libraries are now shipped in separate
   packages.
 - No longer treat Java plugin as an exception, correctly set $JAVA_HOME during
   the build process + ensure build deps are installed.
index 36ce028..d727566 100644 (file)
@@ -17,6 +17,8 @@ endif
 AM_CPPFLAGS += -DPLUGINDIR='"${pkglibdir}"'
 AM_CPPFLAGS += -DPKGDATADIR='"${pkgdatadir}"'
 
+AUTOMAKE_OPTIONS = subdir-objects
+
 sbin_PROGRAMS = collectd collectdmon
 bin_PROGRAMS = collectd-nagios collectdctl collectd-tg
 
@@ -39,7 +41,9 @@ collectd_SOURCES = collectd.c collectd.h \
                   utils_subst.c utils_subst.h \
                   utils_tail.c utils_tail.h \
                   utils_time.c utils_time.h \
-                  types_list.c types_list.h
+                  types_list.c types_list.h \
+                  utils_threshold.c utils_threshold.h
+
 
 collectd_CPPFLAGS =  $(AM_CPPFLAGS) $(LTDLINCL)
 collectd_CFLAGS = $(AM_CFLAGS)
@@ -133,9 +137,9 @@ collectd_tg_LDADD += libcollectdclient/libcollectdclient.la
 collectd_tg_DEPENDENCIES = libcollectdclient/libcollectdclient.la
 
 
-pkglib_LTLIBRARIES = 
+pkglib_LTLIBRARIES =
 
-BUILT_SOURCES = 
+BUILT_SOURCES =
 CLEANFILES =
 
 if BUILD_PLUGIN_AGGREGATION
@@ -217,6 +221,15 @@ collectd_LDADD += "-dlopen" ascent.la
 collectd_DEPENDENCIES += ascent.la
 endif
 
+if BUILD_PLUGIN_BAROMETER
+pkglib_LTLIBRARIES += barometer.la
+barometer_la_SOURCES = barometer.c
+barometer_la_LDFLAGS = -module -avoid-version
+barometer_la_LIBADD = -lm
+collectd_LDADD += "-dlopen" barometer.la
+collectd_DEPENDENCIES += barometer.la
+endif
+
 if BUILD_PLUGIN_BATTERY
 pkglib_LTLIBRARIES += battery.la
 battery_la_SOURCES = battery.c
@@ -273,7 +286,7 @@ pkglib_LTLIBRARIES += cpu.la
 cpu_la_SOURCES = cpu.c
 cpu_la_CFLAGS = $(AM_CFLAGS)
 cpu_la_LDFLAGS = -module -avoid-version
-cpu_la_LIBADD = 
+cpu_la_LIBADD =
 if BUILD_WITH_LIBKSTAT
 cpu_la_LIBADD += -lkstat
 endif
@@ -371,7 +384,7 @@ pkglib_LTLIBRARIES += disk.la
 disk_la_SOURCES = disk.c
 disk_la_CFLAGS = $(AM_CFLAGS)
 disk_la_LDFLAGS = -module -avoid-version
-disk_la_LIBADD = 
+disk_la_LIBADD =
 if BUILD_WITH_LIBKSTAT
 disk_la_LIBADD += -lkstat
 endif
@@ -382,9 +395,12 @@ if BUILD_WITH_LIBIOKIT
 disk_la_LDFLAGS += -framework IOKit
 endif
 if BUILD_WITH_LIBSTATGRAB
-disk_la_CFLAGS += $(BUILD_WITH_LIBSTATGRAB_CFLAGS)  
+disk_la_CFLAGS += $(BUILD_WITH_LIBSTATGRAB_CFLAGS)
 disk_la_LIBADD += $(BUILD_WITH_LIBSTATGRAB_LDFLAGS)
 endif
+if BUILD_WITH_LIBUDEV
+disk_la_LIBADD += -ludev
+endif
 if BUILD_WITH_PERFSTAT
 disk_la_LIBADD += -lperfstat
 endif
@@ -401,6 +417,15 @@ collectd_LDADD += "-dlopen" dns.la
 collectd_DEPENDENCIES += dns.la
 endif
 
+if BUILD_PLUGIN_DRBD
+pkglib_LTLIBRARIES += drbd.la
+drbd_la_SOURCES = drbd.c
+drbd_la_LDFLAGS = -module -avoid-version
+drbd_la_LIBADD = -lpthread
+collectd_LDADD += "-dlopen" drbd.la
+collectd_DEPENDENCIES += drbd.la
+endif
+
 if BUILD_PLUGIN_EMAIL
 pkglib_LTLIBRARIES += email.la
 email_la_SOURCES = email.c
@@ -577,6 +602,17 @@ collectd_LDADD += "-dlopen" logfile.la
 collectd_DEPENDENCIES += logfile.la
 endif
 
+if BUILD_PLUGIN_LOG_LOGSTASH
+pkglib_LTLIBRARIES += log_logstash.la
+log_logstash_la_SOURCES = log_logstash.c
+log_logstash_la_CFLAGS = $(AM_CFLAGS)
+log_logstash_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_LIBYAJL_LDFLAGS)
+log_logstash_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBYAJL_CPPFLAGS)
+log_logstash_la_LIBADD = $(BUILD_WITH_LIBYAJL_LIBS)
+collectd_LDADD += "-dlopen" log_logstash.la
+collectd_DEPENDENCIES += log_logstash.la
+endif
+
 if BUILD_PLUGIN_LPAR
 pkglib_LTLIBRARIES += lpar.la
 lpar_la_SOURCES = lpar.c
@@ -862,7 +898,7 @@ if BUILD_PLUGIN_OLSRD
 pkglib_LTLIBRARIES += olsrd.la
 olsrd_la_SOURCES = olsrd.c
 olsrd_la_LDFLAGS = -module -avoid-version
-olsrd_la_LIBADD = 
+olsrd_la_LIBADD =
 if BUILD_WITH_LIBSOCKET
 olsrd_la_LIBADD += -lsocket
 endif
@@ -1269,6 +1305,7 @@ pkglib_LTLIBRARIES += unixsock.la
 unixsock_la_SOURCES = unixsock.c \
                      utils_cmd_flush.h utils_cmd_flush.c \
                      utils_cmd_getval.h utils_cmd_getval.c \
+                     utils_cmd_getthreshold.h utils_cmd_getthreshold.c \
                      utils_cmd_listval.h utils_cmd_listval.c \
                      utils_cmd_putval.h utils_cmd_putval.c \
                      utils_cmd_putnotif.h utils_cmd_putnotif.c
@@ -1387,6 +1424,19 @@ endif
 collectd_DEPENDENCIES += write_http.la
 endif
 
+if BUILD_PLUGIN_WRITE_KAFKA
+pkglib_LTLIBRARIES += write_kafka.la
+write_kafka_la_SOURCES = write_kafka.c \
+                        utils_format_graphite.c utils_format_graphite.h \
+                        utils_format_json.c utils_format_json.h \
+                        utils_cmd_putval.c utils_cmd_putval.h \
+                        utils_crc32.c utils_crc32.h
+write_kafka_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_LIBRDKAFKA_LDFLAGS)
+write_kafka_la_LIBADD = $(BUILD_WITH_LIBRDKAFKA_LIBS)
+collectd_LDADD += "-dlopen" write_kafka.la
+collectd_DEPENDENCIES += write_kafka.la
+endif
+
 if BUILD_PLUGIN_WRITE_MONGODB
 pkglib_LTLIBRARIES += write_mongodb.la
 write_mongodb_la_SOURCES = write_mongodb.c
@@ -1409,7 +1459,7 @@ endif
 
 if BUILD_PLUGIN_WRITE_RIEMANN
 pkglib_LTLIBRARIES += write_riemann.la
-write_riemann_la_SOURCES = write_riemann.c
+write_riemann_la_SOURCES = write_riemann.c write_riemann_threshold.c
 nodist_write_riemann_la_SOURCES = riemann.pb-c.c riemann.pb-c.h
 write_riemann_la_LDFLAGS = -module -avoid-version
 write_riemann_la_LIBADD = -lprotobuf-c
@@ -1417,6 +1467,14 @@ collectd_LDADD += "-dlopen" write_riemann.la
 collectd_DEPENDENCIES += write_riemann.la
 endif
 
+if BUILD_PLUGIN_WRITE_TSDB
+pkglib_LTLIBRARIES += write_tsdb.la
+write_tsdb_la_SOURCES = write_tsdb.c
+write_tsdb_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" write_tsdb.la
+collectd_DEPENDENCIES += write_tsdb.la
+endif
+
 if BUILD_PLUGIN_XMMS
 pkglib_LTLIBRARIES += xmms.la
 xmms_la_SOURCES = xmms.c
@@ -1535,15 +1593,48 @@ uninstall-hook:
        rm -f $(DESTDIR)$(sysconfdir)/collectd.conf
        rm -f $(DESTDIR)$(pkgdatadir)/postgresql_default.conf;
 
-if BUILD_FEATURE_DEBUG
-bin_PROGRAMS += utils_vl_lookup_test
-utils_vl_lookup_test_SOURCES = utils_vl_lookup_test.c \
+check_PROGRAMS = test_common test_utils_avltree test_utils_heap test_utils_mount test_utils_vl_lookup
+
+test_common_SOURCES = tests/test_common.c \
+                      common.h common.c \
+                      tests/mock/plugin.c \
+                      tests/mock/utils_cache.c \
+                      tests/mock/utils_time.c
+test_common_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL)
+test_common_LDFLAGS = -export-dynamic
+test_common_LDADD =
+
+test_utils_avltree_SOURCES = tests/test_utils_avltree.c \
+                             utils_avltree.c utils_avltree.h
+test_utils_avltree_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL)
+test_utils_avltree_LDFLAGS = -export-dynamic
+test_utils_avltree_LDADD =
+
+test_utils_heap_SOURCES = tests/test_utils_heap.c \
+                          utils_heap.c utils_heap.h
+test_utils_heap_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL)
+test_utils_heap_LDFLAGS = -export-dynamic
+test_utils_heap_LDADD =
+
+test_utils_mount_SOURCES = tests/test_utils_mount.c \
+                           utils_mount.c utils_mount.h \
+                           common.c common.h \
+                           tests/mock/plugin.c \
+                           tests/mock/utils_cache.c \
+                           tests/mock/utils_time.c
+test_utils_mount_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL)
+test_utils_mount_LDFLAGS = -export-dynamic
+test_utils_mount_LDADD =
+
+test_utils_vl_lookup_SOURCES = tests/test_utils_vl_lookup.c \
                                utils_vl_lookup.h utils_vl_lookup.c \
                                utils_avltree.c utils_avltree.h \
-                               common.h
-
-utils_vl_lookup_test_CPPFLAGS =  $(AM_CPPFLAGS) $(LTDLINCL) -DBUILD_TEST=1
-utils_vl_lookup_test_CFLAGS = $(AM_CFLAGS)
-utils_vl_lookup_test_LDFLAGS = -export-dynamic
-utils_vl_lookup_test_LDADD =
-endif
+                               common.c common.h \
+                               tests/mock/plugin.c \
+                               tests/mock/utils_cache.c \
+                               tests/mock/utils_time.c
+test_utils_vl_lookup_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL)
+test_utils_vl_lookup_LDFLAGS = -export-dynamic
+test_utils_vl_lookup_LDADD =
+
+TESTS = test_common test_utils_avltree test_utils_heap test_utils_mount test_utils_vl_lookup
index ab920a6..1764129 100644 (file)
@@ -23,7 +23,7 @@
  *
  * Authors:
  *   Sebastien Pahl <sebastien.pahl at dotcloud.com>
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
@@ -93,6 +93,8 @@ struct camqp_config_s
     /* subscribe only */
     char   *exchange_type;
     char   *queue;
+    _Bool   queue_durable;
+    _Bool   queue_auto_delete;
 
     amqp_connection_state_t connection;
     pthread_mutex_t lock;
@@ -328,9 +330,9 @@ static int camqp_setup_queue (camqp_config_t *conf) /* {{{ */
             ? amqp_cstring_bytes (conf->queue)
             : AMQP_EMPTY_BYTES,
             /* passive     = */ 0,
-            /* durable     = */ 0,
+            /* durable     = */ conf->queue_durable,
             /* exclusive   = */ 0,
-            /* auto_delete = */ 1,
+            /* auto_delete = */ conf->queue_auto_delete,
             /* arguments   = */ AMQP_EMPTY_TABLE);
     if (qd_ret == NULL)
     {
@@ -787,7 +789,7 @@ static int camqp_write (const data_set_t *ds, const value_list_t *vl, /* {{{ */
 {
     camqp_config_t *conf = user_data->data;
     char routing_key[6 * DATA_MAX_NAME_LEN];
-    char buffer[4096];
+    char buffer[8192];
     int status;
 
     if ((ds == NULL) || (vl == NULL) || (conf == NULL))
@@ -931,6 +933,8 @@ static int camqp_config_connection (oconfig_item_t *ci, /* {{{ */
     /* subscribe only */
     conf->exchange_type = NULL;
     conf->queue = NULL;
+    conf->queue_durable = 0;
+    conf->queue_auto_delete = 1;
     /* general */
     conf->connection = NULL;
     pthread_mutex_init (&conf->lock, /* attr = */ NULL);
@@ -970,6 +974,10 @@ static int camqp_config_connection (oconfig_item_t *ci, /* {{{ */
             status = cf_util_get_string (child, &conf->exchange_type);
         else if ((strcasecmp ("Queue", child->key) == 0) && !publish)
             status = cf_util_get_string (child, &conf->queue);
+        else if ((strcasecmp ("QueueDurable", child->key) == 0) && !publish)
+            status = cf_util_get_boolean (child, &conf->queue_durable);
+        else if ((strcasecmp ("QueueAutoDelete", child->key) == 0) && !publish)
+            status = cf_util_get_boolean (child, &conf->queue_auto_delete);
         else if (strcasecmp ("RoutingKey", child->key) == 0)
             status = cf_util_get_string (child, &conf->routing_key);
         else if ((strcasecmp ("Persistent", child->key) == 0) && publish)
index f0ab22a..ad5975c 100644 (file)
@@ -18,7 +18,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>
  *   Florent EppO Monbillard <eppo at darox.net>
  *   - connections/lighttpd extension
  *   Amit Gupta <amit.gupta221 at gmail.com>
@@ -402,7 +402,7 @@ static int init_host (apache_t *st) /* {{{ */
                curl_easy_setopt (st->curl, CURLOPT_WRITEHEADER, st);
        }
 
-       curl_easy_setopt (st->curl, CURLOPT_USERAGENT, PACKAGE_NAME"/"PACKAGE_VERSION);
+       curl_easy_setopt (st->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
        curl_easy_setopt (st->curl, CURLOPT_ERRORBUFFER, st->apache_curl_error);
 
        if (st->user != NULL)
index ee15b14..be7673c 100644 (file)
@@ -21,7 +21,7 @@
  *
  * Authors:
  *   Anthony Gialluca <tonyabg at charter.net>
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index bdba0ff..19d5a49 100644 (file)
@@ -2,21 +2,26 @@
  * collectd - src/apple_sensors.c
  * Copyright (C) 2006,2007  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index 94a3938..ca0fac7 100644 (file)
@@ -1,22 +1,27 @@
 /**
  * collectd - src/ascent.c
- * Copyright (C) 2008  Florian octo Forster
+ * Copyright (C) 2008       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
@@ -541,7 +546,7 @@ static int ascent_init (void) /* {{{ */
 
   curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1L);
   curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, ascent_curl_callback);
-  curl_easy_setopt (curl, CURLOPT_USERAGENT, PACKAGE_NAME"/"PACKAGE_VERSION);
+  curl_easy_setopt (curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
   curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, ascent_curl_error);
 
   if (user != NULL)
diff --git a/src/barometer.c b/src/barometer.c
new file mode 100644 (file)
index 0000000..95b05f4
--- /dev/null
@@ -0,0 +1,1375 @@
+/**
+ * collectd - src/barometer.c
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * 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:
+ *   Tomas Menzl
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "utils_cache.h"
+#include "plugin.h"
+
+#include <stdint.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <linux/i2c-dev.h>
+#include <math.h>
+
+/* ------------ MPL115 defines ------------ */
+/* I2C address of the MPL115 sensor */
+#define MPL115_I2C_ADDRESS          0x60
+                                    
+/* register addresses */            
+#define MPL115_ADDR_CONV            0x00
+#define MPL115_ADDR_COEFFS          0x04
+                                    
+/* register sizes */                
+#define MPL115_NUM_CONV             4
+#define MPL115_NUM_COEFFS           12
+                                    
+/* commands / addresses */          
+#define MPL115_CMD_CONVERT_PRESS    0x10
+#define MPL115_CMD_CONVERT_TEMP     0x11
+#define MPL115_CMD_CONVERT_BOTH     0x12
+                                    
+#define MPL115_CONVERSION_RETRIES   5
+
+
+/* ------------ MPL3115 defines ------------ */
+/* MPL3115 I2C address */
+#define MPL3115_I2C_ADDRESS         0x60
+
+/* register addresses (only the interesting ones) */
+#define MPL3115_REG_STATUS          0x00
+#define MPL3115_REG_OUT_P_MSB       0x01
+#define MPL3115_REG_OUT_P_CSB       0x02
+#define MPL3115_REG_OUT_P_LSB       0x03
+#define MPL3115_REG_OUT_T_MSB       0x04
+#define MPL3115_REG_OUT_T_LSB       0x05
+#define MPL3115_REG_DR_STATUS       0x06
+#define MPL3115_REG_WHO_AM_I        0x0C
+#define MPL3115_REG_SYSMOD          0x11
+#define MPL3115_REG_PT_DATA_CFG     0x13
+#define MPL3115_REG_BAR_IN_MSB      0x14
+#define MPL3115_REG_BAR_IN_LSB      0x15
+#define MPL3115_REG_CTRL_REG1       0x26
+#define MPL3115_REG_CTRL_REG2       0x27
+#define MPL3115_REG_CTRL_REG3       0x28
+#define MPL3115_REG_CTRL_REG4       0x29
+#define MPL3115_REG_CTRL_REG5       0x2A
+#define MPL3115_REG_OFF_P           0x2B
+#define MPL3115_REG_OFF_T           0x2C
+#define MPL3115_REG_OFF_H           0x2D
+
+/* Register values, masks */
+#define MPL3115_WHO_AM_I_RESP       0xC4
+
+#define MPL3115_PT_DATA_DREM        0x04
+#define MPL3115_PT_DATA_PDEF        0x02
+#define MPL3115_PT_DATA_TDEF        0x01
+                                    
+#define MPL3115_DR_STATUS_TDR       0x02
+#define MPL3115_DR_STATUS_PDR       0x04
+#define MPL3115_DR_STATUS_PTDR      0x08
+#define MPL3115_DR_STATUS_DR        (MPL3115_DR_STATUS_TDR | MPL3115_DR_STATUS_PDR | MPL3115_DR_STATUS_PTDR)
+                                    
+#define MPL3115_DR_STATUS_TOW       0x20
+#define MPL3115_DR_STATUS_POW       0x40
+#define MPL3115_DR_STATUS_PTOW      0x80
+
+#define MPL3115_CTRL_REG1_ALT       0x80
+#define MPL3115_CTRL_REG1_RAW       0x40
+#define MPL3115_CTRL_REG1_OST_MASK  0x38
+#define MPL3115_CTRL_REG1_OST_1     0x00
+#define MPL3115_CTRL_REG1_OST_2     0x08
+#define MPL3115_CTRL_REG1_OST_4     0x10
+#define MPL3115_CTRL_REG1_OST_8     0x18
+#define MPL3115_CTRL_REG1_OST_16    0x20
+#define MPL3115_CTRL_REG1_OST_32    0x28
+#define MPL3115_CTRL_REG1_OST_64    0x30
+#define MPL3115_CTRL_REG1_OST_128   0x38
+#define MPL3115_CTRL_REG1_RST       0x04
+#define MPL3115_CTRL_REG1_OST       0x02
+#define MPL3115_CTRL_REG1_SBYB      0x01
+#define MPL3115_CTRL_REG1_SBYB_MASK 0xFE
+
+#define MPL3115_NUM_CONV_VALS       5
+
+
+/* ------------ Normalization ------------ */
+/* Mean sea level pressure normalization methods */
+#define MSLP_NONE          0
+#define MSLP_INTERNATIONAL 1
+#define MSLP_DEU_WETT      2
+
+/** Temperature reference history depth for averaging. See #get_reference_temperature */
+#define REF_TEMP_AVG_NUM   5
+
+/* ------------------------------------------ */
+static const char *config_keys[] =
+{
+    "Device",
+    "Oversampling",
+    "PressureOffset",    /**< only for MPL3115 */
+    "TemperatureOffset", /**< only for MPL3115 */
+    "Altitude",
+    "Normalization",
+    "TemperatureSensor"
+};
+
+static int    config_keys_num     = STATIC_ARRAY_SIZE(config_keys);
+                                  
+static char * config_device       = NULL;  /**< I2C bus device */
+static int    config_oversample   = 1;     /**< averaging window */
+
+static double config_press_offset = 0.0;   /**< pressure offset */
+static double config_temp_offset  = 0.0;   /**< temperature offset */
+
+static double config_altitude     = NAN;   /**< altitude */
+static int    config_normalize    = 0;     /**< normalization method */
+                                  
+static _Bool  configured          = 0;     /**< the whole plugin config status */
+                                  
+static int    i2c_bus_fd          = -1;    /**< I2C bus device FD */
+                                  
+static _Bool  is_MPL3115          = 0;    /**< is this MPL3115? */
+static __s32  oversample_MPL3115  = 0;    /**< MPL3115 CTRL1 oversample setting */
+
+
+/* MPL115 conversion coefficients */
+static double mpl115_coeffA0;
+static double mpl115_coeffB1;
+static double mpl115_coeffB2;
+static double mpl115_coeffC12;
+static double mpl115_coeffC11;
+static double mpl115_coeffC22;
+
+/* ------------------------ averaging ring buffer ------------------------ */
+/*  Used only for MPL115. MPL3115 supports real oversampling in the device so */
+/*  no need for any postprocessing. */
+
+static _Bool avg_initialized = 0;    /**< already initialized by real values */
+
+typedef struct averaging_s {
+    long int * ring_buffer;
+    int        ring_buffer_size;
+    long int   ring_buffer_sum;
+    int        ring_buffer_head;
+} averaging_t;
+
+
+static averaging_t pressure_averaging    = { NULL, 0, 0L, 0 };
+static averaging_t temperature_averaging = { NULL, 0, 0L, 0 };
+
+
+/** 
+ * Create / allocate averaging buffer
+ *
+ * The buffer is initialized with zeros.
+ *
+ * @param avg  pointer to ring buffer to be allocated
+ * @param size requested buffer size
+ *
+ * @return Zero when successful
+ */
+static int averaging_create(averaging_t * avg, int size)
+{
+    int a;
+
+    avg->ring_buffer = (long int *) malloc(size * sizeof(*avg));
+    if (avg->ring_buffer == NULL)
+    {
+        ERROR ("barometer: averaging_create - ring buffer allocation of size %d failed",
+               size);
+        return -1;
+    }
+
+    for (a=0; a<size; ++a)
+    {
+      avg->ring_buffer[a] = 0L;
+    }
+
+    avg->ring_buffer_size = size;
+    avg->ring_buffer_sum  = 0L;
+    avg->ring_buffer_head = 0;
+
+    return 0;
+}
+
+
+/**
+ * Delete / free existing averaging buffer
+ *
+ * @param avg  pointer to the ring buffer to be deleted
+ */
+static void averaging_delete(averaging_t * avg)
+{
+    if (avg->ring_buffer != NULL)
+    {
+        free(avg->ring_buffer);
+        avg->ring_buffer = NULL;
+    }
+    avg->ring_buffer_size = 0;
+    avg->ring_buffer_sum  = 0L;
+    avg->ring_buffer_head = 0;
+}
+
+
+/*
+ * Add new sample to the averaging buffer
+ *
+ * A new averaged value is returned. Note that till the buffer is full
+ * returned value is inaccurate as it is an average of real values and initial
+ * zeros.
+ *
+ * @param avg    pointer to the ring buffer
+ * @param sample new sample value
+ *
+ * @return Averaged sample value
+ */
+static double averaging_add_sample(averaging_t * avg, long int sample)
+{
+    double result;
+
+    avg->ring_buffer_sum += sample - avg->ring_buffer[avg->ring_buffer_head];
+    avg->ring_buffer[avg->ring_buffer_head] = sample;
+    avg->ring_buffer_head = (avg->ring_buffer_head+1) % avg->ring_buffer_size;
+    result = (double)(avg->ring_buffer_sum) / (double)(avg->ring_buffer_size);
+    
+    DEBUG ("barometer: averaging_add_sample - added %ld, result = %lf", 
+           sample, 
+           result);
+
+    return result;
+}
+
+
+/* ------------------------ temperature refference ------------------------ */
+
+/**
+ * Linked list type of temperature sensor references
+ */
+typedef struct temperature_list_s {
+    char                      * sensor_name; /**< sensor name/reference */
+    size_t                      num_values;  /**< number of values (usually one) */
+    _Bool                       initialized; /**< sensor already provides data */
+    struct temperature_list_s * next;        /**< next in the list */
+} temperature_list_t;
+
+static temperature_list_t * temp_list = NULL;
+
+
+/*
+ * Add new sensor to the temperature reference list
+ *
+ * @param list   the list
+ * @param sensor reference name (as provided by the config file)
+ *
+ * @return Zero when successful
+ */
+static int temp_list_add(temperature_list_t * list, const char * sensor)
+{
+    temperature_list_t * new_temp;
+
+    new_temp = (temperature_list_t *) malloc(sizeof(*new_temp));
+    if(new_temp == NULL)
+        return -1;
+
+    new_temp->sensor_name = strdup(sensor);
+    new_temp->initialized = 0;
+    new_temp->num_values = 0;
+    if(new_temp->sensor_name == NULL)
+    {
+        free(new_temp);
+        return -1;
+    }
+
+    new_temp->next = temp_list;
+    temp_list = new_temp;
+    return 0;
+}
+
+
+/*
+ * Delete the whole temperature reference list
+ *
+ * @param list the list to be deleted
+ */
+static void temp_list_delete(temperature_list_t ** list)
+{
+    temperature_list_t * tmp;
+
+    while (*list != NULL)
+    {
+        tmp = (*list);
+        (*list) = (*list)->next;
+        free(tmp->sensor_name);
+        free(tmp);
+        tmp = NULL;
+    }
+}
+
+
+/*
+ * Get reference temperature value
+ *
+ * First initially uc_get_rate_by_name is tried. At the startup due to nondeterministic
+ * order the temperature may not be read yet (then it fails and first measurment gives
+ * only absolute air pressure reading which is acceptable). Once it succedes (should be
+ * second measurement at the latest) we use average of few last readings from
+ * uc_get_history_by_name. It may take few readings to start filling so again we use
+ * uc_get_rate_by_name as a fallback.
+ * The idea is to use basic "noise" filtering (history averaging) across all the values
+ * which given sensor provides (up to given depth). Then we get minimum among
+ * the sensors.
+ *
+ * @param result where the result is stored. When not available NAN is stored.
+ *
+ * @return Zero when successful
+ */
+static int get_reference_temperature(double * result)
+{
+    temperature_list_t * list = temp_list;
+
+    gauge_t * values = NULL;   /**< rate values */
+    size_t    values_num = 0;  /**< number of rate values */
+    int i;
+
+    gauge_t values_history[REF_TEMP_AVG_NUM];
+
+    double avg_sum;  /**< Value sum for computing average */
+    int    avg_num;  /**< Number of values for computing average */
+    double average;  /**< Resulting value average */
+
+    *result = NAN;
+
+    while(list != NULL)
+    {
+        avg_sum = 0.0;
+        avg_num = 0;
+
+        /* First time need to read current rate to learn how many values are
+           there (typically for temperature it would be just one).
+           We do not expect dynamic changing of number of temperarure values
+           in runtime yet (are there any such cases?). */
+        if(!list->initialized)
+        {
+            if(uc_get_rate_by_name(list->sensor_name,
+                                   &values,
+                                   &values_num))
+            {
+                DEBUG ("barometer: get_reference_temperature - rate \"%s\" not found yet",
+                       list->sensor_name);
+                list = list->next;
+                continue;
+            }
+
+            DEBUG ("barometer: get_reference_temperature - initialize \"%s\", %zu vals",
+                   list->sensor_name,
+                   values_num);
+
+            list->initialized = 1;
+            list->num_values = values_num;
+
+            for(i=0; i<values_num; ++i)
+            {
+                DEBUG ("barometer: get_reference_temperature - rate %d: %lf **",
+                       i,
+                       values[i]);
+                if(!isnan(values[i]))
+                {
+                    avg_sum += values[i];
+                    ++avg_num;
+                }
+            }
+            free(values);
+            values = NULL;
+        }
+
+        /* It is OK to get here the first time as well, in the worst case
+           the history will full of NANs. */
+        if(uc_get_history_by_name(list->sensor_name,
+                                  values_history,
+                                  REF_TEMP_AVG_NUM,
+                                  list->num_values))
+        {
+            ERROR ("barometer: get_reference_temperature - history \"%s\" lost",
+                   list->sensor_name);
+            list->initialized = 0;
+            list->num_values = 0;
+            list = list->next;
+            continue;
+        }
+            
+        for(i=0; i<REF_TEMP_AVG_NUM*list->num_values; ++i)
+        {
+            DEBUG ("barometer: get_reference_temperature - history %d: %lf",
+                   i,
+                   values_history[i]);
+            if(!isnan(values_history[i]))
+            {
+                avg_sum += values_history[i];
+                ++avg_num;
+            }
+        }
+
+        if(avg_num == 0)   /* still no history? fallback to current */
+        {
+            if(uc_get_rate_by_name(list->sensor_name,
+                                   &values,
+                                   &values_num))
+            {
+                ERROR ("barometer: get_reference_temperature - rate \"%s\" lost",
+                       list->sensor_name);
+                list->initialized = 0;
+                list->num_values = 0;
+                list = list->next;
+                continue;
+            }
+
+            for(i=0; i<values_num; ++i)
+            {
+                DEBUG ("barometer: get_reference_temperature - rate last %d: %lf **",
+                       i,
+                       values[i]);
+                if(!isnan(values[i]))
+                {
+                    avg_sum += values[i];
+                    ++avg_num;
+                }
+            }
+            free(values);
+            values = NULL;
+        }
+
+        if(avg_num == 0)
+        {
+            ERROR ("barometer: get_reference_temperature - could not read \"%s\"",
+                   list->sensor_name);
+            list->initialized = 0;
+            list->num_values = 0;
+        }
+        else
+        {
+            average = avg_sum / (double) avg_num;
+            if(isnan(*result))
+                *result=average;
+            else if(*result>average)
+                *result=average;
+        }
+        list = list->next;
+    }  /* while sensor list */
+    
+    if(*result == NAN)
+    {
+        ERROR("barometer: get_reference_temperature - no sensor available (yet?)");
+        return -1;
+    }
+    DEBUG ("barometer: get_reference_temperature - temp is %lf", *result);
+    return 0;
+}
+
+/* ------------------------ MPL115 access ------------------------ */
+
+/** 
+ * Read the MPL115 sensor conversion coefficients.
+ *
+ * These are (device specific) constants so we can read them just once.
+ *
+ * @return Zero when successful
+ */
+static int MPL115_read_coeffs(void)
+{
+    uint8_t mpl115_coeffs[MPL115_NUM_COEFFS]; 
+    int32_t res;
+
+    int8_t  sia0MSB, sia0LSB, sib1MSB, sib1LSB, sib2MSB, sib2LSB;
+    int8_t  sic12MSB, sic12LSB, sic11MSB, sic11LSB, sic22MSB, sic22LSB;
+    int16_t sia0, sib1, sib2, sic12, sic11, sic22;
+      
+    char errbuf[1024];
+
+    res = i2c_smbus_read_i2c_block_data(i2c_bus_fd, 
+                                        MPL115_ADDR_COEFFS, 
+                                        MPL115_NUM_COEFFS, 
+                                        mpl115_coeffs);
+    if (res < 0)
+    {
+        ERROR ("barometer: read_mpl115_coeffs - problem reading data: %s",
+               sstrerror (errno, errbuf, sizeof (errbuf)));
+        return -1;
+    }
+   
+    /* Using perhaps less elegant/efficient code, but more readable. */
+    /* a0: 16total 1sign 12int 4fract 0pad */
+    sia0MSB = mpl115_coeffs[0];
+    sia0LSB = mpl115_coeffs[1];
+    sia0 = (int16_t) sia0MSB <<8;          /* s16 type, Shift to MSB */
+    sia0 += (int16_t) sia0LSB & 0x00FF;    /* Add LSB to 16bit number */
+    mpl115_coeffA0 = (double) (sia0);
+    mpl115_coeffA0 /= 8.0;                 /* 3 fract bits */
+    
+    /* b1: 16total 1sign 2int 13fract 0pad */
+    sib1MSB= mpl115_coeffs[2];
+    sib1LSB= mpl115_coeffs[3];
+    sib1 = sib1MSB <<8;                    /* Shift to MSB */
+    sib1 += sib1LSB & 0x00FF;              /* Add LSB to 16bit number */
+    mpl115_coeffB1 = (double) (sib1);
+    mpl115_coeffB1 /= 8192.0;              /* 13 fract */
+    
+    /* b2: 16total 1sign 1int 14fract 0pad */
+    sib2MSB= mpl115_coeffs[4];
+    sib2LSB= mpl115_coeffs[5];
+    sib2 = sib2MSB <<8;                     /* Shift to MSB */
+    sib2 += sib2LSB & 0x00FF;               /* Add LSB to 16bit number */
+    mpl115_coeffB2 = (double) (sib2);
+    mpl115_coeffB2 /= 16384.0;              /* 14 fract */
+
+    /* c12: 14total 1sign 0int 13fract 9pad */
+    sic12MSB= mpl115_coeffs[6];
+    sic12LSB= mpl115_coeffs[7];
+    sic12 = sic12MSB <<8;                   /* Shift to MSB only by 8 for MSB */
+    sic12 += sic12LSB & 0x00FF;
+    mpl115_coeffC12 = (double) (sic12);
+    mpl115_coeffC12 /= 4.0;                 /* 16-14=2 */
+    mpl115_coeffC12 /= 4194304.0;           /* 13+9=22 fract */
+
+    /* c11: 11total 1sign 0int 11fract 11pad */
+    sic11MSB= mpl115_coeffs[8];
+    sic11LSB= mpl115_coeffs[9];
+    sic11 = sic11MSB <<8;                   /* Shift to MSB only by 8 for MSB */
+    sic11 += sic11LSB & 0x00FF;
+    mpl115_coeffC11 = (double) (sic11);
+    mpl115_coeffC11 /= 32.0;               /* 16-11=5 */
+    mpl115_coeffC11 /= 4194304.0;          /* 11+11=22 fract */
+
+    /* c12: 11total 1sign 0int 10fract 15pad */
+    sic22MSB= mpl115_coeffs[10];
+    sic22LSB= mpl115_coeffs[11];
+    sic22 = sic22MSB <<8;                   /* Shift to MSB only by 8 for MSB */
+    sic22 += sic22LSB & 0x00FF;
+    mpl115_coeffC22 = (double) (sic22);
+    mpl115_coeffC22 /= 32.0; //16-11=5
+    mpl115_coeffC22 /= 33554432.0;          /* 10+15=25 fract */
+
+    DEBUG("barometer: read_mpl115_coeffs: a0=%lf, b1=%lf, b2=%lf, c12=%lf, c11=%lf, c22=%lf",
+          mpl115_coeffA0, 
+          mpl115_coeffB1, 
+          mpl115_coeffB2, 
+          mpl115_coeffC12, 
+          mpl115_coeffC11, 
+          mpl115_coeffC22);
+    return 0;
+}
+
+
+/*
+ * Convert raw adc values to real data using the sensor coefficients.
+ *
+ * @param adc_pressure adc pressure value to be converted
+ * @param adc_temp     adc temperature value to be converted
+ * @param pressure     computed real pressure
+ * @param temperature  computed real temperature
+ */
+static void MPL115_convert_adc_to_real(double   adc_pressure,
+                                       double   adc_temp,
+                                       double * pressure,
+                                       double * temperature)
+{
+    double Pcomp;
+    Pcomp = mpl115_coeffA0 +                                            \
+        (mpl115_coeffB1 + mpl115_coeffC11*adc_pressure + mpl115_coeffC12*adc_temp) * adc_pressure + \
+        (mpl115_coeffB2 + mpl115_coeffC22*adc_temp) * adc_temp;
+    
+    *pressure = ((1150.0-500.0) * Pcomp / 1023.0) + 500.0;
+    *temperature = (472.0 - adc_temp) / 5.35 + 25.0;
+    DEBUG ("barometer: convert_adc_to_real - got %lf hPa, %lf C",
+           *pressure,
+           *temperature);
+}
+
+
+/** 
+ * Read sensor averegaed measurements
+ *
+ * @param pressure    averaged measured pressure
+ * @param temperature averaged measured temperature
+ *
+ * @return Zero when successful
+ */
+static int MPL115_read_averaged(double * pressure, double * temperature)
+{
+    uint8_t mpl115_conv[MPL115_NUM_CONV]; 
+    int8_t  res;
+    int     retries;
+    int     conv_pressure;
+    int     conv_temperature;
+    double  adc_pressure;
+    double  adc_temperature;
+    char    errbuf[1024];
+
+    *pressure    = 0.0;
+    *temperature = 0.0;
+   
+    /* start conversion of both temp and presure */
+    retries = MPL115_CONVERSION_RETRIES;
+    while (retries>0)
+    {
+        /* write 1 to start conversion */
+        res = i2c_smbus_write_byte_data (i2c_bus_fd,
+                                         MPL115_CMD_CONVERT_BOTH,
+                                         0x01);
+        if (res >= 0)
+            break;
+
+        --retries;
+        if(retries>0)
+        {
+            ERROR ("barometer: MPL115_read_averaged - requesting conversion: %s, " \
+                   "will retry at most %d more times",
+                   sstrerror (errno, errbuf, sizeof (errbuf)),
+                   retries);
+        }
+        else
+        {
+            ERROR ("barometer: MPL115_read_averaged - requesting conversion: %s, "\
+                   "too many failed retries",
+                   sstrerror (errno, errbuf, sizeof (errbuf)));
+            return -1;
+        }
+    }
+
+    usleep (10000); /* wait 10ms for the conversion */
+
+    retries=MPL115_CONVERSION_RETRIES;
+    while (retries>0)
+    {
+        res = i2c_smbus_read_i2c_block_data(i2c_bus_fd,
+                                            MPL115_ADDR_CONV,
+                                            MPL115_NUM_CONV,
+                                            mpl115_conv); 
+        if (res >= 0)
+            break;
+
+        --retries;
+        if (retries>0)
+        {
+            ERROR ("barometer: MPL115_read_averaged - reading conversion: %s, " \
+                   "will retry at most %d more times",
+                   sstrerror (errno, errbuf, sizeof (errbuf)),
+                   retries);
+        }
+        else
+        {
+            ERROR ("barometer: MPL115_read_averaged - reading conversion: %s, " \
+                   "too many failed retries",
+                   sstrerror (errno, errbuf, sizeof (errbuf)));
+            return -1;
+        }
+    }
+    
+    conv_pressure    = ((mpl115_conv[0] << 8) | mpl115_conv[1]) >> 6;
+    conv_temperature = ((mpl115_conv[2] << 8) | mpl115_conv[3]) >> 6;
+    DEBUG ("barometer: MPL115_read_averaged, raw pressure ADC value = %d, " \
+           "raw temperature ADC value = %d",
+           conv_pressure,
+           conv_temperature);
+
+    adc_pressure    = averaging_add_sample (&pressure_averaging, conv_pressure);
+    adc_temperature = averaging_add_sample (&temperature_averaging, conv_temperature);
+
+    MPL115_convert_adc_to_real(adc_pressure, adc_temperature, pressure, temperature);
+
+    DEBUG ("barometer: MPL115_read_averaged - averaged ADC pressure = %lf / temperature = %lf, " \
+           "real pressure = %lf hPa / temperature = %lf C",
+           adc_pressure,
+           adc_temperature,
+           *pressure,
+           *temperature);
+    
+    return 0;
+}
+
+/* ------------------------ MPL3115 access ------------------------ */
+
+/** 
+ * Detect presence of a MPL3115 pressure sensor by checking register "WHO AM I"
+ * 
+ * @return 1 if MPL3115, 0 otherwise
+ */
+static int MPL3115_detect(void)
+{
+    __s32 res;
+
+    res = i2c_smbus_read_byte_data(i2c_bus_fd, MPL3115_REG_WHO_AM_I);
+    if(res == MPL3115_WHO_AM_I_RESP)
+    {
+        DEBUG ("barometer: MPL3115_detect - positive detection");
+        return 1;
+    }
+
+    DEBUG ("barometer: MPL3115_detect - negative detection");
+    return 0;
+}
+
+/** 
+ * Adjusts oversampling to values supported by MPL3115
+ *
+ * MPL3115 supports only power of 2 in the range 1 to 128. 
+ */
+static void MPL3115_adjust_oversampling(void)
+{
+    int new_val = 0;
+
+    if(config_oversample > 100)
+    {
+        new_val = 128;
+        oversample_MPL3115 = MPL3115_CTRL_REG1_OST_128;
+    }
+    else if(config_oversample > 48)
+    {
+        new_val = 64;
+        oversample_MPL3115 = MPL3115_CTRL_REG1_OST_64;
+    }
+    else if(config_oversample > 24)
+    {
+        new_val = 32;
+        oversample_MPL3115 = MPL3115_CTRL_REG1_OST_32;
+    }
+    else if(config_oversample > 12)
+    {
+        new_val = 16;
+        oversample_MPL3115 = MPL3115_CTRL_REG1_OST_16;
+    }
+    else if(config_oversample > 6)
+    {
+        new_val = 8;
+        oversample_MPL3115 = MPL3115_CTRL_REG1_OST_8;
+    }
+    else if(config_oversample > 3)
+    {
+        new_val = 4;
+        oversample_MPL3115 = MPL3115_CTRL_REG1_OST_4;
+    }
+    else if(config_oversample > 1)
+    {
+        new_val = 2;
+        oversample_MPL3115 = MPL3115_CTRL_REG1_OST_2;
+    }
+    else
+    {
+        new_val = 1;
+        oversample_MPL3115 = MPL3115_CTRL_REG1_OST_1;
+    }
+
+    DEBUG("barometer: correcting oversampling for MPL3115 from %d to %d",
+          config_oversample, 
+          new_val);
+    config_oversample = new_val;
+}
+
+/** 
+ * Read sensor averegaed measurements
+ *
+ * @param pressure    averaged measured pressure
+ * @param temperature averaged measured temperature
+ *
+ * @return Zero when successful
+ */
+static int MPL3115_read(double * pressure, double * temperature)
+{
+    __s32 res;
+    __s32 ctrl ;
+    __u8 data[MPL3115_NUM_CONV_VALS];
+    long int tmp_value = 0;
+    char errbuf[1024];
+    
+    /* Set Active - activate the device from standby */
+    res = i2c_smbus_read_byte_data(i2c_bus_fd, MPL3115_REG_CTRL_REG1);
+    if (res < 0)
+    {
+        ERROR ("barometer: MPL3115_read - cannot read CTRL_REG1: %s",
+               sstrerror (errno, errbuf, sizeof (errbuf)));
+        return 1;
+    }
+    ctrl = res;
+    res = i2c_smbus_write_byte_data(i2c_bus_fd, 
+                                    MPL3115_REG_CTRL_REG1, 
+                                    ctrl | MPL3115_CTRL_REG1_SBYB);
+    if (res < 0)
+    {
+        ERROR ("barometer: MPL3115_read - problem activating: %s",
+               sstrerror (errno, errbuf, sizeof (errbuf)));
+        return 1;
+    }
+    
+    /* base sleep is 5ms x OST */
+    usleep(5000 * config_oversample);
+      
+    /* check the flags/status if ready */
+    res = i2c_smbus_read_byte_data(i2c_bus_fd, MPL3115_REG_STATUS);
+    if (res < 0)
+    {
+        ERROR ("barometer: MPL3115_read - cannot read status register: %s",
+               sstrerror (errno, errbuf, sizeof (errbuf)));
+        return 1;
+    }
+    
+    while ((res & MPL3115_DR_STATUS_DR) != MPL3115_DR_STATUS_DR)
+    {
+        /* try some extra sleep... */
+        usleep(10000);
+        
+        /* ... and repeat the check. The conversion has to finish sooner or later. */
+        res = i2c_smbus_read_byte_data(i2c_bus_fd, MPL3115_REG_STATUS);
+        if (res < 0)
+        {
+            ERROR ("barometer: MPL3115_read - cannot read status register: %s",
+                   sstrerror (errno, errbuf, sizeof (errbuf)));
+            return 1;
+        }
+    }
+    
+    /* Now read all the data in one block. There is address autoincrement. */
+    res = i2c_smbus_read_i2c_block_data(i2c_bus_fd, 
+                                        MPL3115_REG_OUT_P_MSB, 
+                                        MPL3115_NUM_CONV_VALS,
+                                        data);
+    if (res < 0)
+    {
+        ERROR ("barometer: MPL3115_read - cannot read data registers: %s",
+               sstrerror (errno, errbuf, sizeof (errbuf)));
+        return 1;
+    }
+    
+    tmp_value = (data[0] << 16) | (data[1] << 8) | data[2];
+    *pressure = ((double) tmp_value) / 4.0 / 16.0 / 100.0;
+    DEBUG ("barometer: MPL3115_read, absolute pressure = %lf hPa", *pressure);
+    
+    if(data[3] > 0x7F)
+    {
+        data[3] = ~data[3] + 1;
+        *temperature = data[3];
+        *temperature = - *temperature;
+    }
+    else
+    {
+        *temperature = data[3];
+    }
+    
+    *temperature += (double)(data[4]) / 256.0;
+    DEBUG ("barometer: MPL3115_read, temperature = %lf C", *temperature);
+    
+    return 0;
+}
+
+/** 
+ * Initialize MPL3115 for barometeric measurements
+ * 
+ * @return 0 if successful
+ */
+static int MPL3115_init_sensor(void)
+{
+    __s32 res;
+    __s8 offset;
+    char errbuf[1024];
+    
+    /* Reset the sensor. It will reset immediately without ACKing */
+    /* the transaction, so no error handling here. */
+    i2c_smbus_write_byte_data(i2c_bus_fd, 
+                              MPL3115_REG_CTRL_REG1, 
+                              MPL3115_CTRL_REG1_RST);
+    
+    /* wait some time for the reset to finish */
+    usleep(100000);
+
+    /* now it should be in standby already so we can go and configure it */
+    
+    /*  Set temperature offset. */
+    /*  result = ADCtemp + offset [C] */
+    offset = (__s8) (config_temp_offset * 16.0);
+    res = i2c_smbus_write_byte_data(i2c_bus_fd, MPL3115_REG_OFF_T, offset);
+    if (res < 0)
+    {
+        ERROR ("barometer: MPL3115_init_sensor - problem setting temp offset: %s",
+               sstrerror (errno, errbuf, sizeof (errbuf)));
+        return -1;
+    }
+    
+    /*  Set pressure offset. */
+    /*  result = ADCpress + offset [hPa] */
+    offset = (__s8) (config_press_offset * 100.0 / 4.0);
+    res = i2c_smbus_write_byte_data(i2c_bus_fd, MPL3115_REG_OFF_P, offset);
+    if (res < 0)
+    {
+        ERROR ("barometer: MPL3115_init_sensor - problem setting pressure offset: %s",
+               sstrerror (errno, errbuf, sizeof (errbuf)));
+        return -1;
+    }
+
+    /* Enable Data Flags in PT_DATA_CFG - flags on both pressure and temp */
+    res = i2c_smbus_write_byte_data(i2c_bus_fd, 
+                                    MPL3115_REG_PT_DATA_CFG,
+                                    MPL3115_PT_DATA_DREM        \
+                                    | MPL3115_PT_DATA_PDEF      \
+                                    | MPL3115_PT_DATA_TDEF);
+    if (res < 0)
+    {
+        ERROR ("barometer: MPL3115_init_sensor - problem setting PT_DATA_CFG: %s",
+               sstrerror (errno, errbuf, sizeof (errbuf)));
+        return -1;
+    }
+
+    /* Set to barometer with an OSR */ 
+    res = i2c_smbus_write_byte_data(i2c_bus_fd, 
+                                    MPL3115_REG_CTRL_REG1, 
+                                    oversample_MPL3115);
+    if (res < 0)
+    {
+        ERROR ("barometer: MPL3115_init_sensor - problem configuring CTRL_REG1: %s",
+               sstrerror (errno, errbuf, sizeof (errbuf)));
+        return -1;
+    }
+
+    return 0;
+}
+
+
+/* ------------------------ Common functionality ------------------------ */
+
+/**
+ * Convert absolute pressure (in hPa) to mean sea level pressure
+ *
+ * Implemented methods are:
+ * - MSLP_NONE - no converions, returns absolute pressure
+ *
+ * - MSLP_INTERNATIONAL - see http://en.wikipedia.org/wiki/Atmospheric_pressure#Altitude_atmospheric_pressure_variation
+ *           Requires #config_altitude
+ *
+ * - MSLP_DEU_WETT - formula as recommended by the Deutsche Wetterdienst. See 
+ *                http://de.wikipedia.org/wiki/Barometrische_H%C3%B6henformel#Theorie
+ *           Requires both #config_altitude and temperature reference(s).
+ *
+ * @param abs_pressure absloute pressure to be converted
+ *
+ * @return mean sea level pressure if successful, NAN otherwise
+ */
+static double abs_to_mean_sea_level_pressure(double abs_pressure)
+{
+    double mean = -1.0;
+    double temp = 0.0;
+    int result = 0;
+
+    DEBUG ("barometer: abs_to_mean_sea_level_pressure: absPressure = %lf, method = %d",
+           abs_pressure,
+           config_normalize);
+
+    if (config_normalize >= MSLP_DEU_WETT)
+    {
+        result = get_reference_temperature(&temp);
+        if(result)
+        {
+            return NAN;
+        }
+    }
+
+    switch(config_normalize)
+    {
+    case MSLP_NONE:
+        mean = abs_pressure;
+        break;
+        
+    case MSLP_INTERNATIONAL:
+        mean = abs_pressure / \
+            pow(1.0 - 0.0065*config_altitude/288.15, 0.0065*0.0289644/(8.31447*0.0065));
+        break;
+        
+    case MSLP_DEU_WETT:
+    {
+        double E; /* humidity */
+        double x;
+        if(temp<9.1)
+            E = 5.6402 * (-0.0916 + exp(0.06*temp) );
+        else
+            E = 18.2194 * (1.0463 - exp(-0.0666*temp) );
+        x = 9.80665 / (287.05 * (temp+273.15 + 0.12*E + 0.0065*config_altitude/2)) * config_altitude;
+        mean = abs_pressure * exp(x);
+    }
+    break;
+
+    default:
+        ERROR ("barometer: abs_to_mean_sea_level_pressure: wrong conversion method %d", 
+               config_normalize);
+        mean = abs_pressure;
+        break;
+    }
+
+    return mean; 
+}
+
+/* ------------------------ main plugin callbacks ------------------------ */
+
+/** 
+ * Main plugin configuration callback (using simple config)
+ * 
+ * @param key   configuration key we should process
+ * @param value configuration value we should process
+ * 
+ * @return Zero when successful.
+ */
+static int collectd_barometer_config (const char *key, const char *value)
+{
+    DEBUG("barometer: collectd_barometer_config");
+
+    if (strcasecmp (key, "Device") == 0)
+    {
+        sfree (config_device);
+        config_device = strdup (value);
+    }
+    else if (strcasecmp (key, "Oversampling") == 0)
+    {
+        int oversampling_tmp = atoi (value);
+        if (oversampling_tmp < 1 || oversampling_tmp > 1024)
+        {
+            WARNING ("barometer: collectd_barometer_config: invalid oversampling: %d." \
+                     " Allowed values are 1 to 1024 (for MPL115) or 128 (for MPL3115).",
+                     oversampling_tmp);
+            return 1;
+        }
+        config_oversample = oversampling_tmp;
+    }
+    else if (strcasecmp (key, "Altitude") == 0)
+    {
+        config_altitude = atof (value);
+    }
+    else if (strcasecmp (key, "Normalization") == 0)
+    {
+        int normalize_tmp = atoi (value);
+        if (normalize_tmp < 0 || normalize_tmp > 2)
+        {
+            WARNING ("barometer: collectd_barometer_config: invalid normalization: %d",
+                     normalize_tmp);
+            return 1;
+        }
+        config_normalize = normalize_tmp;
+    }
+    else if (strcasecmp (key, "TemperatureSensor") == 0)
+    {
+        if(temp_list_add(temp_list, value))
+        {
+            return -1;
+        }
+    }
+    else if (strcasecmp (key, "PressureOffset") == 0)
+    {
+        config_press_offset = atof(value);
+    }
+    else if (strcasecmp (key, "TemperatureOffset") == 0)
+    {
+        config_temp_offset = atof(value);
+    }
+    else 
+    {
+        return -1;
+    }
+
+    return 0;
+}
+
+
+/** 
+ * Shutdown callback.
+ * 
+ * Close I2C and delete all the buffers.
+ * 
+ * @return Zero when successful (at the moment the only possible outcome)
+ */
+static int collectd_barometer_shutdown(void)
+{
+    DEBUG ("barometer: collectd_barometer_shutdown");
+
+    if(!is_MPL3115)
+    {
+        averaging_delete (&pressure_averaging);
+        averaging_delete (&temperature_averaging);
+
+        temp_list_delete(&temp_list);
+    }
+
+    if (i2c_bus_fd > 0)
+    {
+        close (i2c_bus_fd);
+        i2c_bus_fd = -1;
+        sfree (config_device);
+    }
+
+    return 0;
+}
+
+
+/** 
+ * Plugin read callback for MPL115.
+ * 
+ *  Dispatching will create values:
+ *  - <hostname>/barometer-mpl115/pressure-normalized
+ *  - <hostname>/barometer-mpl115/pressure-absolute
+ *  - <hostname>/barometer-mpl115/temperature
+ *
+ * @return Zero when successful.
+ */
+static int MPL115_collectd_barometer_read (void)
+{
+    int result = 0;
+
+    double pressure        = 0.0;
+    double temperature     = 0.0;
+    double norm_pressure   = 0.0;
+
+    value_list_t vl = VALUE_LIST_INIT;
+    value_t      values[1];
+    
+    DEBUG("barometer: MPL115_collectd_barometer_read");
+
+    if (!configured)
+    {
+        return -1;
+    }
+
+    /* Rather than delaying init, we will intitialize during first read. This
+       way at least we have a better chance to have the reference temperature
+       already available. */
+    if(!avg_initialized)
+    {
+        int i;
+        for(i=0; i<config_oversample-1; ++i)
+        {
+            result = MPL115_read_averaged(&pressure, &temperature);
+            if(result)
+            {
+                ERROR ("barometer: MPL115_collectd_barometer_read - mpl115 read, ignored during init");
+            }
+            DEBUG("barometer: MPL115_collectd_barometer_read - init %d / %d", i+1, config_oversample-1);
+            usleep(20000);
+        }
+        avg_initialized = 1;
+    }
+
+    result = MPL115_read_averaged(&pressure, &temperature);
+    if(result)
+        return result;
+
+    norm_pressure = abs_to_mean_sea_level_pressure(pressure);
+
+    sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+    sstrncpy (vl.plugin, "barometer", sizeof (vl.plugin));
+    sstrncpy (vl.plugin_instance, "mpl115", sizeof (vl.plugin_instance));
+
+    vl.values_len = 1;
+    vl.values = values;
+
+    /* dispatch normalized air pressure */
+    sstrncpy (vl.type, "pressure", sizeof (vl.type));
+    sstrncpy (vl.type_instance, "normalized", sizeof (vl.type_instance));
+    values[0].gauge = norm_pressure;
+    plugin_dispatch_values (&vl);
+
+    /* dispatch absolute air pressure */
+    sstrncpy (vl.type, "pressure", sizeof (vl.type));
+    sstrncpy (vl.type_instance, "absolute", sizeof (vl.type_instance));
+    values[0].gauge = pressure;
+    plugin_dispatch_values (&vl);
+
+    /* dispatch sensor temperature */
+    sstrncpy (vl.type, "temperature", sizeof (vl.type));
+    sstrncpy (vl.type_instance, "", sizeof (vl.type_instance));
+    values[0].gauge = temperature;
+    plugin_dispatch_values (&vl);
+
+    return 0;
+}
+
+
+/** 
+ * Plugin read callback for MPL3115.
+ * 
+ *  Dispatching will create values:
+ *  - <hostname>/barometer-mpl3115/pressure-normalized
+ *  - <hostname>/barometer-mpl3115/pressure-absolute
+ *  - <hostname>/barometer-mpl3115/temperature
+ *
+ * @return Zero when successful.
+ */
+static int MPL3115_collectd_barometer_read (void)
+{
+    int result = 0;
+    
+    double pressure        = 0.0;
+    double temperature     = 0.0;
+    double norm_pressure   = 0.0;
+    
+    value_list_t vl = VALUE_LIST_INIT;
+    value_t      values[1];
+    
+    DEBUG("barometer: MPL3115_collectd_barometer_read");
+    
+    if (!configured)
+    {
+        return -1;
+    }
+    
+    result = MPL3115_read(&pressure, &temperature);
+    if(result)
+        return result;
+
+    norm_pressure = abs_to_mean_sea_level_pressure(pressure);
+
+    sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+    sstrncpy (vl.plugin, "barometer", sizeof (vl.plugin));
+    sstrncpy (vl.plugin_instance, "mpl3115", sizeof (vl.plugin_instance));
+
+    vl.values_len = 1;
+    vl.values = values;
+
+    /* dispatch normalized air pressure */
+    sstrncpy (vl.type, "pressure", sizeof (vl.type));
+    sstrncpy (vl.type_instance, "normalized", sizeof (vl.type_instance));
+    values[0].gauge = norm_pressure;
+    plugin_dispatch_values (&vl);
+
+    /* dispatch absolute air pressure */
+    sstrncpy (vl.type, "pressure", sizeof (vl.type));
+    sstrncpy (vl.type_instance, "absolute", sizeof (vl.type_instance));
+    values[0].gauge = pressure;
+    plugin_dispatch_values (&vl);
+
+    /* dispatch sensor temperature */
+    sstrncpy (vl.type, "temperature", sizeof (vl.type));
+    sstrncpy (vl.type_instance, "", sizeof (vl.type_instance));
+    values[0].gauge = temperature;
+    plugin_dispatch_values (&vl);
+
+    return 0;
+}
+
+
+/** 
+ * Initialization callback
+ * 
+ * Check config, initialize I2C bus access, conversion coefficients and averaging
+ * ring buffers
+ * 
+ * @return Zero when successful.
+ */
+static int collectd_barometer_init (void)
+{
+    char errbuf[1024];
+
+    DEBUG ("barometer: collectd_barometer_init");
+
+    if (config_device == NULL)
+    {
+        ERROR("barometer: collectd_barometer_init I2C bus device not configured");
+        return -1;
+    }
+
+    if (config_normalize >= MSLP_INTERNATIONAL && isnan(config_altitude))
+    {
+        ERROR("barometer: collectd_barometer_init no altitude configured " \
+              "for mean sea level pressure normalization.");
+        return -1;
+    }
+
+    if (config_normalize == MSLP_DEU_WETT
+        &&
+        temp_list == NULL)
+    {
+        ERROR("barometer: collectd_barometer_init no temperature reference "\
+              "configured for mean sea level pressure normalization.");
+        return -1;
+    }
+
+
+    i2c_bus_fd = open(config_device, O_RDWR);
+    if (i2c_bus_fd < 0)
+    {
+        ERROR ("barometer: collectd_barometer_init problem opening I2C bus device \"%s\": %s (is loaded mod i2c-dev?)",
+               config_device,
+               sstrerror (errno, errbuf, sizeof (errbuf)));
+        return -1;
+    }
+
+    if (ioctl(i2c_bus_fd, I2C_SLAVE_FORCE, MPL115_I2C_ADDRESS) < 0)
+    {
+        ERROR("barometer: collectd_barometer_init problem setting i2c slave address to 0x%02X: %s",
+              MPL115_I2C_ADDRESS,
+              sstrerror (errno, errbuf, sizeof (errbuf)));
+        return -1;
+    }
+
+    /* detect sensor type - MPL115 or MPL3115 */
+    is_MPL3115 = MPL3115_detect();
+
+    /* init correct sensor type */
+    if(is_MPL3115) /* MPL3115 */
+    {
+        MPL3115_adjust_oversampling();
+
+        if(MPL3115_init_sensor())
+            return -1;
+
+        plugin_register_read ("barometer", MPL3115_collectd_barometer_read);
+    }
+    else /* MPL115 */
+    {
+        if (averaging_create (&pressure_averaging, config_oversample))
+        {
+            ERROR("barometer: collectd_barometer_init pressure averaging init failed");
+            return -1;
+        }
+        
+        if (averaging_create (&temperature_averaging, config_oversample))
+        {
+            ERROR("barometer: collectd_barometer_init temperature averaging init failed");
+            return -1;
+        }
+        
+        if (MPL115_read_coeffs() < 0)
+            return -1;
+
+        plugin_register_read ("barometer", MPL115_collectd_barometer_read);
+    }
+
+    configured = 1;
+    return 0;
+}
+
+/* ------------------------ plugin register / entry point ------------------------ */
+
+/** 
+ * Plugin "entry" - register all callback.
+ * 
+ */
+void module_register (void)
+{
+    plugin_register_config ("barometer", 
+                            collectd_barometer_config, 
+                            config_keys, 
+                            config_keys_num);
+    plugin_register_init ("barometer", collectd_barometer_init);
+    plugin_register_shutdown ("barometer", collectd_barometer_shutdown);
+}
index 4178d8b..ce58181 100644 (file)
@@ -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>
  *   Michał Mirosław <mirq-linux at rere.qmqm.pl>
  **/
 
@@ -71,7 +71,7 @@ static const char *battery_acpi_dir = "/proc/acpi/battery";
 static int battery_init (void)
 {
 #if HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H
-       /* No init neccessary */
+       /* No init necessary */
 /* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */
 
 #elif KERNEL_LINUX
index ddde840..2f990a2 100644 (file)
@@ -1395,7 +1395,7 @@ static int bind_init (void) /* {{{ */
 
   curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1L);
   curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, bind_curl_callback);
-  curl_easy_setopt (curl, CURLOPT_USERAGENT, PACKAGE_NAME"/"PACKAGE_VERSION);
+  curl_easy_setopt (curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
   curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, bind_curl_error);
   curl_easy_setopt (curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL);
   curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L);
index 17b12d0..6d41972 100644 (file)
@@ -144,7 +144,7 @@ static int read_cpuacct_procs (const char *dirname, char const *cgroup_name,
 
 /*
  * Gets called for every file/folder in /sys/fs/cgroup/cpu,cpuacct (or
- * whereever cpuacct is mounted on the system). Calls walk_directory with the
+ * wherever cpuacct is mounted on the system). Calls walk_directory with the
  * read_cpuacct_procs callback on every folder it finds, such as "system".
  */
 static int read_cpuacct_root (const char *dirname, const char *filename,
index 6f58542..282098e 100644 (file)
@@ -69,6 +69,6 @@ The C<email plugin> has been written by Sebastian Harl E<lt>shE<nbsp>atE<nbsp>to
 
 The SpamAssassin-plugin has been written by Alexander Wirt E<lt>formorerE<nbsp>atE<nbsp>formorer.deE<gt>.
 
-This manpage has been written by Florian Forster E<lt>octoE<nbsp>atE<nbsp>verplant.orgE<gt>.
+This manpage has been written by Florian Forster E<lt>octoE<nbsp>atE<nbsp>collectd.orgE<gt>.
 
 =cut
index 2c59630..5f2c687 100644 (file)
@@ -169,6 +169,19 @@ table. All the options are optional, but B<plugin_instance> without B<plugin>
 or B<type_instance> without B<type> doesn't make much sense and should be
 avoided.
 
+=item B<type:key=>I<value>
+
+Sets user defined meta information. The B<type> key is a single character
+defining the type of the meta information.
+
+The current supported types are:
+
+=over 8
+
+=item B<s> A string passed as-is.
+
+=back
+
 =back
 
 =back
@@ -291,6 +304,6 @@ L<fork(2)>, L<exec(3)>
 
 =head1 AUTHOR
 
-Florian Forster E<lt>octo@verplant.orgE<gt>
+Florian Forster E<lt>octo@collectd.orgE<gt>
 
 =cut
index 00f209a..aade08a 100644 (file)
@@ -693,5 +693,5 @@ L<types.db(5)>
 
 =head1 AUTHOR
 
-Florian Forster E<lt>octoE<nbsp>atE<nbsp>verplant.orgE<gt>
+Florian Forster E<lt>octoE<nbsp>atE<nbsp>collectd.orgE<gt>
 
index e31d95c..2719093 100644 (file)
@@ -2,21 +2,26 @@
  * collectd-nagios - src/collectd-nagios.c
  * Copyright (C) 2008-2010  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #if HAVE_CONFIG_H
index aab753c..e28ff4b 100644 (file)
@@ -121,6 +121,6 @@ L<http://nagios.org/>
 
 =head1 AUTHOR
 
-Florian Forster E<lt>octoE<nbsp>atE<nbsp>verplant.orgE<gt>
+Florian Forster E<lt>octoE<nbsp>atE<nbsp>collectd.orgE<gt>
 
 =cut
index 669e3f4..38d790e 100644 (file)
@@ -716,7 +716,7 @@ types used by the read, write and match functions.
 =item
 
 Please feel free to send in new plugins to collectd's mailing list at
-E<lt>collectdE<nbsp>atE<nbsp>verplant.orgE<gt> for review and, possibly,
+E<lt>collectdE<nbsp>atE<nbsp>collectd.orgE<gt> for review and, possibly,
 inclusion in the main distribution. In the latter case, we will take care of
 keeping the plugin up to date and adapting it to new versions of collectd.
 
@@ -796,7 +796,7 @@ The C<perl plugin> has been written by Sebastian Harl
 E<lt>shE<nbsp>atE<nbsp>tokkee.orgE<gt>.
 
 This manpage has been written by Florian Forster
-E<lt>octoE<nbsp>atE<nbsp>verplant.orgE<gt> and Sebastian Harl
+E<lt>octoE<nbsp>atE<nbsp>collectd.orgE<gt> and Sebastian Harl
 E<lt>shE<nbsp>atE<nbsp>tokkee.orgE<gt>.
 
 =cut
index 426a711..6645614 100644 (file)
@@ -663,7 +663,7 @@ types used by the read, write and match functions.
 =item
 
 Please feel free to send in new plugins to collectd's mailing list at
-E<lt>collectdE<nbsp>atE<nbsp>verplant.orgE<gt> for review and, possibly,
+E<lt>collectdE<nbsp>atE<nbsp>collectd.orgE<gt> for review and, possibly,
 inclusion in the main distribution. In the latter case, we will take care of
 keeping the plugin up to date and adapting it to new versions of collectd.
 
@@ -730,7 +730,7 @@ Sven Trenkel E<lt>collectdE<nbsp>atE<nbsp>semidefinite.deE<gt>.
 This manpage has been written by Sven Trenkel
 E<lt>collectdE<nbsp>atE<nbsp>semidefinite.deE<gt>.
 It is based on the L<collectd-perl(5)> manual page by
-Florian Forster E<lt>octoE<nbsp>atE<nbsp>verplant.orgE<gt> and
+Florian Forster E<lt>octoE<nbsp>atE<nbsp>collectd.orgE<gt> and
 Sebastian Harl E<lt>shE<nbsp>atE<nbsp>tokkee.orgE<gt>.
 
 =cut
index fd7a508..65a9b7c 100644 (file)
@@ -43,6 +43,17 @@ collectd-snmp - Documentation of collectd's C<snmp plugin>
       Community "another_string"
       Collect "std_traffic" "hr_users"
     </Host>
+    <Host "secure.router.mydomain.org">
+      Address "192.168.0.7"
+      Version 3
+      SecurityLevel "authPriv"
+      Username "cosmo"
+      AuthProtocol "SHA"
+      AuthPassphrase "setec_astronomy"
+      PrivacyProtocol "AES"
+      PrivacyPassphrase "too_many_secrets"
+      Collect "std_traffic"
+    </Host>
     <Host "some.ups.mydomain.org">
       Address "192.168.0.3"
       Version 1
@@ -175,7 +186,7 @@ traffic.
 =item B<Scale> I<Value>
 
 The gauge-values returned by the SNMP-agent are multiplied by I<Value>.  This
-is useful when values are transfered as a fixed point real number. For example,
+is useful when values are transferred as a fixed point real number. For example,
 thermometers may transfer B<243> but actually mean B<24.3>, so you can specify
 a scale value of B<0.1> to correct this. The default value is, of course,
 B<1.0>.
@@ -191,6 +202,18 @@ degrees Celsius. The default value is, of course, B<0.0>.
 
 This value is not applied to counter-values.
 
+=item B<Ignore> I<Value> [, I<Value> ...]
+
+The ignore values allows to ignore Instances based on their name and the patterns
+specified by the various values you've entered. The match is a glob-type shell
+matching.
+
+=item B<InvertMatch> I<true|false(default)>
+
+The invertmatch value should be use in combination of the Ignore option.
+It changes the behaviour of the Ignore option, from a blacklist behaviour
+when InvertMatch is set to false, to a whitelist when specified to true.
+
 =back
 
 =head2 The Host block
@@ -207,14 +230,41 @@ stored by collectd.
 
 Set the address to connect to.
 
-=item B<Version> B<1>|B<2>
+=item B<Version> B<1>|B<2>|B<3>
 
 Set the SNMP version to use. When giving B<2> version C<2c> is actually used.
-Version 3 is not supported by this plugin.
 
 =item B<Community> I<Community>
 
-Pass I<Community> to the host.
+Pass I<Community> to the host. (Ignored for SNMPv3).
+
+=item B<Username> I<Username>
+
+Sets the I<Username> to use for SNMPv3 security.
+
+=item B<SecurityLevel> I<authPriv>|I<authNoPriv>|I<noAuthNoPriv>
+
+Selects the security level for SNMPv3 security.
+
+=item B<Context> I<Context>
+
+Sets the I<Context> for SNMPv3 security.
+
+=item B<AuthProtocol> I<MD5>|I<SHA>
+
+Selects the authentication protocol for SNMPv3 security.
+
+=item B<AuthPassphrase> I<Passphrase>
+
+Sets the authentication passphrase for SNMPv3 security. 
+
+=item B<PrivacyProtocol> I<AES>|I<DES>
+
+Selects the privacy (encryption) protocol for SNMPv3 security.
+
+=item B<PrivacyPassphrase> I<Passphrase>
+
+Sets the privacy (encryption) passphrase for SNMPv3 security. 
 
 =item B<Collect> I<Data> [I<Data> ...]
 
@@ -241,8 +291,9 @@ L<snmpgetnext(1)>,
 L<variables(5)>,
 L<unix(7)>
 
-=head1 AUTHOR
+=head1 AUTHORS
 
-Florian Forster E<lt>octo@verplant.orgE<gt>
+Florian Forster E<lt>octo@collectd.orgE<gt>
+Michael Pilat E<lt>mike@mikepilat.comE<gt>
 
 =cut
index 9fec340..45e788c 100644 (file)
@@ -1,19 +1,24 @@
 /**
- * collectd-td - collectd traffic generator
+ * collectd-tg - src/collectd-tg.c
  * Copyright (C) 2010-2012  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian Forster <octo at collectd.org>
@@ -94,7 +99,7 @@ static void exit_usage (int exit_status) /* {{{ */
       "    -h             Print usage information (this output).\n"
       "\n"
       "Copyright (C) 2010-2012  Florian Forster\n"
-      "Licensed under the GNU General Public License, version 2 (GPLv2)\n",
+      "Licensed under the MIT license.\n",
       DEF_NUM_VALUES, DEF_NUM_HOSTS, DEF_NUM_PLUGINS,
       DEF_INTERVAL,
       NET_DEFAULT_V6_ADDR, NET_DEFAULT_PORT);
index c572df1..b241a9f 100644 (file)
@@ -177,11 +177,24 @@ table. All the options are optional, but B<plugin_instance> without B<plugin>
 or B<type_instance> without B<type> doesn't make much sense and should be
 avoided.
 
-Please note that this is the same format as used in the B<exec plugin>, see
-L<collectd-exec(5)>.
+=item B<type:key=>I<value>
+
+Sets user defined meta information. The B<type> key is a single character
+defining the type of the meta information.
+
+The current supported types are:
+
+=over 8
+
+=item B<s> A string passed as-is.
 
 =back
 
+=back
+
+Please note that this is the same format as used in the B<exec plugin>, see
+L<collectd-exec(5)>.
+
 Example:
   -> | PUTNOTIF type=temperature severity=warning time=1201094702 message=The roof is on fire!
   <- | 0 Success
@@ -243,6 +256,6 @@ L<unix(7)>
 
 =head1 AUTHOR
 
-Florian Forster E<lt>octo@verplant.orgE<gt>
+Florian Forster E<lt>octo@collectd.orgE<gt>
 
 =cut
index d259753..f711fb7 100644 (file)
@@ -2,21 +2,26 @@
  * collectd - src/collectd.c
  * Copyright (C) 2005-2007  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  *   Alvaro Barcellos <alvaro.barcellos at gmail.com>
  **/
 
@@ -41,6 +46,7 @@
  */
 char hostname_g[DATA_MAX_NAME_LEN];
 cdtime_t interval_g;
+int  pidfile_from_cli = 0;
 int  timeout_g;
 #if HAVE_LIBKSTAT
 kstat_ctl_t *kc;
@@ -275,7 +281,7 @@ static void exit_usage (int status)
                        "  Plugin directory  "PLUGINDIR"\n"
                        "  Data directory    "PKGLOCALSTATEDIR"\n"
                        "\n"PACKAGE" "VERSION", http://collectd.org/\n"
-                       "by Florian octo Forster <octo@verplant.org>\n"
+                       "by Florian octo Forster <octo@collectd.org>\n"
                        "for contributions see `AUTHORS'\n");
        exit (status);
 } /* static void exit_usage (int status) */
@@ -439,6 +445,7 @@ int main (int argc, char **argv)
 #if COLLECT_DAEMON
                        case 'P':
                                global_option_set ("PIDFile", optarg);
+                               pidfile_from_cli = 1;
                                break;
                        case 'f':
                                daemonize = 0;
index 678cfb3..4d5abe0 100644 (file)
@@ -52,6 +52,7 @@
 
 @LOAD_PLUGIN_SYSLOG@LoadPlugin syslog
 @LOAD_PLUGIN_LOGFILE@LoadPlugin logfile
+@LOAD_PLUGIN_LOG_LOGSTASH@LoadPlugin log_logstash
 
 #<Plugin logfile>
 #      LogLevel @DEFAULT_LOG_LEVEL@
 #      PrintSeverity false
 #</Plugin>
 
+#<Plugin log_logstash>
+#      LogLevel @DEFAULT_LOG_LEVEL@
+#      File "@localstatedir@/log/@PACKAGE_NAME@.json.log"
+#</Plugin>
+
 #<Plugin syslog>
 #      LogLevel @DEFAULT_LOG_LEVEL@
 #</Plugin>
@@ -81,6 +87,7 @@
 #@BUILD_PLUGIN_APPLE_SENSORS_TRUE@LoadPlugin apple_sensors
 #@BUILD_PLUGIN_AQUAERO_TRUE@LoadPlugin aquaero
 #@BUILD_PLUGIN_ASCENT_TRUE@LoadPlugin ascent
+#@BUILD_PLUGIN_BAROMETER_TRUE@LoadPlugin barometer
 #@BUILD_PLUGIN_BATTERY_TRUE@LoadPlugin battery
 #@BUILD_PLUGIN_BIND_TRUE@LoadPlugin bind
 #@BUILD_PLUGIN_CONNTRACK_TRUE@LoadPlugin conntrack
 #@BUILD_PLUGIN_DF_TRUE@LoadPlugin df
 #@BUILD_PLUGIN_DISK_TRUE@LoadPlugin disk
 #@BUILD_PLUGIN_DNS_TRUE@LoadPlugin dns
+#@BUILD_PLUGIN_DRBD_TRUE@LoadPlugin drbd
 #@BUILD_PLUGIN_EMAIL_TRUE@LoadPlugin email
 #@BUILD_PLUGIN_ENTROPY_TRUE@LoadPlugin entropy
 #@BUILD_PLUGIN_ETHSTAT_TRUE@LoadPlugin ethstat
 #@BUILD_PLUGIN_WIRELESS_TRUE@LoadPlugin wireless
 #@BUILD_PLUGIN_WRITE_GRAPHITE_TRUE@LoadPlugin write_graphite
 #@BUILD_PLUGIN_WRITE_HTTP_TRUE@LoadPlugin write_http
+#@BUILD_PLUGIN_WRITE_KAFKA_TRUE@LoadPlugin write_kafka
 #@BUILD_PLUGIN_WRITE_MONGODB_TRUE@LoadPlugin write_mongodb
 #@BUILD_PLUGIN_WRITE_REDIS_TRUE@LoadPlugin write_redis
 #@BUILD_PLUGIN_WRITE_RIEMANN_TRUE@LoadPlugin write_riemann
+#@BUILD_PLUGIN_WRITE_TSDB_TRUE@LoadPlugin write_tsdb
 #@BUILD_PLUGIN_XMMS_TRUE@LoadPlugin xmms
 #@BUILD_PLUGIN_ZFS_ARC_TRUE@LoadPlugin zfs_arc
 
 # ription of those options is available in the collectd.conf(5) manual page. #
 ##############################################################################
 
-#<Plugin "aggregation">
+#<Plugin aggregation>
 #  <Aggregation>
 #    #Host "unspecified"
 #    Plugin "cpu"
 #  </Aggregation>
 #</Plugin>
 
-#<Plugin "amqp">
+#<Plugin amqp>
 #  <Publish "name">
 #    Host "localhost"
 #    Port "5672"
 #      CACert "/etc/ssl/ca.crt"
 #</Plugin>
 
+#<Plugin "barometer">
+#   Device            "/dev/i2c-0";
+#   Oversampling      512
+#   PressureOffset    0.0
+#   TemperatureOffset 0.0
+#   Normalization     2
+#   Altitude          238.0
+#   TemperatureSensor "myserver/onewire-F10FCA000800/temperature"
+#</Plugin>
+
 #<Plugin "bind">
 #  URL "http://localhost:8053/"
 #  ParseTime       false
 #  IgnoreSelected false
 #</Plugin>
 
+#<Plugin cpu>
+#  ReportActive false
+#  ReportByCpu true
+#  ValuesPercentage false
+#</Plugin>
+#
 #<Plugin csv>
 #      DataDir "@localstatedir@/lib/@PACKAGE_NAME@/csv"
 #      StoreRates false
 #  </URL>
 #</Plugin>
 
-#<Plugin "curl_xml">
+#<Plugin curl_xml>
 #  <URL "http://localhost/stats.xml">
 #    Host "my_host"
 #    Instance "some_instance"
 #<Plugin disk>
 #      Disk "/^[hs]d[a-f][0-9]?$/"
 #      IgnoreSelected false
+#      UseBSDName false
+#      UdevNameAttr "DEVNAME"
 #</Plugin>
 
 #<Plugin dns>
 #      </Directory>
 #</Plugin>
 
-#<Plugin "gmond">
+#<Plugin gmond>
 #  MCReceiveFrom "239.2.11.71" "8649"
 #  <Metric "swap_total">
 #    Type "swap"
 #      IgnoreSelected true
 #</Plugin>
 
-#<Plugin "java">
+#<Plugin java>
 #      JVMArg "-verbose:jni"
 #      JVMArg "-Djava.class.path=@prefix@/share/collectd/java/collectd-api.jar"
 #
 #      IgnoreSelected false
 #      HostnameFormat name
 #      InterfaceFormat name
+#      PluginInstanceFormat name
+#</Plugin>
+
+#<Plugin load>
+#        ReportRelative true
 #</Plugin>
 
 #<Plugin lpar>
 #      </Instance>
 #</Plugin>
 
+#<Plugin memory>
+#      ValuesAbsolute true
+#      ValuesPercentage false
+#</Plugin>
+
 #<Plugin modbus>
 #      <Data "data_name">
 #              RegisterBase 1234
 #              Password "secret"
 #              Database "db_name"
 #              MasterStats true
+#              ConnectTimeout 10
+#              InnodbStats true
 #      </Database>
 #
 #      <Database db_name2>
+#              Alias "squeeze"
 #              Host "localhost"
 #              Socket "/var/run/mysql/mysqld.sock"
 #              SlaveStats true
 #  TimerPercentile 90.0
 #</Plugin>
 
-#<Plugin "swap">
+#<Plugin swap>
 #      ReportByDevice false
 #      ReportBytes true
+#      ValuesAbsolute true
+#      ValuesPercentage false
 #</Plugin>
 
-#<Plugin "table">
+#<Plugin table>
 #      <Table "/proc/slabinfo">
 #              Instance "slabinfo"
 #              Separator " "
 #      </Table>
 #</Plugin>
 
-#<Plugin "tail">
+#<Plugin tail>
 #  <File "/var/log/exim4/mainlog">
 #    Instance "exim"
+#    Interval 60
 #    <Match>
 #      Regex "S=([1-9][0-9]*)"
 #      DSType "CounterAdd"
 #  </File>
 #</Plugin>
 
-#<Plugin "tail_csv">
+#<Plugin tail_csv>
 #   <Metric "dropped">
 #       Type "percent"
 #       Instance "dropped"
 #              VerifyPeer true
 #              VerifyHost true
 #              CACert "/etc/ssl/ca.crt"
+#              CAPath "/etc/ssl/certs/"
+#              ClientKey "/etc/ssl/client.pem"
+#              ClientCert "/etc/ssl/client.crt"
+#              ClientKeyPass "secret"
+#              SSLVersion "TLSv1"
 #              Format "Command"
 #              StoreRates false
 #      </URL>
 #</Plugin>
 
+#<Plugin write_kafka>
+#  Property "metadata.broker.list" "localhost:9092"
+#  <Topic "collectd">
+#    Format JSON
+#  </Topic>
+#</Plugin>
+
 #<Plugin write_mongodb>
 #      <Node "example">
 #              Host "localhost"
 #              TTLFactor 2.0
 #      </Node>
 #      Tag "foobar"
+#       Attribute "foo" "bar"
+#</Plugin>
+
+#<Plugin write_tsdb>
+#      <Node>
+#              Host "localhost"
+#              Port "4242"
+#              HostTags "status=production"
+#              StoreRates false
+#              AlwaysAppendDS false
+#      </Node>
 #</Plugin>
 
 ##############################################################################
 ##############################################################################
 
 #@BUILD_PLUGIN_THRESHOLD_TRUE@LoadPlugin "threshold"
-#<Plugin "threshold">
+#<Plugin threshold>
 #  <Type "foo">
 #    WarningMin    0.00
 #    WarningMax 1000.00
index 81c8f4c..3a8af84 100644 (file)
@@ -9,14 +9,14 @@ collectd.conf - Configuration for the system statistics collection daemon B<coll
   BaseDir "/path/to/data/"
   PIDFile "/path/to/pidfile/collectd.pid"
   Server  "123.123.123.123" 12345
-  
+
   LoadPlugin cpu
   LoadPlugin load
-  
+
   <LoadPlugin df>
     Interval 3600
   </LoadPlugin>
-  
+
   LoadPlugin ping
   <Plugin ping>
     Host "example.org"
@@ -341,10 +341,10 @@ The full example configuration looks like this:
    <Aggregation>
      Plugin "cpu"
      Type "cpu"
-     
+
      GroupBy "Host"
      GroupBy "TypeInstance"
-     
+
      CalculateSum true
      CalculateAverage true
    </Aggregation>
@@ -420,13 +420,13 @@ The following example calculates the average usage of all "even" CPUs:
      Plugin "cpu"
      PluginInstance "/[0,2,4,6,8]$/"
      Type "cpu"
-     
+
      SetPlugin "cpu"
      SetPluginInstance "even-%{aggregation}"
-     
+
      GroupBy "Host"
      GroupBy "TypeInstance"
-     
+
      CalculateAverage true
    </Aggregation>
  </Plugin>
@@ -497,7 +497,7 @@ possibly filtering or messages.
  #   GraphiteSeparateInstances false
  #   GraphiteAlwaysAppendDS false
    </Publish>
-   
+
    # Receive values from an AMQP broker
    <Subscribe "some_name">
      Host "localhost"
@@ -508,6 +508,8 @@ possibly filtering or messages.
      Exchange "amq.fanout"
  #   ExchangeType "fanout"
  #   Queue "queue_name"
+ #   QueueDurable false
+ #   QueueAutoDelete true
  #   RoutingKey "collectd.#"
    </Subscribe>
  </Plugin>
@@ -560,9 +562,23 @@ be bound to this exchange.
 
 =item B<Queue> I<Queue> (Subscribe only)
 
-Configures the I<queue> name to subscribe to. If no queue name was configures
+Configures the I<queue> name to subscribe to. If no queue name was configured
 explicitly, a unique queue name will be created by the broker.
 
+=item B<QueueDurable> B<true>|B<false> (Subscribe only)
+
+Defines if the I<queue> subscribed to is durable (saved to persistent storage)
+or transient (will disappear if the AMQP broker is restarted). Defaults to
+"false".
+
+This option should be used in conjunction with the I<Persistent> option on the
+publish side.
+
+=item B<QueueAutoDelete> B<true>|B<false> (Subscribe only)
+
+Defines if the I<queue> subscribed to will be deleted once the last consumer
+unsubscribes. Defaults to "true".
+
 =item B<RoutingKey> I<Key>
 
 In I<Publish> blocks, this configures the routing key to set on all outgoing
@@ -811,6 +827,131 @@ and are checked by default depends on the distribution you use.
 
 =back
 
+=head2 Plugin C<barometer>
+
+This plugin reads absolute air pressure using digital barometer sensor MPL115A2
+or MPL3115 from Freescale (sensor attached to any I2C bus available in
+the computer, for HW details see 
+I<http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPL115A> or
+I<http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPL3115A2>).
+The sensor type - one fo these two - is detected automatically by the plugin
+and indicated in the plugin_instance (typically you will see subdirectory
+"barometer-mpl115" or "barometer-mpl3115").
+
+The plugin provides absolute barometric pressure, air pressure reduced to sea
+level (several possible approximations) and as an auxiliary value also internal
+sensor temperature. It uses (expects/provides) typical metric units - pressure
+in [hPa], temperature in [C], altitude in [m].
+
+It was developed and tested under Linux only. The only platform dependency is
+the standard Linux i2c-dev interface (the particular bus driver has to
+support the SM Bus command subset).
+
+The reduction or normalization to mean sea level pressure requires (depedning on
+selected method/approximation) also altitude and reference to temperature sensor(s).
+When multiple temperature sensors are configured the minumum of their values is
+always used (expecting that the warmer ones are affected by e.g. direct sun light
+at that moment).
+
+Synopsis:
+
+  <Plugin "barometer">
+     Device            "/dev/i2c-0";
+     Oversampling      512
+     PressureOffset    0.0
+     TemperatureOffset 0.0
+     Normalization     2
+     Altitude          238.0
+     TemperatureSensor "myserver/onewire-F10FCA000800/temperature"
+  </Plugin>
+
+=over 4
+
+=item B<Device> I<device>
+
+Device name of the I2C bus to which the sensor is connected. Note that typically
+you need to have loaded the i2c-dev module.
+Using i2c-tools you can check/list i2c buses available on your system by:
+
+  i2cdetect -l
+
+Then you can scan for devices on given bus. E.g. to scan the whole bus 0 use:
+
+  i2cdetect -y -a 0
+
+This way you should be able to verify that the pressure sensor (either type) is
+connected and detected on address 0x60.
+
+=item B<Oversampling> I<value>
+
+For MPL115 this is the size of the averaging window. To filter out sensor noise
+a simple averaging using floating window of configurable size is used. The plugin
+will use average of the last C<value> measurements (value of 1 means no averaging).
+Minimal size is 1, maximal 1024.
+
+For MPL3115 this is the oversampling value. The actual oversampling is performed
+by the sensor and the higher value the higher accuracy and longer conversion time
+(although nothing to worry about in the collectd context). Supported values are:
+1, 2, 4, 8, 16, 32, 64 and 128. Any other value is adjusted by the plugin to
+the closest supported one. Default is 128.
+
+=item B<PressureOffset> I<offset>
+
+You can further calibrate the sensor by supplying pressure and/or temperature offsets.
+This is added to the measured/caclulated value (i.e. if the measured value is too high
+then use negative offset).
+In hPa, default is 0.0.
+
+=item B<TemperatureOffset> I<offset>
+
+You can further calibrate the sensor by supplying pressure and/or temperature offsets.
+This is added to the measured/caclulated value (i.e. if the measured value is too high
+then use negative offset).
+In C, default is 0.0.
+
+=item B<Normalization> I<method>
+
+Normalization method - what approximation/model is used to compute mean sea
+level pressure from the air absolute pressure.
+
+Supported values of the C<method> (integer between from 0 to 2) are:
+
+=over 5
+
+=item B<0> - no conversion, absolute pressrure is simply copied over. For this method you
+       do not need to configure C<Altitude> or C<TemperatureSensor>.
+
+=item B<1> - international formula for conversion ,
+See I<http://en.wikipedia.org/wiki/Atmospheric_pressure#Altitude_atmospheric_pressure_variation>.
+For this method you have to configure C<Altitude> but do not need C<TemperatureSensor>
+(uses fixed global temperature average instead).
+
+=item B<2> - formula as recommended by the Deutsche Wetterdienst (German
+Meteorological Service).
+See I<http://de.wikipedia.org/wiki/Barometrische_H%C3%B6henformel#Theorie>
+For this method you have to configure both  C<Altitude> and C<TemperatureSensor>.
+
+=back
+
+
+=item B<Altitude> I<altitude>
+
+The altitude (in meters) of the location where you meassure the pressure.
+
+=item B<TemperatureSensor> I<reference>
+
+Temperature sensor which should be used as a reference when normalizing the pressure.
+When specified more sensors a minumum is found and uses each time.
+The temperature reading directly from this pressure sensor/plugin
+is typically not suitable as the pressure sensor
+will be probably inside while we want outside temperature. 
+The collectd reference name is something like
+<hostname>/<plugin_name>-<plugin_instance>/<type>-<type_instance>
+(<type_instance> is usually omitted when there is just single value type).
+Or you can figure it out from the path of the output data files.
+
+=back
+
 =head2 Plugin C<bind>
 
 Starting with BIND 9.5.0, the most widely used DNS server software provides
@@ -837,17 +978,17 @@ Synopsis:
    ParseTime       false
    OpCodes         true
    QTypes          true
+
    ServerStats     true
    ZoneMaintStats  true
    ResolverStats   false
    MemoryStats     true
+
    <View "_default">
      QTypes        true
      ResolverStats true
      CacheRRSets   true
+
      Zone "127.in-addr.arpa/IN"
    </View>
  </Plugin>
@@ -988,6 +1129,44 @@ at all, B<all> cgroups are selected.
 
 =back
 
+=head2 Plugin C<conntrack>
+
+This plugin collects IP conntrack statistics.
+
+=over 4
+
+=item B<OldFiles>
+
+Assume the B<conntrack_count> and B<conntrack_max> files to be found in
+F</proc/sys/net/ipv4/netfilter> instead of F</proc/sys/net/netfilter/>.
+
+=back
+
+=head2 Plugin C<cpu>
+
+The I<CPU plugin> collects CPU usage metrics.
+
+The following configuration options are available:
+
+=over 4
+
+=item B<ReportActive> B<false>|B<true>
+
+Reports non-idle CPU usage as the "active" value. Defaults to false.
+
+=item B<ReportByCpu> B<false>|B<true>
+
+When true reports usage for all cores. When false, reports cpu usage
+aggregated over all cores.
+Defaults to true.
+
+=item B<ValuesPercentage> B<false>|B<true>
+
+When true report percentage usage instead of tick values. Defaults to false.
+
+=back
+
+
 =head2 Plugin C<cpufreq>
 
 This plugin doesn't have any options. It reads
@@ -1061,6 +1240,10 @@ Username to use if authorization is required to read the page.
 
 Password to use if authorization is required to read the page.
 
+=item B<Digest> B<true>|B<false>
+
+Enable HTTP digest authentication.
+
 =item B<VerifyPeer> B<true>|B<false>
 
 Enable or disable peer SSL certificate verification. See
@@ -1171,12 +1354,25 @@ The following options are valid within B<URL> blocks:
 
 Sets the plugin instance to I<Instance>.
 
+=item B<Interval> I<Interval>
+
+Sets the interval (in seconds) in which the values will be collected from this
+URL. By default the global B<Interval> setting will be used.
+
 =item B<User> I<Name>
+
 =item B<Password> I<Password>
+
+=item B<Digest> B<true>|B<false>
+
 =item B<VerifyPeer> B<true>|B<false>
+
 =item B<VerifyHost> B<true>|B<false>
+
 =item B<CACert> I<file>
+
 =item B<Header> I<Header>
+
 =item B<Post> I<Body>
 
 These options behave exactly equivalent to the appropriate options of the
@@ -1265,6 +1461,8 @@ Examples:
 
 =item B<Password> I<Password>
 
+=item B<Digest> B<true>|B<false>
+
 =item B<VerifyPeer> B<true>|B<false>
 
 =item B<VerifyHost> B<true>|B<false>
@@ -1504,6 +1702,16 @@ it should be able to handle integer an floating point types, as well as strings
 
 There must be at least one B<ValuesFrom> option inside each B<Result> block.
 
+=item B<MetadataFrom> [I<column0> I<column1> ...]
+
+Names the columns whose content is used as metadata for the data sets
+that are dispatched to the daemon. 
+
+The actual data type in the columns is not that important. The plugin will
+automatically cast the values to the right type if it know how to do that. So
+it should be able to handle integer an floating point types, as well as strings
+(if they include a number at the beginning).
+
 =back
 
 =head3 B<Database> blocks
@@ -1618,17 +1826,17 @@ transfer agents and web caches.
 
 =item B<ValuesAbsolute> B<true>|B<false>
 
-Enables or disables reporting of free, used and used disk space in 1K-blocks. 
-Defaults to true.
+Enables or disables reporting of free and used disk space in 1K-blocks.
+Defaults to B<true>.
 
-=item B<ValuesPercentage> B<true>|B<false>
+=item B<ValuesPercentage> B<false>|B<true>
 
-Enables or disables reporting of free, used and used disk space in percentage.
-Defaults to false.
+Enables or disables reporting of free and used disk space in percentage.
+Defaults to B<false>.
 
-This is useful for deploying collectd on the cloud, where machines with
-different disk size may exist. Then it is more practical to configure thresholds
-based on relative disk size.
+This is useful for deploying I<collectd> on the cloud, where machines with
+different disk size may exist. Then it is more practical to configure
+thresholds based on relative disk size.
 
 =back
 
@@ -1664,6 +1872,20 @@ collected. If at least one B<Disk> option is given and no B<IgnoreSelected> or
 set to B<false>, B<only> matching disks will be collected. If B<IgnoreSelected>
 is set to B<true>, all disks are collected B<except> the ones matched.
 
+=item B<UseBSDName> B<true>|B<false>
+
+Whether to use the device's "BSD Name", on MacE<nbsp>OSE<nbsp>X, instead of the
+default major/minor numbers. Requires collectd to be built with Apple's
+IOKitLib support.
+
+=item B<UdevNameAttr> I<Attribute>
+
+Attempt to override disk instance name with the value of a specified udev
+attribute when built with B<libudev>.  If the attribute is not defined for the
+given device, the default name is used. Example:
+
+  UdevNameAttr "DM_NAME"
+
 =back
 
 =head2 Plugin C<dns>
@@ -2212,8 +2434,35 @@ setting B<name>.
 B<address> means use the interface's mac address. This is useful since the
 interface path might change between reboots of a guest or across migrations.
 
+=item B<PluginInstanceFormat> B<name|uuid>
+
+When the libvirt plugin logs data, it sets the plugin_instance of the collected 
+data according to this setting. The default is to use the guest name as provided 
+by the hypervisor, which is equal to setting B<name>.
+
+B<uuid> means use the guest's UUID.
+
 =back
 
+=head2 Plugin C<load>
+
+The I<Load plugin> collects the system load. These numbers give a rough overview
+over the utilization of a machine. The system load is defined as the number of
+runnable tasks in the run-queue and is provided by many operating systems as a
+one, five or fifteen minute average.
+
+The following configuration options are available:
+
+=over 4
+
+=item B<ReportRelative> B<false>|B<true>
+
+When enabled, system load divided by number of available CPU cores is reported
+for intervals 1 min, 5 min and 15 min. Defaults to false.
+
+=back
+
+
 =head2 Plugin C<logfile>
 
 =over 4
@@ -2248,6 +2497,34 @@ B<Note>: There is no need to notify the daemon after moving or removing the
 log file (e.E<nbsp>g. when rotating the logs). The plugin reopens the file
 for each line it writes.
 
+=head2 Plugin C<log_logstash>
+
+The I<log logstash plugin> behaves like the logfile plugin but formats
+messages as JSON events for logstash to parse and input.
+
+=over 4
+
+=item B<LogLevel> B<debug|info|notice|warning|err>
+
+Sets the log-level. If, for example, set to B<notice>, then all events with
+severity B<notice>, B<warning>, or B<err> will be written to the logfile.
+
+Please note that B<debug> is only available if collectd has been compiled with
+debugging support.
+
+=item B<File> I<File>
+
+Sets the file to write log messages to. The special strings B<stdout> and
+B<stderr> can be used to write to the standard output and standard error
+channels, respectively. This, of course, only makes much sense when I<collectd>
+is running in foreground- or non-daemon-mode.
+
+=back
+
+B<Note>: There is no need to notify the daemon after moving or removing the
+log file (e.E<nbsp>g. when rotating the logs). The plugin reopens the file
+for each line it writes.
+
 =head2 Plugin C<lpar>
 
 The I<LPAR plugin> reads CPU statistics of I<Logical Partitions>, a
@@ -2421,7 +2698,7 @@ B<Synopsis:>
    ShowCPU true
    ShowCPUCores true
    ShowMemory true
-   
+
    ShowTemperatures true
    Temperature vddg
    Temperature vddq
@@ -2430,7 +2707,7 @@ B<Synopsis:>
    ShowPower true
    Power total0
    Power total1
-   IgnoreSelectedPower true   
+   IgnoreSelectedPower true
  </Plugin>
 
 The following options are valid inside the B<PluginE<nbsp>mic> block:
@@ -2439,7 +2716,7 @@ The following options are valid inside the B<PluginE<nbsp>mic> block:
 
 =item B<ShowCPU> B<true>|B<false>
 
-If enabled (the default) a sum of the CPU usage accross all cores is reported.
+If enabled (the default) a sum of the CPU usage across all cores is reported.
 
 =item B<ShowCPUCores> B<true>|B<false>
 
@@ -2487,7 +2764,7 @@ Fan In
 
 =item fout
 
-Fan Out 
+Fan Out
 
 =item vccp
 
@@ -2528,11 +2805,11 @@ Known power names are:
 
 =item total0
 
-Total power utilization averaged over Time Window 0 (uWatts). 
+Total power utilization averaged over Time Window 0 (uWatts).
 
 =item total1
 
-Total power utilization averaged over Time Window 0 (uWatts). 
+Total power utilization averaged over Time Window 0 (uWatts).
 
 =item inst
 
@@ -2540,34 +2817,55 @@ Instantaneous power (uWatts).
 
 =item imax
 
-Max instantaneous power (uWatts). 
+Max instantaneous power (uWatts).
 
 =item pcie
 
-PCI-E connector power (uWatts). 
+PCI-E connector power (uWatts).
 
 =item c2x3
 
-2x3 connector power (uWatts). 
+2x3 connector power (uWatts).
 
 =item c2x4
 
-2x4 connector power (uWatts). 
+2x4 connector power (uWatts).
 
 =item vccp
 
-Core rail (uVolts). 
+Core rail (uVolts).
 
 =item vddg
 
-Uncore rail (uVolts). 
+Uncore rail (uVolts).
 
 =item vddq
 
-Memory subsystem rail (uVolts). 
+Memory subsystem rail (uVolts).
+
+=back
 
 =back
 
+=head2 Plugin C<memory>
+
+The I<memory plugin> provides the following configuration options:
+
+=over 4
+
+=item B<ValuesAbsolute> B<true>|B<false>
+
+Enables or disables reporting of physical memory usage in absolute numbers,
+i.e. bytes. Defaults to B<true>.
+
+=item B<ValuesPercentage> B<false>|B<true>
+
+Enables or disables reporting of physical memory usage in percentages, e.g.
+percent of physical memory used. Defaults to B<false>.
+
+This is useful for deploying I<collectd> in a heterogeneous environment in
+which the sizes of physical memory vary.
+
 =back
 
 =head2 Plugin C<modbus>
@@ -2585,19 +2883,19 @@ B<Synopsis:>
    Type voltage
    Instance "input-1"
  </Data>
+
  <Data "voltage-input-2">
    RegisterBase 2
    RegisterType float
    Type voltage
    Instance "input-2"
  </Data>
+
  <Host "modbus.example.com">
    Address "192.168.0.42"
    Port    "502"
    Interval 60
-   
+
    <Slave 1>
      Instance "power-supply"
      Collect  "voltage-input-1"
@@ -2728,9 +3026,11 @@ Synopsis:
       Password "password"
       Port "3306"
       MasterStats true
+      ConnectTimeout 10
     </Database>
 
     <Database bar>
+      Alias "squeeze"
       Host "localhost"
       Socket "/var/run/mysql/mysqld.sock"
       SlaveStats true
@@ -2745,6 +3045,11 @@ section "mysql_real_connect()" in the B<MySQL reference manual>.
 
 =over 4
 
+=item B<Alias> I<Alias>
+
+Alias to use as sender instead of hostname when reporting. This may be useful
+when having cryptic hostnames.
+
 =item B<Host> I<Hostname>
 
 Hostname of the database server. Defaults to B<localhost>.
@@ -2783,6 +3088,11 @@ only has any effect, if B<Host> is set to B<localhost> (the default).
 Otherwise, use the B<Port> option above. See the documentation for the
 C<mysql_real_connect> function for details.
 
+=item B<InnodbStats> I<true|false>
+
+If enabled, metrics about the InnoDB storage engine are collected.
+Disabled by default.
+
 =item B<MasterStats> I<true|false>
 
 =item B<SlaveStats> I<true|false>
@@ -2796,6 +3106,10 @@ privileges. See the B<User> documentation above.
 If enabled, the plugin sends a notification if the replication slave I/O and /
 or SQL threads are not running.
 
+=item B<ConnectTimeout> I<Seconds>
+
+Sets the connect timeout for the MySQL client.
+
 =back
 
 =head2 Plugin C<netapp>
@@ -2830,7 +3144,7 @@ Required capabilities are documented below.
     User          "username"
     Password      "aef4Aebe"
     Interval      30
-    
+
     <WAFL>
       Interval 30
       GetNameCache   true
@@ -2838,12 +3152,12 @@ Required capabilities are documented below.
       GetBufferCache true
       GetInodeCache  true
     </WAFL>
-    
+
     <Disks>
       Interval 30
       GetBusy true
     </Disks>
-    
+
     <VolumePerf>
       Interval 30
       GetIO      "volume0"
@@ -2853,7 +3167,7 @@ Required capabilities are documented below.
       GetLatency "volume0"
       IgnoreSelectedLatency false
     </VolumePerf>
-    
+
     <VolumeUsage>
       Interval 30
       GetCapacity "vol0"
@@ -2863,15 +3177,15 @@ Required capabilities are documented below.
       GetSnapshot "vol3"
       IgnoreSelectedSnapshot false
     </VolumeUsage>
-    
+
     <Quota>
       Interval 60
     </Quota>
-    
+
     <Snapvault>
       Interval 30
     </Snapvault>
-    
+
     <System>
       Interval 30
       GetCPULoad     true
@@ -3432,7 +3746,7 @@ signature):
    # Export to an internal server
    # (demonstrates usage without additional options)
    Server "collectd.internal.tld"
-   
+
    # Export to an external server
    # (demonstrates usage with signature options)
    <Server "collectd.external.tld">
@@ -3821,13 +4135,36 @@ B<EXPERIMENTAL!> See notes below.
 The C<onewire> plugin uses the B<owcapi> library from the B<owfs> project
 L<http://owfs.org/> to read sensors connected via the onewire bus.
 
-Currently only temperature sensors (sensors with the family code C<10>,
-e.E<nbsp>g. DS1820, DS18S20, DS1920) can be read. If you have other sensors you
-would like to have included, please send a sort request to the mailing list.
+It can be used in two possible modes - standard or advanced.
+
+In the standard mode only temperature sensors (sensors with the family code
+C<10>, C<22> and C<28> - e.g. DS1820, DS18S20, DS1920) can be read. If you have
+other sensors you would like to have included, please send a sort request to
+the mailing list. You can select sensors to be read or to be ignored depending
+on the option B<IgnoreSelected>). When no list is provided the whole bus is
+walked and all sensors are read.
 
 Hubs (the DS2409 chips) are working, but read the note, why this plugin is
 experimental, below.
 
+In the advanced mode you can configure any sensor to be read (only numerical
+value) using full OWFS path (e.g. "/uncached/10.F10FCA000800/temperature").
+In this mode you have to list all the sensors. Neither default bus walk nor
+B<IgnoreSelected> are used here. Address and type (file) is extracted from
+the path automatically and should produce compatible structure with the "standard"
+mode (basically the path is expected as for example
+"/uncached/10.F10FCA000800/temperature" where it would extract address part
+"F10FCA000800" and the rest after the slash is considered the type - here
+"temperature").
+There are two advantages to this mode - you can access virtually any sensor
+(not just temperature), select whether to use cached or directly read values
+and it is slighlty faster. The downside is more complex configuration.
+
+The two modes are distinguished automatically by the format of the address.
+It is not possible to mix the two modes. Once a full path is detected in any
+B<Sensor> then the whole addressing (all sensors) is considered to be this way
+(and as standard addresses will fail parsing they will be ignored).
+
 =over 4
 
 =item B<Device> I<Device>
@@ -3848,14 +4185,23 @@ This directive is B<required> and does not have a default value.
 
 =item B<Sensor> I<Sensor>
 
-Selects sensors to collect or to ignore, depending on B<IgnoreSelected>, see
-below. Sensors are specified without the family byte at the beginning, to you'd
-use C<F10FCA000800>, and B<not> include the leading C<10.> family byte and
-point.
+In the standard mode selects sensors to collect or to ignore
+(depending on B<IgnoreSelected>, see below). Sensors are specified without
+the family byte at the beginning, so you have to use for example C<F10FCA000800>,
+and B<not> include the leading C<10.> family byte and point.
+When no B<Sensor> is configured the whole Onewire bus is walked and all supported
+sensors (see above) are read.
+
+In the advanced mode the B<Sensor> specifies full OWFS path - e.g.
+C</uncached/10.F10FCA000800/temperature> (or when cached values are OK
+C</10.F10FCA000800/temperature>). B<IgnoreSelected> is not used.
+
+As there can be multiple devices on the bus you can list multiple sensor (use
+multiple B<Sensor> elements).
 
 =item B<IgnoreSelected> I<true>|I<false>
 
-If no configuration if given, the B<onewire> plugin will collect data from all
+If no configuration is given, the B<onewire> plugin will collect data from all
 sensors found. This may not be practical, especially if sensors are added and
 removed regularly. Sometimes, however, it's easier/preferred to collect only
 specific sensors or all sensors I<except> a few specified ones. This option
@@ -3863,6 +4209,8 @@ enables you to do that: By setting B<IgnoreSelected> to I<true> the effect of
 B<Sensor> is inverted: All selected interfaces are ignored and all other
 interfaces are collected.
 
+Used only in the standard mode - see above.
+
 =item B<Interval> I<Seconds>
 
 Sets the interval in which all sensors should be read. If not specified, the
@@ -4539,13 +4887,6 @@ Specify the password to be used when connecting to the server.
 Specify whether to use an SSL connection when contacting the server. The
 following modes are supported:
 
-=item B<Instance> I<name>
-
-Specify the plugin instance name that should be used instead of the database
-name (which is the default, if this option has not been specified). This
-allows to query multiple databases of the same name on the same host (e.g.
-when running multiple database server versions in parallel).
-
 =over 4
 
 =item I<disable>
@@ -4566,6 +4907,13 @@ Use SSL only.
 
 =back
 
+=item B<Instance> I<name>
+
+Specify the plugin instance name that should be used instead of the database
+name (which is the default, if this option has not been specified). This
+allows to query multiple databases of the same name on the same host (e.g.
+when running multiple database server versions in parallel).
+
 =item B<KRBSrvName> I<kerberos_service_name>
 
 Specify the Kerberos service name to use when authenticating with Kerberos 5
@@ -5352,6 +5700,19 @@ This option is only available if the I<Swap plugin> can read C</proc/swaps>
 When enabled, the I<swap I/O> is reported in bytes. When disabled, the default,
 I<swap I/O> is reported in pages. This option is available under Linux only.
 
+=item B<ValuesAbsolute> B<true>|B<false>
+
+Enables or disables reporting of absolute swap metrics, i.e. number of I<bytes>
+available and used. Defaults to B<true>.
+
+=item B<ValuesPercentage> B<false>|B<true>
+
+Enables or disables reporting of relative swap metrics, i.e. I<percent>
+available and free. Defaults to B<false>.
+
+This is useful for deploying I<collectd> in a heterogeneous environment, where
+swap sizes differ and you want to specify generic thresholds or similar.
+
 =back
 
 =head2 Plugin C<syslog>
@@ -5487,6 +5848,7 @@ user using (extended) regular expressions, as described in L<regex(7)>.
   <Plugin "tail">
     <File "/var/log/exim4/mainlog">
       Instance "exim"
+      Interval 60
       <Match>
         Regex "S=([1-9][0-9]*)"
         DSType "CounterAdd"
@@ -5513,6 +5875,9 @@ This plugin instance is for all B<Match> blocks that B<follow> it, until the
 next B<Instance> option. This way you can extract several plugin instances from
 one logfile, handy when parsing syslog and the like.
 
+The B<Interval> option allows you to define the length of time between reads. If
+this is not set, the default Interval will be used.
+
 Each B<Match> block has the following options to describe how the match should
 be performed:
 
@@ -6168,6 +6533,59 @@ more than one DS.
 
 =back
 
+=head2 Plugin C<write_tsdb>
+
+The C<write_tsdb> plugin writes data to I<OpenTSDB>, a scalable open-source
+time series database. The plugin connects to a I<TSD>, a masterless, no shared
+state daemon that ingests metrics and stores them in HBase. The plugin uses
+I<TCP> over the "line based" protocol with a default port 4242. The data will
+be sent in blocks of at most 1428 bytes to minimize the number of network
+packets.
+
+Synopsis:
+
+ <Plugin write_tsdb>
+   <Node "example">
+     Host "tsd-1.my.domain"
+     Port "4242"
+     HostTags "status=production"
+   </Node>
+ </Plugin>
+
+The configuration consists of one or more E<lt>B<Node>E<nbsp>I<Name>E<gt>
+blocks. Inside the B<Node> blocks, the following options are recognized:
+
+=over 4
+
+=item B<Host> I<Address>
+
+Hostname or address to connect to. Defaults to C<localhost>.
+
+=item B<Port> I<Service>
+
+Service name or port number to connect to. Defaults to C<4242>.
+
+
+=item B<HostTags> I<String>
+
+When set, I<HostTags> is added to the end of the metric. It is intended to be
+used for name=value pairs that the TSD will tag the metric with. Dots and
+whitespace are I<not> escaped in this string.
+
+=item B<StoreRates> B<false>|B<true>
+
+If set to B<true>, convert counter values to rates. If set to B<false>
+(the default) counter values are stored as is, as an increasing
+integer number.
+
+=item B<AlwaysAppendDS> B<false>|B<true>
+
+If set the B<true>, append the name of the I<Data Source> (DS) to the "metric"
+identifier. If set to B<false> (the default), this is only done when there is
+more than one DS.
+
+=back
+
 =head2 Plugin C<write_mongodb>
 
 The I<write_mongodb plugin> will send values to I<MongoDB>, a schema-less
@@ -6269,6 +6687,33 @@ File that holds one or more SSL certificates. If you want to use HTTPS you will
 possibly need this option. What CA certificates come bundled with C<libcurl>
 and are checked by default depends on the distribution you use.
 
+=item B<CAPath> I<Directory>
+
+Directory holding one or more CA certificate files. You can use this if for
+some reason all the needed CA certificates aren't in the same file and can't be
+pointed to using the B<CACert> option. Requires C<libcurl> to be built against
+OpenSSL.
+
+=item B<ClientKey> I<File>
+
+File that holds the private key in PEM format to be used for certificate-based
+authentication.
+
+=item B<ClientCert> I<File>
+
+File that holds the SSL certificate to be used for certificate-based
+authentication.
+
+=item B<ClientKeyPass> I<Password>
+
+Password required to load the private key in B<ClientKey>.
+
+=item B<SSLVersion> B<SSLv2>|B<SSLv3>|B<TLSv1>|B<TLSv1_0>|B<TLSv1_1>|B<TLSv1_2>
+
+Define which SSL protocol version must be used. By default C<libcurl> will
+attempt to figure out the remote SSL protocol version. See
+L<curl_easy_setopt(3)> for more details.
+
 =item B<Format> B<Command>|B<JSON>
 
 Format of the output to generate. If set to B<Command>, will create output that
@@ -6285,9 +6730,114 @@ number.
 
 =back
 
+=head2 Plugin C<write_kafka>
+
+The I<write_kafka plugin> will send values to a I<Kafka> topic, a distributed
+queue.
+Synopsis:
+
+ <Plugin "write_kafka">
+   Property "metadata.broker.list" "broker1:9092,broker2:9092"
+   <Topic "collectd">
+     Format JSON
+   </Topic>
+ </Plugin>
+
+The following options are understood by the I<write_kafka plugin>:
+
+=over 4
+
+=item E<lt>B<Topic> I<Name>E<gt>
+
+The plugin's configuration consists of one or more B<Topic> blocks. Each block
+is given a unique I<Name> and specifies one kafka producer.
+Inside the B<Topic> block, the following per-topic options are
+understood:
+
+=over 4
+
+=item B<Property> I<String> I<String>
+
+Configure the named property for the current topic. Properties are
+forwarded to the kafka producer library B<librdkafka>.
+
+=item B<Key> I<String>
+
+Use the specified string as a partioning key for the topic. Kafka breaks
+topic into partitions and guarantees that for a given topology, the same
+consumer will be used for a specific key. The special (case insensitive)
+string B<Random> can be used to specify that an arbitrary partition should
+be used.
+
+=item B<Format> B<Command>|B<JSON>|B<Graphite>
+
+Selects the format in which messages are sent to the broker. If set to
+B<Command> (the default), values are sent as C<PUTVAL> commands which are
+identical to the syntax used by the I<Exec> and I<UnixSock plugins>.
+
+If set to B<JSON>, the values are encoded in the I<JavaScript Object Notation>,
+an easy and straight forward exchange format.
+
+If set to B<Graphite>, values are encoded in the I<Graphite> format, which is
+"<metric> <value> <timestamp>\n".
+
+=item B<StoreRates> B<true>|B<false>
+
+Determines whether or not C<COUNTER>, C<DERIVE> and C<ABSOLUTE> data sources
+are converted to a I<rate> (i.e. a C<GAUGE> value). If set to B<false> (the
+default), no conversion is performed. Otherwise the conversion is performed
+using the internal value cache.
+
+Please note that currently this option is only used if the B<Format> option has
+been set to B<JSON>.
+
+=item B<GraphitePrefix> (B<Format>=I<Graphite> only)
+
+A prefix can be added in the metric name when outputting in the I<Graphite> format.
+It's added before the I<Host> name.
+Metric name will be "<prefix><host><postfix><plugin><type><name>"
+
+=item B<GraphitePostfix> (B<Format>=I<Graphite> only)
+
+A postfix can be added in the metric name when outputting in the I<Graphite> format.
+It's added after the I<Host> name.
+Metric name will be "<prefix><host><postfix><plugin><type><name>"
+
+=item B<GraphiteEscapeChar> (B<Format>=I<Graphite> only)
+
+Specify a character to replace dots (.) in the host part of the metric name.
+In I<Graphite> metric name, dots are used as separators between different
+metric parts (host, plugin, type).
+Default is "_" (I<Underscore>).
+
+=item B<GraphiteSeparateInstances> B<false>|B<true>
+
+If set to B<true>, the plugin instance and type instance will be in their own
+path component, for example C<host.cpu.0.cpu.idle>. If set to B<false> (the
+default), the plugin and plugin instance (and likewise the type and type
+instance) are put into one component, for example C<host.cpu-0.cpu-idle>.
+
+=item B<StoreRates> B<true>|B<false>
+
+If set to B<true> (the default), convert counter values to rates. If set to
+B<false> counter values are stored as is, i.e. as an increasing integer number.
+
+This will be reflected in the C<ds_type> tag: If B<StoreRates> is enabled,
+converted values will have "rate" appended to the data source type, e.g.
+C<ds_type:derive:rate>.
+
+=back
+
+=item B<Property> I<String> I<String>
+
+Configure the kafka producer through properties, you almost always will
+want to set B<metadata.broker.list> to your Kafka broker list.
+
+=back
+
 =head2 Plugin C<write_riemann>
 
-The I<write_riemann plugin> will send values to I<Riemann>, a powerfull stream
+The I<write_riemann plugin> will send values to I<Riemann>, a powerful stream
 aggregation and monitoring system. The plugin sends I<Protobuf> encoded data to
 I<Riemann> using UDP packets.
 
@@ -6303,6 +6853,7 @@ Synopsis:
      TTLFactor 2.0
    </Node>
    Tag "foobar"
+   Attribute "foo" "bar"
  </Plugin>
 
 The following options are understood by the I<write_riemann plugin>:
@@ -6356,6 +6907,17 @@ interval is multiplied to set the TTL. The default value is B<2.0>. Unless you
 know exactly what you're doing, you should only increase this setting from its
 default value.
 
+=item B<Notifications> B<false>|B<true>
+
+If set to B<true>, create riemann events for notifications. This is B<true>
+by default. When processing thresholds from write_riemann, it might prove
+useful to avoid getting notification events.
+
+=item B<CheckThresholds> B<false>|B<true>
+
+If set to B<true>, attach state to events based on thresholds defined
+in the B<Threshold> plugin. Defaults to B<false>.
+
 =back
 
 =item B<Tag> I<String>
@@ -6363,6 +6925,11 @@ default value.
 Add the given string as an additional tag to the metric being sent to
 I<Riemann>.
 
+=item B<Attribute> I<String> I<String>
+
+Consider the two given strings to be the key and value of an additional
+attribute for each metric being sent out to I<Riemann>.
+
 =back
 
 =head1 THRESHOLD CONFIGURATION
@@ -7034,7 +7601,7 @@ Example:
    Max 100
    Satisfy "All"
  </Match>
+
  # Match if the value of any data source is outside the range of 0 - 100.
  <Match "value">
    Min   0
@@ -7216,7 +7783,7 @@ Example:
  <Target "replace">
    # Replace "example.net" with "example.com"
    Host "\\<example.net\\>" "example.com"
+
    # Strip "www." from hostnames
    Host "\\<www\\." ""
  </Target>
@@ -7299,6 +7866,6 @@ L<sensors(1)>
 
 =head1 AUTHOR
 
-Florian Forster E<lt>octo@verplant.orgE<gt>
+Florian Forster E<lt>octo@collectd.orgE<gt>
 
 =cut
index 7cb405c..5650b59 100644 (file)
@@ -2,21 +2,26 @@
  * collectd - src/collectd.h
  * Copyright (C) 2005,2006  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #ifndef COLLECTD_H
@@ -262,6 +267,10 @@ typedef int _Bool;
 # define COLLECTD_DEFAULT_INTERVAL 10.0
 #endif
 
+ #ifndef COLLECTD_USERAGENT
+ # define COLLECTD_USERAGENT PACKAGE_NAME"/"PACKAGE_VERSION
+ #endif
+
 /* Remove GNU specific __attribute__ settings when using another compiler */
 #if !__GNUC__
 # define __attribute__(x) /**/
@@ -292,6 +301,7 @@ typedef uint64_t cdtime_t;
 
 extern char     hostname_g[];
 extern cdtime_t interval_g;
+extern int      pidfile_from_cli;
 extern int      timeout_g;
 
 #endif /* COLLECTD_H */
index 2f7b9f7..8fccdb3 100644 (file)
@@ -138,6 +138,6 @@ L<http://collectd.org/>
 
 =head1 AUTHOR
 
-Florian Forster E<lt>octo@verplant.orgE<gt>
+Florian Forster E<lt>octo@collectd.orgE<gt>
 
 =cut
index 0b8d0c1..2329285 100644 (file)
@@ -99,7 +99,7 @@ static void exit_usage (const char *name, int status) {
       "No error is returned if the specified identifier does not exist.\n"
 
       "\n"PACKAGE" "VERSION", http://collectd.org/\n"
-      "by Florian octo Forster <octo@verplant.org>\n"
+      "by Florian octo Forster <octo@collectd.org>\n"
       "for contributions see `AUTHORS'\n"
       , name);
   exit (status);
index 52b8ef2..d921330 100644 (file)
@@ -152,7 +152,7 @@ L<types.db(5)>
 
 =head1 AUTHOR
 
-collectd has been written by Florian Forster E<lt>octo at verplant.orgE<gt>
+collectd has been written by Florian Forster E<lt>octo at collectd.orgE<gt>
 and many contributors (see `AUTHORS').
 
 collectdctl has been written by
index 078b2eb..c3f9525 100644 (file)
@@ -1,21 +1,26 @@
 /**
  * collectd - src/collectdmon.c
- * Copyright (C) 2007  Sebastian Harl
+ * Copyright (C) 2007       Sebastian Harl
  *
- * 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.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
+ * Authors:
  *   Sebastian Harl <sh at tokkee.org>
  **/
 
@@ -76,7 +81,7 @@ static void exit_usage (char *name)
                        "\nFor <collectd options> see collectd.conf(5).\n"
 
                        "\n"PACKAGE" "VERSION", http://collectd.org/\n"
-                       "by Florian octo Forster <octo@verplant.org>\n"
+                       "by Florian octo Forster <octo@collectd.org>\n"
                        "for contributions see `AUTHORS'\n", name);
        exit (0);
 } /* exit_usage */
index 3151e11..8fa62f3 100644 (file)
@@ -67,7 +67,7 @@ L<http://collectd.org/>
 
 =head1 AUTHOR
 
-collectd has been written by Florian Forster E<lt>octo at verplant.orgE<gt>
+collectd has been written by Florian Forster E<lt>octo at collectd.orgE<gt>
 and many contributors (see `AUTHORS').
 
 collectdmon has been written by Sebastian Harl E<lt>sh@tokkee.orgE<gt>.
index dc77e02..8691d3e 100644 (file)
@@ -1,19 +1,24 @@
 /**
  * collectd - src/common.c
- * Copyright (C) 2005-2010  Florian octo Forster
+ * Copyright (C) 2005-2014  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <octo at collectd.org>
@@ -377,8 +382,10 @@ int strunescape (char *buf, size_t buf_len)
                if (buf[i] != '\\')
                        continue;
 
-               if ((i >= buf_len) || (buf[i + 1] == '\0')) {
+               if (((i + 1) >= buf_len) || (buf[i + 1] == 0)) {
                        ERROR ("string unescape: backslash found at end of string.");
+                       /* Ensure null-byte at the end of the buffer. */
+                       buf[i] = 0;
                        return (-1);
                }
 
@@ -397,7 +404,10 @@ int strunescape (char *buf, size_t buf_len)
                                break;
                }
 
+               /* Move everything after the position one position to the left.
+                * Add a null-byte as last character in the buffer. */
                memmove (buf + i + 1, buf + i + 2, buf_len - i - 2);
+               buf[buf_len - 1] = 0;
        }
        return (0);
 } /* int strunescape */
@@ -418,34 +428,36 @@ size_t strstripnewline (char *buffer)
        return (buffer_len);
 } /* size_t strstripnewline */
 
-int escape_slashes (char *buf, int buf_len)
+int escape_slashes (char *buffer, size_t buffer_size)
 {
        int i;
+       size_t buffer_len;
 
-       if (strcmp (buf, "/") == 0)
-       {
-               if (buf_len < 5)
-                       return (-1);
+       buffer_len = strlen (buffer);
 
-               strncpy (buf, "root", buf_len);
+       if (buffer_len <= 1)
+       {
+               if (strcmp ("/", buffer) == 0)
+               {
+                       if (buffer_size < 5)
+                               return (-1);
+                       sstrncpy (buffer, "root", buffer_size);
+               }
                return (0);
        }
 
-       if (buf_len <= 1)
-               return (0);
-
        /* Move one to the left */
-       if (buf[0] == '/')
-               memmove (buf, buf + 1, buf_len - 1);
+       if (buffer[0] == '/')
+       {
+               memmove (buffer, buffer + 1, buffer_len);
+               buffer_len--;
+       }
 
-       for (i = 0; i < buf_len - 1; i++)
+       for (i = 0; i < buffer_len - 1; i++)
        {
-               if (buf[i] == '\0')
-                       break;
-               else if (buf[i] == '/')
-                       buf[i] = '_';
+               if (buffer[i] == '/')
+                       buffer[i] = '_';
        }
-       buf[i] = '\0';
 
        return (0);
 } /* int escape_slashes */
@@ -648,7 +660,7 @@ int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name)
        char ident[128];
 
        *ksp_ptr = NULL;
-       
+
        if (kc == NULL)
                return (-1);
 
@@ -1234,7 +1246,7 @@ int walk_directory (const char *dir, dirwalk_callback_f callback,
        while ((ent = readdir (dh)) != NULL)
        {
                int status;
-               
+
                if (include_hidden)
                {
                        if ((strcmp (".", ent->d_name) == 0)
@@ -1397,6 +1409,69 @@ int rate_to_value (value_t *ret_value, gauge_t rate, /* {{{ */
        return (0);
 } /* }}} value_t rate_to_value */
 
+int value_to_rate (value_t *ret_rate, derive_t value, /* {{{ */
+               value_to_rate_state_t *state,
+               int ds_type, cdtime_t t)
+{
+       double interval;
+
+       /* Another invalid state: The time is not increasing. */
+       if (t <= state->last_time)
+       {
+               memset (state, 0, sizeof (*state));
+               return (EINVAL);
+       }
+
+       interval = CDTIME_T_TO_DOUBLE(t - state->last_time);
+
+       /* Previous value is invalid. */
+       if (state->last_time == 0) /* {{{ */
+       {
+               if (ds_type == DS_TYPE_DERIVE)
+               {
+                       state->last_value.derive = value;
+               }
+               else if (ds_type == DS_TYPE_COUNTER)
+               {
+                       state->last_value.counter = (counter_t) value;
+               }
+               else if (ds_type == DS_TYPE_ABSOLUTE)
+               {
+                       state->last_value.absolute = (absolute_t) value;
+               }
+               else
+               {
+                       assert (23 == 42);
+               }
+
+               state->last_time = t;
+               return (EAGAIN);
+       } /* }}} */
+
+       if (ds_type == DS_TYPE_DERIVE)
+       {
+               ret_rate->gauge = (value - state->last_value.derive) / interval;
+               state->last_value.derive = value;
+       }
+       else if (ds_type == DS_TYPE_COUNTER)
+       {
+               ret_rate->gauge = (((counter_t)value) - state->last_value.counter) / interval;
+               state->last_value.counter = (counter_t) value;
+       }
+       else if (ds_type == DS_TYPE_ABSOLUTE)
+       {
+               ret_rate->gauge = (((absolute_t)value) - state->last_value.absolute) / interval;
+               state->last_value.absolute = (absolute_t) value;
+       }
+       else
+       {
+               assert (23 == 42);
+       }
+
+        state->last_time = t;
+       return (0);
+} /* }}} value_t rate_to_value */
+
 int service_name_to_port_number (const char *service_name)
 {
        struct addrinfo *ai_list;
index 317be8d..b2e4c67 100644 (file)
@@ -1,19 +1,24 @@
 /**
  * collectd - src/common.h
- * Copyright (C) 2005-2010  Florian octo Forster
+ * Copyright (C) 2005-2014  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <octo at collectd.org>
@@ -55,6 +60,13 @@ struct rate_to_value_state_s
 };
 typedef struct rate_to_value_state_s rate_to_value_state_t;
 
+struct value_to_rate_state_s
+{
+  value_t last_value;
+  cdtime_t last_time;
+};
+typedef struct value_to_rate_state_s value_to_rate_state_t;
+
 char *sstrncpy (char *dest, const char *src, size_t n);
 
 __attribute__ ((format(printf,3,4)))
@@ -158,19 +170,21 @@ int strjoin (char *dst, size_t dst_len, char **fields, size_t fields_num, const
  *   escape_slashes
  *
  * DESCRIPTION
- *   Removes slashes from the string `buf' and substitutes them with something
- *   appropriate. This function should be used whenever a path is to be used as
- *   (part of) an instance.
+ *   Removes slashes ("/") from "buffer". If buffer contains a single slash,
+ *   the result will be "root". Leading slashes are removed. All other slashes
+ *   are replaced with underscores ("_").
+ *   This function is used by plugin_dispatch_values() to escape all parts of
+ *   the identifier.
  *
  * PARAMETERS
- *   `buf'         String to be escaped.
- *   `buf_len'     Length of the buffer. No more then this many bytes will be
- *   written to `buf', including the trailing null-byte.
+ *   `buffer'         String to be escaped.
+ *   `buffer_size'    Size of the buffer. No more then this many bytes will be
+ *                    written to `buffer', including the trailing null-byte.
  *
  * RETURN VALUE
  *   Returns zero upon success and a value smaller than zero upon failure.
  */
-int escape_slashes (char *buf, int buf_len);
+int escape_slashes (char *buffer, size_t buffer_size);
 
 /*
  * NAME
@@ -322,6 +336,9 @@ counter_t counter_diff (counter_t old_value, counter_t new_value);
 int rate_to_value (value_t *ret_value, gauge_t rate,
                rate_to_value_state_t *state, int ds_type, cdtime_t t);
 
+int value_to_rate (value_t *ret_rate, derive_t value,
+               value_to_rate_state_t *state, int ds_type, cdtime_t t);
+
 /* Converts a service name (a string) to a port number
  * (in the range [1-65535]). Returns less than zero on error. */
 int service_name_to_port_number (const char *service_name);
index ec39b76..d2a307d 100644 (file)
@@ -2,19 +2,23 @@
  * collectd - src/configfile.c
  * 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
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <octo at collectd.org>
@@ -898,6 +902,13 @@ int global_option_set (const char *option, const char *value)
        if (i >= cf_global_options_num)
                return (-1);
 
+       if (strcasecmp (option, "PIDFile") == 0 && pidfile_from_cli == 1)
+       {
+               DEBUG ("Configfile: Ignoring `PIDFILE' option because "
+                       "command-line option `-P' take precedence.");
+               return (0);
+       }
+
        sfree (cf_global_options[i].value);
 
        if (value != NULL)
index c91fcd5..92c09de 100644 (file)
@@ -1,27 +1,32 @@
-#ifndef CONFIGFILE_H
-#define CONFIGFILE_H
 /**
  * collectd - src/configfile.h
  * 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
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <octo at collectd.org>
  **/
 
+#ifndef CONFIGFILE_H
+#define CONFIGFILE_H
+
 #include "collectd.h"
 #include "utils_time.h"
 #include "liboconfig/oconfig.h"
index 33236c4..49a3355 100644 (file)
@@ -8,7 +8,7 @@
  *
  * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
  * General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License along
@@ -18,7 +18,7 @@
  * Authors:
  *   Tomasz Pala <gotar at pld-linux.org>
  * based on entropy.c by:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
 #endif
 
 #define CONNTRACK_FILE "/proc/sys/net/netfilter/nf_conntrack_count"
+#define CONNTRACK_MAX_FILE "/proc/sys/net/netfilter/nf_conntrack_max"
+#define CONNTRACK_FILE_OLD "/proc/sys/net/ipv4/netfilter/ip_conntrack_count"
+#define CONNTRACK_MAX_FILE_OLD "/proc/sys/net/ipv4/netfilter/ip_conntrack_max"
 
-static void conntrack_submit (value_t conntrack)
+static const char *config_keys[] =
+{
+       "OldFiles"
+};
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+/*
+    Each table/chain combo that will be queried goes into this list
+*/
+
+static int old_files = 0;
+
+static int conntrack_config(const char *key, const char *value)
+{
+    if (strcmp(key, "OldFiles") == 0)
+        old_files = 1;
+
+    return 0;
+}
+
+static void conntrack_submit (const char *type, const char *type_instance,
+                             value_t conntrack)
 {
        value_list_t vl = VALUE_LIST_INIT;
 
@@ -39,19 +62,22 @@ static void conntrack_submit (value_t conntrack)
        vl.values_len = 1;
        sstrncpy (vl.host, hostname_g, sizeof (vl.host));
        sstrncpy (vl.plugin, "conntrack", sizeof (vl.plugin));
-       sstrncpy (vl.type, "conntrack", sizeof (vl.type));
+       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);
 } /* static void conntrack_submit */
 
 static int conntrack_read (void)
 {
-       value_t conntrack;
+       value_t conntrack, conntrack_max, conntrack_pct;
        FILE *fh;
        char buffer[64];
        size_t buffer_len;
 
-       fh = fopen (CONNTRACK_FILE, "r");
+       fh = fopen (old_files?CONNTRACK_FILE_OLD:CONNTRACK_FILE, "r");
        if (fh == NULL)
                return (-1);
 
@@ -74,12 +100,42 @@ static int conntrack_read (void)
        if (parse_value (buffer, &conntrack, DS_TYPE_GAUGE) != 0)
                return (-1);
 
-       conntrack_submit (conntrack);
+       conntrack_submit ("conntrack", NULL, conntrack);
+
+       fh = fopen (old_files?CONNTRACK_MAX_FILE_OLD:CONNTRACK_MAX_FILE, "r");
+       if (fh == NULL)
+               return (-1);
+
+       memset (buffer, 0, sizeof (buffer));
+       if (fgets (buffer, sizeof (buffer), fh) == NULL)
+       {
+               fclose (fh);
+               return (-1);
+       }
+       fclose (fh);
+
+       /* strip trailing newline. */
+       buffer_len = strlen (buffer);
+       while ((buffer_len > 0) && isspace ((int) buffer[buffer_len - 1]))
+       {
+               buffer[buffer_len - 1] = 0;
+               buffer_len--;
+       }
+
+       if (parse_value (buffer, &conntrack_max, DS_TYPE_GAUGE) != 0)
+               return (-1);
+
+       conntrack_submit ("conntrack", "max", conntrack_max);
+       conntrack_pct.gauge = (conntrack.gauge / conntrack_max.gauge) * 100;
+       conntrack_submit ("percent", "used", conntrack_pct);
+
 
        return (0);
 } /* static int conntrack_read */
 
 void module_register (void)
 {
+    plugin_register_config ("conntrack", conntrack_config,
+                            config_keys, config_keys_num);
        plugin_register_read ("conntrack", conntrack_read);
 } /* void module_register */
index 2247d5f..1ab1e6e 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -1,9 +1,9 @@
 /**
  * collectd - src/cpu.c
  * Copyright (C) 2005-2010  Florian octo Forster
- * Copyright (C) 2008       Oleg King
- * Copyright (C) 2009       Simon Kuhnle
- * Copyright (C) 2009       Manuel Sanmartin
+ * Copyright (C) 2008      Oleg King
+ * Copyright (C) 2009      Simon Kuhnle
+ * Copyright (C) 2009      Manuel Sanmartin
  *
  * 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
@@ -11,7 +11,7 @@
  *
  * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
  * General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License along
@@ -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>
  *   Oleg King <king2 at kaluga.ru>
  *   Simon Kuhnle <simon at blarzwurst.de>
  *   Manuel Sanmartin
 # define CAN_USE_SYSCTL 0
 #endif
 
+#define CPU_SUBMIT_USER 0
+#define CPU_SUBMIT_SYSTEM 1
+#define CPU_SUBMIT_WAIT 2
+#define CPU_SUBMIT_NICE 3
+#define CPU_SUBMIT_SWAP 4
+#define CPU_SUBMIT_INTERRUPT 5
+#define CPU_SUBMIT_SOFTIRQ 6
+#define CPU_SUBMIT_STEAL 7
+#define CPU_SUBMIT_IDLE 8
+#define CPU_SUBMIT_ACTIVE 9
+#define CPU_SUBMIT_MAX 10
+
 #if HAVE_STATGRAB_H
 # include <statgrab.h>
 #endif
 # error "No applicable input method."
 #endif
 
+static const char *cpu_state_names[] = {
+       "user",
+       "system",
+       "wait",
+       "nice",
+       "swap",
+       "interrupt",
+       "softirq",
+       "steal",
+       "idle",
+       "active"
+};
+
 #ifdef PROCESSOR_CPU_LOAD_INFO
 static mach_port_t port_host;
 static processor_port_array_t cpu_list;
@@ -107,8 +132,8 @@ static mach_msg_type_number_t cpu_list_len;
 
 #if PROCESSOR_TEMPERATURE
 static int cpu_temp_retry_counter = 0;
-static int cpu_temp_retry_step    = 1;
-static int cpu_temp_retry_max     = 1;
+static int cpu_temp_retry_step   = 1;
+static int cpu_temp_retry_max    = 1;
 #endif /* PROCESSOR_TEMPERATURE */
 /* #endif PROCESSOR_CPU_LOAD_INFO */
 
@@ -145,6 +170,83 @@ static int numcpu;
 static int pnumcpu;
 #endif /* HAVE_PERFSTAT */
 
+static value_to_rate_state_t *values = NULL;
+static gauge_t agg_values[CPU_SUBMIT_MAX] = {
+       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+
+};
+static int cpu_cells = 0;
+static int cpu_count = 0;
+
+
+static _Bool report_by_cpu = 1;
+static _Bool report_percent = 0;
+static _Bool report_active = 0;
+
+static const char *config_keys[] =
+{
+       "ReportByCpu",
+       "ReportActive",
+       "ValuesPercentage"
+};
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+
+
+static int cpu_config (const char *key, const char *value)
+{
+       if (strcasecmp (key, "ReportByCpu") == 0) {
+               report_by_cpu = IS_TRUE (value) ? 1 : 0;
+       }
+       if (strcasecmp (key, "ValuesPercentage") == 0) {
+               report_percent = IS_TRUE (value) ? 1 : 0;
+       }
+       if (strcasecmp (key, "ReportActive") == 0)
+               report_active = IS_TRUE (value) ? 1 : 0;
+       return (-1);
+}
+
+static int cpu_states_grow (void)
+{
+  void *tmp;
+  int size;
+  int i;
+
+  size = cpu_count * CPU_SUBMIT_MAX; /* always alloc for all states */
+
+  if (size <= 0)
+         return 0;
+
+  if (cpu_cells >= size)
+         return 0;
+
+  if (values == NULL) {
+         values = malloc(size * sizeof(*values));
+         if (values == NULL)
+                 return -1;
+         for (i = 0; i < size; i++)
+                 memset(&values[i], 0, sizeof(*values));
+         cpu_cells = size;
+         return 0;
+  }
+
+  tmp = realloc(values, size * sizeof(*values));
+
+  if (tmp == NULL) {
+         ERROR ("cpu plugin: could not reserve enough space to hold states");
+         values = NULL;
+         return -1;
+  }
+
+  values = tmp;
+
+  for (i = cpu_cells ; i < size; i++)
+         memset(&values[i], 0, sizeof(*values));
+
+  cpu_cells = size;
+  return 0;
+} /* cpu_states_grow */
+
+
 static int init (void)
 {
 #if PROCESSOR_CPU_LOAD_INFO || PROCESSOR_TEMPERATURE
@@ -241,39 +343,183 @@ static int init (void)
        return (0);
 } /* int init */
 
-static void submit (int cpu_num, const char *type_instance, derive_t value)
+static void submit_value (int cpu_num, int cpu_state, const char *type, value_t value)
 {
        value_t values[1];
        value_list_t vl = VALUE_LIST_INIT;
 
-       values[0].derive = value;
+       memcpy(&values[0], &value, sizeof(value));
 
        vl.values = values;
        vl.values_len = 1;
+
        sstrncpy (vl.host, hostname_g, sizeof (vl.host));
        sstrncpy (vl.plugin, "cpu", sizeof (vl.plugin));
-       ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
-                       "%i", cpu_num);
-       sstrncpy (vl.type, "cpu", sizeof (vl.type));
-       sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+       sstrncpy (vl.type, type, sizeof (vl.type));
+       sstrncpy (vl.type_instance, cpu_state_names[cpu_state],
+                 sizeof (vl.type_instance));
 
+       if (cpu_num >= 0) {
+               ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
+                          "%i", cpu_num);
+       }
        plugin_dispatch_values (&vl);
 }
 
+static void submit_percent(int cpu_num, int cpu_state, gauge_t percent)
+{
+       value_t value;
+
+       value.gauge = percent;
+       submit_value (cpu_num, cpu_state, "percent", value);
+}
+
+static void submit_derive(int cpu_num, int cpu_state, derive_t derive)
+{
+       value_t value;
+
+       value.derive = derive;
+       submit_value (cpu_num, cpu_state, "cpu", value);
+}
+
+static void submit_flush (void)
+{
+       int i = 0;
+       int cpu_submit_max = CPU_SUBMIT_MAX;
+
+       if (report_by_cpu) {
+               cpu_count = 0;
+               return;
+       }
+
+       if (report_active)
+               cpu_submit_max = CPU_SUBMIT_MAX;
+       else
+               cpu_submit_max = CPU_SUBMIT_ACTIVE;
+       for (i = 0; i < cpu_submit_max; i++) {
+               if (agg_values[i] == -1)
+                       continue;
+
+               if (report_percent)
+                       submit_percent(-1, i, agg_values[i] / cpu_count);
+               else
+                       submit_derive(-1, i, agg_values[i]);
+               agg_values[i] = -1;
+       }
+       cpu_count = 0;
+}
+
+static void submit (int cpu_num, derive_t *derives)
+{
+
+       int i = 0;
+       int cpu_submit_max = CPU_SUBMIT_MAX;
+
+       if (report_active)
+               cpu_submit_max = CPU_SUBMIT_MAX;
+       else
+               cpu_submit_max = CPU_SUBMIT_ACTIVE;
+
+       if (!report_percent && report_by_cpu) {
+               derive_t cpu_active = 0;
+               for (i = 0; i < CPU_SUBMIT_ACTIVE; i++)
+               {
+                       if (derives[i] == -1)
+                               continue;
+
+                       if (i != CPU_SUBMIT_IDLE)
+                               cpu_active += derives[i];
+
+                       submit_derive(cpu_num, i, derives[i]);
+               }
+               if (report_active)
+                       submit_derive(cpu_num, CPU_SUBMIT_ACTIVE, cpu_active);
+       }
+       else {
+               cdtime_t cdt;
+               gauge_t value;
+               gauge_t cpu_total = 0;
+               gauge_t cpu_active = 0;
+               gauge_t local_rates[CPU_SUBMIT_MAX];
+
+               cpu_count++;
+               if (cpu_states_grow())
+                       return;
+
+               memset(local_rates, 0, sizeof(local_rates));
+
+               cdt = cdtime();
+               for (i = 0; i < CPU_SUBMIT_ACTIVE; i++) {
+                       if (report_percent) {
+                               value_t rate;
+                               int index;
+
+                               if (derives[i] == -1)
+                                       continue;
+
+                               index = (cpu_num * CPU_SUBMIT_MAX) + i;
+                               if (value_to_rate(&rate, derives[i], &values[index],
+                                                       DS_TYPE_DERIVE, cdt) != 0) {
+                                       local_rates[i] = -1;
+                                       continue;
+                               }
+
+                               local_rates[i] = rate.gauge;
+                               cpu_total += rate.gauge;
+                               if (i != CPU_SUBMIT_IDLE)
+                                       cpu_active += rate.gauge;
+                       }
+                       else {
+                               cpu_total += derives[i];
+                               if (i != CPU_SUBMIT_IDLE)
+                                       cpu_active += derives[i];
+                       }
+               }
+               if (cpu_total == 0.0)
+                       return;
+
+               if (report_active)
+                       local_rates[CPU_SUBMIT_ACTIVE] = cpu_active;
+
+               for (i = 0; i < cpu_submit_max; i++) {
+                       if (local_rates[i] == -1)
+                               continue;
+
+                       if (report_percent)
+                               value = (local_rates[i] / cpu_total) * 100;
+                       else
+                               value = derives[i];
+                       if (report_by_cpu) {
+                               if (report_percent) {
+                                       submit_percent (cpu_num, i, value);
+                               } else {
+                                       submit_derive(cpu_num, i, value);
+                               }
+                       }
+                       else {
+                               if (agg_values[i] == -1)
+                                       agg_values[i] = value;
+                               else
+                                       agg_values[i] += value;
+                       }
+               }
+       }
+}
+
 static int cpu_read (void)
 {
 #if PROCESSOR_CPU_LOAD_INFO || PROCESSOR_TEMPERATURE
        int cpu;
 
        kern_return_t status;
-       
+
 #if PROCESSOR_CPU_LOAD_INFO
        processor_cpu_load_info_data_t cpu_info;
-       mach_msg_type_number_t         cpu_info_len;
+       mach_msg_type_number_t         cpu_info_len;
 #endif
 #if PROCESSOR_TEMPERATURE
-       processor_info_data_t          cpu_temp;
-       mach_msg_type_number_t         cpu_temp_len;
+       processor_info_data_t          cpu_temp;
+       mach_msg_type_number_t         cpu_temp_len;
 #endif
 
        host_t cpu_host;
@@ -281,6 +527,10 @@ static int cpu_read (void)
        for (cpu = 0; cpu < cpu_list_len; cpu++)
        {
 #if PROCESSOR_CPU_LOAD_INFO
+               derive_t derives[CPU_SUBMIT_MAX] = {
+                       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+               };
+               memset(derives, -1, sizeof(derives));
                cpu_host = 0;
                cpu_info_len = PROCESSOR_BASIC_INFO_COUNT;
 
@@ -298,10 +548,12 @@ static int cpu_read (void)
                        continue;
                }
 
-               submit (cpu, "user", (derive_t) cpu_info.cpu_ticks[CPU_STATE_USER]);
-               submit (cpu, "nice", (derive_t) cpu_info.cpu_ticks[CPU_STATE_NICE]);
-               submit (cpu, "system", (derive_t) cpu_info.cpu_ticks[CPU_STATE_SYSTEM]);
-               submit (cpu, "idle", (derive_t) cpu_info.cpu_ticks[CPU_STATE_IDLE]);
+               derives[CPU_SUBMIT_USER] = (derive_t) cpu_info.cpu_ticks[CPU_STATE_USER];
+               derives[CPU_SUBMIT_NICE] = (derive_t) cpu_info.cpu_ticks[CPU_STATE_NICE];
+               derives[CPU_SUBMIT_SYSTEM] = (derive_t) cpu_info.cpu_ticks[CPU_STATE_SYSTEM];
+               derives[CPU_SUBMIT_IDLE] = (derive_t) cpu_info.cpu_ticks[CPU_STATE_IDLE];
+               submit (cpu, derives);
+
 #endif /* PROCESSOR_CPU_LOAD_INFO */
 #if PROCESSOR_TEMPERATURE
                /*
@@ -338,7 +590,7 @@ static int cpu_read (void)
                if (cpu_temp_len != 1)
                {
                        DEBUG ("processor_info (PROCESSOR_TEMPERATURE) returned %i elements..?",
-                                       (int) cpu_temp_len);
+                                       (int) cpu_temp_len);
                        continue;
                }
 
@@ -346,12 +598,11 @@ static int cpu_read (void)
                cpu_temp_retry_step    = 1;
 #endif /* PROCESSOR_TEMPERATURE */
        }
+       submit_flush ();
 /* #endif PROCESSOR_CPU_LOAD_INFO */
 
 #elif defined(KERNEL_LINUX)
        int cpu;
-       derive_t user, nice, syst, idle;
-       derive_t wait, intr, sitr; /* sitr == soft interrupt */
        FILE *fh;
        char buf[1024];
 
@@ -368,6 +619,10 @@ static int cpu_read (void)
 
        while (fgets (buf, 1024, fh) != NULL)
        {
+               derive_t derives[CPU_SUBMIT_MAX] = {
+                       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+               };
+
                if (strncmp (buf, "cpu", 3))
                        continue;
                if ((buf[3] < '0') || (buf[3] > '9'))
@@ -378,37 +633,29 @@ static int cpu_read (void)
                        continue;
 
                cpu = atoi (fields[0] + 3);
-               user = atoll (fields[1]);
-               nice = atoll (fields[2]);
-               syst = atoll (fields[3]);
-               idle = atoll (fields[4]);
-
-               submit (cpu, "user", user);
-               submit (cpu, "nice", nice);
-               submit (cpu, "system", syst);
-               submit (cpu, "idle", idle);
+               derives[CPU_SUBMIT_USER] = atoll(fields[1]);
+               derives[CPU_SUBMIT_NICE] = atoll(fields[2]);
+               derives[CPU_SUBMIT_SYSTEM] = atoll(fields[3]);
+               derives[CPU_SUBMIT_IDLE] = atoll(fields[4]);
 
                if (numfields >= 8)
                {
-                       wait = atoll (fields[5]);
-                       intr = atoll (fields[6]);
-                       sitr = atoll (fields[7]);
-
-                       submit (cpu, "wait", wait);
-                       submit (cpu, "interrupt", intr);
-                       submit (cpu, "softirq", sitr);
+                       derives[CPU_SUBMIT_WAIT] = atoll(fields[5]);
+                       derives[CPU_SUBMIT_INTERRUPT] = atoll(fields[6]);
+                       derives[CPU_SUBMIT_SOFTIRQ] = atoll(fields[6]);
 
                        if (numfields >= 9)
-                               submit (cpu, "steal", atoll (fields[8]));
+                               derives[CPU_SUBMIT_STEAL] = atoll(fields[8]);
                }
+               submit(cpu, derives);
        }
+       submit_flush();
 
        fclose (fh);
 /* #endif defined(KERNEL_LINUX) */
 
 #elif defined(HAVE_LIBKSTAT)
        int cpu;
-       derive_t user, syst, idle, wait;
        static cpu_stat_t cs;
 
        if (kc == NULL)
@@ -416,19 +663,21 @@ static int cpu_read (void)
 
        for (cpu = 0; cpu < numcpu; cpu++)
        {
+               derive_t derives[CPU_SUBMIT_MAX] = {
+                       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+               };
+
                if (kstat_read (kc, ksp[cpu], &cs) == -1)
                        continue; /* error message? */
 
-               idle = (derive_t) cs.cpu_sysinfo.cpu[CPU_IDLE];
-               user = (derive_t) cs.cpu_sysinfo.cpu[CPU_USER];
-               syst = (derive_t) cs.cpu_sysinfo.cpu[CPU_KERNEL];
-               wait = (derive_t) cs.cpu_sysinfo.cpu[CPU_WAIT];
-
-               submit (ksp[cpu]->ks_instance, "user", user);
-               submit (ksp[cpu]->ks_instance, "system", syst);
-               submit (ksp[cpu]->ks_instance, "idle", idle);
-               submit (ksp[cpu]->ks_instance, "wait", wait);
+               memset(derives, -1, sizeof(derives));
+               derives[CPU_SUBMIT_IDLE] = cs.cpu_sysinfo.cpu[CPU_IDLE];
+               derives[CPU_SUBMIT_USER] = cs.cpu_sysinfo.cpu[CPU_USER];
+               derives[CPU_SUBMIT_SYSTEM] = cs.cpu_sysinfo.cpu[CPU_KERNEL];
+               derives[CPU_SUBMIT_WAIT] = cs.cpu_sysinfo.cpu[CPU_WAIT];
+               submit (ksp[cpu]->ks_instance, derives);
        }
+       submit_flush ();
 /* #endif defined(HAVE_LIBKSTAT) */
 
 #elif CAN_USE_SYSCTL
@@ -487,12 +736,18 @@ static int cpu_read (void)
        }
 
        for (i = 0; i < numcpu; i++) {
-               submit (i, "user",      cpuinfo[i][CP_USER]);
-               submit (i, "nice",      cpuinfo[i][CP_NICE]);
-               submit (i, "system",    cpuinfo[i][CP_SYS]);
-               submit (i, "idle",      cpuinfo[i][CP_IDLE]);
-               submit (i, "interrupt", cpuinfo[i][CP_INTR]);
+               derive_t derives[CPU_SUBMIT_MAX] = {
+                       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+               };
+
+               derives[CPU_SUBMIT_USER] = cpuinfo[i][CP_USER];
+               derives[CPU_SUBMIT_NICE] = cpuinfo[i][CP_NICE];
+               derives[CPU_SUBMIT_SYSTEM] = cpuinfo[i][CP_SYS];
+               derives[CPU_SUBMIT_IDLE] = cpuinfo[i][CP_IDLE];
+               derives[CPU_SUBMIT_INTERRUPT] = cpuinfo[i][CP_INTR];
+               submit(i, derives);
        }
+       submit_flush();
 /* #endif CAN_USE_SYSCTL */
 #elif defined(HAVE_SYSCTLBYNAME) && defined(HAVE_SYSCTL_KERN_CP_TIMES)
        long cpuinfo[maxcpu][CPUSTATES];
@@ -511,16 +766,26 @@ static int cpu_read (void)
        }
 
        for (i = 0; i < numcpu; i++) {
-               submit (i, "user", cpuinfo[i][CP_USER]);
-               submit (i, "nice", cpuinfo[i][CP_NICE]);
-               submit (i, "system", cpuinfo[i][CP_SYS]);
-               submit (i, "idle", cpuinfo[i][CP_IDLE]);
-               submit (i, "interrupt", cpuinfo[i][CP_INTR]);
+               derive_t derives[CPU_SUBMIT_MAX] = {
+                       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+               };
+
+               derives[CPU_SUBMIT_USER] = cpuinfo[i][CP_USER];
+               derives[CPU_SUBMIT_NICE] = cpuinfo[i][CP_NICE];
+               derives[CPU_SUBMIT_SYSTEM] = cpuinfo[i][CP_SYS];
+               derives[CPU_SUBMIT_IDLE] = cpuinfo[i][CP_IDLE];
+               derives[CPU_SUBMIT_INTERRUPT] = cpuinfo[i][CP_INTR];
+               submit(i, derives);
        }
+       submit_flush();
+
 /* #endif HAVE_SYSCTL_KERN_CP_TIMES */
 #elif defined(HAVE_SYSCTLBYNAME)
        long cpuinfo[CPUSTATES];
        size_t cpuinfo_size;
+       derive_t derives[CPU_SUBMIT_MAX] = {
+               -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+       };
 
        cpuinfo_size = sizeof (cpuinfo);
 
@@ -532,15 +797,21 @@ static int cpu_read (void)
                return (-1);
        }
 
-       submit (0, "user", cpuinfo[CP_USER]);
-       submit (0, "nice", cpuinfo[CP_NICE]);
-       submit (0, "system", cpuinfo[CP_SYS]);
-       submit (0, "idle", cpuinfo[CP_IDLE]);
-       submit (0, "interrupt", cpuinfo[CP_INTR]);
+       derives[CPU_SUBMIT_USER] = cpuinfo[CP_USER];
+       derives[CPU_SUBMIT_SYSTEM] = cpuinfo[CP_SYS];
+       derives[CPU_SUBMIT_NICE] = cpuinfo[CP_NICE];
+       derives[CPU_SUBMIT_IDLE] = cpuinfo[CP_IDLE];
+       derives[CPU_SUBMIT_INTERRUPT] = cpuinfo[CP_INTR];
+       submit(0, derives);
+       submit_flush();
+
 /* #endif HAVE_SYSCTLBYNAME */
 
 #elif defined(HAVE_LIBSTATGRAB)
        sg_cpu_stats *cs;
+       derive_t derives[CPU_SUBMIT_MAX] = {
+               -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+       };
        cs = sg_get_cpu_stats ();
 
        if (cs == NULL)
@@ -549,12 +820,14 @@ static int cpu_read (void)
                return (-1);
        }
 
-       submit (0, "idle",   (derive_t) cs->idle);
-       submit (0, "nice",   (derive_t) cs->nice);
-       submit (0, "swap",   (derive_t) cs->swap);
-       submit (0, "system", (derive_t) cs->kernel);
-       submit (0, "user",   (derive_t) cs->user);
-       submit (0, "wait",   (derive_t) cs->iowait);
+       derives[CPU_SUBMIT_IDLE] = (derive_t) cs->idle;
+       derives[CPU_SUBMIT_NICE] = (derive_t) cs->nice;
+       derives[CPU_SUBMIT_SWAP] = (derive_t) cs->swap;
+       derives[CPU_SUBMIT_SYSTEM] = (derive_t) cs->kernel;
+       derives[CPU_SUBMIT_USER] = (derive_t) cs->user;
+       derives[CPU_SUBMIT_WAIT] = (derive_t) cs->iowait;
+       submit(0, derives);
+       submit_flush();
 /* #endif HAVE_LIBSTATGRAB */
 
 #elif defined(HAVE_PERFSTAT)
@@ -569,10 +842,10 @@ static int cpu_read (void)
                        sstrerror (errno, errbuf, sizeof (errbuf)));
                return (-1);
        }
-       
-       if (pnumcpu != numcpu || perfcpu == NULL) 
+
+       if (pnumcpu != numcpu || perfcpu == NULL)
        {
-               if (perfcpu != NULL) 
+               if (perfcpu != NULL)
                        free(perfcpu);
                perfcpu = malloc(numcpu * sizeof(perfstat_cpu_t));
        }
@@ -587,13 +860,18 @@ static int cpu_read (void)
                return (-1);
        }
 
-       for (i = 0; i < cpus; i++) 
+       for (i = 0; i < cpus; i++)
        {
-               submit (i, "idle",   (derive_t) perfcpu[i].idle);
-               submit (i, "system", (derive_t) perfcpu[i].sys);
-               submit (i, "user",   (derive_t) perfcpu[i].user);
-               submit (i, "wait",   (derive_t) perfcpu[i].wait);
+               derive_t derives[CPU_SUBMIT_MAX] = {
+                       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+               };
+               derives[CPU_SUBMIT_IDLE] = perfcpu[i].idle;
+               derives[CPU_SUBMIT_SYSTEM] = perfcpu[i].sys;
+               derives[CPU_SUBMIT_USER] = perfcpu[i].user;
+               derives[CPU_SUBMIT_WAIT] = perfcpu[i].wait;
+               submit(i, derives);
        }
+       submit_flush();
 #endif /* HAVE_PERFSTAT */
 
        return (0);
@@ -602,5 +880,6 @@ static int cpu_read (void)
 void module_register (void)
 {
        plugin_register_init ("cpu", init);
+       plugin_register_config ("cpu", cpu_config, config_keys, config_keys_num);
        plugin_register_read ("cpu", cpu_read);
 } /* void module_register */
index 4b8aa72..81e580d 100644 (file)
@@ -28,7 +28,7 @@
 
 #include <longintrepr.h>
 
-/* These two macros are basicly Py_BEGIN_ALLOW_THREADS and Py_BEGIN_ALLOW_THREADS
+/* These two macros are basically Py_BEGIN_ALLOW_THREADS and Py_BEGIN_ALLOW_THREADS
  * from the other direction. If a Python thread calls a C function
  * Py_BEGIN_ALLOW_THREADS is used to allow other python threads to run because
  * we don't intend to call any Python functions.
@@ -36,7 +36,7 @@
  * These two macros are used whenever a C thread intends to call some Python
  * function, usually because some registered callback was triggered.
  * Just like Py_BEGIN_ALLOW_THREADS it opens a block so these macros have to be
- * used in pairs. They aquire the GIL, create a new Python thread state and swap
+ * used in pairs. They acquire the GIL, create a new Python thread state and swap
  * the current thread state with the new one. This means this thread is now allowed
  * to execute Python code. */
 
index 958e34b..e9a409d 100644 (file)
--- a/src/csv.c
+++ b/src/csv.c
@@ -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>
  *   Doug MacEachern <dougm@hyperic.com>
  **/
 
index 1f78f82..f605c07 100644 (file)
@@ -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>
  *   Aman Gupta <aman at tmm1.net>
  **/
 
@@ -58,6 +58,7 @@ struct web_page_s /* {{{ */
   char *user;
   char *pass;
   char *credentials;
+  _Bool digest;
   _Bool verify_peer;
   _Bool verify_host;
   char *cacert;
@@ -364,8 +365,7 @@ static int cc_page_init_curl (web_page_t *wp) /* {{{ */
   curl_easy_setopt (wp->curl, CURLOPT_NOSIGNAL, 1L);
   curl_easy_setopt (wp->curl, CURLOPT_WRITEFUNCTION, cc_curl_callback);
   curl_easy_setopt (wp->curl, CURLOPT_WRITEDATA, wp);
-  curl_easy_setopt (wp->curl, CURLOPT_USERAGENT,
-      PACKAGE_NAME"/"PACKAGE_VERSION);
+  curl_easy_setopt (wp->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
   curl_easy_setopt (wp->curl, CURLOPT_ERRORBUFFER, wp->curl_errbuf);
   curl_easy_setopt (wp->curl, CURLOPT_URL, wp->url);
   curl_easy_setopt (wp->curl, CURLOPT_FOLLOWLOCATION, 1L);
@@ -389,6 +389,13 @@ static int cc_page_init_curl (web_page_t *wp) /* {{{ */
     ssnprintf (wp->credentials, credentials_size, "%s:%s",
         wp->user, (wp->pass == NULL) ? "" : wp->pass);
     curl_easy_setopt (wp->curl, CURLOPT_USERPWD, wp->credentials);
+    
+    if (wp->digest)
+    {
+      curl_easy_setopt (wp->curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
+      curl_easy_setopt (wp->curl, CURLOPT_USERNAME, wp->user);
+      curl_easy_setopt (wp->curl, CURLOPT_PASSWORD, wp->pass);
+    }
   }
 
   curl_easy_setopt (wp->curl, CURLOPT_SSL_VERIFYPEER, (long) wp->verify_peer);
@@ -426,6 +433,7 @@ static int cc_config_add_page (oconfig_item_t *ci) /* {{{ */
   page->url = NULL;
   page->user = NULL;
   page->pass = NULL;
+  page->digest = 0;
   page->verify_peer = 1;
   page->verify_host = 1;
   page->response_time = 0;
@@ -451,6 +459,8 @@ static int cc_config_add_page (oconfig_item_t *ci) /* {{{ */
       status = cf_util_get_string (child, &page->user);
     else if (strcasecmp ("Password", child->key) == 0)
       status = cf_util_get_string (child, &page->pass);
+    else if (strcasecmp ("Digest", child->key) == 0)
+      status = cf_util_get_boolean (child, &page->digest);
     else if (strcasecmp ("VerifyPeer", child->key) == 0)
       status = cf_util_get_boolean (child, &page->verify_peer);
     else if (strcasecmp ("VerifyHost", child->key) == 0)
index 9e0f672..a84cba0 100644 (file)
@@ -71,11 +71,13 @@ struct cj_s /* {{{ */
   char *user;
   char *pass;
   char *credentials;
+  _Bool digest;
   _Bool verify_peer;
   _Bool verify_host;
   char *cacert;
   struct curl_slist *headers;
   char *post_body;
+  cdtime_t interval;
 
   CURL *curl;
   char curl_errbuf[CURL_ERROR_SIZE];
@@ -587,8 +589,7 @@ static int cj_init_curl (cj_t *db) /* {{{ */
   curl_easy_setopt (db->curl, CURLOPT_NOSIGNAL, 1L);
   curl_easy_setopt (db->curl, CURLOPT_WRITEFUNCTION, cj_curl_callback);
   curl_easy_setopt (db->curl, CURLOPT_WRITEDATA, db);
-  curl_easy_setopt (db->curl, CURLOPT_USERAGENT,
-                    PACKAGE_NAME"/"PACKAGE_VERSION);
+  curl_easy_setopt (db->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
   curl_easy_setopt (db->curl, CURLOPT_ERRORBUFFER, db->curl_errbuf);
   curl_easy_setopt (db->curl, CURLOPT_URL, db->url);
 
@@ -610,6 +611,13 @@ static int cj_init_curl (cj_t *db) /* {{{ */
     ssnprintf (db->credentials, credentials_size, "%s:%s",
                db->user, (db->pass == NULL) ? "" : db->pass);
     curl_easy_setopt (db->curl, CURLOPT_USERPWD, db->credentials);
+    
+    if (db->digest)
+    {
+      curl_easy_setopt (db->curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
+      curl_easy_setopt (db->curl, CURLOPT_USERNAME, db->user);
+      curl_easy_setopt (db->curl, CURLOPT_PASSWORD, db->pass);
+    }
   }
 
   curl_easy_setopt (db->curl, CURLOPT_SSL_VERIFYPEER, (long) db->verify_peer);
@@ -676,6 +684,8 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */
       status = cf_util_get_string (child, &db->user);
     else if (db->url && strcasecmp ("Password", child->key) == 0)
       status = cf_util_get_string (child, &db->pass);
+    else if (strcasecmp ("Digest", child->key) == 0)
+      status = cf_util_get_boolean (child, &db->digest);
     else if (db->url && strcasecmp ("VerifyPeer", child->key) == 0)
       status = cf_util_get_boolean (child, &db->verify_peer);
     else if (db->url && strcasecmp ("VerifyHost", child->key) == 0)
@@ -688,6 +698,8 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */
       status = cf_util_get_string (child, &db->post_body);
     else if (strcasecmp ("Key", child->key) == 0)
       status = cj_config_add_key (db, child);
+    else if (strcasecmp ("Interval", child->key) == 0)
+      status = cf_util_get_cdtime(child, &db->interval);
     else
     {
       WARNING ("curl_json plugin: Option `%s' not allowed here.", child->key);
@@ -715,6 +727,9 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */
   {
     user_data_t ud;
     char *cb_name;
+    struct timespec interval = { 0, 0 };
+
+    CDTIME_T_TO_TIMESPEC (db->interval, &interval);
 
     if (db->instance == NULL)
       db->instance = strdup("default");
@@ -729,8 +744,9 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */
     cb_name = ssnprintf_alloc ("curl_json-%s-%s",
                db->instance, db->url ? db->url : db->sock);
 
-    plugin_register_complex_read (/* group = */ "curl_json", cb_name, cj_read,
-                                  /* interval = */ NULL, &ud);
+    plugin_register_complex_read (/* group = */ NULL, cb_name, cj_read,
+                                  /* interval = */ (db->interval > 0) ? &interval : NULL,
+                                  &ud);
     sfree (cb_name);
   }
   else
@@ -801,11 +817,10 @@ static void cj_submit (cj_t *db, cj_key_t *key, value_t *value) /* {{{ */
 
   if (key->instance == NULL)
   {
-    if ((db->depth == 0) || (strcmp ("", db->state[db->depth-1].name) == 0))
-      sstrncpy (vl.type_instance, db->state[db->depth].name, sizeof (vl.type_instance));
-    else
-      ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%s-%s",
-          db->state[db->depth-1].name, db->state[db->depth].name);
+    int i, len = 0;
+    for (i = 0; i < db->depth; i++)
+      len += ssnprintf(vl.type_instance+len, sizeof(vl.type_instance)-len,
+                       i ? "-%s" : "%s", db->state[i+1].name);
   }
   else
     sstrncpy (vl.type_instance, key->instance, sizeof (vl.type_instance));
@@ -815,6 +830,9 @@ static void cj_submit (cj_t *db, cj_key_t *key, value_t *value) /* {{{ */
   sstrncpy (vl.plugin_instance, db->instance, sizeof (vl.plugin_instance));
   sstrncpy (vl.type, key->type, sizeof (vl.type));
 
+  if (db->interval > 0)
+    vl.interval = db->interval;
+
   plugin_dispatch_values (&vl);
 } /* }}} int cj_submit */
 
index 7432edf..a743753 100644 (file)
@@ -76,6 +76,7 @@ struct cx_s /* {{{ */
   char *user;
   char *pass;
   char *credentials;
+  _Bool digest;
   _Bool verify_peer;
   _Bool verify_host;
   char *cacert;
@@ -838,8 +839,7 @@ static int cx_init_curl (cx_t *db) /* {{{ */
   curl_easy_setopt (db->curl, CURLOPT_NOSIGNAL, 1L);
   curl_easy_setopt (db->curl, CURLOPT_WRITEFUNCTION, cx_curl_callback);
   curl_easy_setopt (db->curl, CURLOPT_WRITEDATA, db);
-  curl_easy_setopt (db->curl, CURLOPT_USERAGENT,
-                    PACKAGE_NAME"/"PACKAGE_VERSION);
+  curl_easy_setopt (db->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
   curl_easy_setopt (db->curl, CURLOPT_ERRORBUFFER, db->curl_errbuf);
   curl_easy_setopt (db->curl, CURLOPT_URL, db->url);
 
@@ -861,6 +861,13 @@ static int cx_init_curl (cx_t *db) /* {{{ */
     ssnprintf (db->credentials, credentials_size, "%s:%s",
                db->user, (db->pass == NULL) ? "" : db->pass);
     curl_easy_setopt (db->curl, CURLOPT_USERPWD, db->credentials);
+    
+    if (db->digest)
+    {
+      curl_easy_setopt (db->curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
+      curl_easy_setopt (db->curl, CURLOPT_USERNAME, db->user);
+      curl_easy_setopt (db->curl, CURLOPT_PASSWORD, db->pass);
+    }
   }
 
   curl_easy_setopt (db->curl, CURLOPT_SSL_VERIFYPEER, db->verify_peer ? 1L : 0L);
@@ -927,6 +934,8 @@ static int cx_config_add_url (oconfig_item_t *ci) /* {{{ */
       status = cf_util_get_string (child, &db->user);
     else if (strcasecmp ("Password", child->key) == 0)
       status = cf_util_get_string (child, &db->pass);
+    else if (strcasecmp ("Digest", child->key) == 0)
+      status = cf_util_get_boolean (child, &db->digest);
     else if (strcasecmp ("VerifyPeer", child->key) == 0)
       status = cf_util_get_boolean (child, &db->verify_peer);
     else if (strcasecmp ("VerifyHost", child->key) == 0)
index 80488d8..223e159 100644 (file)
--- a/src/dbi.c
+++ b/src/dbi.c
@@ -2,18 +2,23 @@
  * collectd - src/dbi.c
  * Copyright (C) 2008-2013  Florian octo Forster
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <octo at collectd.org>
@@ -27,6 +32,9 @@
 
 #include <dbi/dbi.h>
 
+#ifdef HAVE_LIBDBI_R
+  dbi_inst inst = NULL;
+#endif
 /*
  * Data types
  */
@@ -68,6 +76,8 @@ static size_t            queries_num   = 0;
 static cdbi_database_t **databases     = NULL;
 static size_t            databases_num = 0;
 
+static int cdbi_read_database (user_data_t *ud);
+
 /*
  * Functions
  */
@@ -124,7 +134,7 @@ static int cdbi_result_get_field (dbi_result res, /* {{{ */
   else if (src_type == DBI_TYPE_STRING)
   {
     const char *value;
-    
+
     value = dbi_result_get_string_idx (res, index);
     if (value == NULL)
       sstrncpy (buffer, "", buffer_size);
@@ -190,7 +200,7 @@ static void cdbi_database_free (cdbi_database_t *db) /* {{{ */
  *     </Result>
  *     ...
  *   </Query>
- *     
+ *
  *   <Database "plugin_instance1">
  *     Driver "mysql"
  *     DriverOption "hostname" "localhost"
@@ -369,9 +379,24 @@ static int cdbi_config_add_database (oconfig_item_t *ci) /* {{{ */
     }
     else
     {
+      user_data_t ud;
+      char *name = NULL;
+
       databases = temp;
       databases[databases_num] = db;
       databases_num++;
+
+      memset (&ud, 0, sizeof (ud));
+      ud.data = (void *) db;
+      ud.free_func = NULL;
+      name = ssnprintf_alloc("dbi:%s", db->name);
+
+      plugin_register_complex_read (/* group = */ NULL,
+          /* name = */ name ? name : db->name,
+          /* callback = */ cdbi_read_database,
+          /* interval = */ NULL,
+          /* user_data = */ &ud);
+      free (name);
     }
   }
 
@@ -398,7 +423,7 @@ static int cdbi_config (oconfig_item_t *ci) /* {{{ */
       cdbi_config_add_database (child);
     else
     {
-      WARNING ("snmp plugin: Ignoring unknown config option `%s'.", child->key);
+      WARNING ("dbi plugin: Ignoring unknown config option `%s'.", child->key);
     }
   } /* for (ci->children) */
 
@@ -429,7 +454,11 @@ static int cdbi_init (void) /* {{{ */
     return (-1);
   }
 
+#ifdef HAVE_LIBDBI_R
+  status = dbi_initialize_r (NULL, &inst);
+#else
   status = dbi_initialize (NULL);
+#endif
   if (status < 0)
   {
     ERROR ("dbi plugin: cdbi_init: dbi_initialize failed with status %i.",
@@ -650,16 +679,26 @@ static int cdbi_connect_database (cdbi_database_t *db) /* {{{ */
     db->connection = NULL;
   }
 
+#ifdef HAVE_LIBDBI_R
+  driver = dbi_driver_open_r (db->driver, inst);
+#else
   driver = dbi_driver_open (db->driver);
+#endif
   if (driver == NULL)
   {
     ERROR ("dbi plugin: cdbi_connect_database: dbi_driver_open (%s) failed.",
         db->driver);
     INFO ("dbi plugin: Maybe the driver isn't installed? "
         "Known drivers are:");
+#ifdef HAVE_LIBDBI_R
+    for (driver = dbi_driver_list_r (NULL, inst);
+        driver != NULL;
+        driver = dbi_driver_list_r (driver, inst))
+#else
     for (driver = dbi_driver_list (NULL);
         driver != NULL;
         driver = dbi_driver_list (driver))
+#endif
     {
       INFO ("dbi plugin: * %s", dbi_driver_get_name (driver));
     }
@@ -758,8 +797,9 @@ static int cdbi_connect_database (cdbi_database_t *db) /* {{{ */
   return (0);
 } /* }}} int cdbi_connect_database */
 
-static int cdbi_read_database (cdbi_database_t *db) /* {{{ */
+static int cdbi_read_database (user_data_t *ud) /* {{{ */
 {
+  cdbi_database_t *db = (cdbi_database_t *) ud->data;
   size_t i;
   int success;
   int status;
@@ -798,29 +838,6 @@ static int cdbi_read_database (cdbi_database_t *db) /* {{{ */
   return (0);
 } /* }}} int cdbi_read_database */
 
-static int cdbi_read (void) /* {{{ */
-{
-  size_t i;
-  int success = 0;
-  int status;
-
-  for (i = 0; i < databases_num; i++)
-  {
-    status = cdbi_read_database (databases[i]);
-    if (status == 0)
-      success++;
-  }
-
-  if (success == 0)
-  {
-    ERROR ("dbi plugin: No database could be read. Will return an error so "
-        "the plugin will be delayed.");
-    return (-1);
-  }
-
-  return (0);
-} /* }}} int cdbi_read */
-
 static int cdbi_shutdown (void) /* {{{ */
 {
   size_t i;
@@ -848,7 +865,6 @@ void module_register (void) /* {{{ */
 {
   plugin_register_complex_config ("dbi", cdbi_config);
   plugin_register_init ("dbi", cdbi_init);
-  plugin_register_read ("dbi", cdbi_read);
   plugin_register_shutdown ("dbi", cdbi_shutdown);
 } /* }}} void module_register */
 
index 3d5a402..a6fa526 100644 (file)
--- a/src/df.c
+++ b/src/df.c
@@ -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>
  *   Paul Sadauskas <psadauskas at gmail.com>
  **/
 
index 36d0a0c..cdf2816 100644 (file)
@@ -128,11 +128,19 @@ static int pnumdisk;
 # error "No applicable input method."
 #endif
 
+#if HAVE_LIBUDEV
+#include <libudev.h>
+
+static char *conf_udev_name_attr = NULL;
+static struct udev *handle_udev;
+#endif
+
 static const char *config_keys[] =
 {
        "Disk",
        "UseBSDName",
-       "IgnoreSelected"
+       "IgnoreSelected",
+       "UdevNameAttr"
 };
 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
 
@@ -165,6 +173,21 @@ static int disk_config (const char *key, const char *value)
         "on Mach / Mac OS X and will be ignored.");
 #endif
   }
+  else if (strcasecmp ("UdevNameAttr", key) == 0)
+  {
+#if HAVE_LIBUDEV
+    if (conf_udev_name_attr != NULL)
+    {
+      free (conf_udev_name_attr);
+      conf_udev_name_attr = NULL;
+    }
+    if ((conf_udev_name_attr = strdup (value)) == NULL)
+      return (1);
+#else
+    WARNING ("disk plugin: The \"UdevNameAttr\" option is only supported "
+        "if collectd is built with libudev support");
+#endif
+  }
   else
   {
     return (-1);
@@ -259,6 +282,34 @@ static counter_t disk_calc_time_incr (counter_t delta_time, counter_t delta_ops)
 }
 #endif
 
+#if HAVE_LIBUDEV
+/**
+ * Attempt to provide an rename disk instance from an assigned udev attribute.
+ *
+ * On success, it returns a strduped char* to the desired attribute value.
+ * Otherwise it returns NULL.
+ */
+
+static char *disk_udev_attr_name (struct udev *udev, char *disk_name, const char *attr)
+{
+       struct udev_device *dev;
+       const char *prop;
+       char *output = NULL;
+
+       dev = udev_device_new_from_subsystem_sysname (udev, "block", disk_name);
+       if (dev != NULL)
+       {
+               prop = udev_device_get_property_value (dev, attr);
+               if (prop) {
+                       output = strdup (prop);
+                       DEBUG ("disk plugin: renaming %s => %s", disk_name, output);
+               }
+               udev_device_unref (dev);
+       }
+       return output;
+}
+#endif
+
 #if HAVE_IOKIT_IOKITLIB_H
 static signed long long dict_get_value (CFDictionaryRef dict, const char *key)
 {
@@ -505,9 +556,15 @@ static int disk_read (void)
                fieldshift = 1;
        }
 
+#if HAVE_LIBUDEV
+       handle_udev = udev_new();
+#endif
+
        while (fgets (buffer, sizeof (buffer), fh) != NULL)
        {
                char *disk_name;
+               char *output_name;
+               char *alt_name;
 
                numfields = strsplit (buffer, fields, 32);
 
@@ -659,25 +716,43 @@ static int disk_read (void)
                        continue;
                }
 
+               output_name = disk_name;
+
+#if HAVE_LIBUDEV
+               alt_name = disk_udev_attr_name (handle_udev, disk_name,
+                               conf_udev_name_attr);
+#else
+               alt_name = NULL;
+#endif
+               if (alt_name != NULL)
+                       output_name = alt_name;
+
                if ((ds->read_bytes != 0) || (ds->write_bytes != 0))
-                       disk_submit (disk_name, "disk_octets",
+                       disk_submit (output_name, "disk_octets",
                                        ds->read_bytes, ds->write_bytes);
 
                if ((ds->read_ops != 0) || (ds->write_ops != 0))
-                       disk_submit (disk_name, "disk_ops",
+                       disk_submit (output_name, "disk_ops",
                                        read_ops, write_ops);
 
                if ((ds->avg_read_time != 0) || (ds->avg_write_time != 0))
-                       disk_submit (disk_name, "disk_time",
+                       disk_submit (output_name, "disk_time",
                                        ds->avg_read_time, ds->avg_write_time);
 
                if (is_disk)
                {
-                       disk_submit (disk_name, "disk_merged",
+                       disk_submit (output_name, "disk_merged",
                                        read_merged, write_merged);
                } /* if (is_disk) */
+
+               /* release udev-based alternate name, if allocated */
+               free(alt_name);
        } /* while (fgets (buffer, sizeof (buffer), fh) != NULL) */
 
+#if HAVE_LIBUDEV
+       udev_unref(handle_udev);
+#endif
+
        fclose (fh);
 /* #endif defined(KERNEL_LINUX) */
 
diff --git a/src/drbd.c b/src/drbd.c
new file mode 100644 (file)
index 0000000..cc306dc
--- /dev/null
@@ -0,0 +1,170 @@
+/**
+ * collectd - src/drbd.c
+ * Copyright (C) 2014  Tim Laszlo
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Tim Laszlo <tim.laszlo at gmail.com>
+ **/
+
+/*
+ See: http://www.drbd.org/users-guide/ch-admin.html#s-performance-indicators
+
+ version: 8.3.11 (api:88/proto:86-96)
+ srcversion: 71955441799F513ACA6DA60 
+  0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate B r-----
+        ns:64363752 nr:0 dw:357799284 dr:846902273 al:34987022 bm:18062 lo:0 \
+                                               pe:0 ua:0 ap:0 ep:1 wo:f oos:0
+ */
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+static const char *drbd_stats = "/proc/drbd";
+static const char *drbd_names[] =
+{
+       "network_send",  /* ns (network send) */
+       "network_recv",  /* nr (network receive) */
+       "disk_write",      /* dw (disk write) */
+       "disk_read",            /* dr (disk read) */
+       "activity_log",  /* al (activity log) */
+       "bitmap",                  /* bm (bit map) */
+       "local_count",    /* lo (local count) */
+       "pending",                /* pe (pending) */
+       "unacknowledged",   /* ua (unacknowledged) */
+       "app pending",    /* ap (application pending) */
+       "epochs",                  /* ep (epochs) */
+       NULL,                      /* wo (write order) */
+       "oos"                      /* oos (out of sync) */
+};
+static size_t drbd_names_num = STATIC_ARRAY_SIZE (drbd_names);
+
+static int drbd_init (void)
+{
+       return (0);
+}
+
+
+static int drbd_submit_fields (long int resource,
+               char **fields, size_t fields_num)
+{
+       char plugin_instance[DATA_MAX_NAME_LEN];
+       value_t values[fields_num];
+       value_list_t vl = VALUE_LIST_INIT;
+       size_t i;
+
+       if (resource < 0)
+       {
+               WARNING ("drbd plugin: Unable to parse resource");
+               return (EINVAL);
+       }
+
+       if (fields_num != drbd_names_num)
+       {
+               WARNING ("drbd plugin: Wrong number of fields for "
+                                "r%ld statistics. Expected %zu, got %zu.",
+                                resource, drbd_names_num, fields_num);
+               return (EINVAL);
+       }
+
+       ssnprintf (plugin_instance, sizeof (plugin_instance), "r%ld",
+                       resource);
+
+       for (i = 0; i < drbd_names_num; i++)
+       {
+               char *data;
+               /* skip non numeric wo */
+               if (strncmp(fields[i], "wo", 2) == 0)
+                       continue;
+               data = strchr(fields[i], ':');
+               if (data == NULL)
+                       return (EINVAL);
+               (void) parse_value (++data, &values[i], DS_TYPE_DERIVE);
+       }
+
+       vl.values_len = 1;
+       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       sstrncpy (vl.plugin, "drbd", sizeof (vl.plugin));
+       sstrncpy (vl.plugin_instance, plugin_instance,
+                       sizeof (vl.plugin_instance));
+       sstrncpy (vl.type, "drbd_resource", sizeof (vl.type));
+
+       for (i = 0; i < fields_num; i++)
+       {
+               if (drbd_names[i] == NULL)
+                       continue;
+               vl.values = values + i;
+               sstrncpy (vl.type_instance, drbd_names[i],
+                               sizeof (vl.type_instance));
+               plugin_dispatch_values (&vl);
+       }
+
+       return (0);
+} /* drbd_submit_fields */
+
+static int drbd_read (void)
+{
+       FILE *fh;
+       char buffer[256];
+
+       long int resource = -1;
+       char *fields[16];
+       int fields_num = 0;
+
+       fh = fopen (drbd_stats, "r");
+       if (fh == NULL)
+       {
+               WARNING ("drbd plugin: Unable to open %s", drbd_stats);
+               return (EINVAL);
+       }
+
+       while (fgets (buffer, sizeof (buffer), fh) != NULL)
+       {
+               fields_num = strsplit (buffer,
+                               fields, STATIC_ARRAY_SIZE (fields));
+
+               /* ignore headers (first two iterations) */
+               if (fields_num < 4)
+                       continue;
+
+               if (isdigit(fields[0][0]))
+               {
+                       /* parse the resource line, next loop iteration
+                          will submit values for this resource */
+                       resource = strtol(fields[0], NULL, 10);
+               }
+               else
+               {
+                       /* handle stats data for the resource defined in the
+                          previous iteration */
+                       drbd_submit_fields(resource, fields, fields_num);
+               }
+       } /* while (fgets) */
+
+       fclose (fh);
+       return (0);
+} /* void drbd_read */
+
+void module_register (void)
+{
+       plugin_register_init ("drbd", drbd_init);
+       plugin_register_read ("drbd", drbd_read);
+} /* void module_register */
index 8f633cd..d1a8719 100644 (file)
@@ -2,20 +2,25 @@
  * collectd - src/email.c
  * Copyright (C) 2006-2008  Sebastian Harl
  *
- * 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.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
+ * Authors:
  *   Sebastian Harl <sh at tokkee.org>
  **/
 
index d56be6d..03de9ef 100644 (file)
@@ -1,22 +1,27 @@
 /**
  * collectd - src/entropy.c
- * Copyright (C) 2007  Florian octo Forster
+ * Copyright (C) 2007       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index b9a7365..cb6844b 100644 (file)
@@ -18,7 +18,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 Harl <sh at tokkee.org>
  *   Peter Holik <peter at holik.at>
  **/
index 47f99e9..47caf93 100644 (file)
@@ -18,7 +18,7 @@
  *
  * Authors:
  *   Alessandro Iurlano <alessandro.iurlano at gmail.com>
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index 7d8369b..c87b877 100644 (file)
@@ -1,22 +1,27 @@
 /**
- * collectd - src/filter_chain.h
+ * collectd - src/filter_chain.c
  * Copyright (C) 2008-2010  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
@@ -435,9 +440,10 @@ static int fc_config_add_rule (fc_chain_t *chain, /* {{{ */
 
 static int fc_config_add_chain (const oconfig_item_t *ci) /* {{{ */
 {
-  fc_chain_t *chain;
+  fc_chain_t *chain = NULL;
   int status = 0;
   int i;
+  int new_chain = 1;
 
   if ((ci->values_num != 1)
       || (ci->values[0].type != OCONFIG_TYPE_STRING))
@@ -447,17 +453,26 @@ static int fc_config_add_chain (const oconfig_item_t *ci) /* {{{ */
     return (-1);
   }
 
-  chain = (fc_chain_t *) malloc (sizeof (*chain));
+  if (chain_list_head != NULL)
+  {
+    if ((chain = fc_chain_get_by_name (ci->values[0].value.string)) != NULL)
+      new_chain = 0;
+  }
+
   if (chain == NULL)
   {
-    ERROR ("fc_config_add_chain: malloc failed.");
-    return (-1);
+    chain = (fc_chain_t *) malloc (sizeof (*chain));
+    if (chain == NULL)
+    {
+      ERROR ("fc_config_add_chain: malloc failed.");
+      return (-1);
+    }
+    memset (chain, 0, sizeof (*chain));
+    sstrncpy (chain->name, ci->values[0].value.string, sizeof (chain->name));
+    chain->rules = NULL;
+    chain->targets = NULL;
+    chain->next = NULL;
   }
-  memset (chain, 0, sizeof (*chain));
-  sstrncpy (chain->name, ci->values[0].value.string, sizeof (chain->name));
-  chain->rules = NULL;
-  chain->targets = NULL;
-  chain->next = NULL;
 
   for (i = 0; i < ci->children_num; i++)
   {
@@ -487,6 +502,9 @@ static int fc_config_add_chain (const oconfig_item_t *ci) /* {{{ */
 
   if (chain_list_head != NULL)
   {
+    if (!new_chain)
+      return (0);
+
     fc_chain_t *ptr;
 
     ptr = chain_list_head;
index 187fe22..2db90db 100644 (file)
@@ -2,21 +2,26 @@
  * collectd - src/filter_chain.h
  * Copyright (C) 2008,2009  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #ifndef FILTER_CHAIN_H
index 28be092..a00b26d 100644 (file)
@@ -2,18 +2,23 @@
  * collectd - src/gmond.c
  * Copyright (C) 2009,2010  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <octo at collectd.org>
index 4428b75..82c158c 100644 (file)
@@ -20,7 +20,7 @@
  *
  * Authors:
  *   Vincent Stehlé <vincent.stehle at free.fr>
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  *   Sebastian Harl <sh at tokkee.org>
  *
  * TODO:
index c618af9..df8ffb4 100644 (file)
@@ -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>
  *   Sune Marcher <sm at flork.dk>
  *   Manuel Sanmartin
  **/
index fada5bd..47ceaca 100644 (file)
@@ -18,7 +18,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>
  *   Peter Holik <peter at holik.at>
  *   Bruno Prémont <bonbons at linux-vserver.org>
  **/
index ee50355..8de59d2 100644 (file)
@@ -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>
  *   Justo Alonso Achaques <justo.alonso at gmail.com>
  **/
 
@@ -120,7 +120,7 @@ static int cjni_match_target_destroy (void **user_data);
 static int cjni_match_target_invoke (const data_set_t *ds, value_list_t *vl,
     notification_meta_t **meta, void **user_data);
 
-/* 
+/*
  * C to Java conversion functions
  */
 static int ctoj_string (JNIEnv *jvm_env, /* {{{ */
@@ -159,6 +159,23 @@ static int ctoj_string (JNIEnv *jvm_env, /* {{{ */
   return (0);
 } /* }}} int ctoj_string */
 
+static jstring ctoj_output_string (JNIEnv *jvm_env, /* {{{ */
+    const char *string)
+{
+  jstring o_string;
+
+  /* Create a java.lang.String */
+  o_string = (*jvm_env)->NewStringUTF (jvm_env,
+      (string != NULL) ? string : "");
+  if (o_string == NULL)
+  {
+    ERROR ("java plugin: ctoj_output_string: NewStringUTF failed.");
+    return NULL;
+  }
+
+  return (o_string);
+} /* }}} int ctoj_output_string */
+
 static int ctoj_int (JNIEnv *jvm_env, /* {{{ */
     jint value,
     jclass class_ptr, jobject object_ptr, const char *method_name)
@@ -1319,7 +1336,7 @@ static int jtoc_notification (JNIEnv *jvm_env, notification_t *n, /* {{{ */
 
   return (0);
 } /* }}} int jtoc_notification */
-/* 
+/*
  * Functions accessible from Java
  */
 static jint JNICALL cjni_api_dispatch_values (JNIEnv *jvm_env, /* {{{ */
@@ -1629,6 +1646,11 @@ static void JNICALL cjni_api_log (JNIEnv *jvm_env, /* {{{ */
   (*jvm_env)->ReleaseStringUTFChars (jvm_env, o_message, c_str);
 } /* }}} void cjni_api_log */
 
+static jstring JNICALL cjni_api_get_hostname (JNIEnv *jvm_env, jobject this)
+{
+    return ctoj_output_string(jvm_env, hostname_g);
+}
+
 /* List of ``native'' functions, i. e. C-functions that can be called from
  * Java. */
 static JNINativeMethod jni_api_functions[] = /* {{{ */
@@ -1688,6 +1710,11 @@ static JNINativeMethod jni_api_functions[] = /* {{{ */
   { "log",
     "(ILjava/lang/String;)V",
     cjni_api_log },
+
+  { "getHostname",
+    "()Ljava/lang/String;",
+    cjni_api_get_hostname },
+
 };
 static size_t jni_api_functions_num = sizeof (jni_api_functions)
   / sizeof (jni_api_functions[0]);
@@ -2436,7 +2463,7 @@ static void cjni_callback_info_destroy (void *arg) /* {{{ */
 
   cbi = (cjni_callback_info_t *) arg;
 
-  /* This condition can occurr when shutting down. */
+  /* This condition can occur when shutting down. */
   if (jvm == NULL)
   {
     sfree (cbi);
index 726f25d..20015be 100644 (file)
@@ -84,7 +84,7 @@
     _b[sizeof (_b) - 1] = 0; \
     SSTRCAT ((d), _b); \
   } while (0)
-    
+
 
 #define LCC_SET_ERRSTR(c, ...) do { \
   snprintf ((c)->errbuf, sizeof ((c)->errbuf), __VA_ARGS__); \
index 3962666..049f7f0 100644 (file)
@@ -65,6 +65,7 @@ int lcc_server_destroy (lcc_network_t *net, lcc_server_t *srv);
 
 /* Configure servers */
 int lcc_server_set_ttl (lcc_server_t *srv, uint8_t ttl);
+int lcc_server_set_interface (lcc_server_t *srv, char const *interface);
 int lcc_server_set_security_level (lcc_server_t *srv,
     lcc_security_level_t level,
     const char *username, const char *password);
index 6b6450c..ddb3b5b 100644 (file)
@@ -1,6 +1,7 @@
 /**
  * collectd - src/libcollectdclient/network.c
- * Copyright (C) 2005-2012  Florian octo Forster
+ * Copyright (C) 2005-2013  Florian Forster
+ * Copyright (C) 2010       Max Henkel
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -21,7 +22,8 @@
  * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at collectd.org>
+ *   Florian Forster <octo at collectd.org>
+ *   Max Henkel <henkel at gmx.at>
  **/
 
 #include "collectd.h"
 # include <netinet/in.h>
 #endif
 
+#if HAVE_NET_IF_H
+# include <net/if.h>
+#endif
+
 #include "collectd/network.h"
 #include "collectd/network_buffer.h"
 
@@ -379,6 +385,81 @@ int lcc_server_set_ttl (lcc_server_t *srv, uint8_t ttl) /* {{{ */
   return (0);
 } /* }}} int lcc_server_set_ttl */
 
+int lcc_server_set_interface (lcc_server_t *srv, char const *interface) /* {{{ */
+{
+  int if_index;
+  int status;
+
+  if ((srv == NULL) || (interface == NULL))
+    return (EINVAL);
+
+  if_index = if_nametoindex (interface);
+  if (if_index == 0)
+    return (ENOENT);
+
+  /* IPv4 multicast */
+  if (srv->sa->sa_family == AF_INET)
+  {
+    struct sockaddr_in *addr = (struct sockaddr_in *) srv->sa;
+
+    if (IN_MULTICAST (ntohl (addr->sin_addr.s_addr)))
+    {
+#if HAVE_STRUCT_IP_MREQN_IMR_IFINDEX
+      /* If possible, use the "ip_mreqn" structure which has
+       * an "interface index" member. Using the interface
+       * index is preferred here, because of its similarity
+       * to the way IPv6 handles this. Unfortunately, it
+       * appears not to be portable. */
+      struct ip_mreqn mreq;
+
+      memset (&mreq, 0, sizeof (mreq));
+      mreq.imr_multiaddr.s_addr = addr->sin_addr.s_addr;
+      mreq.imr_address.s_addr = ntohl (INADDR_ANY);
+      mreq.imr_ifindex = if_index;
+#else
+      struct ip_mreq mreq;
+
+      memset (&mreq, 0, sizeof (mreq));
+      mreq.imr_multiaddr.s_addr = addr->sin_addr.s_addr;
+      mreq.imr_interface.s_addr = ntohl (INADDR_ANY);
+#endif
+
+      status = setsockopt (srv->fd, IPPROTO_IP, IP_MULTICAST_IF,
+          &mreq, sizeof (mreq));
+      if (status != 0)
+        return (status);
+
+      return (0);
+    }
+  }
+
+  /* IPv6 multicast */
+  if (srv->sa->sa_family == AF_INET6)
+  {
+    struct sockaddr_in6 *addr = (struct sockaddr_in6 *) srv->sa;
+
+    if (IN6_IS_ADDR_MULTICAST (&addr->sin6_addr))
+    {
+      status = setsockopt (srv->fd, IPPROTO_IPV6, IPV6_MULTICAST_IF,
+          &if_index, sizeof (if_index));
+      if (status != 0)
+        return (status);
+
+      return (0);
+    }
+  }
+
+  /* else: Not a multicast interface. */
+#if defined(SO_BINDTODEVICE)
+  status = setsockopt (srv->fd, SOL_SOCKET, SO_BINDTODEVICE,
+      interface, strlen (interface) + 1);
+  if (status != 0)
+    return (-1);
+#endif
+
+  return (0);
+} /* }}} int lcc_server_set_interface */
+
 int lcc_server_set_security_level (lcc_server_t *srv, /* {{{ */
     lcc_security_level_t level,
     const char *username, const char *password)
index 629775a..539c9d3 100644 (file)
@@ -1,20 +1,28 @@
 /**
- * oconfig - src/oconfig.c
- * Copyright (C) 2006,2007  Florian octo Forster <octo at verplant.org>
+ * collectd - src/liboconfig/oconfig.c
+ * Copyright (C) 2006,2007  Florian 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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
- */
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Florian Forster <octo at collectd.org>
+ **/
 
 #include <stdlib.h>
 #include <stdio.h>
index 70fc623..840137c 100644 (file)
@@ -1,26 +1,34 @@
-#ifndef OCONFIG_H
-#define OCONFIG_H 1
-
-#include <stdio.h>
-
 /**
- * oconfig - src/oconfig.h
- * Copyright (C) 2006-2009  Florian octo Forster <octo at verplant.org>
+ * collectd - src/liboconfig/oconfig.h
+ * Copyright (C) 2006-2009  Florian Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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.
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * 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
+ * Authors:
+ *   Florian Forster <octo at collectd.org>
  */
 
+#ifndef OCONFIG_H
+#define OCONFIG_H 1
+
+#include <stdio.h>
+
 /*
  * Types
  */
index 19f58b2..d91df8c 100644 (file)
@@ -1,19 +1,27 @@
 /**
- * oconfig - src/parser.y
- * Copyright (C) 2007,2008  Florian octo Forster <octo at verplant.org>
+ * collectd - src/liboconfig/parser.y
+ * Copyright (C) 2007,2008  Florian 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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Florian Forster <octo at collectd.org>
  */
 
 %{
index 9f0cd8e..b6d757e 100644 (file)
@@ -1,20 +1,29 @@
 /**
- * oconfig - src/scanner.l
- * Copyright (C) 2007  Florian octo Forster <octo at verplant.org>
- * Copyright (C) 2008  Sebastian tokkee Harl <sh at tokkee.org>
+ * collectd - src/liboconfig/scanner.l
+ * Copyright (C) 2007  Florian Forster
+ * Copyright (C) 2008  Sebastian Harl
  *
- * 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.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Florian Forster <octo at collectd.org>
+ *   Sebastian Harl <sh at tokkee.org>
  */
 
 %{
index cfabaaa..b0c694a 100644 (file)
@@ -32,6 +32,9 @@
 #include <libxml/tree.h>
 #include <libxml/xpath.h>
 
+/* Plugin name */
+#define PLUGIN_NAME "libvirt"
+
 static const char *config_keys[] = {
     "Connection",
 
@@ -45,6 +48,8 @@ static const char *config_keys[] = {
     "HostnameFormat",
     "InterfaceFormat",
 
+    "PluginInstanceFormat",
+
     NULL
 };
 #define NR_CONFIG_KEYS ((sizeof config_keys / sizeof config_keys[0]) - 1)
@@ -113,6 +118,18 @@ enum hf_field {
 static enum hf_field hostname_format[HF_MAX_FIELDS] =
     { hf_name };
 
+/* PluginInstanceFormat */
+#define PLGINST_MAX_FIELDS 2
+
+enum plginst_field {
+    plginst_none = 0,
+    plginst_name,
+    plginst_uuid
+};
+
+static enum plginst_field plugin_instance_format[PLGINST_MAX_FIELDS] =
+    { plginst_name };
+
 /* InterfaceFormat. */
 enum if_field {
     if_address,
@@ -141,7 +158,7 @@ init_value_list (value_list_t *vl, virDomainPtr dom)
     const char *name;
     char uuid[VIR_UUID_STRING_BUFLEN];
 
-    sstrncpy (vl->plugin, "libvirt", sizeof (vl->plugin));
+    sstrncpy (vl->plugin, PLUGIN_NAME, sizeof (vl->plugin));
 
     vl->host[0] = '\0';
 
@@ -175,6 +192,35 @@ init_value_list (value_list_t *vl, virDomainPtr dom)
     }
 
     vl->host[sizeof (vl->host) - 1] = '\0';
+
+    /* Construct the plugin instance field according to PluginInstanceFormat. */
+    for (i = 0; i < PLGINST_MAX_FIELDS; ++i) {
+        if (plugin_instance_format[i] == plginst_none)
+            continue;
+
+        n = sizeof(vl->plugin_instance) - strlen (vl->plugin_instance) - 2;
+
+        if (i > 0 && n >= 1) {
+            strncat (vl->plugin_instance, ":", 1);
+            n--;
+        }
+
+        switch (plugin_instance_format[i]) {
+        case plginst_none: break;
+        case plginst_name:
+            name = virDomainGetName (dom);
+            if (name)
+                strncat (vl->plugin_instance, name, n);
+            break;
+        case plginst_uuid:
+            if (virDomainGetUUIDString (dom, uuid) == 0)
+                strncat (vl->plugin_instance, uuid, n);
+            break;
+        }
+    }
+
+    vl->plugin_instance[sizeof (vl->plugin_instance) - 1] = '\0';
+
 } /* void init_value_list */
 
 static void
@@ -197,6 +243,28 @@ memory_submit (gauge_t memory, virDomainPtr dom)
 }
 
 static void
+memory_stats_submit (gauge_t memory, virDomainPtr dom, int tag_index)
+{
+    static const char *tags[] = { "swap_in", "swap_out", "major_fault", "minor_fault",
+                                    "unused", "available", "actual_balloon", "rss"};
+
+    value_t values[1];
+    value_list_t vl = VALUE_LIST_INIT;
+
+    init_value_list (&vl, dom);
+
+    values[0].gauge = memory;
+
+    vl.values = values;
+    vl.values_len = 1;
+
+    sstrncpy (vl.type, "memory", sizeof (vl.type));
+    sstrncpy (vl.type_instance, tags[tag_index], sizeof (vl.type_instance));
+
+    plugin_dispatch_values (&vl);
+}
+
+static void
 cpu_submit (unsigned long long cpu_time,
             virDomainPtr dom, const char *type)
 {
@@ -279,7 +347,7 @@ lv_config (const char *key, const char *value)
     if (strcasecmp (key, "Connection") == 0) {
         char *tmp = strdup (value);
         if (tmp == NULL) {
-            ERROR ("libvirt plugin: Connection strdup failed.");
+            ERROR (PLUGIN_NAME " plugin: Connection strdup failed.");
             return 1;
         }
         sfree (conn_string);
@@ -330,14 +398,14 @@ lv_config (const char *key, const char *value)
 
         value_copy = strdup (value);
         if (value_copy == NULL) {
-            ERROR ("libvirt plugin: strdup failed.");
+            ERROR (PLUGIN_NAME " plugin: strdup failed.");
             return -1;
         }
 
         n = strsplit (value_copy, fields, HF_MAX_FIELDS);
         if (n < 1) {
             sfree (value_copy);
-            ERROR ("HostnameFormat: no fields");
+            ERROR (PLUGIN_NAME " plugin: HostnameFormat: no fields");
             return -1;
         }
 
@@ -350,7 +418,7 @@ lv_config (const char *key, const char *value)
                 hostname_format[i] = hf_uuid;
             else {
                 sfree (value_copy);
-                ERROR ("unknown HostnameFormat field: %s", fields[i]);
+                ERROR (PLUGIN_NAME " plugin: unknown HostnameFormat field: %s", fields[i]);
                 return -1;
             }
         }
@@ -362,6 +430,43 @@ lv_config (const char *key, const char *value)
         return 0;
     }
 
+    if (strcasecmp (key, "PluginInstanceFormat") == 0) {
+        char *value_copy;
+        char *fields[PLGINST_MAX_FIELDS];
+        int i, n;
+
+        value_copy = strdup (value);
+        if (value_copy == NULL) {
+            ERROR (PLUGIN_NAME " plugin: strdup failed.");
+            return -1;
+        }
+
+        n = strsplit (value_copy, fields, PLGINST_MAX_FIELDS);
+        if (n < 1) {
+            sfree (value_copy);
+            ERROR (PLUGIN_NAME " plugin: PluginInstanceFormat: no fields");
+            return -1;
+        }
+
+        for (i = 0; i < n; ++i) {
+            if (strcasecmp (fields[i], "name") == 0)
+                plugin_instance_format[i] = plginst_name;
+            else if (strcasecmp (fields[i], "uuid") == 0)
+                plugin_instance_format[i] = plginst_uuid;
+            else {
+                sfree (value_copy);
+                ERROR (PLUGIN_NAME " plugin: unknown HostnameFormat field: %s", fields[i]);
+                return -1;
+            }
+        }
+        sfree (value_copy);
+
+        for (i = n; i < PLGINST_MAX_FIELDS; ++i)
+            plugin_instance_format[i] = plginst_none;
+
+        return 0;
+    }
+
     if (strcasecmp (key, "InterfaceFormat") == 0) {
         if (strcasecmp (value, "name") == 0)
             interface_format = if_name;
@@ -370,7 +475,7 @@ lv_config (const char *key, const char *value)
         else if (strcasecmp (value, "number") == 0)
             interface_format = if_number;
         else {
-            ERROR ("unknown InterfaceFormat: %s", value);
+            ERROR (PLUGIN_NAME " plugin: unknown InterfaceFormat: %s", value);
             return -1;
         }
         return 0;
@@ -391,13 +496,13 @@ lv_read (void)
         conn = virConnectOpenReadOnly (conn_string);
         if (conn == NULL) {
             c_complain (LOG_ERR, &conn_complain,
-                    "libvirt plugin: Unable to connect: "
+                    PLUGIN_NAME " plugin: Unable to connect: "
                     "virConnectOpenReadOnly failed.");
             return -1;
         }
     }
     c_release (LOG_NOTICE, &conn_complain,
-            "libvirt plugin: Connection established.");
+            PLUGIN_NAME " plugin: Connection established.");
 
     time (&t);
 
@@ -430,13 +535,14 @@ lv_read (void)
     for (i = 0; i < nr_domains; ++i) {
         virDomainInfo info;
         virVcpuInfoPtr vinfo = NULL;
+        virDomainMemoryStatPtr minfo = NULL;
         int status;
         int j;
 
         status = virDomainGetInfo (domains[i], &info);
         if (status != 0)
         {
-            ERROR ("libvirt plugin: virDomainGetInfo failed with status %i.",
+            ERROR (PLUGIN_NAME " plugin: virDomainGetInfo failed with status %i.",
                     status);
             continue;
         }
@@ -446,7 +552,7 @@ lv_read (void)
 
         vinfo = malloc (info.nrVirtCpu * sizeof (vinfo[0]));
         if (vinfo == NULL) {
-            ERROR ("libvirt plugin: malloc failed.");
+            ERROR (PLUGIN_NAME " plugin: malloc failed.");
             continue;
         }
 
@@ -454,9 +560,9 @@ lv_read (void)
                 /* cpu map = */ NULL, /* cpu map length = */ 0);
         if (status < 0)
         {
-            ERROR ("libvirt plugin: virDomainGetVcpus failed with status %i.",
+            ERROR (PLUGIN_NAME " plugin: virDomainGetVcpus failed with status %i.",
                     status);
-            free (vinfo);
+            sfree (vinfo);
             continue;
         }
 
@@ -465,8 +571,30 @@ lv_read (void)
                     domains[i], vinfo[j].number, "virt_vcpu");
 
         sfree (vinfo);
+
+        minfo = malloc (VIR_DOMAIN_MEMORY_STAT_NR * sizeof (virDomainMemoryStatStruct));
+        if (minfo == NULL) {
+            ERROR ("libvirt plugin: malloc failed.");
+            continue;
+        }
+
+        status =  virDomainMemoryStats (domains[i], minfo, VIR_DOMAIN_MEMORY_STAT_NR, 0);
+
+        if (status < 0) {
+            ERROR ("libvirt plugin: virDomainMemoryStats failed with status %i.",
+                    status);
+            sfree (minfo);
+            continue;
+        }
+
+        for (j = 0; j < status; j++) {
+            memory_stats_submit ((gauge_t) minfo[j].val, domains[i], minfo[j].tag);
+        }
+
+        sfree (minfo);
     }
 
+
     /* Get block device stats for each domain. */
     for (i = 0; i < nr_block_devices; ++i) {
         struct _virDomainBlockStats stats;
@@ -551,7 +679,7 @@ refresh_lists (void)
         /* Get list of domains. */
         domids = malloc (sizeof (int) * n);
         if (domids == 0) {
-            ERROR ("libvirt plugin: malloc failed.");
+            ERROR (PLUGIN_NAME " plugin: malloc failed.");
             return -1;
         }
 
@@ -593,7 +721,7 @@ refresh_lists (void)
                 goto cont;
 
             if (add_domain (dom) < 0) {
-                ERROR ("libvirt plugin: malloc failed.");
+                ERROR (PLUGIN_NAME " plugin: malloc failed.");
                 goto cont;
             }
 
@@ -830,7 +958,7 @@ ignore_device_match (ignorelist_t *il, const char *domname, const char *devpath)
     n = sizeof (char) * (strlen (domname) + strlen (devpath) + 2);
     name = malloc (n);
     if (name == NULL) {
-        ERROR ("libvirt plugin: malloc failed.");
+        ERROR (PLUGIN_NAME " plugin: malloc failed.");
         return 0;
     }
     ssnprintf (name, n, "%s:%s", domname, devpath);
@@ -863,12 +991,12 @@ lv_shutdown (void)
 void
 module_register (void)
 {
-    plugin_register_config ("libvirt",
+    plugin_register_config (PLUGIN_NAME,
     lv_config,
     config_keys, NR_CONFIG_KEYS);
-    plugin_register_init ("libvirt", lv_init);
-    plugin_register_read ("libvirt", lv_read);
-    plugin_register_shutdown ("libvirt", lv_shutdown);
+    plugin_register_init (PLUGIN_NAME, lv_init);
+    plugin_register_read (PLUGIN_NAME, lv_read);
+    plugin_register_shutdown (PLUGIN_NAME, lv_shutdown);
 }
 
 /*
index 0188da7..f631476 100644 (file)
@@ -2,6 +2,7 @@
  * collectd - src/load.c
  * Copyright (C) 2005-2008  Florian octo Forster
  * Copyright (C) 2009       Manuel Sanmartin
+ * Copyright (C) 2013       Vedran Bartonicek
  *
  * 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,8 +18,9 @@
  * 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>
  *   Manuel Sanmartin
+ *   Vedran Bartonicek <vbartoni at gmail.com>
  **/
 
 #define _BSD_SOURCE
@@ -27,6 +29,8 @@
 #include "common.h"
 #include "plugin.h"
 
+#include <unistd.h>
+
 #ifdef HAVE_SYS_LOADAVG_H
 #include <sys/loadavg.h>
 #endif
 # include <libperfstat.h>
 #endif /* HAVE_PERFSTAT */
 
+static _Bool report_relative_load = 0;
+
+static const char *config_keys[] =
+{
+       "ReportRelative"
+};
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+
+static int load_config (const char *key, const char *value)
+{
+       if (strcasecmp (key, "ReportRelative") == 0)
+#ifdef _SC_NPROCESSORS_ONLN
+               report_relative_load = IS_TRUE (value) ? 1 : 0;
+#else
+                WARNING ("load plugin: The \"ReportRelative\" configuration "
+                         "is not available, because I can't determine the "
+                         "number of CPUS on this system. Sorry.");
+#endif
+       return (-1);
+
+}
 static void load_submit (gauge_t snum, gauge_t mnum, gauge_t lnum)
 {
        value_t values[3];
        value_list_t vl = VALUE_LIST_INIT;
+        int cores = 0;
+        char errbuf[1024];
+
+#ifdef  _SC_NPROCESSORS_ONLN
+        if (report_relative_load) {
+                if ((cores = sysconf(_SC_NPROCESSORS_ONLN)) < 1) {
+                       WARNING ("load: sysconf failed : %s",
+                                sstrerror (errno, errbuf, sizeof (errbuf)));
+               }
+       }
+#endif
+       if (cores > 0) {
+               snum /= cores;
+               mnum /= cores;
+               lnum /= cores;
+       }
 
        values[0].gauge = snum;
        values[1].gauge = mnum;
@@ -60,10 +101,16 @@ static void load_submit (gauge_t snum, gauge_t mnum, gauge_t lnum)
 
        vl.values = values;
        vl.values_len = STATIC_ARRAY_SIZE (values);
+
        sstrncpy (vl.host, hostname_g, sizeof (vl.host));
        sstrncpy (vl.plugin, "load", sizeof (vl.plugin));
        sstrncpy (vl.type, "load", sizeof (vl.type));
 
+       if (cores > 0) {
+               sstrncpy(vl.type_instance, "relative",
+                        sizeof (vl.type_instance));
+       }
+
        plugin_dispatch_values (&vl);
 }
 
@@ -73,17 +120,17 @@ static int load_read (void)
        double load[3];
 
        if (getloadavg (load, 3) == 3)
-               load_submit (load[LOADAVG_1MIN], load[LOADAVG_5MIN], load[LOADAVG_15MIN]);
-       else
-       {
-               char errbuf[1024];
-               WARNING ("load: getloadavg failed: %s",
-                               sstrerror (errno, errbuf, sizeof (errbuf)));
+                load_submit (load[LOADAVG_1MIN], load[LOADAVG_5MIN], load[LOADAVG_15MIN]);
+        else
+        {
+                char errbuf[1024];
+                WARNING ("load: getloadavg failed: %s",
+                         sstrerror (errno, errbuf, sizeof (errbuf)));
        }
 /* #endif HAVE_GETLOADAVG */
 
 #elif defined(KERNEL_LINUX)
-       gauge_t snum, mnum, lnum;
+        gauge_t snum, mnum, lnum;
        FILE *loadavg;
        char buffer[16];
 
@@ -123,11 +170,11 @@ static int load_read (void)
        mnum = atof (fields[1]);
        lnum = atof (fields[2]);
 
-       load_submit (snum, mnum, lnum);
+        load_submit(snum, mnum, lnum);
 /* #endif KERNEL_LINUX */
 
 #elif HAVE_LIBSTATGRAB
-       gauge_t snum, mnum, lnum;
+        gauge_t snum, mnum, lnum;
        sg_load_stats *ls;
 
        if ((ls = sg_get_load_stats ()) == NULL)
@@ -136,12 +183,11 @@ static int load_read (void)
        snum = ls->min1;
        mnum = ls->min5;
        lnum = ls->min15;
-
-       load_submit (snum, mnum, lnum);
+        load_submit(snum, mnum, lnum);
 /* #endif HAVE_LIBSTATGRAB */
 
 #elif HAVE_PERFSTAT
-       gauge_t snum, mnum, lnum;
+        gauge_t snum, mnum, lnum;
        perfstat_cpu_total_t cputotal;
 
        if (perfstat_cpu_total(NULL,  &cputotal, sizeof(perfstat_cpu_total_t), 1) < 0)
@@ -155,8 +201,7 @@ static int load_read (void)
        snum = (float)cputotal.loadavg[0]/(float)(1<<SBITS);
        mnum = (float)cputotal.loadavg[1]/(float)(1<<SBITS);
        lnum = (float)cputotal.loadavg[2]/(float)(1<<SBITS);
-
-       load_submit (snum, mnum, lnum);
+        load_submit(snum, mnum, lnum);
 /* #endif HAVE_PERFSTAT */
 
 #else
@@ -168,5 +213,6 @@ static int load_read (void)
 
 void module_register (void)
 {
+       plugin_register_config ("load", load_config, config_keys, config_keys_num);
        plugin_register_read ("load", load_read);
 } /* void module_register */
diff --git a/src/log_logstash.c b/src/log_logstash.c
new file mode 100644 (file)
index 0000000..15b3580
--- /dev/null
@@ -0,0 +1,394 @@
+/**
+ * collectd - src/log_logstash.c
+ * Copyright (C) 2013       Pierre-Yves Ritschard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Pierre-Yves Ritschard <pyr at spootnik.org>
+ * Acknowledgements:
+ *   This file is largely inspired by logfile.c
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+#include <sys/types.h>
+#include <pthread.h>
+#include <yajl/yajl_common.h>
+#include <yajl/yajl_gen.h>
+#if HAVE_YAJL_YAJL_VERSION_H
+# include <yajl/yajl_version.h>
+#endif
+#if defined(YAJL_MAJOR) && (YAJL_MAJOR > 1)
+# define HAVE_YAJL_V2 1
+#endif
+
+#define DEFAULT_LOGFILE LOCALSTATEDIR"/log/"PACKAGE_NAME".json.log"
+
+#if COLLECT_DEBUG
+static int log_level = LOG_DEBUG;
+#else
+static int log_level = LOG_INFO;
+#endif /* COLLECT_DEBUG */
+
+static pthread_mutex_t file_lock = PTHREAD_MUTEX_INITIALIZER;
+
+static char *log_file = NULL;
+
+static const char *config_keys[] =
+{
+       "LogLevel",
+       "File"
+};
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+
+static int log_logstash_config (const char *key, const char *value)
+{
+
+       if (0 == strcasecmp (key, "LogLevel")) {
+               log_level = parse_log_severity(value);
+        if (log_level < 0) {
+            log_level = LOG_INFO;
+            ERROR("log_logstash: invalid loglevel [%s] defaulting to 'info'",
+                  value);
+            return 1;
+        }
+       }
+       else if (0 == strcasecmp (key, "File")) {
+               sfree (log_file);
+               log_file = strdup (value);
+       }
+       else {
+               return -1;
+       }
+       return 0;
+} /* int log_logstash_config (const char *, const char *) */
+
+static void log_logstash_print (yajl_gen g, int severity,
+               cdtime_t timestamp_time)
+{
+       FILE *fh;
+       _Bool do_close = 0;
+       struct tm timestamp_tm;
+       char timestamp_str[64];
+       const unsigned char *buf;
+       time_t tt;
+#if HAVE_YAJL_V2
+       size_t len;
+#else
+       unsigned int len;
+#endif
+
+       if (yajl_gen_string(g, (u_char *)"@level", strlen("@level")) !=
+           yajl_gen_status_ok)
+               goto err;
+
+       switch (severity) {
+       case LOG_ERR:
+               if (yajl_gen_string(g, (u_char *)"error", strlen("error")) !=
+                   yajl_gen_status_ok)
+                       goto err;
+               break;
+       case LOG_WARNING:
+               if (yajl_gen_string(g, (u_char *)"warning",
+                                   strlen("warning")) !=
+                   yajl_gen_status_ok)
+                       goto err;
+               break;
+       case LOG_NOTICE:
+               if (yajl_gen_string(g, (u_char *)"notice", strlen("notice")) !=
+                   yajl_gen_status_ok)
+                       goto err;
+               break;
+       case LOG_INFO:
+               if (yajl_gen_string(g, (u_char *)"info", strlen("info")) !=
+                   yajl_gen_status_ok)
+                       goto err;
+               break;
+       case LOG_DEBUG:
+               if (yajl_gen_string(g, (u_char *)"debug", strlen("debug")) !=
+                   yajl_gen_status_ok)
+                       goto err;
+               break;
+       default:
+               if (yajl_gen_string(g, (u_char *)"unknown",
+                                   strlen("unknown")) !=
+                   yajl_gen_status_ok)
+                       goto err;
+               break;
+       }
+
+       if (yajl_gen_string(g, (u_char *)"@timestamp", strlen("@timestamp")) !=
+           yajl_gen_status_ok)
+               goto err;
+
+       tt = CDTIME_T_TO_TIME_T (timestamp_time);
+       gmtime_r (&tt, &timestamp_tm);
+
+       /*
+        * format time as a UTC ISO 8601 compliant string
+        */
+       strftime (timestamp_str, sizeof (timestamp_str),
+                 "%Y-%m-%d %H:%M:%SZ", &timestamp_tm);
+       timestamp_str[sizeof (timestamp_str) - 1] = '\0';
+
+       if (yajl_gen_string(g, (u_char *)timestamp_str,
+                           strlen(timestamp_str)) !=
+           yajl_gen_status_ok)
+               goto err;
+
+       if (yajl_gen_map_close(g) != yajl_gen_status_ok)
+               goto err;
+
+       if (yajl_gen_get_buf(g, &buf, &len) != yajl_gen_status_ok)
+               goto err;
+       pthread_mutex_lock (&file_lock);
+
+       if (log_file == NULL)
+       {
+               fh = fopen (DEFAULT_LOGFILE, "a");
+               do_close = 1;
+       } else if (strcasecmp(log_file, "stdout") == 0) {
+        fh = stdout;
+        do_close = 0;
+       } else if (strcasecmp(log_file, "stderr") == 0) {
+        fh = stderr;
+        do_close = 0;
+       } else {
+               fh = fopen (log_file, "a");
+               do_close = 1;
+       }
+
+       if (fh == NULL)
+       {
+                       char errbuf[1024];
+                       fprintf (stderr, "log_logstash plugin: fopen (%s) failed: %s\n",
+                                       (log_file == NULL) ? DEFAULT_LOGFILE : log_file,
+                                       sstrerror (errno, errbuf, sizeof (errbuf)));
+       }
+       else
+       {
+               fprintf(fh, "%s\n", buf);
+               if (do_close) {
+                       fclose (fh);
+               } else {
+                       fflush(fh);
+               }
+       }
+       pthread_mutex_unlock (&file_lock);
+       yajl_gen_free(g);
+       return;
+
+ err:
+       yajl_gen_free(g);
+       fprintf(stderr, "Could not correctly generate JSON message\n");
+       return;
+} /* void log_logstash_print */
+
+static void log_logstash_log (int severity, const char *msg,
+               user_data_t __attribute__((unused)) *user_data)
+{
+       yajl_gen g;
+#if !defined(HAVE_YAJL_V2)
+       yajl_gen_config conf;
+
+       conf.beautify = 0;
+#endif
+
+       if (severity > log_level)
+               return;
+
+#if HAVE_YAJL_V2
+       g = yajl_gen_alloc(NULL);
+#else
+       g = yajl_gen_alloc(&conf, NULL);
+#endif
+
+       if (g == NULL) {
+               fprintf(stderr, "Could not allocate JSON generator.\n");
+               return;
+       }
+
+       if (yajl_gen_map_open(g) != yajl_gen_status_ok)
+               goto err;
+       if (yajl_gen_string(g, (u_char *)"@message", strlen("@message")) !=
+           yajl_gen_status_ok)
+               goto err;
+       if (yajl_gen_string(g, (u_char *)msg, strlen(msg)) !=
+           yajl_gen_status_ok)
+               goto err;
+
+       log_logstash_print (g, severity, cdtime ());
+       return;
+ err:
+       yajl_gen_free(g);
+       fprintf(stderr, "Could not generate JSON message preamble\n");
+       return;
+
+} /* void log_logstash_log (int, const char *) */
+
+static int log_logstash_notification (const notification_t *n,
+               user_data_t __attribute__((unused)) *user_data)
+{
+       yajl_gen g;
+#if HAVE_YAJL_V2
+       g = yajl_gen_alloc(NULL);
+#else
+       yajl_gen_config conf;
+
+       conf.beautify = 0;
+       g = yajl_gen_alloc(&conf, NULL);
+#endif
+
+       if (g == NULL) {
+               fprintf(stderr, "Could not allocate JSON generator.\n");
+               return (0);
+       }
+
+       if (yajl_gen_map_open(g) != yajl_gen_status_ok)
+               goto err;
+       if (yajl_gen_string(g, (u_char *)"@message", strlen("@message")) !=
+           yajl_gen_status_ok)
+               goto err;
+       if (strlen(n->message) > 0) {
+               if (yajl_gen_string(g, (u_char *)n->message,
+                                   strlen(n->message)) !=
+                   yajl_gen_status_ok)
+                       goto err;
+       } else {
+               if (yajl_gen_string(g, (u_char *)"notification without a message",
+                                   strlen("notification without a message")) !=
+                   yajl_gen_status_ok)
+                       goto err;
+       }
+
+
+       if (yajl_gen_string(g, (u_char *)"@fields", strlen("@fields")) !=
+           yajl_gen_status_ok)
+               goto err;
+       if (yajl_gen_map_open(g) !=
+           yajl_gen_status_ok)
+               goto err;
+
+       if (strlen(n->host) > 0) {
+               if (yajl_gen_string(g, (u_char *)"host", strlen("host")) !=
+                   yajl_gen_status_ok)
+                       goto err;
+               if (yajl_gen_string(g, (u_char *)n->host, strlen(n->host)) !=
+                   yajl_gen_status_ok)
+                       goto err;
+
+       }
+       if (strlen(n->plugin) > 0) {
+               if (yajl_gen_string(g, (u_char *)"plugin", strlen("plugin")) !=
+                   yajl_gen_status_ok)
+                       goto err;
+               if (yajl_gen_string(g, (u_char *)n->plugin, strlen(n->plugin)) !=
+                   yajl_gen_status_ok)
+                       goto err;
+       }
+       if (strlen(n->plugin_instance) > 0) {
+               if (yajl_gen_string(g, (u_char *)"plugin_instance",
+                                   strlen("plugin_instance")) !=
+                   yajl_gen_status_ok)
+                       goto err;
+               if (yajl_gen_string(g, (u_char *)n->plugin_instance,
+                                   strlen(n->plugin_instance)) !=
+                   yajl_gen_status_ok)
+                       goto err;
+       }
+       if (strlen(n->type) > 0) {
+               if (yajl_gen_string(g, (u_char *)"type", strlen("type")) !=
+                   yajl_gen_status_ok)
+                       goto err;
+               if (yajl_gen_string(g, (u_char *)n->type, strlen(n->type)) !=
+                   yajl_gen_status_ok)
+                       goto err;
+       }
+       if (strlen(n->type_instance) > 0) {
+               if (yajl_gen_string(g, (u_char *)"type_instance",
+                                   strlen("type_instance")) !=
+                   yajl_gen_status_ok)
+                       goto err;
+               if (yajl_gen_string(g, (u_char *)n->type_instance,
+                                   strlen(n->type_instance)) !=
+                   yajl_gen_status_ok)
+                       goto err;
+       }
+
+       if (yajl_gen_string(g, (u_char *)"severity",
+                           strlen("severity")) !=
+           yajl_gen_status_ok)
+               goto err;
+
+       switch (n->severity) {
+       case NOTIF_FAILURE:
+               if (yajl_gen_string(g, (u_char *)"failure",
+                                   strlen("failure")) !=
+                   yajl_gen_status_ok)
+                       goto err;
+               break;
+       case NOTIF_WARNING:
+               if (yajl_gen_string(g, (u_char *)"warning",
+                                   strlen("warning")) !=
+                   yajl_gen_status_ok)
+                       goto err;
+               break;
+       case NOTIF_OKAY:
+               if (yajl_gen_string(g, (u_char *)"ok",
+                                   strlen("ok")) !=
+                   yajl_gen_status_ok)
+                       goto err;
+               break;
+       default:
+               if (yajl_gen_string(g, (u_char *)"unknown",
+                                   strlen("unknown")) !=
+                   yajl_gen_status_ok)
+                       goto err;
+               break;
+       }
+       if (yajl_gen_map_close(g) != yajl_gen_status_ok)
+               goto err;
+
+       log_logstash_print (g, LOG_INFO, (n->time != 0) ? n->time : cdtime ());
+       return (0);
+
+ err:
+       yajl_gen_free(g);
+       fprintf(stderr, "Could not correctly generate JSON notification\n");
+       return (0);
+} /* int log_logstash_notification */
+
+void module_register (void)
+{
+       plugin_register_config ("log_logstash",
+                               log_logstash_config,
+                               config_keys,
+                               config_keys_num);
+       plugin_register_log ("log_logstash",
+                            log_logstash_log,
+                            /* user_data = */ NULL);
+       plugin_register_notification ("log_logstash",
+                                     log_logstash_notification,
+                                     /* user_data = */ NULL);
+} /* void module_register (void) */
+
+/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
index 0f20f3c..b75ecb8 100644 (file)
@@ -1,24 +1,29 @@
 /**
  * collectd - src/logfile.c
- * Copyright (C) 2007  Sebastian Harl
+ * Copyright (C) 2007       Sebastian Harl
  * Copyright (C) 2007,2008  Florian 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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Sebastian Harl <sh at tokkee.org>
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
@@ -54,7 +59,11 @@ static int logfile_config (const char *key, const char *value)
 {
        if (0 == strcasecmp (key, "LogLevel")) {
                log_level = parse_log_severity(value);
-               if (log_level == -1) return 1; /* to keep previous behaviour */
+               if (log_level < 0) {
+                       log_level = LOG_INFO;
+                       ERROR ("logfile: invalid loglevel [%s] defaulting to 'info'", value);
+                       return (1);
+               }
        }
        else if (0 == strcasecmp (key, "File")) {
                sfree (log_file);
index 12c621d..82d7f6f 100644 (file)
--- a/src/lvm.c
+++ b/src/lvm.c
@@ -1,6 +1,7 @@
 /**
  * collectd - src/lvm.c
  * Copyright (C) 2013       Chad Malfait
+ * Copyright (C) 2014       Carnegie Mellon University
  *
  * 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,6 +18,7 @@
  *
  * Authors:
  *   Chad Malfait <malfaitc at yahoo.com>
+ *   Benjamin Gilbert <bgilbert at cs.cmu.edu>
  **/
 
 #include <lvm2app.h>
 #include "common.h"
 #include "plugin.h"
 
+#define NO_VALUE UINT64_MAX
+#define PERCENT_SCALE_FACTOR 1e-8
+
+static uint64_t get_lv_property_int(lv_t lv, char const *property)
+{
+    lvm_property_value_t v;
+
+    v = lvm_lv_get_property(lv, property);
+    if (!v.is_valid || !v.is_integer)
+        return NO_VALUE;
+    /* May be NO_VALUE if @property does not apply to this LV */
+    return v.value.integer;
+}
+
+static char const *get_lv_property_string(lv_t lv, char const *property)
+{
+    lvm_property_value_t v;
+
+    v = lvm_lv_get_property(lv, property);
+    if (!v.is_valid || !v.is_string)
+        return NULL;
+    return v.value.string;
+}
+
 static void lvm_submit (char const *plugin_instance, char const *type_instance,
         uint64_t ivalue)
 {
@@ -45,24 +71,95 @@ static void lvm_submit (char const *plugin_instance, char const *type_instance,
     plugin_dispatch_values (&vl);
 }
 
-static int vg_read(vg_t vg, char const *vg_name)
+static void report_lv_utilization(lv_t lv, char const *vg_name,
+        char const *lv_name, uint64_t lv_size,
+        char const *used_percent_property)
+{
+    uint64_t used_percent_unscaled;
+    uint64_t used_bytes;
+    char plugin_instance[DATA_MAX_NAME_LEN];
+
+    used_percent_unscaled = get_lv_property_int(lv, used_percent_property);
+    if (used_percent_unscaled == NO_VALUE)
+        return;
+    used_bytes = lv_size * (used_percent_unscaled * PERCENT_SCALE_FACTOR);
+
+    ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-%s",
+            vg_name, lv_name);
+    lvm_submit(plugin_instance, "used", used_bytes);
+    lvm_submit(plugin_instance, "free", lv_size - used_bytes);
+}
+
+static void report_thin_pool_utilization(lv_t lv, char const *vg_name,
+        uint64_t lv_size)
+{
+    char const *data_lv;
+    char const *metadata_lv;
+    uint64_t metadata_size;
+
+    data_lv = get_lv_property_string(lv, "data_lv");
+    metadata_lv = get_lv_property_string(lv, "metadata_lv");
+    metadata_size = get_lv_property_int(lv, "lv_metadata_size");
+    if (data_lv == NULL || metadata_lv == NULL || metadata_size == NO_VALUE)
+        return;
+
+    report_lv_utilization(lv, vg_name, data_lv, lv_size, "data_percent");
+    report_lv_utilization(lv, vg_name, metadata_lv, metadata_size,
+            "metadata_percent");
+}
+
+static void vg_read(vg_t vg, char const *vg_name)
 {
     struct dm_list *lvs;
     struct lvm_lv_list *lvl;
+    char const *name;
+    char const *attrs;
+    uint64_t size;
 
     lvm_submit (vg_name, "free", lvm_vg_get_free_size(vg));
 
     lvs = lvm_vg_list_lvs(vg);
     if (!lvs) {
         /* no VGs are defined, which is not an error per se */
-        return (0);
+        return;
     }
 
     dm_list_iterate_items(lvl, lvs) {
          lvm_submit(vg_name, lvm_lv_get_name(lvl->lv), lvm_lv_get_size(lvl->lv));
     }
 
-    return (0);
+    dm_list_iterate_items(lvl, lvs) {
+        name = lvm_lv_get_name(lvl->lv);
+        attrs = get_lv_property_string(lvl->lv, "lv_attr");
+        size = lvm_lv_get_size(lvl->lv);
+        if (name == NULL || attrs == NULL || size == NO_VALUE)
+            continue;
+
+        /* Condition on volume type.  We want the reported sizes in the
+           volume group to sum to the size of the volume group, so we ignore
+           virtual volumes.  */
+        switch (attrs[0]) {
+            case 's':
+            case 'S':
+                /* Snapshot.  Also report used/free space. */
+                report_lv_utilization(lvl->lv, vg_name, name, size,
+                        "data_percent");
+                break;
+            case 't':
+                /* Thin pool virtual volume.  We report the underlying data
+                   and metadata volumes, not this one.  Report used/free
+                   space, then ignore. */
+                report_thin_pool_utilization(lvl->lv, vg_name, size);
+                continue;
+            case 'v':
+                /* Virtual volume.  Ignore. */
+                continue;
+            case 'V':
+                /* Thin volume or thin snapshot.  Ignore. */
+                continue;
+        }
+        lvm_submit(vg_name, name, size);
+    }
 }
 
 static int lvm_read(void)
index 1ab445a..abde2b3 100644 (file)
@@ -1,22 +1,27 @@
 /**
  * collectd - src/match_empty_counter.c
- * Copyright (C) 2009  Florian Forster
+ * Copyright (C) 2009       Florian 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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index ee3101a..ba0c47c 100644 (file)
@@ -1,22 +1,27 @@
 /**
  * collectd - src/match_hashed.c
- * Copyright (C) 2009  Florian Forster
+ * Copyright (C) 2009       Florian 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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index 1defc18..4fa6ce7 100644 (file)
@@ -1,24 +1,29 @@
 /**
  * collectd - src/match_regex.c
- * Copyright (C) 2008  Sebastian Harl
- * Copyright (C) 2008  Florian Forster
+ * Copyright (C) 2008       Sebastian Harl
+ * Copyright (C) 2008       Florian 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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Sebastian Harl <sh at tokkee.org>
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 
 /*
index 2e27415..996201a 100644 (file)
@@ -2,21 +2,26 @@
  * collectd - src/match_timediff.c
  * Copyright (C) 2008,2009  Florian 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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index ae6282c..4d49984 100644 (file)
@@ -1,22 +1,27 @@
 /**
  * collectd - src/match_value.c
- * Copyright (C) 2008  Florian Forster
+ * Copyright (C) 2008       Florian 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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 
 /*
index 90226bb..d23062d 100644 (file)
@@ -20,7 +20,7 @@
  *
  * Authors:
  *   Flavio Stanchina <flavio at stanchina.net>
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index c57a831..93dbdbc 100644 (file)
@@ -18,7 +18,7 @@
  *
  * Authors:
  *   Doug MacEachern <Doug.MacEachern at hyperic.com>
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index d739203..e2ccfee 100644 (file)
@@ -387,7 +387,7 @@ static int memcached_read (user_data_t *user_data)
 
     /*
      * For an explanation on these fields please refer to
-     * <http://code.sixapart.com/svn/memcached/trunk/server/doc/protocol.txt>
+     * <https://github.com/memcached/memcached/blob/master/doc/protocol.txt>
      */
 
     /*
@@ -437,6 +437,10 @@ static int memcached_read (user_data_t *user_data)
     {
       submit_gauge ("memcached_connections", "current", atof (fields[2]), st);
     }
+    else if (FIELD_IS ("listen_disabled_num"))
+    {
+      submit_derive ("memcached_connections", "listen_disabled", atof (fields[2]), st);
+    }
 
     /*
      * Commands
index 6a50161..c503821 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * collectd - src/memory.c
- * Copyright (C) 2005-2008  Florian octo Forster
+ * Copyright (C) 2005-2014  Florian octo Forster
  * Copyright (C) 2009       Simon Kuhnle
  * Copyright (C) 2009       Manuel Sanmartin
  *
@@ -18,7 +18,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>
  *   Simon Kuhnle <simon at blarzwurst.de>
  *   Manuel Sanmartin
  **/
@@ -84,12 +84,33 @@ static int pagesize;
 /* endif HAVE_LIBSTATGRAB */
 #elif HAVE_PERFSTAT
 static int pagesize;
-static perfstat_memory_total_t pmemory;
 /* endif HAVE_PERFSTAT */
 #else
 # error "No applicable input method."
 #endif
 
+static _Bool values_absolute = 1;
+static _Bool values_percentage = 0;
+
+static int memory_config (oconfig_item_t *ci) /* {{{ */
+{
+       int i;
+
+       for (i = 0; i < ci->children_num; i++)
+       {
+               oconfig_item_t *child = ci->children + i;
+               if (strcasecmp ("ValuesAbsolute", child->key) == 0)
+                       cf_util_get_boolean (child, &values_absolute);
+               else if (strcasecmp ("ValuesPercentage", child->key) == 0)
+                       cf_util_get_boolean (child, &values_percentage);
+               else
+                       ERROR ("memory plugin: Invalid configuration option: "
+                                       "\"%s\".", child->key);
+       }
+
+       return (0);
+} /* }}} int memory_config */
+
 static int memory_init (void)
 {
 #if HAVE_HOST_STATISTICS
@@ -134,24 +155,14 @@ static int memory_init (void)
        return (0);
 } /* int memory_init */
 
-static void memory_submit (const char *type_instance, gauge_t value)
-{
-       value_t values[1];
-       value_list_t vl = VALUE_LIST_INIT;
-
-       values[0].gauge = value;
-
-       vl.values = values;
-       vl.values_len = 1;
-       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
-       sstrncpy (vl.plugin, "memory", sizeof (vl.plugin));
-       sstrncpy (vl.type, "memory", sizeof (vl.type));
-       sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
-
-       plugin_dispatch_values (&vl);
-}
+#define MEMORY_SUBMIT(...) do { \
+       if (values_absolute) \
+               plugin_dispatch_multivalue (vl, 0, __VA_ARGS__, NULL); \
+       if (values_percentage) \
+               plugin_dispatch_multivalue (vl, 1, __VA_ARGS__, NULL); \
+} while (0)
 
-static int memory_read (void)
+static int memory_read_internal (value_list_t *vl)
 {
 #if HAVE_HOST_STATISTICS
        kern_return_t status;
@@ -200,10 +211,10 @@ static int memory_read (void)
        inactive = (gauge_t) (((uint64_t) vm_data.inactive_count) * ((uint64_t) pagesize));
        free     = (gauge_t) (((uint64_t) vm_data.free_count)     * ((uint64_t) pagesize));
 
-       memory_submit ("wired",    wired);
-       memory_submit ("active",   active);
-       memory_submit ("inactive", inactive);
-       memory_submit ("free",     free);
+       MEMORY_SUBMIT ("wired",    wired,
+                      "active",   active,
+                      "inactive", inactive,
+                      "free",     free);
 /* #endif HAVE_HOST_STATISTICS */
 
 #elif HAVE_SYSCTLBYNAME
@@ -253,11 +264,11 @@ static int memory_read (void)
                if (!isnan (sysctl_vals[i]))
                        sysctl_vals[i] *= sysctl_vals[0];
 
-       memory_submit ("free",     sysctl_vals[2]);
-       memory_submit ("wired",    sysctl_vals[3]);
-       memory_submit ("active",   sysctl_vals[4]);
-       memory_submit ("inactive", sysctl_vals[5]);
-       memory_submit ("cache",    sysctl_vals[6]);
+       MEMORY_SUBMIT ("free",     (gauge_t) sysctl_vals[2],
+                      "wired",    (gauge_t) sysctl_vals[3],
+                      "active",   (gauge_t) sysctl_vals[4],
+                      "inactive", (gauge_t) sysctl_vals[5],
+                      "cache",    (gauge_t) sysctl_vals[6]);
 /* #endif HAVE_SYSCTLBYNAME */
 
 #elif KERNEL_LINUX
@@ -267,10 +278,11 @@ static int memory_read (void)
        char *fields[8];
        int numfields;
 
-       long long mem_used = 0;
-       long long mem_buffered = 0;
-       long long mem_cached = 0;
-       long long mem_free = 0;
+       gauge_t mem_total = 0;
+       gauge_t mem_used = 0;
+       gauge_t mem_buffered = 0;
+       gauge_t mem_cached = 0;
+       gauge_t mem_free = 0;
 
        if ((fh = fopen ("/proc/meminfo", "r")) == NULL)
        {
@@ -280,12 +292,12 @@ static int memory_read (void)
                return (-1);
        }
 
-       while (fgets (buffer, 1024, fh) != NULL)
+       while (fgets (buffer, sizeof (buffer), fh) != NULL)
        {
-               long long *val = NULL;
+               gauge_t *val = NULL;
 
                if (strncasecmp (buffer, "MemTotal:", 9) == 0)
-                       val = &mem_used;
+                       val = &mem_total;
                else if (strncasecmp (buffer, "MemFree:", 8) == 0)
                        val = &mem_free;
                else if (strncasecmp (buffer, "Buffers:", 8) == 0)
@@ -295,12 +307,11 @@ static int memory_read (void)
                else
                        continue;
 
-               numfields = strsplit (buffer, fields, 8);
-
+               numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
                if (numfields < 2)
                        continue;
 
-               *val = atoll (fields[1]) * 1024LL;
+               *val = 1024.0 * atof (fields[1]);
        }
 
        if (fclose (fh))
@@ -310,19 +321,19 @@ static int memory_read (void)
                                sstrerror (errno, errbuf, sizeof (errbuf)));
        }
 
-       if (mem_used >= (mem_free + mem_buffered + mem_cached))
-       {
-               mem_used -= mem_free + mem_buffered + mem_cached;
-               memory_submit ("used",     mem_used);
-               memory_submit ("buffered", mem_buffered);
-               memory_submit ("cached",   mem_cached);
-               memory_submit ("free",     mem_free);
-       }
+       if (mem_total < (mem_free + mem_buffered + mem_cached))
+               return (-1);
+
+       mem_used = mem_total - (mem_free + mem_buffered + mem_cached);
+       MEMORY_SUBMIT ("used",     mem_used,
+                      "buffered", mem_buffered,
+                      "cached",   mem_cached,
+                      "free",     mem_free);
 /* #endif KERNEL_LINUX */
 
 #elif HAVE_LIBKSTAT
-        /* Most of the additions here were taken as-is from the k9toolkit from
-         * Brendan Gregg and are subject to change I guess */
+       /* Most of the additions here were taken as-is from the k9toolkit from
+        * Brendan Gregg and are subject to change I guess */
        long long mem_used;
        long long mem_free;
        long long mem_lock;
@@ -372,7 +383,7 @@ static int memory_read (void)
        }
 
        /* mem_kern is accounted for in mem_lock */
-       if ( pp_kernel < mem_lock )
+       if (pp_kernel < mem_lock)
        {
                mem_kern = pp_kernel;
                mem_lock -= pp_kernel;
@@ -389,16 +400,19 @@ static int memory_read (void)
        mem_kern *= pagesize; /* it's 2011 RAM is cheap */
        mem_unus *= pagesize;
 
-       memory_submit ("used",   mem_used);
-       memory_submit ("free",   mem_free);
-       memory_submit ("locked", mem_lock);
-       memory_submit ("kernel", mem_kern);
-       memory_submit ("unusable", mem_unus);
+       MEMORY_SUBMIT ("used",     (gauge_t) mem_used,
+                      "free",     (gauge_t) mem_free,
+                      "locked",   (gauge_t) mem_lock,
+                      "kernel",   (gauge_t) mem_kern,
+                      "unusable", (gauge_t) mem_unus);
 /* #endif HAVE_LIBKSTAT */
 
 #elif HAVE_SYSCTL
        int mib[] = {CTL_VM, VM_METER};
        struct vmtotal vmtotal;
+       gauge_t mem_active;
+       gauge_t mem_inactive;
+       gauge_t mem_free;
        size_t size;
 
        memset (&vmtotal, 0, sizeof (vmtotal));
@@ -412,42 +426,76 @@ static int memory_read (void)
        }
 
        assert (pagesize > 0);
-       memory_submit ("active",   vmtotal.t_arm * pagesize);
-       memory_submit ("inactive", (vmtotal.t_rm - vmtotal.t_arm) * pagesize);
-       memory_submit ("free",     vmtotal.t_free * pagesize);
+       mem_active   = (gauge_t) (vmtotal.t_arm * pagesize);
+       mem_inactive = (gauge_t) ((vmtotal.t_rm - vmtotal.t_arm) * pagesize);
+       mem_free     = (gauge_t) (vmtotal.t_free * pagesize);
+
+       MEMORY_SUBMIT ("active",   mem_active,
+                      "inactive", mem_inactive,
+                      "free",     mem_free);
 /* #endif HAVE_SYSCTL */
 
 #elif HAVE_LIBSTATGRAB
        sg_mem_stats *ios;
 
-       if ((ios = sg_get_mem_stats ()) != NULL)
-       {
-               memory_submit ("used",   ios->used);
-               memory_submit ("cached", ios->cache);
-               memory_submit ("free",   ios->free);
-       }
+       ios = sg_get_mem_stats ();
+       if (ios == NULL)
+               return (-1);
+
+       MEMORY_SUBMIT ("used",   (gauge_t) ios->used,
+                      "cached", (gauge_t) ios->cache,
+                      "free",   (gauge_t) ios->free);
 /* #endif HAVE_LIBSTATGRAB */
 
 #elif HAVE_PERFSTAT
-       if (perfstat_memory_total(NULL, &pmemory, sizeof(perfstat_memory_total_t), 1) < 0)
+       perfstat_memory_total_t pmemory;
+
+       memset (&pmemory, 0, sizeof (pmemory));
+       if (perfstat_memory_total(NULL, &pmemory, sizeof(pmemory), 1) < 0)
        {
                char errbuf[1024];
                WARNING ("memory plugin: perfstat_memory_total failed: %s",
                        sstrerror (errno, errbuf, sizeof (errbuf)));
                return (-1);
        }
-       memory_submit ("used",   pmemory.real_inuse * pagesize);
-       memory_submit ("free",   pmemory.real_free * pagesize);
-       memory_submit ("cached", pmemory.numperm * pagesize);
-       memory_submit ("system", pmemory.real_system * pagesize);
-       memory_submit ("user",   pmemory.real_process * pagesize);
+
+       /* Unfortunately, the AIX documentation is not very clear on how these
+        * numbers relate to one another. The only thing is states explcitly
+        * is:
+        *   real_total = real_process + real_free + numperm + real_system
+        *
+        * Another segmentation, which would be closer to the numbers reported
+        * by the "svmon" utility, would be:
+        *   real_total = real_free + real_inuse
+        *   real_inuse = "active" + real_pinned + numperm
+        */
+       MEMORY_SUBMIT ("free",   (gauge_t) (pmemory.real_free    * pagesize),
+                      "cached", (gauge_t) (pmemory.numperm      * pagesize),
+                      "system", (gauge_t) (pmemory.real_system  * pagesize),
+                      "user",   (gauge_t) (pmemory.real_process * pagesize));
 #endif /* HAVE_PERFSTAT */
 
        return (0);
-}
+} /* }}} int memory_read_internal */
+
+static int memory_read (void) /* {{{ */
+{
+       value_t v[1];
+       value_list_t vl = VALUE_LIST_INIT;
+
+       vl.values = v;
+       vl.values_len = STATIC_ARRAY_SIZE (v);
+       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       sstrncpy (vl.plugin, "memory", sizeof (vl.plugin));
+       sstrncpy (vl.type, "memory", sizeof (vl.type));
+       vl.time = cdtime ();
+
+       return (memory_read_internal (&vl));
+} /* }}} int memory_read */
 
 void module_register (void)
 {
+       plugin_register_complex_config ("memory", memory_config);
        plugin_register_init ("memory", memory_init);
        plugin_register_read ("memory", memory_read);
 } /* void module_register */
index ea98ba9..fb9b3d4 100644 (file)
@@ -2,21 +2,26 @@
  * collectd - src/meta_data.c
  * Copyright (C) 2008-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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index f1af40e..fa48df3 100644 (file)
@@ -2,21 +2,26 @@
  * collectd - src/meta_data.h
  * Copyright (C) 2008-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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #ifndef META_DATA_H
index d15a055..7d5eddd 100644 (file)
 #include <mysql/mysql.h>
 #endif
 
-/* TODO: Understand `Select_*' and possibly do that stuff as well.. */
-
 struct mysql_database_s /* {{{ */
 {
        char *instance;
+       char *alias;
        char *host;
        char *user;
        char *pass;
        char *database;
        char *socket;
        int   port;
+       int   timeout;
 
        _Bool master_stats;
        _Bool slave_stats;
+       _Bool innodb_stats;
 
        _Bool slave_notif;
        _Bool slave_io_running;
@@ -64,6 +65,9 @@ typedef struct mysql_database_s mysql_database_t; /* }}} */
 
 static int mysql_read (user_data_t *ud);
 
+void mysql_read_default_options(struct st_mysql_options *options,
+               const char *filename,const char *group);
+
 static void mysql_database_free (void *arg) /* {{{ */
 {
        mysql_database_t *db;
@@ -78,6 +82,7 @@ static void mysql_database_free (void *arg) /* {{{ */
        if (db->con != NULL)
                mysql_close (db->con);
 
+       sfree (db->alias);
        sfree (db->host);
        sfree (db->user);
        sfree (db->pass);
@@ -120,12 +125,14 @@ static int mysql_config_database (oconfig_item_t *ci) /* {{{ */
        memset (db, 0, sizeof (*db));
 
        /* initialize all the pointers */
+       db->alias    = NULL;
        db->host     = NULL;
        db->user     = NULL;
        db->pass     = NULL;
        db->database = NULL;
        db->socket   = NULL;
        db->con      = NULL;
+       db->timeout  = 0;
 
        /* trigger a notification, if it's not running */
        db->slave_io_running  = 1;
@@ -144,7 +151,9 @@ static int mysql_config_database (oconfig_item_t *ci) /* {{{ */
        {
                oconfig_item_t *child = ci->children + i;
 
-               if (strcasecmp ("Host", child->key) == 0)
+               if (strcasecmp ("Alias", child->key) == 0)
+                       status = cf_util_get_string (child, &db->alias);
+               else if (strcasecmp ("Host", child->key) == 0)
                        status = cf_util_get_string (child, &db->host);
                else if (strcasecmp ("User", child->key) == 0)
                        status = cf_util_get_string (child, &db->user);
@@ -163,12 +172,16 @@ static int mysql_config_database (oconfig_item_t *ci) /* {{{ */
                        status = cf_util_get_string (child, &db->socket);
                else if (strcasecmp ("Database", child->key) == 0)
                        status = cf_util_get_string (child, &db->database);
+               else if (strcasecmp ("ConnectTimeout", child->key) == 0)
+                       status = cf_util_get_int (child, &db->timeout);
                else if (strcasecmp ("MasterStats", child->key) == 0)
                        status = cf_util_get_boolean (child, &db->master_stats);
                else if (strcasecmp ("SlaveStats", child->key) == 0)
                        status = cf_util_get_boolean (child, &db->slave_stats);
                else if (strcasecmp ("SlaveNotifications", child->key) == 0)
                        status = cf_util_get_boolean (child, &db->slave_notif);
+               else if (strcasecmp ("InnodbStats", child->key) == 0)
+                       status = cf_util_get_boolean (child, &db->innodb_stats);
                else
                {
                        WARNING ("mysql plugin: Option `%s' not allowed here.", child->key);
@@ -261,6 +274,9 @@ static MYSQL *getconnection (mysql_database_t *db)
                }
        }
 
+       /* Configure TCP connect timeout (default: 0) */
+       db->con->options.connect_timeout = db->timeout;
+
        if (mysql_real_connect (db->con, db->host, db->user, db->pass,
                                db->database, db->port, db->socket, 0) == NULL)
        {
@@ -285,8 +301,11 @@ static MYSQL *getconnection (mysql_database_t *db)
 
 static void set_host (mysql_database_t *db, char *buf, size_t buflen)
 {
-       if ((db->host == NULL)
+       if (db->alias)
+               sstrncpy (buf, db->alias, buflen);
+       else if ((db->host == NULL)
                        || (strcmp ("", db->host) == 0)
+                       || (strcmp ("127.0.0.1", db->host) == 0)
                        || (strcmp ("localhost", db->host) == 0))
                sstrncpy (buf, hostname_g, buflen);
        else
@@ -661,6 +680,72 @@ static int mysql_read (user_data_t *ud)
                                        key + strlen ("Table_locks_"),
                                        val, db);
                }
+               else if (db->innodb_stats && strncmp (key, "Innodb_", strlen ("Innodb_")) == 0)
+               {
+                       /* buffer pool */
+                       if (strcmp (key, "Innodb_buffer_pool_pages_data") == 0)
+                               gauge_submit ("mysql_bpool_pages", "data", val, db);
+                       else if (strcmp (key, "Innodb_buffer_pool_pages_dirty") == 0)
+                               gauge_submit ("mysql_bpool_pages", "dirty", val, db);
+                       else if (strcmp (key, "Innodb_buffer_pool_pages_flushed") == 0)
+                               counter_submit ("mysql_bpool_counters", "flushed", val, db);
+                       else if (strcmp (key, "Innodb_buffer_pool_pages_free") == 0)
+                               gauge_submit ("mysql_bpool_pages", "free", val, db);
+                       else if (strcmp (key, "Innodb_buffer_pool_pages_misc") == 0)
+                               gauge_submit ("mysql_bpool_pages", "misc", val, db);
+                       else if (strcmp (key, "Innodb_buffer_pool_pages_total") == 0)
+                               gauge_submit ("mysql_bpool_pages", "total", val, db);
+                       else if (strcmp (key, "Innodb_buffer_pool_read_ahead_rnd") == 0)
+                               counter_submit ("mysql_bpool_counters", "read_ahead_rnd", val, db);
+                       else if (strcmp (key, "Innodb_buffer_pool_read_ahead") == 0)
+                               counter_submit ("mysql_bpool_counters", "read_ahead", val, db);
+                       else if (strcmp (key, "Innodb_buffer_pool_read_ahead_evicted") == 0)
+                               counter_submit ("mysql_bpool_counters", "read_ahead_evicted", val, db);
+                       else if (strcmp (key, "Innodb_buffer_pool_read_requests") == 0)
+                               counter_submit ("mysql_bpool_counters", "read_requests", val, db);
+                       else if (strcmp (key, "Innodb_buffer_pool_reads") == 0)
+                               counter_submit ("mysql_bpool_counters", "reads", val, db);
+                       else if (strcmp (key, "Innodb_buffer_pool_write_requests") == 0)
+                               counter_submit ("mysql_bpool_counters", "write_requests", val, db);
+
+                       /* data */
+                       if (strcmp (key, "Innodb_data_fsyncs") == 0)
+                               counter_submit ("mysql_innodb_data", "fsyncs", val, db);
+                       else if (strcmp (key, "Innodb_data_read") == 0)
+                               counter_submit ("mysql_innodb_data", "read", val, db);
+                       else if (strcmp (key, "Innodb_data_reads") == 0)
+                               counter_submit ("mysql_innodb_data", "reads", val, db);
+                       else if (strcmp (key, "Innodb_data_writes") == 0)
+                               counter_submit ("mysql_bpool_counters", "writes", val, db);
+                       else if (strcmp (key, "Innodb_data_written") == 0)
+                               counter_submit ("mysql_innodb_data", "written", val, db);
+
+                       /* double write */
+                       else if (strcmp (key, "Innodb_dblwr_writes") == 0)
+                               counter_submit ("mysql_innodb_dblwr", "writes", val, db);
+                       else if (strcmp (key, "Innodb_dblwr_pages_written") == 0)
+                               counter_submit ("mysql_innodb_dblwr", "written", val, db);
+
+                       /* rows */
+                       else if (strcmp (key, "Innodb_rows_deleted") == 0)
+                               counter_submit ("mysql_innodb_rows", "deleted", val, db);
+                       else if (strcmp (key, "Innodb_rows_inserted") == 0)
+                               counter_submit ("mysql_innodb_rows", "inserted", val, db);
+                       else if (strcmp (key, "Innodb_rows_read") == 0)
+                               counter_submit ("mysql_innodb_rows", "read", val, db);
+                       else if (strcmp (key, "Innodb_rows_updated") == 0)
+                               counter_submit ("mysql_innodb_rows", "updated", val, db);
+               }
+               else if (strncmp (key, "Select_", strlen ("Select_")) == 0)
+               {
+                       counter_submit ("mysql_select", key + strlen ("Select_"),
+                                       val, db);
+               }
+               else if (strncmp (key, "Sort_", strlen ("Sort_")) == 0)
+               {
+                       counter_submit ("mysql_sort", key + strlen ("Sort_"),
+                                       val, db);
+               }
        }
        mysql_free_result (res); res = NULL;
 
index 422dc8c..de2de9b 100644 (file)
 
 #include <libmnl/libmnl.h>
 
+struct ir_link_stats_storage_s {
+
+  uint64_t rx_packets;
+  uint64_t tx_packets;
+  uint64_t rx_bytes;
+  uint64_t tx_bytes;
+  uint64_t rx_errors;
+  uint64_t tx_errors;
+
+  uint64_t rx_dropped;
+  uint64_t tx_dropped;
+  uint64_t multicast;
+  uint64_t collisions;
+
+  uint64_t rx_length_errors;
+  uint64_t rx_over_errors;
+  uint64_t rx_crc_errors;
+  uint64_t rx_frame_errors;
+  uint64_t rx_fifo_errors;
+  uint64_t rx_missed_errors;
+
+  uint64_t tx_aborted_errors;
+  uint64_t tx_carrier_errors;
+  uint64_t tx_fifo_errors;
+  uint64_t tx_heartbeat_errors;
+  uint64_t tx_window_errors;
+};
+
+union ir_link_stats_u {
+  struct rtnl_link_stats *stats32;
+#ifdef HAVE_RTNL_LINK_STATS64
+  struct rtnl_link_stats64 *stats64;
+#endif
+};
+
 typedef struct ir_ignorelist_s
 {
   char *device;
@@ -235,7 +270,7 @@ static int update_iflist (struct ifinfomsg *msg, const char *dev)
 } /* int update_iflist */
 
 static void check_ignorelist_and_submit (const char *dev,
-    struct rtnl_link_stats *stats)
+    struct ir_link_stats_storage_s *stats)
 {
 
   if (check_ignorelist (dev, "interface", NULL) == 0)
@@ -275,13 +310,61 @@ static void check_ignorelist_and_submit (const char *dev,
 
 } /* void check_ignorelist_and_submit */
 
+#define COPY_RTNL_LINK_VALUE(dst_stats, src_stats, value_name) \
+  (dst_stats)->value_name = (src_stats)->value_name
+
+#define COPY_RTNL_LINK_STATS(dst_stats, src_stats) \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, rx_packets); \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, tx_packets); \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, rx_bytes); \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, tx_bytes); \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, rx_errors); \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, tx_errors); \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, rx_dropped); \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, tx_dropped); \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, multicast); \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, collisions); \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, rx_length_errors); \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, rx_over_errors); \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, rx_crc_errors); \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, rx_frame_errors); \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, rx_fifo_errors); \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, rx_missed_errors); \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, tx_aborted_errors); \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, tx_carrier_errors); \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, tx_fifo_errors); \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, tx_heartbeat_errors); \
+  COPY_RTNL_LINK_VALUE (dst_stats, src_stats, tx_window_errors)
+
+#ifdef HAVE_RTNL_LINK_STATS64
+static void check_ignorelist_and_submit64 (const char *dev,
+    struct rtnl_link_stats64 *stats)
+{
+  struct ir_link_stats_storage_s s;
+
+  COPY_RTNL_LINK_STATS (&s, stats);
+
+  check_ignorelist_and_submit (dev, &s);
+}
+#endif
+
+static void check_ignorelist_and_submit32 (const char *dev,
+    struct rtnl_link_stats *stats)
+{
+  struct ir_link_stats_storage_s s;
+
+  COPY_RTNL_LINK_STATS(&s, stats);
+
+  check_ignorelist_and_submit (dev, &s);
+}
+
 static int link_filter_cb (const struct nlmsghdr *nlh,
     void *args __attribute__((unused)))
 {
   struct ifinfomsg *ifm = mnl_nlmsg_get_payload (nlh);
   struct nlattr *attr;
-  struct rtnl_link_stats *stats = NULL;
   const char *dev = NULL;
+  union ir_link_stats_u stats;
 
   if (nlh->nlmsg_type != RTM_NEWLINK)
   {
@@ -313,30 +396,44 @@ static int link_filter_cb (const struct nlmsghdr *nlh,
     ERROR ("netlink plugin: link_filter_cb: dev == NULL");
     return MNL_CB_ERROR;
   }
+#ifdef HAVE_RTNL_LINK_STATS64
+  mnl_attr_for_each (attr, nlh, sizeof (*ifm))
+  {
+    if (mnl_attr_get_type (attr) != IFLA_STATS64)
+      continue;
+
+    if (mnl_attr_validate2 (attr, MNL_TYPE_UNSPEC, sizeof (*stats.stats64)) < 0)
+    {
+      ERROR ("netlink plugin: link_filter_cb: IFLA_STATS64 mnl_attr_validate2 failed.");
+      return MNL_CB_ERROR;
+    }
+    stats.stats64 = mnl_attr_get_payload (attr);
+
+    check_ignorelist_and_submit64 (dev, stats.stats64);
 
+    return MNL_CB_OK;
+  }
+#endif
   mnl_attr_for_each (attr, nlh, sizeof (*ifm))
   {
     if (mnl_attr_get_type (attr) != IFLA_STATS)
       continue;
 
-    if (mnl_attr_validate2 (attr, MNL_TYPE_UNSPEC, sizeof (*stats)) < 0)
+    if (mnl_attr_validate2 (attr, MNL_TYPE_UNSPEC, sizeof (*stats.stats32)) < 0)
     {
       ERROR ("netlink plugin: link_filter_cb: IFLA_STATS mnl_attr_validate2 failed.");
       return MNL_CB_ERROR;
     }
-    stats = mnl_attr_get_payload (attr);
+    stats.stats32 = mnl_attr_get_payload (attr);
 
-    check_ignorelist_and_submit (dev, stats);
-    break;
-  }
+    check_ignorelist_and_submit32 (dev, stats.stats32);
 
-  if (stats == NULL)
-  {
-    DEBUG ("netlink plugin: link_filter: No statistics for interface %s.", dev);
     return MNL_CB_OK;
   }
 
+  DEBUG ("netlink plugin: link_filter: No statistics for interface %s.", dev);
   return MNL_CB_OK;
+
 } /* int link_filter_cb */
 
 #if HAVE_TCA_STATS2
index 1b6cf1e..b191983 100644 (file)
@@ -2904,6 +2904,10 @@ static int network_config_set_ttl (const oconfig_item_t *ci) /* {{{ */
   tmp = (int) ci->values[0].value.number;
   if ((tmp > 0) && (tmp <= 255))
     network_config_ttl = tmp;
+  else {
+    WARNING ("network plugin: The `TimeToLive' must be between 1 and 255.");
+    return (-1);    
+  }
 
   return (0);
 } /* }}} int network_config_set_ttl */
@@ -3166,6 +3170,14 @@ static int network_config (oconfig_item_t *ci) /* {{{ */
 {
   int i;
 
+  /* The options need to be applied first */
+  for (i = 0; i < ci->children_num; i++)
+  {
+    oconfig_item_t *child = ci->children + i;
+    if (strcasecmp ("TimeToLive", child->key) == 0)
+      network_config_set_ttl (child);
+  }
+
   for (i = 0; i < ci->children_num; i++)
   {
     oconfig_item_t *child = ci->children + i;
@@ -3174,8 +3186,9 @@ static int network_config (oconfig_item_t *ci) /* {{{ */
       network_config_add_listen (child);
     else if (strcasecmp ("Server", child->key) == 0)
       network_config_add_server (child);
-    else if (strcasecmp ("TimeToLive", child->key) == 0)
-      network_config_set_ttl (child);
+    else if (strcasecmp ("TimeToLive", child->key) == 0) {
+      /* Handled earlier */
+    }
     else if (strcasecmp ("MaxPacketSize", child->key) == 0)
       network_config_set_buffer_size (child);
     else if (strcasecmp ("Forward", child->key) == 0)
index 1b35456..5457722 100644 (file)
@@ -2,21 +2,26 @@
  * collectd - src/network.h
  * Copyright (C) 2005-2008  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #ifndef NETWORK_H
index de52262..e8282f2 100644 (file)
@@ -3,19 +3,23 @@
  * Copyright (C) 2006-2010  Florian octo Forster
  * Copyright (C) 2008       Sebastian Harl
  *
- * 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; either version 2 of the License, or (at your
- * option) any later version.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <octo at collectd.org>
@@ -122,7 +126,7 @@ static int init (void)
 
   curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1L);
   curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, nginx_curl_callback);
-  curl_easy_setopt (curl, CURLOPT_USERAGENT, PACKAGE_NAME"/"PACKAGE_VERSION);
+  curl_easy_setopt (curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
   curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, nginx_curl_error);
 
   if (user != NULL)
index 3f3c6df..c2d9752 100644 (file)
@@ -1,21 +1,26 @@
 /**
  * collectd - src/notify_desktop.c
- * Copyright (C) 2008  Sebastian Harl
+ * Copyright (C) 2008       Sebastian Harl
  *
- * 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.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
+ * Authors:
  *   Sebastian Harl <sh at tokkee.org>
  **/
 
index bbc455f..6bed82c 100644 (file)
@@ -2,18 +2,23 @@
  * collectd - src/ntpd.c
  * Copyright (C) 2006-2012  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <octo at collectd.org>
index 4b4ef20..a87a17e 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * collectd - src/numa.c
- * Copyright (C) 2012  Florian Forster
+ * Copyright (C) 2012       Florian Forster
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
index edc48c6..d5ecc98 100644 (file)
--- a/src/nut.c
+++ b/src/nut.c
@@ -1,22 +1,27 @@
 /**
  * collectd - src/nut.c
- * Copyright (C) 2007  Florian octo Forster
+ * Copyright (C) 2007       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index be422ab..6d0576c 100644 (file)
@@ -1,22 +1,27 @@
 /**
  * collectd - src/olsrd.c
- * Copyright (C) 2009  Florian octo Forster
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index 09a6bf0..1383fc5 100644 (file)
@@ -1,6 +1,6 @@
 /**
- * collectd - src/owfs.c
- * Copyright (C) 2008  Florian octo Forster
+ * collectd - src/onewire.c
+ * Copyright (C) 2008  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
@@ -24,6 +24,9 @@
 #include "plugin.h"
 #include "utils_ignorelist.h"
 
+#include <sys/time.h>
+#include <sys/types.h>
+#include <regex.h>
 #include <owcapi.h>
 
 #define OW_FAMILY_LENGTH 8
@@ -41,10 +44,18 @@ struct ow_family_features_s
 };
 typedef struct ow_family_features_s ow_family_features_t;
 
+/* internal timing info collected in debug version only */
+#if COLLECT_DEBUG
+static struct timeval tv_begin, tv_end, tv_diff;
+#endif /* COLLECT_DEBUG */
+
+/* regexp to extract address (without family) and file from the owfs path */
+static const char *regexp_to_match = "[A-Fa-f0-9]{2}\\.([A-Fa-f0-9]{12})/([[:alnum:]]+)$";
+
 /* see http://owfs.sourceforge.net/ow_table.html for a list of families */
 static ow_family_features_t ow_family_features[] =
 {
-  {
+  { /* DS18S20 Precision Thermometer and DS1920 ibutton */
     /* family = */ "10.",
     {
       {
@@ -54,12 +65,57 @@ static ow_family_features_t ow_family_features[] =
       }
     },
     /* features_num = */ 1
+  },
+  { /* DS1822 Econo Thermometer */
+    /* family = */ "22.",
+    {
+      {
+        /* filename = */ "temperature",
+        /* type = */ "temperature",
+        /* type_instance = */ ""
+      }
+    },
+    /* features_num = */ 1
+  },
+  { /* DS18B20 Programmable Resolution Thermometer */
+    /* family = */ "28.",
+    {
+      {
+        /* filename = */ "temperature",
+        /* type = */ "temperature",
+        /* type_instance = */ ""
+      }
+    },
+    /* features_num = */ 1
+  },
+  { /* DS2436 Volts/Temp */
+    /* family = */ "1B.",
+    {
+      {
+        /* filename = */ "temperature",
+        /* type = */ "temperature",
+        /* type_instance = */ ""
+      }
+    },
+    /* features_num = */ 1
+  },
+  { /* DS2438 Volts/Temp */
+    /* family = */ "26.",
+    {
+      {
+        /* filename = */ "temperature",
+        /* type = */ "temperature",
+        /* type_instance = */ ""
+      }
+    },
+    /* features_num = */ 1
   }
 };
 static int ow_family_features_num = STATIC_ARRAY_SIZE (ow_family_features);
 
 static char *device_g = NULL;
 static cdtime_t ow_interval = 0;
+static _Bool direct_access = 0;
 
 static const char *config_keys[] =
 {
@@ -72,6 +128,152 @@ static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
 
 static ignorelist_t *sensor_list;
 
+static _Bool   regex_direct_initialized = 0;
+static regex_t regex_direct;
+
+/**
+ * List of onewire owfs "files" to be directly read
+ */
+typedef struct direct_access_element_s
+{
+       char *path;                 /**< The whole owfs path */
+    char *address;              /**< 1-wire address without family */
+    char *file;                 /**< owfs file - e.g. temperature */
+       struct direct_access_element_s *next; /**< Next in the list */
+} direct_access_element_t;
+
+static direct_access_element_t * direct_list = NULL;
+
+/* =================================================================================== */
+
+#if COLLECT_DEBUG
+/* Return 1 if the difference is negative, otherwise 0.  */
+static int timeval_subtract(struct timeval *result, struct timeval *t2, struct timeval *t1)
+{
+    long int diff = (t2->tv_usec + 1000000 * t2->tv_sec) - (t1->tv_usec + 1000000 * t1->tv_sec);
+    result->tv_sec = diff / 1000000;
+    result->tv_usec = diff % 1000000;
+
+    return (diff<0);
+}
+#endif /* COLLECT_DEBUG */
+
+/* =================================================================================== */
+
+static void direct_list_element_free(direct_access_element_t *el)
+{
+    if (el != NULL)
+    {
+        DEBUG ("onewire plugin: direct_list_element_free - deleting <%s>", el->path);
+        sfree (el->path);
+        sfree (el->address);
+        sfree (el->file);
+        free (el);
+    }
+}
+
+static int direct_list_insert(const char * config)
+{
+    regmatch_t               pmatch[3];
+    size_t                   nmatch = 3;
+    direct_access_element_t *element = NULL;
+
+    DEBUG ("onewire plugin: direct_list_insert <%s>", config);
+
+    element = (direct_access_element_t *) malloc (sizeof(*element));
+    if (element == NULL)
+    {
+        ERROR ("onewire plugin: direct_list_insert - cannot allocate element");
+        return 1;
+    }
+    element->path    = NULL;
+    element->address = NULL;
+    element->file    = NULL;
+
+    element->path = strdup (config);
+    if (element->path == NULL)
+    {
+        ERROR ("onewire plugin: direct_list_insert - cannot allocate path");
+        direct_list_element_free (element);
+        return 1;
+    }
+
+    DEBUG ("onewire plugin: direct_list_insert - about to match %s", config);
+
+    if (!regex_direct_initialized)
+    {
+        if (regcomp (&regex_direct, regexp_to_match, REG_EXTENDED))
+        {
+            ERROR ("onewire plugin: Cannot compile regex");
+            direct_list_element_free (element);
+            return (1);
+        }
+        regex_direct_initialized = 1;
+        DEBUG ("onewire plugin: Compiled regex!!");
+    }
+
+    if (regexec (&regex_direct, config, nmatch, pmatch, 0))
+    {
+        ERROR ("onewire plugin: direct_list_insert - no regex  match");
+        direct_list_element_free (element);
+        return 1;
+    }
+
+    if (pmatch[1].rm_so<0)
+    {
+        ERROR ("onewire plugin: direct_list_insert - no address regex match");
+        direct_list_element_free (element);
+        return 1;
+    }
+    element->address = strndup (config+pmatch[1].rm_so,
+                                pmatch[1].rm_eo - pmatch[1].rm_so);
+    if (element->address == NULL)
+    {
+        ERROR ("onewire plugin: direct_list_insert - cannot allocate address");
+        direct_list_element_free (element);
+        return 1;
+    }
+    DEBUG ("onewire plugin: direct_list_insert - found address <%s>",
+           element->address);
+
+    if (pmatch[2].rm_so<0)
+    {
+        ERROR ("onewire plugin: direct_list_insert - no file regex match");
+        direct_list_element_free (element);
+        return 1;
+    }
+    element->file = strndup (config+pmatch[2].rm_so,
+                             pmatch[2].rm_eo - pmatch[2].rm_so);
+    if (element->file == NULL)
+    {
+        ERROR ("onewire plugin: direct_list_insert - cannot allocate file");
+        direct_list_element_free (element);
+        return 1;
+    }
+    DEBUG ("onewire plugin: direct_list_insert - found file <%s>", element->file);
+
+    element->next = direct_list;
+    direct_list = element;
+
+    return 0;
+}
+
+static void direct_list_free(void)
+{
+    direct_access_element_t *traverse = direct_list;
+    direct_access_element_t *tmp = NULL;;
+
+    while(traverse != NULL)
+    {
+        tmp = traverse;
+        traverse = traverse->next;
+        direct_list_element_free (tmp);
+        tmp = NULL;
+    }
+}
+
+/* =================================================================================== */
+
 static int cow_load_config (const char *key, const char *value)
 {
   if (sensor_list == NULL)
@@ -79,11 +281,20 @@ static int cow_load_config (const char *key, const char *value)
 
   if (strcasecmp (key, "Sensor") == 0)
   {
-    if (ignorelist_add (sensor_list, value))
+    if (direct_list_insert (value))
     {
-      ERROR ("sensors plugin: "
-          "Cannot add value to ignorelist.");
-      return (1);
+        DEBUG ("onewire plugin: Cannot add %s to direct_list_insert.", value);
+
+        if (ignorelist_add (sensor_list, value))
+        {
+            ERROR ("onewire plugin: Cannot add value to ignorelist.");
+            return (1);
+        }
+    }
+    else
+    {
+        DEBUG ("onewire plugin: %s is a direct access", value);
+        direct_access = 1;
     }
   }
   else if (strcasecmp (key, "IgnoreSelected") == 0)
@@ -158,6 +369,7 @@ static int cow_read_values (const char *path, const char *name,
 
     buffer = NULL;
     buffer_size = 0;
+    DEBUG ("Start reading onewire device %s", file);
     status = OW_get (file, &buffer, &buffer_size);
     if (status < 0)
     {
@@ -165,6 +377,7 @@ static int cow_read_values (const char *path, const char *name,
           path, family_info->features[i].filename, status);
       return (-1);
     }
+    DEBUG ("Read onewire device %s as %s", file, buffer);
 
     endptr = NULL;
     values[0].gauge = strtod (buffer, &endptr);
@@ -276,16 +489,104 @@ static int cow_read_bus (const char *path)
   return (0);
 } /* int cow_read_bus */
 
+
+/* =================================================================================== */
+
+static int cow_simple_read (void)
+{
+  value_t      values[1];
+  value_list_t vl = VALUE_LIST_INIT;
+  char        *buffer;
+  size_t       buffer_size;
+  int          status;
+  char        *endptr;
+  direct_access_element_t *traverse;
+
+  /* traverse list and check entries */
+  for (traverse = direct_list; traverse != NULL; traverse = traverse->next)
+  {
+      vl.values = values;
+      vl.values_len = 1;
+
+      sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+      sstrncpy (vl.plugin, "onewire", sizeof (vl.plugin));
+      sstrncpy (vl.plugin_instance, traverse->address, sizeof (vl.plugin_instance));
+
+      status = OW_get (traverse->path, &buffer, &buffer_size);
+      if (status < 0)
+      {
+          ERROR ("onewire plugin: OW_get (%s) failed. status = %#x;",
+                 traverse->path,
+                 status);
+          return (-1);
+      }
+      DEBUG ("onewire plugin: Read onewire device %s as %s", traverse->path, buffer);
+
+
+      endptr = NULL;
+      values[0].gauge = strtod (buffer, &endptr);
+      if (endptr == NULL)
+      {
+          ERROR ("onewire plugin: Buffer is not a number: %s", buffer);
+          status = -1;
+          continue;
+      }
+
+      sstrncpy (vl.type, traverse->file, sizeof (vl.type));
+      sstrncpy (vl.type_instance, "",   sizeof (""));
+
+      plugin_dispatch_values (&vl);
+      free (buffer);
+  } /* for (traverse) */
+
+  return 0;
+} /* int cow_simple_read */
+
+/* =================================================================================== */
+
 static int cow_read (user_data_t *ud __attribute__((unused)))
 {
-  return (cow_read_bus ("/"));
+    int result=0;
+
+#if COLLECT_DEBUG
+    gettimeofday (&tv_begin, NULL);
+#endif /* COLLECT_DEBUG */
+
+    if (direct_access)
+    {
+        DEBUG ("onewire plugin: Direct access read");
+        result = cow_simple_read ();
+    }
+    else
+    {
+        DEBUG ("onewire plugin: Standard access read");
+        result = cow_read_bus ("/");
+    }
+
+#if COLLECT_DEBUG
+    gettimeofday (&tv_end, NULL);
+    timeval_subtract (&tv_diff, &tv_end, &tv_begin);
+    DEBUG ("onewire plugin: Onewire read took us %ld.%06ld s",
+           tv_diff.tv_sec,
+           tv_diff.tv_usec);
+#endif /* COLLECT_DEBUG */
+
+    return result;
 } /* int cow_read */
 
 static int cow_shutdown (void)
 {
-  OW_finish ();
-  ignorelist_free (sensor_list);
-  return (0);
+    OW_finish ();
+    ignorelist_free (sensor_list);
+
+    direct_list_free ();
+
+    if (regex_direct_initialized)
+    {
+        regfree(&regex_direct);
+    }
+
+    return (0);
 } /* int cow_shutdown */
 
 static int cow_init (void)
@@ -299,6 +600,7 @@ static int cow_init (void)
     return (-1);
   }
 
+  DEBUG ("onewire plugin: about to init device <%s>.", device_g);
   status = (int) OW_init (device_g);
   if (status != 0)
   {
@@ -320,7 +622,7 @@ void module_register (void)
 {
   plugin_register_init ("onewire", cow_init);
   plugin_register_config ("onewire", cow_load_config,
-    config_keys, config_keys_num);
+                          config_keys, config_keys_num);
 }
 
 /* vim: set sw=2 sts=2 ts=8 et fdm=marker cindent : */
index 9ce23b4..6d89b37 100644 (file)
@@ -32,6 +32,7 @@
 #define V1STRING "Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since\n"
 #define V2STRING "HEADER,CLIENT_LIST,Common Name,Real Address,Virtual Address,Bytes Received,Bytes Sent,Connected Since,Connected Since (time_t)\n"
 #define V3STRING "HEADER CLIENT_LIST Common Name Real Address Virtual Address Bytes Received Bytes Sent Connected Since Connected Since (time_t)\n"
+#define V4STRING "HEADER,CLIENT_LIST,Common Name,Real Address,Virtual Address,Bytes Received,Bytes Sent,Connected Since,Connected Since (time_t),Username\n"
 #define VSSTRING "OpenVPN STATISTICS\n"
 
 
@@ -43,6 +44,7 @@ struct vpn_status_s
                MULTI1 = 1, /* status-version 1 */
                MULTI2,     /* status-version 2 */
                MULTI3,     /* status-version 3 */
+               MULTI4,     /* status-version 4 */
                SINGLE = 10 /* currently no versions for single mode, maybe in the future */
        } version;
        char *name;
@@ -452,13 +454,77 @@ static int multi3_read (char *name, FILE *fh)
        return (read);
 } /* int multi3_read */
 
+/* for reading status version 4 */
+static int multi4_read (char *name, FILE *fh)
+{
+       char buffer[1024];
+       char *fields[11];
+       const int max_fields = STATIC_ARRAY_SIZE (fields);
+       int  fields_num, read = 0;
+       long long sum_users    = 0;
+
+       while (fgets (buffer, sizeof (buffer), fh) != NULL)
+       {
+               fields_num = openvpn_strsplit (buffer, fields, max_fields);
+
+               /* status file is generated by openvpn/multi.c:multi_print_status()
+                * http://svn.openvpn.net/projects/openvpn/trunk/openvpn/multi.c
+                *
+                * The line we're expecting has 9 fields. We ignore all lines
+                *  with more or less fields.
+                */
+               if (fields_num != 9)
+                       continue;
+
+
+               if (strcmp (fields[0], "CLIENT_LIST") != 0)
+                       continue;
+
+
+               if (collect_user_count)
+                       /* If so, sum all users, ignore the individuals*/
+               {
+                       sum_users += 1;
+               }
+               if (collect_individual_users)
+               {
+                       if (new_naming_schema)
+                       {
+                               /* plugin inst = file name, type inst = fields[1] */
+                               iostats_submit (name,               /* vpn instance */
+                                               fields[1],          /* "Common Name" */
+                                               atoll (fields[4]),  /* "Bytes Received" */
+                                               atoll (fields[5])); /* "Bytes Sent" */
+                       }
+                       else
+                       {
+                               /* plugin inst = fields[1], type inst = "" */
+                               iostats_submit (fields[1],          /* "Common Name" */
+                                               NULL,               /* unused when in multimode */
+                                               atoll (fields[4]),  /* "Bytes Received" */
+                                               atoll (fields[5])); /* "Bytes Sent" */
+                       }
+               }
+
+               read = 1;
+       }
+
+       if (collect_user_count)
+       {
+               numusers_submit(name, name, sum_users);
+               read = 1;
+       }
+
+       return (read);
+} /* int multi4_read */
+
 /* read callback */
 static int openvpn_read (void)
 {
        FILE *fh;
-       int  i, read;
+       int  i, vpn_read, read;
 
-       read = 0;
+       vpn_read = read = 0;
 
        /* call the right read function for every status entry in the list */
        for (i = 0; i < vpn_num; i++)
@@ -476,23 +542,28 @@ static int openvpn_read (void)
                switch (vpn_list[i]->version)
                {
                        case SINGLE:
-                               read = single_read(vpn_list[i]->name, fh);
+                               vpn_read = single_read(vpn_list[i]->name, fh);
                                break;
 
                        case MULTI1:
-                               read = multi1_read(vpn_list[i]->name, fh);
+                               vpn_read = multi1_read(vpn_list[i]->name, fh);
                                break;
 
                        case MULTI2:
-                               read = multi2_read(vpn_list[i]->name, fh);
+                               vpn_read = multi2_read(vpn_list[i]->name, fh);
                                break;
 
                        case MULTI3:
-                               read = multi3_read(vpn_list[i]->name, fh);
+                               vpn_read = multi3_read(vpn_list[i]->name, fh);
+                               break;
+
+                       case MULTI4:
+                               vpn_read = multi4_read(vpn_list[i]->name, fh);
                                break;
                }
 
                fclose (fh);
+               read += vpn_read;
        }
 
        return (read ? 0 : -1);
@@ -549,6 +620,13 @@ static int version_detect (const char *filename)
                        version = MULTI3;
                        break;
                }
+               /* searching for multi version 4 */
+               else if (strcmp (buffer, V4STRING) == 0)
+               {
+                       DEBUG ("openvpn plugin: found status file version MULTI4");
+                       version = MULTI4;
+                       break;
+               }
        }
 
        if (version == 0)
index 78e508a..5b9a483 100644 (file)
@@ -2,20 +2,25 @@
  * collectd - src/perl.c
  * Copyright (C) 2007-2009  Sebastian Harl
  *
- * 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.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
+ * Authors:
  *   Sebastian Harl <sh at tokkee.org>
  **/
 
index 44f0c7b..29f3a3d 100644 (file)
--- a/src/pf.c
+++ b/src/pf.c
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2010 Pierre-Yves Ritschard <pyr@openbsd.org>
- * Copyright (c) 2011 Stefan Rinkes <stefan.rinkes@gmail.org>
+ * Copyright (c) 2010 Pierre-Yves Ritschard
+ * Copyright (c) 2011 Stefan Rinkes
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors:
+ *   Pierre-Yves Ritschard <pyr at openbsd.org>
+ *   Stefan Rinkes <stefan.rinkes at gmail.org>
  */
 
 #include "collectd.h"
index e7bf2aa..9f0a800 100644 (file)
@@ -20,7 +20,7 @@
  * Authors:
  *   Antony Dovgal <tony at daylessday.org>
  *   Phoenix Kayo <kayo.k11.4 at gmail.com>
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index 8bbb807..216feda 100644 (file)
@@ -2,18 +2,23 @@
  * collectd - src/ping.c
  * Copyright (C) 2005-2012  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <octo at collectd.org>
index 6c7aa05..30a1ff1 100644 (file)
@@ -1,19 +1,24 @@
 /**
  * collectd - src/plugin.c
- * Copyright (C) 2005-2013  Florian octo Forster
+ * Copyright (C) 2005-2014  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <octo at collectd.org>
@@ -2089,6 +2094,65 @@ int plugin_dispatch_values (value_list_t const *vl)
        return (0);
 }
 
+__attribute__((sentinel))
+int plugin_dispatch_multivalue (value_list_t const *template, /* {{{ */
+               _Bool store_percentage, ...)
+{
+       value_list_t *vl;
+       int failed = 0;
+       gauge_t sum = 0.0;
+       va_list ap;
+
+       assert (template->values_len == 1);
+
+       va_start (ap, store_percentage);
+       while (42)
+       {
+               char const *name;
+               gauge_t value;
+
+               name = va_arg (ap, char const *);
+               if (name == NULL)
+                       break;
+
+               value = va_arg (ap, gauge_t);
+               if (!isnan (value))
+                       sum += value;
+       }
+       va_end (ap);
+
+       vl = plugin_value_list_clone (template);
+       /* plugin_value_list_clone makes sure vl->time is set to non-zero. */
+       if (store_percentage)
+               sstrncpy (vl->type, "percent", sizeof (vl->type));
+
+       va_start (ap, store_percentage);
+       while (42)
+       {
+               char const *name;
+               int status;
+
+               /* Set the type instance. */
+               name = va_arg (ap, char const *);
+               if (name == NULL)
+                       break;
+               sstrncpy (vl->type_instance, name, sizeof (vl->type_instance));
+
+               /* Set the value. */
+               vl->values[0].gauge = va_arg (ap, gauge_t);
+               if (store_percentage)
+                       vl->values[0].gauge *= 100.0 / sum;
+
+               status = plugin_write_enqueue (vl);
+               if (status != 0)
+                       failed++;
+       }
+       va_end (ap);
+
+       plugin_value_list_free (vl);
+       return (failed);
+} /* }}} int plugin_dispatch_multivalue */
+
 int plugin_dispatch_notification (const notification_t *notif)
 {
        llentry_t *le;
index 8f0c6d8..dfc608e 100644 (file)
@@ -1,27 +1,33 @@
-#ifndef PLUGIN_H
-#define PLUGIN_H
 /**
  * collectd - src/plugin.h
- * Copyright (C) 2005-2011  Florian octo Forster
+ * Copyright (C) 2005-2014  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <octo at collectd.org>
  *   Sebastian Harl <sh at tokkee.org>
  **/
 
+#ifndef PLUGIN_H
+#define PLUGIN_H
+
 #include "collectd.h"
 #include "configfile.h"
 #include "meta_data.h"
@@ -328,6 +334,35 @@ int plugin_unregister_notification (const char *name);
  *              function.
  */
 int plugin_dispatch_values (value_list_t const *vl);
+
+/*
+ * NAME
+ *  plugin_dispatch_multivalue
+ *
+ * SYNOPSIS
+ *  plugin_dispatch_multivalue (vl, 1,
+ *                              "free", 42.0,
+ *                              "used", 58.0,
+ *                              NULL);
+ *
+ * DESCRIPTION
+ *  Takes a list of type instances and values and dispatches that in a batch,
+ *  making sure that all values have the same time stamp. If "store_percentage"
+ *  is set to true, the "type" is set to "percent" and a percentage is
+ *  calculated and dispatched, rather than the absolute values. Values that are
+ *  NaN are dispatched as NaN and will not influence the total.
+ *
+ *  The variadic arguments is a list of type_instance / gauge pairs, that are
+ *  interpreted as type "char const *" and "gauge_t". The last argument must be
+ *  a NULL pointer to signal end-of-list.
+ *
+ * RETURNS
+ *  The number of values it failed to dispatch (zero on success).
+ */
+__attribute__((sentinel))
+int plugin_dispatch_multivalue (value_list_t const *vl,
+               _Bool store_percentage, ...);
+
 int plugin_dispatch_missing (const value_list_t *vl);
 
 int plugin_dispatch_notification (const notification_t *notif);
index 1eaf6bd..635abfc 100644 (file)
@@ -2,34 +2,28 @@
  * collectd - src/postgresql.c
  * Copyright (C) 2008-2012  Sebastian Harl
  * Copyright (C) 2009       Florian Forster
- * All rights reserved.
  *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Sebastian Harl <sh at tokkee.org>
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 
 /*
@@ -571,6 +565,7 @@ static int c_psql_exec_query (c_psql_database_t *db, udb_query_t *q,
        }
 
        if (C_PSQL_IS_UNIX_DOMAIN_SOCKET (db->host)
+                       || (0 == strcmp (db->host, "127.0.0.1"))
                        || (0 == strcmp (db->host, "localhost")))
                host = hostname_g;
        else
index a140a12..ece9f75 100644 (file)
@@ -18,7 +18,7 @@
  *
  * Author:
  *   Luke Heberling <lukeh at c-ware.com>
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  *
  * DESCRIPTION
  *   Queries a PowerDNS control socket for statistics
index c8e7b82..5601d29 100644 (file)
@@ -25,7 +25,7 @@
  *
  * Authors:
  *   Lyonel Vincent <lyonel at ezix.org>
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  *   Oleg King <king2 at kaluga.ru>
  *   Sebastian Harl <sh at tokkee.org>
  *   Andrés J. Díaz <ajdiaz at connectical.com>
index 0dfba21..1a39aad 100644 (file)
@@ -2,21 +2,26 @@
  * collectd - src/protocols.c
  * Copyright (C) 2009,2010  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index 85a8354..92be18f 100644 (file)
@@ -37,6 +37,7 @@
 #define REDIS_DEF_PORT    6379
 #define REDIS_DEF_TIMEOUT 2000
 #define MAX_REDIS_NODE_NAME 64
+#define MAX_REDIS_PASSWD_LENGTH 512
 
 /* Redis plugin configuration example:
  *
@@ -55,7 +56,7 @@ struct redis_node_s
 {
   char name[MAX_REDIS_NODE_NAME];
   char host[HOST_NAME_MAX];
-  char passwd[HOST_NAME_MAX];
+  char passwd[MAX_REDIS_PASSWD_LENGTH];
   int port;
   int timeout;
 
index 2ade3bb..4ca9d5b 100644 (file)
@@ -2,18 +2,23 @@
  * collectd - src/routeros.c
  * Copyright (C) 2009,2010  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <octo at collectd.org>
index e77be2d..645032c 100644 (file)
@@ -2,18 +2,23 @@
  * collectd - src/rrdcached.c
  * Copyright (C) 2008-2013  Florian octo Forster
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <octo at collectd.org>
index 209482e..7389449 100644 (file)
@@ -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>
  *   
  *   Lubos Stanek <lubek at users.sourceforge.net> Wed Oct 27, 2006
  *   - config ExtendedSensorNaming option
index 9bd885d..4300822 100644 (file)
@@ -18,7 +18,7 @@
  *
  * Authors:
  *   David Bacher <drbacher at gmail.com>
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index ba3e406..eecb54c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * collectd - src/sigrok.c
- * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
+ * Copyright (C) 2013 Bert Vermeulen
  *
  * 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
@@ -14,6 +14,9 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *   Bert Vermeulen <bert at biot.com>
  */
 
 #include "collectd.h"
index 3e6cb91..7d6e0a1 100644 (file)
@@ -2,18 +2,23 @@
  * collectd - src/snmp.c
  * Copyright (C) 2007-2012  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <octo at collectd.org>
@@ -29,6 +34,8 @@
 #include <net-snmp/net-snmp-config.h>
 #include <net-snmp/net-snmp-includes.h>
 
+#include <fnmatch.h>
+
 /*
  * Private data structes
  */
@@ -50,7 +57,7 @@ struct data_definition_s
 {
   char *name; /* used to reference this from the `Collect' option */
   char *type; /* used to find the data_set */
-  int is_table;
+  _Bool is_table;
   instance_t instance;
   char *instance_prefix;
   oid_t *values;
@@ -58,6 +65,9 @@ struct data_definition_s
   double scale;
   double shift;
   struct data_definition_s *next;
+  char **ignores;
+  size_t ignores_len;
+  int invert_match;
 };
 typedef struct data_definition_s data_definition_t;
 
@@ -65,8 +75,22 @@ struct host_definition_s
 {
   char *name;
   char *address;
-  char *community;
   int version;
+
+  /* snmpv1/2 options */
+  char *community;
+
+  /* snmpv3 security options */
+  char *username;
+  oid *auth_protocol;
+  size_t auth_protocol_len;
+  char *auth_passphrase;
+  oid *priv_protocol;
+  size_t priv_protocol_len;
+  char *priv_passphrase;
+  int security_level;
+  char *context;
+
   void *sess_handle;
   c_complain_t complaint;
   cdtime_t interval;
@@ -183,6 +207,10 @@ static void csnmp_host_definition_destroy (void *arg) /* {{{ */
   sfree (hd->name);
   sfree (hd->address);
   sfree (hd->community);
+  sfree (hd->username);
+  sfree (hd->auth_passphrase);
+  sfree (hd->priv_passphrase);
+  sfree (hd->context);
   sfree (hd->data_list);
 
   sfree (hd);
@@ -197,16 +225,15 @@ static void csnmp_host_definition_destroy (void *arg) /* {{{ */
  *  csnmp_config
  *  +-> call_snmp_init_once
  *  +-> csnmp_config_add_data
- *  !   +-> csnmp_config_add_data_type
- *  !   +-> csnmp_config_add_data_table
  *  !   +-> csnmp_config_add_data_instance
  *  !   +-> csnmp_config_add_data_instance_prefix
  *  !   +-> csnmp_config_add_data_values
  *  +-> csnmp_config_add_host
- *      +-> csnmp_config_add_host_address
- *      +-> csnmp_config_add_host_community
  *      +-> csnmp_config_add_host_version
  *      +-> csnmp_config_add_host_collect
+ *      +-> csnmp_config_add_host_auth_protocol
+ *      +-> csnmp_config_add_host_priv_protocol
+ *      +-> csnmp_config_add_host_security_level
  */
 static void call_snmp_init_once (void)
 {
@@ -217,60 +244,31 @@ static void call_snmp_init_once (void)
   have_init = 1;
 } /* void call_snmp_init_once */
 
-static int csnmp_config_add_data_type (data_definition_t *dd, oconfig_item_t *ci)
-{
-  if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
-  {
-    WARNING ("snmp plugin: `Type' needs exactly one string argument.");
-    return (-1);
-  }
-
-  sfree (dd->type);
-  dd->type = strdup (ci->values[0].value.string);
-  if (dd->type == NULL)
-    return (-1);
-
-  return (0);
-} /* int csnmp_config_add_data_type */
-
-static int csnmp_config_add_data_table (data_definition_t *dd, oconfig_item_t *ci)
-{
-  if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
-  {
-    WARNING ("snmp plugin: `Table' needs exactly one boolean argument.");
-    return (-1);
-  }
-
-  dd->is_table = ci->values[0].value.boolean ? 1 : 0;
-
-  return (0);
-} /* int csnmp_config_add_data_table */
-
 static int csnmp_config_add_data_instance (data_definition_t *dd, oconfig_item_t *ci)
 {
-  if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
-  {
-    WARNING ("snmp plugin: `Instance' needs exactly one string argument.");
-    return (-1);
-  }
+  char buffer[DATA_MAX_NAME_LEN];
+  int status;
+
+  status = cf_util_get_string_buffer(ci, buffer, sizeof(buffer));
+  if (status != 0)
+    return status;
 
   if (dd->is_table)
   {
     /* Instance is an OID */
     dd->instance.oid.oid_len = MAX_OID_LEN;
 
-    if (!read_objid (ci->values[0].value.string,
+    if (!read_objid (buffer,
           dd->instance.oid.oid, &dd->instance.oid.oid_len))
     {
-      ERROR ("snmp plugin: read_objid (%s) failed.",
-          ci->values[0].value.string);
+      ERROR ("snmp plugin: read_objid (%s) failed.", buffer);
       return (-1);
     }
   }
   else
   {
     /* Instance is a simple string */
-    sstrncpy (dd->instance.string, ci->values[0].value.string,
+    sstrncpy (dd->instance.string, buffer,
         sizeof (dd->instance.string));
   }
 
@@ -280,11 +278,7 @@ static int csnmp_config_add_data_instance (data_definition_t *dd, oconfig_item_t
 static int csnmp_config_add_data_instance_prefix (data_definition_t *dd,
     oconfig_item_t *ci)
 {
-  if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
-  {
-    WARNING ("snmp plugin: `InstancePrefix' needs exactly one string argument.");
-    return (-1);
-  }
+  int status;
 
   if (!dd->is_table)
   {
@@ -293,12 +287,8 @@ static int csnmp_config_add_data_instance_prefix (data_definition_t *dd,
     return (-1);
   }
 
-  sfree (dd->instance_prefix);
-  dd->instance_prefix = strdup (ci->values[0].value.string);
-  if (dd->instance_prefix == NULL)
-    return (-1);
-
-  return (0);
+  status = cf_util_get_string(ci, &dd->instance_prefix);
+  return status;
 } /* int csnmp_config_add_data_instance_prefix */
 
 static int csnmp_config_add_data_values (data_definition_t *dd, oconfig_item_t *ci)
@@ -344,33 +334,49 @@ static int csnmp_config_add_data_values (data_definition_t *dd, oconfig_item_t *
   return (0);
 } /* int csnmp_config_add_data_instance */
 
-static int csnmp_config_add_data_shift (data_definition_t *dd, oconfig_item_t *ci)
+static int csnmp_config_add_data_blacklist(data_definition_t *dd, oconfig_item_t *ci)
 {
-  if ((ci->values_num != 1)
-      || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
+  int i;
+
+  if (ci->values_num < 1)
+    return (0);
+
+  for (i = 0; i < ci->values_num; i++)
   {
-    WARNING ("snmp plugin: The `Shift' config option needs exactly one number argument.");
-    return (-1);
+    if (ci->values[i].type != OCONFIG_TYPE_STRING)
+    {
+      WARNING ("snmp plugin: `Ignore' needs only string argument.");
+      return (-1);
+    }
   }
 
-  dd->shift = ci->values[0].value.number;
+  dd->ignores_len = 0;
+  dd->ignores = NULL;
 
-  return (0);
-} /* int csnmp_config_add_data_shift */
+  for (i = 0; i < ci->values_num; ++i)
+  {
+    if (strarray_add(&(dd->ignores), &(dd->ignores_len), ci->values[i].value.string) != 0)
+    {
+      ERROR("snmp plugin: Can't allocate memory");
+      strarray_free(dd->ignores, dd->ignores_len);
+      return (ENOMEM); 
+    }
+  }
+  return 0;
+} /* int csnmp_config_add_data_blacklist */
 
-static int csnmp_config_add_data_scale (data_definition_t *dd, oconfig_item_t *ci)
+static int csnmp_config_add_data_blacklist_match_inverted(data_definition_t *dd, oconfig_item_t *ci)
 {
-  if ((ci->values_num != 1)
-      || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
+  if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
   {
-    WARNING ("snmp plugin: The `Scale' config option needs exactly one number argument.");
+    WARNING ("snmp plugin: `InvertMatch' needs exactly one boolean argument.");
     return (-1);
   }
 
-  dd->scale = ci->values[0].value.number;
+  dd->invert_match = ci->values[0].value.boolean ? 1 : 0;
 
   return (0);
-} /* int csnmp_config_add_data_scale */
+} /* int csnmp_config_add_data_blacklist_match_inverted */
 
 static int csnmp_config_add_data (oconfig_item_t *ci)
 {
@@ -378,24 +384,18 @@ static int csnmp_config_add_data (oconfig_item_t *ci)
   int status = 0;
   int i;
 
-  if ((ci->values_num != 1)
-      || (ci->values[0].type != OCONFIG_TYPE_STRING))
-  {
-    WARNING ("snmp plugin: The `Data' config option needs exactly one string argument.");
-    return (-1);
-  }
-
   dd = (data_definition_t *) malloc (sizeof (data_definition_t));
   if (dd == NULL)
     return (-1);
   memset (dd, '\0', sizeof (data_definition_t));
 
-  dd->name = strdup (ci->values[0].value.string);
-  if (dd->name == NULL)
+  status = cf_util_get_string(ci, &dd->name);
+  if (status != 0)
   {
     free (dd);
     return (-1);
   }
+
   dd->scale = 1.0;
   dd->shift = 0.0;
 
@@ -405,9 +405,9 @@ static int csnmp_config_add_data (oconfig_item_t *ci)
     status = 0;
 
     if (strcasecmp ("Type", option->key) == 0)
-      status = csnmp_config_add_data_type (dd, option);
+      status = cf_util_get_string(option, &dd->type);
     else if (strcasecmp ("Table", option->key) == 0)
-      status = csnmp_config_add_data_table (dd, option);
+      status = cf_util_get_boolean(option, &dd->is_table);
     else if (strcasecmp ("Instance", option->key) == 0)
       status = csnmp_config_add_data_instance (dd, option);
     else if (strcasecmp ("InstancePrefix", option->key) == 0)
@@ -415,9 +415,13 @@ static int csnmp_config_add_data (oconfig_item_t *ci)
     else if (strcasecmp ("Values", option->key) == 0)
       status = csnmp_config_add_data_values (dd, option);
     else if (strcasecmp ("Shift", option->key) == 0)
-      status = csnmp_config_add_data_shift (dd, option);
+      status = cf_util_get_double(option, &dd->shift);
     else if (strcasecmp ("Scale", option->key) == 0)
-      status = csnmp_config_add_data_scale (dd, option);
+      status = cf_util_get_double(option, &dd->scale);
+    else if (strcasecmp ("Ignore", option->key) == 0)
+      status = csnmp_config_add_data_blacklist(dd, option);
+    else if (strcasecmp ("InvertMatch", option->key) == 0)
+      status = csnmp_config_add_data_blacklist_match_inverted(dd, option);
     else
     {
       WARNING ("snmp plugin: Option `%s' not allowed here.", option->key);
@@ -451,6 +455,7 @@ static int csnmp_config_add_data (oconfig_item_t *ci)
     sfree (dd->name);
     sfree (dd->instance_prefix);
     sfree (dd->values);
+    sfree (dd->ignores);
     sfree (dd);
     return (-1);
   }
@@ -472,50 +477,6 @@ static int csnmp_config_add_data (oconfig_item_t *ci)
   return (0);
 } /* int csnmp_config_add_data */
 
-static int csnmp_config_add_host_address (host_definition_t *hd, oconfig_item_t *ci)
-{
-  if ((ci->values_num != 1)
-      || (ci->values[0].type != OCONFIG_TYPE_STRING))
-  {
-    WARNING ("snmp plugin: The `Address' config option needs exactly one string argument.");
-    return (-1);
-  }
-
-  if (hd->address == NULL)
-    free (hd->address);
-
-  hd->address = strdup (ci->values[0].value.string);
-  if (hd->address == NULL)
-    return (-1);
-
-  DEBUG ("snmp plugin: host = %s; host->address = %s;",
-      hd->name, hd->address);
-
-  return (0);
-} /* int csnmp_config_add_host_address */
-
-static int csnmp_config_add_host_community (host_definition_t *hd, oconfig_item_t *ci)
-{
-  if ((ci->values_num != 1)
-      || (ci->values[0].type != OCONFIG_TYPE_STRING))
-  {
-    WARNING ("snmp plugin: The `Community' config option needs exactly one string argument.");
-    return (-1);
-  }
-
-  if (hd->community == NULL)
-    free (hd->community);
-
-  hd->community = strdup (ci->values[0].value.string);
-  if (hd->community == NULL)
-    return (-1);
-
-  DEBUG ("snmp plugin: host = %s; host->community = %s;",
-      hd->name, hd->community);
-
-  return (0);
-} /* int csnmp_config_add_host_community */
-
 static int csnmp_config_add_host_version (host_definition_t *hd, oconfig_item_t *ci)
 {
   int version;
@@ -528,9 +489,9 @@ static int csnmp_config_add_host_version (host_definition_t *hd, oconfig_item_t
   }
 
   version = (int) ci->values[0].value.number;
-  if ((version != 1) && (version != 2))
+  if ((version < 1) || (version > 3))
   {
-    WARNING ("snmp plugin: `Version' must either be `1' or `2'.");
+    WARNING ("snmp plugin: `Version' must either be `1', `2', or `3'.");
     return (-1);
   }
 
@@ -590,6 +551,92 @@ static int csnmp_config_add_host_collect (host_definition_t *host,
   return (0);
 } /* int csnmp_config_add_host_collect */
 
+static int csnmp_config_add_host_auth_protocol (host_definition_t *hd, oconfig_item_t *ci)
+{
+  char buffer[4];
+  int status;
+
+  status = cf_util_get_string_buffer(ci, buffer, sizeof(buffer));
+  if (status != 0)
+    return status;
+
+  if (strcasecmp("MD5", buffer) == 0) {
+    hd->auth_protocol = usmHMACMD5AuthProtocol;
+    hd->auth_protocol_len = sizeof(usmHMACMD5AuthProtocol)/sizeof(oid);
+  }
+  else if (strcasecmp("SHA", buffer) == 0) {
+    hd->auth_protocol = usmHMACSHA1AuthProtocol;
+    hd->auth_protocol_len = sizeof(usmHMACSHA1AuthProtocol)/sizeof(oid);
+  }
+  else
+  {
+    WARNING ("snmp plugin: The `AuthProtocol' config option must be `MD5' or `SHA'.");
+    return (-1);
+  }
+
+  DEBUG ("snmp plugin: host = %s; host->auth_protocol = %s;",
+      hd->name, hd->auth_protocol == usmHMACMD5AuthProtocol ? "MD5" : "SHA");
+
+  return (0);
+} /* int csnmp_config_add_host_auth_protocol */
+
+static int csnmp_config_add_host_priv_protocol (host_definition_t *hd, oconfig_item_t *ci)
+{
+  char buffer[4];
+  int status;
+
+  status = cf_util_get_string_buffer(ci, buffer, sizeof(buffer));
+  if (status != 0)
+    return status;
+
+  if (strcasecmp("AES", buffer) == 0)
+  {
+    hd->priv_protocol = usmAESPrivProtocol;
+    hd->priv_protocol_len = sizeof(usmAESPrivProtocol)/sizeof(oid);
+  }
+  else if (strcasecmp("DES", buffer) == 0) {
+    hd->priv_protocol = usmDESPrivProtocol;
+    hd->priv_protocol_len = sizeof(usmDESPrivProtocol)/sizeof(oid);
+  }
+  else
+  {
+    WARNING ("snmp plugin: The `PrivProtocol' config option must be `AES' or `DES'.");
+    return (-1);
+  }
+
+  DEBUG ("snmp plugin: host = %s; host->priv_protocol = %s;",
+      hd->name, hd->priv_protocol == usmAESPrivProtocol ? "AES" : "DES");
+
+  return (0);
+} /* int csnmp_config_add_host_priv_protocol */
+
+static int csnmp_config_add_host_security_level (host_definition_t *hd, oconfig_item_t *ci)
+{
+  char buffer[16];
+  int status;
+
+  status = cf_util_get_string_buffer(ci, buffer, sizeof(buffer));
+  if (status != 0)
+    return status;
+
+  if (strcasecmp("noAuthNoPriv", buffer) == 0)
+    hd->security_level = SNMP_SEC_LEVEL_NOAUTH;
+  else if (strcasecmp("authNoPriv", buffer) == 0)
+    hd->security_level = SNMP_SEC_LEVEL_AUTHNOPRIV;
+  else if (strcasecmp("authPriv", buffer) == 0)
+    hd->security_level = SNMP_SEC_LEVEL_AUTHPRIV;
+  else
+  {
+    WARNING ("snmp plugin: The `SecurityLevel' config option must be `noAuthNoPriv', `authNoPriv', or `authPriv'.");
+    return (-1);
+  }
+
+  DEBUG ("snmp plugin: host = %s; host->security_level = %d;",
+      hd->name, hd->security_level);
+
+  return (0);
+} /* int csnmp_config_add_host_security_level */
+
 static int csnmp_config_add_host (oconfig_item_t *ci)
 {
   host_definition_t *hd;
@@ -601,12 +648,6 @@ static int csnmp_config_add_host (oconfig_item_t *ci)
   user_data_t cb_data;
   struct timespec cb_interval;
 
-  if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
-  {
-    WARNING ("snmp plugin: `Host' needs exactly one string argument.");
-    return (-1);
-  }
-
   hd = (host_definition_t *) malloc (sizeof (host_definition_t));
   if (hd == NULL)
     return (-1);
@@ -614,12 +655,9 @@ static int csnmp_config_add_host (oconfig_item_t *ci)
   hd->version = 2;
   C_COMPLAIN_INIT (&hd->complaint);
 
-  hd->name = strdup (ci->values[0].value.string);
-  if (hd->name == NULL)
-  {
-    free (hd);
-    return (-1);
-  }
+  status = cf_util_get_string(ci, &hd->name);
+  if (status != 0)
+    return status;
 
   hd->sess_handle = NULL;
   hd->interval = 0;
@@ -630,15 +668,29 @@ static int csnmp_config_add_host (oconfig_item_t *ci)
     status = 0;
 
     if (strcasecmp ("Address", option->key) == 0)
-      status = csnmp_config_add_host_address (hd, option);
+      status = cf_util_get_string(option, &hd->address);
     else if (strcasecmp ("Community", option->key) == 0)
-      status = csnmp_config_add_host_community (hd, option);
+      status = cf_util_get_string(option, &hd->community);
     else if (strcasecmp ("Version", option->key) == 0)
       status = csnmp_config_add_host_version (hd, option);
     else if (strcasecmp ("Collect", option->key) == 0)
       csnmp_config_add_host_collect (hd, option);
     else if (strcasecmp ("Interval", option->key) == 0)
       cf_util_get_cdtime (option, &hd->interval);
+    else if (strcasecmp ("Username", option->key) == 0)
+      status = cf_util_get_string(option, &hd->username);
+    else if (strcasecmp ("AuthProtocol", option->key) == 0)
+      status = csnmp_config_add_host_auth_protocol (hd, option);
+    else if (strcasecmp ("PrivacyProtocol", option->key) == 0)
+      status = csnmp_config_add_host_priv_protocol (hd, option);
+    else if (strcasecmp ("AuthPassphrase", option->key) == 0)
+      status = cf_util_get_string(option, &hd->auth_passphrase);
+    else if (strcasecmp ("PrivacyPassphrase", option->key) == 0)
+      status = cf_util_get_string(option, &hd->priv_passphrase);
+    else if (strcasecmp ("SecurityLevel", option->key) == 0)
+      status = csnmp_config_add_host_security_level (hd, option);
+    else if (strcasecmp ("Context", option->key) == 0)
+      status = cf_util_get_string(option, &hd->context);
     else
     {
       WARNING ("snmp plugin: csnmp_config_add_host: Option `%s' not allowed here.", option->key);
@@ -657,12 +709,57 @@ static int csnmp_config_add_host (oconfig_item_t *ci)
       status = -1;
       break;
     }
-    if (hd->community == NULL)
+    if (hd->community == NULL && hd->version < 3)
     {
       WARNING ("snmp plugin: `Community' not given for host `%s'", hd->name);
       status = -1;
       break;
     }
+    if (hd->version == 3)
+    {
+      if (hd->username == NULL)
+      {
+        WARNING ("snmp plugin: `Username' not given for host `%s'", hd->name);
+        status = -1;
+        break;
+      }
+      if (hd->security_level == 0)
+      {
+        WARNING ("snmp plugin: `SecurityLevel' not given for host `%s'", hd->name);
+        status = -1;
+        break;
+      }
+      if (hd->security_level == SNMP_SEC_LEVEL_AUTHNOPRIV || hd->security_level == SNMP_SEC_LEVEL_AUTHPRIV)
+      {
+       if (hd->auth_protocol == NULL)
+       {
+         WARNING ("snmp plugin: `AuthProtocol' not given for host `%s'", hd->name);
+         status = -1;
+         break;
+       }
+       if (hd->auth_passphrase == NULL)
+       {
+         WARNING ("snmp plugin: `AuthPassphrase' not given for host `%s'", hd->name);
+         status = -1;
+         break;
+       }
+      }
+      if (hd->security_level == SNMP_SEC_LEVEL_AUTHPRIV)
+      {
+       if (hd->priv_protocol == NULL)
+       {
+         WARNING ("snmp plugin: `PrivacyProtocol' not given for host `%s'", hd->name);
+         status = -1;
+         break;
+       }
+       if (hd->priv_passphrase == NULL)
+       {
+         WARNING ("snmp plugin: `PrivacyPassphrase' not given for host `%s'", hd->name);
+         status = -1;
+         break;
+       }
+      }
+    }
 
     break;
   } /* while (status == 0) */
@@ -724,15 +821,75 @@ static int csnmp_config (oconfig_item_t *ci)
 static void csnmp_host_open_session (host_definition_t *host)
 {
   struct snmp_session sess;
+  int error;
 
   if (host->sess_handle != NULL)
     csnmp_host_close_session (host);
 
   snmp_sess_init (&sess);
   sess.peername = host->address;
-  sess.community = (u_char *) host->community;
-  sess.community_len = strlen (host->community);
-  sess.version = (host->version == 1) ? SNMP_VERSION_1 : SNMP_VERSION_2c;
+  switch (host->version)
+  {
+    case 1:
+      sess.version = SNMP_VERSION_1;
+      break;
+    case 3:
+      sess.version = SNMP_VERSION_3;
+      break;
+    default:
+      sess.version = SNMP_VERSION_2c;
+      break;
+  }
+
+  if (host->version == 3)
+  {
+    sess.securityName = host->username;
+    sess.securityNameLen = strlen (host->username);
+    sess.securityLevel = host->security_level;
+
+    if (sess.securityLevel == SNMP_SEC_LEVEL_AUTHNOPRIV || sess.securityLevel == SNMP_SEC_LEVEL_AUTHPRIV)
+    {
+      sess.securityAuthProto = host->auth_protocol;
+      sess.securityAuthProtoLen = host->auth_protocol_len;
+      sess.securityAuthKeyLen = USM_AUTH_KU_LEN;
+      error = generate_Ku (sess.securityAuthProto,
+           sess.securityAuthProtoLen,
+           (u_char *) host->auth_passphrase,
+           strlen(host->auth_passphrase),
+           sess.securityAuthKey,
+           &sess.securityAuthKeyLen);
+      if (error != SNMPERR_SUCCESS) {
+       ERROR ("snmp plugin: host %s: Error generating Ku from auth_passphrase. (Error %d)", host->name, error);
+      }
+    }
+
+    if (sess.securityLevel == SNMP_SEC_LEVEL_AUTHPRIV)
+    {
+      sess.securityPrivProto = host->priv_protocol;
+      sess.securityPrivProtoLen = host->priv_protocol_len;
+      sess.securityPrivKeyLen = USM_PRIV_KU_LEN;
+      error = generate_Ku (sess.securityAuthProto,
+           sess.securityAuthProtoLen,
+           (u_char *) host->priv_passphrase,
+           strlen(host->priv_passphrase),
+           sess.securityPrivKey,
+           &sess.securityPrivKeyLen);
+      if (error != SNMPERR_SUCCESS) {
+       ERROR ("snmp plugin: host %s: Error generating Ku from priv_passphrase. (Error %d)", host->name, error);
+      }
+    }
+
+    if (host->context != NULL)
+    {
+      sess.contextName = host->context;
+      sess.contextNameLen = strlen (host->context);
+    }
+  }
+  else /* SNMPv1/2 "authenticates" with community string */
+  {
+    sess.community = (u_char *) host->community;
+    sess.community_len = strlen (host->community);
+  }
 
   /* snmp_sess_open will copy the `struct snmp_session *'. */
   host->sess_handle = snmp_sess_open (&sess);
@@ -971,6 +1128,8 @@ static int csnmp_instance_list_add (csnmp_list_instances_t **head,
   struct variable_list *vb;
   oid_t vb_name;
   int status;
+  uint32_t i;
+  uint32_t is_matched;
 
   /* Set vb on the last variable */
   for (vb = res->variables;
@@ -1004,7 +1163,29 @@ static int csnmp_instance_list_add (csnmp_list_instances_t **head,
     char *ptr;
 
     csnmp_strvbcopy (il->instance, vb, sizeof (il->instance));
-
+    is_matched = 0;
+    for (i = 0; i < dd->ignores_len; i++)
+    {
+      status = fnmatch(dd->ignores[i], il->instance, 0);
+      if (status == 0)
+      {
+        if (dd->invert_match == 0)
+        {
+          sfree(il);
+          return 0;
+        }
+       else
+       {
+          is_matched = 1;
+         break;
+       }
+      }
+    }
+    if (dd->invert_match != 0 && is_matched == 0)
+    {
+      sfree(il);
+      return 0;
+    }
     for (ptr = il->instance; *ptr != '\0'; ptr++)
     {
       if ((*ptr > 0) && (*ptr < 32))
@@ -1659,6 +1840,7 @@ static int csnmp_shutdown (void)
     sfree (data_this->name);
     sfree (data_this->type);
     sfree (data_this->values);
+    sfree (data_this->ignores);
     sfree (data_this);
 
     data_this = data_next;
index 52dd8f8..72b8e2b 100644 (file)
@@ -1,19 +1,24 @@
 /**
  * collectd - src/statsd.c
- *
  * Copyright (C) 2013       Florian octo Forster
  *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
- * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <octo at collectd.org>
index 46d3534..508f9d5 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * collectd - src/swap.c
- * Copyright (C) 2005-2012  Florian octo Forster
+ * Copyright (C) 2005-2014  Florian octo Forster
  * Copyright (C) 2009       Stefan Völkel
  * Copyright (C) 2009       Manuel Sanmartin
  * Copyright (C) 2010       Aurélien Reynaud
@@ -97,48 +97,45 @@ int kvm_pagesize;
 
 #elif HAVE_PERFSTAT
 static int pagesize;
-static perfstat_memory_total_t pmemory;
 /*# endif HAVE_PERFSTAT */
 
 #else
 # error "No applicable input method."
 #endif /* HAVE_LIBSTATGRAB */
 
-static const char *config_keys[] =
-{
-       "ReportBytes",
-       "ReportByDevice"
-};
-static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+static _Bool values_absolute = 1;
+static _Bool values_percentage = 0;
 
-static int swap_config (const char *key, const char *value) /* {{{ */
+static int swap_config (oconfig_item_t *ci) /* {{{ */
 {
-       if (strcasecmp ("ReportBytes", key) == 0)
+       int i;
+
+       for (i = 0; i < ci->children_num; i++)
        {
+               oconfig_item_t *child = ci->children + i;
+               if (strcasecmp ("ReportBytes", child->key) == 0)
 #if KERNEL_LINUX
-               report_bytes = IS_TRUE (value) ? 1 : 0;
+                       cf_util_get_boolean (child, &report_bytes);
 #else
-               WARNING ("swap plugin: The \"ReportBytes\" option is only "
-                               "valid under Linux. "
-                               "The option is going to be ignored.");
+                       WARNING ("swap plugin: The \"ReportBytes\" option "
+                                       "is only valid under Linux. "
+                                       "The option is going to be ignored.");
 #endif
-       }
-       else if (strcasecmp ("ReportByDevice", key) == 0)
-       {
+               else if (strcasecmp ("ReportByDevice", child->key) == 0)
 #if SWAP_HAVE_REPORT_BY_DEVICE
-               if (IS_TRUE (value))
-                       report_by_device = 1;
-               else
-                       report_by_device = 0;
+                       cf_util_get_boolean (child, &report_by_device);
 #else
-               WARNING ("swap plugin: The \"ReportByDevice\" option is not "
-                               "supported on this platform. "
-                               "The option is going to be ignored.");
+                       WARNING ("swap plugin: The \"ReportByDevice\" option "
+                                       "is not supported on this platform. "
+                                       "The option is going to be ignored.");
 #endif /* SWAP_HAVE_REPORT_BY_DEVICE */
-       }
-       else
-       {
-               return (-1);
+               else if (strcasecmp ("ValuesAbsolute", child->key) == 0)
+                       cf_util_get_boolean (child, &values_absolute);
+               else if (strcasecmp ("ValuesPercentage", child->key) == 0)
+                       cf_util_get_boolean (child, &values_percentage);
+               else
+                       WARNING ("swap plugin: Unknown config option: \"%s\"",
+                                       child->key);
        }
 
        return (0);
@@ -191,44 +188,50 @@ static int swap_init (void) /* {{{ */
        return (0);
 } /* }}} int swap_init */
 
-static void swap_submit (const char *plugin_instance, /* {{{ */
-               const char *type, const char *type_instance,
-               value_t value)
+static void swap_submit_usage (char const *plugin_instance, /* {{{ */
+               gauge_t used, gauge_t free,
+               char const *other_name, gauge_t other_value)
 {
+       value_t v[1];
        value_list_t vl = VALUE_LIST_INIT;
 
-       assert (type != NULL);
-
-       vl.values = &value;
-       vl.values_len = 1;
+       vl.values = v;
+       vl.values_len = STATIC_ARRAY_SIZE (v);
        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, 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 */
+               sstrncpy (vl.plugin_instance, plugin_instance,
+                               sizeof (vl.plugin_instance));
+       sstrncpy (vl.type, "swap", sizeof (vl.type));
+
+       if (values_absolute)
+               plugin_dispatch_multivalue (&vl, 0,
+                               "used", used, "free", free,
+                               other_name, other_value, NULL);
+       if (values_percentage)
+               plugin_dispatch_multivalue (&vl, 1,
+                               "used", used, "free", free,
+                               other_name, other_value, NULL);
+} /* }}} void swap_submit_usage */
 
-static void swap_submit_gauge (const char *plugin_instance, /* {{{ */
-               const char *type_instance, gauge_t value)
+#if KERNEL_LINUX || HAVE_PERFSTAT
+__attribute__((nonnull(1)))
+static void swap_submit_derive (char const *type_instance, /* {{{ */
+               derive_t value)
 {
-       value_t v;
+       value_list_t vl = VALUE_LIST_INIT;
+       value_t v[1];
 
-       v.gauge = value;
-       swap_submit (plugin_instance, "swap", type_instance, v);
-} /* }}} void swap_submit_gauge */
+       v[0].derive = value;
 
-#if KERNEL_LINUX || HAVE_PERFSTAT
-static void swap_submit_derive (const char *plugin_instance, /* {{{ */
-               const char *type_instance, derive_t value)
-{
-       value_t v;
+       vl.values = v;
+       vl.values_len = STATIC_ARRAY_SIZE (v);
+       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       sstrncpy (vl.plugin, "swap", sizeof (vl.plugin));
+       sstrncpy (vl.type, "swap_io", sizeof (vl.type));
+       sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
 
-       v.derive = value;
-       swap_submit (plugin_instance, "swap_io", type_instance, v);
+       plugin_dispatch_values (&vl);
 } /* }}} void swap_submit_derive */
 #endif
 
@@ -254,9 +257,8 @@ static int swap_read_separate (void) /* {{{ */
                char *endptr;
 
                char path[PATH_MAX];
-               gauge_t size;
+               gauge_t total;
                gauge_t used;
-               gauge_t free;
 
                numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
                if (numfields != 5)
@@ -267,7 +269,7 @@ static int swap_read_separate (void) /* {{{ */
 
                errno = 0;
                endptr = NULL;
-               size = strtod (fields[2], &endptr);
+               total = strtod (fields[2], &endptr);
                if ((endptr == fields[2]) || (errno != 0))
                        continue;
 
@@ -277,13 +279,10 @@ static int swap_read_separate (void) /* {{{ */
                if ((endptr == fields[3]) || (errno != 0))
                        continue;
 
-               if (size < used)
+               if (total < used)
                        continue;
 
-               free = size - used;
-
-               swap_submit_gauge (path, "used", used);
-               swap_submit_gauge (path, "free", free);
+               swap_submit_usage (path, used, total - used, NULL, NAN);
        }
 
        fclose (fh);
@@ -349,10 +348,7 @@ static int swap_read_combined (void) /* {{{ */
 
        swap_used = swap_total - (swap_free + swap_cached);
 
-       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);
-
+       swap_submit_usage (NULL, swap_used, swap_free, "cached", swap_cached);
        return (0);
 } /* }}} int swap_read_combined */
 
@@ -430,8 +426,8 @@ static int swap_read_io (void) /* {{{ */
                swap_out = swap_out * pagesize;
        }
 
-       swap_submit_derive (NULL, "in",  swap_in);
-       swap_submit_derive (NULL, "out", swap_out);
+       swap_submit_derive ("in",  swap_in);
+       swap_submit_derive ("out", swap_out);
 
        return (0);
 } /* }}} int swap_read_io */
@@ -462,9 +458,9 @@ static int swap_read (void) /* {{{ */
 /* kstat-based read function */
 static int swap_read_kstat (void) /* {{{ */
 {
-       derive_t swap_alloc;
-       derive_t swap_resv;
-       derive_t swap_avail;
+       gauge_t swap_alloc;
+       gauge_t swap_resv;
+       gauge_t swap_avail;
 
        struct anoninfo ai;
 
@@ -497,15 +493,11 @@ static int swap_read_kstat (void) /* {{{ */
         * swap_alloc = pagesize * ( ai.ani_max - ai.ani_free );
         * can suffer from a 32bit overflow.
         */
-       swap_alloc  = (derive_t) ((ai.ani_max - ai.ani_free) * pagesize);
-       swap_resv   = (derive_t) ((ai.ani_resv + ai.ani_free - ai.ani_max)
-                       * pagesize);
-       swap_avail  = (derive_t) ((ai.ani_max - ai.ani_resv) * pagesize);
-
-       swap_submit_gauge (NULL, "used", swap_alloc);
-       swap_submit_gauge (NULL, "free", swap_avail);
-       swap_submit_gauge (NULL, "reserved", swap_resv);
+       swap_alloc = (gauge_t) ((ai.ani_max - ai.ani_free) * pagesize);
+       swap_resv  = (gauge_t) ((ai.ani_resv + ai.ani_free - ai.ani_max) * pagesize);
+       swap_avail = (gauge_t) ((ai.ani_max - ai.ani_resv) * pagesize);
 
+       swap_submit_usage (NULL, swap_alloc, swap_avail, "reserved", swap_resv);
        return (0);
 } /* }}} int swap_read_kstat */
 /* #endif 0 && HAVE_LIBKSTAT */
@@ -520,8 +512,8 @@ static int swap_read (void) /* {{{ */
         int status;
         int i;
 
-        derive_t avail = 0;
-        derive_t total = 0;
+        gauge_t avail = 0;
+        gauge_t total = 0;
 
         swap_num = swapctl (SC_GETNSWP, NULL);
         if (swap_num < 0)
@@ -584,14 +576,14 @@ static int swap_read (void) /* {{{ */
         for (i = 0; i < swap_num; i++)
         {
                char path[PATH_MAX];
-               derive_t this_total;
-               derive_t this_avail;
+               gauge_t this_total;
+               gauge_t this_avail;
 
                 if ((s->swt_ent[i].ste_flags & ST_INDEL) != 0)
                         continue;
 
-               this_total = ((derive_t) s->swt_ent[i].ste_pages) * pagesize;
-               this_avail = ((derive_t) s->swt_ent[i].ste_free)  * pagesize;
+               this_total = (gauge_t) (s->swt_ent[i].ste_pages * pagesize);
+               this_avail = (gauge_t) (s->swt_ent[i].ste_free  * pagesize);
 
                /* Shortcut for the "combined" setting (default) */
                if (!report_by_device)
@@ -604,27 +596,23 @@ static int swap_read (void) /* {{{ */
                sstrncpy (path, s->swt_ent[i].ste_path, sizeof (path));
                escape_slashes (path, sizeof (path));
 
-               swap_submit_gauge (path, "used", (gauge_t) (this_total - this_avail));
-               swap_submit_gauge (path, "free", (gauge_t) this_avail);
+               swap_submit_usage (path, this_total - this_avail, this_avail,
+                               NULL, NAN);
         } /* for (swap_num) */
 
         if (total < avail)
         {
-                ERROR ("swap plugin: Total swap space (%"PRIi64") "
-                                "is less than free swap space (%"PRIi64").",
+                ERROR ("swap plugin: Total swap space (%g) is less than free swap space (%g).",
                                 total, avail);
                sfree (s_paths);
                 sfree (s);
                 return (-1);
         }
 
-       /* If the "separate" option was specified (report_by_device == 2), all
+       /* If the "separate" option was specified (report_by_device == 1), all
         * values have already been dispatched from within the loop. */
        if (!report_by_device)
-       {
-               swap_submit_gauge (NULL, "used", (gauge_t) (total - avail));
-               swap_submit_gauge (NULL, "free", (gauge_t) avail);
-       }
+               swap_submit_usage (NULL, total - avail, avail, NULL, NAN);
 
        sfree (s_paths);
         sfree (s);
@@ -640,8 +628,8 @@ static int swap_read (void) /* {{{ */
        int status;
        int i;
 
-       derive_t used  = 0;
-       derive_t total = 0;
+       gauge_t used  = 0;
+       gauge_t total = 0;
 
        swap_num = swapctl (SWAP_NSWAP, NULL, 0);
        if (swap_num < 0)
@@ -670,35 +658,32 @@ static int swap_read (void) /* {{{ */
        }
 
 #if defined(DEV_BSIZE) && (DEV_BSIZE > 0)
-# define C_SWAP_BLOCK_SIZE ((derive_t) DEV_BSIZE)
+# define C_SWAP_BLOCK_SIZE ((gauge_t) DEV_BSIZE)
 #else
-# define C_SWAP_BLOCK_SIZE ((derive_t) 512)
+# define C_SWAP_BLOCK_SIZE 512.0
 #endif
 
+       /* TODO: Report per-device stats. The path name is available from
+        * swap_entries[i].se_path */
        for (i = 0; i < swap_num; i++)
        {
                if ((swap_entries[i].se_flags & SWF_ENABLE) == 0)
                        continue;
 
-               used  += ((derive_t) swap_entries[i].se_inuse)
-                       * C_SWAP_BLOCK_SIZE;
-               total += ((derive_t) swap_entries[i].se_nblks)
-                       * C_SWAP_BLOCK_SIZE;
+               used  += ((gauge_t) swap_entries[i].se_inuse) * C_SWAP_BLOCK_SIZE;
+               total += ((gauge_t) swap_entries[i].se_nblks) * C_SWAP_BLOCK_SIZE;
        }
 
        if (total < used)
        {
-               ERROR ("swap plugin: Total swap space (%"PRIu64") "
-                               "is less than used swap space (%"PRIu64").",
+               ERROR ("swap plugin: Total swap space (%g) is less than used swap space (%g).",
                                total, used);
                return (-1);
        }
 
-       swap_submit_gauge (NULL, "used", (gauge_t) used);
-       swap_submit_gauge (NULL, "free", (gauge_t) (total - used));
+       swap_submit_usage (NULL, used, total - used, NULL, NAN);
 
        sfree (swap_entries);
-
        return (0);
 } /* }}} int swap_read */
 /* #endif HAVE_SWAPCTL && HAVE_SWAPCTL_THREE_ARGS */
@@ -721,8 +706,9 @@ static int swap_read (void) /* {{{ */
                return (-1);
 
        /* The returned values are bytes. */
-       swap_submit_gauge (NULL, "used", (gauge_t) sw_usage.xsu_used);
-       swap_submit_gauge (NULL, "free", (gauge_t) sw_usage.xsu_avail);
+       swap_submit_usage (NULL,
+                       (gauge_t) sw_usage.xsu_used, (gauge_t) sw_usage.xsu_avail,
+                       NULL, NAN);
 
        return (0);
 } /* }}} int swap_read */
@@ -734,9 +720,8 @@ static int swap_read (void) /* {{{ */
        struct kvm_swap data_s;
        int             status;
 
-       derive_t used;
-       derive_t free;
-       derive_t total;
+       gauge_t used;
+       gauge_t total;
 
        if (kvm_obj == NULL)
                return (-1);
@@ -746,16 +731,13 @@ static int swap_read (void) /* {{{ */
        if (status == -1)
                return (-1);
 
-       total = (derive_t) data_s.ksw_total;
-       used  = (derive_t) data_s.ksw_used;
+       total = (gauge_t) data_s.ksw_total;
+       used  = (gauge_t) data_s.ksw_used;
 
-       total *= (derive_t) kvm_pagesize;
-       used  *= (derive_t) kvm_pagesize;
+       total *= (gauge_t) kvm_pagesize;
+       used  *= (gauge_t) kvm_pagesize;
 
-       free = total - used;
-
-       swap_submit_gauge (NULL, "used", (gauge_t) used);
-       swap_submit_gauge (NULL, "free", (gauge_t) free);
+       swap_submit_usage (NULL, used, total - used, NULL, NAN);
 
        return (0);
 } /* }}} int swap_read */
@@ -767,12 +749,11 @@ static int swap_read (void) /* {{{ */
        sg_swap_stats *swap;
 
        swap = sg_get_swap_stats ();
-
        if (swap == NULL)
                return (-1);
 
-       swap_submit_gauge (NULL, "used", (gauge_t) swap->used);
-       swap_submit_gauge (NULL, "free", (gauge_t) swap->free);
+       swap_submit_usage (NULL, (gauge_t) swap->used, (gauge_t) swap->free,
+                       NULL, NAN);
 
        return (0);
 } /* }}} int swap_read */
@@ -781,19 +762,30 @@ static int swap_read (void) /* {{{ */
 #elif HAVE_PERFSTAT
 static int swap_read (void) /* {{{ */
 {
-        if(perfstat_memory_total(NULL, &pmemory, sizeof(perfstat_memory_total_t), 1) < 0)
+       perfstat_memory_total_t pmemory;
+       int status;
+
+       gauge_t total;
+       gauge_t free;
+       gauge_t reserved;
+
+       memset (&pmemory, 0, sizeof (pmemory));
+        status = perfstat_memory_total (NULL, &pmemory, sizeof(perfstat_memory_total_t), 1);
+       if (status < 0)
        {
                 char errbuf[1024];
-                WARNING ("memory plugin: perfstat_memory_total failed: %s",
+                WARNING ("swap plugin: perfstat_memory_total failed: %s",
                         sstrerror (errno, errbuf, sizeof (errbuf)));
                 return (-1);
         }
 
-       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 );
-       swap_submit_gauge (NULL, "reserved", (gauge_t) pmemory.pgsp_rsvd * pagesize);
-       swap_submit_derive (NULL, "in",  (derive_t) pmemory.pgspins * pagesize);
-       swap_submit_derive (NULL, "out", (derive_t) pmemory.pgspouts * pagesize);
+       total    = (gauge_t) (pmemory.pgsp_total * pagesize);
+       free     = (gauge_t) (pmemory.pgsp_free * pagesize);
+       reserved = (gauge_t) (pmemory.pgsp_rsvd * pagesize);
+
+       swap_submit_usage (NULL, total - free, free, "reserved", reserved);
+       swap_submit_derive ("in",  (derive_t) pmemory.pgspins * pagesize);
+       swap_submit_derive ("out", (derive_t) pmemory.pgspouts * pagesize);
 
        return (0);
 } /* }}} int swap_read */
@@ -801,8 +793,7 @@ static int swap_read (void) /* {{{ */
 
 void module_register (void)
 {
-       plugin_register_config ("swap", swap_config,
-                       config_keys, config_keys_num);
+       plugin_register_complex_config ("swap", swap_config);
        plugin_register_init ("swap", swap_init);
        plugin_register_read ("swap", swap_read);
 } /* void module_register */
index 4f5d0c4..3f73178 100644 (file)
@@ -1,23 +1,27 @@
 /**
  * collectd - src/syslog.c
- * Copyright (C) 2007  Florian Forster
+ * Copyright (C) 2007       Florian 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
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
@@ -48,7 +52,11 @@ static int sl_config (const char *key, const char *value)
        {
                log_level = parse_log_severity (value);
                if (log_level < 0)
+               {
+                       log_level = LOG_INFO;
+                       ERROR ("syslog: invalid loglevel [%s] defaulting to 'info'", value);
                        return (1);
+               }
        }
        else if (strcasecmp (key, "NotifyLevel") == 0)
        {
index 9641c75..c6b5bad 100644 (file)
@@ -1,19 +1,24 @@
 /**
  * collectd - src/table.c
- * Copyright (C) 2009  Sebastian Harl
+ * Copyright (C) 2009       Sebastian Harl
  *
- * 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.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Sebastian Harl <sh at tokkee.org>
index bcb1572..ab06338 100644 (file)
@@ -1,22 +1,27 @@
 /**
  * collectd - src/tail.c
- * Copyright (C) 2008  Florian octo Forster
+ * Copyright (C) 2008       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
@@ -28,6 +33,7 @@
  *  <Plugin tail>
  *    <File "/var/log/exim4/mainlog">
  *     Instance "exim"
+ *      Interval 60
  *     <Match>
  *       Regex "S=([1-9][0-9]*)"
  *       ExcludeRegex "U=root.*S="
@@ -46,11 +52,13 @@ struct ctail_config_match_s
   int flags;
   char *type;
   char *type_instance;
+  cdtime_t interval;
 };
 typedef struct ctail_config_match_s ctail_config_match_t;
 
 cu_tail_match_t **tail_match_list = NULL;
 size_t tail_match_list_num = 0;
+cdtime_t tail_match_list_intervals[255];
 
 static int ctail_config_add_match_dstype (ctail_config_match_t *cm,
     oconfig_item_t *ci)
@@ -72,6 +80,10 @@ static int ctail_config_add_match_dstype (ctail_config_match_t *cm,
       cm->flags |= UTILS_MATCH_CF_GAUGE_MAX;
     else if (strcasecmp ("GaugeLast", ci->values[0].value.string) == 0)
       cm->flags |= UTILS_MATCH_CF_GAUGE_LAST;
+    else if (strcasecmp ("GaugeInc", ci->values[0].value.string) == 0)
+      cm->flags |= UTILS_MATCH_CF_GAUGE_INC;
+    else if (strcasecmp ("GaugeAdd", ci->values[0].value.string) == 0)
+      cm->flags |= UTILS_MATCH_CF_GAUGE_ADD;
     else
       cm->flags = 0;
   }
@@ -123,7 +135,7 @@ static int ctail_config_add_match_dstype (ctail_config_match_t *cm,
 } /* int ctail_config_add_match_dstype */
 
 static int ctail_config_add_match (cu_tail_match_t *tm,
-    const char *plugin_instance, oconfig_item_t *ci)
+    const char *plugin_instance, oconfig_item_t *ci, cdtime_t interval)
 {
   ctail_config_match_t cm;
   int status;
@@ -190,7 +202,7 @@ static int ctail_config_add_match (cu_tail_match_t *tm,
   if (status == 0)
   {
     status = tail_match_add_match_simple (tm, cm.regex, cm.excluderegex,
-       cm.flags, "tail", plugin_instance, cm.type, cm.type_instance);
+       cm.flags, "tail", plugin_instance, cm.type, cm.type_instance, interval);
 
     if (status != 0)
     {
@@ -209,6 +221,7 @@ static int ctail_config_add_match (cu_tail_match_t *tm,
 static int ctail_config_add_file (oconfig_item_t *ci)
 {
   cu_tail_match_t *tm;
+  cdtime_t interval = 0;
   char *plugin_instance = NULL;
   int num_matches = 0;
   int status;
@@ -233,19 +246,20 @@ static int ctail_config_add_file (oconfig_item_t *ci)
   {
     oconfig_item_t *option = ci->children + i;
 
-    if (strcasecmp ("Match", option->key) == 0)
+    if (strcasecmp ("Instance", option->key) == 0)
+      status = cf_util_get_string (option, &plugin_instance);
+    else if (strcasecmp ("Interval", option->key) == 0)
+      cf_util_get_cdtime (option, &interval);
+    else if (strcasecmp ("Match", option->key) == 0)
     {
-      status = ctail_config_add_match (tm, plugin_instance, option);
+      status = ctail_config_add_match (tm, plugin_instance, option, interval);
       if (status == 0)
        num_matches++;
       /* Be mild with failed matches.. */
       status = 0;
     }
-    else if (strcasecmp ("Instance", option->key) == 0)
-      status = cf_util_get_string (option, &plugin_instance);
     else
     {
-      WARNING ("tail plugin: Option `%s' not allowed here.", option->key);
       status = -1;
     }
 
@@ -275,6 +289,7 @@ static int ctail_config_add_file (oconfig_item_t *ci)
 
     tail_match_list = temp;
     tail_match_list[tail_match_list_num] = tm;
+    tail_match_list_intervals[tail_match_list_num] = interval;
     tail_match_list_num++;
   }
 
@@ -300,41 +315,43 @@ static int ctail_config (oconfig_item_t *ci)
   return (0);
 } /* int ctail_config */
 
-static int ctail_init (void)
+static int ctail_read (user_data_t *ud)
 {
-  if (tail_match_list_num == 0)
+  int status;
+
+  status = tail_match_read ((cu_tail_match_t *)ud->data);
+  if (status != 0)
   {
-    WARNING ("tail plugin: File list is empty. Returning an error.");
+    ERROR ("tail plugin: tail_match_read failed.");
     return (-1);
   }
 
   return (0);
-} /* int ctail_init */
+} /* int ctail_read */
 
-static int ctail_read (void)
+static int ctail_init (void)
 {
-  int success = 0;
+  struct timespec cb_interval;
+  char str[255];
+  user_data_t ud;
   size_t i;
 
-  for (i = 0; i < tail_match_list_num; i++)
+  if (tail_match_list_num == 0)
   {
-    int status;
+    WARNING ("tail plugin: File list is empty. Returning an error.");
+    return (-1);
+  }
 
-    status = tail_match_read (tail_match_list[i]);
-    if (status != 0)
-    {
-      ERROR ("tail plugin: tail_match_read[%zu] failed.", i);
-    }
-    else
-    {
-      success++;
-    }
+  for (i = 0; i < tail_match_list_num; i++)
+  {
+    ud.data = (void *)tail_match_list[i];
+    ssnprintf(str, sizeof(str), "tail-%zu", i);
+    CDTIME_T_TO_TIMESPEC (tail_match_list_intervals[i], &cb_interval);
+    plugin_register_complex_read (NULL, str, ctail_read, &cb_interval, &ud);
   }
 
-  if (success == 0)
-    return (-1);
   return (0);
-} /* int ctail_read */
+} /* int ctail_init */
 
 static int ctail_shutdown (void)
 {
@@ -355,7 +372,6 @@ void module_register (void)
 {
   plugin_register_complex_config ("tail", ctail_config);
   plugin_register_init ("tail", ctail_init);
-  plugin_register_read ("tail", ctail_read);
   plugin_register_shutdown ("tail", ctail_shutdown);
 } /* void module_register */
 
index cb68048..5eaa427 100644 (file)
@@ -1,22 +1,27 @@
 /**
  * collectd - src/target_notification.c
- * Copyright (C) 2008  Florian Forster
+ * Copyright (C) 2008       Florian 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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index 1d7af5c..a85eced 100644 (file)
@@ -1,22 +1,27 @@
 /**
  * collectd - src/target_replace.c
- * Copyright (C) 2008  Florian Forster
+ * Copyright (C) 2008       Florian 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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index bef03e5..b29a02b 100644 (file)
@@ -2,21 +2,26 @@
  * collectd - src/target_scale.c
  * Copyright (C) 2008-2009  Florian 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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index 2fb9cee..41133e3 100644 (file)
@@ -1,22 +1,27 @@
 /**
  * collectd - src/target_set.c
- * Copyright (C) 2008  Florian Forster
+ * Copyright (C) 2008       Florian 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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index 25f4637..d85a181 100644 (file)
@@ -1,23 +1,27 @@
 /**
- * collectd - src/target_set.c
+ * collectd - src/target_v5upgrade.c
  * Copyright (C) 2008-2010  Florian Forster
  *
- * This program is free software; you can redistribute it and/or modify it
- * 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.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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
- * Lesser General Public License for more details.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index 6351c7b..5a04231 100644 (file)
@@ -17,7 +17,7 @@
  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  *
  * Author:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  *   Michael Stapelberg <michael+git at stapelberg.de>
  **/
 
@@ -219,13 +219,13 @@ static const char *tcp_state[] =
   "CLOSED",
   "LISTEN",
   "SYN_SENT",
-  "SYN_RCVD",
+  "SYN_RECV",
   "ESTABLISHED",
   "CLOSE_WAIT",
-  "FIN_WAIT_1",
+  "FIN_WAIT1",
   "CLOSING",
   "LAST_ACK",
-  "FIN_WAIT_2",
+  "FIN_WAIT2",
   "TIME_WAIT"
 };
 
index 2552ad3..201e182 100644 (file)
@@ -18,7 +18,7 @@
  *
  * Authors:
  *   Stefan Hacker <d0t at dbclan dot de>
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
@@ -439,7 +439,7 @@ static int tss2_vserver_gapl (FILE *read_fh, FILE *write_fh,
                status = tss2_receive_line (read_fh, buffer, sizeof (buffer));
                if (status != 0)
                {
-                       /* Set to NULL just to make sure noone uses these FHs anymore. */
+                       /* Set to NULL just to make sure no one uses these FHs anymore. */
                        read_fh = NULL;
                        write_fh = NULL;
                        ERROR ("teamspeak2 plugin: tss2_receive_line failed.");
@@ -564,7 +564,7 @@ static int tss2_read_vserver (vserver_list_t *vserver)
                status = tss2_receive_line (read_fh, buffer, sizeof (buffer));
                if (status != 0)
                {
-                       /* Set to NULL just to make sure noone uses these FHs anymore. */
+                       /* Set to NULL just to make sure no one uses these FHs anymore. */
                        read_fh = NULL;
                        write_fh = NULL;
                        ERROR ("teamspeak2 plugin: tss2_receive_line failed.");
diff --git a/src/tests/common_test.c b/src/tests/common_test.c
new file mode 100644 (file)
index 0000000..f65fcab
--- /dev/null
@@ -0,0 +1,246 @@
+/**
+ * collectd - src/tests/common_test.c
+ * Copyright (C) 2013       Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
+ */
+
+#include "tests/macros.h"
+#include "common.h"
+
+DEF_TEST(sstrncpy)
+{
+  char buffer[16] = "";
+  char *ptr = &buffer[4];
+  char *ret;
+
+  buffer[0] = buffer[1] = buffer[2] = buffer[3] = 0xff;
+  buffer[12] = buffer[13] = buffer[14] = buffer[15] = 0xff;
+
+  ret = sstrncpy (ptr, "foobar", 8);
+  OK(ret == ptr);
+  STREQ ("foobar", ptr);
+  OK(buffer[3] == buffer[12]);
+
+  ret = sstrncpy (ptr, "abc", 8);
+  OK(ret == ptr);
+  STREQ ("abc", ptr);
+  OK(buffer[3] == buffer[12]);
+
+  ret = sstrncpy (ptr, "collectd", 8);
+  OK(ret == ptr);
+  OK(ptr[7] == 0);
+  STREQ ("collect", ptr);
+  OK(buffer[3] == buffer[12]);
+
+  return (0);
+}
+
+DEF_TEST(ssnprintf)
+{
+  char buffer[16] = "";
+  char *ptr = &buffer[4];
+  int status;
+
+  buffer[0] = buffer[1] = buffer[2] = buffer[3] = 0xff;
+  buffer[12] = buffer[13] = buffer[14] = buffer[15] = 0xff;
+
+  status = ssnprintf (ptr, 8, "%i", 1337);
+  OK(status == 4);
+  STREQ ("1337", ptr);
+
+  status = ssnprintf (ptr, 8, "%s", "collectd");
+  OK(status == 8);
+  OK(ptr[7] == 0);
+  STREQ ("collect", ptr);
+  OK(buffer[3] == buffer[12]);
+
+  return (0);
+}
+
+DEF_TEST(sstrdup)
+{
+  char *ptr;
+
+  ptr = sstrdup ("collectd");
+  OK(ptr != NULL);
+  STREQ ("collectd", ptr);
+
+  sfree(ptr);
+  OK(ptr == NULL);
+
+  ptr = sstrdup (NULL);
+  OK(ptr == NULL);
+
+  return (0);
+}
+
+DEF_TEST(strsplit)
+{
+  char buffer[32];
+  char *fields[8];
+  int status;
+
+  strncpy (buffer, "foo bar", sizeof (buffer));
+  status = strsplit (buffer, fields, 8);
+  OK(status == 2);
+  STREQ ("foo", fields[0]);
+  STREQ ("bar", fields[1]);
+
+  strncpy (buffer, "foo \t bar", sizeof (buffer));
+  status = strsplit (buffer, fields, 8);
+  OK(status == 2);
+  STREQ ("foo", fields[0]);
+  STREQ ("bar", fields[1]);
+
+  strncpy (buffer, "one two\tthree\rfour\nfive", sizeof (buffer));
+  status = strsplit (buffer, fields, 8);
+  OK(status == 5);
+  STREQ ("one", fields[0]);
+  STREQ ("two", fields[1]);
+  STREQ ("three", fields[2]);
+  STREQ ("four", fields[3]);
+  STREQ ("five", fields[4]);
+
+  strncpy (buffer, "\twith trailing\n", sizeof (buffer));
+  status = strsplit (buffer, fields, 8);
+  OK(status == 2);
+  STREQ ("with", fields[0]);
+  STREQ ("trailing", fields[1]);
+
+  strncpy (buffer, "1 2 3 4 5 6 7 8 9 10 11 12 13", sizeof (buffer));
+  status = strsplit (buffer, fields, 8);
+  OK(status == 8);
+  STREQ ("7", fields[6]);
+  STREQ ("8", fields[7]);
+
+  strncpy (buffer, "single", sizeof (buffer));
+  status = strsplit (buffer, fields, 8);
+  OK(status == 1);
+  STREQ ("single", fields[0]);
+
+  strncpy (buffer, "", sizeof (buffer));
+  status = strsplit (buffer, fields, 8);
+  OK(status == 0);
+
+  return (0);
+}
+
+DEF_TEST(strjoin)
+{
+  char buffer[16];
+  char *fields[4];
+  int status;
+
+  fields[0] = "foo";
+  fields[1] = "bar";
+  fields[2] = "baz";
+  fields[3] = "qux";
+
+  status = strjoin (buffer, sizeof (buffer), fields, 2, "!");
+  OK(status == 7);
+  STREQ ("foo!bar", buffer);
+
+  status = strjoin (buffer, sizeof (buffer), fields, 1, "!");
+  OK(status == 3);
+  STREQ ("foo", buffer);
+
+  status = strjoin (buffer, sizeof (buffer), fields, 0, "!");
+  OK(status < 0);
+
+  status = strjoin (buffer, sizeof (buffer), fields, 2, "rcht");
+  OK(status == 10);
+  STREQ ("foorchtbar", buffer);
+
+  status = strjoin (buffer, sizeof (buffer), fields, 4, "");
+  OK(status == 12);
+  STREQ ("foobarbazqux", buffer);
+
+  status = strjoin (buffer, sizeof (buffer), fields, 4, "!");
+  OK(status == 15);
+  STREQ ("foo!bar!baz!qux", buffer);
+
+  fields[0] = "0123";
+  fields[1] = "4567";
+  fields[2] = "8901";
+  fields[3] = "2345";
+  status = strjoin (buffer, sizeof (buffer), fields, 4, "-");
+  OK(status < 0);
+
+  return (0);
+}
+
+DEF_TEST(strunescape)
+{
+  char buffer[16];
+  int status;
+
+  strncpy (buffer, "foo\\tbar", sizeof (buffer));
+  status = strunescape (buffer, sizeof (buffer));
+  OK(status == 0);
+  STREQ ("foo\tbar", buffer);
+
+  strncpy (buffer, "\\tfoo\\r\\n", sizeof (buffer));
+  status = strunescape (buffer, sizeof (buffer));
+  OK(status == 0);
+  STREQ ("\tfoo\r\n", buffer);
+
+  strncpy (buffer, "With \\\"quotes\\\"", sizeof (buffer));
+  status = strunescape (buffer, sizeof (buffer));
+  OK(status == 0);
+  STREQ ("With \"quotes\"", buffer);
+
+  /* Backslash before null byte */
+  strncpy (buffer, "\\tbackslash end\\", sizeof (buffer));
+  status = strunescape (buffer, sizeof (buffer));
+  OK(status != 0);
+  STREQ ("\tbackslash end", buffer);
+  return (0);
+
+  /* Backslash at buffer end */
+  strncpy (buffer, "\\t3\\56", sizeof (buffer));
+  status = strunescape (buffer, 4);
+  OK(status != 0);
+  OK(buffer[0] == '\t');
+  OK(buffer[1] == '3');
+  OK(buffer[2] == 0);
+  OK(buffer[3] == 0);
+  OK(buffer[4] == '5');
+  OK(buffer[5] == '6');
+  OK(buffer[6] == '7');
+
+  return (0);
+}
+
+int main (void)
+{
+  RUN_TEST(sstrncpy);
+  RUN_TEST(ssnprintf);
+  RUN_TEST(sstrdup);
+  RUN_TEST(strsplit);
+  RUN_TEST(strjoin);
+  RUN_TEST(strunescape);
+
+  END_TEST;
+}
+
+/* vim: set sw=2 sts=2 et : */
diff --git a/src/tests/macros.h b/src/tests/macros.h
new file mode 100644 (file)
index 0000000..5df1b83
--- /dev/null
@@ -0,0 +1,67 @@
+/**
+ * collectd - src/tests/macros.h
+ * Copyright (C) 2013       Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
+ */
+
+static int fail_count__ = 0;
+static int check_count__ = 0;
+
+#define DEF_TEST(func) static int test_##func ()
+
+#define RUN_TEST(func) do { \
+  int status; \
+  printf ("Testing %s ...\n", #func); \
+  status = test_ ## func (); \
+  printf ("%s.\n", (status == 0) ? "Success" : "FAILURE"); \
+  if (status != 0) { fail_count__++; } \
+} while (0)
+
+#define END_TEST exit ((fail_count__ == 0) ? 0 : 1);
+
+#define OK1(cond, text) do { \
+  _Bool result = (cond); \
+  printf ("%s %i - %s\n", result ? "ok" : "not ok", ++check_count__, text); \
+} while (0)
+#define OK(cond) OK1(cond, #cond)
+
+#define STREQ(expect, actual) do { \
+  if (strcmp (expect, actual) != 0) { \
+    printf ("not ok %i - %s incorrect: expected \"%s\", got \"%s\"\n", \
+        ++check_count__, #actual, expect, actual); \
+    return (-1); \
+  } \
+  printf ("ok %i - %s evaluates to \"%s\"\n", ++check_count__, #actual, expect); \
+} while (0)
+
+#define CHECK_NOT_NULL(expr) do { \
+  void *ptr_; \
+  ptr_ = (expr); \
+  OK1(ptr_ != NULL, #expr); \
+} while (0)
+
+#define CHECK_ZERO(expr) do { \
+  long status_; \
+  status_ = (long) (expr); \
+  OK1(status_ == 0L, #expr); \
+} while (0)
diff --git a/src/tests/mock/plugin.c b/src/tests/mock/plugin.c
new file mode 100644 (file)
index 0000000..8652880
--- /dev/null
@@ -0,0 +1,41 @@
+/**
+ * collectd - src/tests/mock/plugin.c
+ * Copyright (C) 2013       Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
+ */
+
+#include "plugin.h"
+
+void plugin_log (int level, char const *format, ...)
+{
+  char buffer[1024];
+  va_list ap;
+
+  va_start (ap, format);
+  vsnprintf (buffer, sizeof (buffer), format, ap);
+  va_end (ap);
+
+  printf ("plugin_log (%i, \"%s\");\n", level, buffer);
+}
+
+/* vim: set sw=2 sts=2 et : */
diff --git a/src/tests/mock/utils_cache.c b/src/tests/mock/utils_cache.c
new file mode 100644 (file)
index 0000000..6c78d64
--- /dev/null
@@ -0,0 +1,32 @@
+/**
+ * collectd - src/tests/mock/utils_cache.c
+ * Copyright (C) 2013       Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
+ */
+
+#include "utils_cache.h"
+
+gauge_t *uc_get_rate (const data_set_t *ds, const value_list_t *vl)
+{
+  return (NULL);
+}
diff --git a/src/tests/mock/utils_time.c b/src/tests/mock/utils_time.c
new file mode 100644 (file)
index 0000000..5edfe6f
--- /dev/null
@@ -0,0 +1,33 @@
+/**
+ * collectd - src/tests/mock/utils_time.c
+ * Copyright (C) 2013       Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
+ */
+
+#include "utils_time.h"
+
+cdtime_t cdtime (void)
+{
+  return (0);
+}
+
diff --git a/src/tests/test_common.c b/src/tests/test_common.c
new file mode 100644 (file)
index 0000000..c2eec95
--- /dev/null
@@ -0,0 +1,246 @@
+/**
+ * collectd - src/tests/test_common.c
+ * Copyright (C) 2013       Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
+ */
+
+#include "tests/macros.h"
+#include "common.h"
+
+DEF_TEST(sstrncpy)
+{
+  char buffer[16] = "";
+  char *ptr = &buffer[4];
+  char *ret;
+
+  buffer[0] = buffer[1] = buffer[2] = buffer[3] = 0xff;
+  buffer[12] = buffer[13] = buffer[14] = buffer[15] = 0xff;
+
+  ret = sstrncpy (ptr, "foobar", 8);
+  OK(ret == ptr);
+  STREQ ("foobar", ptr);
+  OK(buffer[3] == buffer[12]);
+
+  ret = sstrncpy (ptr, "abc", 8);
+  OK(ret == ptr);
+  STREQ ("abc", ptr);
+  OK(buffer[3] == buffer[12]);
+
+  ret = sstrncpy (ptr, "collectd", 8);
+  OK(ret == ptr);
+  OK(ptr[7] == 0);
+  STREQ ("collect", ptr);
+  OK(buffer[3] == buffer[12]);
+
+  return (0);
+}
+
+DEF_TEST(ssnprintf)
+{
+  char buffer[16] = "";
+  char *ptr = &buffer[4];
+  int status;
+
+  buffer[0] = buffer[1] = buffer[2] = buffer[3] = 0xff;
+  buffer[12] = buffer[13] = buffer[14] = buffer[15] = 0xff;
+
+  status = ssnprintf (ptr, 8, "%i", 1337);
+  OK(status == 4);
+  STREQ ("1337", ptr);
+
+  status = ssnprintf (ptr, 8, "%s", "collectd");
+  OK(status == 8);
+  OK(ptr[7] == 0);
+  STREQ ("collect", ptr);
+  OK(buffer[3] == buffer[12]);
+
+  return (0);
+}
+
+DEF_TEST(sstrdup)
+{
+  char *ptr;
+
+  ptr = sstrdup ("collectd");
+  OK(ptr != NULL);
+  STREQ ("collectd", ptr);
+
+  sfree(ptr);
+  OK(ptr == NULL);
+
+  ptr = sstrdup (NULL);
+  OK(ptr == NULL);
+
+  return (0);
+}
+
+DEF_TEST(strsplit)
+{
+  char buffer[32];
+  char *fields[8];
+  int status;
+
+  strncpy (buffer, "foo bar", sizeof (buffer));
+  status = strsplit (buffer, fields, 8);
+  OK(status == 2);
+  STREQ ("foo", fields[0]);
+  STREQ ("bar", fields[1]);
+
+  strncpy (buffer, "foo \t bar", sizeof (buffer));
+  status = strsplit (buffer, fields, 8);
+  OK(status == 2);
+  STREQ ("foo", fields[0]);
+  STREQ ("bar", fields[1]);
+
+  strncpy (buffer, "one two\tthree\rfour\nfive", sizeof (buffer));
+  status = strsplit (buffer, fields, 8);
+  OK(status == 5);
+  STREQ ("one", fields[0]);
+  STREQ ("two", fields[1]);
+  STREQ ("three", fields[2]);
+  STREQ ("four", fields[3]);
+  STREQ ("five", fields[4]);
+
+  strncpy (buffer, "\twith trailing\n", sizeof (buffer));
+  status = strsplit (buffer, fields, 8);
+  OK(status == 2);
+  STREQ ("with", fields[0]);
+  STREQ ("trailing", fields[1]);
+
+  strncpy (buffer, "1 2 3 4 5 6 7 8 9 10 11 12 13", sizeof (buffer));
+  status = strsplit (buffer, fields, 8);
+  OK(status == 8);
+  STREQ ("7", fields[6]);
+  STREQ ("8", fields[7]);
+
+  strncpy (buffer, "single", sizeof (buffer));
+  status = strsplit (buffer, fields, 8);
+  OK(status == 1);
+  STREQ ("single", fields[0]);
+
+  strncpy (buffer, "", sizeof (buffer));
+  status = strsplit (buffer, fields, 8);
+  OK(status == 0);
+
+  return (0);
+}
+
+DEF_TEST(strjoin)
+{
+  char buffer[16];
+  char *fields[4];
+  int status;
+
+  fields[0] = "foo";
+  fields[1] = "bar";
+  fields[2] = "baz";
+  fields[3] = "qux";
+
+  status = strjoin (buffer, sizeof (buffer), fields, 2, "!");
+  OK(status == 7);
+  STREQ ("foo!bar", buffer);
+
+  status = strjoin (buffer, sizeof (buffer), fields, 1, "!");
+  OK(status == 3);
+  STREQ ("foo", buffer);
+
+  status = strjoin (buffer, sizeof (buffer), fields, 0, "!");
+  OK(status < 0);
+
+  status = strjoin (buffer, sizeof (buffer), fields, 2, "rcht");
+  OK(status == 10);
+  STREQ ("foorchtbar", buffer);
+
+  status = strjoin (buffer, sizeof (buffer), fields, 4, "");
+  OK(status == 12);
+  STREQ ("foobarbazqux", buffer);
+
+  status = strjoin (buffer, sizeof (buffer), fields, 4, "!");
+  OK(status == 15);
+  STREQ ("foo!bar!baz!qux", buffer);
+
+  fields[0] = "0123";
+  fields[1] = "4567";
+  fields[2] = "8901";
+  fields[3] = "2345";
+  status = strjoin (buffer, sizeof (buffer), fields, 4, "-");
+  OK(status < 0);
+
+  return (0);
+}
+
+DEF_TEST(strunescape)
+{
+  char buffer[16];
+  int status;
+
+  strncpy (buffer, "foo\\tbar", sizeof (buffer));
+  status = strunescape (buffer, sizeof (buffer));
+  OK(status == 0);
+  STREQ ("foo\tbar", buffer);
+
+  strncpy (buffer, "\\tfoo\\r\\n", sizeof (buffer));
+  status = strunescape (buffer, sizeof (buffer));
+  OK(status == 0);
+  STREQ ("\tfoo\r\n", buffer);
+
+  strncpy (buffer, "With \\\"quotes\\\"", sizeof (buffer));
+  status = strunescape (buffer, sizeof (buffer));
+  OK(status == 0);
+  STREQ ("With \"quotes\"", buffer);
+
+  /* Backslash before null byte */
+  strncpy (buffer, "\\tbackslash end\\", sizeof (buffer));
+  status = strunescape (buffer, sizeof (buffer));
+  OK(status != 0);
+  STREQ ("\tbackslash end", buffer);
+  return (0);
+
+  /* Backslash at buffer end */
+  strncpy (buffer, "\\t3\\56", sizeof (buffer));
+  status = strunescape (buffer, 4);
+  OK(status != 0);
+  OK(buffer[0] == '\t');
+  OK(buffer[1] == '3');
+  OK(buffer[2] == 0);
+  OK(buffer[3] == 0);
+  OK(buffer[4] == '5');
+  OK(buffer[5] == '6');
+  OK(buffer[6] == '7');
+
+  return (0);
+}
+
+int main (void)
+{
+  RUN_TEST(sstrncpy);
+  RUN_TEST(ssnprintf);
+  RUN_TEST(sstrdup);
+  RUN_TEST(strsplit);
+  RUN_TEST(strjoin);
+  RUN_TEST(strunescape);
+
+  END_TEST;
+}
+
+/* vim: set sw=2 sts=2 et : */
diff --git a/src/tests/test_utils_avltree.c b/src/tests/test_utils_avltree.c
new file mode 100644 (file)
index 0000000..00d14e1
--- /dev/null
@@ -0,0 +1,82 @@
+/**
+ * collectd - src/tests/test_utils_avltree.c
+ * Copyright (C) 2013       Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
+ */
+
+#include "tests/macros.h"
+#include "collectd.h"
+#include "utils_avltree.h"
+
+static int compare_total_count = 0;
+#define RESET_COUNTS() do { compare_total_count = 0; } while (0)
+
+static int compare_callback (void const *v0, void const *v1)
+{
+  assert (v0 != NULL);
+  assert (v1 != NULL);
+
+  compare_total_count++;
+  return (strcmp (v0, v1));
+}
+
+DEF_TEST(success)
+{
+  c_avl_tree_t *t;
+  char key_orig[] = "foo";
+  char value_orig[] = "bar";
+  char *key_ret = NULL;
+  char *value_ret = NULL;
+
+  RESET_COUNTS ();
+  t = c_avl_create (compare_callback);
+  OK (t != NULL);
+
+  OK (c_avl_insert (t, key_orig, value_orig) == 0);
+  OK (c_avl_size (t) == 1);
+
+  /* Key already exists. */
+  OK (c_avl_insert (t, "foo", "qux") > 0);
+
+  OK (c_avl_get (t, "foo", (void *) &value_ret) == 0);
+  OK (value_ret == &value_orig[0]);
+
+  key_ret = value_ret = NULL;
+  OK (c_avl_remove (t, "foo", (void *) &key_ret, (void *) &value_ret) == 0);
+  OK (key_ret == &key_orig[0]);
+  OK (value_ret == &value_orig[0]);
+  OK (c_avl_size (t) == 0);
+
+  c_avl_destroy (t);
+
+  return (0);
+}
+
+int main (void)
+{
+  RUN_TEST(success);
+
+  END_TEST;
+}
+
+/* vim: set sw=2 sts=2 et : */
diff --git a/src/tests/test_utils_heap.c b/src/tests/test_utils_heap.c
new file mode 100644 (file)
index 0000000..91c90e5
--- /dev/null
@@ -0,0 +1,85 @@
+/**
+ * collectd - src/tests/test_utils_heap.c
+ * Copyright (C) 2013       Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
+ */
+
+#include "collectd.h"
+#include "tests/macros.h"
+#include "utils_heap.h"
+
+static int compare (void const *v0, void const *v1)
+{
+  int const *i0 = v0;
+  int const *i1 = v1;
+
+  if ((*i0) < (*i1))
+    return -1;
+  else if ((*i0) > (*i1))
+    return 1;
+  else
+    return 0;
+}
+
+DEF_TEST(simple)
+{
+  int values[] = { 9, 5, 6, 1, 3, 4, 0, 8, 2, 7 };
+  int i;
+  c_heap_t *h;
+
+  CHECK_NOT_NULL(h = c_heap_create (compare));
+  for (i = 0; i < 10; i++)
+    CHECK_ZERO(c_heap_insert (h, &values[i]));
+
+  for (i = 0; i < 5; i++)
+  {
+    int *ret = NULL;
+    CHECK_NOT_NULL(ret = c_heap_get_root(h));
+    OK(*ret == i);
+  }
+
+  CHECK_ZERO(c_heap_insert (h, &values[6] /* = 0 */));
+  CHECK_ZERO(c_heap_insert (h, &values[3] /* = 1 */));
+  CHECK_ZERO(c_heap_insert (h, &values[8] /* = 2 */));
+  CHECK_ZERO(c_heap_insert (h, &values[4] /* = 3 */));
+  CHECK_ZERO(c_heap_insert (h, &values[5] /* = 4 */));
+
+  for (i = 0; i < 10; i++)
+  {
+    int *ret = NULL;
+    CHECK_NOT_NULL(ret = c_heap_get_root(h));
+    OK(*ret == i);
+  }
+
+  c_heap_destroy(h);
+  return (0);
+}
+
+int main (void)
+{
+  RUN_TEST(simple);
+
+  END_TEST;
+}
+
+/* vim: set sw=2 sts=2 et : */
diff --git a/src/tests/test_utils_mount.c b/src/tests/test_utils_mount.c
new file mode 100644 (file)
index 0000000..ba6b99b
--- /dev/null
@@ -0,0 +1,101 @@
+/**
+ * collectd - src/tests/test_utils_mount.c
+ * Copyright (C) 2013       Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
+ */
+
+#include "tests/macros.h"
+#include "collectd.h"
+#include "utils_mount.h"
+
+DEF_TEST(cu_mount_checkoption)
+{
+  char line_opts[] = "foo=one,bar=two,qux=three";
+  char *foo = strstr (line_opts, "foo");
+  char *bar = strstr (line_opts, "bar");
+  char *qux = strstr (line_opts, "qux");
+
+  char line_bool[] = "one,two,three";
+  char *one = strstr (line_bool, "one");
+  char *two = strstr (line_bool, "two");
+  char *three = strstr (line_bool, "three");
+
+  /* Normal operation */
+  OK (foo == cu_mount_checkoption (line_opts, "foo", 0));
+  OK (bar == cu_mount_checkoption (line_opts, "bar", 0));
+  OK (qux == cu_mount_checkoption (line_opts, "qux", 0));
+  OK (NULL == cu_mount_checkoption (line_opts, "unknown", 0));
+
+  OK (one == cu_mount_checkoption (line_bool, "one", 0));
+  OK (two == cu_mount_checkoption (line_bool, "two", 0));
+  OK (three == cu_mount_checkoption (line_bool, "three", 0));
+  OK (NULL == cu_mount_checkoption (line_bool, "four", 0));
+
+  /* Shorter and longer parts */
+  OK (foo == cu_mount_checkoption (line_opts, "fo", 0));
+  OK (bar == cu_mount_checkoption (line_opts, "bar=", 0));
+  OK (qux == cu_mount_checkoption (line_opts, "qux=thr", 0));
+
+  OK (one == cu_mount_checkoption (line_bool, "o", 0));
+  OK (two == cu_mount_checkoption (line_bool, "tw", 0));
+  OK (three == cu_mount_checkoption (line_bool, "thr", 0));
+
+  /* "full" flag */
+  OK (one == cu_mount_checkoption (line_bool, "one", 1));
+  OK (two == cu_mount_checkoption (line_bool, "two", 1));
+  OK (three == cu_mount_checkoption (line_bool, "three", 1));
+  OK (NULL == cu_mount_checkoption (line_bool, "four", 1));
+
+  OK (NULL == cu_mount_checkoption (line_bool, "o", 1));
+  OK (NULL == cu_mount_checkoption (line_bool, "tw", 1));
+  OK (NULL == cu_mount_checkoption (line_bool, "thr", 1));
+
+  return (0);
+}
+DEF_TEST(cu_mount_getoptionvalue)
+{
+  char line_opts[] = "foo=one,bar=two,qux=three";
+  char line_bool[] = "one,two,three";
+
+  STREQ ("one", cu_mount_getoptionvalue (line_opts, "foo="));
+  STREQ ("two", cu_mount_getoptionvalue (line_opts, "bar="));
+  STREQ ("three", cu_mount_getoptionvalue (line_opts, "qux="));
+  OK (NULL == cu_mount_getoptionvalue (line_opts, "unknown="));
+
+  STREQ ("", cu_mount_getoptionvalue (line_bool, "one"));
+  STREQ ("", cu_mount_getoptionvalue (line_bool, "two"));
+  STREQ ("", cu_mount_getoptionvalue (line_bool, "three"));
+  OK (NULL == cu_mount_getoptionvalue (line_bool, "four"));
+
+  return (0);
+}
+
+int main (void)
+{
+  RUN_TEST(cu_mount_checkoption);
+  RUN_TEST(cu_mount_getoptionvalue);
+
+  END_TEST;
+}
+
+/* vim: set sw=2 sts=2 et : */
diff --git a/src/tests/test_utils_vl_lookup.c b/src/tests/test_utils_vl_lookup.c
new file mode 100644 (file)
index 0000000..842f3fd
--- /dev/null
@@ -0,0 +1,249 @@
+/**
+ * collectd - src/tests/test_utils_vl_lookup.c
+ * Copyright (C) 2012       Florian Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Florian Forster <octo at collectd.org>
+ **/
+
+#include "tests/macros.h"
+#include "collectd.h"
+#include "utils_vl_lookup.h"
+
+static _Bool expect_new_obj = 0;
+static _Bool have_new_obj = 0;
+
+static identifier_t last_class_ident;
+static identifier_t last_obj_ident;
+
+static data_source_t dsrc_test = { "value", DS_TYPE_DERIVE, 0.0, NAN };
+static data_set_t const ds_test = { "test", 1, &dsrc_test };
+
+static data_source_t dsrc_unknown = { "value", DS_TYPE_DERIVE, 0.0, NAN };
+static data_set_t const ds_unknown = { "unknown", 1, &dsrc_unknown };
+
+static int lookup_obj_callback (data_set_t const *ds,
+    value_list_t const *vl,
+    void *user_class, void *user_obj)
+{
+  identifier_t *class = user_class;
+  identifier_t *obj = user_obj;
+
+  OK1(expect_new_obj == have_new_obj,
+      (expect_new_obj ? "New obj is created." : "Updating existing obj."));
+
+  memcpy (&last_class_ident, class, sizeof (last_class_ident));
+  memcpy (&last_obj_ident, obj, sizeof (last_obj_ident));
+
+  if (strcmp (obj->plugin_instance, "failure") == 0)
+    return (-1);
+
+  return (0);
+}
+
+static void *lookup_class_callback (data_set_t const *ds,
+    value_list_t const *vl, void *user_class)
+{
+  identifier_t *class = user_class;
+  identifier_t *obj;
+
+  OK(expect_new_obj);
+
+  memcpy (&last_class_ident, class, sizeof (last_class_ident));
+  
+  obj = malloc (sizeof (*obj));
+  strncpy (obj->host, vl->host, sizeof (obj->host));
+  strncpy (obj->plugin, vl->plugin, sizeof (obj->plugin));
+  strncpy (obj->plugin_instance, vl->plugin_instance, sizeof (obj->plugin_instance));
+  strncpy (obj->type, vl->type, sizeof (obj->type));
+  strncpy (obj->type_instance, vl->type_instance, sizeof (obj->type_instance));
+
+  have_new_obj = 1;
+
+  return ((void *) obj);
+}
+
+static void checked_lookup_add (lookup_t *obj, /* {{{ */
+    char const *host,
+    char const *plugin, char const *plugin_instance,
+    char const *type, char const *type_instance,
+    unsigned int group_by)
+{
+  identifier_t ident;
+  void *user_class;
+
+  memset (&ident, 0, sizeof (ident));
+  strncpy (ident.host, host, sizeof (ident.host));
+  strncpy (ident.plugin, plugin, sizeof (ident.plugin));
+  strncpy (ident.plugin_instance, plugin_instance, sizeof (ident.plugin_instance));
+  strncpy (ident.type, type, sizeof (ident.type));
+  strncpy (ident.type_instance, type_instance, sizeof (ident.type_instance));
+
+  user_class = malloc (sizeof (ident));
+  memmove (user_class, &ident, sizeof (ident));
+
+  OK(lookup_add (obj, &ident, group_by, user_class) == 0);
+} /* }}} void test_add */
+
+static int checked_lookup_search (lookup_t *obj,
+    char const *host,
+    char const *plugin, char const *plugin_instance,
+    char const *type, char const *type_instance,
+    _Bool expect_new)
+{
+  int status;
+  value_list_t vl = VALUE_LIST_STATIC;
+  data_set_t const *ds = &ds_unknown;
+
+  strncpy (vl.host, host, sizeof (vl.host));
+  strncpy (vl.plugin, plugin, sizeof (vl.plugin));
+  strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
+  strncpy (vl.type, type, sizeof (vl.type));
+  strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+
+  if (strcmp (vl.type, "test") == 0)
+    ds = &ds_test;
+
+  expect_new_obj = expect_new;
+  have_new_obj = 0;
+
+  status = lookup_search (obj, ds, &vl);
+  return (status);
+}
+
+static lookup_t *checked_lookup_create (void)
+{
+  lookup_t *obj = lookup_create (
+      lookup_class_callback,
+      lookup_obj_callback,
+      (void *) free,
+      (void *) free);
+  OK(obj != NULL);
+  return (obj);
+}
+
+DEF_TEST(group_by_specific_host)
+{
+  lookup_t *obj = checked_lookup_create ();
+
+  checked_lookup_add (obj, "/.*/", "test", "", "test", "/.*/", LU_GROUP_BY_HOST);
+  checked_lookup_search (obj, "host0", "test", "", "test", "0",
+      /* expect new = */ 1);
+  checked_lookup_search (obj, "host0", "test", "", "test", "1",
+      /* expect new = */ 0);
+  checked_lookup_search (obj, "host1", "test", "", "test", "0",
+      /* expect new = */ 1);
+  checked_lookup_search (obj, "host1", "test", "", "test", "1",
+      /* expect new = */ 0);
+
+  lookup_destroy (obj);
+  return (0);
+}
+
+DEF_TEST(group_by_any_host)
+{
+  lookup_t *obj = checked_lookup_create ();
+
+  checked_lookup_add (obj, "/.*/", "/.*/", "/.*/", "test", "/.*/", LU_GROUP_BY_HOST);
+  checked_lookup_search (obj, "host0", "plugin0", "", "test", "0",
+      /* expect new = */ 1);
+  checked_lookup_search (obj, "host0", "plugin0", "", "test", "1",
+      /* expect new = */ 0);
+  checked_lookup_search (obj, "host0", "plugin1", "", "test", "0",
+      /* expect new = */ 0);
+  checked_lookup_search (obj, "host0", "plugin1", "", "test", "1",
+      /* expect new = */ 0);
+  checked_lookup_search (obj, "host1", "plugin0", "", "test", "0",
+      /* expect new = */ 1);
+  checked_lookup_search (obj, "host1", "plugin0", "", "test", "1",
+      /* expect new = */ 0);
+  checked_lookup_search (obj, "host1", "plugin1", "", "test", "0",
+      /* expect new = */ 0);
+  checked_lookup_search (obj, "host1", "plugin1", "", "test", "1",
+      /* expect new = */ 0);
+
+  lookup_destroy (obj);
+  return (0);
+}
+
+DEF_TEST(multiple_lookups)
+{
+  lookup_t *obj = checked_lookup_create ();
+  int status;
+
+  checked_lookup_add (obj, "/.*/", "plugin0", "", "test", "/.*/", LU_GROUP_BY_HOST);
+  checked_lookup_add (obj, "/.*/", "/.*/", "", "test", "ti0", LU_GROUP_BY_HOST);
+
+  status = checked_lookup_search (obj, "host0", "plugin1", "", "test", "",
+      /* expect new = */ 0);
+  assert (status == 0);
+  status = checked_lookup_search (obj, "host0", "plugin0", "", "test", "",
+      /* expect new = */ 1);
+  assert (status == 1);
+  status = checked_lookup_search (obj, "host0", "plugin1", "", "test", "ti0",
+      /* expect new = */ 1);
+  assert (status == 1);
+  status = checked_lookup_search (obj, "host0", "plugin0", "", "test", "ti0",
+      /* expect new = */ 0);
+  assert (status == 2);
+
+  lookup_destroy (obj);
+  return (0);
+}
+
+DEF_TEST(regex)
+{
+  lookup_t *obj = checked_lookup_create ();
+
+  checked_lookup_add (obj, "/^db[0-9]\\./", "cpu", "/.*/", "cpu", "/.*/",
+      LU_GROUP_BY_TYPE_INSTANCE);
+  checked_lookup_search (obj, "db0.example.com", "cpu", "0", "cpu", "user",
+      /* expect new = */ 1);
+  checked_lookup_search (obj, "db0.example.com", "cpu", "0", "cpu", "idle",
+      /* expect new = */ 1);
+  checked_lookup_search (obj, "db0.example.com", "cpu", "1", "cpu", "user",
+      /* expect new = */ 0);
+  checked_lookup_search (obj, "db0.example.com", "cpu", "1", "cpu", "idle",
+      /* expect new = */ 0);
+  checked_lookup_search (obj, "app0.example.com", "cpu", "0", "cpu", "user",
+      /* expect new = */ 0);
+  checked_lookup_search (obj, "app0.example.com", "cpu", "0", "cpu", "idle",
+      /* expect new = */ 0);
+  checked_lookup_search (obj, "db1.example.com", "cpu", "0", "cpu", "user",
+      /* expect new = */ 0);
+  checked_lookup_search (obj, "db1.example.com", "cpu", "0", "cpu", "idle",
+      /* expect new = */ 0);
+  checked_lookup_search (obj, "db1.example.com", "cpu", "0", "cpu", "system",
+      /* expect new = */ 1);
+
+  lookup_destroy (obj);
+  return (0);
+}
+
+int main (int argc, char **argv) /* {{{ */
+{
+  RUN_TEST(group_by_specific_host);
+  RUN_TEST(group_by_any_host);
+  RUN_TEST(multiple_lookups);
+  RUN_TEST(regex);
+
+  END_TEST;
+} /* }}} int main */
index 887dbca..8815a00 100644 (file)
 #include "plugin.h"
 #include "utils_avltree.h"
 #include "utils_cache.h"
+#include "utils_threshold.h"
 
 #include <assert.h>
 #include <pthread.h>
 
 /*
- * Private data structures
- * {{{ */
-#define UT_FLAG_INVERT  0x01
-#define UT_FLAG_PERSIST 0x02
-#define UT_FLAG_PERCENTAGE 0x04
-#define UT_FLAG_INTERESTING 0x08
-#define UT_FLAG_PERSIST_OK 0x10
-typedef struct threshold_s
-{
-  char host[DATA_MAX_NAME_LEN];
-  char plugin[DATA_MAX_NAME_LEN];
-  char plugin_instance[DATA_MAX_NAME_LEN];
-  char type[DATA_MAX_NAME_LEN];
-  char type_instance[DATA_MAX_NAME_LEN];
-  char data_source[DATA_MAX_NAME_LEN];
-  gauge_t warning_min;
-  gauge_t warning_max;
-  gauge_t failure_min;
-  gauge_t failure_max;
-  gauge_t hysteresis;
-  unsigned int flags;
-  int hits;
-  struct threshold_s *next;
-} threshold_t;
-/* }}} */
-
-/*
- * Private (static) variables
- * {{{ */
-static c_avl_tree_t   *threshold_tree = NULL;
-static pthread_mutex_t threshold_lock = PTHREAD_MUTEX_INITIALIZER;
-/* }}} */
-
-/*
  * Threshold management
  * ====================
  * The following functions add, delete, search, etc. configured thresholds to
  * the underlying AVL trees.
  */
-/*
- * threshold_t *threshold_get
- *
- * Retrieve one specific threshold configuration. For looking up a threshold
- * matching a value_list_t, see "threshold_search" below. Returns NULL if the
- * specified threshold doesn't exist.
- */
-static threshold_t *threshold_get (const char *hostname,
-    const char *plugin, const char *plugin_instance,
-    const char *type, const char *type_instance)
-{ /* {{{ */
-  char name[6 * DATA_MAX_NAME_LEN];
-  threshold_t *th = NULL;
-
-  format_name (name, sizeof (name),
-      (hostname == NULL) ? "" : hostname,
-      (plugin == NULL) ? "" : plugin, plugin_instance,
-      (type == NULL) ? "" : type, type_instance);
-  name[sizeof (name) - 1] = '\0';
-
-  if (c_avl_get (threshold_tree, name, (void *) &th) == 0)
-    return (th);
-  else
-    return (NULL);
-} /* }}} threshold_t *threshold_get */
 
 /*
  * int ut_threshold_add
@@ -171,58 +113,6 @@ static int ut_threshold_add (const threshold_t *th)
   return (status);
 } /* }}} int ut_threshold_add */
 
-/* 
- * threshold_t *threshold_search
- *
- * Searches for a threshold configuration using all the possible variations of
- * "Host", "Plugin" and "Type" blocks. Returns NULL if no threshold could be
- * found.
- * XXX: This is likely the least efficient function in collectd.
- */
-static threshold_t *threshold_search (const value_list_t *vl)
-{ /* {{{ */
-  threshold_t *th;
-
-  if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance,
-         vl->type, vl->type_instance)) != NULL)
-    return (th);
-  else if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance,
-         vl->type, NULL)) != NULL)
-    return (th);
-  else if ((th = threshold_get (vl->host, vl->plugin, NULL,
-         vl->type, vl->type_instance)) != NULL)
-    return (th);
-  else if ((th = threshold_get (vl->host, vl->plugin, NULL,
-         vl->type, NULL)) != NULL)
-    return (th);
-  else if ((th = threshold_get (vl->host, "", NULL,
-         vl->type, vl->type_instance)) != NULL)
-    return (th);
-  else if ((th = threshold_get (vl->host, "", NULL,
-         vl->type, NULL)) != NULL)
-    return (th);
-  else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance,
-         vl->type, vl->type_instance)) != NULL)
-    return (th);
-  else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance,
-         vl->type, NULL)) != NULL)
-    return (th);
-  else if ((th = threshold_get ("", vl->plugin, NULL,
-         vl->type, vl->type_instance)) != NULL)
-    return (th);
-  else if ((th = threshold_get ("", vl->plugin, NULL,
-         vl->type, NULL)) != NULL)
-    return (th);
-  else if ((th = threshold_get ("", "", NULL,
-         vl->type, vl->type_instance)) != NULL)
-    return (th);
-  else if ((th = threshold_get ("", "", NULL,
-         vl->type, NULL)) != NULL)
-    return (th);
-
-  return (NULL);
-} /* }}} threshold_t *threshold_search */
-
 /*
  * Configuration
  * =============
@@ -629,7 +519,9 @@ static int ut_report_state (const data_set_t *ds,
           ": Value is no longer missing.");
     else
       status = ssnprintf (buf, bufsize,
-          ": All data sources are within range again.");
+          ": All data sources are within range again. "
+          "Current value of \"%s\" is %f.",
+          ds->ds[ds_index].name, values[ds_index]);
     buf += status;
     bufsize -= status;
   }
@@ -747,23 +639,40 @@ static int ut_check_one_data_source (const data_set_t *ds,
 
   /* XXX: This is an experimental code, not optimized, not fast, not reliable,
    * and probably, do not work as you expect. Enjoy! :D */
-  if ( (th->hysteresis > 0) && ((prev_state = uc_get_state(ds,vl)) != STATE_OKAY) )
-  {
-    switch(prev_state)
+  if (th->hysteresis > 0)
+  {
+    prev_state = uc_get_state(ds,vl);
+    /* The purpose of hysteresis is elliminating flapping state when the value
+     * oscilates around the thresholds. In other words, what is important is
+     * the previous state; if the new value would trigger a transition, make
+     * sure that we artificially widen the range which is considered to apply
+     * for the previous state, and only trigger the notification if the value
+     * is outside of this expanded range.
+     *
+     * There is no hysteresis for the OKAY state.
+     * */
+    gauge_t hysteresis_for_warning = 0, hysteresis_for_failure = 0;
+    switch (prev_state)
     {
       case STATE_ERROR:
-       if ( (!isnan (th->failure_min) && ((th->failure_min + th->hysteresis) < values[ds_index])) ||
-            (!isnan (th->failure_max) && ((th->failure_max - th->hysteresis) > values[ds_index])) )
-         return (STATE_OKAY);
-       else
-         is_failure++;
+        hysteresis_for_failure = th->hysteresis;
+        break;
       case STATE_WARNING:
-       if ( (!isnan (th->warning_min) && ((th->warning_min + th->hysteresis) < values[ds_index])) ||
-            (!isnan (th->warning_max) && ((th->warning_max - th->hysteresis) > values[ds_index])) )
-         return (STATE_OKAY);
-       else
-         is_warning++;
-     }
+        hysteresis_for_warning = th->hysteresis;
+        break;
+      case STATE_OKAY:
+        /* do nothing -- the hysteresis only applies to the non-normal states */
+        break;
+    }
+
+    if ((!isnan (th->failure_min) && (th->failure_min + hysteresis_for_failure > values[ds_index]))
+       || (!isnan (th->failure_max) && (th->failure_max - hysteresis_for_failure < values[ds_index])))
+      is_failure++;
+
+    if ((!isnan (th->warning_min) && (th->warning_min + hysteresis_for_warning > values[ds_index]))
+       || (!isnan (th->warning_max) && (th->warning_max - hysteresis_for_warning < values[ds_index])))
+      is_warning++;
+
   }
   else { /* no hysteresis */
     if ((!isnan (th->failure_min) && (th->failure_min > values[ds_index]))
@@ -773,7 +682,7 @@ static int ut_check_one_data_source (const data_set_t *ds,
     if ((!isnan (th->warning_min) && (th->warning_min > values[ds_index]))
        || (!isnan (th->warning_max) && (th->warning_max < values[ds_index])))
       is_warning++;
- }
 }
 
   if (is_failure != 0)
     return (STATE_ERROR);
@@ -862,7 +771,7 @@ static int ut_check_one_threshold (const data_set_t *ds,
  *
  * Gets a list of matching thresholds and searches for the worst status by one
  * of the thresholds. Then reports that status using the ut_report_state
- * function above. 
+ * function above.
  * Returns zero on success and if no threshold has been configured. Returns
  * less than zero on failure.
  */
@@ -993,7 +902,7 @@ int ut_config (oconfig_item_t *ci)
   th.hits = 0;
   th.hysteresis = 0;
   th.flags = UT_FLAG_INTERESTING; /* interesting by default */
-    
+
   for (i = 0; i < ci->children_num; i++)
   {
     oconfig_item_t *option = ci->children + i;
index 97cc4cc..fcdea23 100644 (file)
@@ -53,6 +53,7 @@ dns_response          value:DERIVE:0:U
 dns_transfer           value:DERIVE:0:U
 dns_update             value:DERIVE:0:U
 dns_zops               value:DERIVE:0:U
+drbd_resource  value:DERIVE:0:U
 duration               seconds:GAUGE:0:U
 email_check            value:GAUGE:0:U
 email_count            value:GAUGE:0:U
@@ -105,6 +106,13 @@ mysql_handler              value:DERIVE:0:U
 mysql_locks            value:DERIVE:0:U
 mysql_log_position     value:DERIVE:0:U
 mysql_octets           rx:DERIVE:0:U, tx:DERIVE:0:U
+mysql_bpool_pages      value:GAUGE:0:U
+mysql_bpool_counters   value:DERIVE:0:U
+mysql_innodb_data      value:DERIVE:0:U
+mysql_innodb_dblwr     value:DERIVE:0:U
+mysql_innodb_rows      value:DERIVE:0:U
+mysql_select           value:DERIVE:0:U
+mysql_sort             value:DERIVE:0:U
 nfs_procedure          value:DERIVE:0:U
 nginx_connections      value:GAUGE:0:U
 nginx_requests         value:DERIVE:0:U
@@ -134,6 +142,7 @@ ping_stddev         value:GAUGE:0:65535
 ping                   value:GAUGE:0:65535
 players                        value:GAUGE:0:1000000
 power                  value:GAUGE:0:U
+pressure                       value:GAUGE:0:U
 protocol_counter       value:DERIVE:0:U
 ps_code                        value:GAUGE:0:9223372036854775807
 ps_count               processes:GAUGE:0:1000000, threads:GAUGE:0:1000000
index 111742b..f0af60e 100644 (file)
@@ -59,7 +59,7 @@ L<rrdcreate(1)>
 =head1 AUTHOR
 
 B<collectd> has been written by Florian Forster
-E<lt>octoE<nbsp>atE<nbsp>verplant.orgE<gt>.
+E<lt>octoE<nbsp>atE<nbsp>collectd.orgE<gt>.
 
 This manpage has been written by Sebastian Harl
 E<lt>shE<nbsp>atE<nbsp>tokkee.orgE<gt>.
index 10cb4f2..b3cb8cf 100644 (file)
@@ -1,22 +1,27 @@
 /**
  * collectd - src/types_list.c
- * Copyright (C) 2007  Florian octo Forster
+ * Copyright (C) 2007       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index 8fe6ce8..f375a2f 100644 (file)
@@ -1,27 +1,32 @@
-#ifndef TYPES_LIST_H
-#define TYPES_LIST_H 1
-
 /**
  * collectd - src/types_list.h
- * Copyright (C) 2007  Florian octo Forster
+ * Copyright (C) 2007       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
+#ifndef TYPES_LIST_H
+#define TYPES_LIST_H 1
+
 int read_types_list (const char *file);
 
 #endif /* TYPES_LIST_H */
index 2c1665f..664c018 100644 (file)
@@ -2,21 +2,26 @@
  * collectd - src/unixsock.c
  * Copyright (C) 2007,2008  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
- *   Florian octo Forster <octo at verplant.org>
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
@@ -26,6 +31,7 @@
 
 #include "utils_cmd_flush.h"
 #include "utils_cmd_getval.h"
+#include "utils_cmd_getthreshold.h"
 #include "utils_cmd_listval.h"
 #include "utils_cmd_putval.h"
 #include "utils_cmd_putnotif.h"
@@ -281,6 +287,10 @@ static void *us_handle_client (void *arg)
                {
                        handle_getval (fhout, buffer);
                }
+               else if (strcasecmp (fields[0], "getthreshold") == 0)
+               {
+                       handle_getthreshold (fhout, buffer);
+               }
                else if (strcasecmp (fields[0], "putval") == 0)
                {
                        handle_putval (fhout, buffer);
index 064c3ce..345128d 100644 (file)
@@ -241,7 +241,7 @@ static int uptime_read (void)
        gauge_t uptime;
        time_t elapsed;
 
-       /* calculate the ammount of time elapsed since boot, AKA uptime */
+       /* calculate the amount of time elapsed since boot, AKA uptime */
        elapsed = time (NULL) - boottime;
 
        uptime = (gauge_t) elapsed;
index 1e33754..781e778 100644 (file)
@@ -21,7 +21,7 @@
  * Authors:
  *   Sebastian Harl <sh at tokkee.org>
  *   Niki W. Waibel <niki.waibel at newlogic.com>
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  *   Oleg King <king2 at kaluga.ru>
  **/
 
index f71b1fd..04e5403 100644 (file)
@@ -2,22 +2,26 @@
  * collectd - src/utils_avltree.c
  * Copyright (C) 2006,2007  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
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "config.h"
index 10fb5cb..1e0f271 100644 (file)
@@ -2,22 +2,26 @@
  * collectd - src/utils_avltree.h
  * Copyright (C) 2006,2007  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
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * 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.
- *
- * 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
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #ifndef UTILS_AVLTREE_H
index fa6e660..9d86781 100644 (file)
@@ -2,20 +2,25 @@
  * collectd - src/utils_cache.c
  * Copyright (C) 2007-2010  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
+ * Authors:
  *   Florian octo Forster <octo at collectd.org>
  **/
 
@@ -68,7 +73,9 @@ static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
 
 static int cache_compare (const cache_entry_t *a, const cache_entry_t *b)
 {
+#if COLLECT_DEBUG
   assert ((a != NULL) && (b != NULL));
+#endif
   return (strcmp (a->name, b->name));
 } /* int cache_compare */
 
index 87f93c0..16039aa 100644 (file)
@@ -1,22 +1,27 @@
 /**
  * collectd - src/utils_cache.h
- * Copyright (C) 2007  Florian octo Forster
+ * Copyright (C) 2007       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
- *   Florian octo Forster <octo at verplant.org>
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #ifndef UTILS_CACHE_H
index 3584f3b..30da630 100644 (file)
@@ -1,24 +1,29 @@
 /**
  * collectd - src/utils_cmd_flush.c
- * Copyright (C) 2008  Sebastian Harl
- * Copyright (C) 2008  Florian Forster
+ * Copyright (C) 2008       Sebastian Harl
+ * Copyright (C) 2008       Florian 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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Sebastian "tokkee" Harl <sh at tokkee.org>
- *   Florian "octo" Forster <octo at verplant.org>
+ *   Florian "octo" Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
@@ -168,7 +173,7 @@ int handle_flush (FILE *fh, char *buffer)
        }
        else
        {
-               plugin_flush (NULL, timeout, NULL);
+               plugin_flush (NULL, DOUBLE_TO_CDTIME_T (timeout), NULL);
                print_to_socket (fh, "0 Done\n");
        }
 
index 6b54ace..f43b257 100644 (file)
@@ -1,21 +1,26 @@
 /**
  * collectd - src/utils_cmd_flush.h
- * Copyright (C) 2008  Sebastian Harl
+ * Copyright (C) 2008       Sebastian Harl
  *
- * 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.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
+ * Authors:
  *   Sebastian "tokkee" Harl <sh at tokkee.org>
  **/
 
index e8c29fa..80babe3 100644 (file)
@@ -1,28 +1,34 @@
 /**
- * collectd - src/utils_cms_getthreshold.c
+ * collectd - src/utils_cmd_getthreshold.c
  * Copyright (C) 2008,2009  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
- *   Florian octo Forster <octo at verplant.org>
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
 #include "common.h"
 #include "plugin.h"
 
+#include "utils_avltree.h"
 #include "utils_threshold.h"
 #include "utils_parse_option.h" /* for `parse_string' */
 #include "utils_cmd_getthreshold.h"
index 5481cfd..8d581c8 100644 (file)
@@ -1,22 +1,27 @@
 /**
  * collectd - src/utils_cmd_getthreshold.h
- * Copyright (C) 2009  Florian octo Forster
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
- *   Florian octo Forster <octo at verplant.org>
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #ifndef UTILS_CMD_GETTHRESHOLD_H
index ce3e28e..354c553 100644 (file)
@@ -1,22 +1,27 @@
 /**
- * collectd - src/utils_cms_getval.c
- * Copyright (C) 2008  Florian octo Forster
+ * collectd - src/utils_cmd_getval.c
+ * Copyright (C) 2008       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
- *   Florian octo Forster <octo at verplant.org>
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index ed9ca9a..5e12f69 100644 (file)
@@ -1,22 +1,27 @@
 /**
- * collectd - src/utils_cms_getval.h
- * Copyright (C) 2008  Florian octo Forster
+ * collectd - src/utils_cmd_getval.h
+ * Copyright (C) 2008       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
- *   Florian octo Forster <octo at verplant.org>
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #ifndef UTILS_CMD_GETVAL_H
index ef66af5..d9dc5c1 100644 (file)
@@ -1,22 +1,27 @@
 /**
- * collectd - src/utils_cms_listval.c
- * Copyright (C) 2008  Florian octo Forster
+ * collectd - src/utils_cmd_listval.c
+ * Copyright (C) 2008       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
- *   Florian octo Forster <octo at verplant.org>
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index 0c72d67..fc125bc 100644 (file)
@@ -1,22 +1,27 @@
 /**
- * collectd - src/utils_cms_listval.h
- * Copyright (C) 2008  Florian octo Forster
+ * collectd - src/utils_cmd_listval.h
+ * Copyright (C) 2008       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
- *   Florian octo Forster <octo at verplant.org>
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #ifndef UTILS_CMD_LISTVAL_H
index d3cf383..e14a258 100644 (file)
@@ -1,22 +1,27 @@
 /**
- * collectd - src/utils_cms_putnotif.c
- * Copyright (C) 2008  Florian octo Forster
+ * collectd - src/utils_cmd_putnotif.c
+ * Copyright (C) 2008       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
- *   Florian octo Forster <octo at verplant.org>
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
@@ -73,6 +78,18 @@ static int set_option (notification_t *n, const char *option, const char *value)
   DEBUG ("utils_cmd_putnotif: set_option (option = %s, value = %s);",
       option, value);
 
+  /* Add a meta option in the form: <type>:<key> */
+  if (option[0] != '\0' && option[1] == ':') {
+    /* Refuse empty key */
+    if (option[2] == '\0')
+      return (1);
+
+    if (option[0] == 's')
+      return plugin_notification_meta_add_string (n, option + 2, value);
+    else
+      return (1);
+  }
+
   if (strcasecmp ("severity", option) == 0)
     return (set_option_severity (n, value));
   else if (strcasecmp ("time", option) == 0)
index 7e900b5..9d699ec 100644 (file)
@@ -1,22 +1,27 @@
 /**
- * collectd - src/utils_cms_putnotif.h
- * Copyright (C) 2008  Florian octo Forster
+ * collectd - src/utils_cmd_putnotif.h
+ * Copyright (C) 2008       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
- *   Florian octo Forster <octo at verplant.org>
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #ifndef UTILS_CMD_PUTNOTIF_H
index 4cbc2f1..366b413 100644 (file)
@@ -1,22 +1,27 @@
 /**
- * collectd - src/utils_cms_putval.c
+ * collectd - src/utils_cmd_putval.c
  * Copyright (C) 2007-2009  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
- *   Florian octo Forster <octo at verplant.org>
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index 9c92fd3..795409e 100644 (file)
@@ -1,22 +1,27 @@
 /**
- * collectd - src/utils_cms_putval.h
- * Copyright (C) 2007  Florian octo Forster
+ * collectd - src/utils_cmd_putval.h
+ * Copyright (C) 2007       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
- *   Florian octo Forster <octo at verplant.org>
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #ifndef UTILS_CMD_PUTVAL_H
index c3752bc..6193614 100644 (file)
@@ -1,23 +1,28 @@
 /**
  * collectd - src/utils_complain.c
  * Copyright (C) 2006-2013  Florian octo Forster
- * Copyright (C) 2008  Sebastian tokkee Harl
+ * Copyright (C) 2008       Sebastian tokkee Harl
  *
- * 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.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  *   Sebastian tokkee Harl <sh at tokkee.org>
  **/
 
index 028dda6..390f961 100644 (file)
@@ -1,23 +1,28 @@
 /**
  * collectd - src/utils_complain.h
  * Copyright (C) 2006-2013  Florian octo Forster
- * Copyright (C) 2008  Sebastian tokkee Harl
+ * Copyright (C) 2008       Sebastian tokkee Harl
  *
- * 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.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  *   Sebastian tokkee Harl <sh at tokkee.org>
  **/
 
diff --git a/src/utils_crc32.c b/src/utils_crc32.c
new file mode 100644 (file)
index 0000000..4c6d694
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ *  COPYRIGHT (C) 1986 Gary S. Brown.  You may use this program, or
+ *  code or tables extracted from it, as desired without restriction.
+ *
+ *  First, the polynomial itself and its table of feedback terms.  The
+ *  polynomial is
+ *  X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0
+ *
+ *  Note that we take it "backwards" and put the highest-order term in
+ *  the lowest-order bit.  The X^32 term is "implied"; the LSB is the
+ *  X^31 term, etc.  The X^0 term (usually shown as "+1") results in
+ *  the MSB being 1
+ *
+ *  Note that the usual hardware shift register implementation, which
+ *  is what we're using (we're merely optimizing it by doing eight-bit
+ *  chunks at a time) shifts bits into the lowest-order term.  In our
+ *  implementation, that means shifting towards the right.  Why do we
+ *  do it this way?  Because the calculated CRC must be transmitted in
+ *  order from highest-order term to lowest-order term.  UARTs transmit
+ *  characters in order from LSB to MSB.  By storing the CRC this way
+ *  we hand it to the UART in the order low-byte to high-byte; the UART
+ *  sends each low-bit to hight-bit; and the result is transmission bit
+ *  by bit from highest- to lowest-order term without requiring any bit
+ *  shuffling on our part.  Reception works similarly
+ *
+ *  The feedback terms table consists of 256, 32-bit entries.  Notes
+ *
+ *      The table can be generated at runtime if desired; code to do so
+ *      is shown later.  It might not be obvious, but the feedback
+ *      terms simply represent the results of eight shift/xor opera
+ *      tions for all combinations of data and CRC register values
+ *
+ *      The values must be right-shifted by eight bits by the "updcrc
+ *      logic; the shift must be unsigned (bring in zeroes).  On some
+ *      hardware you could probably optimize the shift in assembler by
+ *      using byte-swap instructions
+ *      polynomial $edb88320
+ */
+
+#include <sys/types.h>
+
+u_int32_t               crc32_buffer(const u_char *, size_t);
+static unsigned int     crc32_tab[] = {
+       0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
+       0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
+       0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
+       0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
+       0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
+       0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
+       0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
+       0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
+       0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
+       0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
+       0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
+       0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
+       0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
+       0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
+       0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
+       0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
+       0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
+       0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
+       0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
+       0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
+       0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
+       0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
+       0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
+       0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
+       0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
+       0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
+       0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
+       0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
+       0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
+       0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
+       0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
+       0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
+       0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
+       0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
+       0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
+       0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
+       0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
+       0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
+       0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
+       0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
+       0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
+       0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
+       0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
+       0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
+       0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
+       0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
+       0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
+       0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
+       0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
+       0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
+       0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
+       0x2d02ef8dL
+};
+
+/* Return a 32-bit CRC of the contents of the buffer. */
+
+u_int32_t
+crc32_buffer(const u_char *s, size_t len)
+{
+    size_t      i;
+    u_int32_t   ret;
+
+    ret = 0;
+    for (i = 0;  i < len;  i++)
+        ret = crc32_tab[(ret ^ s[i]) & 0xff] ^ (ret >> 8);
+    return ret;
+}
diff --git a/src/utils_crc32.h b/src/utils_crc32.h
new file mode 100644 (file)
index 0000000..822a62b
--- /dev/null
@@ -0,0 +1,32 @@
+/**
+ * collectd - src/utils_crc32.h
+ * Copyright (C) 2014       Pierre-Yves Ritschard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Pierre-Yves Ritschard <pyr at spootnik.org>
+ */
+
+#ifndef UTILS_CRC32_H
+#define UTILS_CRC32_H 1
+
+u_int32_t               crc32_buffer(const u_char *, size_t);
+
+#endif
index aadf9c5..893d590 100644 (file)
@@ -2,21 +2,26 @@
  * collectd - src/utils_db_query.c
  * Copyright (C) 2008,2009  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
@@ -38,6 +43,8 @@ struct udb_result_s
   size_t   instances_num;
   char   **values;
   size_t   values_num;
+  char   **metadata;
+  size_t   metadata_num;
 
   udb_result_t *next;
 }; /* }}} */
@@ -59,8 +66,10 @@ struct udb_result_preparation_area_s /* {{{ */
   const   data_set_t *ds;
   size_t *instances_pos;
   size_t *values_pos;
+  size_t *metadata_pos;
   char  **instances_buffer;
   char  **values_buffer;
+  char  **metadata_buffer;
 
   struct udb_result_preparation_area_s *next;
 }; /* }}} */
@@ -188,6 +197,7 @@ static int udb_result_submit (udb_result_t *r, /* {{{ */
 {
   value_list_t vl = VALUE_LIST_INIT;
   size_t i;
+  int status;
 
   assert (r != NULL);
   assert (r_area->ds != NULL);
@@ -253,8 +263,38 @@ static int udb_result_submit (udb_result_t *r, /* {{{ */
   vl.type_instance[sizeof (vl.type_instance) - 1] = 0;
   /* }}} */
 
+  /* Annotate meta data. {{{ */
+  if (r->metadata_num > 0)
+  {
+    vl.meta = meta_data_create ();
+    if (vl.meta == NULL)
+    {
+      ERROR ("db query utils:: meta_data_create failed.");
+      return (-ENOMEM);
+    }
+
+    for (i = 0; i < r->metadata_num; i++)
+    {
+      status = meta_data_add_string (vl.meta, r->metadata[i],
+          r_area->metadata_buffer[i]);
+      if (status != 0)
+      {
+        ERROR ("db query utils:: meta_data_add_string failed.");
+        meta_data_destroy (vl.meta);
+        vl.meta = NULL;
+        return (status);
+      }
+    }
+  }
+  /* }}} */
+
   plugin_dispatch_values (&vl);
 
+  if (r->metadata_num > 0)
+  {
+    meta_data_destroy (vl.meta);
+    vl.meta = NULL;
+  }
   sfree (vl.values);
   return (0);
 } /* }}} void udb_result_submit */
@@ -268,8 +308,10 @@ static void udb_result_finish_result (udb_result_t const *r, /* {{{ */
   prep_area->ds = NULL;
   sfree (prep_area->instances_pos);
   sfree (prep_area->values_pos);
+  sfree (prep_area->metadata_pos);
   sfree (prep_area->instances_buffer);
   sfree (prep_area->values_buffer);
+  sfree (prep_area->metadata_buffer);
 } /* }}} void udb_result_finish_result */
 
 static int udb_result_handle_result (udb_result_t *r, /* {{{ */
@@ -287,6 +329,9 @@ static int udb_result_handle_result (udb_result_t *r, /* {{{ */
   for (i = 0; i < r->values_num; i++)
     r_area->values_buffer[i] = column_values[r_area->values_pos[i]];
 
+  for (i = 0; i < r->metadata_num; i++)
+    r_area->metadata_buffer[i] = column_values[r_area->metadata_pos[i]];
+
   return udb_result_submit (r, r_area, q, q_area);
 } /* }}} int udb_result_handle_result */
 
@@ -303,14 +348,17 @@ static int udb_result_prepare_result (udb_result_t const *r, /* {{{ */
   prep_area->ds = NULL; \
   sfree (prep_area->instances_pos); \
   sfree (prep_area->values_pos); \
+  sfree (prep_area->metadata_pos); \
   sfree (prep_area->instances_buffer); \
   sfree (prep_area->values_buffer); \
+  sfree (prep_area->metadata_buffer); \
   return (status)
 
   /* Make sure previous preparations are cleaned up. */
   udb_result_finish_result (r, prep_area);
   prep_area->instances_pos = NULL;
   prep_area->values_pos = NULL;
+  prep_area->metadata_pos = NULL;
 
   /* Read `ds' and check number of values {{{ */
   prep_area->ds = plugin_get_ds (r->type);
@@ -333,8 +381,8 @@ static int udb_result_prepare_result (udb_result_t const *r, /* {{{ */
   }
   /* }}} */
 
-  /* Allocate r->instances_pos, r->values_pos, r->instances_buffer, and
-   * r->values_buffer {{{ */
+  /* Allocate r->instances_pos, r->values_pos, r->metadata_post,
+   * r->instances_buffer, r->values_buffer, and r->metadata_buffer {{{ */
   if (r->instances_num > 0)
   {
     prep_area->instances_pos
@@ -369,6 +417,23 @@ static int udb_result_prepare_result (udb_result_t const *r, /* {{{ */
     ERROR ("db query utils: udb_result_prepare_result: malloc failed.");
     BAIL_OUT (-ENOMEM);
   }
+
+  prep_area->metadata_pos
+    = (size_t *) calloc (r->metadata_num, sizeof (size_t));
+  if (prep_area->metadata_pos == NULL)
+  {
+    ERROR ("db query utils: udb_result_prepare_result: malloc failed.");
+    BAIL_OUT (-ENOMEM);
+  }
+
+  prep_area->metadata_buffer
+    = (char **) calloc (r->metadata_num, sizeof (char *));
+  if (prep_area->metadata_buffer == NULL)
+  {
+    ERROR ("db query utils: udb_result_prepare_result: malloc failed.");
+    BAIL_OUT (-ENOMEM);
+  }
+
   /* }}} */
 
   /* Determine the position of the instance columns {{{ */
@@ -417,6 +482,29 @@ static int udb_result_prepare_result (udb_result_t const *r, /* {{{ */
     }
   } /* }}} for (i = 0; i < r->values_num; i++) */
 
+  /* Determine the position of the metadata columns {{{ */
+  for (i = 0; i < r->metadata_num; i++)
+  {
+    size_t j;
+
+    for (j = 0; j < column_num; j++)
+    {
+      if (strcasecmp (r->metadata[i], column_names[j]) == 0)
+      {
+        prep_area->metadata_pos[i] = j;
+        break;
+      }
+    }
+
+    if (j >= column_num)
+    {
+      ERROR ("db query utils: udb_result_prepare_result: "
+          "Metadata column `%s' could not be found.",
+          r->values[i]);
+      BAIL_OUT (-ENOENT);
+    }
+  } /* }}} for (i = 0; i < r->metadata_num; i++) */
+
 #undef BAIL_OUT
   return (0);
 } /* }}} int udb_result_prepare_result */
@@ -438,6 +526,10 @@ static void udb_result_free (udb_result_t *r) /* {{{ */
     sfree (r->values[i]);
   sfree (r->values);
 
+  for (i = 0; i < r->metadata_num; i++)
+    sfree (r->metadata[i]);
+  sfree (r->metadata);
+
   udb_result_free (r->next);
 
   sfree (r);
@@ -468,6 +560,7 @@ static int udb_result_create (const char *query_name, /* {{{ */
   r->instance_prefix = NULL;
   r->instances = NULL;
   r->values = NULL;
+  r->metadata = NULL;
   r->next = NULL;
 
   /* Fill the `udb_result_t' structure.. */
@@ -484,6 +577,8 @@ static int udb_result_create (const char *query_name, /* {{{ */
       status = udb_config_add_string (&r->instances, &r->instances_num, child);
     else if (strcasecmp ("ValuesFrom", child->key) == 0)
       status = udb_config_add_string (&r->values, &r->values_num, child);
+    else if (strcasecmp ("MetadataFrom", child->key) == 0)
+      status = udb_config_add_string (&r->metadata, &r->metadata_num, child);
     else
     {
       WARNING ("db query utils: Query `%s': Option `%s' not allowed here.",
index b6f4cea..08b10bd 100644 (file)
@@ -2,21 +2,26 @@
  * collectd - src/utils_db_query.h
  * Copyright (C) 2008,2009  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #ifndef UTILS_DB_QUERY_H
index 655c61e..712b1ae 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * collectd - src/utils_dns.c
- * Modifications Copyright (C) 2006  Florian octo Forster
- * Copyright (C) 2002  The Measurement Factory, Inc.
+ * Copyright (C) 2006       Florian octo Forster
+ * Copyright (C) 2002       The Measurement Factory, Inc.
  * All rights reserved.
  * 
  * Redistribution and use in source and binary forms, with or without
@@ -30,7 +30,7 @@
  *
  * Authors:
  *   The Measurement Factory, Inc. <http://www.measurement-factory.com/>
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
 #define _BSD_SOURCE
index 56213af..83f0ea4 100644 (file)
@@ -1,8 +1,7 @@
-#ifndef COLLECTD_UTILS_DNS_H
-#define COLLECTD_UTILS_DNS_H 1
 /*
  * collectd - src/utils_dns.h
- * Copyright (C) 2006  Florian octo Forster
+ * Copyright (C) 2006       Florian octo Forster
+ * Copyright (C) 2002       The Measurement Factory, Inc.
  * All rights reserved.
  * 
  * Redistribution and use in source and binary forms, with or without
  * POSSIBILITY OF SUCH DAMAGE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   The Measurement Factory, Inc. <http://www.measurement-factory.com/>
+ *   Florian octo Forster <octo at collectd.org>
  */
 
+#ifndef COLLECTD_UTILS_DNS_H
+#define COLLECTD_UTILS_DNS_H 1
+
 #include "config.h"
 
 #include <arpa/nameser.h>
index 97f21a1..70b8908 100644 (file)
@@ -1,22 +1,27 @@
 /**
  * collectd - src/utils_fbhash.c
- * Copyright (C) 2009  Florian octo Forster
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
@@ -253,7 +258,7 @@ char *fbh_get (fbhash_t *h, const char *key) /* {{{ */
 
   pthread_mutex_lock (&h->lock);
 
-  /* TODO: Checking this everytime may be a bit much..? */
+  /* TODO: Checking this every time may be a bit much..? */
   fbh_check_file (h);
 
   status = c_avl_get (h->tree, key, (void *) &value);
index 0a0305e..d9206a0 100644 (file)
@@ -1,22 +1,27 @@
 /**
  * collectd - src/utils_fbhash.h
- * Copyright (C) 2009  Florian octo Forster
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #ifndef UTILS_FBHASH_H
index bbc3dfd..355eaf1 100644 (file)
@@ -1,22 +1,27 @@
 /**
  * collectd - src/utils_format_json.c
- * Copyright (C) 2009  Florian octo Forster
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index c902e27..a56913d 100644 (file)
@@ -1,22 +1,27 @@
 /**
- * collectd - src/utils_format_json.c
- * Copyright (C) 2009  Florian octo Forster
+ * collectd - src/utils_format_json.h
+ * Copyright (C) 2009       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #ifndef UTILS_FORMAT_JSON_H
index f8f7405..1b5dca7 100644 (file)
@@ -1,23 +1,27 @@
 /**
  * collectd - src/utils_heap.c
- * Copyright (C) 2009  Florian octo Forster
+ * Copyright (C) 2009       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
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include <stdlib.h>
index 6428006..6d71c43 100644 (file)
@@ -1,23 +1,27 @@
 /**
  * collectd - src/utils_heap.h
- * Copyright (C) 2009  Florian octo Forster
+ * Copyright (C) 2009       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
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #ifndef UTILS_HEAP_H
index de42d0f..0ad252b 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * collectd - src/utils_ignorelist.c
  * Copyright (C) 2006 Lubos Stanek <lubek at users.sourceforge.net>
- * Copyright (C) 2008 Florian Forster <octo at verplant.org>
+ * Copyright (C) 2008 Florian Forster <octo at collectd.org>
  *
  * This program is free software; you can redistribute it and/
  * or modify it under the terms of the GNU General Public Li-
@@ -20,7 +20,7 @@
  *
  * Authors:
  *   Lubos Stanek <lubek at users.sourceforge.net>
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 /**
  * ignorelist handles plugin's list of configured collectable
index 94da211..91ddd5f 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * collectd - src/utils_latency.c
- * Copyright (C) 2013  Florian Forster
+ * Copyright (C) 2013       Florian Forster
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -128,7 +128,7 @@ cdtime_t latency_counter_get_average (latency_counter_t *lc) /* {{{ */
 {
   double average;
 
-  if (lc == NULL)
+  if ((lc == NULL) || (lc->num == 0))
     return (0);
 
   average = CDTIME_T_TO_DOUBLE (lc->sum) / ((double) lc->num);
@@ -146,7 +146,7 @@ cdtime_t latency_counter_get_percentile (latency_counter_t *lc,
   int sum;
   size_t i;
 
-  if ((lc == NULL) || !((percent > 0.0) && (percent < 100.0)))
+  if ((lc == NULL) || (lc->num == 0) || !((percent > 0.0) && (percent < 100.0)))
     return (0);
 
   /* Find index i so that at least "percent" events are within i+1 ms. */
index 3787c77..9930b72 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * collectd - src/utils_latency.h
- * Copyright (C) 2013  Florian Forster
+ * Copyright (C) 2013       Florian Forster
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
index 6a0c6f0..09c9834 100644 (file)
@@ -1,24 +1,27 @@
 /**
  * collectd - src/utils_llist.c
- * Copyright (C) 2006 Florian Forster <octo at verplant.org>
+ * Copyright (C) 2006       Florian Forster <octo at collectd.org>
  *
- * This program is free software; you can redistribute it and/
- * or modify it under the terms of the GNU General Public Li-
- * cence as published by the Free Software Foundation; only
- * version 2 of the Licence is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * This program is distributed in the hope that it will be use-
- * ful, but WITHOUT ANY WARRANTY; without even the implied war-
- * ranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public Licence for more details.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * You should have received a copy of the GNU General Public
- * Licence along with this program; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
- * USA.
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  */
 
 #include "config.h"
index 19d8d94..59bf2e4 100644 (file)
@@ -1,24 +1,27 @@
 /**
  * collectd - src/utils_llist.h
- * Copyright (C) 2006 Florian Forster <octo at verplant.org>
+ * Copyright (C) 2006       Florian Forster <octo at collectd.org>
  *
- * This program is free software; you can redistribute it and/
- * or modify it under the terms of the GNU General Public Li-
- * cence as published by the Free Software Foundation; only
- * version 2 of the Licence is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * This program is distributed in the hope that it will be use-
- * ful, but WITHOUT ANY WARRANTY; without even the implied war-
- * ranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public Licence for more details.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * You should have received a copy of the GNU General Public
- * Licence along with this program; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
- * USA.
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  */
 
 #ifndef UTILS_LLIST_H
index 062bcfe..b024c69 100644 (file)
@@ -1,23 +1,27 @@
 /**
  * collectd - src/utils_match.c
- * Copyright (C) 2008  Florian octo Forster
+ * Copyright (C) 2008       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
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
@@ -80,6 +84,13 @@ static int default_callback (const char __attribute__((unused)) *str,
     gauge_t value;
     char *endptr = NULL;
 
+    if (data->ds_type & UTILS_MATCH_CF_GAUGE_INC)
+    {
+      data->value.gauge = isnan (data->value.gauge) ? 1 : data->value.gauge + 1;
+      data->values_num++;
+      return(0);
+    }
+
     if (matches_num < 2)
       return (-1);
 
@@ -108,6 +119,10 @@ static int default_callback (const char __attribute__((unused)) *str,
       if (data->value.gauge < value)
        data->value.gauge = value;
     }
+    else if (data->ds_type & UTILS_MATCH_CF_GAUGE_ADD)
+    {
+      data->value.gauge += value;
+    }
     else
     {
       ERROR ("utils_match: default_callback: obj->ds_type is invalid!");
index 36abe30..705a609 100644 (file)
@@ -1,23 +1,27 @@
 /**
  * collectd - src/utils_match.h
- * Copyright (C) 2008  Florian octo Forster
+ * Copyright (C) 2008       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
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #ifndef UTILS_MATCH_H
 #include "plugin.h"
 
 /*
- * Defines
+ * Each type may have 12 sub-types
+ * 0x1000 = 1000000000000
+ *          ^             <- Type bit
+ *           ^^^^^^^^^^^^ <- Subtype bits
  */
-#define UTILS_MATCH_DS_TYPE_GAUGE    0x10
-#define UTILS_MATCH_DS_TYPE_COUNTER  0x20
-#define UTILS_MATCH_DS_TYPE_DERIVE   0x40
-#define UTILS_MATCH_DS_TYPE_ABSOLUTE 0x80
+#define UTILS_MATCH_DS_TYPE_GAUGE    0x1000
+#define UTILS_MATCH_DS_TYPE_COUNTER  0x2000
+#define UTILS_MATCH_DS_TYPE_DERIVE   0x4000
+#define UTILS_MATCH_DS_TYPE_ABSOLUTE 0x8000
 
 #define UTILS_MATCH_CF_GAUGE_AVERAGE 0x01
 #define UTILS_MATCH_CF_GAUGE_MIN     0x02
 #define UTILS_MATCH_CF_GAUGE_MAX     0x04
 #define UTILS_MATCH_CF_GAUGE_LAST    0x08
+#define UTILS_MATCH_CF_GAUGE_INC     0x10
+#define UTILS_MATCH_CF_GAUGE_ADD     0x20
 
 #define UTILS_MATCH_CF_COUNTER_SET   0x01
 #define UTILS_MATCH_CF_COUNTER_ADD   0x02
index 83f789b..bc0077f 100644 (file)
@@ -119,7 +119,7 @@ char *cu_mount_checkoption(char *line, char *keyword, int full);
   DESCRIPTION
        The cu_mount_checkoption() function is a replacement of
        char *hasmntopt(const struct mntent *mnt, const char *opt).
-       In fact hasmntopt() just looks for the first occurence of the
+       In fact hasmntopt() just looks for the first occurrence of the
        characters at opt in mnt->mnt_opts. cu_mount_checkoption()
        checks for the *option* keyword in line, starting at the
        first character of line or after a ','.
index 820f14f..56e65ea 100644 (file)
@@ -1,22 +1,27 @@
 /**
  * collectd - src/utils_parse_option.c
- * Copyright (C) 2008  Florian Forster
+ * Copyright (C) 2008       Florian 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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
- *   Florian octo Forster <octo at verplant.org>
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
@@ -127,7 +132,7 @@ int parse_option (char **ret_buffer, char **ret_key, char **ret_value)
 
   /* Look for the equal sign */
   buffer = key;
-  while (isalnum ((int) *buffer) || *buffer == '_')
+  while (isalnum ((int) *buffer) || *buffer == '_' || *buffer == ':')
     buffer++;
   if ((*buffer != '=') || (buffer == key))
     return (1);
index 1dfb3ae..01b73d1 100644 (file)
@@ -1,22 +1,27 @@
 /**
  * collectd - src/utils_parse_option.h
- * Copyright (C) 2008  Florian Forster
+ * Copyright (C) 2008       Florian 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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
- *   Florian octo Forster <octo at verplant.org>
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #ifndef UTILS_PARSE_OPTION
index a34e0da..de74c0a 100644 (file)
@@ -2,18 +2,23 @@
  * collectd - src/utils_rrdcreate.c
  * Copyright (C) 2006-2013  Florian octo Forster
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <octo at collectd.org>
index fdfd6ec..14daadf 100644 (file)
@@ -2,18 +2,23 @@
  * collectd - src/utils_rrdcreate.h
  * Copyright (C) 2008-2013  Florian octo Forster
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <octo at collectd.org>
index a49f6db..2f28eb9 100644 (file)
@@ -1,19 +1,24 @@
 /**
  * collectd - src/utils_subst.c
- * Copyright (C) 2008  Sebastian Harl
+ * Copyright (C) 2008       Sebastian Harl
  *
- * 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.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Sebastian "tokkee" Harl <sh at tokkee.org>
index 4387b85..9085286 100644 (file)
@@ -1,19 +1,24 @@
 /**
  * collectd - src/utils_subst.h
- * Copyright (C) 2008  Sebastian Harl
- *
- * 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.
- *
- * 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.
- *
- * 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
+ * Copyright (C) 2008       Sebastian Harl
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Sebastian "tokkee" Harl <sh at tokkee.org>
index 0b31262..fe5dca8 100644 (file)
@@ -1,24 +1,29 @@
 /**
  * collectd - src/utils_tail.c
  * Copyright (C) 2007-2008  C-Ware, Inc.
- * Copyright (C) 2008  Florian Forster
+ * Copyright (C) 2008       Florian 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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Author:
  *   Luke Heberling <lukeh at c-ware.com>
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  *
  * Description:
  *   Encapsulates useful code for plugins which must watch for appends to
index c479319..6fb7013 100644 (file)
@@ -2,18 +2,23 @@
  * collectd - src/utils_tail.h
  * Copyright (C) 2007-2008  C-Ware, Inc.
  *
- * 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.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Author:
  *   Luke Heberling <lukeh at c-ware.com>
index 8ae2208..8776ad1 100644 (file)
@@ -3,22 +3,27 @@
  * Copyright (C) 2007-2008  C-Ware, Inc.
  * Copyright (C) 2008       Florian 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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Author:
  *   Luke Heberling <lukeh at c-ware.com>
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  *
  * Description:
  *   Encapsulates useful code to plugins which must parse a log file.
@@ -37,6 +42,7 @@ struct cu_tail_match_simple_s
   char plugin_instance[DATA_MAX_NAME_LEN];
   char type[DATA_MAX_NAME_LEN];
   char type_instance[DATA_MAX_NAME_LEN];
+  cdtime_t interval;
 };
 typedef struct cu_tail_match_simple_s cu_tail_match_simple_t;
 
@@ -54,6 +60,7 @@ struct cu_tail_match_s
   int flags;
   cu_tail_t *tail;
 
+  cdtime_t interval;
   cu_tail_match_match_t *matches;
   size_t matches_num;
 };
@@ -88,6 +95,7 @@ static int simple_submit_match (cu_match_t *match, void *user_data)
   sstrncpy (vl.type_instance, data->type_instance,
       sizeof (vl.type_instance));
 
+  vl.interval = data->interval;
   plugin_dispatch_values (&vl);
 
   if (match_value->ds_type & UTILS_MATCH_DS_TYPE_GAUGE)
@@ -180,6 +188,7 @@ int tail_match_add_match (cu_tail_match_t *obj, cu_match_t *match,
   obj->matches = temp;
   obj->matches_num++;
 
+  DEBUG ("tail_match_add_match interval %lf", CDTIME_T_TO_DOUBLE(((cu_tail_match_simple_t *)user_data)->interval));
   temp = obj->matches + (obj->matches_num - 1);
 
   temp->match = match;
@@ -193,7 +202,7 @@ int tail_match_add_match (cu_tail_match_t *obj, cu_match_t *match,
 int tail_match_add_match_simple (cu_tail_match_t *obj,
     const char *regex, const char *excluderegex, int ds_type,
     const char *plugin, const char *plugin_instance,
-    const char *type, const char *type_instance)
+    const char *type, const char *type_instance, const cdtime_t interval)
 {
   cu_match_t *match;
   cu_tail_match_simple_t *user_data;
@@ -221,6 +230,8 @@ int tail_match_add_match_simple (cu_tail_match_t *obj,
     sstrncpy (user_data->type_instance, type_instance,
        sizeof (user_data->type_instance));
 
+  user_data->interval = interval;
+
   status = tail_match_add_match (obj, match, simple_submit_match,
       user_data, free);
 
index 7659745..0404de2 100644 (file)
@@ -3,22 +3,27 @@
  * Copyright (C) 2007-2008  C-Ware, Inc.
  * Copyright (C) 2008       Florian 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
- * Free Software Foundation; only version 2 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.
- *
- * 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
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Luke Heberling <lukeh at c-ware.com>
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  *
  * Description:
  *   `tail_match' uses `utils_tail' and `utils_match' to tail a file and try to
@@ -105,7 +110,7 @@ int tail_match_add_match (cu_tail_match_t *obj, cu_match_t *match,
 int tail_match_add_match_simple (cu_tail_match_t *obj,
     const char *regex, const char *excluderegex, int ds_type,
     const char *plugin, const char *plugin_instance,
-    const char *type, const char *type_instance);
+    const char *type, const char *type_instance, const cdtime_t interval);
 
 /*
  * NAME
diff --git a/src/utils_threshold.c b/src/utils_threshold.c
new file mode 100644 (file)
index 0000000..4a8df89
--- /dev/null
@@ -0,0 +1,143 @@
+/**
+ * collectd - src/utils_threshold.c
+ * Copyright (C) 2014       Pierre-Yves Ritschard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Pierre-Yves Ritschard <pyr at spootnik.org>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "utils_avltree.h"
+#include "utils_threshold.h"
+
+#include <pthread.h>
+
+/*
+ * Exported symbols
+ * {{{ */
+c_avl_tree_t   *threshold_tree = NULL;
+pthread_mutex_t threshold_lock = PTHREAD_MUTEX_INITIALIZER;
+/* }}} */
+
+/*
+ * threshold_t *threshold_get
+ *
+ * Retrieve one specific threshold configuration. For looking up a threshold
+ * matching a value_list_t, see "threshold_search" below. Returns NULL if the
+ * specified threshold doesn't exist.
+ */
+threshold_t *threshold_get (const char *hostname,
+    const char *plugin, const char *plugin_instance,
+    const char *type, const char *type_instance)
+{ /* {{{ */
+  char name[6 * DATA_MAX_NAME_LEN];
+  threshold_t *th = NULL;
+
+  format_name (name, sizeof (name),
+      (hostname == NULL) ? "" : hostname,
+      (plugin == NULL) ? "" : plugin, plugin_instance,
+      (type == NULL) ? "" : type, type_instance);
+  name[sizeof (name) - 1] = '\0';
+
+  if (c_avl_get (threshold_tree, name, (void *) &th) == 0)
+    return (th);
+  else
+    return (NULL);
+} /* }}} threshold_t *threshold_get */
+
+/*
+ * threshold_t *threshold_search
+ *
+ * Searches for a threshold configuration using all the possible variations of
+ * "Host", "Plugin" and "Type" blocks. Returns NULL if no threshold could be
+ * found.
+ * XXX: This is likely the least efficient function in collectd.
+ */
+threshold_t *threshold_search (const value_list_t *vl)
+{ /* {{{ */
+  threshold_t *th;
+
+  if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance,
+         vl->type, vl->type_instance)) != NULL)
+    return (th);
+  else if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance,
+         vl->type, NULL)) != NULL)
+    return (th);
+  else if ((th = threshold_get (vl->host, vl->plugin, NULL,
+         vl->type, vl->type_instance)) != NULL)
+    return (th);
+  else if ((th = threshold_get (vl->host, vl->plugin, NULL,
+         vl->type, NULL)) != NULL)
+    return (th);
+  else if ((th = threshold_get (vl->host, "", NULL,
+         vl->type, vl->type_instance)) != NULL)
+    return (th);
+  else if ((th = threshold_get (vl->host, "", NULL,
+         vl->type, NULL)) != NULL)
+    return (th);
+  else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance,
+         vl->type, vl->type_instance)) != NULL)
+    return (th);
+  else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance,
+         vl->type, NULL)) != NULL)
+    return (th);
+  else if ((th = threshold_get ("", vl->plugin, NULL,
+         vl->type, vl->type_instance)) != NULL)
+    return (th);
+  else if ((th = threshold_get ("", vl->plugin, NULL,
+         vl->type, NULL)) != NULL)
+    return (th);
+  else if ((th = threshold_get ("", "", NULL,
+         vl->type, vl->type_instance)) != NULL)
+    return (th);
+  else if ((th = threshold_get ("", "", NULL,
+         vl->type, NULL)) != NULL)
+    return (th);
+
+  return (NULL);
+} /* }}} threshold_t *threshold_search */
+
+int ut_search_threshold (const value_list_t *vl, /* {{{ */
+    threshold_t *ret_threshold)
+{
+  threshold_t *t;
+
+  if (vl == NULL)
+    return (EINVAL);
+
+       /* Is this lock really necessary? */
+       pthread_mutex_lock (&threshold_lock);
+  t = threshold_search (vl);
+  if (t == NULL) {
+               pthread_mutex_unlock (&threshold_lock);
+    return (ENOENT);
+       }
+
+  memcpy (ret_threshold, t, sizeof (*ret_threshold));
+       pthread_mutex_unlock (&threshold_lock);
+
+  ret_threshold->next = NULL;
+
+  return (0);
+} /* }}} int ut_search_threshold */
+
+
diff --git a/src/utils_threshold.h b/src/utils_threshold.h
new file mode 100644 (file)
index 0000000..bf097fa
--- /dev/null
@@ -0,0 +1,67 @@
+/**
+ * collectd - src/utils_threshold.h
+ * Copyright (C) 2014       Pierre-Yves Ritschard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Pierre-Yves Ritschard <pyr at spootnik.org>
+ **/
+
+#ifndef UTILS_THRESHOLD_H
+#define UTILS_THRESHOLD_H 1
+
+#define UT_FLAG_INVERT  0x01
+#define UT_FLAG_PERSIST 0x02
+#define UT_FLAG_PERCENTAGE 0x04
+#define UT_FLAG_INTERESTING 0x08
+#define UT_FLAG_PERSIST_OK 0x10
+typedef struct threshold_s
+{
+  char host[DATA_MAX_NAME_LEN];
+  char plugin[DATA_MAX_NAME_LEN];
+  char plugin_instance[DATA_MAX_NAME_LEN];
+  char type[DATA_MAX_NAME_LEN];
+  char type_instance[DATA_MAX_NAME_LEN];
+  char data_source[DATA_MAX_NAME_LEN];
+  gauge_t warning_min;
+  gauge_t warning_max;
+  gauge_t failure_min;
+  gauge_t failure_max;
+  gauge_t hysteresis;
+  unsigned int flags;
+  int hits;
+  struct threshold_s *next;
+} threshold_t;
+
+extern c_avl_tree_t   *threshold_tree;
+extern pthread_mutex_t threshold_lock;
+
+threshold_t *threshold_get (const char *hostname,
+    const char *plugin, const char *plugin_instance,
+    const char *type, const char *type_instance);
+
+threshold_t *threshold_search (const value_list_t *vl);
+
+int ut_search_threshold (const value_list_t *vl, 
+  threshold_t *ret_threshold);
+
+#endif /* UTILS_THRESHOLD_H */
+
+/* vim: set sw=2 sts=2 ts=8 : */
index 6789758..6603c15 100644 (file)
@@ -1,19 +1,24 @@
 /**
- * collectd - src/utils_time.h
- * Copyright (C) 2010  Florian octo Forster
+ * collectd - src/utils_time.c
+ * Copyright (C) 2010       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <ff at octo.it>
index 0081957..9b08e8e 100644 (file)
@@ -1,19 +1,24 @@
 /**
  * collectd - src/utils_time.h
- * Copyright (C) 2010  Florian octo Forster
+ * Copyright (C) 2010       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <ff at octo.it>
index 8180d0d..75c0206 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * collectd - src/utils_vl_lookup.c
- * Copyright (C) 2012  Florian Forster
+ * Copyright (C) 2012       Florian Forster
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
index 31787f5..1d01ebd 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * collectd - src/utils_vl_lookup.h
- * Copyright (C) 2012  Florian Forster
+ * Copyright (C) 2012       Florian Forster
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
diff --git a/src/utils_vl_lookup_test.c b/src/utils_vl_lookup_test.c
deleted file mode 100644 (file)
index bbb3a67..0000000
+++ /dev/null
@@ -1,244 +0,0 @@
-/**
- * collectd - src/utils_vl_lookup_test.c
- * Copyright (C) 2012  Florian Forster
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *   Florian Forster <octo at collectd.org>
- **/
-
-#include "collectd.h"
-#include "utils_vl_lookup.h"
-
-static _Bool expect_new_obj = 0;
-static _Bool have_new_obj = 0;
-
-static identifier_t last_class_ident;
-static identifier_t last_obj_ident;
-
-static data_source_t dsrc_test = { "value", DS_TYPE_DERIVE, 0.0, NAN };
-static data_set_t const ds_test = { "test", 1, &dsrc_test };
-
-static data_source_t dsrc_unknown = { "value", DS_TYPE_DERIVE, 0.0, NAN };
-static data_set_t const ds_unknown = { "unknown", 1, &dsrc_unknown };
-
-static int lookup_obj_callback (data_set_t const *ds,
-    value_list_t const *vl,
-    void *user_class, void *user_obj)
-{
-  identifier_t *class = user_class;
-  identifier_t *obj = user_obj;
-
-  assert (expect_new_obj == have_new_obj);
-
-  memcpy (&last_class_ident, class, sizeof (last_class_ident));
-  memcpy (&last_obj_ident, obj, sizeof (last_obj_ident));
-
-  if (strcmp (obj->plugin_instance, "failure") == 0)
-    return (-1);
-
-  return (0);
-}
-
-static void *lookup_class_callback (data_set_t const *ds,
-    value_list_t const *vl, void *user_class)
-{
-  identifier_t *class = user_class;
-  identifier_t *obj;
-
-  assert (expect_new_obj);
-
-  memcpy (&last_class_ident, class, sizeof (last_class_ident));
-  
-  obj = malloc (sizeof (*obj));
-  strncpy (obj->host, vl->host, sizeof (obj->host));
-  strncpy (obj->plugin, vl->plugin, sizeof (obj->plugin));
-  strncpy (obj->plugin_instance, vl->plugin_instance, sizeof (obj->plugin_instance));
-  strncpy (obj->type, vl->type, sizeof (obj->type));
-  strncpy (obj->type_instance, vl->type_instance, sizeof (obj->type_instance));
-
-  have_new_obj = 1;
-
-  return ((void *) obj);
-}
-
-static void checked_lookup_add (lookup_t *obj, /* {{{ */
-    char const *host,
-    char const *plugin, char const *plugin_instance,
-    char const *type, char const *type_instance,
-    unsigned int group_by)
-{
-  identifier_t ident;
-  void *user_class;
-  int status;
-
-  memset (&ident, 0, sizeof (ident));
-  strncpy (ident.host, host, sizeof (ident.host));
-  strncpy (ident.plugin, plugin, sizeof (ident.plugin));
-  strncpy (ident.plugin_instance, plugin_instance, sizeof (ident.plugin_instance));
-  strncpy (ident.type, type, sizeof (ident.type));
-  strncpy (ident.type_instance, type_instance, sizeof (ident.type_instance));
-
-  user_class = malloc (sizeof (ident));
-  memmove (user_class, &ident, sizeof (ident));
-
-  status = lookup_add (obj, &ident, group_by, user_class);
-  assert (status == 0);
-} /* }}} void test_add */
-
-static int checked_lookup_search (lookup_t *obj,
-    char const *host,
-    char const *plugin, char const *plugin_instance,
-    char const *type, char const *type_instance,
-    _Bool expect_new)
-{
-  int status;
-  value_list_t vl = VALUE_LIST_STATIC;
-  data_set_t const *ds = &ds_unknown;
-
-  strncpy (vl.host, host, sizeof (vl.host));
-  strncpy (vl.plugin, plugin, sizeof (vl.plugin));
-  strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
-  strncpy (vl.type, type, sizeof (vl.type));
-  strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
-
-  if (strcmp (vl.type, "test") == 0)
-    ds = &ds_test;
-
-  expect_new_obj = expect_new;
-  have_new_obj = 0;
-
-  status = lookup_search (obj, ds, &vl);
-  return (status);
-}
-
-static lookup_t *checked_lookup_create (void)
-{
-  lookup_t *obj = lookup_create (
-      lookup_class_callback,
-      lookup_obj_callback,
-      (void *) free,
-      (void *) free);
-  assert (obj != NULL);
-  return (obj);
-}
-
-static void testcase0 (void)
-{
-  lookup_t *obj = checked_lookup_create ();
-
-  checked_lookup_add (obj, "/.*/", "test", "", "test", "/.*/", LU_GROUP_BY_HOST);
-  checked_lookup_search (obj, "host0", "test", "", "test", "0",
-      /* expect new = */ 1);
-  checked_lookup_search (obj, "host0", "test", "", "test", "1",
-      /* expect new = */ 0);
-  checked_lookup_search (obj, "host1", "test", "", "test", "0",
-      /* expect new = */ 1);
-  checked_lookup_search (obj, "host1", "test", "", "test", "1",
-      /* expect new = */ 0);
-
-  lookup_destroy (obj);
-}
-
-static void testcase1 (void)
-{
-  lookup_t *obj = checked_lookup_create ();
-
-  checked_lookup_add (obj, "/.*/", "/.*/", "/.*/", "test", "/.*/", LU_GROUP_BY_HOST);
-  checked_lookup_search (obj, "host0", "plugin0", "", "test", "0",
-      /* expect new = */ 1);
-  checked_lookup_search (obj, "host0", "plugin0", "", "test", "1",
-      /* expect new = */ 0);
-  checked_lookup_search (obj, "host0", "plugin1", "", "test", "0",
-      /* expect new = */ 0);
-  checked_lookup_search (obj, "host0", "plugin1", "", "test", "1",
-      /* expect new = */ 0);
-  checked_lookup_search (obj, "host1", "plugin0", "", "test", "0",
-      /* expect new = */ 1);
-  checked_lookup_search (obj, "host1", "plugin0", "", "test", "1",
-      /* expect new = */ 0);
-  checked_lookup_search (obj, "host1", "plugin1", "", "test", "0",
-      /* expect new = */ 0);
-  checked_lookup_search (obj, "host1", "plugin1", "", "test", "1",
-      /* expect new = */ 0);
-
-  lookup_destroy (obj);
-}
-
-static void testcase2 (void)
-{
-  lookup_t *obj = checked_lookup_create ();
-  int status;
-
-  checked_lookup_add (obj, "/.*/", "plugin0", "", "test", "/.*/", LU_GROUP_BY_HOST);
-  checked_lookup_add (obj, "/.*/", "/.*/", "", "test", "ti0", LU_GROUP_BY_HOST);
-
-  status = checked_lookup_search (obj, "host0", "plugin1", "", "test", "",
-      /* expect new = */ 0);
-  assert (status == 0);
-  status = checked_lookup_search (obj, "host0", "plugin0", "", "test", "",
-      /* expect new = */ 1);
-  assert (status == 1);
-  status = checked_lookup_search (obj, "host0", "plugin1", "", "test", "ti0",
-      /* expect new = */ 1);
-  assert (status == 1);
-  status = checked_lookup_search (obj, "host0", "plugin0", "", "test", "ti0",
-      /* expect new = */ 0);
-  assert (status == 2);
-
-  lookup_destroy (obj);
-}
-
-static void testcase3 (void)
-{
-  lookup_t *obj = checked_lookup_create ();
-
-  checked_lookup_add (obj, "/^db[0-9]\\./", "cpu", "/.*/", "cpu", "/.*/",
-      LU_GROUP_BY_TYPE_INSTANCE);
-  checked_lookup_search (obj, "db0.example.com", "cpu", "0", "cpu", "user",
-      /* expect new = */ 1);
-  checked_lookup_search (obj, "db0.example.com", "cpu", "0", "cpu", "idle",
-      /* expect new = */ 1);
-  checked_lookup_search (obj, "db0.example.com", "cpu", "1", "cpu", "user",
-      /* expect new = */ 0);
-  checked_lookup_search (obj, "db0.example.com", "cpu", "1", "cpu", "idle",
-      /* expect new = */ 0);
-  checked_lookup_search (obj, "app0.example.com", "cpu", "0", "cpu", "user",
-      /* expect new = */ 0);
-  checked_lookup_search (obj, "app0.example.com", "cpu", "0", "cpu", "idle",
-      /* expect new = */ 0);
-  checked_lookup_search (obj, "db1.example.com", "cpu", "0", "cpu", "user",
-      /* expect new = */ 0);
-  checked_lookup_search (obj, "db1.example.com", "cpu", "0", "cpu", "idle",
-      /* expect new = */ 0);
-  checked_lookup_search (obj, "db1.example.com", "cpu", "0", "cpu", "system",
-      /* expect new = */ 1);
-
-  lookup_destroy (obj);
-}
-
-int main (int argc, char **argv) /* {{{ */
-{
-  testcase0 ();
-  testcase1 ();
-  testcase2 ();
-  testcase3 ();
-  return (EXIT_SUCCESS);
-} /* }}} int main */
index 56997bf..c3ccbe6 100644 (file)
@@ -2,18 +2,23 @@
  * collectd - src/vmem.c
  * Copyright (C) 2008-2010  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Florian octo Forster <octo at collectd.org>
index d80717c..bd2e867 100644 (file)
@@ -3,22 +3,27 @@
  * Copyright (C) 2006,2007  Sebastian Harl
  * Copyright (C) 2007-2010  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
- * Free Software Foundation; only version 2 of the license is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Sebastian Harl <sh at tokkee.org>
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index f7ba735..f2a3cf5 100644 (file)
@@ -2,21 +2,26 @@
  * collectd - src/wireless.c
  * Copyright (C) 2006,2007  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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
- *   Florian octo Forster <octo at verplant.org>
+ * Authors:
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index 34ea46d..eee5a1c 100644 (file)
@@ -18,7 +18,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>
  *   Doug MacEachern <dougm@hyperic.com>
  *   Paul Sadauskas <psadauskas@gmail.com>
  **/
@@ -46,10 +46,15 @@ struct wh_callback_s
         char *user;
         char *pass;
         char *credentials;
-        int   verify_peer;
-        int   verify_host;
+        _Bool verify_peer;
+        _Bool verify_host;
         char *cacert;
-        int   store_rates;
+        char *capath;
+        char *clientkey;
+        char *clientcert;
+        char *clientkeypass;
+        long sslversion;
+        _Bool store_rates;
 
 #define WH_FORMAT_COMMAND 0
 #define WH_FORMAT_JSON    1
@@ -112,7 +117,7 @@ static int wh_callback_init (wh_callback_t *cb) /* {{{ */
         }
 
         curl_easy_setopt (cb->curl, CURLOPT_NOSIGNAL, 1L);
-        curl_easy_setopt (cb->curl, CURLOPT_USERAGENT, PACKAGE_NAME"/"PACKAGE_VERSION);
+        curl_easy_setopt (cb->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
 
         headers = NULL;
         headers = curl_slist_append (headers, "Accept:  */*");
@@ -150,8 +155,20 @@ static int wh_callback_init (wh_callback_t *cb) /* {{{ */
         curl_easy_setopt (cb->curl, CURLOPT_SSL_VERIFYPEER, (long) cb->verify_peer);
         curl_easy_setopt (cb->curl, CURLOPT_SSL_VERIFYHOST,
                         cb->verify_host ? 2L : 0L);
+        curl_easy_setopt (cb->curl, CURLOPT_SSLVERSION, cb->sslversion);
         if (cb->cacert != NULL)
                 curl_easy_setopt (cb->curl, CURLOPT_CAINFO, cb->cacert);
+        if (cb->capath != NULL)
+                curl_easy_setopt (cb->curl, CURLOPT_CAPATH, cb->capath);
+
+        if (cb->clientkey != NULL && cb->clientcert != NULL)
+        {
+            curl_easy_setopt (cb->curl, CURLOPT_SSLKEY, cb->clientkey);
+            curl_easy_setopt (cb->curl, CURLOPT_SSLCERT, cb->clientcert);
+
+            if (cb->clientkeypass != NULL)
+                curl_easy_setopt (cb->curl, CURLOPT_SSLKEYPASSWD, cb->clientkeypass);
+        }
 
         wh_reset_buffer (cb);
 
@@ -269,6 +286,10 @@ static void wh_callback_free (void *data) /* {{{ */
         sfree (cb->pass);
         sfree (cb->credentials);
         sfree (cb->cacert);
+        sfree (cb->capath);
+        sfree (cb->clientkey);
+        sfree (cb->clientcert);
+        sfree (cb->clientkeypass);
 
         sfree (cb);
 } /* }}} void wh_callback_free */
@@ -433,47 +454,6 @@ static int wh_write (const data_set_t *ds, const value_list_t *vl, /* {{{ */
         return (status);
 } /* }}} int wh_write */
 
-static int config_set_string (char **ret_string, /* {{{ */
-                oconfig_item_t *ci)
-{
-        char *string;
-
-        if ((ci->values_num != 1)
-                        || (ci->values[0].type != OCONFIG_TYPE_STRING))
-        {
-                WARNING ("write_http plugin: The `%s' config option "
-                                "needs exactly one string argument.", ci->key);
-                return (-1);
-        }
-
-        string = strdup (ci->values[0].value.string);
-        if (string == NULL)
-        {
-                ERROR ("write_http plugin: strdup failed.");
-                return (-1);
-        }
-
-        if (*ret_string != NULL)
-                free (*ret_string);
-        *ret_string = string;
-
-        return (0);
-} /* }}} int config_set_string */
-
-static int config_set_boolean (int *dest, oconfig_item_t *ci) /* {{{ */
-{
-        if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
-        {
-                WARNING ("write_http plugin: The `%s' config option "
-                                "needs exactly one boolean argument.", ci->key);
-                return (-1);
-        }
-
-        *dest = ci->values[0].value.boolean ? 1 : 0;
-
-        return (0);
-} /* }}} int config_set_boolean */
-
 static int config_set_format (wh_callback_t *cb, /* {{{ */
                 oconfig_item_t *ci)
 {
@@ -500,7 +480,7 @@ static int config_set_format (wh_callback_t *cb, /* {{{ */
         }
 
         return (0);
-} /* }}} int config_set_string */
+} /* }}} int config_set_format */
 
 static int wh_config_url (oconfig_item_t *ci) /* {{{ */
 {
@@ -515,19 +495,14 @@ static int wh_config_url (oconfig_item_t *ci) /* {{{ */
                 return (-1);
         }
         memset (cb, 0, sizeof (*cb));
-        cb->location = NULL;
-        cb->user = NULL;
-        cb->pass = NULL;
-        cb->credentials = NULL;
         cb->verify_peer = 1;
         cb->verify_host = 1;
-        cb->cacert = NULL;
         cb->format = WH_FORMAT_COMMAND;
-        cb->curl = NULL;
+        cb->sslversion = CURL_SSLVERSION_DEFAULT;
 
         pthread_mutex_init (&cb->send_lock, /* attr = */ NULL);
 
-        config_set_string (&cb->location, ci);
+        cf_util_get_string (ci, &cb->location);
         if (cb->location == NULL)
                 return (-1);
 
@@ -536,19 +511,55 @@ static int wh_config_url (oconfig_item_t *ci) /* {{{ */
                 oconfig_item_t *child = ci->children + i;
 
                 if (strcasecmp ("User", child->key) == 0)
-                        config_set_string (&cb->user, child);
+                        cf_util_get_string (child, &cb->user);
                 else if (strcasecmp ("Password", child->key) == 0)
-                        config_set_string (&cb->pass, child);
+                        cf_util_get_string (child, &cb->pass);
                 else if (strcasecmp ("VerifyPeer", child->key) == 0)
-                        config_set_boolean (&cb->verify_peer, child);
+                        cf_util_get_boolean (child, &cb->verify_peer);
                 else if (strcasecmp ("VerifyHost", child->key) == 0)
-                        config_set_boolean (&cb->verify_host, child);
+                        cf_util_get_boolean (child, &cb->verify_host);
                 else if (strcasecmp ("CACert", child->key) == 0)
-                        config_set_string (&cb->cacert, child);
+                        cf_util_get_string (child, &cb->cacert);
+                else if (strcasecmp ("CAPath", child->key) == 0)
+                        cf_util_get_string (child, &cb->capath);
+                else if (strcasecmp ("ClientKey", child->key) == 0)
+                        cf_util_get_string (child, &cb->clientkey);
+                else if (strcasecmp ("ClientCert", child->key) == 0)
+                        cf_util_get_string (child, &cb->clientcert);
+                else if (strcasecmp ("ClientKeyPass", child->key) == 0)
+                        cf_util_get_string (child, &cb->clientkeypass);
+                else if (strcasecmp ("SSLVersion", child->key) == 0)
+                {
+                        char *value = NULL;
+
+                        cf_util_get_string (child, &value);
+
+                        if (value == NULL || strcasecmp ("default", value) == 0)
+                                cb->sslversion = CURL_SSLVERSION_DEFAULT;
+                        else if (strcasecmp ("SSLv2", value) == 0)
+                                cb->sslversion = CURL_SSLVERSION_SSLv2;
+                        else if (strcasecmp ("SSLv3", value) == 0)
+                                cb->sslversion = CURL_SSLVERSION_SSLv3;
+                        else if (strcasecmp ("TLSv1", value) == 0)
+                                cb->sslversion = CURL_SSLVERSION_TLSv1;
+#if (LIBCURL_VERSION_MAJOR > 7) || (LIBCURL_VERSION_MAJOR == 7 && LIBCURL_VERSION_MINOR >= 34)
+                        else if (strcasecmp ("TLSv1_0", value) == 0)
+                                cb->sslversion = CURL_SSLVERSION_TLSv1_0;
+                        else if (strcasecmp ("TLSv1_1", value) == 0)
+                                cb->sslversion = CURL_SSLVERSION_TLSv1_1;
+                        else if (strcasecmp ("TLSv1_2", value) == 0)
+                                cb->sslversion = CURL_SSLVERSION_TLSv1_2;
+#endif
+                        else
+                                ERROR ("write_http plugin: Invalid SSLVersion "
+                                                "option: %s.", value);
+
+                        sfree(value);
+                }
                 else if (strcasecmp ("Format", child->key) == 0)
                         config_set_format (cb, child);
                 else if (strcasecmp ("StoreRates", child->key) == 0)
-                        config_set_boolean (&cb->store_rates, child);
+                        cf_util_get_boolean (child, &cb->store_rates);
                 else
                 {
                         ERROR ("write_http plugin: Invalid configuration "
diff --git a/src/write_kafka.c b/src/write_kafka.c
new file mode 100644 (file)
index 0000000..3e683c8
--- /dev/null
@@ -0,0 +1,432 @@
+/**
+ * collectd - src/write_kafka.c
+ * Copyright (C) 2014       Pierre-Yves Ritschard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *   Pierre-Yves Ritschard <pyr at spootnik.org>
+ */
+
+#include "collectd.h"
+#include "plugin.h"
+#include "common.h"
+#include "configfile.h"
+#include "utils_cache.h"
+#include "utils_cmd_putval.h"
+#include "utils_format_graphite.h"
+#include "utils_format_json.h"
+#include "utils_crc32.h"
+
+#include <sys/types.h>
+#include <librdkafka/rdkafka.h>
+#include <pthread.h>
+#include <zlib.h>
+
+struct kafka_topic_context {
+#define KAFKA_FORMAT_JSON        0
+#define KAFKA_FORMAT_COMMAND     1
+#define KAFKA_FORMAT_GRAPHITE    2
+    u_int8_t                     format;
+    unsigned int                 graphite_flags;
+    _Bool                        store_rates;
+    rd_kafka_topic_conf_t       *conf;
+    rd_kafka_topic_t            *topic;
+    rd_kafka_t                  *kafka;
+    int                          has_key;
+    u_int32_t                    key;
+    char                        *prefix;
+    char                        *postfix;
+    char                         escape_char;
+    char                        *topic_name;
+};
+
+static int kafka_write(const data_set_t *, const value_list_t *, user_data_t *);
+static int32_t kafka_partition(const rd_kafka_topic_t *, const void *, size_t,
+                               int32_t, void *, void *);
+
+#ifdef HAVE_LIBRDKAFKA_LOGGER
+static void kafka_log(const rd_kafka_t *, int, const char *, const char *);
+
+static void kafka_log(const rd_kafka_t *rkt, int level,
+                      const char *fac, const char *msg)
+{
+    plugin_log(level, "%s", msg);
+}
+#endif
+
+static int32_t kafka_partition(const rd_kafka_topic_t *rkt,
+                               const void *keydata, size_t keylen,
+                               int32_t partition_cnt, void *p, void *m)
+{
+    u_int32_t key = *((u_int32_t *)keydata );
+
+    return key % partition_cnt;
+}
+
+static int kafka_write(const data_set_t *ds, /* {{{ */
+             const value_list_t *vl,
+             user_data_t *ud)
+{
+       int                      status = 0;
+    u_int32_t    key;
+    char         buffer[8192];
+    size_t bfree = sizeof(buffer);
+    size_t bfill = 0;
+    size_t blen = 0;
+       struct kafka_topic_context      *ctx = ud->data;
+
+    if ((ds == NULL) || (vl == NULL) || (ctx == NULL))
+        return EINVAL;
+
+    bzero(buffer, sizeof(buffer));
+
+    switch (ctx->format) {
+    case KAFKA_FORMAT_COMMAND:
+        status = create_putval(buffer, sizeof(buffer), ds, vl);
+        if (status != 0) {
+            ERROR("write_kafka plugin: create_putval failed with status %i.",
+                  status);
+            return status;
+        }
+        blen = strlen(buffer);
+        break;
+    case KAFKA_FORMAT_JSON:
+
+        format_json_initialize(buffer, &bfill, &bfree);
+        format_json_value_list(buffer, &bfill, &bfree, ds, vl,
+                               ctx->store_rates);
+        format_json_finalize(buffer, &bfill, &bfree);
+        blen = strlen(buffer);
+        break;
+    case KAFKA_FORMAT_GRAPHITE:
+        status = format_graphite(buffer, sizeof(buffer), ds, vl,
+                                 ctx->prefix, ctx->postfix, ctx->escape_char,
+                                 ctx->graphite_flags);
+        if (status != 0) {
+            ERROR("write_kafka plugin: format_graphite failed with status %i.",
+                  status);
+            return status;
+        }
+        blen = strlen(buffer);
+        break;
+    default:
+        ERROR("write_kafka plugin: invalid format %i.", ctx->format);
+        return -1;
+    }
+
+    /*
+     * We partition our stream by metric name
+     */
+    if (ctx->has_key)
+        key = ctx->key;
+    else
+        key = rand();
+
+    rd_kafka_produce(ctx->topic, RD_KAFKA_PARTITION_UA,
+                     RD_KAFKA_MSG_F_COPY, buffer, blen,
+                     &key, sizeof(key), NULL);
+
+       return status;
+} /* }}} int kafka_write */
+
+static void kafka_topic_context_free(void *p) /* {{{ */
+{
+       struct kafka_topic_context *ctx = p;
+
+       if (ctx == NULL)
+               return;
+
+    if (ctx->topic_name != NULL)
+        sfree(ctx->topic_name);
+    if (ctx->topic != NULL)
+        rd_kafka_topic_destroy(ctx->topic);
+    if (ctx->conf != NULL)
+        rd_kafka_topic_conf_destroy(ctx->conf);
+
+    sfree(ctx);
+} /* }}} void kafka_topic_context_free */
+
+static void kafka_config_topic(rd_kafka_conf_t *conf, oconfig_item_t *ci) /* {{{ */
+{
+    int                          status;
+    int                          i;
+    struct kafka_topic_context  *tctx;
+    char                        *key = NULL;
+    char                        *val;
+    char                         callback_name[DATA_MAX_NAME_LEN];
+    char                         errbuf[1024];
+    user_data_t                  ud;
+       oconfig_item_t              *child;
+    rd_kafka_conf_res_t          ret;
+
+       if ((tctx = calloc(1, sizeof (*tctx))) == NULL) {
+               ERROR ("write_kafka plugin: calloc failed.");
+        return;
+       }
+
+    tctx->escape_char = '.';
+    tctx->store_rates = 1;
+    tctx->format = KAFKA_FORMAT_JSON;
+
+#ifdef HAVE_LIBRDKAFKA_LOG_CB
+    rd_kafka_conf_set_log_cb(conf, kafka_log);
+#endif
+    if ((tctx->kafka = rd_kafka_new(RD_KAFKA_PRODUCER, conf,
+                                    errbuf, sizeof(errbuf))) == NULL) {
+        sfree(tctx);
+        ERROR("write_kafka plugin: cannot create kafka handle.");
+        return;
+    }
+#ifdef HAVE_LIBRDKAFKA_LOGGER
+    rd_kafka_conf_set_logger(tctx->kafka, kafka_log);
+#endif
+    conf = NULL;
+
+    if ((tctx->conf = rd_kafka_topic_conf_new()) == NULL) {
+        rd_kafka_destroy(tctx->kafka);
+        sfree(tctx);
+        ERROR ("write_kafka plugin: cannot create topic configuration.");
+        return;
+    }
+
+    if (ci->values_num != 1) {
+        WARNING("kafka topic name needed.");
+        goto errout;
+    }
+
+    if (ci->values[0].type != OCONFIG_TYPE_STRING) {
+        WARNING("kafka topic needs a string argument.");
+        goto errout;
+    }
+
+    if ((tctx->topic_name = strdup(ci->values[0].value.string)) == NULL) {
+        ERROR("write_kafka plugin: cannot copy topic name.");
+        goto errout;
+    }
+
+       for (i = 0; i < ci->children_num; i++) {
+               /*
+                * The code here could be simplified but makes room
+                * for easy adding of new options later on.
+                */
+               child = &ci->children[i];
+               status = 0;
+
+               if (strcasecmp ("Property", child->key) == 0) {
+                       if (child->values_num != 2) {
+                               WARNING("kafka properties need both a key and a value.");
+                goto errout;
+                       }
+                       if (child->values[0].type != OCONFIG_TYPE_STRING ||
+                           child->values[1].type != OCONFIG_TYPE_STRING) {
+                               WARNING("kafka properties needs string arguments.");
+                goto errout;
+                       }
+            key = child->values[0].value.string;
+            val = child->values[0].value.string;
+            ret = rd_kafka_topic_conf_set(tctx->conf,key, val,
+                                          errbuf, sizeof(errbuf));
+            if (ret != RD_KAFKA_CONF_OK) {
+                               WARNING("cannot set kafka topic property %s to %s: %s.",
+                        key, val, errbuf);
+                goto errout;
+                       }
+
+        } else if (strcasecmp ("Key", child->key) == 0)  {
+            char *tmp_buf = NULL;
+            status = cf_util_get_string(child, &tmp_buf);
+            if (status != 0) {
+                WARNING("write_kafka plugin: invalid key supplied");
+                break;
+            }
+
+            if (strcasecmp(tmp_buf, "Random") != 0) {
+                tctx->has_key = 1;
+                tctx->key = crc32_buffer((u_char *)tmp_buf, strlen(tmp_buf));
+            }
+            sfree(tmp_buf);
+
+        } else if (strcasecmp ("Format", child->key) == 0) {
+            status = cf_util_get_string(child, &key);
+            if (status != 0)
+                goto errout;
+
+            assert(key != NULL);
+
+            if (strcasecmp(key, "Command") == 0) {
+                tctx->format = KAFKA_FORMAT_COMMAND;
+
+            } else if (strcasecmp(key, "Graphite") == 0) {
+                tctx->format = KAFKA_FORMAT_GRAPHITE;
+
+            } else if (strcasecmp(key, "Json") == 0) {
+                tctx->format = KAFKA_FORMAT_JSON;
+
+            } else {
+                WARNING ("write_kafka plugin: Invalid format string: %s",
+                         key);
+            }
+
+            sfree(key);
+
+        } else if (strcasecmp ("StoreRates", child->key) == 0) {
+            status = cf_util_get_boolean (child, &tctx->store_rates);
+            (void) cf_util_get_flag (child, &tctx->graphite_flags,
+                                     GRAPHITE_STORE_RATES);
+
+        } else if (strcasecmp ("GraphiteSeparateInstances", child->key) == 0) {
+            status = cf_util_get_flag (child, &tctx->graphite_flags,
+                                       GRAPHITE_SEPARATE_INSTANCES);
+
+        } else if (strcasecmp ("GraphiteAlwaysAppendDS", child->key) == 0) {
+            status = cf_util_get_flag (child, &tctx->graphite_flags,
+                                       GRAPHITE_ALWAYS_APPEND_DS);
+
+        } else if (strcasecmp ("GraphitePrefix", child->key) == 0) {
+            status = cf_util_get_string (child, &tctx->prefix);
+        } else if (strcasecmp ("GraphitePostfix", child->key) == 0) {
+            status = cf_util_get_string (child, &tctx->postfix);
+        } else if (strcasecmp ("GraphiteEscapeChar", child->key) == 0) {
+            char *tmp_buff = NULL;
+            status = cf_util_get_string (child, &tmp_buff);
+            if (strlen (tmp_buff) > 1)
+                WARNING ("write_kafka plugin: The option \"GraphiteEscapeChar\" handles "
+                        "only one character. Others will be ignored.");
+            tctx->escape_char = tmp_buff[0];
+            sfree (tmp_buff);
+        } else {
+            WARNING ("write_kafka plugin: Invalid directive: %s.", child->key);
+        }
+
+        if (status != 0)
+            break;
+    }
+
+    rd_kafka_topic_conf_set_partitioner_cb(tctx->conf, kafka_partition);
+    rd_kafka_topic_conf_set_opaque(tctx->conf, tctx);
+
+    if ((tctx->topic = rd_kafka_topic_new(tctx->kafka, tctx->topic_name,
+                                       tctx->conf)) == NULL) {
+        ERROR("write_kafka plugin: cannot create topic.");
+        goto errout;
+    }
+    tctx->conf = NULL;
+
+    ssnprintf(callback_name, sizeof(callback_name),
+              "write_kafka/%s", tctx->topic_name);
+
+    ud.data = tctx;
+    ud.free_func = kafka_topic_context_free;
+
+       status = plugin_register_write (callback_name, kafka_write, &ud);
+       if (status != 0) {
+               WARNING ("write_kafka plugin: plugin_register_write (\"%s\") "
+                               "failed with status %i.",
+                               callback_name, status);
+        goto errout;
+    }
+    return;
+ errout:
+    if (conf != NULL)
+        rd_kafka_conf_destroy(conf);
+    if (tctx->kafka != NULL)
+        rd_kafka_destroy(tctx->kafka);
+    if (tctx->topic != NULL)
+        rd_kafka_topic_destroy(tctx->topic);
+    if (tctx->topic_name != NULL)
+        free(tctx->topic_name);
+    if (tctx->conf != NULL)
+        rd_kafka_topic_conf_destroy(tctx->conf);
+    sfree(tctx);
+} /* }}} int kafka_config_topic */
+
+static int kafka_config(oconfig_item_t *ci) /* {{{ */
+{
+       int                          i;
+       oconfig_item_t              *child;
+    rd_kafka_conf_t             *conf;
+    rd_kafka_conf_t             *cloned;
+    rd_kafka_conf_res_t          ret;
+    char                         errbuf[1024];
+
+    if ((conf = rd_kafka_conf_new()) == NULL) {
+        WARNING("cannot allocate kafka configuration.");
+        return -1;
+    }
+
+       for (i = 0; i < ci->children_num; i++)  {
+               child = &ci->children[i];
+
+               if (strcasecmp("Topic", child->key) == 0) {
+            if ((cloned = rd_kafka_conf_dup(conf)) == NULL) {
+                WARNING("write_kafka plugin: cannot allocate memory for kafka config");
+                goto errout;
+            }
+                       kafka_config_topic (cloned, child);
+               } else if (strcasecmp(child->key, "Property") == 0) {
+                       char *key = NULL;
+                       char *val = NULL;
+
+                       if (child->values_num != 2) {
+                               WARNING("kafka properties need both a key and a value.");
+                goto errout;
+                       }
+                       if (child->values[0].type != OCONFIG_TYPE_STRING ||
+                           child->values[1].type != OCONFIG_TYPE_STRING) {
+                               WARNING("kafka properties needs string arguments.");
+                goto errout;
+                       }
+                       if ((key = strdup(child->values[0].value.string)) == NULL) {
+                               WARNING("cannot allocate memory for attribute key.");
+                goto errout;
+                       }
+                       if ((val = strdup(child->values[1].value.string)) == NULL) {
+                               WARNING("cannot allocate memory for attribute value.");
+                goto errout;
+                       }
+            ret = rd_kafka_conf_set(conf, key, val, errbuf, sizeof(errbuf));
+            if (ret != RD_KAFKA_CONF_OK) {
+                WARNING("cannot set kafka property %s to %s: %s",
+                        key, val, errbuf);
+                goto errout;
+            }
+                       sfree(key);
+                       sfree(val);
+               } else {
+                       WARNING ("write_kafka plugin: Ignoring unknown "
+                                "configuration option \"%s\" at top level.",
+                                child->key);
+               }
+       }
+    if (conf != NULL)
+        rd_kafka_conf_destroy(conf);
+       return (0);
+ errout:
+    if (conf != NULL)
+        rd_kafka_conf_destroy(conf);
+    return -1;
+} /* }}} int kafka_config */
+
+void module_register(void)
+{
+       plugin_register_complex_config ("write_kafka", kafka_config);
+}
+
+/* vim: set sw=8 sts=8 ts=8 noet : */
index 58f2cae..3defaca 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * collectd - src/write_redis.c
- * Copyright (C) 2010  Florian Forster
+ * Copyright (C) 2010       Florian Forster
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
index a404ff6..b59c3e3 100644 (file)
@@ -1,20 +1,25 @@
 /**
  * collectd - src/write_riemann.c
- *
  * Copyright (C) 2012,2013  Pierre-Yves Ritschard
  * Copyright (C) 2013       Florian octo Forster
  *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
- * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *   Pierre-Yves Ritschard <pyr at spootnik.org>
 #define RIEMANN_PORT           "5555"
 #define RIEMANN_TTL_FACTOR      2.0
 
+int write_riemann_threshold_check(const data_set_t *, const value_list_t *, int *);
+
 struct riemann_host {
        char                    *name;
 #define F_CONNECT               0x01
        uint8_t                  flags;
        pthread_mutex_t          lock;
+       _Bool                    notifications;
+       _Bool                    check_thresholds;
        _Bool                    store_rates;
        _Bool                    always_append_ds;
        char                    *node;
@@ -57,6 +66,8 @@ struct riemann_host {
 
 static char    **riemann_tags;
 static size_t    riemann_tags_num;
+static char    **riemann_attrs;
+static size_t     riemann_attrs_num;
 
 static void riemann_event_protobuf_free (Event *event) /* {{{ */
 {
@@ -148,7 +159,7 @@ static int riemann_connect(struct riemann_host *host) /* {{{ */
                }
 
                host->flags |= F_CONNECT;
-               DEBUG("write_riemann plugin: got a succesful connection for: %s:%s",
+               DEBUG("write_riemann plugin: got a successful connection for: %s:%s",
                                node, service);
                break;
        }
@@ -410,6 +421,11 @@ static Msg *riemann_notification_to_protobuf(struct riemann_host *host, /* {{{ *
                riemann_event_add_attribute (event, "type_instance",
                                n->type_instance);
 
+       for (i = 0; i < riemann_attrs_num; i += 2)
+               riemann_event_add_attribute(event,
+                                           riemann_attrs[i],
+                                           riemann_attrs[i +1]);
+
        for (i = 0; i < riemann_tags_num; i++)
                riemann_event_add_tag (event, riemann_tags[i]);
 
@@ -418,15 +434,23 @@ static Msg *riemann_notification_to_protobuf(struct riemann_host *host, /* {{{ *
                        n->type, n->type_instance);
        event->service = strdup (&service_buffer[1]);
 
-       /* Pull in values from threshold */
+       if (n->message[0] != 0)
+               riemann_event_add_attribute (event, "description", n->message);
+
+       /* Pull in values from threshold and add extra attributes */
        for (meta = n->meta; meta != NULL; meta = meta->next)
        {
-               if (strcasecmp ("CurrentValue", meta->name) != 0)
+               if (strcasecmp ("CurrentValue", meta->name) == 0 && meta->type == NM_TYPE_DOUBLE)
+               {
+                       event->metric_d = meta->nm_value.nm_double;
+                       event->has_metric_d = 1;
                        continue;
+               }
 
-               event->metric_d = meta->nm_value.nm_double;
-               event->has_metric_d = 1;
-               break;
+               if (meta->type == NM_TYPE_STRING) {
+                       riemann_event_add_attribute (event, meta->name, meta->nm_value.nm_string);
+                       continue;
+               }
        }
 
        DEBUG ("write_riemann plugin: Successfully created protobuf for notification: "
@@ -438,7 +462,8 @@ static Msg *riemann_notification_to_protobuf(struct riemann_host *host, /* {{{ *
 static Event *riemann_value_to_protobuf(struct riemann_host const *host, /* {{{ */
                data_set_t const *ds,
                value_list_t const *vl, size_t index,
-               gauge_t const *rates)
+                                        gauge_t const *rates,
+                                        int status)
 {
        Event *event;
        char name_buffer[5 * DATA_MAX_NAME_LEN];
@@ -459,6 +484,23 @@ static Event *riemann_value_to_protobuf(struct riemann_host const *host, /* {{{
        event->time = CDTIME_T_TO_TIME_T (vl->time);
        event->has_time = 1;
 
+       if (host->check_thresholds) {
+               switch (status) {
+                       case STATE_OKAY:
+                               event->state = strdup("ok");
+                               break;
+                       case STATE_ERROR:
+                               event->state = strdup("critical");
+                               break;
+                       case STATE_WARNING:
+                               event->state = strdup("warning");
+                               break;
+                       case STATE_MISSING:
+                               event->state = strdup("unknown");
+                               break;
+               }
+       }
+
        ttl = CDTIME_T_TO_DOUBLE (vl->interval) * host->ttl_factor;
        event->ttl = (float) ttl;
        event->has_ttl = 1;
@@ -494,6 +536,11 @@ static Event *riemann_value_to_protobuf(struct riemann_host const *host, /* {{{
                riemann_event_add_attribute (event, "ds_index", ds_index);
        }
 
+       for (i = 0; i < riemann_attrs_num; i += 2)
+               riemann_event_add_attribute(event,
+                                           riemann_attrs[i],
+                                           riemann_attrs[i +1]);
+
        for (i = 0; i < riemann_tags_num; i++)
                riemann_event_add_tag (event, riemann_tags[i]);
 
@@ -536,9 +583,10 @@ static Event *riemann_value_to_protobuf(struct riemann_host const *host, /* {{{
        return (event);
 } /* }}} Event *riemann_value_to_protobuf */
 
-static Msg *riemann_value_list_to_protobuf(struct riemann_host const *host, /* {{{ */
-               data_set_t const *ds,
-               value_list_t const *vl)
+static Msg *riemann_value_list_to_protobuf (struct riemann_host const *host, /* {{{ */
+                                           data_set_t const *ds,
+                                           value_list_t const *vl,
+                                           int *statuses)
 {
        Msg *msg;
        size_t i;
@@ -578,7 +626,7 @@ static Msg *riemann_value_list_to_protobuf(struct riemann_host const *host, /* {
        for (i = 0; i < msg->n_events; i++)
        {
                msg->events[i] = riemann_value_to_protobuf (host, ds, vl,
-                               (int) i, rates);
+                                                           (int) i, rates, statuses[i]);
                if (msg->events[i] == NULL)
                {
                        riemann_msg_protobuf_free (msg);
@@ -597,6 +645,9 @@ static int riemann_notification(const notification_t *n, user_data_t *ud) /* {{{
        struct riemann_host     *host = ud->data;
        Msg                     *msg;
 
+       if (!host->notifications)
+               return 0;
+
        msg = riemann_notification_to_protobuf (host, n);
        if (msg == NULL)
                return (-1);
@@ -615,10 +666,13 @@ static int riemann_write(const data_set_t *ds, /* {{{ */
              user_data_t *ud)
 {
        int                      status;
+       int                      statuses[vl->values_len];
        struct riemann_host     *host = ud->data;
        Msg                     *msg;
 
-       msg = riemann_value_list_to_protobuf (host, ds, vl);
+       if (host->check_thresholds)
+               write_riemann_threshold_check(ds, vl, statuses);
+       msg = riemann_value_list_to_protobuf (host, ds, vl, statuses);
        if (msg == NULL)
                return (-1);
 
@@ -671,6 +725,8 @@ static int riemann_config_node(oconfig_item_t *ci) /* {{{ */
        host->reference_count = 1;
        host->node = NULL;
        host->service = NULL;
+       host->notifications = 1;
+       host->check_thresholds = 0;
        host->store_rates = 1;
        host->always_append_ds = 0;
        host->use_tcp = 0;
@@ -695,6 +751,14 @@ static int riemann_config_node(oconfig_item_t *ci) /* {{{ */
                        status = cf_util_get_string (child, &host->node);
                        if (status != 0)
                                break;
+               } else if (strcasecmp ("Notifications", child->key) == 0) {
+                       status = cf_util_get_boolean(child, &host->notifications);
+                       if (status != 0)
+                               break;
+               } else if (strcasecmp ("CheckThresholds", child->key) == 0) {
+                       status = cf_util_get_boolean(child, &host->check_thresholds);
+                       if (status != 0)
+                               break;
                } else if (strcasecmp ("Port", child->key) == 0) {
                        status = cf_util_get_service (child, &host->service);
                        if (status != 0) {
@@ -823,6 +887,32 @@ static int riemann_config(oconfig_item_t *ci) /* {{{ */
 
                if (strcasecmp("Node", child->key) == 0) {
                        riemann_config_node (child);
+               } else if (strcasecmp(child->key, "attribute") == 0) {
+                       char *key = NULL;
+                       char *val = NULL;
+
+                       if (child->values_num != 2) {
+                               WARNING("riemann attributes need both a key and a value.");
+                               return (-1);
+                       }
+                       if (child->values[0].type != OCONFIG_TYPE_STRING ||
+                           child->values[1].type != OCONFIG_TYPE_STRING) {
+                               WARNING("riemann attribute needs string arguments.");
+                               return (-1);
+                       }
+                       if ((key = strdup(child->values[0].value.string)) == NULL) {
+                               WARNING("cannot allocate memory for attribute key.");
+                               return (-1);
+                       }
+                       if ((val = strdup(child->values[1].value.string)) == NULL) {
+                               WARNING("cannot allocate memory for attribute value.");
+                               return (-1);
+                       }
+                       strarray_add(&riemann_attrs, &riemann_attrs_num, key);
+                       strarray_add(&riemann_attrs, &riemann_attrs_num, val);
+                       DEBUG("write_riemann: got attr: %s => %s", key, val);
+                       sfree(key);
+                       sfree(val);
                } else if (strcasecmp(child->key, "tag") == 0) {
                        char *tmp = NULL;
                        status = cf_util_get_string(child, &tmp);
diff --git a/src/write_riemann_threshold.c b/src/write_riemann_threshold.c
new file mode 100644 (file)
index 0000000..6d5af03
--- /dev/null
@@ -0,0 +1,242 @@
+/**
+ * collectd - src/threshold.c
+ * Copyright (C) 2007-2010  Florian Forster
+ * Copyright (C) 2008-2009  Sebastian Harl
+ * Copyright (C) 2009       Andrés J. Díaz
+ * Copyright (C) 2014       Pierre-Yves Ritschard
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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
+ *
+ * Author:
+ *   Pierre-Yves Ritschard <pyr at spootnik.org>
+ *   Florian octo Forster <octo at collectd.org>
+ *   Sebastian Harl <sh at tokkee.org>
+ *   Andrés J. Díaz <ajdiaz at connectical.com>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+#include "utils_avltree.h"
+#include "utils_cache.h"
+#include "utils_threshold.h"
+
+#include <assert.h>
+#include <ltdl.h>
+#include <pthread.h>
+
+/*
+ * Threshold management
+ * ====================
+ * The following functions add, delete, etc. configured thresholds to
+ * the underlying AVL trees.
+ */
+
+/*
+ * int ut_check_one_data_source
+ *
+ * Checks one data source against the given threshold configuration. If the
+ * `DataSource' option is set in the threshold, and the name does NOT match,
+ * `okay' is returned. If the threshold does match, its failure and warning
+ * min and max values are checked and `failure' or `warning' is returned if
+ * appropriate.
+ * Does not fail.
+ */
+static int ut_check_one_data_source (const data_set_t *ds,
+    const value_list_t __attribute__((unused)) *vl,
+    const threshold_t *th,
+    const gauge_t *values,
+    int ds_index)
+{ /* {{{ */
+  const char *ds_name;
+  int is_warning = 0;
+  int is_failure = 0;
+  int prev_state = STATE_OKAY;
+
+  /* check if this threshold applies to this data source */
+  if (ds != NULL)
+  {
+    ds_name = ds->ds[ds_index].name;
+    if ((th->data_source[0] != 0)
+       && (strcmp (ds_name, th->data_source) != 0))
+      return (STATE_OKAY);
+  }
+
+  if ((th->flags & UT_FLAG_INVERT) != 0)
+  {
+    is_warning--;
+    is_failure--;
+  }
+
+  /* XXX: This is an experimental code, not optimized, not fast, not reliable,
+   * and probably, do not work as you expect. Enjoy! :D */
+  if ( (th->hysteresis > 0) && ((prev_state = uc_get_state(ds,vl)) != STATE_OKAY) )
+  {
+    switch(prev_state)
+    {
+      case STATE_ERROR:
+       if ( (!isnan (th->failure_min) && ((th->failure_min + th->hysteresis) < values[ds_index])) ||
+            (!isnan (th->failure_max) && ((th->failure_max - th->hysteresis) > values[ds_index])) )
+         return (STATE_OKAY);
+       else
+         is_failure++;
+      case STATE_WARNING:
+       if ( (!isnan (th->warning_min) && ((th->warning_min + th->hysteresis) < values[ds_index])) ||
+            (!isnan (th->warning_max) && ((th->warning_max - th->hysteresis) > values[ds_index])) )
+         return (STATE_OKAY);
+       else
+         is_warning++;
+     }
+  }
+  else { /* no hysteresis */
+    if ((!isnan (th->failure_min) && (th->failure_min > values[ds_index]))
+       || (!isnan (th->failure_max) && (th->failure_max < values[ds_index])))
+      is_failure++;
+
+    if ((!isnan (th->warning_min) && (th->warning_min > values[ds_index]))
+       || (!isnan (th->warning_max) && (th->warning_max < values[ds_index])))
+      is_warning++;
+ }
+
+  if (is_failure != 0)
+    return (STATE_ERROR);
+
+  if (is_warning != 0)
+    return (STATE_WARNING);
+
+  return (STATE_OKAY);
+} /* }}} int ut_check_one_data_source */
+
+/*
+ * int ut_check_one_threshold
+ *
+ * Checks all data sources of a value list against the given threshold, using
+ * the ut_check_one_data_source function above. Returns the worst status,
+ * which is `okay' if nothing has failed.
+ * Returns less than zero if the data set doesn't have any data sources.
+ */
+static int ut_check_one_threshold (const data_set_t *ds,
+    const value_list_t *vl,
+    const threshold_t *th,
+    const gauge_t *values,
+    int *statuses)
+{ /* {{{ */
+  int ret = -1;
+  int i;
+  int status;
+  gauge_t values_copy[ds->ds_num];
+
+  memcpy (values_copy, values, sizeof (values_copy));
+
+  if ((th->flags & UT_FLAG_PERCENTAGE) != 0)
+  {
+    int num = 0;
+    gauge_t sum=0.0;
+
+    if (ds->ds_num == 1)
+    {
+      WARNING ("ut_check_one_threshold: The %s type has only one data "
+          "source, but you have configured to check this as a percentage. "
+          "That doesn't make much sense, because the percentage will always "
+          "be 100%%!", ds->type);
+    }
+
+    /* Prepare `sum' and `num'. */
+    for (i = 0; i < ds->ds_num; i++)
+      if (!isnan (values[i]))
+      {
+        num++;
+       sum += values[i];
+      }
+
+    if ((num == 0) /* All data sources are undefined. */
+        || (sum == 0.0)) /* Sum is zero, cannot calculate percentage. */
+    {
+      for (i = 0; i < ds->ds_num; i++)
+        values_copy[i] = NAN;
+    }
+    else /* We can actually calculate the percentage. */
+    {
+      for (i = 0; i < ds->ds_num; i++)
+        values_copy[i] = 100.0 * values[i] / sum;
+    }
+  } /* if (UT_FLAG_PERCENTAGE) */
+
+  for (i = 0; i < ds->ds_num; i++)
+  {
+    status = ut_check_one_data_source (ds, vl, th, values_copy, i);
+    if (status != -1) {
+           ret = 0;
+           if (statuses[i] < status)
+                   statuses[i] = status;
+    }
+  } /* for (ds->ds_num) */
+
+  return (ret);
+} /* }}} int ut_check_one_threshold */
+
+/*
+ * int ut_check_threshold
+ *
+ * Gets a list of matching thresholds and searches for the worst status by one
+ * of the thresholds. Then reports that status using the ut_report_state
+ * function above.
+ * Returns zero on success and if no threshold has been configured. Returns
+ * less than zero on failure.
+ */
+int write_riemann_threshold_check (const data_set_t *ds, const value_list_t *vl,
+                                  int *statuses)
+{ /* {{{ */
+  threshold_t *th;
+  gauge_t *values;
+  int status;
+
+  memset(statuses, 0, vl->values_len * sizeof(*statuses));
+  if (threshold_tree == NULL)
+         return 0;
+
+  /* Is this lock really necessary? So far, thresholds are only inserted at
+   * startup. -octo */
+  pthread_mutex_lock (&threshold_lock);
+  th = threshold_search (vl);
+  pthread_mutex_unlock (&threshold_lock);
+  if (th == NULL)
+         return (0);
+
+  DEBUG ("ut_check_threshold: Found matching threshold(s)");
+
+  values = uc_get_rate (ds, vl);
+  if (values == NULL)
+         return (0);
+
+  while (th != NULL)
+  {
+    status = ut_check_one_threshold (ds, vl, th, values, statuses);
+    if (status < 0)
+    {
+      ERROR ("ut_check_threshold: ut_check_one_threshold failed.");
+      sfree (values);
+      return (-1);
+    }
+
+    th = th->next;
+  } /* while (th) */
+
+  sfree (values);
+
+  return (0);
+} /* }}} int ut_check_threshold */
+
+
+/* vim: set sw=2 ts=8 sts=2 tw=78 et fdm=marker : */
diff --git a/src/write_tsdb.c b/src/write_tsdb.c
new file mode 100644 (file)
index 0000000..2eca77e
--- /dev/null
@@ -0,0 +1,647 @@
+/**
+ * collectd - src/write_tsdb.c
+ * Copyright (C) 2012       Pierre-Yves Ritschard
+ * Copyright (C) 2011       Scott Sanders
+ * Copyright (C) 2009       Paul Sadauskas
+ * Copyright (C) 2009       Doug MacEachern
+ * Copyright (C) 2007-2012  Florian octo Forster
+ * Copyright (C) 2013-2014  Limelight Networks, Inc.
+ * 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.
+ *
+ * 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.
+ *
+ * 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
+ *
+ * Based on the write_graphite plugin. Authors:
+ *   Florian octo Forster <octo at collectd.org>
+ *   Doug MacEachern <dougm at hyperic.com>
+ *   Paul Sadauskas <psadauskas at gmail.com>
+ *   Scott Sanders <scott at jssjr.com>
+ *   Pierre-Yves Ritschard <pyr at spootnik.org>
+ * write_tsdb Authors:
+ *   Brett Hawn <bhawn at llnw.com>
+ *   Kevin Bowling <kbowling@llnw.com>
+ **/
+
+/* write_tsdb plugin configuation example
+ *
+ * <Plugin write_tsdb>
+ *   <Node>
+ *     Host "localhost"
+ *     Port "4242"
+ *     HostTags "status=production deviceclass=www"
+ *   </Node>
+ * </Plugin>
+ */
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+#include "configfile.h"
+
+#include "utils_cache.h"
+#include "utils_parse_option.h"
+
+#include <pthread.h>
+#include <sys/socket.h>
+#include <netdb.h>
+
+#ifndef WT_DEFAULT_NODE
+# define WT_DEFAULT_NODE "localhost"
+#endif
+
+#ifndef WT_DEFAULT_SERVICE
+# define WT_DEFAULT_SERVICE "4242"
+#endif
+
+#ifndef WT_DEFAULT_ESCAPE
+# define WT_DEFAULT_ESCAPE '.'
+#endif
+
+/* Ethernet - (IPv6 + TCP) = 1500 - (40 + 32) = 1428 */
+#ifndef WT_SEND_BUF_SIZE
+# define WT_SEND_BUF_SIZE 1428
+#endif
+
+/*
+ * Private variables
+ */
+struct wt_callback
+{
+    int      sock_fd;
+
+    char     *node;
+    char     *service;
+    char     *host_tags;
+
+    _Bool    store_rates;
+    _Bool    always_append_ds;
+
+    char     send_buf[WT_SEND_BUF_SIZE];
+    size_t   send_buf_free;
+    size_t   send_buf_fill;
+    cdtime_t send_buf_init_time;
+
+    pthread_mutex_t send_lock;
+};
+
+
+/*
+ * Functions
+ */
+static void wt_reset_buffer(struct wt_callback *cb)
+{
+    memset(cb->send_buf, 0, sizeof(cb->send_buf));
+    cb->send_buf_free = sizeof(cb->send_buf);
+    cb->send_buf_fill = 0;
+    cb->send_buf_init_time = cdtime();
+}
+
+static int wt_send_buffer(struct wt_callback *cb)
+{
+    ssize_t status = 0;
+
+    status = swrite(cb->sock_fd, cb->send_buf, strlen(cb->send_buf));
+    if (status < 0)
+    {
+        char errbuf[1024];
+        ERROR("write_tsdb plugin: send failed with status %zi (%s)",
+              status, sstrerror (errno, errbuf, sizeof (errbuf)));
+
+        close (cb->sock_fd);
+        cb->sock_fd = -1;
+
+        return -1;
+    }
+
+    return 0;
+}
+
+/* NOTE: You must hold cb->send_lock when calling this function! */
+static int wt_flush_nolock(cdtime_t timeout, struct wt_callback *cb)
+{
+    int status;
+
+    DEBUG("write_tsdb plugin: wt_flush_nolock: timeout = %.3f; "
+          "send_buf_fill = %zu;",
+          (double)timeout,
+          cb->send_buf_fill);
+
+    /* timeout == 0  => flush unconditionally */
+    if (timeout > 0)
+    {
+        cdtime_t now;
+
+        now = cdtime();
+        if ((cb->send_buf_init_time + timeout) > now)
+            return 0;
+    }
+
+    if (cb->send_buf_fill <= 0)
+    {
+        cb->send_buf_init_time = cdtime();
+        return 0;
+    }
+
+    status = wt_send_buffer(cb);
+    wt_reset_buffer(cb);
+
+    return status;
+}
+
+static int wt_callback_init(struct wt_callback *cb)
+{
+    struct addrinfo ai_hints;
+    struct addrinfo *ai_list;
+    struct addrinfo *ai_ptr;
+    int status;
+
+    const char *node = cb->node ? cb->node : WT_DEFAULT_NODE;
+    const char *service = cb->service ? cb->service : WT_DEFAULT_SERVICE;
+
+    if (cb->sock_fd > 0)
+        return 0;
+
+    memset(&ai_hints, 0, sizeof(ai_hints));
+#ifdef AI_ADDRCONFIG
+    ai_hints.ai_flags    |= AI_ADDRCONFIG;
+#endif
+    ai_hints.ai_family   = AF_UNSPEC;
+    ai_hints.ai_socktype = SOCK_STREAM;
+
+    ai_list = NULL;
+
+    status = getaddrinfo(node, service, &ai_hints, &ai_list);
+    if (status != 0)
+    {
+        ERROR("write_tsdb plugin: getaddrinfo (%s, %s) failed: %s",
+              node, service, gai_strerror (status));
+        return -1;
+    }
+
+    assert (ai_list != NULL);
+    for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+    {
+        cb->sock_fd = socket(ai_ptr->ai_family, ai_ptr->ai_socktype,
+                             ai_ptr->ai_protocol);
+        if (cb->sock_fd < 0)
+            continue;
+
+        status = connect(cb->sock_fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
+        if (status != 0)
+        {
+            close(cb->sock_fd);
+            cb->sock_fd = -1;
+            continue;
+        }
+
+        break;
+    }
+
+    freeaddrinfo(ai_list);
+
+    if (cb->sock_fd < 0)
+    {
+        char errbuf[1024];
+        ERROR("write_tsdb plugin: Connecting to %s:%s failed. "
+              "The last error was: %s", node, service,
+              sstrerror (errno, errbuf, sizeof(errbuf)));
+        close(cb->sock_fd);
+        return -1;
+    }
+
+    wt_reset_buffer(cb);
+
+    return 0;
+}
+
+static void wt_callback_free(void *data)
+{
+    struct wt_callback *cb;
+
+    if (data == NULL)
+        return;
+
+    cb = data;
+
+    pthread_mutex_lock(&cb->send_lock);
+
+    wt_flush_nolock(0, cb);
+
+    close(cb->sock_fd);
+    cb->sock_fd = -1;
+
+    sfree(cb->node);
+    sfree(cb->service);
+    sfree(cb->host_tags);
+
+    pthread_mutex_destroy(&cb->send_lock);
+
+    sfree(cb);
+}
+
+static int wt_flush(cdtime_t timeout,
+                    const char *identifier __attribute__((unused)),
+                    user_data_t *user_data)
+{
+    struct wt_callback *cb;
+    int status;
+
+    if (user_data == NULL)
+        return -EINVAL;
+
+    cb = user_data->data;
+
+    pthread_mutex_lock(&cb->send_lock);
+
+    if (cb->sock_fd < 0)
+    {
+        status = wt_callback_init(cb);
+        if (status != 0)
+        {
+            ERROR("write_tsdb plugin: wt_callback_init failed.");
+            pthread_mutex_unlock(&cb->send_lock);
+            return -1;
+        }
+    }
+
+    status = wt_flush_nolock(timeout, cb);
+    pthread_mutex_unlock(&cb->send_lock);
+
+    return status;
+}
+
+static int wt_format_values(char *ret, size_t ret_len,
+                            int ds_num, const data_set_t *ds,
+                            const value_list_t *vl,
+                            _Bool store_rates)
+{
+    size_t offset = 0;
+    int status;
+    gauge_t *rates = NULL;
+
+    assert(0 == strcmp (ds->type, vl->type));
+
+    memset(ret, 0, ret_len);
+
+#define BUFFER_ADD(...) do { \
+        status = ssnprintf (ret + offset, ret_len - offset, \
+                            __VA_ARGS__); \
+        if (status < 1) \
+        { \
+            sfree(rates); \
+            return -1; \
+        } \
+        else if (((size_t) status) >= (ret_len - offset)) \
+        { \
+            sfree(rates); \
+            return -1; \
+        } \
+        else \
+            offset += ((size_t) status); \
+} while (0)
+
+    if (ds->ds[ds_num].type == DS_TYPE_GAUGE)
+        BUFFER_ADD("%f", vl->values[ds_num].gauge);
+    else if (store_rates)
+    {
+        if (rates == NULL)
+            rates = uc_get_rate (ds, vl);
+        if (rates == NULL)
+        {
+            WARNING("format_values: "
+                    "uc_get_rate failed.");
+            return -1;
+        }
+        BUFFER_ADD("%f", rates[ds_num]);
+    }
+    else if (ds->ds[ds_num].type == DS_TYPE_COUNTER)
+        BUFFER_ADD("%llu", vl->values[ds_num].counter);
+    else if (ds->ds[ds_num].type == DS_TYPE_DERIVE)
+        BUFFER_ADD("%" PRIi64, vl->values[ds_num].derive);
+    else if (ds->ds[ds_num].type == DS_TYPE_ABSOLUTE)
+        BUFFER_ADD("%" PRIu64, vl->values[ds_num].absolute);
+    else
+    {
+        ERROR("format_values plugin: Unknown data source type: %i",
+              ds->ds[ds_num].type);
+        sfree(rates);
+        return -1;
+    }
+
+#undef BUFFER_ADD
+
+    sfree(rates);
+    return 0;
+}
+
+static int wt_format_name(char *ret, int ret_len,
+                          const value_list_t *vl,
+                          const struct wt_callback *cb,
+                          const char *ds_name)
+{
+    int status;
+    char *temp = NULL;
+    char *prefix = "";
+    const char *meta_prefix = "tsdb_prefix";
+
+    if (vl->meta) {
+        status = meta_data_get_string(vl->meta, meta_prefix, &temp);
+        if (status == -ENOENT) {
+            /* defaults to empty string */
+        } else if (status < 0) {
+            sfree(temp);
+            return status;
+        } else {
+            prefix = temp;
+        }
+    }
+
+    if (ds_name != NULL) {
+        if (vl->plugin_instance[0] == '\0') {
+            ssnprintf(ret, ret_len, "%s%s.%s",
+                      prefix, vl->plugin, ds_name);
+        } else if (vl->type_instance == '\0') {
+            ssnprintf(ret, ret_len, "%s%s.%s.%s.%s",
+                      prefix, vl->plugin, vl->plugin_instance,
+                      vl->type_instance, ds_name);
+        } else {
+            ssnprintf(ret, ret_len, "%s%s.%s.%s.%s",
+                      prefix, vl->plugin, vl->plugin_instance, vl->type,
+                      ds_name);
+        }
+    } else if (vl->plugin_instance[0] == '\0') {
+        if (vl->type_instance[0] == '\0')
+            ssnprintf(ret, ret_len, "%s%s.%s",
+                      prefix, vl->plugin, vl->type);
+        else
+            ssnprintf(ret, ret_len, "%s%s.%s",
+                      prefix, vl->plugin, vl->type_instance);
+    } else if (vl->type_instance[0] == '\0') {
+        ssnprintf(ret, ret_len, "%s%s.%s.%s",
+                  prefix, vl->plugin, vl->plugin_instance, vl->type);
+    } else {
+        ssnprintf(ret, ret_len, "%s%s.%s.%s",
+                  prefix, vl->plugin, vl->plugin_instance, vl->type_instance);
+    }
+
+    sfree(temp);
+    return 0;
+}
+
+static int wt_send_message (const char* key, const char* value,
+                            cdtime_t time, struct wt_callback *cb,
+                            const char* host, meta_data_t *md)
+{
+    int status;
+    int message_len;
+    char *temp = NULL;
+    char *tags = "";
+    char message[1024];
+    char *host_tags = cb->host_tags ? cb->host_tags : "";
+    const char *meta_tsdb = "tsdb_tags";
+
+    /* skip if value is NaN */
+    if (value[0] == 'n')
+        return 0;
+
+    if (md) {
+        status = meta_data_get_string(md, meta_tsdb, &temp);
+        if (status == -ENOENT) {
+            /* defaults to empty string */
+        } else if (status < 0) {
+            ERROR("write_tsdb plugin: tags metadata get failure");
+            sfree(temp);
+            pthread_mutex_unlock(&cb->send_lock);
+            return status;
+        } else {
+            tags = temp;
+        }
+    }
+
+    message_len = ssnprintf (message,
+                             sizeof(message),
+                             "put %s %.0f %s fqdn=%s %s %s\r\n",
+                             key,
+                             CDTIME_T_TO_DOUBLE(time),
+                             value,
+                             host,
+                             tags,
+                             host_tags);
+
+    sfree(temp);
+
+    if (message_len >= sizeof(message)) {
+        ERROR("write_tsdb plugin: message buffer too small: "
+              "Need %d bytes.", message_len + 1);
+        return -1;
+    }
+
+    pthread_mutex_lock(&cb->send_lock);
+
+    if (cb->sock_fd < 0)
+    {
+        status = wt_callback_init(cb);
+        if (status != 0)
+        {
+            ERROR("write_tsdb plugin: wt_callback_init failed.");
+            pthread_mutex_unlock(&cb->send_lock);
+            return -1;
+        }
+    }
+
+    if (message_len >= cb->send_buf_free)
+    {
+        status = wt_flush_nolock(0, cb);
+        if (status != 0)
+        {
+            pthread_mutex_unlock(&cb->send_lock);
+            return status;
+        }
+    }
+
+    /* Assert that we have enough space for this message. */
+    assert(message_len < cb->send_buf_free);
+
+    /* `message_len + 1' because `message_len' does not include the
+     * trailing null byte. Neither does `send_buffer_fill'. */
+    memcpy(cb->send_buf + cb->send_buf_fill,
+            message, message_len + 1);
+    cb->send_buf_fill += message_len;
+    cb->send_buf_free -= message_len;
+
+    DEBUG("write_tsdb plugin: [%s]:%s buf %zu/%zu (%.1f %%) \"%s\"",
+          cb->node,
+          cb->service,
+          cb->send_buf_fill, sizeof(cb->send_buf),
+          100.0 * ((double) cb->send_buf_fill) /
+          ((double) sizeof(cb->send_buf)),
+          message);
+
+    pthread_mutex_unlock(&cb->send_lock);
+
+    return 0;
+}
+
+static int wt_write_messages(const data_set_t *ds, const value_list_t *vl,
+                             struct wt_callback *cb)
+{
+    char key[10*DATA_MAX_NAME_LEN];
+    char values[512];
+
+    int status, i;
+
+    if (0 != strcmp(ds->type, vl->type))
+    {
+        ERROR("write_tsdb plugin: DS type does not match "
+              "value list type");
+        return -1;
+    }
+
+    for (i = 0; i < ds->ds_num; i++)
+    {
+        const char *ds_name = NULL;
+
+        if (cb->always_append_ds || (ds->ds_num > 1))
+            ds_name = ds->ds[i].name;
+
+        /* Copy the identifier to 'key' and escape it. */
+        status = wt_format_name(key, sizeof(key), vl, cb, ds_name);
+        if (status != 0)
+        {
+            ERROR("write_tsdb plugin: error with format_name");
+            return status;
+        }
+
+        escape_string(key, sizeof(key));
+        /* Convert the values to an ASCII representation and put that into
+         * 'values'. */
+        status = wt_format_values(values, sizeof(values), i, ds, vl,
+                                  cb->store_rates);
+        if (status != 0)
+        {
+            ERROR("write_tsdb plugin: error with "
+                  "wt_format_values");
+            return status;
+        }
+
+        /* Send the message to tsdb */
+        status = wt_send_message(key, values, vl->time, cb, vl->host, vl->meta);
+        if (status != 0)
+        {
+            ERROR("write_tsdb plugin: error with "
+                  "wt_send_message");
+            return status;
+        }
+    }
+
+    return 0;
+}
+
+static int wt_write(const data_set_t *ds, const value_list_t *vl,
+                    user_data_t *user_data)
+{
+    struct wt_callback *cb;
+    int status;
+
+    if (user_data == NULL)
+        return EINVAL;
+
+    cb = user_data->data;
+
+    status = wt_write_messages(ds, vl, cb);
+
+    return status;
+}
+
+static int wt_config_tsd(oconfig_item_t *ci)
+{
+    struct wt_callback *cb;
+    user_data_t user_data;
+    char callback_name[DATA_MAX_NAME_LEN];
+    int i;
+
+    cb = malloc(sizeof(*cb));
+    if (cb == NULL)
+    {
+        ERROR("write_tsdb plugin: malloc failed.");
+        return -1;
+    }
+    memset(cb, 0, sizeof(*cb));
+    cb->sock_fd = -1;
+    cb->node = NULL;
+    cb->service = NULL;
+    cb->host_tags = NULL;
+    cb->store_rates = 0;
+
+    pthread_mutex_init (&cb->send_lock, NULL);
+
+    for (i = 0; i < ci->children_num; i++)
+    {
+        oconfig_item_t *child = ci->children + i;
+
+        if (strcasecmp("Host", child->key) == 0)
+            cf_util_get_string(child, &cb->node);
+        else if (strcasecmp("Port", child->key) == 0)
+            cf_util_get_service(child, &cb->service);
+        else if (strcasecmp("HostTags", child->key) == 0)
+            cf_util_get_string(child, &cb->host_tags);
+        else if (strcasecmp("StoreRates", child->key) == 0)
+            cf_util_get_boolean(child, &cb->store_rates);
+        else if (strcasecmp("AlwaysAppendDS", child->key) == 0)
+            cf_util_get_boolean(child, &cb->always_append_ds);
+        else
+        {
+            ERROR("write_tsdb plugin: Invalid configuration "
+                  "option: %s.", child->key);
+        }
+    }
+
+    ssnprintf(callback_name, sizeof(callback_name), "write_tsdb/%s/%s",
+              cb->node != NULL ? cb->node : WT_DEFAULT_NODE,
+              cb->service != NULL ? cb->service : WT_DEFAULT_SERVICE);
+
+    memset(&user_data, 0, sizeof(user_data));
+    user_data.data = cb;
+    user_data.free_func = wt_callback_free;
+    plugin_register_write(callback_name, wt_write, &user_data);
+
+    user_data.free_func = NULL;
+    plugin_register_flush(callback_name, wt_flush, &user_data);
+
+    return 0;
+}
+
+static int wt_config(oconfig_item_t *ci)
+{
+    int i;
+
+    for (i = 0; i < ci->children_num; i++)
+    {
+        oconfig_item_t *child = ci->children + i;
+
+        if (strcasecmp("Node", child->key) == 0)
+            wt_config_tsd(child);
+        else
+        {
+            ERROR("write_tsdb plugin: Invalid configuration "
+                  "option: %s.", child->key);
+        }
+    }
+
+    return 0;
+}
+
+void module_register(void)
+{
+    plugin_register_complex_config("write_tsdb", wt_config);
+}
+
+/* vim: set sw=4 ts=4 sts=4 tw=78 et : */
index 52beb65..a423bb6 100644 (file)
@@ -1,22 +1,27 @@
 /**
  * collectd - src/xmms.c
- * Copyright (C) 2007  Florian octo Forster
+ * Copyright (C) 2007       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * 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.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * 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
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
index 95b15d8..6b5e40e 100755 (executable)
@@ -2,7 +2,7 @@
 
 DEFAULT_VERSION="5.4.1.git"
 
-VERSION="`git describe 2> /dev/null | sed -e 's/^collectd-//'`"
+VERSION="`git describe 2> /dev/null | grep collectd | sed -e 's/^collectd-//'`"
 
 if test -z "$VERSION"; then
        VERSION="$DEFAULT_VERSION"