Code

Merge branch 'collectd-5.4' into collectd-5.5
authorMarc Fournier <marc.fournier@camptocamp.com>
Sat, 1 Aug 2015 07:30:22 +0000 (09:30 +0200)
committerMarc Fournier <marc.fournier@camptocamp.com>
Sat, 1 Aug 2015 07:30:22 +0000 (09:30 +0200)
307 files changed:
.gitignore
AUTHORS
COPYING
ChangeLog
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/Makefile.PL
bindings/perl/lib/Collectd/MockDaemon.pm [new file with mode: 0644]
bindings/perl/lib/Collectd/Plugins/OpenVZ.pm
bindings/perl/lib/Collectd/Unixsock.pm
bindings/perl/t/00_load.t [new file with mode: 0644]
bindings/perl/t/01_methods.t [new file with mode: 0644]
clean.sh
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
contrib/systemd.collectd.service [new file with mode: 0644]
contrib/upstart.collectd.conf
contrib/wiki2changelog.pl [new file with mode: 0755]
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/ceph.c [new file with mode: 0644]
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 [deleted file]
src/collectd.conf.in
src/collectd.conf.pod
src/collectd.h [deleted file]
src/collectd.pod
src/collectdctl.c
src/collectdctl.pod
src/collectdmon.c
src/collectdmon.pod
src/common.c [deleted file]
src/common.h [deleted file]
src/configfile.c [deleted file]
src/configfile.h [deleted file]
src/conntrack.c
src/cpu.c
src/cpython.h
src/csv.c
src/curl.c
src/curl_json.c
src/curl_xml.c
src/daemon/Makefile.am [new file with mode: 0644]
src/daemon/collectd.c [new file with mode: 0644]
src/daemon/collectd.h [new file with mode: 0644]
src/daemon/common.c [new file with mode: 0644]
src/daemon/common.h [new file with mode: 0644]
src/daemon/common_test.c [new file with mode: 0644]
src/daemon/configfile.c [new file with mode: 0644]
src/daemon/configfile.h [new file with mode: 0644]
src/daemon/filter_chain.c [new file with mode: 0644]
src/daemon/filter_chain.h [new file with mode: 0644]
src/daemon/meta_data.c [new file with mode: 0644]
src/daemon/meta_data.h [new file with mode: 0644]
src/daemon/plugin.c [new file with mode: 0644]
src/daemon/plugin.h [new file with mode: 0644]
src/daemon/plugin_mock.c [new file with mode: 0644]
src/daemon/types_list.c [new file with mode: 0644]
src/daemon/types_list.h [new file with mode: 0644]
src/daemon/utils_avltree.c [new file with mode: 0644]
src/daemon/utils_avltree.h [new file with mode: 0644]
src/daemon/utils_avltree_test.c [new file with mode: 0644]
src/daemon/utils_cache.c [new file with mode: 0644]
src/daemon/utils_cache.h [new file with mode: 0644]
src/daemon/utils_cache_mock.c [new file with mode: 0644]
src/daemon/utils_complain.c [new file with mode: 0644]
src/daemon/utils_complain.h [new file with mode: 0644]
src/daemon/utils_heap.c [new file with mode: 0644]
src/daemon/utils_heap.h [new file with mode: 0644]
src/daemon/utils_heap_test.c [new file with mode: 0644]
src/daemon/utils_llist.c [new file with mode: 0644]
src/daemon/utils_llist.h [new file with mode: 0644]
src/daemon/utils_match.c [new file with mode: 0644]
src/daemon/utils_match.h [new file with mode: 0644]
src/daemon/utils_random.c [new file with mode: 0644]
src/daemon/utils_random.h [new file with mode: 0644]
src/daemon/utils_subst.c [new file with mode: 0644]
src/daemon/utils_subst.h [new file with mode: 0644]
src/daemon/utils_tail.c [new file with mode: 0644]
src/daemon/utils_tail.h [new file with mode: 0644]
src/daemon/utils_tail_match.c [new file with mode: 0644]
src/daemon/utils_tail_match.h [new file with mode: 0644]
src/daemon/utils_threshold.c [new file with mode: 0644]
src/daemon/utils_threshold.h [new file with mode: 0644]
src/daemon/utils_time.c [new file with mode: 0644]
src/daemon/utils_time.h [new file with mode: 0644]
src/daemon/utils_time_mock.c [new file with mode: 0644]
src/dbi.c
src/df.c
src/disk.c
src/dns.c
src/drbd.c [new file with mode: 0644]
src/email.c
src/entropy.c
src/exec.c
src/fhcount.c [new file with mode: 0644]
src/filecount.c
src/filter_chain.c [deleted file]
src/filter_chain.h [deleted file]
src/gmond.c
src/hddtemp.c
src/interface.c
src/ipc.c [new file with mode: 0644]
src/ipmi.c
src/java.c
src/libcollectdclient/Makefile.am
src/libcollectdclient/client.c
src/libcollectdclient/collectd/network.h
src/libcollectdclient/network.c
src/libcollectdclient/network_buffer.c
src/liboconfig/oconfig.c
src/liboconfig/oconfig.h
src/liboconfig/parser.y
src/liboconfig/scanner.l
src/libvirt.c [deleted file]
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 [deleted file]
src/meta_data.h [deleted file]
src/modbus.c
src/mysql.c
src/netlink.c
src/network.c
src/network.h
src/nfs.c
src/nginx.c
src/notify_desktop.c
src/ntpd.c
src/numa.c
src/nut.c
src/olsrd.c
src/onewire.c
src/openldap.c [new file with mode: 0644]
src/openvpn.c
src/perl.c
src/pf.c
src/pinba.c
src/ping.c
src/plugin.c [deleted file]
src/plugin.h [deleted file]
src/postgresql.c
src/powerdns.c
src/processes.c
src/protocols.c
src/python.c
src/redis.c
src/routeros.c
src/rrdcached.c
src/sensors.c
src/serial.c
src/sigrok.c
src/smart.c [new file with mode: 0644]
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/testing.h [new file with mode: 0644]
src/threshold.c
src/tokyotyrant.c
src/turbostat.c [new file with mode: 0644]
src/types.db
src/types.db.pod
src/types_list.c [deleted file]
src/types_list.h [deleted file]
src/unixsock.c
src/uptime.c
src/users.c
src/utils_avltree.c [deleted file]
src/utils_avltree.h [deleted file]
src/utils_cache.c [deleted file]
src/utils_cache.h [deleted file]
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 [deleted file]
src/utils_complain.h [deleted file]
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_graphite.c
src/utils_format_json.c
src/utils_format_json.h
src/utils_heap.c [deleted file]
src/utils_heap.h [deleted file]
src/utils_ignorelist.c
src/utils_latency.c
src/utils_latency.h
src/utils_llist.c [deleted file]
src/utils_llist.h [deleted file]
src/utils_match.c [deleted file]
src/utils_match.h [deleted file]
src/utils_mount.c
src/utils_mount.h
src/utils_mount_test.c [new file with mode: 0644]
src/utils_parse_option.c
src/utils_parse_option.h
src/utils_random.c [deleted file]
src/utils_random.h [deleted file]
src/utils_rrdcreate.c
src/utils_rrdcreate.h
src/utils_subst.c [deleted file]
src/utils_subst.h [deleted file]
src/utils_tail.c [deleted file]
src/utils_tail.h [deleted file]
src/utils_tail_match.c [deleted file]
src/utils_tail_match.h [deleted file]
src/utils_time.c [deleted file]
src/utils_time.h [deleted file]
src/utils_vl_lookup.c
src/utils_vl_lookup.h
src/utils_vl_lookup_test.c
src/varnish.c
src/virt.c [new file with mode: 0644]
src/vmem.c
src/vserver.c
src/wireless.c
src/write_graphite.c
src/write_http.c
src/write_kafka.c [new file with mode: 0644]
src/write_log.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_sensu.c [new file with mode: 0644]
src/write_tsdb.c [new file with mode: 0644]
src/xmms.c
src/zfs_arc.c
src/zookeeper.c [new file with mode: 0644]
version-gen.sh

index 7c7c848fab9bba94e3b0505a8d1efc80026d6eae..54eaa9748ef6240a0e8cd12650275d6536892f53 100644 (file)
@@ -38,6 +38,7 @@ src/collectdctl
 src/collectdmon
 src/*.1
 src/*.5
+src/.pod2man.tmp.*
 src/libcollectdclient/collectd/lcc_features.h
 
 # patch stuff
@@ -62,6 +63,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 +78,14 @@ src/tags
 
 # backup stuff
 *~
+# tests stuff
+src/tests/.deps/
+src/tests/mock/.deps/
+src/tests/.dirstamp
+src/tests/mock/.dirstamp
+test*.log
+
+# new daemon repo
+src/daemon/.deps/
+src/daemon/.dirstamp
+src/daemon/collectd
diff --git a/AUTHORS b/AUTHORS
index 31d132fbfa3c12cf27948ab5e1c9019ddab49adc..3f63c3dcd5591c72131b4bfa3dc579d9bc5e36cc 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -5,7 +5,7 @@ Florian "octo" Forster <octo at verplant.org>
  - Initial author.
 
 Sebastian "tokkee" Harl <sh at tokkee.org>
- - Bugfixes and enhancments in many places all around the project.
+ - Bugfixes and enhancements in many places all around the project.
  - perl plugin.
  - users plugin.
  - vserver plugin.
@@ -34,6 +34,9 @@ Amit Gupta <amit.gupta221 at gmail.com>
 Andreas Henriksson <andreas at fatal.se>
  - libmnl support in the netlink plugin.
 
+Andy Parkins <andyp at fussylogic.co.uk>
+ - battery plugin: sysfs code.
+
 Anthony Dewhurst <dewhurst at gmail.com>
  - zfs_arc plugin.
 
@@ -47,12 +50,18 @@ 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,
+ - Many bug reports and -fixes in various plugins,
    especially a nasty bug in the network plugin.
  - Wireshark dissector.
 
@@ -72,6 +81,9 @@ Cyril Feraudet <cyril at feraudet.com>
 Dan Berrange <berrange at redhat.com>
  - uuid plugin.
 
+Dan Ryder <daryder at cisco.com>
+ - ceph plugin.
+
 David Bacher <drbacher at gmail.com>
  - serial plugin.
 
@@ -94,6 +106,9 @@ Fabian Linzberger <e at lefant.net>
 Fabien Wernli <cpan at faxm0dem.org>
  - Solaris improvements in the memory and interfaces plugin.
 
+Fabrice A. Marie <fabrice at kibinlabs.com>
+ - write_sensu plugin.
+
 Flavio Stanchina <flavio at stanchina.net>
  - mbmon plugin.
 
@@ -106,9 +121,22 @@ Jason Pepas <cell at ices.utexas.edu>
 J. Javier Maestro <jjmaestro at ieee.org>
  - Write-Graphite plugin: UDP support and LogSendErrors flag.
 
+Jeremy Katz <jeremy at katzbox.net>
+ - percentage reporting in memory and swap plugins.
+ - zookeeper plugin.
+
 Jérôme Renard <jerome.renard at gmail.com>
  - varnish plugin.
 
+Jiri Tyr <jiri.tyr at gmail.com>
+ - fhcount plugin.
+
+Kevin Bowling <kbowling at llnw.com>
+ - write_tsdb plugin for http://opentsdb.net/
+
+Kimo Rosenbaum <kimor79 at yahoo.com>
+ - openldap plugin.
+
 Kris Nielander <nielander at fox-it.com>
  - tail_csv plugin.
 
@@ -138,6 +166,8 @@ Marc Fournier <marc.fournier at camptocamp.com>
  - Various fixes to the varnish plugin.
  - RPM specfile update.
  - libmnl support in the netlink plugin.
+ - linux support in the zfs_arc plugin.
+ - openldap plugin.
 
 Marco Chiappero <marco at absence.it>
  - uptime plugin.
@@ -147,6 +177,9 @@ Marco Chiappero <marco at absence.it>
 Michael Hanselmann <public at hansmi.ch>
  - md plugin.
 
+Michael Schenck <mschenck at digitalocean.com>
+ - IO time support to disk plugin.
+
 Michael Stapelberg <michael+git at stapelberg.de>
  - OpenBSD port of the tcpconns plugin.
  - cgroups plugin.
@@ -195,12 +228,16 @@ 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.
 
 Richard W. M. Jones <rjones at redhat.com>
- - libvirt plugin.
+ - virt plugin.
  - uuid plugin.
 
 Roman Klesel <roman.klesel at noris.de>
@@ -231,6 +268,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.
 
@@ -240,9 +280,18 @@ Tomasz Pala <gotar at pld-linux.org>
 Tommie Gannert <d00-tga at d.kth.se>
  - PID-file patch.
 
+Vincent Bernat <vincent at bernat.im>
+ - smart plugin.
+
+Vincent Brillault <git at lerya.net>
+ - turbostat plugin, based on Len Brown <len.brown at intel.com> kernel tool
+
 Vincent Stehlé <vincent.stehle at free.fr>
  - hddtemp plugin.
 
+Wilfried Goesgens <dothebart at citadel.org>
+ - linux support in the zfs_arc plugin.
+
 Xin Li <delphij at freebsd.org>
  - FreeBSD port of the ZFS-ARC plugin.
 
diff --git a/COPYING b/COPYING
index d511905c1647a1e311e8b20d5930a37a9c2531cd..191af71e0574c70c7ab2a74a0dc64381a24887bb 100644 (file)
--- a/COPYING
+++ b/COPYING
@@ -1,3 +1,35 @@
+collectd consists of a daemon and numerous plugins. The daemon is licensed
+under the "MIT License"; its source files are located at src/daemon/. The
+plugins are licenses individually, please check the top of the plugin's source
+file(s) to see which license applies. The majority of plugins is licensed
+either under the "MIT License" or the "GNU General Public License".
+
+The "MIT License" and "GNU General Public License" follow. Other licenses, not
+included in this file, should be considered "as published by the Open Source
+Initiative (OSI)".
+
+MIT License
+===========
+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.
+
+GNU General Public License (GPL)
+================================
                    GNU GENERAL PUBLIC LICENSE
                       Version 2, June 1991
 
index 84e25b83f3e1a19b69d223f980703a288aca99cf..b0a997c53ac1a74bc39470bdd243f853fa095c9f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,282 @@
+2015-05-27, Version 5.5.0
+       * Build system: Ability to make out-of-tree builds has been fixed.
+         Thanks to Vincent Bernat. #792
+       * Build system, Disk and Users plugins: Detection and use of libstatgrab
+         ≧ 0.90 has been added. Thanks to Vincent Bernat. #445, #795, #806,
+         #807, #908
+       * Build system, Memory, CPU, TCPConns and Processes plugins: Numerous
+         fixes related to OpenBSD support have been added. Thanks to Landry
+         Breuil. #777, #778, #779, #808
+       * Build system: Plugins now only export "module_register()". Thanks to
+         Florian Forster.
+       * Build system: Various cleanups and improvements have been done. Thanks
+         to Marc Fournier.
+       * collectd: Numerous internal changes and improvements to the daemon and
+         the plugin API have been make. Thanks to Florian Forster, Pierre-Yves
+         Ritschard and Alex Petrov. #512, #727
+       * collectd: Numerous spelling mistakes have been corrected in comments
+         and documentation and several error messages have been improved.
+         Thanks to Ruben Kerkhof, Abhinav Upadhyay, Olivier Bazoud, Pierre-Yves
+         Ritschard, Tim Smith, Moshe Zada, Katelyn Perry and Marc Fournier.
+       * collectd: Rules/Targets can now be appended to existing Filter Chains.
+         Thanks to Marc Falzon. #444
+       * collectd: Failing Filter Chains destinations will now log the list of
+         available write targets. Thanks to Wilfried Goesgens. #650, #1043
+       * collectd: Support for process signaling and management by upstart and
+         systemd has been implemented for the Linux platform. Thanks to
+         Pierre-Yves Ritschard and Marc Fournier. #798, #811, #814
+       * collectd: The "CollectInternalStats" option has been added. Thanks to
+         Yves Mettier. #691
+       * collectd: The daemon source code and dependencies have moved to the
+         "src/daemon/" directory. Thanks to Florian Forster.
+       * collectd: The new "MaxReadInterval" option allows to cap the
+         exponential retry interval of plugins read errors. Thanks to Alexey
+         Remizov and Florian Forster. #713
+       * collectd: The "-P" command-line option now has precedence over the
+         "PIDFile" option. Thanks to Thomas D. #553
+       * collection.cgi: Various data-source related adjustments have been
+         made. Thanks to Fabiano Pires and Sebastian Harl.
+       * libcollectdclient: Now propagates errors when signing / encrypting
+         network packets. Thanks to Florian Forster.
+       * Configuration: Support for unquoted IPv6 addresses has been added.
+         Thanks to Sebastian Harl. #489
+       * Documentation: Various improvements have been done. Thanks to Florian
+         Forster and Marc Fournier.
+       * Examples: the sample C plugin has been updated to the current plugin
+         API. Thanks to Sebastian Harl.
+       * Licensing: The following components have been relicensed to the MIT
+         license: the Apple Sensors, Ascent, DBI, E-Mail, Entropy, GenericJMX,
+         gmond, LogFile, nginx, Notify Desktop, NTPd, NUT, olsrd, Perl, Ping,
+         PostgreSQL, Protocols, RouterOS, RRDCacheD, SNMP, StatsD, SysLog,
+         Table, Tail, UnixSock, vmem, VServer, Wireless, Write Riemann and XMMS
+         plugins, the core collectd daemon, the collectdmon, collectd-nagios
+         and collectd-tg utilities, all the Targets and Matches, liboconfig,
+         most of the "utils_*" files and the plugin API.
+       * Tests: A test suite has been added. Thanks to Florian Forster.
+       * Threshold: The hysteresis calculation has been made more reliable.
+         Thanks to Jan Kundrát. #581
+       * Threshold: Various fixes and improvements have been made. Thanks to
+         Manuel Luis Sanmartín Rozada. #649, #644
+       * AMQP plugin: The "ConnectionRetryDelay" option has been added,
+         allowing to delay reconnection. Thanks to Yoga Ramalingam and Marc
+         Fournier. #833
+       * AMQP plugin: The "QueueDurable" and "QueueAutoDelete" options have
+         been added, giving control over queue creation and deletion. Thanks to
+         David Blundell and Marc Fournier. #623
+       * Apache, Ascent, BIND, cURL, cURL-JSON, cURL-XML, nginx and Write HTTP
+         plugins: Customizing the "User-Agent" field is now possible at
+         compile-time. Thanks to Jeremy Katz. #440
+       * Apache, Ascent, BIND, cURL, cURL-JSON, cURL-XML, nginx plugins: The
+         connection will be reset if it hasn't completed within the configured
+         "Interval". The new "Timeout" option gives control over this behavior.
+         Thanks to Jan Kundrát and Marc Fournier. #982, #983, #993
+       * Apache, Ascent, cURL, cURL-JSON, cURL-XML, nginx, Write HTTP plugins:
+         Allow usernames and passwords to contain colons if built against
+         libcurl ≧ 7.19.1. Thanks to Marc Fournier. #695, #947
+       * Apache plugin: The "SSLCiphers" option gives control over the
+         encryption algorithms to use with TLS connections. Thanks to Toni
+         Moreno. #946
+       * Barometer plugin: This new plugin reads sensor data from various
+         Freescale and Bosch digital barometers. Thanks to Tomas Menzl. #69,
+         #693
+       * Battery plugin: Reporting values as percentages and reporting degraded
+         batteries has been added. Thanks to Florian Forster.
+       * Battery plugin: Support for reading values from sysfs on Linux has
+         been added. Thanks to Andy Parkins, Nicholas Humfrey, Peter Wu and
+         Florian Forster. #725, #810, #998
+       * Battery plugin: The value for current is no longer supplied unless the
+         battery provides this information. Thanks to Florian Forster.
+       * BIND plugin: Bind's XML v3 API is now supported; Thanks to Victor
+         Berger, Bruno Prémont and Michal Humpula. #742, #847
+       * Ceph plugin: This new plugin collects statistics from the Ceph
+         distributed storage system. Thanks to Dan Ryder, Dennis Zou, Colin
+         McCabe, Sage Weil. #522, #598
+       * ConnTrack plugin: Support for reporting values as percentages as well
+         as legacy conntrack files in "/proc" has been added. Thanks to
+         Pierre-Yves Ritschard. #497, #680
+       * CPU plugin: The plugin is now able to report values as percentages and
+         aggregate values per-state and per-CPU. Thanks to Pierre-Yves
+         Ritschard, Florian Forster, Fabien Wernli, Nicholas Humfrey and
+         Wilfried Goesgens. #499, #516, #639 #734, #812, #802
+       * cURL-JSON plugin: Extracting values from complex JSON structures has
+         been enhanced. Thanks to Jim Radford. #408, #411
+       * cURL-JSON plugin: Intervals can now be configured on a per-URL basis.
+         Thanks to Stan Sawa. #685
+       * cURL-JSON, cURL-XML, Write HTTP plugins: These plugins now also follow
+         HTTP redirects. Thanks to Marc Fournier.
+       * cURL, cURL-JSON, cURL-XML plugins: HTTP Digest authentication has been
+         implemented. Thanks to Frank Cornelis. #482
+       * DBI, Oracle, PostgreSQL plugins: A "MetadataFrom" parameter has been
+         added which allows to set metadata from database columns. Thanks to
+         Mark Wong. #317, #321
+       * DBI plugin: Querying several databases in parallel is now possible.
+         Thanks to Vincent Bernat. #453
+       * Disk plugin: On the Linux platform, disk names can now get looked up
+         in udev with the "UdevNameAttr" option. Thanks to Patrick Mooney. #537
+       * Disk plugin: This plugin now collects several additional I/O-related
+         metrics on the Linux platform. Thanks to Florian Forster and Michael
+         Schenck. #705, #759
+       * DRBD plugin: This new plugin reads Linux's Distributed Replicated
+         Block Device (DRBD) statistics. Thanks to Tim Laszlo. #566, #700
+       * Exec, UnixSock plugins: The "PUTNOTIF" command now allows to set
+         metadata on notifications. Thanks to John-John Tedro. #416
+       * fhcount plugin: This new plugin reports the number of used file
+         handles. Thanks to Jiri Tyr. #1009
+       * GenericJMX plugin: A Class Loader for "JMXConnectorFactory" has been
+         added, allowing the plugin to work with JBOSS > 7. Thanks to Alexandre
+         Moutot. #452
+       * IPC plugin: This new plugin collects information related to shared
+         memory. Thanks to Andrés J. Díaz. #925
+       * Java plugin: Now uses the hostname defined in the configuration file.
+         Thanks to Pierre-Yves Ritschard. #530, #681
+       * Load plugin: The plugin is now able to report values as percentages.
+         Thanks to Vedran Bartonicek and Pierre-Yves Ritschard. #344, #498
+       * Log Logstash plugin: This new plugin writes collectd logs and events
+         as Logstash JSON formatted events. Thanks to Pierre-Yves Ritschard.
+         #360
+       * LVM plugin: The plugin collects thin pool data volumes size, and no
+         longer reports virtual volumes. Thanks to Benjamin Gilbert. #603
+       * memcached plugin: "listen_disabled_num" are now also reported. Thanks
+         to Matt Cottingham. #622
+       * Memory plugin: Slab memory reporting on the Linux platform has been
+         added. Thanks to Manuel CISSÉ and Marc Fournier. #560, #697
+       * Memory plugin: The plugin is now able to report values as percentages.
+         Thanks to Jeremy Katz, Florian Forster and Manuel CISSÉ. #501, #511,
+         #559
+       * Modbus plugin: Selecting between holding and input registers is now
+         possible. Thanks to Jan Vitek. #338
+       * Modbus plugin: Support for accessing devices through an RS-485 serial
+         port has been added. Thanks to Eric Sandeen.
+       * Multimeter plugin: This plugin isn't built by default on the AIX
+         platform anymore. Thanks to Manuel Luis Sanmartin Rozada. #549, #684
+       * MySQL and PostgreSQL plugins: Passing "127.0.0.1" as a host will now
+         result in the global Hostname being used in metric names. Thanks to
+         Jeremy Katz. #441
+       * MySQL plugin: InnoDB, Select and Sort statistics collection has been
+         added. Thanks to Wilson Felipe, Marek Becka and Pierre-Yves Ritschard.
+         #248, #621, #699, #824
+       * MySQL plugin: The "Alias" and "ConnectTimeout" options have been
+         added. Thanks to William Tisäter.
+       * Netlink plugin: Support for 64bit netlink counters has been added.
+         Thanks to Marek Becka. #435
+       * Network plugin: The "ReconnectInterval" configuration option has been
+         added. Thanks to John Ferlito. #732
+       * NFS plugin: Support for NFSv4.0 has been implemented. Thanks to Marek
+         Becka. #550
+       * OneWire plugin: Support for more temperature-providing sensor families
+         has been added. Thanks to Tomasz Torcz. #672
+       * OneWire plugin: Support for full OWFS path and more device families
+         has been implemented. Thanks to Tomas Menzl. #68
+       * OpenLDAP plugin: This new plugin reads monitoring information from
+         OpenLDAP's "cn=Monitor" subtree. Thanks to Kimo Rosenbaum, Marc
+         Fournier and Nicholas Humfrey. #719
+       * OpenVPN plugin: Support for OpenVPN 2.3.0 has been implemented. Thanks
+         to Ed Okerson. #252
+       * OpenVZ plugin: Various improvements have been made, making the plugin
+         report values like the other collectd plugins do. Thanks to Chris
+         Lundquist. #264
+       * Perl plugin: A new "listval_filter" method has been added, various
+         internal cleanups and improvements have been made and a test suite has
+         been added. Thanks to Matthias Bethke. #728
+       * PostgreSQL plugin: The new "ExpireDelay" option allows skipping older
+         values pending write when the database slows down. Thanks to Stephen
+         O'Dor. #593
+       * PowerDNS plugin: The plugin was updated for stats from pdns 3.4.3.
+         Thanks to Ruben Kerkhof. #965
+       * Processes plugin: A memory-usage related optimization for low-profile
+         systems has been added. Thanks to Florian Forster. #652
+       * Python plugin: Support for Python3 has been improved, "ModulePath" is
+         now prepended to "sys.path", and the "get_dataset()" function has been
+         added to the Python API. Thanks to Sven Trenkel and Patrick Browne.
+         #890, #751, #771
+       * Redis and Write_Redis plugins: The support library has been switched
+         from credis to hiredis. Thanks to Andrés J. Díaz, Victor Seva, Marc
+         Fournier, Johan Bergström, Michael Spiegle and brianpkelly. #296,
+         #464, #475, #799, #1030
+       * Redis plugin: Custom commands can now be used to fetch values stored
+         in Redis. Thanks to Pierre-Yves Ritschard. #816
+       * Redis plugin: Support for passwords up to 512 characters long has been
+         added. Thanks to Jeremy Katz. #532
+       * Sensors plugin: Support for lm_sensors' power sensors has been added.
+         Thanks to Jan Kundrát. #571
+       * SMART plugin: This new plugin collects SMART statistics from disk
+         drives. Thanks to Vincent Bernat. #797
+       * SNMP plugin: A blacklist/whitelist feature can now be used to filter
+         which OIDs to collect. Thanks to Christophe Courtaut. #414
+       * SNMP plugin: SNMPv3 authentication and encryption support has been
+         implemented. Thanks to Michael Pilat. #362
+       * SNMP plugin: Two error messages have been disambiguated. Thanks to
+         Sergey. #939, #952
+       * Swap plugin: The plugin is now able to report values as percentages.
+         Thanks to Jeremy Katz and Florian Forster. #500, #510
+       * Swap plugin: The plugin no longer fails on Linux systems where
+         "SwapCached" isn't exposed by the kernel. Thanks to Florian Forster.
+         #733
+       * Tail plugin: "GaugeInc" and "GaugeAdd" options have been implemented.
+         Thanks to Andre Ferraz. #673
+       * Tail plugin: Intervals can now be configured on a per-File basis.
+         Thanks to Tom Leaman. #446
+       * TCPConns plugin: The "AllPortsSummary" option, allowing to summarize
+         all connections, has been added. Thanks to Marek Becka. #488
+       * TCPConns plugin: Three metrics were renamed on the AIX platform, for
+         the sake of consistency. Thanks to Manuel Luis Sanmartín Rozada. #546
+       * Turbostat plugin: This new plugin reads CPU frequency and C-state
+         residency on modern Intel turbo-capable processors. Thanks to Vincent
+         Brillault, Jean Delvare and Nicolas Iooss. #651
+       * UnixSock plugin: The "GETTHRESHOLD" command has been re-added. Thanks
+         to Manuel Luis Sanmartín Rozada. #674
+       * Varnish plugin: Varnish 4 support has been added, as well as as
+         monitoring metrics only available in Varnish 4. Thanks to Marc
+         Fournier. #618, #783
+       * virt plugin: Guests memory usage is now also collected. Thanks to
+         Tiago Carvalho, jazzmes and Zollner Robert.
+       * virt plugin: It is now possible to chose between using guests' name or
+         UUID as plugin_instance. Thanks to Remi Ferrand. #385
+       * virt plugin: The libvirt plugin has been renamed to virt. Thanks to
+         Florian Forster.
+       * Write Graphite plugin: When the connection to graphite fails,
+         reconnection attempts are now limited to once per second. Thanks to
+         Florian Forster. #625
+       * Write HTTP plugin: Multi-instance support of this plugin has been
+         improved. The "<URL "url">" block has been deprecated in favor of
+         "<Node "identifier">". Thanks to Marc Fournier. #902
+       * Write HTTP plugin: Several TLS-related configuration options have been
+         added. Thanks to Ingmar Runge. #666
+       * Write HTTP plugin: The "LowSpeedLimit" and "Timeout" options allow to
+         reset slow/stalled network connections. Thanks to loginator17 and Marc
+         Fournier. #752, #985
+       * Write HTTP plugin: The size of the payload posted to the HTTP server
+         can now be controlled with the "BufferSize" option. Thanks to Florian
+         Forster. #722
+       * Write Kafka plugin: This new plugin sends data to Apache Kafka, a
+         distributed messaging queue. Thanks to Pierre-Yves Ritschard,
+         ciomaire, Vincent Bernat, Marc Fournier. #670, #694, #794, #853, #014
+       * Write Log plugin: This new plugin dispatches collected values to the
+         configured log destination(s). Thanks to Pierre-Yves Ritschard. #886
+       * Write Riemann plugin: Extra meta strings are now added as attributes
+         in notifications. Thanks to John-John Tedro. #417
+       * Write Riemann plugin: Notification message are now sent to the Riemann
+         server via the description field. Thanks to Adrian Miron. #575
+       * Write Riemann plugin: Support for custom attributes has been added.
+         Thanks to Pierre-Yves Ritschard. #459
+       * Write Riemann plugin: Support had been implemented for sending events
+         to Riemann in batches (when using TCP), and is enabled by default.
+         Thanks to Pierre-Yves Ritschard. #800
+       * Write Riemann plugin: The "EventServicePrefix" option has been added,
+         which adds a prefix to event service names. Thanks to Moshe Zada. #706
+       * Write Riemann plugin: Threshold checks can now be passed down to the
+         Riemann server. Thanks to Pierre-Yves Ritschard. #518
+       * Write Sensu plugin: This new plugin submits values to Sensu, a stream
+         processing and monitoring system. Thanks to Fabrice A. Marie and Marc
+         Fournier. #912, #1001, #1016
+       * Write TSDB plugin: This new plugin sends data to OpenTSDB, a scalable
+         time series database. Thanks to Kevin Bowling, Florian Forster, Dallin
+         Young, Michael Schenck and Pierre-Yves Ritschard. #703, #772, #945
+       * ZFS ARC plugin: Support for ZFS-on-Linux has been added. Thanks to
+         Marc Fournier and Wilfried Goesgens. #552
+       * Zookeeper plugin: This new plugin reads data from the Apache Zookeeper
+         "MNTR" command. Thanks to Jeremy Katz. #826
+
 2015-02-26, Version 5.4.2
        * Build system: Numerous fixes. Thanks to Bjørn Nordbø, Jim Radford,
          KOMEDA Shinji, Lauri Tirkkonen, Manuel Luis Sanmartin Rozada, Marc
 
 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
diff --git a/README b/README
index 430f52cdbb1f5e6b17399e2744a56cf249401844..3e2c0233adc3ea9ccfbcbbf072c107a0f6dcbd5b 100644 (file)
--- a/README
+++ b/README
@@ -16,22 +16,27 @@ Features
   * collectd is able to collect the following data:
 
     - apache
-      Apache server utilization: Number of bytes transfered, number of
+      Apache server utilization: Number of bytes transferred, number of
       requests handled and detailed scoreboard statistics
 
     - apcups
       APC UPS Daemon: UPS charge, load, input/output/battery voltage, etc.
 
     - apple_sensors
-      Sensors in Macs running Mac OS X / Darwin: Temperature, fanspeed and
+      Sensors in Macs running Mac OS X / Darwin: Temperature, fan speed and
       voltage sensors.
 
     - aquaero
-      Various sensors in the Aquaero 5 watercooling board made by Aquacomputer.
+      Various sensors in the Aquaero 5 water cooling board made by Aquacomputer.
 
     - ascent
       Statistics about Ascent, a free server for the game `World of Warcraft'.
 
+    - barometer
+      Reads absolute barometric pressure, air pressure reduced to sea level and
+      temperature.  Supported sensors are MPL115A2 and MPL3115 from Freescale
+      and BMP085 from Bosch.
+
     - battery
       Batterycharge, -current and voltage of ACPI and PMU based laptop
       batteries.
@@ -40,6 +45,9 @@ Features
       Name server and resolver statistics from the `statistics-channel'
       interface of BIND 9.5, 9,6 and later.
 
+    - ceph
+      Statistics from the Ceph distributed storage system.
+
     - cgroups
       CPU accounting information for process groups under Linux.
 
@@ -80,7 +88,10 @@ Features
 
     - dns
       DNS traffic: Query types, response codes, opcodes and traffic/octets
-      transfered.
+      transferred.
+
+    - drbd
+      Collect individual drbd resource statistics.
 
     - email
       Email statistics: Count, traffic, spam scores and checks.
@@ -96,6 +107,9 @@ Features
       Values gathered by a custom program or script.
       See collectd-exec(5).
 
+    - fhcount
+      File handles statistics.
+
     - filecount
       Count the number of files in directories.
 
@@ -106,19 +120,23 @@ Features
       Receive multicast traffic from Ganglia instances.
 
     - hddtemp
-      Harddisk temperatures using hddtempd.
+      Hard disk temperatures using hddtempd.
 
     - interface
       Interface traffic: Number of octets, packets and errors for each
       interface.
 
-    - iptables
-      Iptables' counters: Number of bytes that were matched by a certain
-      iptables rule.
+    - ipc
+      IPC counters: semaphores used, number of allocated segments in shared
+      memory and more.
 
     - ipmi
       IPMI (Intelligent Platform Management Interface) sensors information.
 
+    - iptables
+      Iptables' counters: Number of bytes that were matched by a certain
+      iptables rule.
+
     - ipvs
       IPVS connection statistics (number of connections, octets and packets
       for each service and destination).
@@ -138,9 +156,6 @@ Features
       Detailed CPU statistics of the “Logical Partitions” virtualization
       technique built into IBM's POWER processors.
 
-    - libvirt
-      CPU, memory, disk and network I/O statistics from virtual machines.
-
     - lvm
       Size of “Logical Volumes” (LV) and “Volume Groups” (VG) of Linux'
       “Logical Volume Manager” (LVM).
@@ -150,7 +165,7 @@ Features
       interfaces that use the Atheros chipset and the MadWifi driver.
 
     - mbmon
-      Motherboard sensors: temperature, fanspeed and voltage information,
+      Motherboard sensors: temperature, fan speed and voltage information,
       using mbmon(1).
 
     - md
@@ -209,13 +224,13 @@ Features
     - ntpd
       NTP daemon statistics: Local clock drift, offset to peers, etc.
 
+    - numa
+      Information about Non-Uniform Memory Access (NUMA).
+
     - nut
       Network UPS tools: UPS current, voltage, power, charge, utilisation,
       temperature, etc. See upsd(8).
 
-    - numa
-      Information about Non-Uniform Memory Access (NUMA).
-
     - olsrd
       Queries routing information from the “Optimized Link State Routing”
       daemon.
@@ -224,6 +239,9 @@ Features
       Read onewire sensors using the owcapu library of the owfs project.
       Please read in collectd.conf(5) why this plugin is experimental.
 
+    - openldap
+      Read monitoring information from OpenLDAP's cn=Monitor subtree.
+
     - openvpn
       RX and TX of each client in openvpn-status.log (status-version 2).
       <http://openvpn.net/index.php/documentation/howto.html>
@@ -267,7 +285,7 @@ Features
       See collectd-python(5) for details.
 
     - redis
-      The redis plugin gathers information from a redis server, including:
+      The redis plugin gathers information from a Redis server, including:
       uptime, used memory, total connections etc.
 
     - routeros
@@ -288,19 +306,27 @@ Features
       to have its measurements fed to collectd. This includes multimeters,
       sound level meters, thermometers, and much more.
 
+    - smart
+      Collect SMART statistics, notably load cycle count, temperature
+      and bad sectors.
+
     - snmp
       Read values from SNMP (Simple Network Management Protocol) enabled
       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..
+      Pages swapped out onto hard disk or whatever is called `swap' by the OS..
 
     - table
       Parse table-like structured files.
 
     - tail
-      Follows (tails) logfiles, parses them by lines and submits matched
+      Follows (tails) log files, parses them by lines and submits matched
       values.
 
     - tail_csv
@@ -326,6 +352,10 @@ Features
       Reads the number of records and file size from a running Tokyo Tyrant
       server.
 
+    - turbostat
+      Reads CPU frequency and C-state residency on modern Intel
+      turbo-capable processors.
+
     - uptime
       System uptime statistics.
 
@@ -335,6 +365,9 @@ Features
     - varnish
       Various statistics from Varnish, an HTTP accelerator.
 
+    - virt
+      CPU, memory, disk and network I/O statistics from virtual machines.
+
     - vmem
       Virtual memory statistics, e. g. the number of page-ins/-outs or the
       number of pagefaults.
@@ -352,6 +385,9 @@ Features
     - zfs_arc
       Statistics for ZFS' “Adaptive Replacement Cache” (ARC).
 
+    - zookeeper
+      Read data from Zookeeper's MNTR command.
+
   * Output can be written or sent to various destinations by the following
     plugins:
 
@@ -404,6 +440,12 @@ Features
       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_log
+      Writes data to the log
+
     - write_mongodb
       Sends data to MongoDB, a NoSQL database.
 
@@ -413,11 +455,19 @@ Features
     - write_riemann
       Sends data to Riemann, a stream processing and monitoring system.
 
+    - write_sensu
+      Sends data to Sensu, a stream processing and monitoring system, via the
+      Sensu client local TCP socket.
+
+    - write_tsdb
+      Sends data OpenTSDB, a scalable no master, no shared state time series
+      database.
+
   * Logging is, as everything in collectd, provided by plugins. The following
     plugins keep us 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 +480,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
@@ -501,7 +554,7 @@ Features
       values are out of bounds. See collectd-threshold(5) for details.
 
     - uuid
-      Sets the hostname to an unique identifier. This is meant for setups
+      Sets the hostname to a unique identifier. This is meant for setups
       where each client may migrate to another physical host, possibly going
       through one or more name changes in the process.
 
@@ -509,7 +562,7 @@ Features
     time starting up again and again. With the exception of the exec plugin no
     processes are forked. Caching in output plugins, such as the rrdtool and
     network plugins, makes sure your resources are used efficiently. Also,
-    since collectd is programmed multithreaded it benefits from hyperthreading
+    since collectd is programmed multithreaded it benefits from hyper-threading
     and multicore processors and makes sure that the daemon isn't idle if only
     one plugin waits for an IO-operation to complete.
 
@@ -521,7 +574,7 @@ Operation
 ---------
 
   * collectd's configuration file can be found at `sysconfdir'/collectd.conf.
-    Run `collectd -h' for a list of builtin defaults. See `collectd.conf(5)'
+    Run `collectd -h' for a list of built-in defaults. See `collectd.conf(5)'
     for a list of options and a syntax description.
 
   * When the `csv' or `rrdtool' plugins are loaded they'll write the values to
@@ -565,7 +618,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.
 
@@ -582,16 +635,26 @@ Prerequisites
     particular.
     <http://developer.apple.com/corefoundation/>
 
+  * libatasmart (optional)
+    Used by the `smart' plugin.
+    <http://git.0pointer.de/?p=libatasmart.git>
+
+  * libcap (optional)
+    The `turbostat' plugin can optionally build Linux Capabilities support,
+    which avoids full privileges requirement (aka. running as root) to read
+    values.
+    <http://sites.google.com/site/fullycapable/>
+
   * libclntsh (optional)
     Used by the `oracle' plugin.
 
-  * libcredis (optional)
-    Used by the redis plugin. Please note that you require a 0.2.2 version
-    or higher. <http://code.google.com/p/credis/>
+  * libhiredis (optional)
+    Used by the redis plugin. Please note that you require a 0.10.0 version
+    or higher. <https://github.com/redis/hiredis>
 
   * 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 +674,31 @@ 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)
 
+  * libldap (optional)
+    Used by the `openldap' plugin.
+    <http://www.openldap.org/>
+
+  * 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 +708,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 +718,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 +729,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 +760,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 +770,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 +797,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 +807,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 +819,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
+    `virt' 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 `ceph', `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
@@ -821,6 +903,23 @@ Configuring with libjvm
   Adding "-ljvm" to the JAVA_LDFLAGS is done automatically, you don't have to
   do that.
 
+Generating the configure script
+-------------------------------
+
+Collectd ships with a `build.sh' script to generate the `configure'
+script shipped with releases.
+
+To generate the `configure` script, you'll need the following dependencies:
+
+- autoconf
+- automake
+- flex
+- bison
+- libtool
+- libtool-ltdl
+
+The `build.sh' script takes no arguments.
+
 Crosscompiling
 --------------
 
@@ -857,7 +956,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 +965,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 84e659265850dceafd0650c4a9bb7297e728b11f..450f87ae8ff96be28fb6d719a3ea1d0d90755fb7 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
 {
@@ -251,6 +256,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.
    */
index 060f9442fb18544d74cf3e365e6e00a01bc24d96..4b66097801c7ed1fbbf4317d5428a6c4365af570 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 410c61c60ef21d2d350e29a699fe1c2e5630d42c..ea7bd64f01920d9fe6c2186b1dd7e97a993ecb27 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 fbfd3061cf0d2ef10b56abd57d4e60fa754ce82d..545f41eb268f5782a34906d7e2d4cdfcc895f3ab 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 ba0350a24312905f440fd6c84f343a3efc9e578d..a516df5463e2350614edf1a41ddbf3f6eba31609 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 7b1c71a470d4f441a68a69c9fb5740ab9c1addb6..b19c77918e5d81784f8b22b904ced3c98b9e484f 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 cc8a99e6e0f7aeb1173381711e4bd0b4c5281895..20a03d2aab111aab8766a7965a922fd5a63ba6aa 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 d278fe21a47db3e57d4f8e79baa8c4116c559a0e..ddff6cd93dd68c5a6a6940746afcc70ba4808af2 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 67f1898ba2411a08892fe84734a5f3ad35980d46..996841aad7216d518bc1b01d1b6e5b76c2ac711b 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 108c54ed0c608bed8230fe55daf5214859cc7909..e496d3c2caaf936d14d71e2d47c82c5bf3ae44d2 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 65f6181806c21d155e49e7945ad341d27161a22a..b4c2321c223f8f5150ae29793b27e4f38ec2d922 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 74412a32047202264e7496a4c65f7b2b1e457ece..1f5ece1672fa80e2595ea67626167aa456406843 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 28e0230b6856ad99af6a4e0851c382e64eb6cf3c..f95169a606d909b8e878d53e64d3ba814a0d47de 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 98230730280ca44426048e8fefda316ccd9e809e..3cba5eb043508aaa5fd1532334fb2065a77df913 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 4c6a778d0c31123a7e4d6f37daa855a4bbe27eb6..08d8b7088649d45ef9a9db7b02516af0cbceb61a 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 1ebafff7a066d63942fb2db23405edc3d0fc76b7..0a33773a76ddfe2671fc7531c63b0f37854950ea 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 319615c96ff43752a44d6ac985bed8b903832756..a678d5fb9ff8f7f932a0544c2a82d14122715ea7 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 81aee033e774ce32208d410a33b3094dbcfc384e..ea0f2fa2e54a1a3eabe7ca65517ac336c60ca40d 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>
@@ -84,15 +89,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 () /* {{{ */
@@ -116,6 +113,7 @@ private void connect () /* {{{ */
 
     environment = new HashMap ();
     environment.put (JMXConnector.CREDENTIALS, credentials);
+    environment.put(JMXConnectorFactory.PROTOCOL_PROVIDER_CLASS_LOADER, this.getClass().getClassLoader());
   }
 
   try
index b1fbfb3ec18c14fadf0ae56c845d8ff76a0f5417..64a53acb0fa744bd8b901e5d5b7d28ab8334e0d0 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 9fb0fc2eda9fd175038e755e7c1260b4456c160a..4b42c91171036ca70d213d0f1131373f79b7f572 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 6e6a2fb09e5233918670dd199bacbf9a387a8370..050d8936f6d48c8bac4163419211b24a86d05c47 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 f2ef2fd33c1799a6d44f265018c34d8eb3588716..68fb260d581440854e5217c580fadf77e36c215f 100644 (file)
@@ -1,8 +1,9 @@
 use ExtUtils::MakeMaker;
 
 WriteMakefile(
-       'NAME'          => 'Collectd',
-       'AUTHOR'        => 'Sebastian Harl <sh@tokkee.org>',
+       NAME                    => 'Collectd',
+       AUTHOR                  => 'Sebastian Harl <sh@tokkee.org>',
+       TEST_REQUIRES   => { 'YAML::Any' => 0 },
 );
 
 # vim: set sw=4 ts=4 tw=78 noexpandtab :
diff --git a/bindings/perl/lib/Collectd/MockDaemon.pm b/bindings/perl/lib/Collectd/MockDaemon.pm
new file mode 100644 (file)
index 0000000..381b2d1
--- /dev/null
@@ -0,0 +1,10745 @@
+package Collectd::MockDaemon;
+use strict;
+use warnings;
+use IO::Socket::UNIX;
+use IO::Handle;
+use File::Temp;
+use Carp;
+use YAML::Any qw/Load/;
+
+use base 'Exporter';
+our @EXPORT = qw/ mockd_start mockd_stop /;
+
+my ($pid, $childfh, $sock_path);
+my $data = Load(do{local $/; <DATA>});
+my @metrics = sort keys %$data;
+
+sub mockd_start {
+    croak "don't call me twice" if defined $pid;
+    $sock_path = File::Temp::mktemp('collectd-mocksock.XXXXXX');
+
+    my $sock = IO::Socket::UNIX->new(
+        Type => SOCK_STREAM,
+        Local => $sock_path,
+        Listen => 1
+    ) or die "Can't open Unix domain socket `$sock_path': $!";
+    $pid = open(my $kid, "-|");
+    croak "cannot fork(): $!" unless defined $pid;
+    if($pid) {
+        $childfh = $kid;
+    } else {
+        daemon($sock);
+        exit 0;
+    }
+    return $sock_path;
+}
+
+sub mockd_stop {
+    return unless defined $childfh;
+    kill 'TERM', $pid;  # kill it with fire
+    unlink $sock_path;
+    $childfh = $pid = undef;
+}
+
+sub daemon {
+    my $sock = shift;
+    while(my $csock = $sock->accept) {
+        while(<$csock>) {
+            chomp;
+            /^LISTVAL\s*$/i and $csock->print(listval()), next;
+            /^GETVAL\s+(.*)$/i and $csock->print(getval($1), "\n"), next;
+            /^PUTVAL|PUTNOTIF|FLUSH\s+(.*)$/i and $csock->print("-1 Unimplemented command `$1'\n"), next;
+            $csock->print("-1 Unknown command: $_\n"), next;
+        }
+    }
+}
+
+sub listval {
+    my $now = time;
+    return print_nvalues(scalar @metrics) .
+    join('', map { "$now $_\n" } @metrics);
+}
+
+sub getval {
+    my ($val) = @_;
+    $val =~ s/(?:^\s+|\s+$)//g;
+    $val =~ s/(?:^"|"$)//g;
+    my $id = _parse_identifier($val) or return "-1 Cannot parse identifier `$val'";
+    return "-1 No such value ($val)" unless exists $data->{$val};
+    my $result = print_nvalues(scalar keys %{$data->{$val}});
+    return $result . join("\n", map { "$_=$data->{$val}{$_}" } keys %{$data->{$val}});
+}
+
+sub _parse_identifier
+{
+       my $s = shift;
+       my ($plugin_instance, $type_instance);
+
+       my ($host, $plugin, $type) = split ('/', $s);
+    return unless length $host and length $plugin and length $type;
+
+       ($plugin, $plugin_instance) = split ('-', $plugin, 2);
+       ($type, $type_instance) = split ('-', $type, 2);
+
+       my $ident =
+       {
+               host => $host,
+               plugin => $plugin,
+               type => $type
+       };
+       $ident->{'plugin_instance'} = $plugin_instance if (defined ($plugin_instance));
+       $ident->{'type_instance'} = $type_instance if (defined ($type_instance));
+
+       return $ident;
+}
+
+sub print_nvalues {
+    my $nvals = shift;
+    return sprintf("%d Value%s found\n", $nvals, $nvals > 1 ? 's' : '');
+}
+
+1;
+
+__DATA__
+---
+a1d8f6310/cpu-0/cpu-idle:
+  value: 9.999973e+01
+a1d8f6310/cpu-0/cpu-interrupt:
+  value: 0.000000e+00
+a1d8f6310/cpu-0/cpu-nice:
+  value: 0.000000e+00
+a1d8f6310/cpu-0/cpu-softirq:
+  value: 0.000000e+00
+a1d8f6310/cpu-0/cpu-steal:
+  value: 0.000000e+00
+a1d8f6310/cpu-0/cpu-system:
+  value: 0.000000e+00
+a1d8f6310/cpu-0/cpu-user:
+  value: 9.999996e-02
+a1d8f6310/cpu-0/cpu-wait:
+  value: 0.000000e+00
+a1d8f6310/cpu-1/cpu-idle:
+  value: 9.989979e+01
+a1d8f6310/cpu-1/cpu-interrupt:
+  value: 0.000000e+00
+a1d8f6310/cpu-1/cpu-nice:
+  value: 0.000000e+00
+a1d8f6310/cpu-1/cpu-softirq:
+  value: 0.000000e+00
+a1d8f6310/cpu-1/cpu-steal:
+  value: 0.000000e+00
+a1d8f6310/cpu-1/cpu-system:
+  value: 0.000000e+00
+a1d8f6310/cpu-1/cpu-user:
+  value: 0.000000e+00
+a1d8f6310/cpu-1/cpu-wait:
+  value: 0.000000e+00
+a1d8f6310/df-boot/df_complex-free:
+  value: 4.368712e+08
+a1d8f6310/df-boot/df_complex-reserved:
+  value: 2.684109e+07
+a1d8f6310/df-boot/df_complex-used:
+  value: 6.471270e+07
+a1d8f6310/df-boot/df_inodes-free:
+  value: 3.271800e+04
+a1d8f6310/df-boot/df_inodes-reserved:
+  value: 0.000000e+00
+a1d8f6310/df-boot/df_inodes-used:
+  value: 5.000000e+01
+a1d8f6310/df-boot/percent_bytes-free:
+  value: 8.267421e+01
+a1d8f6310/df-boot/percent_bytes-reserved:
+  value: 5.079451e+00
+a1d8f6310/df-boot/percent_bytes-used:
+  value: 1.224634e+01
+a1d8f6310/df-boot/percent_inodes-free:
+  value: 9.984741e+01
+a1d8f6310/df-boot/percent_inodes-reserved:
+  value: 0.000000e+00
+a1d8f6310/df-boot/percent_inodes-used:
+  value: 1.525879e-01
+a1d8f6310/df-data1/df_complex-free:
+  value: 2.636943e+10
+a1d8f6310/df-data1/df_complex-reserved:
+  value: 1.476235e+09
+a1d8f6310/df-data1/df_complex-used:
+  value: 1.215783e+09
+a1d8f6310/df-data1/df_inodes-free:
+  value: 1.797470e+06
+a1d8f6310/df-data1/df_inodes-reserved:
+  value: 0.000000e+00
+a1d8f6310/df-data1/df_inodes-used:
+  value: 4.770000e+03
+a1d8f6310/df-data1/percent_bytes-free:
+  value: 9.073681e+01
+a1d8f6310/df-data1/percent_bytes-reserved:
+  value: 5.079704e+00
+a1d8f6310/df-data1/percent_bytes-used:
+  value: 4.183491e+00
+a1d8f6310/df-data1/percent_inodes-free:
+  value: 9.973533e+01
+a1d8f6310/df-data1/percent_inodes-reserved:
+  value: 0.000000e+00
+a1d8f6310/df-data1/percent_inodes-used:
+  value: 2.646706e-01
+a1d8f6310/df-dev-shm/df_complex-free:
+  value: 9.842483e+08
+a1d8f6310/df-dev-shm/df_complex-reserved:
+  value: 0.000000e+00
+a1d8f6310/df-dev-shm/df_complex-used:
+  value: 0.000000e+00
+a1d8f6310/df-dev-shm/df_inodes-free:
+  value: 2.402940e+05
+a1d8f6310/df-dev-shm/df_inodes-reserved:
+  value: 0.000000e+00
+a1d8f6310/df-dev-shm/df_inodes-used:
+  value: 1.000000e+00
+a1d8f6310/df-dev-shm/percent_bytes-free:
+  value: 1.000000e+02
+a1d8f6310/df-dev-shm/percent_bytes-reserved:
+  value: 0.000000e+00
+a1d8f6310/df-dev-shm/percent_bytes-used:
+  value: 0.000000e+00
+a1d8f6310/df-dev-shm/percent_inodes-free:
+  value: 9.999958e+01
+a1d8f6310/df-dev-shm/percent_inodes-reserved:
+  value: 0.000000e+00
+a1d8f6310/df-dev-shm/percent_inodes-used:
+  value: 4.161551e-04
+a1d8f6310/df-root/df_complex-free:
+  value: 1.072081e+10
+a1d8f6310/df-root/df_complex-reserved:
+  value: 6.442435e+08
+a1d8f6310/df-root/df_complex-used:
+  value: 1.317655e+09
+a1d8f6310/df-root/df_inodes-free:
+  value: 7.423750e+05
+a1d8f6310/df-root/df_inodes-reserved:
+  value: 0.000000e+00
+a1d8f6310/df-root/df_inodes-used:
+  value: 4.405700e+04
+a1d8f6310/df-root/percent_bytes-free:
+  value: 8.453092e+01
+a1d8f6310/df-root/percent_bytes-reserved:
+  value: 5.079700e+00
+a1d8f6310/df-root/percent_bytes-used:
+  value: 1.038938e+01
+a1d8f6310/df-root/percent_inodes-free:
+  value: 9.439786e+01
+a1d8f6310/df-root/percent_inodes-reserved:
+  value: 0.000000e+00
+a1d8f6310/df-root/percent_inodes-used:
+  value: 5.602138e+00
+a1d8f6310/df-var/df_complex-free:
+  value: 7.454015e+09
+a1d8f6310/df-var/df_complex-reserved:
+  value: 4.294943e+08
+a1d8f6310/df-var/df_complex-used:
+  value: 5.716091e+08
+a1d8f6310/df-var/df_inodes-free:
+  value: 5.222690e+05
+a1d8f6310/df-var/df_inodes-reserved:
+  value: 0.000000e+00
+a1d8f6310/df-var/df_inodes-used:
+  value: 2.019000e+03
+a1d8f6310/df-var/percent_bytes-free:
+  value: 8.815979e+01
+a1d8f6310/df-var/percent_bytes-reserved:
+  value: 5.079695e+00
+a1d8f6310/df-var/percent_bytes-used:
+  value: 6.760509e+00
+a1d8f6310/df-var/percent_inodes-free:
+  value: 9.961491e+01
+a1d8f6310/df-var/percent_inodes-reserved:
+  value: 0.000000e+00
+a1d8f6310/df-var/percent_inodes-used:
+  value: 3.850937e-01
+a1d8f6310/disk-vda/disk_merged:
+  read: 0.000000e+00
+  write: 9.999910e-02
+a1d8f6310/disk-vda/disk_octets:
+  read: 0.000000e+00
+  write: 1.228789e+03
+a1d8f6310/disk-vda/disk_ops:
+  read: 0.000000e+00
+  write: 1.999982e-01
+a1d8f6310/disk-vda/disk_time:
+  read: 0.000000e+00
+  write: 4.999955e-01
+a1d8f6310/disk-vda1/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6310/disk-vda1/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6310/disk-vda1/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6310/disk-vda1/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6310/disk-vda2/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6310/disk-vda2/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6310/disk-vda2/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6310/disk-vda2/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6310/disk-vda3/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6310/disk-vda3/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6310/disk-vda3/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6310/disk-vda3/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6310/disk-vda4/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6310/disk-vda4/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6310/disk-vda4/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6310/disk-vda4/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6310/disk-vda5/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6310/disk-vda5/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6310/disk-vda5/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6310/disk-vda5/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6310/disk-vda6/disk_merged:
+  read: 0.000000e+00
+  write: 9.999878e-02
+a1d8f6310/disk-vda6/disk_octets:
+  read: 0.000000e+00
+  write: 1.228786e+03
+a1d8f6310/disk-vda6/disk_ops:
+  read: 0.000000e+00
+  write: 1.999976e-01
+a1d8f6310/disk-vda6/disk_time:
+  read: 0.000000e+00
+  write: 4.999941e-01
+a1d8f6310/load/load:
+  longterm: 7.000000e-02
+  midterm: 6.000000e-02
+  shortterm: 0.000000e+00
+a1d8f6310/memory/memory-buffered:
+  value: 2.348646e+08
+a1d8f6310/memory/memory-cached:
+  value: 5.790310e+08
+a1d8f6310/memory/memory-free:
+  value: 2.351022e+08
+a1d8f6310/memory/memory-used:
+  value: 9.194988e+08
+a1d8f6310/network/if_octets:
+  rx: 0.000000e+00
+  tx: 6.586002e+02
+a1d8f6310/network/if_packets:
+  rx: 0.000000e+00
+  tx: 4.999991e-01
+a1d8f6310/network/queue_length:
+  value: 0.000000e+00
+a1d8f6310/network/total_values-dispatch-accepted:
+  value: 0.000000e+00
+a1d8f6310/network/total_values-dispatch-rejected:
+  value: 0.000000e+00
+a1d8f6310/network/total_values-send-accepted:
+  value: 1.480003e+01
+a1d8f6310/network/total_values-send-rejected:
+  value: 0.000000e+00
+a1d8f6310/swap/swap-cached:
+  value: 4.173824e+06
+a1d8f6310/swap/swap-free:
+  value: 2.118148e+09
+a1d8f6310/swap/swap-used:
+  value: 2.515354e+07
+a1d8f6310/swap/swap_io-in:
+  value: 0.000000e+00
+a1d8f6310/swap/swap_io-out:
+  value: 0.000000e+00
+a1d8f6310/vmem/vmpage_faults:
+  majflt: 0.000000e+00
+  minflt: 6.999952e-01
+a1d8f6310/vmem/vmpage_io-memory:
+  in: 0.000000e+00
+  out: 0.000000e+00
+a1d8f6310/vmem/vmpage_io-swap:
+  in: 0.000000e+00
+  out: 0.000000e+00
+a1d8f6310/vmem/vmpage_number-active_anon:
+  value: 5.748900e+04
+a1d8f6310/vmem/vmpage_number-active_file:
+  value: 1.023940e+05
+a1d8f6310/vmem/vmpage_number-anon_pages:
+  value: 5.851400e+04
+a1d8f6310/vmem/vmpage_number-anon_transparent_hugepages:
+  value: 1.920000e+02
+a1d8f6310/vmem/vmpage_number-boudfe:
+  value: 0.000000e+00
+a1d8f6310/vmem/vmpage_number-dirty:
+  value: 2.000000e+00
+a1d8f6310/vmem/vmpage_number-file_pages:
+  value: 1.997240e+05
+a1d8f6310/vmem/vmpage_number-free_pages:
+  value: 5.739800e+04
+a1d8f6310/vmem/vmpage_number-inactive_anon:
+  value: 1.004470e+05
+a1d8f6310/vmem/vmpage_number-inactive_file:
+  value: 9.618100e+04
+a1d8f6310/vmem/vmpage_number-isolated_anon:
+  value: 0.000000e+00
+a1d8f6310/vmem/vmpage_number-isolated_file:
+  value: 0.000000e+00
+a1d8f6310/vmem/vmpage_number-kernel_stack:
+  value: 1.280000e+02
+a1d8f6310/vmem/vmpage_number-mapped:
+  value: 4.414000e+03
+a1d8f6310/vmem/vmpage_number-mlock:
+  value: 0.000000e+00
+a1d8f6310/vmem/vmpage_number-page_table_pages:
+  value: 2.171000e+03
+a1d8f6310/vmem/vmpage_number-shmem:
+  value: 1.290000e+02
+a1d8f6310/vmem/vmpage_number-slab_reclaimable:
+  value: 5.264400e+04
+a1d8f6310/vmem/vmpage_number-slab_unreclaimable:
+  value: 5.743000e+03
+a1d8f6310/vmem/vmpage_number-unevictable:
+  value: 0.000000e+00
+a1d8f6310/vmem/vmpage_number-unstable:
+  value: 0.000000e+00
+a1d8f6310/vmem/vmpage_number-vmscan_write:
+  value: 7.366000e+03
+a1d8f6310/vmem/vmpage_number-writeback:
+  value: 0.000000e+00
+a1d8f6310/vmem/vmpage_number-writeback_temp:
+  value: 0.000000e+00
+a1d8f6410/cpu-0/cpu-idle:
+  value: 9.920010e+01
+a1d8f6410/cpu-0/cpu-interrupt:
+  value: 0.000000e+00
+a1d8f6410/cpu-0/cpu-nice:
+  value: 0.000000e+00
+a1d8f6410/cpu-0/cpu-softirq:
+  value: 0.000000e+00
+a1d8f6410/cpu-0/cpu-steal:
+  value: 0.000000e+00
+a1d8f6410/cpu-0/cpu-system:
+  value: 1.000001e-01
+a1d8f6410/cpu-0/cpu-user:
+  value: 3.000003e-01
+a1d8f6410/cpu-0/cpu-wait:
+  value: 0.000000e+00
+a1d8f6410/cpu-1/cpu-idle:
+  value: 9.900000e+01
+a1d8f6410/cpu-1/cpu-interrupt:
+  value: 0.000000e+00
+a1d8f6410/cpu-1/cpu-nice:
+  value: 0.000000e+00
+a1d8f6410/cpu-1/cpu-softirq:
+  value: 0.000000e+00
+a1d8f6410/cpu-1/cpu-steal:
+  value: 0.000000e+00
+a1d8f6410/cpu-1/cpu-system:
+  value: 2.000000e-01
+a1d8f6410/cpu-1/cpu-user:
+  value: 2.000002e-01
+a1d8f6410/cpu-1/cpu-wait:
+  value: 2.000000e-01
+a1d8f6410/df-boot/df_complex-free:
+  value: 4.369080e+08
+a1d8f6410/df-boot/df_complex-reserved:
+  value: 2.684109e+07
+a1d8f6410/df-boot/df_complex-used:
+  value: 6.467584e+07
+a1d8f6410/df-boot/df_inodes-free:
+  value: 3.271800e+04
+a1d8f6410/df-boot/df_inodes-reserved:
+  value: 0.000000e+00
+a1d8f6410/df-boot/df_inodes-used:
+  value: 5.000000e+01
+a1d8f6410/df-boot/percent_bytes-free:
+  value: 8.268118e+01
+a1d8f6410/df-boot/percent_bytes-reserved:
+  value: 5.079451e+00
+a1d8f6410/df-boot/percent_bytes-used:
+  value: 1.223936e+01
+a1d8f6410/df-boot/percent_inodes-free:
+  value: 9.984741e+01
+a1d8f6410/df-boot/percent_inodes-reserved:
+  value: 0.000000e+00
+a1d8f6410/df-boot/percent_inodes-used:
+  value: 1.525879e-01
+a1d8f6410/df-data1/df_complex-free:
+  value: 2.740489e+10
+a1d8f6410/df-data1/df_complex-reserved:
+  value: 1.476235e+09
+a1d8f6410/df-data1/df_complex-used:
+  value: 1.803182e+08
+a1d8f6410/df-data1/df_inodes-free:
+  value: 1.802223e+06
+a1d8f6410/df-data1/df_inodes-reserved:
+  value: 0.000000e+00
+a1d8f6410/df-data1/df_inodes-used:
+  value: 1.700000e+01
+a1d8f6410/df-data1/percent_bytes-free:
+  value: 9.429982e+01
+a1d8f6410/df-data1/percent_bytes-reserved:
+  value: 5.079704e+00
+a1d8f6410/df-data1/percent_bytes-used:
+  value: 6.204723e-01
+a1d8f6410/df-data1/percent_inodes-free:
+  value: 9.999906e+01
+a1d8f6410/df-data1/percent_inodes-reserved:
+  value: 0.000000e+00
+a1d8f6410/df-data1/percent_inodes-used:
+  value: 9.432706e-04
+a1d8f6410/df-dev-shm/df_complex-free:
+  value: 2.008437e+09
+a1d8f6410/df-dev-shm/df_complex-reserved:
+  value: 0.000000e+00
+a1d8f6410/df-dev-shm/df_complex-used:
+  value: 0.000000e+00
+a1d8f6410/df-dev-shm/df_inodes-free:
+  value: 4.903400e+05
+a1d8f6410/df-dev-shm/df_inodes-reserved:
+  value: 0.000000e+00
+a1d8f6410/df-dev-shm/df_inodes-used:
+  value: 1.000000e+00
+a1d8f6410/df-dev-shm/percent_bytes-free:
+  value: 1.000000e+02
+a1d8f6410/df-dev-shm/percent_bytes-reserved:
+  value: 0.000000e+00
+a1d8f6410/df-dev-shm/percent_bytes-used:
+  value: 0.000000e+00
+a1d8f6410/df-dev-shm/percent_inodes-free:
+  value: 9.999979e+01
+a1d8f6410/df-dev-shm/percent_inodes-reserved:
+  value: 0.000000e+00
+a1d8f6410/df-dev-shm/percent_inodes-used:
+  value: 2.039397e-04
+a1d8f6410/df-root/df_complex-free:
+  value: 1.030750e+10
+a1d8f6410/df-root/df_complex-reserved:
+  value: 6.442435e+08
+a1d8f6410/df-root/df_complex-used:
+  value: 1.730961e+09
+a1d8f6410/df-root/df_inodes-free:
+  value: 7.294150e+05
+a1d8f6410/df-root/df_inodes-reserved:
+  value: 0.000000e+00
+a1d8f6410/df-root/df_inodes-used:
+  value: 5.701700e+04
+a1d8f6410/df-root/percent_bytes-free:
+  value: 8.127210e+01
+a1d8f6410/df-root/percent_bytes-reserved:
+  value: 5.079700e+00
+a1d8f6410/df-root/percent_bytes-used:
+  value: 1.364820e+01
+a1d8f6410/df-root/percent_inodes-free:
+  value: 9.274991e+01
+a1d8f6410/df-root/percent_inodes-reserved:
+  value: 0.000000e+00
+a1d8f6410/df-root/percent_inodes-used:
+  value: 7.250086e+00
+a1d8f6410/df-var/df_complex-free:
+  value: 6.861853e+09
+a1d8f6410/df-var/df_complex-reserved:
+  value: 4.294943e+08
+a1d8f6410/df-var/df_complex-used:
+  value: 1.163772e+09
+a1d8f6410/df-var/df_inodes-free:
+  value: 5.104480e+05
+a1d8f6410/df-var/df_inodes-reserved:
+  value: 0.000000e+00
+a1d8f6410/df-var/df_inodes-used:
+  value: 1.384000e+04
+a1d8f6410/df-var/percent_bytes-free:
+  value: 8.115620e+01
+a1d8f6410/df-var/percent_bytes-reserved:
+  value: 5.079695e+00
+a1d8f6410/df-var/percent_bytes-used:
+  value: 1.376411e+01
+a1d8f6410/df-var/percent_inodes-free:
+  value: 9.736023e+01
+a1d8f6410/df-var/percent_inodes-reserved:
+  value: 0.000000e+00
+a1d8f6410/df-var/percent_inodes-used:
+  value: 2.639771e+00
+a1d8f6410/disk-vda/disk_merged:
+  read: 0.000000e+00
+  write: 3.569994e+01
+a1d8f6410/disk-vda/disk_octets:
+  read: 0.000000e+00
+  write: 1.724413e+05
+a1d8f6410/disk-vda/disk_ops:
+  read: 0.000000e+00
+  write: 6.399989e+00
+a1d8f6410/disk-vda/disk_time:
+  read: 0.000000e+00
+  write: 3.099995e+01
+a1d8f6410/disk-vda1/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6410/disk-vda1/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6410/disk-vda1/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6410/disk-vda1/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6410/disk-vda2/disk_merged:
+  read: 0.000000e+00
+  write: 3.999993e-01
+a1d8f6410/disk-vda2/disk_octets:
+  read: 0.000000e+00
+  write: 7.372786e+03
+a1d8f6410/disk-vda2/disk_ops:
+  read: 0.000000e+00
+  write: 1.399997e+00
+a1d8f6410/disk-vda2/disk_time:
+  read: 0.000000e+00
+  write: 9.999982e-01
+a1d8f6410/disk-vda3/disk_merged:
+  read: 0.000000e+00
+  write: 3.529993e+01
+a1d8f6410/disk-vda3/disk_octets:
+  read: 0.000000e+00
+  write: 1.650685e+05
+a1d8f6410/disk-vda3/disk_ops:
+  read: 0.000000e+00
+  write: 4.999991e+00
+a1d8f6410/disk-vda3/disk_time:
+  read: 0.000000e+00
+  write: 3.939993e+01
+a1d8f6410/disk-vda4/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6410/disk-vda4/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6410/disk-vda4/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6410/disk-vda4/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6410/disk-vda5/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6410/disk-vda5/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6410/disk-vda5/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6410/disk-vda5/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6410/disk-vda6/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6410/disk-vda6/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6410/disk-vda6/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6410/disk-vda6/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1d8f6410/load/load:
+  longterm: 0.000000e+00
+  midterm: 3.000000e-02
+  shortterm: 5.000000e-02
+a1d8f6410/memory/memory-buffered:
+  value: 3.095921e+08
+a1d8f6410/memory/memory-cached:
+  value: 1.241870e+09
+a1d8f6410/memory/memory-free:
+  value: 2.926060e+08
+a1d8f6410/memory/memory-used:
+  value: 2.172809e+09
+a1d8f6410/network/if_octets:
+  rx: 0.000000e+00
+  tx: 6.586998e+02
+a1d8f6410/network/if_packets:
+  rx: 0.000000e+00
+  tx: 4.999999e-01
+a1d8f6410/network/queue_length:
+  value: 0.000000e+00
+a1d8f6410/network/total_values-dispatch-accepted:
+  value: 0.000000e+00
+a1d8f6410/network/total_values-dispatch-rejected:
+  value: 0.000000e+00
+a1d8f6410/network/total_values-send-accepted:
+  value: 1.479998e+01
+a1d8f6410/network/total_values-send-rejected:
+  value: 0.000000e+00
+a1d8f6410/swap/swap-cached:
+  value: 2.048000e+05
+a1d8f6410/swap/swap-free:
+  value: 2.147271e+09
+a1d8f6410/swap/swap-used:
+  value: 0.000000e+00
+a1d8f6410/swap/swap_io-in:
+  value: 0.000000e+00
+a1d8f6410/swap/swap_io-out:
+  value: 0.000000e+00
+a1d8f6410/vmem/vmpage_faults:
+  majflt: 0.000000e+00
+  minflt: 6.400115e+00
+a1d8f6410/vmem/vmpage_io-memory:
+  in: 0.000000e+00
+  out: 1.684030e+02
+a1d8f6410/vmem/vmpage_io-swap:
+  in: 0.000000e+00
+  out: 0.000000e+00
+a1d8f6410/vmem/vmpage_number-active_anon:
+  value: 2.143920e+05
+a1d8f6410/vmem/vmpage_number-active_file:
+  value: 1.979880e+05
+a1d8f6410/vmem/vmpage_number-anon_pages:
+  value: 2.734200e+04
+a1d8f6410/vmem/vmpage_number-anon_transparent_hugepages:
+  value: 3.880000e+02
+a1d8f6410/vmem/vmpage_number-boudfe:
+  value: 0.000000e+00
+a1d8f6410/vmem/vmpage_number-dirty:
+  value: 2.700000e+01
+a1d8f6410/vmem/vmpage_number-file_pages:
+  value: 3.788250e+05
+a1d8f6410/vmem/vmpage_number-free_pages:
+  value: 7.143700e+04
+a1d8f6410/vmem/vmpage_number-inactive_anon:
+  value: 1.176200e+04
+a1d8f6410/vmem/vmpage_number-inactive_file:
+  value: 1.806700e+05
+a1d8f6410/vmem/vmpage_number-isolated_anon:
+  value: 0.000000e+00
+a1d8f6410/vmem/vmpage_number-isolated_file:
+  value: 0.000000e+00
+a1d8f6410/vmem/vmpage_number-kernel_stack:
+  value: 3.000000e+02
+a1d8f6410/vmem/vmpage_number-mapped:
+  value: 1.012100e+04
+a1d8f6410/vmem/vmpage_number-mlock:
+  value: 0.000000e+00
+a1d8f6410/vmem/vmpage_number-page_table_pages:
+  value: 1.602000e+03
+a1d8f6410/vmem/vmpage_number-shmem:
+  value: 1.170000e+02
+a1d8f6410/vmem/vmpage_number-slab_reclaimable:
+  value: 2.856060e+05
+a1d8f6410/vmem/vmpage_number-slab_unreclaimable:
+  value: 6.201000e+03
+a1d8f6410/vmem/vmpage_number-unevictable:
+  value: 0.000000e+00
+a1d8f6410/vmem/vmpage_number-unstable:
+  value: 0.000000e+00
+a1d8f6410/vmem/vmpage_number-vmscan_write:
+  value: 7.900000e+01
+a1d8f6410/vmem/vmpage_number-writeback:
+  value: 0.000000e+00
+a1d8f6410/vmem/vmpage_number-writeback_temp:
+  value: 0.000000e+00
+a1ddf6210/cpu-0/cpu-idle:
+  value: 9.020090e+01
+a1ddf6210/cpu-0/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6210/cpu-0/cpu-nice:
+  value: 0.000000e+00
+a1ddf6210/cpu-0/cpu-softirq:
+  value: 4.000034e-01
+a1ddf6210/cpu-0/cpu-steal:
+  value: 0.000000e+00
+a1ddf6210/cpu-0/cpu-system:
+  value: 3.000031e-01
+a1ddf6210/cpu-0/cpu-user:
+  value: 4.200047e+00
+a1ddf6210/cpu-0/cpu-wait:
+  value: 0.000000e+00
+a1ddf6210/cpu-1/cpu-idle:
+  value: 9.969991e+01
+a1ddf6210/cpu-1/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6210/cpu-1/cpu-nice:
+  value: 0.000000e+00
+a1ddf6210/cpu-1/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6210/cpu-1/cpu-steal:
+  value: 0.000000e+00
+a1ddf6210/cpu-1/cpu-system:
+  value: 0.000000e+00
+a1ddf6210/cpu-1/cpu-user:
+  value: 2.000011e-01
+a1ddf6210/cpu-1/cpu-wait:
+  value: 0.000000e+00
+a1ddf6210/cpu-10/cpu-idle:
+  value: 9.979942e+01
+a1ddf6210/cpu-10/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6210/cpu-10/cpu-nice:
+  value: 0.000000e+00
+a1ddf6210/cpu-10/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6210/cpu-10/cpu-steal:
+  value: 0.000000e+00
+a1ddf6210/cpu-10/cpu-system:
+  value: 0.000000e+00
+a1ddf6210/cpu-10/cpu-user:
+  value: 9.999943e-02
+a1ddf6210/cpu-10/cpu-wait:
+  value: 0.000000e+00
+a1ddf6210/cpu-11/cpu-idle:
+  value: 9.989938e+01
+a1ddf6210/cpu-11/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6210/cpu-11/cpu-nice:
+  value: 0.000000e+00
+a1ddf6210/cpu-11/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6210/cpu-11/cpu-steal:
+  value: 0.000000e+00
+a1ddf6210/cpu-11/cpu-system:
+  value: 9.999938e-02
+a1ddf6210/cpu-11/cpu-user:
+  value: 0.000000e+00
+a1ddf6210/cpu-11/cpu-wait:
+  value: 0.000000e+00
+a1ddf6210/cpu-2/cpu-idle:
+  value: 9.959987e+01
+a1ddf6210/cpu-2/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6210/cpu-2/cpu-nice:
+  value: 0.000000e+00
+a1ddf6210/cpu-2/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6210/cpu-2/cpu-steal:
+  value: 0.000000e+00
+a1ddf6210/cpu-2/cpu-system:
+  value: 1.999997e-01
+a1ddf6210/cpu-2/cpu-user:
+  value: 9.999988e-02
+a1ddf6210/cpu-2/cpu-wait:
+  value: 0.000000e+00
+a1ddf6210/cpu-3/cpu-idle:
+  value: 9.989985e+01
+a1ddf6210/cpu-3/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6210/cpu-3/cpu-nice:
+  value: 0.000000e+00
+a1ddf6210/cpu-3/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6210/cpu-3/cpu-steal:
+  value: 0.000000e+00
+a1ddf6210/cpu-3/cpu-system:
+  value: 0.000000e+00
+a1ddf6210/cpu-3/cpu-user:
+  value: 0.000000e+00
+a1ddf6210/cpu-3/cpu-wait:
+  value: 0.000000e+00
+a1ddf6210/cpu-4/cpu-idle:
+  value: 9.989964e+01
+a1ddf6210/cpu-4/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6210/cpu-4/cpu-nice:
+  value: 0.000000e+00
+a1ddf6210/cpu-4/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6210/cpu-4/cpu-steal:
+  value: 0.000000e+00
+a1ddf6210/cpu-4/cpu-system:
+  value: 0.000000e+00
+a1ddf6210/cpu-4/cpu-user:
+  value: 0.000000e+00
+a1ddf6210/cpu-4/cpu-wait:
+  value: 0.000000e+00
+a1ddf6210/cpu-5/cpu-idle:
+  value: 9.989956e+01
+a1ddf6210/cpu-5/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6210/cpu-5/cpu-nice:
+  value: 0.000000e+00
+a1ddf6210/cpu-5/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6210/cpu-5/cpu-steal:
+  value: 0.000000e+00
+a1ddf6210/cpu-5/cpu-system:
+  value: 0.000000e+00
+a1ddf6210/cpu-5/cpu-user:
+  value: 0.000000e+00
+a1ddf6210/cpu-5/cpu-wait:
+  value: 0.000000e+00
+a1ddf6210/cpu-6/cpu-idle:
+  value: 8.899957e+01
+a1ddf6210/cpu-6/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6210/cpu-6/cpu-nice:
+  value: 0.000000e+00
+a1ddf6210/cpu-6/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6210/cpu-6/cpu-steal:
+  value: 0.000000e+00
+a1ddf6210/cpu-6/cpu-system:
+  value: 1.599993e+00
+a1ddf6210/cpu-6/cpu-user:
+  value: 9.499956e+00
+a1ddf6210/cpu-6/cpu-wait:
+  value: 0.000000e+00
+a1ddf6210/cpu-7/cpu-idle:
+  value: 9.969946e+01
+a1ddf6210/cpu-7/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6210/cpu-7/cpu-nice:
+  value: 0.000000e+00
+a1ddf6210/cpu-7/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6210/cpu-7/cpu-steal:
+  value: 0.000000e+00
+a1ddf6210/cpu-7/cpu-system:
+  value: 1.999989e-01
+a1ddf6210/cpu-7/cpu-user:
+  value: 9.999947e-02
+a1ddf6210/cpu-7/cpu-wait:
+  value: 0.000000e+00
+a1ddf6210/cpu-8/cpu-idle:
+  value: 9.079948e+01
+a1ddf6210/cpu-8/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6210/cpu-8/cpu-nice:
+  value: 0.000000e+00
+a1ddf6210/cpu-8/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6210/cpu-8/cpu-steal:
+  value: 0.000000e+00
+a1ddf6210/cpu-8/cpu-system:
+  value: 8.999950e-01
+a1ddf6210/cpu-8/cpu-user:
+  value: 8.099954e+00
+a1ddf6210/cpu-8/cpu-wait:
+  value: 0.000000e+00
+a1ddf6210/cpu-9/cpu-idle:
+  value: 9.989942e+01
+a1ddf6210/cpu-9/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6210/cpu-9/cpu-nice:
+  value: 0.000000e+00
+a1ddf6210/cpu-9/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6210/cpu-9/cpu-steal:
+  value: 0.000000e+00
+a1ddf6210/cpu-9/cpu-system:
+  value: 9.999942e-02
+a1ddf6210/cpu-9/cpu-user:
+  value: 0.000000e+00
+a1ddf6210/cpu-9/cpu-wait:
+  value: 0.000000e+00
+a1ddf6210/df-boot/df_complex-free:
+  value: 3.880919e+08
+a1ddf6210/df-boot/df_complex-reserved:
+  value: 2.684109e+07
+a1ddf6210/df-boot/df_complex-used:
+  value: 1.134920e+08
+a1ddf6210/df-boot/df_inodes-free:
+  value: 3.270600e+04
+a1ddf6210/df-boot/df_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6210/df-boot/df_inodes-used:
+  value: 6.200000e+01
+a1ddf6210/df-boot/percent_bytes-free:
+  value: 7.344315e+01
+a1ddf6210/df-boot/percent_bytes-reserved:
+  value: 5.079451e+00
+a1ddf6210/df-boot/percent_bytes-used:
+  value: 2.147740e+01
+a1ddf6210/df-boot/percent_inodes-free:
+  value: 9.981079e+01
+a1ddf6210/df-boot/percent_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6210/df-boot/percent_inodes-used:
+  value: 1.892090e-01
+a1ddf6210/df-data1/df_complex-free:
+  value: 5.390209e+11
+a1ddf6210/df-data1/df_complex-reserved:
+  value: 2.933339e+10
+a1ddf6210/df-data1/df_complex-used:
+  value: 9.088414e+09
+a1ddf6210/df-data1/df_inodes-free:
+  value: 3.587710e+07
+a1ddf6210/df-data1/df_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6210/df-data1/df_inodes-used:
+  value: 7.000000e+01
+a1ddf6210/df-data1/percent_bytes-free:
+  value: 9.334621e+01
+a1ddf6210/df-data1/percent_bytes-reserved:
+  value: 5.079879e+00
+a1ddf6210/df-data1/percent_bytes-used:
+  value: 1.573908e+00
+a1ddf6210/df-data1/percent_inodes-free:
+  value: 9.999979e+01
+a1ddf6210/df-data1/percent_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6210/df-data1/percent_inodes-used:
+  value: 1.951102e-04
+a1ddf6210/df-data2/df_complex-free:
+  value: 1.042212e+13
+a1ddf6210/df-data2/df_complex-reserved:
+  value: 1.200219e+11
+a1ddf6210/df-data2/df_complex-used:
+  value: 1.271712e+12
+a1ddf6210/df-data2/df_inodes-free:
+  value: 7.319628e+08
+a1ddf6210/df-data2/df_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6210/df-data2/df_inodes-used:
+  value: 5.985960e+05
+a1ddf6210/df-data2/percent_bytes-free:
+  value: 8.821947e+01
+a1ddf6210/df-data2/percent_bytes-reserved:
+  value: 1.015942e+00
+a1ddf6210/df-data2/percent_bytes-used:
+  value: 1.076458e+01
+a1ddf6210/df-data2/percent_inodes-free:
+  value: 9.991829e+01
+a1ddf6210/df-data2/percent_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6210/df-data2/percent_inodes-used:
+  value: 8.171274e-02
+a1ddf6210/df-data3/df_complex-free:
+  value: 1.143610e+13
+a1ddf6210/df-data3/df_complex-reserved:
+  value: 1.200219e+11
+a1ddf6210/df-data3/df_complex-used:
+  value: 2.577290e+11
+a1ddf6210/df-data3/df_inodes-free:
+  value: 7.323576e+08
+a1ddf6210/df-data3/df_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6210/df-data3/df_inodes-used:
+  value: 2.037680e+05
+a1ddf6210/df-data3/percent_bytes-free:
+  value: 9.680247e+01
+a1ddf6210/df-data3/percent_bytes-reserved:
+  value: 1.015942e+00
+a1ddf6210/df-data3/percent_bytes-used:
+  value: 2.181582e+00
+a1ddf6210/df-data3/percent_inodes-free:
+  value: 9.997218e+01
+a1ddf6210/df-data3/percent_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6210/df-data3/percent_inodes-used:
+  value: 2.781583e-02
+a1ddf6210/df-dev-shm/df_complex-free:
+  value: 3.375733e+10
+a1ddf6210/df-dev-shm/df_complex-reserved:
+  value: 0.000000e+00
+a1ddf6210/df-dev-shm/df_complex-used:
+  value: 0.000000e+00
+a1ddf6210/df-dev-shm/df_inodes-free:
+  value: 8.241535e+06
+a1ddf6210/df-dev-shm/df_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6210/df-dev-shm/df_inodes-used:
+  value: 1.000000e+00
+a1ddf6210/df-dev-shm/percent_bytes-free:
+  value: 1.000000e+02
+a1ddf6210/df-dev-shm/percent_bytes-reserved:
+  value: 0.000000e+00
+a1ddf6210/df-dev-shm/percent_bytes-used:
+  value: 0.000000e+00
+a1ddf6210/df-dev-shm/percent_inodes-free:
+  value: 9.999998e+01
+a1ddf6210/df-dev-shm/percent_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6210/df-dev-shm/percent_inodes-used:
+  value: 1.213366e-05
+a1ddf6210/df-root/df_complex-free:
+  value: 2.006712e+08
+a1ddf6210/df-root/df_complex-reserved:
+  value: 1.073725e+08
+a1ddf6210/df-root/df_complex-used:
+  value: 1.805705e+09
+a1ddf6210/df-root/df_inodes-free:
+  value: 7.542600e+04
+a1ddf6210/df-root/df_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6210/df-root/df_inodes-used:
+  value: 5.564600e+04
+a1ddf6210/df-root/percent_bytes-free:
+  value: 9.493617e+00
+a1ddf6210/df-root/percent_bytes-reserved:
+  value: 5.079720e+00
+a1ddf6210/df-root/percent_bytes-used:
+  value: 8.542667e+01
+a1ddf6210/df-root/percent_inodes-free:
+  value: 5.754547e+01
+a1ddf6210/df-root/percent_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6210/df-root/percent_inodes-used:
+  value: 4.245453e+01
+a1ddf6210/df-tmp/df_complex-free:
+  value: 1.102356e+08
+a1ddf6210/df-tmp/df_complex-reserved:
+  value: 0.000000e+00
+a1ddf6210/df-tmp/df_complex-used:
+  value: 2.398208e+07
+a1ddf6210/df-tmp/df_inodes-free:
+  value: 8.241515e+06
+a1ddf6210/df-tmp/df_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6210/df-tmp/df_inodes-used:
+  value: 2.100000e+01
+a1ddf6210/df-tmp/percent_bytes-free:
+  value: 8.213196e+01
+a1ddf6210/df-tmp/percent_bytes-reserved:
+  value: 0.000000e+00
+a1ddf6210/df-tmp/percent_bytes-used:
+  value: 1.786804e+01
+a1ddf6210/df-tmp/percent_inodes-free:
+  value: 9.999974e+01
+a1ddf6210/df-tmp/percent_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6210/df-tmp/percent_inodes-used:
+  value: 2.548069e-04
+a1ddf6210/df-var/df_complex-free:
+  value: 6.870528e+09
+a1ddf6210/df-var/df_complex-reserved:
+  value: 4.294943e+08
+a1ddf6210/df-var/df_complex-used:
+  value: 1.155097e+09
+a1ddf6210/df-var/df_inodes-free:
+  value: 5.196230e+05
+a1ddf6210/df-var/df_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6210/df-var/df_inodes-used:
+  value: 4.665000e+03
+a1ddf6210/df-var/percent_bytes-free:
+  value: 8.125880e+01
+a1ddf6210/df-var/percent_bytes-reserved:
+  value: 5.079695e+00
+a1ddf6210/df-var/percent_bytes-used:
+  value: 1.366151e+01
+a1ddf6210/df-var/percent_inodes-free:
+  value: 9.911022e+01
+a1ddf6210/df-var/percent_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6210/df-var/percent_inodes-used:
+  value: 8.897781e-01
+a1ddf6210/disk-sda/disk_merged:
+  read: 0.000000e+00
+  write: 2.080016e+01
+a1ddf6210/disk-sda/disk_octets:
+  read: 0.000000e+00
+  write: 1.212425e+05
+a1ddf6210/disk-sda/disk_ops:
+  read: 0.000000e+00
+  write: 8.700063e+00
+a1ddf6210/disk-sda/disk_time:
+  read: 0.000000e+00
+  write: 1.000007e-01
+a1ddf6210/disk-sda1/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sda1/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sda1/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sda1/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sda2/disk_merged:
+  read: 0.000000e+00
+  write: 1.960018e+01
+a1ddf6210/disk-sda2/disk_octets:
+  read: 0.000000e+00
+  write: 1.138698e+05
+a1ddf6210/disk-sda2/disk_ops:
+  read: 0.000000e+00
+  write: 8.200073e+00
+a1ddf6210/disk-sda2/disk_time:
+  read: 0.000000e+00
+  write: 1.000009e-01
+a1ddf6210/disk-sda3/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sda3/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sda3/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sda3/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sda4/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sda4/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sda4/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sda4/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sda5/disk_merged:
+  read: 0.000000e+00
+  write: 1.200011e+00
+a1ddf6210/disk-sda5/disk_octets:
+  read: 0.000000e+00
+  write: 6.144060e+03
+a1ddf6210/disk-sda5/disk_ops:
+  read: 0.000000e+00
+  write: 3.000029e-01
+a1ddf6210/disk-sda5/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sda6/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sda6/disk_octets:
+  read: 0.000000e+00
+  write: 1.228812e+03
+a1ddf6210/disk-sda6/disk_ops:
+  read: 0.000000e+00
+  write: 2.000019e-01
+a1ddf6210/disk-sda6/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sdb/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sdb/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sdb/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sdb/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sdc/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sdc/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sdc/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/disk-sdc/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6210/load/load:
+  longterm: 9.000000e-02
+  midterm: 1.400000e-01
+  shortterm: 1.400000e-01
+a1ddf6210/memory/memory-buffered:
+  value: 7.775150e+08
+a1ddf6210/memory/memory-cached:
+  value: 2.349433e+10
+a1ddf6210/memory/memory-free:
+  value: 2.759657e+10
+a1ddf6210/memory/memory-used:
+  value: 1.564624e+10
+a1ddf6210/network/if_octets:
+  rx: 0.000000e+00
+  tx: 1.455100e+03
+a1ddf6210/network/if_packets:
+  rx: 0.000000e+00
+  tx: 1.100000e+00
+a1ddf6210/network/queue_length:
+  value: 0.000000e+00
+a1ddf6210/network/total_values-dispatch-accepted:
+  value: 0.000000e+00
+a1ddf6210/network/total_values-dispatch-rejected:
+  value: 0.000000e+00
+a1ddf6210/network/total_values-send-accepted:
+  value: 2.720003e+01
+a1ddf6210/network/total_values-send-rejected:
+  value: 0.000000e+00
+a1ddf6210/swap/swap-cached:
+  value: 0.000000e+00
+a1ddf6210/swap/swap-free:
+  value: 2.147475e+09
+a1ddf6210/swap/swap-used:
+  value: 0.000000e+00
+a1ddf6210/swap/swap_io-in:
+  value: 0.000000e+00
+a1ddf6210/swap/swap_io-out:
+  value: 0.000000e+00
+a1ddf6210/vmem/vmpage_faults:
+  majflt: 0.000000e+00
+  minflt: 1.770240e+04
+a1ddf6210/vmem/vmpage_io-memory:
+  in: 0.000000e+00
+  out: 1.100000e+02
+a1ddf6210/vmem/vmpage_io-swap:
+  in: 0.000000e+00
+  out: 0.000000e+00
+a1ddf6210/vmem/vmpage_number-active_anon:
+  value: 7.455600e+05
+a1ddf6210/vmem/vmpage_number-active_file:
+  value: 3.175860e+05
+a1ddf6210/vmem/vmpage_number-anon_pages:
+  value: 5.005000e+04
+a1ddf6210/vmem/vmpage_number-anon_transparent_hugepages:
+  value: 1.356000e+03
+a1ddf6210/vmem/vmpage_number-boudfe:
+  value: 0.000000e+00
+a1ddf6210/vmem/vmpage_number-dirty:
+  value: 1.550000e+02
+a1ddf6210/vmem/vmpage_number-file_pages:
+  value: 5.925744e+06
+a1ddf6210/vmem/vmpage_number-free_pages:
+  value: 6.737445e+06
+a1ddf6210/vmem/vmpage_number-inactive_anon:
+  value: 4.923000e+03
+a1ddf6210/vmem/vmpage_number-inactive_file:
+  value: 5.601994e+06
+a1ddf6210/vmem/vmpage_number-isolated_anon:
+  value: 0.000000e+00
+a1ddf6210/vmem/vmpage_number-isolated_file:
+  value: 0.000000e+00
+a1ddf6210/vmem/vmpage_number-kernel_stack:
+  value: 3.480000e+02
+a1ddf6210/vmem/vmpage_number-mapped:
+  value: 6.515000e+03
+a1ddf6210/vmem/vmpage_number-mlock:
+  value: 0.000000e+00
+a1ddf6210/vmem/vmpage_number-page_table_pages:
+  value: 4.479000e+03
+a1ddf6210/vmem/vmpage_number-shmem:
+  value: 6.170000e+03
+a1ddf6210/vmem/vmpage_number-slab_reclaimable:
+  value: 2.916436e+06
+a1ddf6210/vmem/vmpage_number-slab_unreclaimable:
+  value: 4.737700e+04
+a1ddf6210/vmem/vmpage_number-unevictable:
+  value: 0.000000e+00
+a1ddf6210/vmem/vmpage_number-unstable:
+  value: 0.000000e+00
+a1ddf6210/vmem/vmpage_number-vmscan_write:
+  value: 0.000000e+00
+a1ddf6210/vmem/vmpage_number-writeback:
+  value: 0.000000e+00
+a1ddf6210/vmem/vmpage_number-writeback_temp:
+  value: 0.000000e+00
+a1ddf6510/cpu-0/cpu-idle:
+  value: 9.159977e+01
+a1ddf6510/cpu-0/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6510/cpu-0/cpu-nice:
+  value: 0.000000e+00
+a1ddf6510/cpu-0/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6510/cpu-0/cpu-steal:
+  value: 0.000000e+00
+a1ddf6510/cpu-0/cpu-system:
+  value: 2.999997e+00
+a1ddf6510/cpu-0/cpu-user:
+  value: 5.200008e+00
+a1ddf6510/cpu-0/cpu-wait:
+  value: 0.000000e+00
+a1ddf6510/cpu-1/cpu-idle:
+  value: 9.989949e+01
+a1ddf6510/cpu-1/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6510/cpu-1/cpu-nice:
+  value: 0.000000e+00
+a1ddf6510/cpu-1/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6510/cpu-1/cpu-steal:
+  value: 0.000000e+00
+a1ddf6510/cpu-1/cpu-system:
+  value: 9.999952e-02
+a1ddf6510/cpu-1/cpu-user:
+  value: 0.000000e+00
+a1ddf6510/cpu-1/cpu-wait:
+  value: 0.000000e+00
+a1ddf6510/cpu-10/cpu-idle:
+  value: 9.799903e+01
+a1ddf6510/cpu-10/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6510/cpu-10/cpu-nice:
+  value: 0.000000e+00
+a1ddf6510/cpu-10/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6510/cpu-10/cpu-steal:
+  value: 0.000000e+00
+a1ddf6510/cpu-10/cpu-system:
+  value: 1.199988e+00
+a1ddf6510/cpu-10/cpu-user:
+  value: 5.999943e-01
+a1ddf6510/cpu-10/cpu-wait:
+  value: 0.000000e+00
+a1ddf6510/cpu-11/cpu-idle:
+  value: 9.999894e+01
+a1ddf6510/cpu-11/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6510/cpu-11/cpu-nice:
+  value: 0.000000e+00
+a1ddf6510/cpu-11/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6510/cpu-11/cpu-steal:
+  value: 0.000000e+00
+a1ddf6510/cpu-11/cpu-system:
+  value: 0.000000e+00
+a1ddf6510/cpu-11/cpu-user:
+  value: 0.000000e+00
+a1ddf6510/cpu-11/cpu-wait:
+  value: 0.000000e+00
+a1ddf6510/cpu-2/cpu-idle:
+  value: 9.989933e+01
+a1ddf6510/cpu-2/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6510/cpu-2/cpu-nice:
+  value: 0.000000e+00
+a1ddf6510/cpu-2/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6510/cpu-2/cpu-steal:
+  value: 0.000000e+00
+a1ddf6510/cpu-2/cpu-system:
+  value: 0.000000e+00
+a1ddf6510/cpu-2/cpu-user:
+  value: 0.000000e+00
+a1ddf6510/cpu-2/cpu-wait:
+  value: 0.000000e+00
+a1ddf6510/cpu-3/cpu-idle:
+  value: 9.989927e+01
+a1ddf6510/cpu-3/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6510/cpu-3/cpu-nice:
+  value: 0.000000e+00
+a1ddf6510/cpu-3/cpu-softirq:
+  value: 9.999927e-02
+a1ddf6510/cpu-3/cpu-steal:
+  value: 0.000000e+00
+a1ddf6510/cpu-3/cpu-system:
+  value: 0.000000e+00
+a1ddf6510/cpu-3/cpu-user:
+  value: 0.000000e+00
+a1ddf6510/cpu-3/cpu-wait:
+  value: 0.000000e+00
+a1ddf6510/cpu-4/cpu-idle:
+  value: 9.999933e+01
+a1ddf6510/cpu-4/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6510/cpu-4/cpu-nice:
+  value: 0.000000e+00
+a1ddf6510/cpu-4/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6510/cpu-4/cpu-steal:
+  value: 0.000000e+00
+a1ddf6510/cpu-4/cpu-system:
+  value: 0.000000e+00
+a1ddf6510/cpu-4/cpu-user:
+  value: 9.999930e-02
+a1ddf6510/cpu-4/cpu-wait:
+  value: 0.000000e+00
+a1ddf6510/cpu-5/cpu-idle:
+  value: 9.999932e+01
+a1ddf6510/cpu-5/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6510/cpu-5/cpu-nice:
+  value: 0.000000e+00
+a1ddf6510/cpu-5/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6510/cpu-5/cpu-steal:
+  value: 0.000000e+00
+a1ddf6510/cpu-5/cpu-system:
+  value: 0.000000e+00
+a1ddf6510/cpu-5/cpu-user:
+  value: 0.000000e+00
+a1ddf6510/cpu-5/cpu-wait:
+  value: 0.000000e+00
+a1ddf6510/cpu-6/cpu-idle:
+  value: 9.589926e+01
+a1ddf6510/cpu-6/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6510/cpu-6/cpu-nice:
+  value: 0.000000e+00
+a1ddf6510/cpu-6/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6510/cpu-6/cpu-steal:
+  value: 0.000000e+00
+a1ddf6510/cpu-6/cpu-system:
+  value: 2.099986e+00
+a1ddf6510/cpu-6/cpu-user:
+  value: 1.999987e+00
+a1ddf6510/cpu-6/cpu-wait:
+  value: 0.000000e+00
+a1ddf6510/cpu-7/cpu-idle:
+  value: 9.679919e+01
+a1ddf6510/cpu-7/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6510/cpu-7/cpu-nice:
+  value: 0.000000e+00
+a1ddf6510/cpu-7/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6510/cpu-7/cpu-steal:
+  value: 0.000000e+00
+a1ddf6510/cpu-7/cpu-system:
+  value: 2.199982e+00
+a1ddf6510/cpu-7/cpu-user:
+  value: 1.099991e+00
+a1ddf6510/cpu-7/cpu-wait:
+  value: 0.000000e+00
+a1ddf6510/cpu-8/cpu-idle:
+  value: 9.439919e+01
+a1ddf6510/cpu-8/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6510/cpu-8/cpu-nice:
+  value: 0.000000e+00
+a1ddf6510/cpu-8/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6510/cpu-8/cpu-steal:
+  value: 0.000000e+00
+a1ddf6510/cpu-8/cpu-system:
+  value: 4.399963e+00
+a1ddf6510/cpu-8/cpu-user:
+  value: 1.099991e+00
+a1ddf6510/cpu-8/cpu-wait:
+  value: 0.000000e+00
+a1ddf6510/cpu-9/cpu-idle:
+  value: 9.949910e+01
+a1ddf6510/cpu-9/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6510/cpu-9/cpu-nice:
+  value: 0.000000e+00
+a1ddf6510/cpu-9/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6510/cpu-9/cpu-steal:
+  value: 0.000000e+00
+a1ddf6510/cpu-9/cpu-system:
+  value: 1.999982e-01
+a1ddf6510/cpu-9/cpu-user:
+  value: 9.999913e-02
+a1ddf6510/cpu-9/cpu-wait:
+  value: 0.000000e+00
+a1ddf6510/df-boot/df_complex-free:
+  value: 4.369039e+08
+a1ddf6510/df-boot/df_complex-reserved:
+  value: 2.684109e+07
+a1ddf6510/df-boot/df_complex-used:
+  value: 6.467994e+07
+a1ddf6510/df-boot/df_inodes-free:
+  value: 3.271800e+04
+a1ddf6510/df-boot/df_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6510/df-boot/df_inodes-used:
+  value: 5.000000e+01
+a1ddf6510/df-boot/percent_bytes-free:
+  value: 8.268041e+01
+a1ddf6510/df-boot/percent_bytes-reserved:
+  value: 5.079451e+00
+a1ddf6510/df-boot/percent_bytes-used:
+  value: 1.224014e+01
+a1ddf6510/df-boot/percent_inodes-free:
+  value: 9.984741e+01
+a1ddf6510/df-boot/percent_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6510/df-boot/percent_inodes-used:
+  value: 1.525879e-01
+a1ddf6510/df-data1/df_complex-free:
+  value: 5.378703e+11
+a1ddf6510/df-data1/df_complex-reserved:
+  value: 2.879652e+10
+a1ddf6510/df-data1/df_complex-used:
+  value: 2.072412e+08
+a1ddf6510/df-data1/df_inodes-free:
+  value: 3.522052e+07
+a1ddf6510/df-data1/df_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6510/df-data1/df_inodes-used:
+  value: 1.300000e+01
+a1ddf6510/df-data1/percent_bytes-free:
+  value: 9.488357e+01
+a1ddf6510/df-data1/percent_bytes-reserved:
+  value: 5.079879e+00
+a1ddf6510/df-data1/percent_bytes-used:
+  value: 3.655860e-02
+a1ddf6510/df-data1/percent_inodes-free:
+  value: 9.999996e+01
+a1ddf6510/df-data1/percent_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6510/df-data1/percent_inodes-used:
+  value: 3.691029e-05
+a1ddf6510/df-dev-shm/df_complex-free:
+  value: 3.375725e+10
+a1ddf6510/df-dev-shm/df_complex-reserved:
+  value: 0.000000e+00
+a1ddf6510/df-dev-shm/df_complex-used:
+  value: 0.000000e+00
+a1ddf6510/df-dev-shm/df_inodes-free:
+  value: 8.241515e+06
+a1ddf6510/df-dev-shm/df_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6510/df-dev-shm/df_inodes-used:
+  value: 1.000000e+00
+a1ddf6510/df-dev-shm/percent_bytes-free:
+  value: 1.000000e+02
+a1ddf6510/df-dev-shm/percent_bytes-reserved:
+  value: 0.000000e+00
+a1ddf6510/df-dev-shm/percent_bytes-used:
+  value: 0.000000e+00
+a1ddf6510/df-dev-shm/percent_inodes-free:
+  value: 9.999998e+01
+a1ddf6510/df-dev-shm/percent_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6510/df-dev-shm/percent_inodes-used:
+  value: 1.213369e-05
+a1ddf6510/df-root/df_complex-free:
+  value: 1.057486e+10
+a1ddf6510/df-root/df_complex-reserved:
+  value: 6.442435e+08
+a1ddf6510/df-root/df_complex-used:
+  value: 1.463607e+09
+a1ddf6510/df-root/df_inodes-free:
+  value: 7.435400e+05
+a1ddf6510/df-root/df_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6510/df-root/df_inodes-used:
+  value: 4.289200e+04
+a1ddf6510/df-root/percent_bytes-free:
+  value: 8.338012e+01
+a1ddf6510/df-root/percent_bytes-reserved:
+  value: 5.079700e+00
+a1ddf6510/df-root/percent_bytes-used:
+  value: 1.154018e+01
+a1ddf6510/df-root/percent_inodes-free:
+  value: 9.454601e+01
+a1ddf6510/df-root/percent_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6510/df-root/percent_inodes-used:
+  value: 5.454000e+00
+a1ddf6510/df-var/df_complex-free:
+  value: 6.990479e+09
+a1ddf6510/df-var/df_complex-reserved:
+  value: 4.294943e+08
+a1ddf6510/df-var/df_complex-used:
+  value: 1.035145e+09
+a1ddf6510/df-var/df_inodes-free:
+  value: 5.169860e+05
+a1ddf6510/df-var/df_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6510/df-var/df_inodes-used:
+  value: 7.302000e+03
+a1ddf6510/df-var/percent_bytes-free:
+  value: 8.267748e+01
+a1ddf6510/df-var/percent_bytes-reserved:
+  value: 5.079695e+00
+a1ddf6510/df-var/percent_bytes-used:
+  value: 1.224282e+01
+a1ddf6510/df-var/percent_inodes-free:
+  value: 9.860725e+01
+a1ddf6510/df-var/percent_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6510/df-var/percent_inodes-used:
+  value: 1.392746e+00
+a1ddf6510/disk-sda/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda/disk_octets:
+  read: 0.000000e+00
+  write: 2.457548e+03
+a1ddf6510/disk-sda/disk_ops:
+  read: 0.000000e+00
+  write: 5.999873e-01
+a1ddf6510/disk-sda/disk_time:
+  read: 0.000000e+00
+  write: 9.999788e-01
+a1ddf6510/disk-sda1/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda1/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda1/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda1/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda2/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda2/disk_octets:
+  read: 0.000000e+00
+  write: 2.457548e+03
+a1ddf6510/disk-sda2/disk_ops:
+  read: 0.000000e+00
+  write: 5.999872e-01
+a1ddf6510/disk-sda2/disk_time:
+  read: 0.000000e+00
+  write: 9.999786e-01
+a1ddf6510/disk-sda3/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda3/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda3/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda3/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda4/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda4/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda4/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda4/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda5/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda5/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda5/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda5/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda6/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda6/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda6/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/disk-sda6/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6510/load/load:
+  longterm: 0.000000e+00
+  midterm: 0.000000e+00
+  shortterm: 0.000000e+00
+a1ddf6510/memory/memory-buffered:
+  value: 2.371871e+08
+a1ddf6510/memory/memory-cached:
+  value: 1.447993e+09
+a1ddf6510/memory/memory-free:
+  value: 6.351406e+10
+a1ddf6510/memory/memory-used:
+  value: 2.315260e+09
+a1ddf6510/network/if_octets:
+  rx: 0.000000e+00
+  tx: 1.052800e+03
+a1ddf6510/network/if_packets:
+  rx: 0.000000e+00
+  tx: 8.000000e-01
+a1ddf6510/network/queue_length:
+  value: 0.000000e+00
+a1ddf6510/network/total_values-dispatch-accepted:
+  value: 0.000000e+00
+a1ddf6510/network/total_values-dispatch-rejected:
+  value: 0.000000e+00
+a1ddf6510/network/total_values-send-accepted:
+  value: 2.280001e+01
+a1ddf6510/network/total_values-send-rejected:
+  value: 0.000000e+00
+a1ddf6510/swap/swap-cached:
+  value: 0.000000e+00
+a1ddf6510/swap/swap-free:
+  value: 2.147475e+09
+a1ddf6510/swap/swap-used:
+  value: 0.000000e+00
+a1ddf6510/swap/swap_io-in:
+  value: 0.000000e+00
+a1ddf6510/swap/swap_io-out:
+  value: 0.000000e+00
+a1ddf6510/vmem/vmpage_faults:
+  majflt: 0.000000e+00
+  minflt: 3.700034e+00
+a1ddf6510/vmem/vmpage_io-memory:
+  in: 0.000000e+00
+  out: 0.000000e+00
+a1ddf6510/vmem/vmpage_io-swap:
+  in: 0.000000e+00
+  out: 0.000000e+00
+a1ddf6510/vmem/vmpage_number-active_anon:
+  value: 8.369400e+04
+a1ddf6510/vmem/vmpage_number-active_file:
+  value: 2.449340e+05
+a1ddf6510/vmem/vmpage_number-anon_pages:
+  value: 4.576400e+04
+a1ddf6510/vmem/vmpage_number-anon_transparent_hugepages:
+  value: 7.500000e+01
+a1ddf6510/vmem/vmpage_number-boudfe:
+  value: 0.000000e+00
+a1ddf6510/vmem/vmpage_number-dirty:
+  value: 1.000000e+00
+a1ddf6510/vmem/vmpage_number-file_pages:
+  value: 4.114210e+05
+a1ddf6510/vmem/vmpage_number-free_pages:
+  value: 1.550636e+07
+a1ddf6510/vmem/vmpage_number-inactive_anon:
+  value: 2.130000e+02
+a1ddf6510/vmem/vmpage_number-inactive_file:
+  value: 1.662360e+05
+a1ddf6510/vmem/vmpage_number-isolated_anon:
+  value: 0.000000e+00
+a1ddf6510/vmem/vmpage_number-isolated_file:
+  value: 0.000000e+00
+a1ddf6510/vmem/vmpage_number-kernel_stack:
+  value: 3.110000e+02
+a1ddf6510/vmem/vmpage_number-mapped:
+  value: 6.615000e+03
+a1ddf6510/vmem/vmpage_number-mlock:
+  value: 0.000000e+00
+a1ddf6510/vmem/vmpage_number-page_table_pages:
+  value: 2.683000e+03
+a1ddf6510/vmem/vmpage_number-shmem:
+  value: 2.550000e+02
+a1ddf6510/vmem/vmpage_number-slab_reclaimable:
+  value: 3.633060e+05
+a1ddf6510/vmem/vmpage_number-slab_unreclaimable:
+  value: 1.422200e+04
+a1ddf6510/vmem/vmpage_number-unevictable:
+  value: 0.000000e+00
+a1ddf6510/vmem/vmpage_number-unstable:
+  value: 0.000000e+00
+a1ddf6510/vmem/vmpage_number-vmscan_write:
+  value: 0.000000e+00
+a1ddf6510/vmem/vmpage_number-writeback:
+  value: 0.000000e+00
+a1ddf6510/vmem/vmpage_number-writeback_temp:
+  value: 0.000000e+00
+a1ddf6610/cpu-0/cpu-idle:
+  value: 8.969821e+01
+a1ddf6610/cpu-0/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-0/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-0/cpu-softirq:
+  value: 1.099984e+00
+a1ddf6610/cpu-0/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-0/cpu-system:
+  value: 3.499955e+00
+a1ddf6610/cpu-0/cpu-user:
+  value: 2.199975e+00
+a1ddf6610/cpu-0/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-1/cpu-idle:
+  value: 9.719322e+01
+a1ddf6610/cpu-1/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-1/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-1/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-1/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-1/cpu-system:
+  value: 1.899957e+00
+a1ddf6610/cpu-1/cpu-user:
+  value: 5.999838e-01
+a1ddf6610/cpu-1/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-10/cpu-idle:
+  value: 9.979814e+01
+a1ddf6610/cpu-10/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-10/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-10/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-10/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-10/cpu-system:
+  value: 9.999814e-02
+a1ddf6610/cpu-10/cpu-user:
+  value: 0.000000e+00
+a1ddf6610/cpu-10/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-11/cpu-idle:
+  value: 9.979789e+01
+a1ddf6610/cpu-11/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-11/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-11/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-11/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-11/cpu-system:
+  value: 9.999790e-02
+a1ddf6610/cpu-11/cpu-user:
+  value: 0.000000e+00
+a1ddf6610/cpu-11/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-12/cpu-idle:
+  value: 9.709848e+01
+a1ddf6610/cpu-12/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-12/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-12/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-12/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-12/cpu-system:
+  value: 1.599972e+00
+a1ddf6610/cpu-12/cpu-user:
+  value: 1.199978e+00
+a1ddf6610/cpu-12/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-13/cpu-idle:
+  value: 7.879859e+01
+a1ddf6610/cpu-13/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-13/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-13/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-13/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-13/cpu-system:
+  value: 1.309976e+01
+a1ddf6610/cpu-13/cpu-user:
+  value: 8.099863e+00
+a1ddf6610/cpu-13/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-14/cpu-idle:
+  value: 9.309875e+01
+a1ddf6610/cpu-14/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-14/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-14/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-14/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-14/cpu-system:
+  value: 4.699934e+00
+a1ddf6610/cpu-14/cpu-user:
+  value: 2.099971e+00
+a1ddf6610/cpu-14/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-15/cpu-idle:
+  value: 8.789892e+01
+a1ddf6610/cpu-15/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-15/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-15/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-15/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-15/cpu-system:
+  value: 7.999894e+00
+a1ddf6610/cpu-15/cpu-user:
+  value: 3.599950e+00
+a1ddf6610/cpu-15/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-16/cpu-idle:
+  value: 9.959880e+01
+a1ddf6610/cpu-16/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-16/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-16/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-16/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-16/cpu-system:
+  value: 2.999964e-01
+a1ddf6610/cpu-16/cpu-user:
+  value: 9.999874e-02
+a1ddf6610/cpu-16/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-17/cpu-idle:
+  value: 9.959911e+01
+a1ddf6610/cpu-17/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-17/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-17/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-17/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-17/cpu-system:
+  value: 1.999981e-01
+a1ddf6610/cpu-17/cpu-user:
+  value: 9.999911e-02
+a1ddf6610/cpu-17/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-18/cpu-idle:
+  value: 9.519927e+01
+a1ddf6610/cpu-18/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-18/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-18/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-18/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-18/cpu-system:
+  value: 2.499979e+00
+a1ddf6610/cpu-18/cpu-user:
+  value: 1.899982e+00
+a1ddf6610/cpu-18/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-19/cpu-idle:
+  value: 8.319942e+01
+a1ddf6610/cpu-19/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-19/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-19/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-19/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-19/cpu-system:
+  value: 1.189992e+01
+a1ddf6610/cpu-19/cpu-user:
+  value: 3.999985e+00
+a1ddf6610/cpu-19/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-2/cpu-idle:
+  value: 9.899200e+01
+a1ddf6610/cpu-2/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-2/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-2/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-2/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-2/cpu-system:
+  value: 3.999674e-01
+a1ddf6610/cpu-2/cpu-user:
+  value: 2.999799e-01
+a1ddf6610/cpu-2/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-20/cpu-idle:
+  value: 9.389955e+01
+a1ddf6610/cpu-20/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-20/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-20/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-20/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-20/cpu-system:
+  value: 4.199980e+00
+a1ddf6610/cpu-20/cpu-user:
+  value: 1.399991e+00
+a1ddf6610/cpu-20/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-21/cpu-idle:
+  value: 8.779956e+01
+a1ddf6610/cpu-21/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-21/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-21/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-21/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-21/cpu-system:
+  value: 8.199940e+00
+a1ddf6610/cpu-21/cpu-user:
+  value: 3.599972e+00
+a1ddf6610/cpu-21/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-22/cpu-idle:
+  value: 9.959932e+01
+a1ddf6610/cpu-22/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-22/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-22/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-22/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-22/cpu-system:
+  value: 2.999981e-01
+a1ddf6610/cpu-22/cpu-user:
+  value: 9.999956e-02
+a1ddf6610/cpu-22/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-23/cpu-idle:
+  value: 9.929916e+01
+a1ddf6610/cpu-23/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-23/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-23/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-23/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-23/cpu-system:
+  value: 4.999943e-01
+a1ddf6610/cpu-23/cpu-user:
+  value: 0.000000e+00
+a1ddf6610/cpu-23/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-3/cpu-idle:
+  value: 9.949283e+01
+a1ddf6610/cpu-3/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-3/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-3/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-3/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-3/cpu-system:
+  value: 9.999309e-02
+a1ddf6610/cpu-3/cpu-user:
+  value: 1.999852e-01
+a1ddf6610/cpu-3/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-4/cpu-idle:
+  value: 9.989305e+01
+a1ddf6610/cpu-4/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-4/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-4/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-4/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-4/cpu-system:
+  value: 0.000000e+00
+a1ddf6610/cpu-4/cpu-user:
+  value: 0.000000e+00
+a1ddf6610/cpu-4/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-5/cpu-idle:
+  value: 9.989362e+01
+a1ddf6610/cpu-5/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-5/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-5/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-5/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-5/cpu-system:
+  value: 9.999406e-02
+a1ddf6610/cpu-5/cpu-user:
+  value: 0.000000e+00
+a1ddf6610/cpu-5/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-6/cpu-idle:
+  value: 9.469571e+01
+a1ddf6610/cpu-6/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-6/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-6/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-6/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-6/cpu-system:
+  value: 3.499803e+00
+a1ddf6610/cpu-6/cpu-user:
+  value: 1.199947e+00
+a1ddf6610/cpu-6/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-7/cpu-idle:
+  value: 9.819573e+01
+a1ddf6610/cpu-7/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-7/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-7/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-7/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-7/cpu-system:
+  value: 1.299941e+00
+a1ddf6610/cpu-7/cpu-user:
+  value: 2.999861e-01
+a1ddf6610/cpu-7/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-8/cpu-idle:
+  value: 9.929729e+01
+a1ddf6610/cpu-8/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-8/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-8/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-8/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-8/cpu-system:
+  value: 1.999943e-01
+a1ddf6610/cpu-8/cpu-user:
+  value: 9.999644e-02
+a1ddf6610/cpu-8/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/cpu-9/cpu-idle:
+  value: 9.989737e+01
+a1ddf6610/cpu-9/cpu-interrupt:
+  value: 0.000000e+00
+a1ddf6610/cpu-9/cpu-nice:
+  value: 0.000000e+00
+a1ddf6610/cpu-9/cpu-softirq:
+  value: 0.000000e+00
+a1ddf6610/cpu-9/cpu-steal:
+  value: 0.000000e+00
+a1ddf6610/cpu-9/cpu-system:
+  value: 9.999736e-02
+a1ddf6610/cpu-9/cpu-user:
+  value: 0.000000e+00
+a1ddf6610/cpu-9/cpu-wait:
+  value: 0.000000e+00
+a1ddf6610/df-boot/df_complex-free:
+  value: 4.793754e+08
+a1ddf6610/df-boot/df_complex-reserved:
+  value: 2.684109e+07
+a1ddf6610/df-boot/df_complex-used:
+  value: 2.220851e+07
+a1ddf6610/df-boot/df_inodes-free:
+  value: 3.273000e+04
+a1ddf6610/df-boot/df_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6610/df-boot/df_inodes-used:
+  value: 3.800000e+01
+a1ddf6610/df-boot/percent_bytes-free:
+  value: 9.071777e+01
+a1ddf6610/df-boot/percent_bytes-reserved:
+  value: 5.079451e+00
+a1ddf6610/df-boot/percent_bytes-used:
+  value: 4.202775e+00
+a1ddf6610/df-boot/percent_inodes-free:
+  value: 9.988403e+01
+a1ddf6610/df-boot/percent_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6610/df-boot/percent_inodes-used:
+  value: 1.159668e-01
+a1ddf6610/df-data1/df_complex-free:
+  value: 2.574899e+11
+a1ddf6610/df-data1/df_complex-reserved:
+  value: 1.379019e+10
+a1ddf6610/df-data1/df_complex-used:
+  value: 1.961411e+08
+a1ddf6610/df-data1/df_inodes-free:
+  value: 1.683454e+07
+a1ddf6610/df-data1/df_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6610/df-data1/df_inodes-used:
+  value: 1.800000e+01
+a1ddf6610/df-data1/percent_bytes-free:
+  value: 9.484805e+01
+a1ddf6610/df-data1/percent_bytes-reserved:
+  value: 5.079704e+00
+a1ddf6610/df-data1/percent_bytes-used:
+  value: 7.224981e-02
+a1ddf6610/df-data1/percent_inodes-free:
+  value: 9.999989e+01
+a1ddf6610/df-data1/percent_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6610/df-data1/percent_inodes-used:
+  value: 1.069229e-04
+a1ddf6610/df-dev-shm/df_complex-free:
+  value: 3.375709e+10
+a1ddf6610/df-dev-shm/df_complex-reserved:
+  value: 0.000000e+00
+a1ddf6610/df-dev-shm/df_complex-used:
+  value: 0.000000e+00
+a1ddf6610/df-dev-shm/df_inodes-free:
+  value: 8.241475e+06
+a1ddf6610/df-dev-shm/df_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6610/df-dev-shm/df_inodes-used:
+  value: 1.000000e+00
+a1ddf6610/df-dev-shm/percent_bytes-free:
+  value: 1.000000e+02
+a1ddf6610/df-dev-shm/percent_bytes-reserved:
+  value: 0.000000e+00
+a1ddf6610/df-dev-shm/percent_bytes-used:
+  value: 0.000000e+00
+a1ddf6610/df-dev-shm/percent_inodes-free:
+  value: 9.999998e+01
+a1ddf6610/df-dev-shm/percent_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6610/df-dev-shm/percent_inodes-used:
+  value: 1.213375e-05
+a1ddf6610/df-root/df_complex-free:
+  value: 1.030392e+10
+a1ddf6610/df-root/df_complex-reserved:
+  value: 6.442435e+08
+a1ddf6610/df-root/df_complex-used:
+  value: 1.734545e+09
+a1ddf6610/df-root/df_inodes-free:
+  value: 7.387960e+05
+a1ddf6610/df-root/df_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6610/df-root/df_inodes-used:
+  value: 4.763600e+04
+a1ddf6610/df-root/percent_bytes-free:
+  value: 8.124384e+01
+a1ddf6610/df-root/percent_bytes-reserved:
+  value: 5.079700e+00
+a1ddf6610/df-root/percent_bytes-used:
+  value: 1.367646e+01
+a1ddf6610/df-root/percent_inodes-free:
+  value: 9.394276e+01
+a1ddf6610/df-root/percent_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6610/df-root/percent_inodes-used:
+  value: 6.057231e+00
+a1ddf6610/df-var/df_complex-free:
+  value: 5.412876e+09
+a1ddf6610/df-var/df_complex-reserved:
+  value: 4.294943e+08
+a1ddf6610/df-var/df_complex-used:
+  value: 2.612748e+09
+a1ddf6610/df-var/df_inodes-free:
+  value: 5.218510e+05
+a1ddf6610/df-var/df_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6610/df-var/df_inodes-used:
+  value: 2.437000e+03
+a1ddf6610/df-var/percent_bytes-free:
+  value: 6.401893e+01
+a1ddf6610/df-var/percent_bytes-reserved:
+  value: 5.079695e+00
+a1ddf6610/df-var/percent_bytes-used:
+  value: 3.090138e+01
+a1ddf6610/df-var/percent_inodes-free:
+  value: 9.953518e+01
+a1ddf6610/df-var/percent_inodes-reserved:
+  value: 0.000000e+00
+a1ddf6610/df-var/percent_inodes-used:
+  value: 4.648209e-01
+a1ddf6610/disk-sda/disk_merged:
+  read: 0.000000e+00
+  write: 1.224974e+02
+a1ddf6610/disk-sda/disk_octets:
+  read: 0.000000e+00
+  write: 5.377975e+05
+a1ddf6610/disk-sda/disk_ops:
+  read: 0.000000e+00
+  write: 8.799739e+00
+a1ddf6610/disk-sda/disk_time:
+  read: 0.000000e+00
+  write: 1.599958e+00
+a1ddf6610/disk-sda1/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6610/disk-sda1/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6610/disk-sda1/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6610/disk-sda1/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6610/disk-sda2/disk_merged:
+  read: 0.000000e+00
+  write: 1.148967e+02
+a1ddf6610/disk-sda2/disk_octets:
+  read: 0.000000e+00
+  write: 4.829033e+05
+a1ddf6610/disk-sda2/disk_ops:
+  read: 0.000000e+00
+  write: 2.999895e+00
+a1ddf6610/disk-sda2/disk_time:
+  read: 0.000000e+00
+  write: 3.999861e-01
+a1ddf6610/disk-sda3/disk_merged:
+  read: 0.000000e+00
+  write: 7.599447e+00
+a1ddf6610/disk-sda3/disk_octets:
+  read: 0.000000e+00
+  write: 5.488478e+04
+a1ddf6610/disk-sda3/disk_ops:
+  read: 0.000000e+00
+  write: 5.799747e+00
+a1ddf6610/disk-sda3/disk_time:
+  read: 0.000000e+00
+  write: 2.299833e+00
+a1ddf6610/disk-sda4/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6610/disk-sda4/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6610/disk-sda4/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6610/disk-sda4/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6610/disk-sda5/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6610/disk-sda5/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6610/disk-sda5/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6610/disk-sda5/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6610/disk-sda6/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6610/disk-sda6/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6610/disk-sda6/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6610/disk-sda6/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+a1ddf6610/load/load:
+  longterm: 2.600000e-01
+  midterm: 2.400000e-01
+  shortterm: 3.000000e-02
+a1ddf6610/memory/memory-buffered:
+  value: 2.945802e+08
+a1ddf6610/memory/memory-cached:
+  value: 2.390438e+09
+a1ddf6610/memory/memory-free:
+  value: 6.154120e+10
+a1ddf6610/memory/memory-used:
+  value: 3.287953e+09
+a1ddf6610/network/if_octets:
+  rx: 2.326949e+04
+  tx: 0.000000e+00
+a1ddf6610/network/if_packets:
+  rx: 1.759976e+01
+  tx: 0.000000e+00
+a1ddf6610/network/queue_length:
+  value: 0.000000e+00
+a1ddf6610/network/total_values-dispatch-accepted:
+  value: 4.607941e+02
+a1ddf6610/network/total_values-dispatch-rejected:
+  value: 0.000000e+00
+a1ddf6610/network/total_values-send-accepted:
+  value: 0.000000e+00
+a1ddf6610/network/total_values-send-rejected:
+  value: 0.000000e+00
+a1ddf6610/swap/swap-cached:
+  value: 0.000000e+00
+a1ddf6610/swap/swap-free:
+  value: 2.147475e+09
+a1ddf6610/swap/swap-used:
+  value: 0.000000e+00
+a1ddf6610/swap/swap_io-in:
+  value: 0.000000e+00
+a1ddf6610/swap/swap_io-out:
+  value: 0.000000e+00
+a1ddf6610/vmem/vmpage_faults:
+  majflt: 0.000000e+00
+  minflt: 1.460435e+05
+a1ddf6610/vmem/vmpage_io-memory:
+  in: 0.000000e+00
+  out: 5.252066e+02
+a1ddf6610/vmem/vmpage_io-swap:
+  in: 0.000000e+00
+  out: 0.000000e+00
+a1ddf6610/vmem/vmpage_number-active_anon:
+  value: 7.743400e+04
+a1ddf6610/vmem/vmpage_number-active_file:
+  value: 5.886950e+05
+a1ddf6610/vmem/vmpage_number-anon_pages:
+  value: 3.168900e+04
+a1ddf6610/vmem/vmpage_number-anon_transparent_hugepages:
+  value: 8.900000e+01
+a1ddf6610/vmem/vmpage_number-boudfe:
+  value: 0.000000e+00
+a1ddf6610/vmem/vmpage_number-dirty:
+  value: 1.217000e+03
+a1ddf6610/vmem/vmpage_number-file_pages:
+  value: 6.555230e+05
+a1ddf6610/vmem/vmpage_number-free_pages:
+  value: 1.502482e+07
+a1ddf6610/vmem/vmpage_number-inactive_anon:
+  value: 1.440000e+02
+a1ddf6610/vmem/vmpage_number-inactive_file:
+  value: 6.663400e+04
+a1ddf6610/vmem/vmpage_number-isolated_anon:
+  value: 0.000000e+00
+a1ddf6610/vmem/vmpage_number-isolated_file:
+  value: 0.000000e+00
+a1ddf6610/vmem/vmpage_number-kernel_stack:
+  value: 5.050000e+02
+a1ddf6610/vmem/vmpage_number-mapped:
+  value: 7.061000e+03
+a1ddf6610/vmem/vmpage_number-mlock:
+  value: 0.000000e+00
+a1ddf6610/vmem/vmpage_number-page_table_pages:
+  value: 2.714000e+03
+a1ddf6610/vmem/vmpage_number-shmem:
+  value: 2.010000e+02
+a1ddf6610/vmem/vmpage_number-slab_reclaimable:
+  value: 5.981700e+05
+a1ddf6610/vmem/vmpage_number-slab_unreclaimable:
+  value: 1.751300e+04
+a1ddf6610/vmem/vmpage_number-unevictable:
+  value: 0.000000e+00
+a1ddf6610/vmem/vmpage_number-unstable:
+  value: 0.000000e+00
+a1ddf6610/vmem/vmpage_number-vmscan_write:
+  value: 0.000000e+00
+a1ddf6610/vmem/vmpage_number-writeback:
+  value: 0.000000e+00
+a1ddf6610/vmem/vmpage_number-writeback_temp:
+  value: 0.000000e+00
+h2gdf6120/cpu-0/cpu-idle:
+  value: 9.830055e+01
+h2gdf6120/cpu-0/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-0/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-0/cpu-softirq:
+  value: 1.000006e-01
+h2gdf6120/cpu-0/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-0/cpu-system:
+  value: 2.000012e-01
+h2gdf6120/cpu-0/cpu-user:
+  value: 7.000045e-01
+h2gdf6120/cpu-0/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-1/cpu-idle:
+  value: 9.630047e+01
+h2gdf6120/cpu-1/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-1/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-1/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-1/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-1/cpu-system:
+  value: 5.000024e-01
+h2gdf6120/cpu-1/cpu-user:
+  value: 3.300017e+00
+h2gdf6120/cpu-1/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-10/cpu-idle:
+  value: 9.990053e+01
+h2gdf6120/cpu-10/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-10/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-10/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-10/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-10/cpu-system:
+  value: 0.000000e+00
+h2gdf6120/cpu-10/cpu-user:
+  value: 1.000005e-01
+h2gdf6120/cpu-10/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-11/cpu-idle:
+  value: 9.990010e+01
+h2gdf6120/cpu-11/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-11/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-11/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-11/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-11/cpu-system:
+  value: 0.000000e+00
+h2gdf6120/cpu-11/cpu-user:
+  value: 0.000000e+00
+h2gdf6120/cpu-11/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-12/cpu-idle:
+  value: 9.600001e+01
+h2gdf6120/cpu-12/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-12/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-12/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-12/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-12/cpu-system:
+  value: 7.000001e-01
+h2gdf6120/cpu-12/cpu-user:
+  value: 2.900000e+00
+h2gdf6120/cpu-12/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-13/cpu-idle:
+  value: 9.740004e+01
+h2gdf6120/cpu-13/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-13/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-13/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-13/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-13/cpu-system:
+  value: 2.000001e-01
+h2gdf6120/cpu-13/cpu-user:
+  value: 2.100001e+00
+h2gdf6120/cpu-13/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-14/cpu-idle:
+  value: 9.920005e+01
+h2gdf6120/cpu-14/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-14/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-14/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-14/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-14/cpu-system:
+  value: 1.000000e-01
+h2gdf6120/cpu-14/cpu-user:
+  value: 6.000003e-01
+h2gdf6120/cpu-14/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-15/cpu-idle:
+  value: 9.990025e+01
+h2gdf6120/cpu-15/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-15/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-15/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-15/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-15/cpu-system:
+  value: 1.000002e-01
+h2gdf6120/cpu-15/cpu-user:
+  value: 0.000000e+00
+h2gdf6120/cpu-15/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-16/cpu-idle:
+  value: 9.989996e+01
+h2gdf6120/cpu-16/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-16/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-16/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-16/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-16/cpu-system:
+  value: 0.000000e+00
+h2gdf6120/cpu-16/cpu-user:
+  value: 1.000000e-01
+h2gdf6120/cpu-16/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-17/cpu-idle:
+  value: 9.999995e+01
+h2gdf6120/cpu-17/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-17/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-17/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-17/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-17/cpu-system:
+  value: 0.000000e+00
+h2gdf6120/cpu-17/cpu-user:
+  value: 0.000000e+00
+h2gdf6120/cpu-17/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-18/cpu-idle:
+  value: 9.989994e+01
+h2gdf6120/cpu-18/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-18/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-18/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-18/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-18/cpu-system:
+  value: 0.000000e+00
+h2gdf6120/cpu-18/cpu-user:
+  value: 9.999997e-02
+h2gdf6120/cpu-18/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-19/cpu-idle:
+  value: 9.930003e+01
+h2gdf6120/cpu-19/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-19/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-19/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-19/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-19/cpu-system:
+  value: 9.999996e-02
+h2gdf6120/cpu-19/cpu-user:
+  value: 4.999998e-01
+h2gdf6120/cpu-19/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-2/cpu-idle:
+  value: 9.800028e+01
+h2gdf6120/cpu-2/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-2/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-2/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-2/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-2/cpu-system:
+  value: 3.000009e-01
+h2gdf6120/cpu-2/cpu-user:
+  value: 2.000007e+00
+h2gdf6120/cpu-2/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-20/cpu-idle:
+  value: 9.980000e+01
+h2gdf6120/cpu-20/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-20/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-20/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-20/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-20/cpu-system:
+  value: 9.999990e-02
+h2gdf6120/cpu-20/cpu-user:
+  value: 0.000000e+00
+h2gdf6120/cpu-20/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-21/cpu-idle:
+  value: 9.990021e+01
+h2gdf6120/cpu-21/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-21/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-21/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-21/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-21/cpu-system:
+  value: 0.000000e+00
+h2gdf6120/cpu-21/cpu-user:
+  value: 0.000000e+00
+h2gdf6120/cpu-21/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-22/cpu-idle:
+  value: 9.660017e+01
+h2gdf6120/cpu-22/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-22/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-22/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-22/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-22/cpu-system:
+  value: 1.000002e-01
+h2gdf6120/cpu-22/cpu-user:
+  value: 3.000008e+00
+h2gdf6120/cpu-22/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-23/cpu-idle:
+  value: 1.000001e+02
+h2gdf6120/cpu-23/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-23/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-23/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-23/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-23/cpu-system:
+  value: 0.000000e+00
+h2gdf6120/cpu-23/cpu-user:
+  value: 0.000000e+00
+h2gdf6120/cpu-23/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-3/cpu-idle:
+  value: 9.840034e+01
+h2gdf6120/cpu-3/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-3/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-3/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-3/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-3/cpu-system:
+  value: 3.000008e-01
+h2gdf6120/cpu-3/cpu-user:
+  value: 1.700004e+00
+h2gdf6120/cpu-3/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-4/cpu-idle:
+  value: 9.930038e+01
+h2gdf6120/cpu-4/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-4/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-4/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-4/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-4/cpu-system:
+  value: 1.000004e-01
+h2gdf6120/cpu-4/cpu-user:
+  value: 5.000020e-01
+h2gdf6120/cpu-4/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-5/cpu-idle:
+  value: 1.000003e+02
+h2gdf6120/cpu-5/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-5/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-5/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-5/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-5/cpu-system:
+  value: 0.000000e+00
+h2gdf6120/cpu-5/cpu-user:
+  value: 0.000000e+00
+h2gdf6120/cpu-5/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-6/cpu-idle:
+  value: 9.840033e+01
+h2gdf6120/cpu-6/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-6/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-6/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-6/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-6/cpu-system:
+  value: 3.000009e-01
+h2gdf6120/cpu-6/cpu-user:
+  value: 1.200004e+00
+h2gdf6120/cpu-6/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-7/cpu-idle:
+  value: 9.700041e+01
+h2gdf6120/cpu-7/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-7/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-7/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-7/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-7/cpu-system:
+  value: 2.000008e-01
+h2gdf6120/cpu-7/cpu-user:
+  value: 2.500009e+00
+h2gdf6120/cpu-7/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-8/cpu-idle:
+  value: 1.000004e+02
+h2gdf6120/cpu-8/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-8/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-8/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-8/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-8/cpu-system:
+  value: 0.000000e+00
+h2gdf6120/cpu-8/cpu-user:
+  value: 0.000000e+00
+h2gdf6120/cpu-8/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/cpu-9/cpu-idle:
+  value: 9.990057e+01
+h2gdf6120/cpu-9/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6120/cpu-9/cpu-nice:
+  value: 0.000000e+00
+h2gdf6120/cpu-9/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6120/cpu-9/cpu-steal:
+  value: 0.000000e+00
+h2gdf6120/cpu-9/cpu-system:
+  value: 0.000000e+00
+h2gdf6120/cpu-9/cpu-user:
+  value: 0.000000e+00
+h2gdf6120/cpu-9/cpu-wait:
+  value: 0.000000e+00
+h2gdf6120/df-boot/df_complex-free:
+  value: 4.325089e+08
+h2gdf6120/df-boot/df_complex-reserved:
+  value: 2.684109e+07
+h2gdf6120/df-boot/df_complex-used:
+  value: 6.907494e+07
+h2gdf6120/df-boot/df_inodes-free:
+  value: 3.271800e+04
+h2gdf6120/df-boot/df_inodes-reserved:
+  value: 0.000000e+00
+h2gdf6120/df-boot/df_inodes-used:
+  value: 5.000000e+01
+h2gdf6120/df-boot/percent_bytes-free:
+  value: 8.184869e+01
+h2gdf6120/df-boot/percent_bytes-reserved:
+  value: 5.079451e+00
+h2gdf6120/df-boot/percent_bytes-used:
+  value: 1.307185e+01
+h2gdf6120/df-boot/percent_inodes-free:
+  value: 9.984741e+01
+h2gdf6120/df-boot/percent_inodes-reserved:
+  value: 0.000000e+00
+h2gdf6120/df-boot/percent_inodes-used:
+  value: 1.525879e-01
+h2gdf6120/df-data1/df_complex-free:
+  value: 2.503070e+11
+h2gdf6120/df-data1/df_complex-reserved:
+  value: 1.378982e+10
+h2gdf6120/df-data1/df_complex-used:
+  value: 7.372034e+09
+h2gdf6120/df-data1/df_inodes-free:
+  value: 1.683450e+07
+h2gdf6120/df-data1/df_inodes-reserved:
+  value: 0.000000e+00
+h2gdf6120/df-data1/df_inodes-used:
+  value: 5.900000e+01
+h2gdf6120/df-data1/percent_bytes-free:
+  value: 9.220468e+01
+h2gdf6120/df-data1/percent_bytes-reserved:
+  value: 5.079707e+00
+h2gdf6120/df-data1/percent_bytes-used:
+  value: 2.715609e+00
+h2gdf6120/df-data1/percent_inodes-free:
+  value: 9.999964e+01
+h2gdf6120/df-data1/percent_inodes-reserved:
+  value: 0.000000e+00
+h2gdf6120/df-data1/percent_inodes-used:
+  value: 3.504695e-04
+h2gdf6120/df-dev-shm/df_complex-free:
+  value: 3.375709e+10
+h2gdf6120/df-dev-shm/df_complex-reserved:
+  value: 0.000000e+00
+h2gdf6120/df-dev-shm/df_complex-used:
+  value: 0.000000e+00
+h2gdf6120/df-dev-shm/df_inodes-free:
+  value: 8.241475e+06
+h2gdf6120/df-dev-shm/df_inodes-reserved:
+  value: 0.000000e+00
+h2gdf6120/df-dev-shm/df_inodes-used:
+  value: 1.000000e+00
+h2gdf6120/df-dev-shm/percent_bytes-free:
+  value: 1.000000e+02
+h2gdf6120/df-dev-shm/percent_bytes-reserved:
+  value: 0.000000e+00
+h2gdf6120/df-dev-shm/percent_bytes-used:
+  value: 0.000000e+00
+h2gdf6120/df-dev-shm/percent_inodes-free:
+  value: 9.999998e+01
+h2gdf6120/df-dev-shm/percent_inodes-reserved:
+  value: 0.000000e+00
+h2gdf6120/df-dev-shm/percent_inodes-used:
+  value: 1.213375e-05
+h2gdf6120/df-root/df_complex-free:
+  value: 1.058675e+10
+h2gdf6120/df-root/df_complex-reserved:
+  value: 6.442435e+08
+h2gdf6120/df-root/df_complex-used:
+  value: 1.451717e+09
+h2gdf6120/df-root/df_inodes-free:
+  value: 7.435350e+05
+h2gdf6120/df-root/df_inodes-reserved:
+  value: 0.000000e+00
+h2gdf6120/df-root/df_inodes-used:
+  value: 4.289700e+04
+h2gdf6120/df-root/percent_bytes-free:
+  value: 8.347388e+01
+h2gdf6120/df-root/percent_bytes-reserved:
+  value: 5.079700e+00
+h2gdf6120/df-root/percent_bytes-used:
+  value: 1.144643e+01
+h2gdf6120/df-root/percent_inodes-free:
+  value: 9.454536e+01
+h2gdf6120/df-root/percent_inodes-reserved:
+  value: 0.000000e+00
+h2gdf6120/df-root/percent_inodes-used:
+  value: 5.454636e+00
+h2gdf6120/df-var/df_complex-free:
+  value: 7.503532e+09
+h2gdf6120/df-var/df_complex-reserved:
+  value: 4.294943e+08
+h2gdf6120/df-var/df_complex-used:
+  value: 5.220925e+08
+h2gdf6120/df-var/df_inodes-free:
+  value: 5.225340e+05
+h2gdf6120/df-var/df_inodes-reserved:
+  value: 0.000000e+00
+h2gdf6120/df-var/df_inodes-used:
+  value: 1.754000e+03
+h2gdf6120/df-var/percent_bytes-free:
+  value: 8.874543e+01
+h2gdf6120/df-var/percent_bytes-reserved:
+  value: 5.079695e+00
+h2gdf6120/df-var/percent_bytes-used:
+  value: 6.174870e+00
+h2gdf6120/df-var/percent_inodes-free:
+  value: 9.966545e+01
+h2gdf6120/df-var/percent_inodes-reserved:
+  value: 0.000000e+00
+h2gdf6120/df-var/percent_inodes-used:
+  value: 3.345490e-01
+h2gdf6120/disk-sda/disk_merged:
+  read: 0.000000e+00
+  write: 1.000000e-01
+h2gdf6120/disk-sda/disk_octets:
+  read: 0.000000e+00
+  write: 4.915201e+03
+h2gdf6120/disk-sda/disk_ops:
+  read: 0.000000e+00
+  write: 1.000000e+00
+h2gdf6120/disk-sda/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6120/disk-sda1/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6120/disk-sda1/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6120/disk-sda1/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6120/disk-sda1/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6120/disk-sda2/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6120/disk-sda2/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6120/disk-sda2/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6120/disk-sda2/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6120/disk-sda3/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6120/disk-sda3/disk_octets:
+  read: 0.000000e+00
+  write: 1.638401e+03
+h2gdf6120/disk-sda3/disk_ops:
+  read: 0.000000e+00
+  write: 4.000002e-01
+h2gdf6120/disk-sda3/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6120/disk-sda4/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6120/disk-sda4/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6120/disk-sda4/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6120/disk-sda4/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6120/disk-sda5/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6120/disk-sda5/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6120/disk-sda5/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6120/disk-sda5/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6120/disk-sda6/disk_merged:
+  read: 0.000000e+00
+  write: 9.999979e-02
+h2gdf6120/disk-sda6/disk_octets:
+  read: 0.000000e+00
+  write: 3.276793e+03
+h2gdf6120/disk-sda6/disk_ops:
+  read: 0.000000e+00
+  write: 5.999987e-01
+h2gdf6120/disk-sda6/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6120/load/load:
+  longterm: 3.000000e-02
+  midterm: 3.000000e-02
+  shortterm: 0.000000e+00
+h2gdf6120/memory/memory-buffered:
+  value: 3.471032e+08
+h2gdf6120/memory/memory-cached:
+  value: 6.819758e+08
+h2gdf6120/memory/memory-free:
+  value: 5.914347e+10
+h2gdf6120/memory/memory-used:
+  value: 7.341625e+09
+h2gdf6120/network/if_octets:
+  rx: 0.000000e+00
+  tx: 1.587800e+03
+h2gdf6120/network/if_packets:
+  rx: 0.000000e+00
+  tx: 1.200000e+00
+h2gdf6120/network/queue_length:
+  value: 0.000000e+00
+h2gdf6120/network/total_values-dispatch-accepted:
+  value: 0.000000e+00
+h2gdf6120/network/total_values-dispatch-rejected:
+  value: 0.000000e+00
+h2gdf6120/network/total_values-send-accepted:
+  value: 3.189999e+01
+h2gdf6120/network/total_values-send-rejected:
+  value: 0.000000e+00
+h2gdf6120/swap/swap-cached:
+  value: 0.000000e+00
+h2gdf6120/swap/swap-free:
+  value: 2.147475e+09
+h2gdf6120/swap/swap-used:
+  value: 0.000000e+00
+h2gdf6120/swap/swap_io-in:
+  value: 0.000000e+00
+h2gdf6120/swap/swap_io-out:
+  value: 0.000000e+00
+h2gdf6120/vmem/vmpage_faults:
+  majflt: 0.000000e+00
+  minflt: 4.499975e+00
+h2gdf6120/vmem/vmpage_io-memory:
+  in: 0.000000e+00
+  out: 8.799950e+00
+h2gdf6120/vmem/vmpage_io-swap:
+  in: 0.000000e+00
+  out: 0.000000e+00
+h2gdf6120/vmem/vmpage_number-active_anon:
+  value: 1.425964e+06
+h2gdf6120/vmem/vmpage_number-active_file:
+  value: 1.796950e+05
+h2gdf6120/vmem/vmpage_number-anon_pages:
+  value: 1.638300e+04
+h2gdf6120/vmem/vmpage_number-anon_transparent_hugepages:
+  value: 2.753000e+03
+h2gdf6120/vmem/vmpage_number-boudfe:
+  value: 0.000000e+00
+h2gdf6120/vmem/vmpage_number-dirty:
+  value: 8.000000e+00
+h2gdf6120/vmem/vmpage_number-file_pages:
+  value: 2.512400e+05
+h2gdf6120/vmem/vmpage_number-free_pages:
+  value: 1.443932e+07
+h2gdf6120/vmem/vmpage_number-inactive_anon:
+  value: 1.100000e+01
+h2gdf6120/vmem/vmpage_number-inactive_file:
+  value: 7.149200e+04
+h2gdf6120/vmem/vmpage_number-isolated_anon:
+  value: 0.000000e+00
+h2gdf6120/vmem/vmpage_number-isolated_file:
+  value: 0.000000e+00
+h2gdf6120/vmem/vmpage_number-kernel_stack:
+  value: 4.730000e+02
+h2gdf6120/vmem/vmpage_number-mapped:
+  value: 4.319000e+03
+h2gdf6120/vmem/vmpage_number-mlock:
+  value: 0.000000e+00
+h2gdf6120/vmem/vmpage_number-page_table_pages:
+  value: 3.607000e+03
+h2gdf6120/vmem/vmpage_number-shmem:
+  value: 5.700000e+01
+h2gdf6120/vmem/vmpage_number-slab_reclaimable:
+  value: 2.365580e+05
+h2gdf6120/vmem/vmpage_number-slab_unreclaimable:
+  value: 1.603500e+04
+h2gdf6120/vmem/vmpage_number-unevictable:
+  value: 0.000000e+00
+h2gdf6120/vmem/vmpage_number-unstable:
+  value: 0.000000e+00
+h2gdf6120/vmem/vmpage_number-vmscan_write:
+  value: 0.000000e+00
+h2gdf6120/vmem/vmpage_number-writeback:
+  value: 0.000000e+00
+h2gdf6120/vmem/vmpage_number-writeback_temp:
+  value: 0.000000e+00
+h2gdf6220/cpu-0/cpu-idle:
+  value: 9.760209e+01
+h2gdf6220/cpu-0/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-0/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-0/cpu-softirq:
+  value: 1.000040e-01
+h2gdf6220/cpu-0/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-0/cpu-system:
+  value: 4.000084e-01
+h2gdf6220/cpu-0/cpu-user:
+  value: 9.999957e-01
+h2gdf6220/cpu-0/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-1/cpu-idle:
+  value: 9.970561e+01
+h2gdf6220/cpu-1/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-1/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-1/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-1/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-1/cpu-system:
+  value: 1.000053e-01
+h2gdf6220/cpu-1/cpu-user:
+  value: 1.000047e-01
+h2gdf6220/cpu-1/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-10/cpu-idle:
+  value: 9.990600e+01
+h2gdf6220/cpu-10/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-10/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-10/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-10/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-10/cpu-system:
+  value: 0.000000e+00
+h2gdf6220/cpu-10/cpu-user:
+  value: 0.000000e+00
+h2gdf6220/cpu-10/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-11/cpu-idle:
+  value: 1.000060e+02
+h2gdf6220/cpu-11/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-11/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-11/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-11/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-11/cpu-system:
+  value: 0.000000e+00
+h2gdf6220/cpu-11/cpu-user:
+  value: 0.000000e+00
+h2gdf6220/cpu-11/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-12/cpu-idle:
+  value: 9.780591e+01
+h2gdf6220/cpu-12/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-12/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-12/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-12/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-12/cpu-system:
+  value: 5.000302e-01
+h2gdf6220/cpu-12/cpu-user:
+  value: 8.000479e-01
+h2gdf6220/cpu-12/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-13/cpu-idle:
+  value: 9.980613e+01
+h2gdf6220/cpu-13/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-13/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-13/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-13/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-13/cpu-system:
+  value: 0.000000e+00
+h2gdf6220/cpu-13/cpu-user:
+  value: 0.000000e+00
+h2gdf6220/cpu-13/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-14/cpu-idle:
+  value: 1.000061e+02
+h2gdf6220/cpu-14/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-14/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-14/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-14/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-14/cpu-system:
+  value: 0.000000e+00
+h2gdf6220/cpu-14/cpu-user:
+  value: 0.000000e+00
+h2gdf6220/cpu-14/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-15/cpu-idle:
+  value: 9.990596e+01
+h2gdf6220/cpu-15/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-15/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-15/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-15/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-15/cpu-system:
+  value: 0.000000e+00
+h2gdf6220/cpu-15/cpu-user:
+  value: 0.000000e+00
+h2gdf6220/cpu-15/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-16/cpu-idle:
+  value: 9.990572e+01
+h2gdf6220/cpu-16/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-16/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-16/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-16/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-16/cpu-system:
+  value: 0.000000e+00
+h2gdf6220/cpu-16/cpu-user:
+  value: 0.000000e+00
+h2gdf6220/cpu-16/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-17/cpu-idle:
+  value: 1.000057e+02
+h2gdf6220/cpu-17/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-17/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-17/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-17/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-17/cpu-system:
+  value: 0.000000e+00
+h2gdf6220/cpu-17/cpu-user:
+  value: 0.000000e+00
+h2gdf6220/cpu-17/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-18/cpu-idle:
+  value: 1.000058e+02
+h2gdf6220/cpu-18/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-18/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-18/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-18/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-18/cpu-system:
+  value: 0.000000e+00
+h2gdf6220/cpu-18/cpu-user:
+  value: 0.000000e+00
+h2gdf6220/cpu-18/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-19/cpu-idle:
+  value: 9.990559e+01
+h2gdf6220/cpu-19/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-19/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-19/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-19/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-19/cpu-system:
+  value: 2.000113e-01
+h2gdf6220/cpu-19/cpu-user:
+  value: 1.000057e-01
+h2gdf6220/cpu-19/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-2/cpu-idle:
+  value: 9.990540e+01
+h2gdf6220/cpu-2/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-2/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-2/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-2/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-2/cpu-system:
+  value: 0.000000e+00
+h2gdf6220/cpu-2/cpu-user:
+  value: 1.000054e-01
+h2gdf6220/cpu-2/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-20/cpu-idle:
+  value: 1.000055e+02
+h2gdf6220/cpu-20/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-20/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-20/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-20/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-20/cpu-system:
+  value: 0.000000e+00
+h2gdf6220/cpu-20/cpu-user:
+  value: 0.000000e+00
+h2gdf6220/cpu-20/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-21/cpu-idle:
+  value: 1.000054e+02
+h2gdf6220/cpu-21/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-21/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-21/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-21/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-21/cpu-system:
+  value: 0.000000e+00
+h2gdf6220/cpu-21/cpu-user:
+  value: 0.000000e+00
+h2gdf6220/cpu-21/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-22/cpu-idle:
+  value: 9.990534e+01
+h2gdf6220/cpu-22/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-22/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-22/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-22/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-22/cpu-system:
+  value: 0.000000e+00
+h2gdf6220/cpu-22/cpu-user:
+  value: 0.000000e+00
+h2gdf6220/cpu-22/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-23/cpu-idle:
+  value: 1.000054e+02
+h2gdf6220/cpu-23/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-23/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-23/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-23/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-23/cpu-system:
+  value: 0.000000e+00
+h2gdf6220/cpu-23/cpu-user:
+  value: 0.000000e+00
+h2gdf6220/cpu-23/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-3/cpu-idle:
+  value: 1.000058e+02
+h2gdf6220/cpu-3/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-3/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-3/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-3/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-3/cpu-system:
+  value: 0.000000e+00
+h2gdf6220/cpu-3/cpu-user:
+  value: 0.000000e+00
+h2gdf6220/cpu-3/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-4/cpu-idle:
+  value: 9.990588e+01
+h2gdf6220/cpu-4/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-4/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-4/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-4/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-4/cpu-system:
+  value: 0.000000e+00
+h2gdf6220/cpu-4/cpu-user:
+  value: 0.000000e+00
+h2gdf6220/cpu-4/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-5/cpu-idle:
+  value: 1.000061e+02
+h2gdf6220/cpu-5/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-5/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-5/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-5/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-5/cpu-system:
+  value: 0.000000e+00
+h2gdf6220/cpu-5/cpu-user:
+  value: 0.000000e+00
+h2gdf6220/cpu-5/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-6/cpu-idle:
+  value: 9.980614e+01
+h2gdf6220/cpu-6/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-6/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-6/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-6/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-6/cpu-system:
+  value: 0.000000e+00
+h2gdf6220/cpu-6/cpu-user:
+  value: 0.000000e+00
+h2gdf6220/cpu-6/cpu-wait:
+  value: 1.000062e-01
+h2gdf6220/cpu-7/cpu-idle:
+  value: 9.990617e+01
+h2gdf6220/cpu-7/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-7/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-7/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-7/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-7/cpu-system:
+  value: 1.000062e-01
+h2gdf6220/cpu-7/cpu-user:
+  value: 0.000000e+00
+h2gdf6220/cpu-7/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-8/cpu-idle:
+  value: 1.000060e+02
+h2gdf6220/cpu-8/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-8/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-8/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-8/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-8/cpu-system:
+  value: 0.000000e+00
+h2gdf6220/cpu-8/cpu-user:
+  value: 0.000000e+00
+h2gdf6220/cpu-8/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/cpu-9/cpu-idle:
+  value: 9.990601e+01
+h2gdf6220/cpu-9/cpu-interrupt:
+  value: 0.000000e+00
+h2gdf6220/cpu-9/cpu-nice:
+  value: 0.000000e+00
+h2gdf6220/cpu-9/cpu-softirq:
+  value: 0.000000e+00
+h2gdf6220/cpu-9/cpu-steal:
+  value: 0.000000e+00
+h2gdf6220/cpu-9/cpu-system:
+  value: 0.000000e+00
+h2gdf6220/cpu-9/cpu-user:
+  value: 0.000000e+00
+h2gdf6220/cpu-9/cpu-wait:
+  value: 0.000000e+00
+h2gdf6220/df-boot/df_complex-free:
+  value: 4.324721e+08
+h2gdf6220/df-boot/df_complex-reserved:
+  value: 2.684109e+07
+h2gdf6220/df-boot/df_complex-used:
+  value: 6.911181e+07
+h2gdf6220/df-boot/df_inodes-free:
+  value: 3.271800e+04
+h2gdf6220/df-boot/df_inodes-reserved:
+  value: 0.000000e+00
+h2gdf6220/df-boot/df_inodes-used:
+  value: 5.000000e+01
+h2gdf6220/df-boot/percent_bytes-free:
+  value: 8.184172e+01
+h2gdf6220/df-boot/percent_bytes-reserved:
+  value: 5.079451e+00
+h2gdf6220/df-boot/percent_bytes-used:
+  value: 1.307883e+01
+h2gdf6220/df-boot/percent_inodes-free:
+  value: 9.984741e+01
+h2gdf6220/df-boot/percent_inodes-reserved:
+  value: 0.000000e+00
+h2gdf6220/df-boot/percent_inodes-used:
+  value: 1.525879e-01
+h2gdf6220/df-data1/df_complex-free:
+  value: 2.459593e+11
+h2gdf6220/df-data1/df_complex-reserved:
+  value: 1.378982e+10
+h2gdf6220/df-data1/df_complex-used:
+  value: 1.171974e+10
+h2gdf6220/df-data1/df_inodes-free:
+  value: 1.683450e+07
+h2gdf6220/df-data1/df_inodes-reserved:
+  value: 0.000000e+00
+h2gdf6220/df-data1/df_inodes-used:
+  value: 6.100000e+01
+h2gdf6220/df-data1/percent_bytes-free:
+  value: 9.060313e+01
+h2gdf6220/df-data1/percent_bytes-reserved:
+  value: 5.079707e+00
+h2gdf6220/df-data1/percent_bytes-used:
+  value: 4.317159e+00
+h2gdf6220/df-data1/percent_inodes-free:
+  value: 9.999964e+01
+h2gdf6220/df-data1/percent_inodes-reserved:
+  value: 0.000000e+00
+h2gdf6220/df-data1/percent_inodes-used:
+  value: 3.623498e-04
+h2gdf6220/df-dev-shm/df_complex-free:
+  value: 3.375709e+10
+h2gdf6220/df-dev-shm/df_complex-reserved:
+  value: 0.000000e+00
+h2gdf6220/df-dev-shm/df_complex-used:
+  value: 0.000000e+00
+h2gdf6220/df-dev-shm/df_inodes-free:
+  value: 8.241475e+06
+h2gdf6220/df-dev-shm/df_inodes-reserved:
+  value: 0.000000e+00
+h2gdf6220/df-dev-shm/df_inodes-used:
+  value: 1.000000e+00
+h2gdf6220/df-dev-shm/percent_bytes-free:
+  value: 1.000000e+02
+h2gdf6220/df-dev-shm/percent_bytes-reserved:
+  value: 0.000000e+00
+h2gdf6220/df-dev-shm/percent_bytes-used:
+  value: 0.000000e+00
+h2gdf6220/df-dev-shm/percent_inodes-free:
+  value: 9.999998e+01
+h2gdf6220/df-dev-shm/percent_inodes-reserved:
+  value: 0.000000e+00
+h2gdf6220/df-dev-shm/percent_inodes-used:
+  value: 1.213375e-05
+h2gdf6220/df-root/df_complex-free:
+  value: 1.058283e+10
+h2gdf6220/df-root/df_complex-reserved:
+  value: 6.442435e+08
+h2gdf6220/df-root/df_complex-used:
+  value: 1.455632e+09
+h2gdf6220/df-root/df_inodes-free:
+  value: 7.435320e+05
+h2gdf6220/df-root/df_inodes-reserved:
+  value: 0.000000e+00
+h2gdf6220/df-root/df_inodes-used:
+  value: 4.290000e+04
+h2gdf6220/df-root/percent_bytes-free:
+  value: 8.344300e+01
+h2gdf6220/df-root/percent_bytes-reserved:
+  value: 5.079700e+00
+h2gdf6220/df-root/percent_bytes-used:
+  value: 1.147730e+01
+h2gdf6220/df-root/percent_inodes-free:
+  value: 9.454498e+01
+h2gdf6220/df-root/percent_inodes-reserved:
+  value: 0.000000e+00
+h2gdf6220/df-root/percent_inodes-used:
+  value: 5.455017e+00
+h2gdf6220/df-var/df_complex-free:
+  value: 7.501562e+09
+h2gdf6220/df-var/df_complex-reserved:
+  value: 4.294943e+08
+h2gdf6220/df-var/df_complex-used:
+  value: 5.240627e+08
+h2gdf6220/df-var/df_inodes-free:
+  value: 5.225360e+05
+h2gdf6220/df-var/df_inodes-reserved:
+  value: 0.000000e+00
+h2gdf6220/df-var/df_inodes-used:
+  value: 1.752000e+03
+h2gdf6220/df-var/percent_bytes-free:
+  value: 8.872214e+01
+h2gdf6220/df-var/percent_bytes-reserved:
+  value: 5.079695e+00
+h2gdf6220/df-var/percent_bytes-used:
+  value: 6.198171e+00
+h2gdf6220/df-var/percent_inodes-free:
+  value: 9.966583e+01
+h2gdf6220/df-var/percent_inodes-reserved:
+  value: 0.000000e+00
+h2gdf6220/df-var/percent_inodes-used:
+  value: 3.341675e-01
+h2gdf6220/disk-sda/disk_merged:
+  read: 0.000000e+00
+  write: 5.000078e-01
+h2gdf6220/disk-sda/disk_octets:
+  read: 0.000000e+00
+  write: 1.761274e+05
+h2gdf6220/disk-sda/disk_ops:
+  read: 0.000000e+00
+  write: 6.599997e+00
+h2gdf6220/disk-sda/disk_time:
+  read: 0.000000e+00
+  write: 1.200000e+00
+h2gdf6220/disk-sda1/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6220/disk-sda1/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6220/disk-sda1/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6220/disk-sda1/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6220/disk-sda2/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6220/disk-sda2/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6220/disk-sda2/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6220/disk-sda2/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6220/disk-sda3/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6220/disk-sda3/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6220/disk-sda3/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6220/disk-sda3/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6220/disk-sda4/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6220/disk-sda4/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6220/disk-sda4/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6220/disk-sda4/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6220/disk-sda5/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6220/disk-sda5/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6220/disk-sda5/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6220/disk-sda5/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+h2gdf6220/disk-sda6/disk_merged:
+  read: 0.000000e+00
+  write: 5.000119e-01
+h2gdf6220/disk-sda6/disk_octets:
+  read: 0.000000e+00
+  write: 1.761322e+05
+h2gdf6220/disk-sda6/disk_ops:
+  read: 0.000000e+00
+  write: 6.600157e+00
+h2gdf6220/disk-sda6/disk_time:
+  read: 0.000000e+00
+  write: 1.200029e+00
+h2gdf6220/load/load:
+  longterm: 3.000000e-02
+  midterm: 1.300000e-01
+  shortterm: 1.800000e-01
+h2gdf6220/memory/memory-buffered:
+  value: 3.538944e+08
+h2gdf6220/memory/memory-cached:
+  value: 6.890127e+08
+h2gdf6220/memory/memory-free:
+  value: 5.744062e+10
+h2gdf6220/memory/memory-used:
+  value: 9.030652e+09
+h2gdf6220/network/if_octets:
+  rx: 0.000000e+00
+  tx: 1.449803e+03
+h2gdf6220/network/if_packets:
+  rx: 0.000000e+00
+  tx: 1.100003e+00
+h2gdf6220/network/queue_length:
+  value: 0.000000e+00
+h2gdf6220/network/total_values-dispatch-accepted:
+  value: 0.000000e+00
+h2gdf6220/network/total_values-dispatch-rejected:
+  value: 0.000000e+00
+h2gdf6220/network/total_values-send-accepted:
+  value: 2.630008e+01
+h2gdf6220/network/total_values-send-rejected:
+  value: 0.000000e+00
+h2gdf6220/swap/swap-cached:
+  value: 0.000000e+00
+h2gdf6220/swap/swap-free:
+  value: 2.147475e+09
+h2gdf6220/swap/swap-used:
+  value: 0.000000e+00
+h2gdf6220/swap/swap_io-in:
+  value: 0.000000e+00
+h2gdf6220/swap/swap_io-out:
+  value: 0.000000e+00
+h2gdf6220/vmem/vmpage_faults:
+  majflt: 0.000000e+00
+  minflt: 7.000005e-01
+h2gdf6220/vmem/vmpage_io-memory:
+  in: 0.000000e+00
+  out: 2.800002e+00
+h2gdf6220/vmem/vmpage_io-swap:
+  in: 0.000000e+00
+  out: 0.000000e+00
+h2gdf6220/vmem/vmpage_number-active_anon:
+  value: 1.830919e+06
+h2gdf6220/vmem/vmpage_number-active_file:
+  value: 1.812510e+05
+h2gdf6220/vmem/vmpage_number-anon_pages:
+  value: 1.841200e+04
+h2gdf6220/vmem/vmpage_number-anon_transparent_hugepages:
+  value: 3.540000e+03
+h2gdf6220/vmem/vmpage_number-boudfe:
+  value: 0.000000e+00
+h2gdf6220/vmem/vmpage_number-dirty:
+  value: 4.000000e+00
+h2gdf6220/vmem/vmpage_number-file_pages:
+  value: 2.546160e+05
+h2gdf6220/vmem/vmpage_number-free_pages:
+  value: 1.402359e+07
+h2gdf6220/vmem/vmpage_number-inactive_anon:
+  value: 1.600000e+01
+h2gdf6220/vmem/vmpage_number-inactive_file:
+  value: 7.330700e+04
+h2gdf6220/vmem/vmpage_number-isolated_anon:
+  value: 0.000000e+00
+h2gdf6220/vmem/vmpage_number-isolated_file:
+  value: 0.000000e+00
+h2gdf6220/vmem/vmpage_number-kernel_stack:
+  value: 4.900000e+02
+h2gdf6220/vmem/vmpage_number-mapped:
+  value: 4.792000e+03
+h2gdf6220/vmem/vmpage_number-mlock:
+  value: 0.000000e+00
+h2gdf6220/vmem/vmpage_number-page_table_pages:
+  value: 4.540000e+03
+h2gdf6220/vmem/vmpage_number-shmem:
+  value: 6.200000e+01
+h2gdf6220/vmem/vmpage_number-slab_reclaimable:
+  value: 2.343820e+05
+h2gdf6220/vmem/vmpage_number-slab_unreclaimable:
+  value: 2.127200e+04
+h2gdf6220/vmem/vmpage_number-unevictable:
+  value: 0.000000e+00
+h2gdf6220/vmem/vmpage_number-unstable:
+  value: 0.000000e+00
+h2gdf6220/vmem/vmpage_number-vmscan_write:
+  value: 0.000000e+00
+h2gdf6220/vmem/vmpage_number-writeback:
+  value: 0.000000e+00
+h2gdf6220/vmem/vmpage_number-writeback_temp:
+  value: 0.000000e+00
+m01df6100/cpu-0/cpu-idle:
+  value: 9.980233e+01
+m01df6100/cpu-0/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-0/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-0/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-0/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-0/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-0/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-0/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-1/cpu-idle:
+  value: 1.000105e+02
+m01df6100/cpu-1/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-1/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-1/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-1/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-1/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-1/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-1/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-10/cpu-idle:
+  value: 1.000294e+02
+m01df6100/cpu-10/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-10/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-10/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-10/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-10/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-10/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-10/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-11/cpu-idle:
+  value: 9.993001e+01
+m01df6100/cpu-11/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-11/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-11/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-11/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-11/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-11/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-11/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-12/cpu-idle:
+  value: 1.000310e+02
+m01df6100/cpu-12/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-12/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-12/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-12/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-12/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-12/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-12/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-13/cpu-idle:
+  value: 9.993154e+01
+m01df6100/cpu-13/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-13/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-13/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-13/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-13/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-13/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-13/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-14/cpu-idle:
+  value: 1.000329e+02
+m01df6100/cpu-14/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-14/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-14/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-14/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-14/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-14/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-14/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-15/cpu-idle:
+  value: 1.000341e+02
+m01df6100/cpu-15/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-15/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-15/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-15/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-15/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-15/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-15/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-16/cpu-idle:
+  value: 1.000347e+02
+m01df6100/cpu-16/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-16/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-16/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-16/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-16/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-16/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-16/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-17/cpu-idle:
+  value: 1.000354e+02
+m01df6100/cpu-17/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-17/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-17/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-17/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-17/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-17/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-17/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-18/cpu-idle:
+  value: 9.993624e+01
+m01df6100/cpu-18/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-18/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-18/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-18/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-18/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-18/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-18/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-19/cpu-idle:
+  value: 9.993717e+01
+m01df6100/cpu-19/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-19/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-19/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-19/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-19/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-19/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-19/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-2/cpu-idle:
+  value: 1.000135e+02
+m01df6100/cpu-2/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-2/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-2/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-2/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-2/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-2/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-2/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-20/cpu-idle:
+  value: 9.993831e+01
+m01df6100/cpu-20/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-20/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-20/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-20/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-20/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-20/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-20/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-21/cpu-idle:
+  value: 1.000397e+02
+m01df6100/cpu-21/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-21/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-21/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-21/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-21/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-21/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-21/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-22/cpu-idle:
+  value: 9.994092e+01
+m01df6100/cpu-22/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-22/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-22/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-22/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-22/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-22/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-22/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-23/cpu-idle:
+  value: 1.000420e+02
+m01df6100/cpu-23/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-23/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-23/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-23/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-23/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-23/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-23/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-3/cpu-idle:
+  value: 1.000161e+02
+m01df6100/cpu-3/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-3/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-3/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-3/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-3/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-3/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-3/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-4/cpu-idle:
+  value: 1.000191e+02
+m01df6100/cpu-4/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-4/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-4/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-4/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-4/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-4/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-4/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-5/cpu-idle:
+  value: 1.000243e+02
+m01df6100/cpu-5/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-5/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-5/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-5/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-5/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-5/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-5/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-6/cpu-idle:
+  value: 1.000268e+02
+m01df6100/cpu-6/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-6/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-6/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-6/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-6/cpu-system:
+  value: 1.000266e-01
+m01df6100/cpu-6/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-6/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-7/cpu-idle:
+  value: 1.000274e+02
+m01df6100/cpu-7/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-7/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-7/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-7/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-7/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-7/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-7/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-8/cpu-idle:
+  value: 1.000283e+02
+m01df6100/cpu-8/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-8/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-8/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-8/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-8/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-8/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-8/cpu-wait:
+  value: 0.000000e+00
+m01df6100/cpu-9/cpu-idle:
+  value: 1.000291e+02
+m01df6100/cpu-9/cpu-interrupt:
+  value: 0.000000e+00
+m01df6100/cpu-9/cpu-nice:
+  value: 0.000000e+00
+m01df6100/cpu-9/cpu-softirq:
+  value: 0.000000e+00
+m01df6100/cpu-9/cpu-steal:
+  value: 0.000000e+00
+m01df6100/cpu-9/cpu-system:
+  value: 0.000000e+00
+m01df6100/cpu-9/cpu-user:
+  value: 0.000000e+00
+m01df6100/cpu-9/cpu-wait:
+  value: 0.000000e+00
+m01df6100/df-boot/df_complex-free:
+  value: 4.369408e+08
+m01df6100/df-boot/df_complex-reserved:
+  value: 2.684109e+07
+m01df6100/df-boot/df_complex-used:
+  value: 6.464307e+07
+m01df6100/df-boot/df_inodes-free:
+  value: 3.271800e+04
+m01df6100/df-boot/df_inodes-reserved:
+  value: 0.000000e+00
+m01df6100/df-boot/df_inodes-used:
+  value: 5.000000e+01
+m01df6100/df-boot/percent_bytes-free:
+  value: 8.268739e+01
+m01df6100/df-boot/percent_bytes-reserved:
+  value: 5.079451e+00
+m01df6100/df-boot/percent_bytes-used:
+  value: 1.223316e+01
+m01df6100/df-boot/percent_inodes-free:
+  value: 9.984741e+01
+m01df6100/df-boot/percent_inodes-reserved:
+  value: 0.000000e+00
+m01df6100/df-boot/percent_inodes-used:
+  value: 1.525879e-01
+m01df6100/df-data1/df_complex-free:
+  value: 2.574032e+11
+m01df6100/df-data1/df_complex-reserved:
+  value: 1.378982e+10
+m01df6100/df-data1/df_complex-used:
+  value: 2.758984e+08
+m01df6100/df-data1/df_inodes-free:
+  value: 1.683426e+07
+m01df6100/df-data1/df_inodes-reserved:
+  value: 0.000000e+00
+m01df6100/df-data1/df_inodes-used:
+  value: 2.960000e+02
+m01df6100/df-data1/percent_bytes-free:
+  value: 9.481866e+01
+m01df6100/df-data1/percent_bytes-reserved:
+  value: 5.079707e+00
+m01df6100/df-data1/percent_bytes-used:
+  value: 1.016317e-01
+m01df6100/df-data1/percent_inodes-free:
+  value: 9.999825e+01
+m01df6100/df-data1/percent_inodes-reserved:
+  value: 0.000000e+00
+m01df6100/df-data1/percent_inodes-used:
+  value: 1.758288e-03
+m01df6100/df-dev-shm/df_complex-free:
+  value: 3.375709e+10
+m01df6100/df-dev-shm/df_complex-reserved:
+  value: 0.000000e+00
+m01df6100/df-dev-shm/df_complex-used:
+  value: 0.000000e+00
+m01df6100/df-dev-shm/df_inodes-free:
+  value: 8.241475e+06
+m01df6100/df-dev-shm/df_inodes-reserved:
+  value: 0.000000e+00
+m01df6100/df-dev-shm/df_inodes-used:
+  value: 1.000000e+00
+m01df6100/df-dev-shm/percent_bytes-free:
+  value: 1.000000e+02
+m01df6100/df-dev-shm/percent_bytes-reserved:
+  value: 0.000000e+00
+m01df6100/df-dev-shm/percent_bytes-used:
+  value: 0.000000e+00
+m01df6100/df-dev-shm/percent_inodes-free:
+  value: 9.999998e+01
+m01df6100/df-dev-shm/percent_inodes-reserved:
+  value: 0.000000e+00
+m01df6100/df-dev-shm/percent_inodes-used:
+  value: 1.213375e-05
+m01df6100/df-root/df_complex-free:
+  value: 1.072688e+10
+m01df6100/df-root/df_complex-reserved:
+  value: 6.442435e+08
+m01df6100/df-root/df_complex-used:
+  value: 1.311580e+09
+m01df6100/df-root/df_inodes-free:
+  value: 7.454950e+05
+m01df6100/df-root/df_inodes-reserved:
+  value: 0.000000e+00
+m01df6100/df-root/df_inodes-used:
+  value: 4.093700e+04
+m01df6100/df-root/percent_bytes-free:
+  value: 8.457882e+01
+m01df6100/df-root/percent_bytes-reserved:
+  value: 5.079700e+00
+m01df6100/df-root/percent_bytes-used:
+  value: 1.034148e+01
+m01df6100/df-root/percent_inodes-free:
+  value: 9.479459e+01
+m01df6100/df-root/percent_inodes-reserved:
+  value: 0.000000e+00
+m01df6100/df-root/percent_inodes-used:
+  value: 5.205409e+00
+m01df6100/df-var/df_complex-free:
+  value: 7.566787e+09
+m01df6100/df-var/df_complex-reserved:
+  value: 4.294943e+08
+m01df6100/df-var/df_complex-used:
+  value: 4.588380e+08
+m01df6100/df-var/df_inodes-free:
+  value: 5.228090e+05
+m01df6100/df-var/df_inodes-reserved:
+  value: 0.000000e+00
+m01df6100/df-var/df_inodes-used:
+  value: 1.479000e+03
+m01df6100/df-var/percent_bytes-free:
+  value: 8.949355e+01
+m01df6100/df-var/percent_bytes-reserved:
+  value: 5.079695e+00
+m01df6100/df-var/percent_bytes-used:
+  value: 5.426748e+00
+m01df6100/df-var/percent_inodes-free:
+  value: 9.971790e+01
+m01df6100/df-var/percent_inodes-reserved:
+  value: 0.000000e+00
+m01df6100/df-var/percent_inodes-used:
+  value: 2.820969e-01
+m01df6100/disk-sda/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda1/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda1/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda1/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda1/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda2/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda2/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda2/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda2/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda3/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda3/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda3/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda3/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda4/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda4/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda4/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda4/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda5/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda5/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda5/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda5/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda6/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda6/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda6/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/disk-sda6/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6100/load/load:
+  longterm: 0.000000e+00
+  midterm: 2.000000e-02
+  shortterm: 3.000000e-02
+m01df6100/memory/memory-buffered:
+  value: 3.348275e+08
+m01df6100/memory/memory-cached:
+  value: 5.892219e+08
+m01df6100/memory/memory-free:
+  value: 6.425088e+10
+m01df6100/memory/memory-used:
+  value: 2.339246e+09
+m01df6100/network/if_octets:
+  rx: 0.000000e+00
+  tx: 1.057501e+03
+m01df6100/network/if_packets:
+  rx: 0.000000e+00
+  tx: 8.000004e-01
+m01df6100/network/queue_length:
+  value: 0.000000e+00
+m01df6100/network/total_values-dispatch-accepted:
+  value: 0.000000e+00
+m01df6100/network/total_values-dispatch-rejected:
+  value: 0.000000e+00
+m01df6100/network/total_values-send-accepted:
+  value: 1.929969e+01
+m01df6100/network/total_values-send-rejected:
+  value: 0.000000e+00
+m01df6100/swap/swap-cached:
+  value: 0.000000e+00
+m01df6100/swap/swap-free:
+  value: 2.147475e+09
+m01df6100/swap/swap-used:
+  value: 0.000000e+00
+m01df6100/swap/swap_io-in:
+  value: 0.000000e+00
+m01df6100/swap/swap_io-out:
+  value: 0.000000e+00
+m01df6100/vmem/vmpage_faults:
+  majflt: 0.000000e+00
+  minflt: 3.199662e+00
+m01df6100/vmem/vmpage_io-memory:
+  in: 0.000000e+00
+  out: 0.000000e+00
+m01df6100/vmem/vmpage_io-swap:
+  in: 0.000000e+00
+  out: 0.000000e+00
+m01df6100/vmem/vmpage_number-active_anon:
+  value: 2.152660e+05
+m01df6100/vmem/vmpage_number-active_file:
+  value: 1.507500e+05
+m01df6100/vmem/vmpage_number-anon_pages:
+  value: 1.456100e+04
+m01df6100/vmem/vmpage_number-anon_transparent_hugepages:
+  value: 3.920000e+02
+m01df6100/vmem/vmpage_number-boudfe:
+  value: 0.000000e+00
+m01df6100/vmem/vmpage_number-dirty:
+  value: 0.000000e+00
+m01df6100/vmem/vmpage_number-file_pages:
+  value: 2.255980e+05
+m01df6100/vmem/vmpage_number-free_pages:
+  value: 1.568625e+07
+m01df6100/vmem/vmpage_number-inactive_anon:
+  value: 4.600000e+01
+m01df6100/vmem/vmpage_number-inactive_file:
+  value: 7.480400e+04
+m01df6100/vmem/vmpage_number-isolated_anon:
+  value: 0.000000e+00
+m01df6100/vmem/vmpage_number-isolated_file:
+  value: 0.000000e+00
+m01df6100/vmem/vmpage_number-kernel_stack:
+  value: 4.500000e+02
+m01df6100/vmem/vmpage_number-mapped:
+  value: 3.560000e+03
+m01df6100/vmem/vmpage_number-mlock:
+  value: 0.000000e+00
+m01df6100/vmem/vmpage_number-page_table_pages:
+  value: 1.060000e+03
+m01df6100/vmem/vmpage_number-shmem:
+  value: 4.800000e+01
+m01df6100/vmem/vmpage_number-slab_reclaimable:
+  value: 2.369210e+05
+m01df6100/vmem/vmpage_number-slab_unreclaimable:
+  value: 1.479000e+04
+m01df6100/vmem/vmpage_number-unevictable:
+  value: 0.000000e+00
+m01df6100/vmem/vmpage_number-unstable:
+  value: 0.000000e+00
+m01df6100/vmem/vmpage_number-vmscan_write:
+  value: 0.000000e+00
+m01df6100/vmem/vmpage_number-writeback:
+  value: 0.000000e+00
+m01df6100/vmem/vmpage_number-writeback_temp:
+  value: 0.000000e+00
+m01df6200/cpu-0/cpu-idle:
+  value: 9.970372e+01
+m01df6200/cpu-0/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-0/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-0/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-0/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-0/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-0/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-0/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-1/cpu-idle:
+  value: 1.000038e+02
+m01df6200/cpu-1/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-1/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-1/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-1/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-1/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-1/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-1/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-10/cpu-idle:
+  value: 1.000043e+02
+m01df6200/cpu-10/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-10/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-10/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-10/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-10/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-10/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-10/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-11/cpu-idle:
+  value: 1.000045e+02
+m01df6200/cpu-11/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-11/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-11/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-11/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-11/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-11/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-11/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-12/cpu-idle:
+  value: 1.000044e+02
+m01df6200/cpu-12/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-12/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-12/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-12/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-12/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-12/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-12/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-13/cpu-idle:
+  value: 1.000045e+02
+m01df6200/cpu-13/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-13/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-13/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-13/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-13/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-13/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-13/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-14/cpu-idle:
+  value: 1.000044e+02
+m01df6200/cpu-14/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-14/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-14/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-14/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-14/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-14/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-14/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-15/cpu-idle:
+  value: 9.990450e+01
+m01df6200/cpu-15/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-15/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-15/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-15/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-15/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-15/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-15/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-16/cpu-idle:
+  value: 1.000046e+02
+m01df6200/cpu-16/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-16/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-16/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-16/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-16/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-16/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-16/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-17/cpu-idle:
+  value: 1.000047e+02
+m01df6200/cpu-17/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-17/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-17/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-17/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-17/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-17/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-17/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-18/cpu-idle:
+  value: 1.000047e+02
+m01df6200/cpu-18/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-18/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-18/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-18/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-18/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-18/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-18/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-19/cpu-idle:
+  value: 9.990492e+01
+m01df6200/cpu-19/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-19/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-19/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-19/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-19/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-19/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-19/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-2/cpu-idle:
+  value: 1.000038e+02
+m01df6200/cpu-2/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-2/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-2/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-2/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-2/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-2/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-2/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-20/cpu-idle:
+  value: 9.990475e+01
+m01df6200/cpu-20/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-20/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-20/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-20/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-20/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-20/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-20/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-21/cpu-idle:
+  value: 1.000048e+02
+m01df6200/cpu-21/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-21/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-21/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-21/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-21/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-21/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-21/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-22/cpu-idle:
+  value: 1.000049e+02
+m01df6200/cpu-22/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-22/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-22/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-22/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-22/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-22/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-22/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-23/cpu-idle:
+  value: 9.990458e+01
+m01df6200/cpu-23/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-23/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-23/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-23/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-23/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-23/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-23/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-3/cpu-idle:
+  value: 9.990383e+01
+m01df6200/cpu-3/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-3/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-3/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-3/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-3/cpu-system:
+  value: 1.000038e-01
+m01df6200/cpu-3/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-3/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-4/cpu-idle:
+  value: 1.000039e+02
+m01df6200/cpu-4/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-4/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-4/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-4/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-4/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-4/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-4/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-5/cpu-idle:
+  value: 1.000039e+02
+m01df6200/cpu-5/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-5/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-5/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-5/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-5/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-5/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-5/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-6/cpu-idle:
+  value: 1.000039e+02
+m01df6200/cpu-6/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-6/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-6/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-6/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-6/cpu-system:
+  value: 1.000039e-01
+m01df6200/cpu-6/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-6/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-7/cpu-idle:
+  value: 9.990388e+01
+m01df6200/cpu-7/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-7/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-7/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-7/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-7/cpu-system:
+  value: 1.000039e-01
+m01df6200/cpu-7/cpu-user:
+  value: 0.000000e+00
+m01df6200/cpu-7/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-8/cpu-idle:
+  value: 9.990408e+01
+m01df6200/cpu-8/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-8/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-8/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-8/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-8/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-8/cpu-user:
+  value: 1.000040e-01
+m01df6200/cpu-8/cpu-wait:
+  value: 0.000000e+00
+m01df6200/cpu-9/cpu-idle:
+  value: 1.000043e+02
+m01df6200/cpu-9/cpu-interrupt:
+  value: 0.000000e+00
+m01df6200/cpu-9/cpu-nice:
+  value: 0.000000e+00
+m01df6200/cpu-9/cpu-softirq:
+  value: 0.000000e+00
+m01df6200/cpu-9/cpu-steal:
+  value: 0.000000e+00
+m01df6200/cpu-9/cpu-system:
+  value: 0.000000e+00
+m01df6200/cpu-9/cpu-user:
+  value: 1.000043e-01
+m01df6200/cpu-9/cpu-wait:
+  value: 0.000000e+00
+m01df6200/df-boot/df_complex-free:
+  value: 4.368957e+08
+m01df6200/df-boot/df_complex-reserved:
+  value: 2.684109e+07
+m01df6200/df-boot/df_complex-used:
+  value: 6.468813e+07
+m01df6200/df-boot/df_inodes-free:
+  value: 3.271800e+04
+m01df6200/df-boot/df_inodes-reserved:
+  value: 0.000000e+00
+m01df6200/df-boot/df_inodes-used:
+  value: 5.000000e+01
+m01df6200/df-boot/percent_bytes-free:
+  value: 8.267886e+01
+m01df6200/df-boot/percent_bytes-reserved:
+  value: 5.079451e+00
+m01df6200/df-boot/percent_bytes-used:
+  value: 1.224169e+01
+m01df6200/df-boot/percent_inodes-free:
+  value: 9.984741e+01
+m01df6200/df-boot/percent_inodes-reserved:
+  value: 0.000000e+00
+m01df6200/df-boot/percent_inodes-used:
+  value: 1.525879e-01
+m01df6200/df-data1/df_complex-free:
+  value: 2.574203e+11
+m01df6200/df-data1/df_complex-reserved:
+  value: 1.378982e+10
+m01df6200/df-data1/df_complex-used:
+  value: 2.587075e+08
+m01df6200/df-data1/df_inodes-free:
+  value: 1.683427e+07
+m01df6200/df-data1/df_inodes-reserved:
+  value: 0.000000e+00
+m01df6200/df-data1/df_inodes-used:
+  value: 2.940000e+02
+m01df6200/df-data1/percent_bytes-free:
+  value: 9.482500e+01
+m01df6200/df-data1/percent_bytes-reserved:
+  value: 5.079707e+00
+m01df6200/df-data1/percent_bytes-used:
+  value: 9.529912e-02
+m01df6200/df-data1/percent_inodes-free:
+  value: 9.999825e+01
+m01df6200/df-data1/percent_inodes-reserved:
+  value: 0.000000e+00
+m01df6200/df-data1/percent_inodes-used:
+  value: 1.746407e-03
+m01df6200/df-dev-shm/df_complex-free:
+  value: 3.375709e+10
+m01df6200/df-dev-shm/df_complex-reserved:
+  value: 0.000000e+00
+m01df6200/df-dev-shm/df_complex-used:
+  value: 0.000000e+00
+m01df6200/df-dev-shm/df_inodes-free:
+  value: 8.241475e+06
+m01df6200/df-dev-shm/df_inodes-reserved:
+  value: 0.000000e+00
+m01df6200/df-dev-shm/df_inodes-used:
+  value: 1.000000e+00
+m01df6200/df-dev-shm/percent_bytes-free:
+  value: 1.000000e+02
+m01df6200/df-dev-shm/percent_bytes-reserved:
+  value: 0.000000e+00
+m01df6200/df-dev-shm/percent_bytes-used:
+  value: 0.000000e+00
+m01df6200/df-dev-shm/percent_inodes-free:
+  value: 9.999998e+01
+m01df6200/df-dev-shm/percent_inodes-reserved:
+  value: 0.000000e+00
+m01df6200/df-dev-shm/percent_inodes-used:
+  value: 1.213375e-05
+m01df6200/df-root/df_complex-free:
+  value: 1.073381e+10
+m01df6200/df-root/df_complex-reserved:
+  value: 6.442435e+08
+m01df6200/df-root/df_complex-used:
+  value: 1.304654e+09
+m01df6200/df-root/df_inodes-free:
+  value: 7.455060e+05
+m01df6200/df-root/df_inodes-reserved:
+  value: 0.000000e+00
+m01df6200/df-root/df_inodes-used:
+  value: 4.092600e+04
+m01df6200/df-root/percent_bytes-free:
+  value: 8.463343e+01
+m01df6200/df-root/percent_bytes-reserved:
+  value: 5.079700e+00
+m01df6200/df-root/percent_bytes-used:
+  value: 1.028687e+01
+m01df6200/df-root/percent_inodes-free:
+  value: 9.479599e+01
+m01df6200/df-root/percent_inodes-reserved:
+  value: 0.000000e+00
+m01df6200/df-root/percent_inodes-used:
+  value: 5.204010e+00
+m01df6200/df-var/df_complex-free:
+  value: 7.567528e+09
+m01df6200/df-var/df_complex-reserved:
+  value: 4.294943e+08
+m01df6200/df-var/df_complex-used:
+  value: 4.580966e+08
+m01df6200/df-var/df_inodes-free:
+  value: 5.228110e+05
+m01df6200/df-var/df_inodes-reserved:
+  value: 0.000000e+00
+m01df6200/df-var/df_inodes-used:
+  value: 1.477000e+03
+m01df6200/df-var/percent_bytes-free:
+  value: 8.950232e+01
+m01df6200/df-var/percent_bytes-reserved:
+  value: 5.079695e+00
+m01df6200/df-var/percent_bytes-used:
+  value: 5.417980e+00
+m01df6200/df-var/percent_inodes-free:
+  value: 9.971828e+01
+m01df6200/df-var/percent_inodes-reserved:
+  value: 0.000000e+00
+m01df6200/df-var/percent_inodes-used:
+  value: 2.817154e-01
+m01df6200/disk-sda/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda1/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda1/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda1/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda1/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda2/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda2/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda2/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda2/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda3/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda3/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda3/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda3/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda4/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda4/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda4/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda4/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda5/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda5/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda5/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda5/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda6/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda6/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda6/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/disk-sda6/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+m01df6200/load/load:
+  longterm: 0.000000e+00
+  midterm: 0.000000e+00
+  shortterm: 0.000000e+00
+m01df6200/memory/memory-buffered:
+  value: 3.312067e+08
+m01df6200/memory/memory-cached:
+  value: 5.615206e+08
+m01df6200/memory/memory-free:
+  value: 6.428290e+10
+m01df6200/memory/memory-used:
+  value: 2.338546e+09
+m01df6200/network/if_octets:
+  rx: 0.000000e+00
+  tx: 1.583300e+03
+m01df6200/network/if_packets:
+  rx: 0.000000e+00
+  tx: 1.200000e+00
+m01df6200/network/queue_length:
+  value: 0.000000e+00
+m01df6200/network/total_values-dispatch-accepted:
+  value: 0.000000e+00
+m01df6200/network/total_values-dispatch-rejected:
+  value: 0.000000e+00
+m01df6200/network/total_values-send-accepted:
+  value: 3.150000e+01
+m01df6200/network/total_values-send-rejected:
+  value: 0.000000e+00
+m01df6200/swap/swap-cached:
+  value: 0.000000e+00
+m01df6200/swap/swap-free:
+  value: 2.147475e+09
+m01df6200/swap/swap-used:
+  value: 0.000000e+00
+m01df6200/swap/swap_io-in:
+  value: 0.000000e+00
+m01df6200/swap/swap_io-out:
+  value: 0.000000e+00
+m01df6200/vmem/vmpage_faults:
+  majflt: 0.000000e+00
+  minflt: 3.600012e+00
+m01df6200/vmem/vmpage_io-memory:
+  in: 0.000000e+00
+  out: 0.000000e+00
+m01df6200/vmem/vmpage_io-swap:
+  in: 0.000000e+00
+  out: 0.000000e+00
+m01df6200/vmem/vmpage_number-active_anon:
+  value: 2.124650e+05
+m01df6200/vmem/vmpage_number-active_file:
+  value: 1.424970e+05
+m01df6200/vmem/vmpage_number-anon_pages:
+  value: 1.227400e+04
+m01df6200/vmem/vmpage_number-anon_transparent_hugepages:
+  value: 3.910000e+02
+m01df6200/vmem/vmpage_number-boudfe:
+  value: 0.000000e+00
+m01df6200/vmem/vmpage_number-dirty:
+  value: 0.000000e+00
+m01df6200/vmem/vmpage_number-file_pages:
+  value: 2.179510e+05
+m01df6200/vmem/vmpage_number-free_pages:
+  value: 1.569406e+07
+m01df6200/vmem/vmpage_number-inactive_anon:
+  value: 4.800000e+01
+m01df6200/vmem/vmpage_number-inactive_file:
+  value: 7.540800e+04
+m01df6200/vmem/vmpage_number-isolated_anon:
+  value: 0.000000e+00
+m01df6200/vmem/vmpage_number-isolated_file:
+  value: 0.000000e+00
+m01df6200/vmem/vmpage_number-kernel_stack:
+  value: 4.460000e+02
+m01df6200/vmem/vmpage_number-mapped:
+  value: 3.063000e+03
+m01df6200/vmem/vmpage_number-mlock:
+  value: 0.000000e+00
+m01df6200/vmem/vmpage_number-page_table_pages:
+  value: 8.920000e+02
+m01df6200/vmem/vmpage_number-shmem:
+  value: 5.000000e+01
+m01df6200/vmem/vmpage_number-slab_reclaimable:
+  value: 2.398380e+05
+m01df6200/vmem/vmpage_number-slab_unreclaimable:
+  value: 1.473600e+04
+m01df6200/vmem/vmpage_number-unevictable:
+  value: 0.000000e+00
+m01df6200/vmem/vmpage_number-unstable:
+  value: 0.000000e+00
+m01df6200/vmem/vmpage_number-vmscan_write:
+  value: 0.000000e+00
+m01df6200/vmem/vmpage_number-writeback:
+  value: 0.000000e+00
+m01df6200/vmem/vmpage_number-writeback_temp:
+  value: 0.000000e+00
+w838f6010/cpu-0/cpu-idle:
+  value: 9.990008e+01
+w838f6010/cpu-0/cpu-interrupt:
+  value: 0.000000e+00
+w838f6010/cpu-0/cpu-nice:
+  value: 0.000000e+00
+w838f6010/cpu-0/cpu-softirq:
+  value: 0.000000e+00
+w838f6010/cpu-0/cpu-steal:
+  value: 0.000000e+00
+w838f6010/cpu-0/cpu-system:
+  value: 0.000000e+00
+w838f6010/cpu-0/cpu-user:
+  value: 0.000000e+00
+w838f6010/cpu-0/cpu-wait:
+  value: 0.000000e+00
+w838f6010/cpu-1/cpu-idle:
+  value: 9.980017e+01
+w838f6010/cpu-1/cpu-interrupt:
+  value: 0.000000e+00
+w838f6010/cpu-1/cpu-nice:
+  value: 0.000000e+00
+w838f6010/cpu-1/cpu-softirq:
+  value: 0.000000e+00
+w838f6010/cpu-1/cpu-steal:
+  value: 0.000000e+00
+w838f6010/cpu-1/cpu-system:
+  value: 0.000000e+00
+w838f6010/cpu-1/cpu-user:
+  value: 0.000000e+00
+w838f6010/cpu-1/cpu-wait:
+  value: 0.000000e+00
+w838f6010/df-boot/df_complex-free:
+  value: 4.793754e+08
+w838f6010/df-boot/df_complex-reserved:
+  value: 2.684109e+07
+w838f6010/df-boot/df_complex-used:
+  value: 2.220851e+07
+w838f6010/df-boot/df_inodes-free:
+  value: 3.273000e+04
+w838f6010/df-boot/df_inodes-reserved:
+  value: 0.000000e+00
+w838f6010/df-boot/df_inodes-used:
+  value: 3.800000e+01
+w838f6010/df-boot/percent_bytes-free:
+  value: 9.071777e+01
+w838f6010/df-boot/percent_bytes-reserved:
+  value: 5.079451e+00
+w838f6010/df-boot/percent_bytes-used:
+  value: 4.202775e+00
+w838f6010/df-boot/percent_inodes-free:
+  value: 9.988403e+01
+w838f6010/df-boot/percent_inodes-reserved:
+  value: 0.000000e+00
+w838f6010/df-boot/percent_inodes-used:
+  value: 1.159668e-01
+w838f6010/df-data1/df_complex-free:
+  value: 2.740491e+10
+w838f6010/df-data1/df_complex-reserved:
+  value: 1.476235e+09
+w838f6010/df-data1/df_complex-used:
+  value: 1.802977e+08
+w838f6010/df-data1/df_inodes-free:
+  value: 1.802227e+06
+w838f6010/df-data1/df_inodes-reserved:
+  value: 0.000000e+00
+w838f6010/df-data1/df_inodes-used:
+  value: 1.300000e+01
+w838f6010/df-data1/percent_bytes-free:
+  value: 9.429990e+01
+w838f6010/df-data1/percent_bytes-reserved:
+  value: 5.079704e+00
+w838f6010/df-data1/percent_bytes-used:
+  value: 6.204019e-01
+w838f6010/df-data1/percent_inodes-free:
+  value: 9.999928e+01
+w838f6010/df-data1/percent_inodes-reserved:
+  value: 0.000000e+00
+w838f6010/df-data1/percent_inodes-used:
+  value: 7.213246e-04
+w838f6010/df-dev-shm/df_complex-free:
+  value: 9.842483e+08
+w838f6010/df-dev-shm/df_complex-reserved:
+  value: 0.000000e+00
+w838f6010/df-dev-shm/df_complex-used:
+  value: 0.000000e+00
+w838f6010/df-dev-shm/df_inodes-free:
+  value: 2.402940e+05
+w838f6010/df-dev-shm/df_inodes-reserved:
+  value: 0.000000e+00
+w838f6010/df-dev-shm/df_inodes-used:
+  value: 1.000000e+00
+w838f6010/df-dev-shm/percent_bytes-free:
+  value: 1.000000e+02
+w838f6010/df-dev-shm/percent_bytes-reserved:
+  value: 0.000000e+00
+w838f6010/df-dev-shm/percent_bytes-used:
+  value: 0.000000e+00
+w838f6010/df-dev-shm/percent_inodes-free:
+  value: 9.999958e+01
+w838f6010/df-dev-shm/percent_inodes-reserved:
+  value: 0.000000e+00
+w838f6010/df-dev-shm/percent_inodes-used:
+  value: 4.161551e-04
+w838f6010/df-root/df_complex-free:
+  value: 1.099070e+10
+w838f6010/df-root/df_complex-reserved:
+  value: 6.442435e+08
+w838f6010/df-root/df_complex-used:
+  value: 1.047761e+09
+w838f6010/df-root/df_inodes-free:
+  value: 7.509290e+05
+w838f6010/df-root/df_inodes-reserved:
+  value: 0.000000e+00
+w838f6010/df-root/df_inodes-used:
+  value: 3.550300e+04
+w838f6010/df-root/percent_bytes-free:
+  value: 8.665897e+01
+w838f6010/df-root/percent_bytes-reserved:
+  value: 5.079700e+00
+w838f6010/df-root/percent_bytes-used:
+  value: 8.261335e+00
+w838f6010/df-root/percent_inodes-free:
+  value: 9.548557e+01
+w838f6010/df-root/percent_inodes-reserved:
+  value: 0.000000e+00
+w838f6010/df-root/percent_inodes-used:
+  value: 4.514440e+00
+w838f6010/df-var/df_complex-free:
+  value: 7.638827e+09
+w838f6010/df-var/df_complex-reserved:
+  value: 4.294943e+08
+w838f6010/df-var/df_complex-used:
+  value: 3.867976e+08
+w838f6010/df-var/df_inodes-free:
+  value: 5.230900e+05
+w838f6010/df-var/df_inodes-reserved:
+  value: 0.000000e+00
+w838f6010/df-var/df_inodes-used:
+  value: 1.198000e+03
+w838f6010/df-var/percent_bytes-free:
+  value: 9.034559e+01
+w838f6010/df-var/percent_bytes-reserved:
+  value: 5.079695e+00
+w838f6010/df-var/percent_bytes-used:
+  value: 4.574715e+00
+w838f6010/df-var/percent_inodes-free:
+  value: 9.977150e+01
+w838f6010/df-var/percent_inodes-reserved:
+  value: 0.000000e+00
+w838f6010/df-var/percent_inodes-used:
+  value: 2.285004e-01
+w838f6010/disk-vda/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda1/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda1/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda1/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda1/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda2/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda2/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda2/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda2/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda3/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda3/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda3/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda3/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda4/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda4/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda4/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda4/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda5/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda5/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda5/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda5/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda6/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda6/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda6/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/disk-vda6/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6010/load/load:
+  longterm: 0.000000e+00
+  midterm: 2.000000e-02
+  shortterm: 2.000000e-02
+w838f6010/memory/memory-buffered:
+  value: 1.263739e+08
+w838f6010/memory/memory-cached:
+  value: 4.350566e+08
+w838f6010/memory/memory-free:
+  value: 1.024844e+09
+w838f6010/memory/memory-used:
+  value: 3.822223e+08
+w838f6010/network/if_octets:
+  rx: 0.000000e+00
+  tx: 6.632999e+02
+w838f6010/network/if_packets:
+  rx: 0.000000e+00
+  tx: 5.000010e-01
+w838f6010/network/queue_length:
+  value: 0.000000e+00
+w838f6010/network/total_values-dispatch-accepted:
+  value: 0.000000e+00
+w838f6010/network/total_values-dispatch-rejected:
+  value: 0.000000e+00
+w838f6010/network/total_values-send-accepted:
+  value: 1.480000e+01
+w838f6010/network/total_values-send-rejected:
+  value: 0.000000e+00
+w838f6010/swap/swap-cached:
+  value: 0.000000e+00
+w838f6010/swap/swap-free:
+  value: 2.147475e+09
+w838f6010/swap/swap-used:
+  value: 0.000000e+00
+w838f6010/swap/swap_io-in:
+  value: 0.000000e+00
+w838f6010/swap/swap_io-out:
+  value: 0.000000e+00
+w838f6010/vmem/vmpage_faults:
+  majflt: 0.000000e+00
+  minflt: 4.999995e+00
+w838f6010/vmem/vmpage_io-memory:
+  in: 0.000000e+00
+  out: 0.000000e+00
+w838f6010/vmem/vmpage_io-swap:
+  in: 0.000000e+00
+  out: 0.000000e+00
+w838f6010/vmem/vmpage_number-active_anon:
+  value: 1.249400e+04
+w838f6010/vmem/vmpage_number-active_file:
+  value: 7.016800e+04
+w838f6010/vmem/vmpage_number-anon_pages:
+  value: 1.095500e+04
+w838f6010/vmem/vmpage_number-anon_transparent_hugepages:
+  value: 3.000000e+00
+w838f6010/vmem/vmpage_number-boudfe:
+  value: 0.000000e+00
+w838f6010/vmem/vmpage_number-dirty:
+  value: 0.000000e+00
+w838f6010/vmem/vmpage_number-file_pages:
+  value: 1.370680e+05
+w838f6010/vmem/vmpage_number-free_pages:
+  value: 2.502060e+05
+w838f6010/vmem/vmpage_number-inactive_anon:
+  value: 4.200000e+01
+w838f6010/vmem/vmpage_number-inactive_file:
+  value: 6.685900e+04
+w838f6010/vmem/vmpage_number-isolated_anon:
+  value: 0.000000e+00
+w838f6010/vmem/vmpage_number-isolated_file:
+  value: 0.000000e+00
+w838f6010/vmem/vmpage_number-kernel_stack:
+  value: 1.130000e+02
+w838f6010/vmem/vmpage_number-mapped:
+  value: 1.480000e+03
+w838f6010/vmem/vmpage_number-mlock:
+  value: 0.000000e+00
+w838f6010/vmem/vmpage_number-page_table_pages:
+  value: 4.220000e+02
+w838f6010/vmem/vmpage_number-shmem:
+  value: 4.500000e+01
+w838f6010/vmem/vmpage_number-slab_reclaimable:
+  value: 6.896900e+04
+w838f6010/vmem/vmpage_number-slab_unreclaimable:
+  value: 5.190000e+03
+w838f6010/vmem/vmpage_number-unevictable:
+  value: 0.000000e+00
+w838f6010/vmem/vmpage_number-unstable:
+  value: 0.000000e+00
+w838f6010/vmem/vmpage_number-vmscan_write:
+  value: 0.000000e+00
+w838f6010/vmem/vmpage_number-writeback:
+  value: 0.000000e+00
+w838f6010/vmem/vmpage_number-writeback_temp:
+  value: 0.000000e+00
+w838f6700/cpu-0/cpu-idle:
+  value: 9.619931e+01
+w838f6700/cpu-0/cpu-interrupt:
+  value: 0.000000e+00
+w838f6700/cpu-0/cpu-nice:
+  value: 0.000000e+00
+w838f6700/cpu-0/cpu-softirq:
+  value: 0.000000e+00
+w838f6700/cpu-0/cpu-steal:
+  value: 0.000000e+00
+w838f6700/cpu-0/cpu-system:
+  value: 1.899992e+00
+w838f6700/cpu-0/cpu-user:
+  value: 1.600000e+00
+w838f6700/cpu-0/cpu-wait:
+  value: 0.000000e+00
+w838f6700/cpu-1/cpu-idle:
+  value: 9.599589e+01
+w838f6700/cpu-1/cpu-interrupt:
+  value: 0.000000e+00
+w838f6700/cpu-1/cpu-nice:
+  value: 0.000000e+00
+w838f6700/cpu-1/cpu-softirq:
+  value: 0.000000e+00
+w838f6700/cpu-1/cpu-steal:
+  value: 0.000000e+00
+w838f6700/cpu-1/cpu-system:
+  value: 1.799923e+00
+w838f6700/cpu-1/cpu-user:
+  value: 1.799919e+00
+w838f6700/cpu-1/cpu-wait:
+  value: 0.000000e+00
+w838f6700/cpu-2/cpu-idle:
+  value: 9.539595e+01
+w838f6700/cpu-2/cpu-interrupt:
+  value: 0.000000e+00
+w838f6700/cpu-2/cpu-nice:
+  value: 0.000000e+00
+w838f6700/cpu-2/cpu-softirq:
+  value: 0.000000e+00
+w838f6700/cpu-2/cpu-steal:
+  value: 9.999593e-02
+w838f6700/cpu-2/cpu-system:
+  value: 2.299903e+00
+w838f6700/cpu-2/cpu-user:
+  value: 1.899919e+00
+w838f6700/cpu-2/cpu-wait:
+  value: 0.000000e+00
+w838f6700/cpu-3/cpu-idle:
+  value: 9.439610e+01
+w838f6700/cpu-3/cpu-interrupt:
+  value: 0.000000e+00
+w838f6700/cpu-3/cpu-nice:
+  value: 0.000000e+00
+w838f6700/cpu-3/cpu-softirq:
+  value: 0.000000e+00
+w838f6700/cpu-3/cpu-steal:
+  value: 0.000000e+00
+w838f6700/cpu-3/cpu-system:
+  value: 2.699890e+00
+w838f6700/cpu-3/cpu-user:
+  value: 2.599893e+00
+w838f6700/cpu-3/cpu-wait:
+  value: 0.000000e+00
+w838f6700/df-boot/df_complex-free:
+  value: 4.793713e+08
+w838f6700/df-boot/df_complex-reserved:
+  value: 2.684109e+07
+w838f6700/df-boot/df_complex-used:
+  value: 2.221261e+07
+w838f6700/df-boot/df_inodes-free:
+  value: 3.273000e+04
+w838f6700/df-boot/df_inodes-reserved:
+  value: 0.000000e+00
+w838f6700/df-boot/df_inodes-used:
+  value: 3.800000e+01
+w838f6700/df-boot/percent_bytes-free:
+  value: 9.071700e+01
+w838f6700/df-boot/percent_bytes-reserved:
+  value: 5.079451e+00
+w838f6700/df-boot/percent_bytes-used:
+  value: 4.203550e+00
+w838f6700/df-boot/percent_inodes-free:
+  value: 9.988403e+01
+w838f6700/df-boot/percent_inodes-reserved:
+  value: 0.000000e+00
+w838f6700/df-boot/percent_inodes-used:
+  value: 1.159668e-01
+w838f6700/df-data1/df_complex-free:
+  value: 2.740491e+10
+w838f6700/df-data1/df_complex-reserved:
+  value: 1.476235e+09
+w838f6700/df-data1/df_complex-used:
+  value: 1.802977e+08
+w838f6700/df-data1/df_inodes-free:
+  value: 1.802227e+06
+w838f6700/df-data1/df_inodes-reserved:
+  value: 0.000000e+00
+w838f6700/df-data1/df_inodes-used:
+  value: 1.300000e+01
+w838f6700/df-data1/percent_bytes-free:
+  value: 9.429990e+01
+w838f6700/df-data1/percent_bytes-reserved:
+  value: 5.079704e+00
+w838f6700/df-data1/percent_bytes-used:
+  value: 6.204019e-01
+w838f6700/df-data1/percent_inodes-free:
+  value: 9.999928e+01
+w838f6700/df-data1/percent_inodes-reserved:
+  value: 0.000000e+00
+w838f6700/df-data1/percent_inodes-used:
+  value: 7.213246e-04
+w838f6700/df-dev-shm/df_complex-free:
+  value: 4.126425e+09
+w838f6700/df-dev-shm/df_complex-reserved:
+  value: 0.000000e+00
+w838f6700/df-dev-shm/df_complex-used:
+  value: 0.000000e+00
+w838f6700/df-dev-shm/df_inodes-free:
+  value: 1.007427e+06
+w838f6700/df-dev-shm/df_inodes-reserved:
+  value: 0.000000e+00
+w838f6700/df-dev-shm/df_inodes-used:
+  value: 1.000000e+00
+w838f6700/df-dev-shm/percent_bytes-free:
+  value: 1.000000e+02
+w838f6700/df-dev-shm/percent_bytes-reserved:
+  value: 0.000000e+00
+w838f6700/df-dev-shm/percent_bytes-used:
+  value: 0.000000e+00
+w838f6700/df-dev-shm/percent_inodes-free:
+  value: 9.999990e+01
+w838f6700/df-dev-shm/percent_inodes-reserved:
+  value: 0.000000e+00
+w838f6700/df-dev-shm/percent_inodes-used:
+  value: 9.926267e-05
+w838f6700/df-root/df_complex-free:
+  value: 1.069915e+10
+w838f6700/df-root/df_complex-reserved:
+  value: 6.442435e+08
+w838f6700/df-root/df_complex-used:
+  value: 1.339314e+09
+w838f6700/df-root/df_inodes-free:
+  value: 7.466750e+05
+w838f6700/df-root/df_inodes-reserved:
+  value: 0.000000e+00
+w838f6700/df-root/df_inodes-used:
+  value: 3.975700e+04
+w838f6700/df-root/percent_bytes-free:
+  value: 8.436014e+01
+w838f6700/df-root/percent_bytes-reserved:
+  value: 5.079700e+00
+w838f6700/df-root/percent_bytes-used:
+  value: 1.056016e+01
+w838f6700/df-root/percent_inodes-free:
+  value: 9.494464e+01
+w838f6700/df-root/percent_inodes-reserved:
+  value: 0.000000e+00
+w838f6700/df-root/percent_inodes-used:
+  value: 5.055364e+00
+w838f6700/df-var/df_complex-free:
+  value: 6.687375e+09
+w838f6700/df-var/df_complex-reserved:
+  value: 4.294943e+08
+w838f6700/df-var/df_complex-used:
+  value: 1.338249e+09
+w838f6700/df-var/df_inodes-free:
+  value: 5.212840e+05
+w838f6700/df-var/df_inodes-reserved:
+  value: 0.000000e+00
+w838f6700/df-var/df_inodes-used:
+  value: 3.004000e+03
+w838f6700/df-var/percent_bytes-free:
+  value: 7.909262e+01
+w838f6700/df-var/percent_bytes-reserved:
+  value: 5.079695e+00
+w838f6700/df-var/percent_bytes-used:
+  value: 1.582768e+01
+w838f6700/df-var/percent_inodes-free:
+  value: 9.942703e+01
+w838f6700/df-var/percent_inodes-reserved:
+  value: 0.000000e+00
+w838f6700/df-var/percent_inodes-used:
+  value: 5.729675e-01
+w838f6700/disk-vda/disk_merged:
+  read: 0.000000e+00
+  write: 1.000002e-01
+w838f6700/disk-vda/disk_octets:
+  read: 0.000000e+00
+  write: 2.457603e+03
+w838f6700/disk-vda/disk_ops:
+  read: 0.000000e+00
+  write: 5.000007e-01
+w838f6700/disk-vda/disk_time:
+  read: 0.000000e+00
+  write: 1.200001e+00
+w838f6700/disk-vda1/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6700/disk-vda1/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6700/disk-vda1/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6700/disk-vda1/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6700/disk-vda2/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6700/disk-vda2/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6700/disk-vda2/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6700/disk-vda2/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6700/disk-vda3/disk_merged:
+  read: 0.000000e+00
+  write: 1.000001e-01
+w838f6700/disk-vda3/disk_octets:
+  read: 0.000000e+00
+  write: 2.457604e+03
+w838f6700/disk-vda3/disk_ops:
+  read: 0.000000e+00
+  write: 5.000007e-01
+w838f6700/disk-vda3/disk_time:
+  read: 0.000000e+00
+  write: 1.200002e+00
+w838f6700/disk-vda4/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6700/disk-vda4/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6700/disk-vda4/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6700/disk-vda4/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6700/disk-vda5/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6700/disk-vda5/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6700/disk-vda5/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6700/disk-vda5/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6700/disk-vda6/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6700/disk-vda6/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6700/disk-vda6/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6700/disk-vda6/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6700/load/load:
+  longterm: 2.000000e-02
+  midterm: 4.000000e-02
+  shortterm: 0.000000e+00
+w838f6700/memory/memory-buffered:
+  value: 1.980662e+08
+w838f6700/memory/memory-cached:
+  value: 1.702576e+09
+w838f6700/memory/memory-free:
+  value: 4.717773e+09
+w838f6700/memory/memory-used:
+  value: 1.634439e+09
+w838f6700/network/if_octets:
+  rx: 0.000000e+00
+  tx: 9.293005e+02
+w838f6700/network/if_packets:
+  rx: 0.000000e+00
+  tx: 7.000008e-01
+w838f6700/network/queue_length:
+  value: 0.000000e+00
+w838f6700/network/total_values-dispatch-accepted:
+  value: 0.000000e+00
+w838f6700/network/total_values-dispatch-rejected:
+  value: 0.000000e+00
+w838f6700/network/total_values-send-accepted:
+  value: 1.640000e+01
+w838f6700/network/total_values-send-rejected:
+  value: 0.000000e+00
+w838f6700/swap/swap-cached:
+  value: 0.000000e+00
+w838f6700/swap/swap-free:
+  value: 2.147475e+09
+w838f6700/swap/swap-used:
+  value: 0.000000e+00
+w838f6700/swap/swap_io-in:
+  value: 0.000000e+00
+w838f6700/swap/swap_io-out:
+  value: 0.000000e+00
+w838f6700/vmem/vmpage_faults:
+  majflt: 0.000000e+00
+  minflt: 2.519992e+01
+w838f6700/vmem/vmpage_io-memory:
+  in: 0.000000e+00
+  out: 1.999993e+00
+w838f6700/vmem/vmpage_io-swap:
+  in: 0.000000e+00
+  out: 0.000000e+00
+w838f6700/vmem/vmpage_number-active_anon:
+  value: 2.680560e+05
+w838f6700/vmem/vmpage_number-active_file:
+  value: 1.344860e+05
+w838f6700/vmem/vmpage_number-anon_pages:
+  value: 1.661620e+05
+w838f6700/vmem/vmpage_number-anon_transparent_hugepages:
+  value: 1.990000e+02
+w838f6700/vmem/vmpage_number-boudfe:
+  value: 0.000000e+00
+w838f6700/vmem/vmpage_number-dirty:
+  value: 6.000000e+00
+w838f6700/vmem/vmpage_number-file_pages:
+  value: 4.640230e+05
+w838f6700/vmem/vmpage_number-free_pages:
+  value: 1.151800e+06
+w838f6700/vmem/vmpage_number-inactive_anon:
+  value: 6.300000e+01
+w838f6700/vmem/vmpage_number-inactive_file:
+  value: 3.294730e+05
+w838f6700/vmem/vmpage_number-isolated_anon:
+  value: 0.000000e+00
+w838f6700/vmem/vmpage_number-isolated_file:
+  value: 0.000000e+00
+w838f6700/vmem/vmpage_number-kernel_stack:
+  value: 2.060000e+02
+w838f6700/vmem/vmpage_number-mapped:
+  value: 7.423000e+03
+w838f6700/vmem/vmpage_number-mlock:
+  value: 0.000000e+00
+w838f6700/vmem/vmpage_number-page_table_pages:
+  value: 2.612000e+03
+w838f6700/vmem/vmpage_number-shmem:
+  value: 6.900000e+01
+w838f6700/vmem/vmpage_number-slab_reclaimable:
+  value: 1.048400e+05
+w838f6700/vmem/vmpage_number-slab_unreclaimable:
+  value: 6.180000e+03
+w838f6700/vmem/vmpage_number-unevictable:
+  value: 0.000000e+00
+w838f6700/vmem/vmpage_number-unstable:
+  value: 0.000000e+00
+w838f6700/vmem/vmpage_number-vmscan_write:
+  value: 0.000000e+00
+w838f6700/vmem/vmpage_number-writeback:
+  value: 0.000000e+00
+w838f6700/vmem/vmpage_number-writeback_temp:
+  value: 0.000000e+00
+w838f6800/cpu-0/cpu-idle:
+  value: 1.000001e+02
+w838f6800/cpu-0/cpu-interrupt:
+  value: 0.000000e+00
+w838f6800/cpu-0/cpu-nice:
+  value: 0.000000e+00
+w838f6800/cpu-0/cpu-softirq:
+  value: 0.000000e+00
+w838f6800/cpu-0/cpu-steal:
+  value: 0.000000e+00
+w838f6800/cpu-0/cpu-system:
+  value: 0.000000e+00
+w838f6800/cpu-0/cpu-user:
+  value: 0.000000e+00
+w838f6800/cpu-0/cpu-wait:
+  value: 0.000000e+00
+w838f6800/cpu-1/cpu-idle:
+  value: 9.989984e+01
+w838f6800/cpu-1/cpu-interrupt:
+  value: 0.000000e+00
+w838f6800/cpu-1/cpu-nice:
+  value: 0.000000e+00
+w838f6800/cpu-1/cpu-softirq:
+  value: 0.000000e+00
+w838f6800/cpu-1/cpu-steal:
+  value: 0.000000e+00
+w838f6800/cpu-1/cpu-system:
+  value: 0.000000e+00
+w838f6800/cpu-1/cpu-user:
+  value: 0.000000e+00
+w838f6800/cpu-1/cpu-wait:
+  value: 0.000000e+00
+w838f6800/cpu-2/cpu-idle:
+  value: 9.989981e+01
+w838f6800/cpu-2/cpu-interrupt:
+  value: 0.000000e+00
+w838f6800/cpu-2/cpu-nice:
+  value: 0.000000e+00
+w838f6800/cpu-2/cpu-softirq:
+  value: 0.000000e+00
+w838f6800/cpu-2/cpu-steal:
+  value: 0.000000e+00
+w838f6800/cpu-2/cpu-system:
+  value: 0.000000e+00
+w838f6800/cpu-2/cpu-user:
+  value: 0.000000e+00
+w838f6800/cpu-2/cpu-wait:
+  value: 0.000000e+00
+w838f6800/cpu-3/cpu-idle:
+  value: 9.989982e+01
+w838f6800/cpu-3/cpu-interrupt:
+  value: 0.000000e+00
+w838f6800/cpu-3/cpu-nice:
+  value: 0.000000e+00
+w838f6800/cpu-3/cpu-softirq:
+  value: 0.000000e+00
+w838f6800/cpu-3/cpu-steal:
+  value: 0.000000e+00
+w838f6800/cpu-3/cpu-system:
+  value: 0.000000e+00
+w838f6800/cpu-3/cpu-user:
+  value: 0.000000e+00
+w838f6800/cpu-3/cpu-wait:
+  value: 0.000000e+00
+w838f6800/df-boot/df_complex-free:
+  value: 4.793917e+08
+w838f6800/df-boot/df_complex-reserved:
+  value: 2.684109e+07
+w838f6800/df-boot/df_complex-used:
+  value: 2.219213e+07
+w838f6800/df-boot/df_inodes-free:
+  value: 3.273000e+04
+w838f6800/df-boot/df_inodes-reserved:
+  value: 0.000000e+00
+w838f6800/df-boot/df_inodes-used:
+  value: 3.800000e+01
+w838f6800/df-boot/percent_bytes-free:
+  value: 9.072087e+01
+w838f6800/df-boot/percent_bytes-reserved:
+  value: 5.079451e+00
+w838f6800/df-boot/percent_bytes-used:
+  value: 4.199674e+00
+w838f6800/df-boot/percent_inodes-free:
+  value: 9.988403e+01
+w838f6800/df-boot/percent_inodes-reserved:
+  value: 0.000000e+00
+w838f6800/df-boot/percent_inodes-used:
+  value: 1.159668e-01
+w838f6800/df-data1/df_complex-free:
+  value: 2.740491e+10
+w838f6800/df-data1/df_complex-reserved:
+  value: 1.476235e+09
+w838f6800/df-data1/df_complex-used:
+  value: 1.802977e+08
+w838f6800/df-data1/df_inodes-free:
+  value: 1.802227e+06
+w838f6800/df-data1/df_inodes-reserved:
+  value: 0.000000e+00
+w838f6800/df-data1/df_inodes-used:
+  value: 1.300000e+01
+w838f6800/df-data1/percent_bytes-free:
+  value: 9.429990e+01
+w838f6800/df-data1/percent_bytes-reserved:
+  value: 5.079704e+00
+w838f6800/df-data1/percent_bytes-used:
+  value: 6.204019e-01
+w838f6800/df-data1/percent_inodes-free:
+  value: 9.999928e+01
+w838f6800/df-data1/percent_inodes-reserved:
+  value: 0.000000e+00
+w838f6800/df-data1/percent_inodes-used:
+  value: 7.213246e-04
+w838f6800/df-dev-shm/df_complex-free:
+  value: 4.126425e+09
+w838f6800/df-dev-shm/df_complex-reserved:
+  value: 0.000000e+00
+w838f6800/df-dev-shm/df_complex-used:
+  value: 0.000000e+00
+w838f6800/df-dev-shm/df_inodes-free:
+  value: 1.007427e+06
+w838f6800/df-dev-shm/df_inodes-reserved:
+  value: 0.000000e+00
+w838f6800/df-dev-shm/df_inodes-used:
+  value: 1.000000e+00
+w838f6800/df-dev-shm/percent_bytes-free:
+  value: 1.000000e+02
+w838f6800/df-dev-shm/percent_bytes-reserved:
+  value: 0.000000e+00
+w838f6800/df-dev-shm/percent_bytes-used:
+  value: 0.000000e+00
+w838f6800/df-dev-shm/percent_inodes-free:
+  value: 9.999990e+01
+w838f6800/df-dev-shm/percent_inodes-reserved:
+  value: 0.000000e+00
+w838f6800/df-dev-shm/percent_inodes-used:
+  value: 9.926267e-05
+w838f6800/df-root/df_complex-free:
+  value: 1.099071e+10
+w838f6800/df-root/df_complex-reserved:
+  value: 6.442435e+08
+w838f6800/df-root/df_complex-used:
+  value: 1.047757e+09
+w838f6800/df-root/df_inodes-free:
+  value: 7.509280e+05
+w838f6800/df-root/df_inodes-reserved:
+  value: 0.000000e+00
+w838f6800/df-root/df_inodes-used:
+  value: 3.550400e+04
+w838f6800/df-root/percent_bytes-free:
+  value: 8.665900e+01
+w838f6800/df-root/percent_bytes-reserved:
+  value: 5.079700e+00
+w838f6800/df-root/percent_bytes-used:
+  value: 8.261303e+00
+w838f6800/df-root/percent_inodes-free:
+  value: 9.548543e+01
+w838f6800/df-root/percent_inodes-reserved:
+  value: 0.000000e+00
+w838f6800/df-root/percent_inodes-used:
+  value: 4.514567e+00
+w838f6800/df-var/df_complex-free:
+  value: 7.635927e+09
+w838f6800/df-var/df_complex-reserved:
+  value: 4.294943e+08
+w838f6800/df-var/df_complex-used:
+  value: 3.896975e+08
+w838f6800/df-var/df_inodes-free:
+  value: 5.230400e+05
+w838f6800/df-var/df_inodes-reserved:
+  value: 0.000000e+00
+w838f6800/df-var/df_inodes-used:
+  value: 1.248000e+03
+w838f6800/df-var/percent_bytes-free:
+  value: 9.031129e+01
+w838f6800/df-var/percent_bytes-reserved:
+  value: 5.079695e+00
+w838f6800/df-var/percent_bytes-used:
+  value: 4.609013e+00
+w838f6800/df-var/percent_inodes-free:
+  value: 9.976196e+01
+w838f6800/df-var/percent_inodes-reserved:
+  value: 0.000000e+00
+w838f6800/df-var/percent_inodes-used:
+  value: 2.380371e-01
+w838f6800/disk-vda/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda1/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda1/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda1/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda1/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda2/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda2/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda2/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda2/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda3/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda3/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda3/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda3/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda4/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda4/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda4/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda4/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda5/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda5/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda5/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda5/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda6/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda6/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda6/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/disk-vda6/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6800/load/load:
+  longterm: 0.000000e+00
+  midterm: 0.000000e+00
+  shortterm: 0.000000e+00
+w838f6800/memory/memory-buffered:
+  value: 1.443430e+08
+w838f6800/memory/memory-cached:
+  value: 4.507607e+08
+w838f6800/memory/memory-free:
+  value: 7.122756e+09
+w838f6800/memory/memory-used:
+  value: 5.349949e+08
+w838f6800/network/if_octets:
+  rx: 0.000000e+00
+  tx: 7.896001e+02
+w838f6800/network/if_packets:
+  rx: 0.000000e+00
+  tx: 6.000121e-01
+w838f6800/network/queue_length:
+  value: 0.000000e+00
+w838f6800/network/total_values-dispatch-accepted:
+  value: 0.000000e+00
+w838f6800/network/total_values-dispatch-rejected:
+  value: 0.000000e+00
+w838f6800/network/total_values-send-accepted:
+  value: 1.530036e+01
+w838f6800/network/total_values-send-rejected:
+  value: 0.000000e+00
+w838f6800/swap/swap-cached:
+  value: 0.000000e+00
+w838f6800/swap/swap-free:
+  value: 2.147475e+09
+w838f6800/swap/swap-used:
+  value: 0.000000e+00
+w838f6800/swap/swap_io-in:
+  value: 0.000000e+00
+w838f6800/swap/swap_io-out:
+  value: 0.000000e+00
+w838f6800/vmem/vmpage_faults:
+  majflt: 0.000000e+00
+  minflt: 4.500056e+00
+w838f6800/vmem/vmpage_io-memory:
+  in: 0.000000e+00
+  out: 0.000000e+00
+w838f6800/vmem/vmpage_io-swap:
+  in: 0.000000e+00
+  out: 0.000000e+00
+w838f6800/vmem/vmpage_number-active_anon:
+  value: 1.298400e+04
+w838f6800/vmem/vmpage_number-active_file:
+  value: 7.437200e+04
+w838f6800/vmem/vmpage_number-anon_pages:
+  value: 1.042100e+04
+w838f6800/vmem/vmpage_number-anon_transparent_hugepages:
+  value: 5.000000e+00
+w838f6800/vmem/vmpage_number-boudfe:
+  value: 0.000000e+00
+w838f6800/vmem/vmpage_number-dirty:
+  value: 0.000000e+00
+w838f6800/vmem/vmpage_number-file_pages:
+  value: 1.452890e+05
+w838f6800/vmem/vmpage_number-free_pages:
+  value: 1.738954e+06
+w838f6800/vmem/vmpage_number-inactive_anon:
+  value: 4.200000e+01
+w838f6800/vmem/vmpage_number-inactive_file:
+  value: 7.087600e+04
+w838f6800/vmem/vmpage_number-isolated_anon:
+  value: 0.000000e+00
+w838f6800/vmem/vmpage_number-isolated_file:
+  value: 0.000000e+00
+w838f6800/vmem/vmpage_number-kernel_stack:
+  value: 1.390000e+02
+w838f6800/vmem/vmpage_number-mapped:
+  value: 1.478000e+03
+w838f6800/vmem/vmpage_number-mlock:
+  value: 0.000000e+00
+w838f6800/vmem/vmpage_number-page_table_pages:
+  value: 4.100000e+02
+w838f6800/vmem/vmpage_number-shmem:
+  value: 4.500000e+01
+w838f6800/vmem/vmpage_number-slab_reclaimable:
+  value: 9.488500e+04
+w838f6800/vmem/vmpage_number-slab_unreclaimable:
+  value: 5.513000e+03
+w838f6800/vmem/vmpage_number-unevictable:
+  value: 0.000000e+00
+w838f6800/vmem/vmpage_number-unstable:
+  value: 0.000000e+00
+w838f6800/vmem/vmpage_number-vmscan_write:
+  value: 0.000000e+00
+w838f6800/vmem/vmpage_number-writeback:
+  value: 0.000000e+00
+w838f6800/vmem/vmpage_number-writeback_temp:
+  value: 0.000000e+00
+w838f6900/cpu-0/cpu-idle:
+  value: 9.700088e+01
+w838f6900/cpu-0/cpu-interrupt:
+  value: 0.000000e+00
+w838f6900/cpu-0/cpu-nice:
+  value: 0.000000e+00
+w838f6900/cpu-0/cpu-softirq:
+  value: 0.000000e+00
+w838f6900/cpu-0/cpu-steal:
+  value: 0.000000e+00
+w838f6900/cpu-0/cpu-system:
+  value: 1.000009e-01
+w838f6900/cpu-0/cpu-user:
+  value: 2.900025e+00
+w838f6900/cpu-0/cpu-wait:
+  value: 0.000000e+00
+w838f6900/cpu-1/cpu-idle:
+  value: 9.960079e+01
+w838f6900/cpu-1/cpu-interrupt:
+  value: 0.000000e+00
+w838f6900/cpu-1/cpu-nice:
+  value: 0.000000e+00
+w838f6900/cpu-1/cpu-softirq:
+  value: 0.000000e+00
+w838f6900/cpu-1/cpu-steal:
+  value: 0.000000e+00
+w838f6900/cpu-1/cpu-system:
+  value: 0.000000e+00
+w838f6900/cpu-1/cpu-user:
+  value: 0.000000e+00
+w838f6900/cpu-1/cpu-wait:
+  value: 0.000000e+00
+w838f6900/df-boot/df_complex-free:
+  value: 4.793836e+08
+w838f6900/df-boot/df_complex-reserved:
+  value: 2.684109e+07
+w838f6900/df-boot/df_complex-used:
+  value: 2.220032e+07
+w838f6900/df-boot/df_inodes-free:
+  value: 3.273000e+04
+w838f6900/df-boot/df_inodes-reserved:
+  value: 0.000000e+00
+w838f6900/df-boot/df_inodes-used:
+  value: 3.800000e+01
+w838f6900/df-boot/percent_bytes-free:
+  value: 9.071932e+01
+w838f6900/df-boot/percent_bytes-reserved:
+  value: 5.079451e+00
+w838f6900/df-boot/percent_bytes-used:
+  value: 4.201225e+00
+w838f6900/df-boot/percent_inodes-free:
+  value: 9.988403e+01
+w838f6900/df-boot/percent_inodes-reserved:
+  value: 0.000000e+00
+w838f6900/df-boot/percent_inodes-used:
+  value: 1.159668e-01
+w838f6900/df-data1/df_complex-free:
+  value: 2.740491e+10
+w838f6900/df-data1/df_complex-reserved:
+  value: 1.476235e+09
+w838f6900/df-data1/df_complex-used:
+  value: 1.802977e+08
+w838f6900/df-data1/df_inodes-free:
+  value: 1.802227e+06
+w838f6900/df-data1/df_inodes-reserved:
+  value: 0.000000e+00
+w838f6900/df-data1/df_inodes-used:
+  value: 1.300000e+01
+w838f6900/df-data1/percent_bytes-free:
+  value: 9.429990e+01
+w838f6900/df-data1/percent_bytes-reserved:
+  value: 5.079704e+00
+w838f6900/df-data1/percent_bytes-used:
+  value: 6.204019e-01
+w838f6900/df-data1/percent_inodes-free:
+  value: 9.999928e+01
+w838f6900/df-data1/percent_inodes-reserved:
+  value: 0.000000e+00
+w838f6900/df-data1/percent_inodes-used:
+  value: 7.213246e-04
+w838f6900/df-dev-shm/df_complex-free:
+  value: 9.842483e+08
+w838f6900/df-dev-shm/df_complex-reserved:
+  value: 0.000000e+00
+w838f6900/df-dev-shm/df_complex-used:
+  value: 0.000000e+00
+w838f6900/df-dev-shm/df_inodes-free:
+  value: 2.402940e+05
+w838f6900/df-dev-shm/df_inodes-reserved:
+  value: 0.000000e+00
+w838f6900/df-dev-shm/df_inodes-used:
+  value: 1.000000e+00
+w838f6900/df-dev-shm/percent_bytes-free:
+  value: 1.000000e+02
+w838f6900/df-dev-shm/percent_bytes-reserved:
+  value: 0.000000e+00
+w838f6900/df-dev-shm/percent_bytes-used:
+  value: 0.000000e+00
+w838f6900/df-dev-shm/percent_inodes-free:
+  value: 9.999958e+01
+w838f6900/df-dev-shm/percent_inodes-reserved:
+  value: 0.000000e+00
+w838f6900/df-dev-shm/percent_inodes-used:
+  value: 4.161551e-04
+w838f6900/df-root/df_complex-free:
+  value: 1.097382e+10
+w838f6900/df-root/df_complex-reserved:
+  value: 6.442435e+08
+w838f6900/df-root/df_complex-used:
+  value: 1.064645e+09
+w838f6900/df-root/df_inodes-free:
+  value: 7.501330e+05
+w838f6900/df-root/df_inodes-reserved:
+  value: 0.000000e+00
+w838f6900/df-root/df_inodes-used:
+  value: 3.629900e+04
+w838f6900/df-root/percent_bytes-free:
+  value: 8.652584e+01
+w838f6900/df-root/percent_bytes-reserved:
+  value: 5.079700e+00
+w838f6900/df-root/percent_bytes-used:
+  value: 8.394459e+00
+w838f6900/df-root/percent_inodes-free:
+  value: 9.538434e+01
+w838f6900/df-root/percent_inodes-reserved:
+  value: 0.000000e+00
+w838f6900/df-root/percent_inodes-used:
+  value: 4.615657e+00
+w838f6900/df-var/df_complex-free:
+  value: 7.637877e+09
+w838f6900/df-var/df_complex-reserved:
+  value: 4.294943e+08
+w838f6900/df-var/df_complex-used:
+  value: 3.877478e+08
+w838f6900/df-var/df_inodes-free:
+  value: 5.229840e+05
+w838f6900/df-var/df_inodes-reserved:
+  value: 0.000000e+00
+w838f6900/df-var/df_inodes-used:
+  value: 1.304000e+03
+w838f6900/df-var/percent_bytes-free:
+  value: 9.033435e+01
+w838f6900/df-var/percent_bytes-reserved:
+  value: 5.079695e+00
+w838f6900/df-var/percent_bytes-used:
+  value: 4.585954e+00
+w838f6900/df-var/percent_inodes-free:
+  value: 9.975128e+01
+w838f6900/df-var/percent_inodes-reserved:
+  value: 0.000000e+00
+w838f6900/df-var/percent_inodes-used:
+  value: 2.487183e-01
+w838f6900/disk-vda/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda1/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda1/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda1/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda1/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda2/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda2/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda2/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda2/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda3/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda3/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda3/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda3/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda4/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda4/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda4/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda4/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda5/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda5/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda5/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda5/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda6/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda6/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda6/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/disk-vda6/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w838f6900/load/load:
+  longterm: 0.000000e+00
+  midterm: 0.000000e+00
+  shortterm: 0.000000e+00
+w838f6900/memory/memory-buffered:
+  value: 1.040671e+08
+w838f6900/memory/memory-cached:
+  value: 4.379361e+08
+w838f6900/memory/memory-free:
+  value: 9.871852e+08
+w838f6900/memory/memory-used:
+  value: 4.393083e+08
+w838f6900/network/if_octets:
+  rx: 0.000000e+00
+  tx: 6.614006e+02
+w838f6900/network/if_packets:
+  rx: 0.000000e+00
+  tx: 4.999994e-01
+w838f6900/network/queue_length:
+  value: 0.000000e+00
+w838f6900/network/total_values-dispatch-accepted:
+  value: 0.000000e+00
+w838f6900/network/total_values-dispatch-rejected:
+  value: 0.000000e+00
+w838f6900/network/total_values-send-accepted:
+  value: 1.479996e+01
+w838f6900/network/total_values-send-rejected:
+  value: 0.000000e+00
+w838f6900/swap/swap-cached:
+  value: 0.000000e+00
+w838f6900/swap/swap-free:
+  value: 2.147475e+09
+w838f6900/swap/swap-used:
+  value: 0.000000e+00
+w838f6900/swap/swap_io-in:
+  value: 0.000000e+00
+w838f6900/swap/swap_io-out:
+  value: 0.000000e+00
+w838f6900/vmem/vmpage_faults:
+  majflt: 0.000000e+00
+  minflt: 4.300042e+00
+w838f6900/vmem/vmpage_io-memory:
+  in: 0.000000e+00
+  out: 0.000000e+00
+w838f6900/vmem/vmpage_io-swap:
+  in: 0.000000e+00
+  out: 0.000000e+00
+w838f6900/vmem/vmpage_number-active_anon:
+  value: 3.653600e+04
+w838f6900/vmem/vmpage_number-active_file:
+  value: 7.163800e+04
+w838f6900/vmem/vmpage_number-anon_pages:
+  value: 2.014900e+04
+w838f6900/vmem/vmpage_number-anon_transparent_hugepages:
+  value: 3.200000e+01
+w838f6900/vmem/vmpage_number-boudfe:
+  value: 0.000000e+00
+w838f6900/vmem/vmpage_number-dirty:
+  value: 0.000000e+00
+w838f6900/vmem/vmpage_number-file_pages:
+  value: 1.323250e+05
+w838f6900/vmem/vmpage_number-free_pages:
+  value: 2.410120e+05
+w838f6900/vmem/vmpage_number-inactive_anon:
+  value: 4.300000e+01
+w838f6900/vmem/vmpage_number-inactive_file:
+  value: 6.064500e+04
+w838f6900/vmem/vmpage_number-isolated_anon:
+  value: 0.000000e+00
+w838f6900/vmem/vmpage_number-isolated_file:
+  value: 0.000000e+00
+w838f6900/vmem/vmpage_number-kernel_stack:
+  value: 1.280000e+02
+w838f6900/vmem/vmpage_number-mapped:
+  value: 3.447000e+03
+w838f6900/vmem/vmpage_number-mlock:
+  value: 0.000000e+00
+w838f6900/vmem/vmpage_number-page_table_pages:
+  value: 6.660000e+02
+w838f6900/vmem/vmpage_number-shmem:
+  value: 4.600000e+01
+w838f6900/vmem/vmpage_number-slab_reclaimable:
+  value: 5.838000e+04
+w838f6900/vmem/vmpage_number-slab_unreclaimable:
+  value: 5.330000e+03
+w838f6900/vmem/vmpage_number-unevictable:
+  value: 0.000000e+00
+w838f6900/vmem/vmpage_number-unstable:
+  value: 0.000000e+00
+w838f6900/vmem/vmpage_number-vmscan_write:
+  value: 0.000000e+00
+w838f6900/vmem/vmpage_number-writeback:
+  value: 0.000000e+00
+w838f6900/vmem/vmpage_number-writeback_temp:
+  value: 0.000000e+00
+w83df6100/cpu-0/cpu-idle:
+  value: 9.979989e+01
+w83df6100/cpu-0/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-0/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-0/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-0/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-0/cpu-system:
+  value: 0.000000e+00
+w83df6100/cpu-0/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-0/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-1/cpu-idle:
+  value: 9.999984e+01
+w83df6100/cpu-1/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-1/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-1/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-1/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-1/cpu-system:
+  value: 9.999985e-02
+w83df6100/cpu-1/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-1/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-10/cpu-idle:
+  value: 9.989993e+01
+w83df6100/cpu-10/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-10/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-10/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-10/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-10/cpu-system:
+  value: 9.999993e-02
+w83df6100/cpu-10/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-10/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-11/cpu-idle:
+  value: 9.999994e+01
+w83df6100/cpu-11/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-11/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-11/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-11/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-11/cpu-system:
+  value: 0.000000e+00
+w83df6100/cpu-11/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-11/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-12/cpu-idle:
+  value: 9.999992e+01
+w83df6100/cpu-12/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-12/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-12/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-12/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-12/cpu-system:
+  value: 0.000000e+00
+w83df6100/cpu-12/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-12/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-13/cpu-idle:
+  value: 9.989989e+01
+w83df6100/cpu-13/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-13/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-13/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-13/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-13/cpu-system:
+  value: 0.000000e+00
+w83df6100/cpu-13/cpu-user:
+  value: 9.999990e-02
+w83df6100/cpu-13/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-14/cpu-idle:
+  value: 9.999994e+01
+w83df6100/cpu-14/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-14/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-14/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-14/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-14/cpu-system:
+  value: 0.000000e+00
+w83df6100/cpu-14/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-14/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-15/cpu-idle:
+  value: 9.990003e+01
+w83df6100/cpu-15/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-15/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-15/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-15/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-15/cpu-system:
+  value: 0.000000e+00
+w83df6100/cpu-15/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-15/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-16/cpu-idle:
+  value: 1.000001e+02
+w83df6100/cpu-16/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-16/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-16/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-16/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-16/cpu-system:
+  value: 0.000000e+00
+w83df6100/cpu-16/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-16/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-17/cpu-idle:
+  value: 9.999995e+01
+w83df6100/cpu-17/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-17/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-17/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-17/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-17/cpu-system:
+  value: 0.000000e+00
+w83df6100/cpu-17/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-17/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-18/cpu-idle:
+  value: 9.999993e+01
+w83df6100/cpu-18/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-18/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-18/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-18/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-18/cpu-system:
+  value: 9.999993e-02
+w83df6100/cpu-18/cpu-user:
+  value: 9.999991e-02
+w83df6100/cpu-18/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-19/cpu-idle:
+  value: 9.989974e+01
+w83df6100/cpu-19/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-19/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-19/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-19/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-19/cpu-system:
+  value: 9.999975e-02
+w83df6100/cpu-19/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-19/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-2/cpu-idle:
+  value: 9.999995e+01
+w83df6100/cpu-2/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-2/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-2/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-2/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-2/cpu-system:
+  value: 0.000000e+00
+w83df6100/cpu-2/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-2/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-20/cpu-idle:
+  value: 9.999968e+01
+w83df6100/cpu-20/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-20/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-20/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-20/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-20/cpu-system:
+  value: 0.000000e+00
+w83df6100/cpu-20/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-20/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-21/cpu-idle:
+  value: 9.999958e+01
+w83df6100/cpu-21/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-21/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-21/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-21/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-21/cpu-system:
+  value: 0.000000e+00
+w83df6100/cpu-21/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-21/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-22/cpu-idle:
+  value: 9.999951e+01
+w83df6100/cpu-22/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-22/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-22/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-22/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-22/cpu-system:
+  value: 9.999951e-02
+w83df6100/cpu-22/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-22/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-23/cpu-idle:
+  value: 9.989947e+01
+w83df6100/cpu-23/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-23/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-23/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-23/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-23/cpu-system:
+  value: 0.000000e+00
+w83df6100/cpu-23/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-23/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-3/cpu-idle:
+  value: 1.000002e+02
+w83df6100/cpu-3/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-3/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-3/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-3/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-3/cpu-system:
+  value: 0.000000e+00
+w83df6100/cpu-3/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-3/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-4/cpu-idle:
+  value: 1.000004e+02
+w83df6100/cpu-4/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-4/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-4/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-4/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-4/cpu-system:
+  value: 0.000000e+00
+w83df6100/cpu-4/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-4/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-5/cpu-idle:
+  value: 1.000004e+02
+w83df6100/cpu-5/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-5/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-5/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-5/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-5/cpu-system:
+  value: 0.000000e+00
+w83df6100/cpu-5/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-5/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-6/cpu-idle:
+  value: 9.990037e+01
+w83df6100/cpu-6/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-6/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-6/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-6/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-6/cpu-system:
+  value: 1.000004e-01
+w83df6100/cpu-6/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-6/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-7/cpu-idle:
+  value: 9.990034e+01
+w83df6100/cpu-7/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-7/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-7/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-7/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-7/cpu-system:
+  value: 0.000000e+00
+w83df6100/cpu-7/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-7/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-8/cpu-idle:
+  value: 9.990024e+01
+w83df6100/cpu-8/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-8/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-8/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-8/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-8/cpu-system:
+  value: 3.000007e-01
+w83df6100/cpu-8/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-8/cpu-wait:
+  value: 0.000000e+00
+w83df6100/cpu-9/cpu-idle:
+  value: 9.999998e+01
+w83df6100/cpu-9/cpu-interrupt:
+  value: 0.000000e+00
+w83df6100/cpu-9/cpu-nice:
+  value: 0.000000e+00
+w83df6100/cpu-9/cpu-softirq:
+  value: 0.000000e+00
+w83df6100/cpu-9/cpu-steal:
+  value: 0.000000e+00
+w83df6100/cpu-9/cpu-system:
+  value: 0.000000e+00
+w83df6100/cpu-9/cpu-user:
+  value: 0.000000e+00
+w83df6100/cpu-9/cpu-wait:
+  value: 0.000000e+00
+w83df6100/df-boot/df_complex-free:
+  value: 4.369900e+08
+w83df6100/df-boot/df_complex-reserved:
+  value: 2.684109e+07
+w83df6100/df-boot/df_complex-used:
+  value: 6.459392e+07
+w83df6100/df-boot/df_inodes-free:
+  value: 3.271800e+04
+w83df6100/df-boot/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6100/df-boot/df_inodes-used:
+  value: 5.000000e+01
+w83df6100/df-boot/percent_bytes-free:
+  value: 8.269669e+01
+w83df6100/df-boot/percent_bytes-reserved:
+  value: 5.079451e+00
+w83df6100/df-boot/percent_bytes-used:
+  value: 1.222386e+01
+w83df6100/df-boot/percent_inodes-free:
+  value: 9.984741e+01
+w83df6100/df-boot/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6100/df-boot/percent_inodes-used:
+  value: 1.525879e-01
+w83df6100/df-data1/df_complex-free:
+  value: 2.574625e+11
+w83df6100/df-data1/df_complex-reserved:
+  value: 1.378982e+10
+w83df6100/df-data1/df_complex-used:
+  value: 2.165924e+08
+w83df6100/df-data1/df_inodes-free:
+  value: 1.683452e+07
+w83df6100/df-data1/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6100/df-data1/df_inodes-used:
+  value: 4.400000e+01
+w83df6100/df-data1/percent_bytes-free:
+  value: 9.484051e+01
+w83df6100/df-data1/percent_bytes-reserved:
+  value: 5.079707e+00
+w83df6100/df-data1/percent_bytes-used:
+  value: 7.978535e-02
+w83df6100/df-data1/percent_inodes-free:
+  value: 9.999974e+01
+w83df6100/df-data1/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6100/df-data1/percent_inodes-used:
+  value: 2.613671e-04
+w83df6100/df-dev-shm/df_complex-free:
+  value: 3.375709e+10
+w83df6100/df-dev-shm/df_complex-reserved:
+  value: 0.000000e+00
+w83df6100/df-dev-shm/df_complex-used:
+  value: 0.000000e+00
+w83df6100/df-dev-shm/df_inodes-free:
+  value: 8.241475e+06
+w83df6100/df-dev-shm/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6100/df-dev-shm/df_inodes-used:
+  value: 1.000000e+00
+w83df6100/df-dev-shm/percent_bytes-free:
+  value: 1.000000e+02
+w83df6100/df-dev-shm/percent_bytes-reserved:
+  value: 0.000000e+00
+w83df6100/df-dev-shm/percent_bytes-used:
+  value: 0.000000e+00
+w83df6100/df-dev-shm/percent_inodes-free:
+  value: 9.999998e+01
+w83df6100/df-dev-shm/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6100/df-dev-shm/percent_inodes-used:
+  value: 1.213375e-05
+w83df6100/df-root/df_complex-free:
+  value: 1.076427e+10
+w83df6100/df-root/df_complex-reserved:
+  value: 6.442435e+08
+w83df6100/df-root/df_complex-used:
+  value: 1.274192e+09
+w83df6100/df-root/df_inodes-free:
+  value: 7.458150e+05
+w83df6100/df-root/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6100/df-root/df_inodes-used:
+  value: 4.061700e+04
+w83df6100/df-root/percent_bytes-free:
+  value: 8.487361e+01
+w83df6100/df-root/percent_bytes-reserved:
+  value: 5.079700e+00
+w83df6100/df-root/percent_bytes-used:
+  value: 1.004669e+01
+w83df6100/df-root/percent_inodes-free:
+  value: 9.483528e+01
+w83df6100/df-root/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6100/df-root/percent_inodes-used:
+  value: 5.164719e+00
+w83df6100/df-var/df_complex-free:
+  value: 7.566651e+09
+w83df6100/df-var/df_complex-reserved:
+  value: 4.294943e+08
+w83df6100/df-var/df_complex-used:
+  value: 4.589732e+08
+w83df6100/df-var/df_inodes-free:
+  value: 5.227920e+05
+w83df6100/df-var/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6100/df-var/df_inodes-used:
+  value: 1.496000e+03
+w83df6100/df-var/percent_bytes-free:
+  value: 8.949196e+01
+w83df6100/df-var/percent_bytes-reserved:
+  value: 5.079695e+00
+w83df6100/df-var/percent_bytes-used:
+  value: 5.428347e+00
+w83df6100/df-var/percent_inodes-free:
+  value: 9.971466e+01
+w83df6100/df-var/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6100/df-var/percent_inodes-used:
+  value: 2.853394e-01
+w83df6100/disk-sda/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda1/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda1/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda1/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda1/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda2/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda2/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda2/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda2/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda3/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda3/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda3/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda3/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda4/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda4/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda4/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda4/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda5/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda5/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda5/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda5/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda6/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda6/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda6/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/disk-sda6/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6100/load/load:
+  longterm: 0.000000e+00
+  midterm: 0.000000e+00
+  shortterm: 0.000000e+00
+w83df6100/memory/memory-buffered:
+  value: 2.127012e+08
+w83df6100/memory/memory-cached:
+  value: 5.203763e+08
+w83df6100/memory/memory-free:
+  value: 6.526190e+10
+w83df6100/memory/memory-used:
+  value: 1.519194e+09
+w83df6100/network/if_octets:
+  rx: 0.000000e+00
+  tx: 1.580500e+03
+w83df6100/network/if_packets:
+  rx: 0.000000e+00
+  tx: 1.200000e+00
+w83df6100/network/queue_length:
+  value: 0.000000e+00
+w83df6100/network/total_values-dispatch-accepted:
+  value: 0.000000e+00
+w83df6100/network/total_values-dispatch-rejected:
+  value: 0.000000e+00
+w83df6100/network/total_values-send-accepted:
+  value: 3.239997e+01
+w83df6100/network/total_values-send-rejected:
+  value: 0.000000e+00
+w83df6100/swap/swap-cached:
+  value: 0.000000e+00
+w83df6100/swap/swap-free:
+  value: 2.147475e+09
+w83df6100/swap/swap-used:
+  value: 0.000000e+00
+w83df6100/swap/swap_io-in:
+  value: 0.000000e+00
+w83df6100/swap/swap_io-out:
+  value: 0.000000e+00
+w83df6100/vmem/vmpage_faults:
+  majflt: 0.000000e+00
+  minflt: 3.899998e+00
+w83df6100/vmem/vmpage_io-memory:
+  in: 0.000000e+00
+  out: 0.000000e+00
+w83df6100/vmem/vmpage_io-swap:
+  in: 0.000000e+00
+  out: 0.000000e+00
+w83df6100/vmem/vmpage_number-active_anon:
+  value: 1.617900e+04
+w83df6100/vmem/vmpage_number-active_file:
+  value: 1.166460e+05
+w83df6100/vmem/vmpage_number-anon_pages:
+  value: 1.208200e+04
+w83df6100/vmem/vmpage_number-anon_transparent_hugepages:
+  value: 8.000000e+00
+w83df6100/vmem/vmpage_number-boudfe:
+  value: 0.000000e+00
+w83df6100/vmem/vmpage_number-dirty:
+  value: 0.000000e+00
+w83df6100/vmem/vmpage_number-file_pages:
+  value: 1.789740e+05
+w83df6100/vmem/vmpage_number-free_pages:
+  value: 1.593308e+07
+w83df6100/vmem/vmpage_number-inactive_anon:
+  value: 4.500000e+01
+w83df6100/vmem/vmpage_number-inactive_file:
+  value: 6.228400e+04
+w83df6100/vmem/vmpage_number-isolated_anon:
+  value: 0.000000e+00
+w83df6100/vmem/vmpage_number-isolated_file:
+  value: 0.000000e+00
+w83df6100/vmem/vmpage_number-kernel_stack:
+  value: 4.390000e+02
+w83df6100/vmem/vmpage_number-mapped:
+  value: 1.670000e+03
+w83df6100/vmem/vmpage_number-mlock:
+  value: 0.000000e+00
+w83df6100/vmem/vmpage_number-page_table_pages:
+  value: 5.870000e+02
+w83df6100/vmem/vmpage_number-shmem:
+  value: 4.700000e+01
+w83df6100/vmem/vmpage_number-slab_reclaimable:
+  value: 2.364110e+05
+w83df6100/vmem/vmpage_number-slab_unreclaimable:
+  value: 1.472600e+04
+w83df6100/vmem/vmpage_number-unevictable:
+  value: 0.000000e+00
+w83df6100/vmem/vmpage_number-unstable:
+  value: 0.000000e+00
+w83df6100/vmem/vmpage_number-vmscan_write:
+  value: 0.000000e+00
+w83df6100/vmem/vmpage_number-writeback:
+  value: 0.000000e+00
+w83df6100/vmem/vmpage_number-writeback_temp:
+  value: 0.000000e+00
+w83df6200/cpu-0/cpu-idle:
+  value: 9.970004e+01
+w83df6200/cpu-0/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-0/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-0/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-0/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-0/cpu-system:
+  value: 0.000000e+00
+w83df6200/cpu-0/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-0/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-1/cpu-idle:
+  value: 1.000000e+02
+w83df6200/cpu-1/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-1/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-1/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-1/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-1/cpu-system:
+  value: 0.000000e+00
+w83df6200/cpu-1/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-1/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-10/cpu-idle:
+  value: 9.990010e+01
+w83df6200/cpu-10/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-10/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-10/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-10/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-10/cpu-system:
+  value: 0.000000e+00
+w83df6200/cpu-10/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-10/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-11/cpu-idle:
+  value: 1.000000e+02
+w83df6200/cpu-11/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-11/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-11/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-11/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-11/cpu-system:
+  value: 1.000001e-01
+w83df6200/cpu-11/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-11/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-12/cpu-idle:
+  value: 9.990011e+01
+w83df6200/cpu-12/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-12/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-12/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-12/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-12/cpu-system:
+  value: 0.000000e+00
+w83df6200/cpu-12/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-12/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-13/cpu-idle:
+  value: 9.990010e+01
+w83df6200/cpu-13/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-13/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-13/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-13/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-13/cpu-system:
+  value: 0.000000e+00
+w83df6200/cpu-13/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-13/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-14/cpu-idle:
+  value: 1.000000e+02
+w83df6200/cpu-14/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-14/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-14/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-14/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-14/cpu-system:
+  value: 0.000000e+00
+w83df6200/cpu-14/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-14/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-15/cpu-idle:
+  value: 1.000000e+02
+w83df6200/cpu-15/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-15/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-15/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-15/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-15/cpu-system:
+  value: 0.000000e+00
+w83df6200/cpu-15/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-15/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-16/cpu-idle:
+  value: 9.999999e+01
+w83df6200/cpu-16/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-16/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-16/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-16/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-16/cpu-system:
+  value: 0.000000e+00
+w83df6200/cpu-16/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-16/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-17/cpu-idle:
+  value: 1.000000e+02
+w83df6200/cpu-17/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-17/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-17/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-17/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-17/cpu-system:
+  value: 1.000000e-01
+w83df6200/cpu-17/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-17/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-18/cpu-idle:
+  value: 9.990002e+01
+w83df6200/cpu-18/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-18/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-18/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-18/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-18/cpu-system:
+  value: 0.000000e+00
+w83df6200/cpu-18/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-18/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-19/cpu-idle:
+  value: 9.989997e+01
+w83df6200/cpu-19/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-19/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-19/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-19/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-19/cpu-system:
+  value: 0.000000e+00
+w83df6200/cpu-19/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-19/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-2/cpu-idle:
+  value: 9.980002e+01
+w83df6200/cpu-2/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-2/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-2/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-2/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-2/cpu-system:
+  value: 1.000000e-01
+w83df6200/cpu-2/cpu-user:
+  value: 1.000000e-01
+w83df6200/cpu-2/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-20/cpu-idle:
+  value: 9.999997e+01
+w83df6200/cpu-20/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-20/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-20/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-20/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-20/cpu-system:
+  value: 0.000000e+00
+w83df6200/cpu-20/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-20/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-21/cpu-idle:
+  value: 9.989997e+01
+w83df6200/cpu-21/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-21/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-21/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-21/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-21/cpu-system:
+  value: 0.000000e+00
+w83df6200/cpu-21/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-21/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-22/cpu-idle:
+  value: 9.990010e+01
+w83df6200/cpu-22/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-22/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-22/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-22/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-22/cpu-system:
+  value: 0.000000e+00
+w83df6200/cpu-22/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-22/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-23/cpu-idle:
+  value: 1.000000e+02
+w83df6200/cpu-23/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-23/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-23/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-23/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-23/cpu-system:
+  value: 0.000000e+00
+w83df6200/cpu-23/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-23/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-3/cpu-idle:
+  value: 9.990001e+01
+w83df6200/cpu-3/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-3/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-3/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-3/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-3/cpu-system:
+  value: 0.000000e+00
+w83df6200/cpu-3/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-3/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-4/cpu-idle:
+  value: 9.989997e+01
+w83df6200/cpu-4/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-4/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-4/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-4/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-4/cpu-system:
+  value: 0.000000e+00
+w83df6200/cpu-4/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-4/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-5/cpu-idle:
+  value: 9.989993e+01
+w83df6200/cpu-5/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-5/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-5/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-5/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-5/cpu-system:
+  value: 0.000000e+00
+w83df6200/cpu-5/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-5/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-6/cpu-idle:
+  value: 9.989989e+01
+w83df6200/cpu-6/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-6/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-6/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-6/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-6/cpu-system:
+  value: 9.999989e-02
+w83df6200/cpu-6/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-6/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-7/cpu-idle:
+  value: 9.990003e+01
+w83df6200/cpu-7/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-7/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-7/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-7/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-7/cpu-system:
+  value: 2.000001e-01
+w83df6200/cpu-7/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-7/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-8/cpu-idle:
+  value: 9.990009e+01
+w83df6200/cpu-8/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-8/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-8/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-8/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-8/cpu-system:
+  value: 0.000000e+00
+w83df6200/cpu-8/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-8/cpu-wait:
+  value: 0.000000e+00
+w83df6200/cpu-9/cpu-idle:
+  value: 1.000001e+02
+w83df6200/cpu-9/cpu-interrupt:
+  value: 0.000000e+00
+w83df6200/cpu-9/cpu-nice:
+  value: 0.000000e+00
+w83df6200/cpu-9/cpu-softirq:
+  value: 0.000000e+00
+w83df6200/cpu-9/cpu-steal:
+  value: 0.000000e+00
+w83df6200/cpu-9/cpu-system:
+  value: 0.000000e+00
+w83df6200/cpu-9/cpu-user:
+  value: 0.000000e+00
+w83df6200/cpu-9/cpu-wait:
+  value: 0.000000e+00
+w83df6200/df-boot/df_complex-free:
+  value: 4.369490e+08
+w83df6200/df-boot/df_complex-reserved:
+  value: 2.684109e+07
+w83df6200/df-boot/df_complex-used:
+  value: 6.463488e+07
+w83df6200/df-boot/df_inodes-free:
+  value: 3.271800e+04
+w83df6200/df-boot/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6200/df-boot/df_inodes-used:
+  value: 5.000000e+01
+w83df6200/df-boot/percent_bytes-free:
+  value: 8.268894e+01
+w83df6200/df-boot/percent_bytes-reserved:
+  value: 5.079451e+00
+w83df6200/df-boot/percent_bytes-used:
+  value: 1.223161e+01
+w83df6200/df-boot/percent_inodes-free:
+  value: 9.984741e+01
+w83df6200/df-boot/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6200/df-boot/percent_inodes-used:
+  value: 1.525879e-01
+w83df6200/df-data1/df_complex-free:
+  value: 2.574625e+11
+w83df6200/df-data1/df_complex-reserved:
+  value: 1.378982e+10
+w83df6200/df-data1/df_complex-used:
+  value: 2.165924e+08
+w83df6200/df-data1/df_inodes-free:
+  value: 1.683452e+07
+w83df6200/df-data1/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6200/df-data1/df_inodes-used:
+  value: 4.400000e+01
+w83df6200/df-data1/percent_bytes-free:
+  value: 9.484051e+01
+w83df6200/df-data1/percent_bytes-reserved:
+  value: 5.079707e+00
+w83df6200/df-data1/percent_bytes-used:
+  value: 7.978535e-02
+w83df6200/df-data1/percent_inodes-free:
+  value: 9.999974e+01
+w83df6200/df-data1/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6200/df-data1/percent_inodes-used:
+  value: 2.613671e-04
+w83df6200/df-dev-shm/df_complex-free:
+  value: 3.375709e+10
+w83df6200/df-dev-shm/df_complex-reserved:
+  value: 0.000000e+00
+w83df6200/df-dev-shm/df_complex-used:
+  value: 0.000000e+00
+w83df6200/df-dev-shm/df_inodes-free:
+  value: 8.241475e+06
+w83df6200/df-dev-shm/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6200/df-dev-shm/df_inodes-used:
+  value: 1.000000e+00
+w83df6200/df-dev-shm/percent_bytes-free:
+  value: 1.000000e+02
+w83df6200/df-dev-shm/percent_bytes-reserved:
+  value: 0.000000e+00
+w83df6200/df-dev-shm/percent_bytes-used:
+  value: 0.000000e+00
+w83df6200/df-dev-shm/percent_inodes-free:
+  value: 9.999998e+01
+w83df6200/df-dev-shm/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6200/df-dev-shm/percent_inodes-used:
+  value: 1.213375e-05
+w83df6200/df-root/df_complex-free:
+  value: 1.076426e+10
+w83df6200/df-root/df_complex-reserved:
+  value: 6.442435e+08
+w83df6200/df-root/df_complex-used:
+  value: 1.274200e+09
+w83df6200/df-root/df_inodes-free:
+  value: 7.458150e+05
+w83df6200/df-root/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6200/df-root/df_inodes-used:
+  value: 4.061700e+04
+w83df6200/df-root/percent_bytes-free:
+  value: 8.487355e+01
+w83df6200/df-root/percent_bytes-reserved:
+  value: 5.079700e+00
+w83df6200/df-root/percent_bytes-used:
+  value: 1.004675e+01
+w83df6200/df-root/percent_inodes-free:
+  value: 9.483528e+01
+w83df6200/df-root/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6200/df-root/percent_inodes-used:
+  value: 5.164719e+00
+w83df6200/df-var/df_complex-free:
+  value: 7.567688e+09
+w83df6200/df-var/df_complex-reserved:
+  value: 4.294943e+08
+w83df6200/df-var/df_complex-used:
+  value: 4.579369e+08
+w83df6200/df-var/df_inodes-free:
+  value: 5.227970e+05
+w83df6200/df-var/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6200/df-var/df_inodes-used:
+  value: 1.491000e+03
+w83df6200/df-var/percent_bytes-free:
+  value: 8.950421e+01
+w83df6200/df-var/percent_bytes-reserved:
+  value: 5.079695e+00
+w83df6200/df-var/percent_bytes-used:
+  value: 5.416090e+00
+w83df6200/df-var/percent_inodes-free:
+  value: 9.971561e+01
+w83df6200/df-var/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6200/df-var/percent_inodes-used:
+  value: 2.843857e-01
+w83df6200/disk-sda/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda1/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda1/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda1/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda1/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda2/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda2/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda2/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda2/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda3/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda3/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda3/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda3/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda4/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda4/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda4/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda4/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda5/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda5/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda5/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda5/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda6/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda6/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda6/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/disk-sda6/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6200/load/load:
+  longterm: 0.000000e+00
+  midterm: 2.000000e-02
+  shortterm: 1.000000e-02
+w83df6200/memory/memory-buffered:
+  value: 2.156175e+08
+w83df6200/memory/memory-cached:
+  value: 5.203517e+08
+w83df6200/memory/memory-free:
+  value: 6.524863e+10
+w83df6200/memory/memory-used:
+  value: 1.529577e+09
+w83df6200/network/if_octets:
+  rx: 0.000000e+00
+  tx: 2.117499e+03
+w83df6200/network/if_packets:
+  rx: 0.000000e+00
+  tx: 1.600001e+00
+w83df6200/network/queue_length:
+  value: 0.000000e+00
+w83df6200/network/total_values-dispatch-accepted:
+  value: 0.000000e+00
+w83df6200/network/total_values-dispatch-rejected:
+  value: 0.000000e+00
+w83df6200/network/total_values-send-accepted:
+  value: 4.570050e+01
+w83df6200/network/total_values-send-rejected:
+  value: 0.000000e+00
+w83df6200/swap/swap-cached:
+  value: 0.000000e+00
+w83df6200/swap/swap-free:
+  value: 2.147475e+09
+w83df6200/swap/swap-used:
+  value: 0.000000e+00
+w83df6200/swap/swap_io-in:
+  value: 0.000000e+00
+w83df6200/swap/swap_io-out:
+  value: 0.000000e+00
+w83df6200/vmem/vmpage_faults:
+  majflt: 0.000000e+00
+  minflt: 8.000883e-01
+w83df6200/vmem/vmpage_io-memory:
+  in: 0.000000e+00
+  out: 0.000000e+00
+w83df6200/vmem/vmpage_io-swap:
+  in: 0.000000e+00
+  out: 0.000000e+00
+w83df6200/vmem/vmpage_number-active_anon:
+  value: 1.666900e+04
+w83df6200/vmem/vmpage_number-active_file:
+  value: 1.167210e+05
+w83df6200/vmem/vmpage_number-anon_pages:
+  value: 1.154700e+04
+w83df6200/vmem/vmpage_number-anon_transparent_hugepages:
+  value: 1.000000e+01
+w83df6200/vmem/vmpage_number-boudfe:
+  value: 0.000000e+00
+w83df6200/vmem/vmpage_number-dirty:
+  value: 2.000000e+00
+w83df6200/vmem/vmpage_number-file_pages:
+  value: 1.796800e+05
+w83df6200/vmem/vmpage_number-free_pages:
+  value: 1.592984e+07
+w83df6200/vmem/vmpage_number-inactive_anon:
+  value: 4.500000e+01
+w83df6200/vmem/vmpage_number-inactive_file:
+  value: 6.291600e+04
+w83df6200/vmem/vmpage_number-isolated_anon:
+  value: 0.000000e+00
+w83df6200/vmem/vmpage_number-isolated_file:
+  value: 0.000000e+00
+w83df6200/vmem/vmpage_number-kernel_stack:
+  value: 4.390000e+02
+w83df6200/vmem/vmpage_number-mapped:
+  value: 1.669000e+03
+w83df6200/vmem/vmpage_number-mlock:
+  value: 0.000000e+00
+w83df6200/vmem/vmpage_number-page_table_pages:
+  value: 5.770000e+02
+w83df6200/vmem/vmpage_number-shmem:
+  value: 4.700000e+01
+w83df6200/vmem/vmpage_number-slab_reclaimable:
+  value: 2.386770e+05
+w83df6200/vmem/vmpage_number-slab_unreclaimable:
+  value: 1.476200e+04
+w83df6200/vmem/vmpage_number-unevictable:
+  value: 0.000000e+00
+w83df6200/vmem/vmpage_number-unstable:
+  value: 0.000000e+00
+w83df6200/vmem/vmpage_number-vmscan_write:
+  value: 0.000000e+00
+w83df6200/vmem/vmpage_number-writeback:
+  value: 0.000000e+00
+w83df6200/vmem/vmpage_number-writeback_temp:
+  value: 0.000000e+00
+w83df6300/cpu-0/cpu-idle:
+  value: 9.980074e+01
+w83df6300/cpu-0/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-0/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-0/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-0/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-0/cpu-system:
+  value: 0.000000e+00
+w83df6300/cpu-0/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-0/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-1/cpu-idle:
+  value: 9.990070e+01
+w83df6300/cpu-1/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-1/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-1/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-1/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-1/cpu-system:
+  value: 0.000000e+00
+w83df6300/cpu-1/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-1/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-10/cpu-idle:
+  value: 1.000010e+02
+w83df6300/cpu-10/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-10/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-10/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-10/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-10/cpu-system:
+  value: 1.000011e-01
+w83df6300/cpu-10/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-10/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-11/cpu-idle:
+  value: 1.000011e+02
+w83df6300/cpu-11/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-11/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-11/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-11/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-11/cpu-system:
+  value: 0.000000e+00
+w83df6300/cpu-11/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-11/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-12/cpu-idle:
+  value: 9.980111e+01
+w83df6300/cpu-12/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-12/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-12/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-12/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-12/cpu-system:
+  value: 0.000000e+00
+w83df6300/cpu-12/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-12/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-13/cpu-idle:
+  value: 9.990102e+01
+w83df6300/cpu-13/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-13/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-13/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-13/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-13/cpu-system:
+  value: 0.000000e+00
+w83df6300/cpu-13/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-13/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-14/cpu-idle:
+  value: 9.990101e+01
+w83df6300/cpu-14/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-14/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-14/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-14/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-14/cpu-system:
+  value: 0.000000e+00
+w83df6300/cpu-14/cpu-user:
+  value: 1.000010e-01
+w83df6300/cpu-14/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-15/cpu-idle:
+  value: 1.000010e+02
+w83df6300/cpu-15/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-15/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-15/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-15/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-15/cpu-system:
+  value: 0.000000e+00
+w83df6300/cpu-15/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-15/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-16/cpu-idle:
+  value: 1.000010e+02
+w83df6300/cpu-16/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-16/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-16/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-16/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-16/cpu-system:
+  value: 0.000000e+00
+w83df6300/cpu-16/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-16/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-17/cpu-idle:
+  value: 1.000010e+02
+w83df6300/cpu-17/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-17/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-17/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-17/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-17/cpu-system:
+  value: 0.000000e+00
+w83df6300/cpu-17/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-17/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-18/cpu-idle:
+  value: 1.000009e+02
+w83df6300/cpu-18/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-18/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-18/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-18/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-18/cpu-system:
+  value: 1.000009e-01
+w83df6300/cpu-18/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-18/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-19/cpu-idle:
+  value: 9.990092e+01
+w83df6300/cpu-19/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-19/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-19/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-19/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-19/cpu-system:
+  value: 0.000000e+00
+w83df6300/cpu-19/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-19/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-2/cpu-idle:
+  value: 1.000009e+02
+w83df6300/cpu-2/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-2/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-2/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-2/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-2/cpu-system:
+  value: 0.000000e+00
+w83df6300/cpu-2/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-2/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-20/cpu-idle:
+  value: 1.000010e+02
+w83df6300/cpu-20/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-20/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-20/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-20/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-20/cpu-system:
+  value: 0.000000e+00
+w83df6300/cpu-20/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-20/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-21/cpu-idle:
+  value: 1.000011e+02
+w83df6300/cpu-21/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-21/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-21/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-21/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-21/cpu-system:
+  value: 1.000011e-01
+w83df6300/cpu-21/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-21/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-22/cpu-idle:
+  value: 1.000012e+02
+w83df6300/cpu-22/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-22/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-22/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-22/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-22/cpu-system:
+  value: 1.000012e-01
+w83df6300/cpu-22/cpu-user:
+  value: 1.000012e-01
+w83df6300/cpu-22/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-23/cpu-idle:
+  value: 9.990117e+01
+w83df6300/cpu-23/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-23/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-23/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-23/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-23/cpu-system:
+  value: 0.000000e+00
+w83df6300/cpu-23/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-23/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-3/cpu-idle:
+  value: 1.000009e+02
+w83df6300/cpu-3/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-3/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-3/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-3/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-3/cpu-system:
+  value: 0.000000e+00
+w83df6300/cpu-3/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-3/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-4/cpu-idle:
+  value: 9.990089e+01
+w83df6300/cpu-4/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-4/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-4/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-4/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-4/cpu-system:
+  value: 0.000000e+00
+w83df6300/cpu-4/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-4/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-5/cpu-idle:
+  value: 1.000010e+02
+w83df6300/cpu-5/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-5/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-5/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-5/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-5/cpu-system:
+  value: 0.000000e+00
+w83df6300/cpu-5/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-5/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-6/cpu-idle:
+  value: 1.000010e+02
+w83df6300/cpu-6/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-6/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-6/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-6/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-6/cpu-system:
+  value: 1.000010e-01
+w83df6300/cpu-6/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-6/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-7/cpu-idle:
+  value: 1.000011e+02
+w83df6300/cpu-7/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-7/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-7/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-7/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-7/cpu-system:
+  value: 0.000000e+00
+w83df6300/cpu-7/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-7/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-8/cpu-idle:
+  value: 9.990103e+01
+w83df6300/cpu-8/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-8/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-8/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-8/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-8/cpu-system:
+  value: 0.000000e+00
+w83df6300/cpu-8/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-8/cpu-wait:
+  value: 0.000000e+00
+w83df6300/cpu-9/cpu-idle:
+  value: 1.000010e+02
+w83df6300/cpu-9/cpu-interrupt:
+  value: 0.000000e+00
+w83df6300/cpu-9/cpu-nice:
+  value: 0.000000e+00
+w83df6300/cpu-9/cpu-softirq:
+  value: 0.000000e+00
+w83df6300/cpu-9/cpu-steal:
+  value: 0.000000e+00
+w83df6300/cpu-9/cpu-system:
+  value: 0.000000e+00
+w83df6300/cpu-9/cpu-user:
+  value: 0.000000e+00
+w83df6300/cpu-9/cpu-wait:
+  value: 0.000000e+00
+w83df6300/df-boot/df_complex-free:
+  value: 4.369449e+08
+w83df6300/df-boot/df_complex-reserved:
+  value: 2.684109e+07
+w83df6300/df-boot/df_complex-used:
+  value: 6.463898e+07
+w83df6300/df-boot/df_inodes-free:
+  value: 3.271800e+04
+w83df6300/df-boot/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6300/df-boot/df_inodes-used:
+  value: 5.000000e+01
+w83df6300/df-boot/percent_bytes-free:
+  value: 8.268816e+01
+w83df6300/df-boot/percent_bytes-reserved:
+  value: 5.079451e+00
+w83df6300/df-boot/percent_bytes-used:
+  value: 1.223238e+01
+w83df6300/df-boot/percent_inodes-free:
+  value: 9.984741e+01
+w83df6300/df-boot/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6300/df-boot/percent_inodes-used:
+  value: 1.525879e-01
+w83df6300/df-data1/df_complex-free:
+  value: 2.574625e+11
+w83df6300/df-data1/df_complex-reserved:
+  value: 1.378982e+10
+w83df6300/df-data1/df_complex-used:
+  value: 2.165924e+08
+w83df6300/df-data1/df_inodes-free:
+  value: 1.683452e+07
+w83df6300/df-data1/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6300/df-data1/df_inodes-used:
+  value: 4.400000e+01
+w83df6300/df-data1/percent_bytes-free:
+  value: 9.484051e+01
+w83df6300/df-data1/percent_bytes-reserved:
+  value: 5.079707e+00
+w83df6300/df-data1/percent_bytes-used:
+  value: 7.978535e-02
+w83df6300/df-data1/percent_inodes-free:
+  value: 9.999974e+01
+w83df6300/df-data1/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6300/df-data1/percent_inodes-used:
+  value: 2.613671e-04
+w83df6300/df-dev-shm/df_complex-free:
+  value: 3.375709e+10
+w83df6300/df-dev-shm/df_complex-reserved:
+  value: 0.000000e+00
+w83df6300/df-dev-shm/df_complex-used:
+  value: 0.000000e+00
+w83df6300/df-dev-shm/df_inodes-free:
+  value: 8.241475e+06
+w83df6300/df-dev-shm/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6300/df-dev-shm/df_inodes-used:
+  value: 1.000000e+00
+w83df6300/df-dev-shm/percent_bytes-free:
+  value: 1.000000e+02
+w83df6300/df-dev-shm/percent_bytes-reserved:
+  value: 0.000000e+00
+w83df6300/df-dev-shm/percent_bytes-used:
+  value: 0.000000e+00
+w83df6300/df-dev-shm/percent_inodes-free:
+  value: 9.999998e+01
+w83df6300/df-dev-shm/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6300/df-dev-shm/percent_inodes-used:
+  value: 1.213375e-05
+w83df6300/df-root/df_complex-free:
+  value: 1.022576e+10
+w83df6300/df-root/df_complex-reserved:
+  value: 6.442435e+08
+w83df6300/df-root/df_complex-used:
+  value: 1.812701e+09
+w83df6300/df-root/df_inodes-free:
+  value: 7.415980e+05
+w83df6300/df-root/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6300/df-root/df_inodes-used:
+  value: 4.483400e+04
+w83df6300/df-root/percent_bytes-free:
+  value: 8.062760e+01
+w83df6300/df-root/percent_bytes-reserved:
+  value: 5.079700e+00
+w83df6300/df-root/percent_bytes-used:
+  value: 1.429270e+01
+w83df6300/df-root/percent_inodes-free:
+  value: 9.429906e+01
+w83df6300/df-root/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6300/df-root/percent_inodes-used:
+  value: 5.700938e+00
+w83df6300/df-var/df_complex-free:
+  value: 7.485731e+09
+w83df6300/df-var/df_complex-reserved:
+  value: 4.294943e+08
+w83df6300/df-var/df_complex-used:
+  value: 5.398938e+08
+w83df6300/df-var/df_inodes-free:
+  value: 5.224290e+05
+w83df6300/df-var/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6300/df-var/df_inodes-used:
+  value: 1.859000e+03
+w83df6300/df-var/percent_bytes-free:
+  value: 8.853490e+01
+w83df6300/df-var/percent_bytes-reserved:
+  value: 5.079695e+00
+w83df6300/df-var/percent_bytes-used:
+  value: 6.385407e+00
+w83df6300/df-var/percent_inodes-free:
+  value: 9.964542e+01
+w83df6300/df-var/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6300/df-var/percent_inodes-used:
+  value: 3.545761e-01
+w83df6300/disk-sda/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda1/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda1/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda1/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda1/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda2/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda2/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda2/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda2/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda3/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda3/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda3/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda3/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda4/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda4/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda4/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda4/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda5/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda5/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda5/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda5/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda6/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda6/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda6/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/disk-sda6/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6300/load/load:
+  longterm: 0.000000e+00
+  midterm: 2.000000e-02
+  shortterm: 1.000000e-02
+w83df6300/memory/memory-buffered:
+  value: 2.686280e+08
+w83df6300/memory/memory-cached:
+  value: 1.142759e+09
+w83df6300/memory/memory-free:
+  value: 6.452790e+10
+w83df6300/memory/memory-used:
+  value: 1.574883e+09
+w83df6300/network/if_octets:
+  rx: 0.000000e+00
+  tx: 1.575799e+03
+w83df6300/network/if_packets:
+  rx: 0.000000e+00
+  tx: 1.199999e+00
+w83df6300/network/queue_length:
+  value: 0.000000e+00
+w83df6300/network/total_values-dispatch-accepted:
+  value: 0.000000e+00
+w83df6300/network/total_values-dispatch-rejected:
+  value: 0.000000e+00
+w83df6300/network/total_values-send-accepted:
+  value: 3.240001e+01
+w83df6300/network/total_values-send-rejected:
+  value: 0.000000e+00
+w83df6300/swap/swap-cached:
+  value: 0.000000e+00
+w83df6300/swap/swap-free:
+  value: 2.147475e+09
+w83df6300/swap/swap-used:
+  value: 0.000000e+00
+w83df6300/swap/swap_io-in:
+  value: 0.000000e+00
+w83df6300/swap/swap_io-out:
+  value: 0.000000e+00
+w83df6300/vmem/vmpage_faults:
+  majflt: 0.000000e+00
+  minflt: 3.800015e+00
+w83df6300/vmem/vmpage_io-memory:
+  in: 0.000000e+00
+  out: 0.000000e+00
+w83df6300/vmem/vmpage_io-swap:
+  in: 0.000000e+00
+  out: 0.000000e+00
+w83df6300/vmem/vmpage_number-active_anon:
+  value: 1.835300e+04
+w83df6300/vmem/vmpage_number-active_file:
+  value: 1.867190e+05
+w83df6300/vmem/vmpage_number-anon_pages:
+  value: 1.272000e+04
+w83df6300/vmem/vmpage_number-anon_transparent_hugepages:
+  value: 1.100000e+01
+w83df6300/vmem/vmpage_number-boudfe:
+  value: 0.000000e+00
+w83df6300/vmem/vmpage_number-dirty:
+  value: 4.000000e+00
+w83df6300/vmem/vmpage_number-file_pages:
+  value: 3.445770e+05
+w83df6300/vmem/vmpage_number-free_pages:
+  value: 1.575388e+07
+w83df6300/vmem/vmpage_number-inactive_anon:
+  value: 4.900000e+01
+w83df6300/vmem/vmpage_number-inactive_file:
+  value: 1.578110e+05
+w83df6300/vmem/vmpage_number-isolated_anon:
+  value: 0.000000e+00
+w83df6300/vmem/vmpage_number-isolated_file:
+  value: 0.000000e+00
+w83df6300/vmem/vmpage_number-kernel_stack:
+  value: 4.460000e+02
+w83df6300/vmem/vmpage_number-mapped:
+  value: 2.404000e+03
+w83df6300/vmem/vmpage_number-mlock:
+  value: 0.000000e+00
+w83df6300/vmem/vmpage_number-page_table_pages:
+  value: 8.250000e+02
+w83df6300/vmem/vmpage_number-shmem:
+  value: 5.100000e+01
+w83df6300/vmem/vmpage_number-slab_reclaimable:
+  value: 2.469330e+05
+w83df6300/vmem/vmpage_number-slab_unreclaimable:
+  value: 1.504900e+04
+w83df6300/vmem/vmpage_number-unevictable:
+  value: 0.000000e+00
+w83df6300/vmem/vmpage_number-unstable:
+  value: 0.000000e+00
+w83df6300/vmem/vmpage_number-vmscan_write:
+  value: 0.000000e+00
+w83df6300/vmem/vmpage_number-writeback:
+  value: 0.000000e+00
+w83df6300/vmem/vmpage_number-writeback_temp:
+  value: 0.000000e+00
+w83df6400/cpu-0/cpu-idle:
+  value: 9.979917e+01
+w83df6400/cpu-0/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-0/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-0/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-0/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-0/cpu-system:
+  value: 0.000000e+00
+w83df6400/cpu-0/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-0/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-1/cpu-idle:
+  value: 9.989810e+01
+w83df6400/cpu-1/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-1/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-1/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-1/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-1/cpu-system:
+  value: 0.000000e+00
+w83df6400/cpu-1/cpu-user:
+  value: 9.999843e-02
+w83df6400/cpu-1/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-10/cpu-idle:
+  value: 9.999853e+01
+w83df6400/cpu-10/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-10/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-10/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-10/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-10/cpu-system:
+  value: 9.999853e-02
+w83df6400/cpu-10/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-10/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-11/cpu-idle:
+  value: 9.989854e+01
+w83df6400/cpu-11/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-11/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-11/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-11/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-11/cpu-system:
+  value: 9.999853e-02
+w83df6400/cpu-11/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-11/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-12/cpu-idle:
+  value: 9.989849e+01
+w83df6400/cpu-12/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-12/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-12/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-12/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-12/cpu-system:
+  value: 0.000000e+00
+w83df6400/cpu-12/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-12/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-13/cpu-idle:
+  value: 9.989843e+01
+w83df6400/cpu-13/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-13/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-13/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-13/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-13/cpu-system:
+  value: 0.000000e+00
+w83df6400/cpu-13/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-13/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-14/cpu-idle:
+  value: 9.999838e+01
+w83df6400/cpu-14/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-14/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-14/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-14/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-14/cpu-system:
+  value: 0.000000e+00
+w83df6400/cpu-14/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-14/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-15/cpu-idle:
+  value: 9.989833e+01
+w83df6400/cpu-15/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-15/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-15/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-15/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-15/cpu-system:
+  value: 0.000000e+00
+w83df6400/cpu-15/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-15/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-16/cpu-idle:
+  value: 9.999832e+01
+w83df6400/cpu-16/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-16/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-16/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-16/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-16/cpu-system:
+  value: 9.999834e-02
+w83df6400/cpu-16/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-16/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-17/cpu-idle:
+  value: 9.989833e+01
+w83df6400/cpu-17/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-17/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-17/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-17/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-17/cpu-system:
+  value: 0.000000e+00
+w83df6400/cpu-17/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-17/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-18/cpu-idle:
+  value: 9.999827e+01
+w83df6400/cpu-18/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-18/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-18/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-18/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-18/cpu-system:
+  value: 0.000000e+00
+w83df6400/cpu-18/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-18/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-19/cpu-idle:
+  value: 9.999815e+01
+w83df6400/cpu-19/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-19/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-19/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-19/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-19/cpu-system:
+  value: 0.000000e+00
+w83df6400/cpu-19/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-19/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-2/cpu-idle:
+  value: 9.979807e+01
+w83df6400/cpu-2/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-2/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-2/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-2/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-2/cpu-system:
+  value: 0.000000e+00
+w83df6400/cpu-2/cpu-user:
+  value: 9.999811e-02
+w83df6400/cpu-2/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-20/cpu-idle:
+  value: 9.999811e+01
+w83df6400/cpu-20/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-20/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-20/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-20/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-20/cpu-system:
+  value: 0.000000e+00
+w83df6400/cpu-20/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-20/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-21/cpu-idle:
+  value: 9.999773e+01
+w83df6400/cpu-21/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-21/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-21/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-21/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-21/cpu-system:
+  value: 0.000000e+00
+w83df6400/cpu-21/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-21/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-22/cpu-idle:
+  value: 9.999773e+01
+w83df6400/cpu-22/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-22/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-22/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-22/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-22/cpu-system:
+  value: 0.000000e+00
+w83df6400/cpu-22/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-22/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-23/cpu-idle:
+  value: 9.989763e+01
+w83df6400/cpu-23/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-23/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-23/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-23/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-23/cpu-system:
+  value: 0.000000e+00
+w83df6400/cpu-23/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-23/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-3/cpu-idle:
+  value: 9.999817e+01
+w83df6400/cpu-3/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-3/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-3/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-3/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-3/cpu-system:
+  value: 0.000000e+00
+w83df6400/cpu-3/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-3/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-4/cpu-idle:
+  value: 9.989839e+01
+w83df6400/cpu-4/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-4/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-4/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-4/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-4/cpu-system:
+  value: 0.000000e+00
+w83df6400/cpu-4/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-4/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-5/cpu-idle:
+  value: 9.999820e+01
+w83df6400/cpu-5/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-5/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-5/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-5/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-5/cpu-system:
+  value: 9.999815e-02
+w83df6400/cpu-5/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-5/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-6/cpu-idle:
+  value: 9.989865e+01
+w83df6400/cpu-6/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-6/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-6/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-6/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-6/cpu-system:
+  value: 0.000000e+00
+w83df6400/cpu-6/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-6/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-7/cpu-idle:
+  value: 9.999866e+01
+w83df6400/cpu-7/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-7/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-7/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-7/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-7/cpu-system:
+  value: 9.999866e-02
+w83df6400/cpu-7/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-7/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-8/cpu-idle:
+  value: 9.999857e+01
+w83df6400/cpu-8/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-8/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-8/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-8/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-8/cpu-system:
+  value: 9.999860e-02
+w83df6400/cpu-8/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-8/cpu-wait:
+  value: 0.000000e+00
+w83df6400/cpu-9/cpu-idle:
+  value: 9.989853e+01
+w83df6400/cpu-9/cpu-interrupt:
+  value: 0.000000e+00
+w83df6400/cpu-9/cpu-nice:
+  value: 0.000000e+00
+w83df6400/cpu-9/cpu-softirq:
+  value: 0.000000e+00
+w83df6400/cpu-9/cpu-steal:
+  value: 0.000000e+00
+w83df6400/cpu-9/cpu-system:
+  value: 9.999854e-02
+w83df6400/cpu-9/cpu-user:
+  value: 0.000000e+00
+w83df6400/cpu-9/cpu-wait:
+  value: 0.000000e+00
+w83df6400/df-boot/df_complex-free:
+  value: 4.369449e+08
+w83df6400/df-boot/df_complex-reserved:
+  value: 2.684109e+07
+w83df6400/df-boot/df_complex-used:
+  value: 6.463898e+07
+w83df6400/df-boot/df_inodes-free:
+  value: 3.271800e+04
+w83df6400/df-boot/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6400/df-boot/df_inodes-used:
+  value: 5.000000e+01
+w83df6400/df-boot/percent_bytes-free:
+  value: 8.268816e+01
+w83df6400/df-boot/percent_bytes-reserved:
+  value: 5.079451e+00
+w83df6400/df-boot/percent_bytes-used:
+  value: 1.223238e+01
+w83df6400/df-boot/percent_inodes-free:
+  value: 9.984741e+01
+w83df6400/df-boot/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6400/df-boot/percent_inodes-used:
+  value: 1.525879e-01
+w83df6400/df-data1/df_complex-free:
+  value: 2.574625e+11
+w83df6400/df-data1/df_complex-reserved:
+  value: 1.378982e+10
+w83df6400/df-data1/df_complex-used:
+  value: 2.165924e+08
+w83df6400/df-data1/df_inodes-free:
+  value: 1.683452e+07
+w83df6400/df-data1/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6400/df-data1/df_inodes-used:
+  value: 4.400000e+01
+w83df6400/df-data1/percent_bytes-free:
+  value: 9.484051e+01
+w83df6400/df-data1/percent_bytes-reserved:
+  value: 5.079707e+00
+w83df6400/df-data1/percent_bytes-used:
+  value: 7.978535e-02
+w83df6400/df-data1/percent_inodes-free:
+  value: 9.999974e+01
+w83df6400/df-data1/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6400/df-data1/percent_inodes-used:
+  value: 2.613671e-04
+w83df6400/df-dev-shm/df_complex-free:
+  value: 3.375709e+10
+w83df6400/df-dev-shm/df_complex-reserved:
+  value: 0.000000e+00
+w83df6400/df-dev-shm/df_complex-used:
+  value: 0.000000e+00
+w83df6400/df-dev-shm/df_inodes-free:
+  value: 8.241475e+06
+w83df6400/df-dev-shm/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6400/df-dev-shm/df_inodes-used:
+  value: 1.000000e+00
+w83df6400/df-dev-shm/percent_bytes-free:
+  value: 1.000000e+02
+w83df6400/df-dev-shm/percent_bytes-reserved:
+  value: 0.000000e+00
+w83df6400/df-dev-shm/percent_bytes-used:
+  value: 0.000000e+00
+w83df6400/df-dev-shm/percent_inodes-free:
+  value: 9.999998e+01
+w83df6400/df-dev-shm/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6400/df-dev-shm/percent_inodes-used:
+  value: 1.213375e-05
+w83df6400/df-root/df_complex-free:
+  value: 1.062062e+10
+w83df6400/df-root/df_complex-reserved:
+  value: 6.442435e+08
+w83df6400/df-root/df_complex-used:
+  value: 1.417847e+09
+w83df6400/df-root/df_inodes-free:
+  value: 7.449690e+05
+w83df6400/df-root/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6400/df-root/df_inodes-used:
+  value: 4.146300e+04
+w83df6400/df-root/percent_bytes-free:
+  value: 8.374093e+01
+w83df6400/df-root/percent_bytes-reserved:
+  value: 5.079700e+00
+w83df6400/df-root/percent_bytes-used:
+  value: 1.117937e+01
+w83df6400/df-root/percent_inodes-free:
+  value: 9.472771e+01
+w83df6400/df-root/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6400/df-root/percent_inodes-used:
+  value: 5.272293e+00
+w83df6400/df-var/df_complex-free:
+  value: 7.567413e+09
+w83df6400/df-var/df_complex-reserved:
+  value: 4.294943e+08
+w83df6400/df-var/df_complex-used:
+  value: 4.582113e+08
+w83df6400/df-var/df_inodes-free:
+  value: 5.227820e+05
+w83df6400/df-var/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6400/df-var/df_inodes-used:
+  value: 1.506000e+03
+w83df6400/df-var/percent_bytes-free:
+  value: 8.950097e+01
+w83df6400/df-var/percent_bytes-reserved:
+  value: 5.079695e+00
+w83df6400/df-var/percent_bytes-used:
+  value: 5.419336e+00
+w83df6400/df-var/percent_inodes-free:
+  value: 9.971275e+01
+w83df6400/df-var/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6400/df-var/percent_inodes-used:
+  value: 2.872467e-01
+w83df6400/disk-sda/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda1/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda1/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda1/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda1/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda2/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda2/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda2/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda2/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda3/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda3/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda3/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda3/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda4/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda4/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda4/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda4/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda5/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda5/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda5/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda5/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda6/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda6/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda6/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/disk-sda6/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6400/load/load:
+  longterm: 0.000000e+00
+  midterm: 2.000000e-02
+  shortterm: 3.000000e-02
+w83df6400/memory/memory-buffered:
+  value: 2.072453e+08
+w83df6400/memory/memory-cached:
+  value: 6.651863e+08
+w83df6400/memory/memory-free:
+  value: 6.511982e+10
+w83df6400/memory/memory-used:
+  value: 1.521922e+09
+w83df6400/network/if_octets:
+  rx: 0.000000e+00
+  tx: 1.849000e+03
+w83df6400/network/if_packets:
+  rx: 0.000000e+00
+  tx: 1.400000e+00
+w83df6400/network/queue_length:
+  value: 0.000000e+00
+w83df6400/network/total_values-dispatch-accepted:
+  value: 0.000000e+00
+w83df6400/network/total_values-dispatch-rejected:
+  value: 0.000000e+00
+w83df6400/network/total_values-send-accepted:
+  value: 3.370000e+01
+w83df6400/network/total_values-send-rejected:
+  value: 0.000000e+00
+w83df6400/swap/swap-cached:
+  value: 0.000000e+00
+w83df6400/swap/swap-free:
+  value: 2.147475e+09
+w83df6400/swap/swap-used:
+  value: 0.000000e+00
+w83df6400/swap/swap_io-in:
+  value: 0.000000e+00
+w83df6400/swap/swap_io-out:
+  value: 0.000000e+00
+w83df6400/vmem/vmpage_faults:
+  majflt: 0.000000e+00
+  minflt: 4.700028e+00
+w83df6400/vmem/vmpage_io-memory:
+  in: 0.000000e+00
+  out: 0.000000e+00
+w83df6400/vmem/vmpage_io-swap:
+  in: 0.000000e+00
+  out: 0.000000e+00
+w83df6400/vmem/vmpage_number-active_anon:
+  value: 1.704400e+04
+w83df6400/vmem/vmpage_number-active_file:
+  value: 1.158240e+05
+w83df6400/vmem/vmpage_number-anon_pages:
+  value: 1.090600e+04
+w83df6400/vmem/vmpage_number-anon_transparent_hugepages:
+  value: 1.200000e+01
+w83df6400/vmem/vmpage_number-boudfe:
+  value: 0.000000e+00
+w83df6400/vmem/vmpage_number-dirty:
+  value: 0.000000e+00
+w83df6400/vmem/vmpage_number-file_pages:
+  value: 2.129960e+05
+w83df6400/vmem/vmpage_number-free_pages:
+  value: 1.589839e+07
+w83df6400/vmem/vmpage_number-inactive_anon:
+  value: 4.400000e+01
+w83df6400/vmem/vmpage_number-inactive_file:
+  value: 9.713000e+04
+w83df6400/vmem/vmpage_number-isolated_anon:
+  value: 0.000000e+00
+w83df6400/vmem/vmpage_number-isolated_file:
+  value: 0.000000e+00
+w83df6400/vmem/vmpage_number-kernel_stack:
+  value: 4.350000e+02
+w83df6400/vmem/vmpage_number-mapped:
+  value: 1.621000e+03
+w83df6400/vmem/vmpage_number-mlock:
+  value: 0.000000e+00
+w83df6400/vmem/vmpage_number-page_table_pages:
+  value: 4.680000e+02
+w83df6400/vmem/vmpage_number-shmem:
+  value: 4.600000e+01
+w83df6400/vmem/vmpage_number-slab_reclaimable:
+  value: 2.361780e+05
+w83df6400/vmem/vmpage_number-slab_unreclaimable:
+  value: 1.468100e+04
+w83df6400/vmem/vmpage_number-unevictable:
+  value: 0.000000e+00
+w83df6400/vmem/vmpage_number-unstable:
+  value: 0.000000e+00
+w83df6400/vmem/vmpage_number-vmscan_write:
+  value: 0.000000e+00
+w83df6400/vmem/vmpage_number-writeback:
+  value: 0.000000e+00
+w83df6400/vmem/vmpage_number-writeback_temp:
+  value: 0.000000e+00
+w83df6500/cpu-0/cpu-idle:
+  value: 8.689957e+01
+w83df6500/cpu-0/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-0/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-0/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-0/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-0/cpu-system:
+  value: 2.299989e+00
+w83df6500/cpu-0/cpu-user:
+  value: 1.059998e+01
+w83df6500/cpu-0/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-1/cpu-idle:
+  value: 9.869419e+01
+w83df6500/cpu-1/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-1/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-1/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-1/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-1/cpu-system:
+  value: 3.999803e-01
+w83df6500/cpu-1/cpu-user:
+  value: 6.999674e-01
+w83df6500/cpu-1/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-10/cpu-idle:
+  value: 9.999000e+01
+w83df6500/cpu-10/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-10/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-10/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-10/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-10/cpu-system:
+  value: 9.999001e-02
+w83df6500/cpu-10/cpu-user:
+  value: 0.000000e+00
+w83df6500/cpu-10/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-11/cpu-idle:
+  value: 9.988985e+01
+w83df6500/cpu-11/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-11/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-11/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-11/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-11/cpu-system:
+  value: 9.998982e-02
+w83df6500/cpu-11/cpu-user:
+  value: 0.000000e+00
+w83df6500/cpu-11/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-12/cpu-idle:
+  value: 9.988970e+01
+w83df6500/cpu-12/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-12/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-12/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-12/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-12/cpu-system:
+  value: 0.000000e+00
+w83df6500/cpu-12/cpu-user:
+  value: 9.998982e-02
+w83df6500/cpu-12/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-13/cpu-idle:
+  value: 9.239045e+01
+w83df6500/cpu-13/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-13/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-13/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-13/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-13/cpu-system:
+  value: 2.999690e+00
+w83df6500/cpu-13/cpu-user:
+  value: 4.399545e+00
+w83df6500/cpu-13/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-14/cpu-idle:
+  value: 9.639002e+01
+w83df6500/cpu-14/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-14/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-14/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-14/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-14/cpu-system:
+  value: 2.999689e-01
+w83df6500/cpu-14/cpu-user:
+  value: 3.299658e+00
+w83df6500/cpu-14/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-15/cpu-idle:
+  value: 9.998962e+01
+w83df6500/cpu-15/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-15/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-15/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-15/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-15/cpu-system:
+  value: 0.000000e+00
+w83df6500/cpu-15/cpu-user:
+  value: 0.000000e+00
+w83df6500/cpu-15/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-16/cpu-idle:
+  value: 9.998964e+01
+w83df6500/cpu-16/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-16/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-16/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-16/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-16/cpu-system:
+  value: 0.000000e+00
+w83df6500/cpu-16/cpu-user:
+  value: 0.000000e+00
+w83df6500/cpu-16/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-17/cpu-idle:
+  value: 9.998943e+01
+w83df6500/cpu-17/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-17/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-17/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-17/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-17/cpu-system:
+  value: 0.000000e+00
+w83df6500/cpu-17/cpu-user:
+  value: 0.000000e+00
+w83df6500/cpu-17/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-18/cpu-idle:
+  value: 9.978947e+01
+w83df6500/cpu-18/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-18/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-18/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-18/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-18/cpu-system:
+  value: 0.000000e+00
+w83df6500/cpu-18/cpu-user:
+  value: 9.998947e-02
+w83df6500/cpu-18/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-19/cpu-idle:
+  value: 9.149020e+01
+w83df6500/cpu-19/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-19/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-19/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-19/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-19/cpu-system:
+  value: 3.299646e+00
+w83df6500/cpu-19/cpu-user:
+  value: 5.099453e+00
+w83df6500/cpu-19/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-2/cpu-idle:
+  value: 9.999229e+01
+w83df6500/cpu-2/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-2/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-2/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-2/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-2/cpu-system:
+  value: 0.000000e+00
+w83df6500/cpu-2/cpu-user:
+  value: 0.000000e+00
+w83df6500/cpu-2/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-20/cpu-idle:
+  value: 9.988926e+01
+w83df6500/cpu-20/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-20/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-20/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-20/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-20/cpu-system:
+  value: 0.000000e+00
+w83df6500/cpu-20/cpu-user:
+  value: 0.000000e+00
+w83df6500/cpu-20/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-21/cpu-idle:
+  value: 9.888932e+01
+w83df6500/cpu-21/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-21/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-21/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-21/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-21/cpu-system:
+  value: 9.998920e-02
+w83df6500/cpu-21/cpu-user:
+  value: 7.999136e-01
+w83df6500/cpu-21/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-22/cpu-idle:
+  value: 9.998916e+01
+w83df6500/cpu-22/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-22/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-22/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-22/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-22/cpu-system:
+  value: 9.998916e-02
+w83df6500/cpu-22/cpu-user:
+  value: 0.000000e+00
+w83df6500/cpu-22/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-23/cpu-idle:
+  value: 9.988925e+01
+w83df6500/cpu-23/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-23/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-23/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-23/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-23/cpu-system:
+  value: 0.000000e+00
+w83df6500/cpu-23/cpu-user:
+  value: 9.998923e-02
+w83df6500/cpu-23/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-3/cpu-idle:
+  value: 9.989136e+01
+w83df6500/cpu-3/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-3/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-3/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-3/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-3/cpu-system:
+  value: 0.000000e+00
+w83df6500/cpu-3/cpu-user:
+  value: 0.000000e+00
+w83df6500/cpu-3/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-4/cpu-idle:
+  value: 9.989094e+01
+w83df6500/cpu-4/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-4/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-4/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-4/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-4/cpu-system:
+  value: 0.000000e+00
+w83df6500/cpu-4/cpu-user:
+  value: 0.000000e+00
+w83df6500/cpu-4/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-5/cpu-idle:
+  value: 9.999060e+01
+w83df6500/cpu-5/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-5/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-5/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-5/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-5/cpu-system:
+  value: 0.000000e+00
+w83df6500/cpu-5/cpu-user:
+  value: 0.000000e+00
+w83df6500/cpu-5/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-6/cpu-idle:
+  value: 9.959022e+01
+w83df6500/cpu-6/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-6/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-6/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-6/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-6/cpu-system:
+  value: 9.999033e-02
+w83df6500/cpu-6/cpu-user:
+  value: 2.999711e-01
+w83df6500/cpu-6/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-7/cpu-idle:
+  value: 9.809048e+01
+w83df6500/cpu-7/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-7/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-7/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-7/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-7/cpu-system:
+  value: 4.999515e-01
+w83df6500/cpu-7/cpu-user:
+  value: 1.299874e+00
+w83df6500/cpu-7/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-8/cpu-idle:
+  value: 9.999017e+01
+w83df6500/cpu-8/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-8/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-8/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-8/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-8/cpu-system:
+  value: 0.000000e+00
+w83df6500/cpu-8/cpu-user:
+  value: 0.000000e+00
+w83df6500/cpu-8/cpu-wait:
+  value: 0.000000e+00
+w83df6500/cpu-9/cpu-idle:
+  value: 9.989011e+01
+w83df6500/cpu-9/cpu-interrupt:
+  value: 0.000000e+00
+w83df6500/cpu-9/cpu-nice:
+  value: 0.000000e+00
+w83df6500/cpu-9/cpu-softirq:
+  value: 0.000000e+00
+w83df6500/cpu-9/cpu-steal:
+  value: 0.000000e+00
+w83df6500/cpu-9/cpu-system:
+  value: 0.000000e+00
+w83df6500/cpu-9/cpu-user:
+  value: 0.000000e+00
+w83df6500/cpu-9/cpu-wait:
+  value: 0.000000e+00
+w83df6500/df-boot/df_complex-free:
+  value: 4.793876e+08
+w83df6500/df-boot/df_complex-reserved:
+  value: 2.684109e+07
+w83df6500/df-boot/df_complex-used:
+  value: 2.219622e+07
+w83df6500/df-boot/df_inodes-free:
+  value: 3.273000e+04
+w83df6500/df-boot/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6500/df-boot/df_inodes-used:
+  value: 3.800000e+01
+w83df6500/df-boot/percent_bytes-free:
+  value: 9.072010e+01
+w83df6500/df-boot/percent_bytes-reserved:
+  value: 5.079451e+00
+w83df6500/df-boot/percent_bytes-used:
+  value: 4.200449e+00
+w83df6500/df-boot/percent_inodes-free:
+  value: 9.988403e+01
+w83df6500/df-boot/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6500/df-boot/percent_inodes-used:
+  value: 1.159668e-01
+w83df6500/df-data1/df_complex-free:
+  value: 2.574625e+11
+w83df6500/df-data1/df_complex-reserved:
+  value: 1.378982e+10
+w83df6500/df-data1/df_complex-used:
+  value: 2.165883e+08
+w83df6500/df-data1/df_inodes-free:
+  value: 1.683452e+07
+w83df6500/df-data1/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6500/df-data1/df_inodes-used:
+  value: 4.300000e+01
+w83df6500/df-data1/percent_bytes-free:
+  value: 9.484052e+01
+w83df6500/df-data1/percent_bytes-reserved:
+  value: 5.079707e+00
+w83df6500/df-data1/percent_bytes-used:
+  value: 7.978383e-02
+w83df6500/df-data1/percent_inodes-free:
+  value: 9.999974e+01
+w83df6500/df-data1/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6500/df-data1/percent_inodes-used:
+  value: 2.554269e-04
+w83df6500/df-dev-shm/df_complex-free:
+  value: 3.375709e+10
+w83df6500/df-dev-shm/df_complex-reserved:
+  value: 0.000000e+00
+w83df6500/df-dev-shm/df_complex-used:
+  value: 0.000000e+00
+w83df6500/df-dev-shm/df_inodes-free:
+  value: 8.241475e+06
+w83df6500/df-dev-shm/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6500/df-dev-shm/df_inodes-used:
+  value: 1.000000e+00
+w83df6500/df-dev-shm/percent_bytes-free:
+  value: 1.000000e+02
+w83df6500/df-dev-shm/percent_bytes-reserved:
+  value: 0.000000e+00
+w83df6500/df-dev-shm/percent_bytes-used:
+  value: 0.000000e+00
+w83df6500/df-dev-shm/percent_inodes-free:
+  value: 9.999998e+01
+w83df6500/df-dev-shm/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6500/df-dev-shm/percent_inodes-used:
+  value: 1.213375e-05
+w83df6500/df-root/df_complex-free:
+  value: 1.055831e+10
+w83df6500/df-root/df_complex-reserved:
+  value: 6.442435e+08
+w83df6500/df-root/df_complex-used:
+  value: 1.480151e+09
+w83df6500/df-root/df_inodes-free:
+  value: 7.465750e+05
+w83df6500/df-root/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6500/df-root/df_inodes-used:
+  value: 3.985700e+04
+w83df6500/df-root/percent_bytes-free:
+  value: 8.324968e+01
+w83df6500/df-root/percent_bytes-reserved:
+  value: 5.079700e+00
+w83df6500/df-root/percent_bytes-used:
+  value: 1.167062e+01
+w83df6500/df-root/percent_inodes-free:
+  value: 9.493192e+01
+w83df6500/df-root/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6500/df-root/percent_inodes-used:
+  value: 5.068080e+00
+w83df6500/df-var/df_complex-free:
+  value: 7.641543e+09
+w83df6500/df-var/df_complex-reserved:
+  value: 4.294943e+08
+w83df6500/df-var/df_complex-used:
+  value: 3.840819e+08
+w83df6500/df-var/df_inodes-free:
+  value: 5.228880e+05
+w83df6500/df-var/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6500/df-var/df_inodes-used:
+  value: 1.400000e+03
+w83df6500/df-var/percent_bytes-free:
+  value: 9.037771e+01
+w83df6500/df-var/percent_bytes-reserved:
+  value: 5.079695e+00
+w83df6500/df-var/percent_bytes-used:
+  value: 4.542596e+00
+w83df6500/df-var/percent_inodes-free:
+  value: 9.973297e+01
+w83df6500/df-var/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6500/df-var/percent_inodes-used:
+  value: 2.670288e-01
+w83df6500/disk-sda/disk_merged:
+  read: 0.000000e+00
+  write: 7.199968e+00
+w83df6500/disk-sda/disk_octets:
+  read: 0.000000e+00
+  write: 3.850286e+04
+w83df6500/disk-sda/disk_ops:
+  read: 0.000000e+00
+  write: 2.200014e+00
+w83df6500/disk-sda/disk_time:
+  read: 0.000000e+00
+  write: 4.000026e-01
+w83df6500/disk-sda1/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6500/disk-sda1/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6500/disk-sda1/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6500/disk-sda1/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6500/disk-sda2/disk_merged:
+  read: 0.000000e+00
+  write: 2.299968e+00
+w83df6500/disk-sda2/disk_octets:
+  read: 0.000000e+00
+  write: 1.146866e+04
+w83df6500/disk-sda2/disk_ops:
+  read: 0.000000e+00
+  write: 4.999937e-01
+w83df6500/disk-sda2/disk_time:
+  read: 0.000000e+00
+  write: 1.999972e-01
+w83df6500/disk-sda3/disk_merged:
+  read: 0.000000e+00
+  write: 4.899926e+00
+w83df6500/disk-sda3/disk_octets:
+  read: 0.000000e+00
+  write: 2.703321e+04
+w83df6500/disk-sda3/disk_ops:
+  read: 0.000000e+00
+  write: 1.699975e+00
+w83df6500/disk-sda3/disk_time:
+  read: 0.000000e+00
+  write: 4.999926e-01
+w83df6500/disk-sda4/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6500/disk-sda4/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6500/disk-sda4/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6500/disk-sda4/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6500/disk-sda5/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6500/disk-sda5/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6500/disk-sda5/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6500/disk-sda5/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6500/disk-sda6/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6500/disk-sda6/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6500/disk-sda6/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6500/disk-sda6/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6500/load/load:
+  longterm: 2.000000e-02
+  midterm: 9.000000e-02
+  shortterm: 1.600000e-01
+w83df6500/memory/memory-buffered:
+  value: 4.858675e+07
+w83df6500/memory/memory-cached:
+  value: 7.746028e+08
+w83df6500/memory/memory-free:
+  value: 6.579641e+10
+w83df6500/memory/memory-used:
+  value: 8.945746e+08
+w83df6500/network/if_octets:
+  rx: 0.000000e+00
+  tx: 1.591300e+03
+w83df6500/network/if_packets:
+  rx: 0.000000e+00
+  tx: 1.199999e+00
+w83df6500/network/queue_length:
+  value: 0.000000e+00
+w83df6500/network/total_values-dispatch-accepted:
+  value: 0.000000e+00
+w83df6500/network/total_values-dispatch-rejected:
+  value: 0.000000e+00
+w83df6500/network/total_values-send-accepted:
+  value: 3.239995e+01
+w83df6500/network/total_values-send-rejected:
+  value: 0.000000e+00
+w83df6500/swap/swap-cached:
+  value: 0.000000e+00
+w83df6500/swap/swap-free:
+  value: 2.147475e+09
+w83df6500/swap/swap-used:
+  value: 0.000000e+00
+w83df6500/swap/swap_io-in:
+  value: 0.000000e+00
+w83df6500/swap/swap_io-out:
+  value: 0.000000e+00
+w83df6500/vmem/vmpage_faults:
+  majflt: 0.000000e+00
+  minflt: 1.747727e+04
+w83df6500/vmem/vmpage_io-memory:
+  in: 0.000000e+00
+  out: 3.759999e+01
+w83df6500/vmem/vmpage_io-swap:
+  in: 0.000000e+00
+  out: 0.000000e+00
+w83df6500/vmem/vmpage_number-active_anon:
+  value: 7.795900e+04
+w83df6500/vmem/vmpage_number-active_file:
+  value: 8.036800e+04
+w83df6500/vmem/vmpage_number-anon_pages:
+  value: 2.727800e+04
+w83df6500/vmem/vmpage_number-anon_transparent_hugepages:
+  value: 1.000000e+02
+w83df6500/vmem/vmpage_number-boudfe:
+  value: 0.000000e+00
+w83df6500/vmem/vmpage_number-dirty:
+  value: 3.920000e+02
+w83df6500/vmem/vmpage_number-file_pages:
+  value: 2.009740e+05
+w83df6500/vmem/vmpage_number-free_pages:
+  value: 1.606358e+07
+w83df6500/vmem/vmpage_number-inactive_anon:
+  value: 4.600000e+01
+w83df6500/vmem/vmpage_number-inactive_file:
+  value: 1.205540e+05
+w83df6500/vmem/vmpage_number-isolated_anon:
+  value: 0.000000e+00
+w83df6500/vmem/vmpage_number-isolated_file:
+  value: 0.000000e+00
+w83df6500/vmem/vmpage_number-kernel_stack:
+  value: 5.970000e+02
+w83df6500/vmem/vmpage_number-mapped:
+  value: 6.373000e+03
+w83df6500/vmem/vmpage_number-mlock:
+  value: 0.000000e+00
+w83df6500/vmem/vmpage_number-page_table_pages:
+  value: 1.091000e+03
+w83df6500/vmem/vmpage_number-shmem:
+  value: 4.800000e+01
+w83df6500/vmem/vmpage_number-slab_reclaimable:
+  value: 1.991400e+04
+w83df6500/vmem/vmpage_number-slab_unreclaimable:
+  value: 1.512500e+04
+w83df6500/vmem/vmpage_number-unevictable:
+  value: 0.000000e+00
+w83df6500/vmem/vmpage_number-unstable:
+  value: 0.000000e+00
+w83df6500/vmem/vmpage_number-vmscan_write:
+  value: 0.000000e+00
+w83df6500/vmem/vmpage_number-writeback:
+  value: 0.000000e+00
+w83df6500/vmem/vmpage_number-writeback_temp:
+  value: 0.000000e+00
+w83df6600/cpu-0/cpu-idle:
+  value: 9.980063e+01
+w83df6600/cpu-0/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-0/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-0/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-0/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-0/cpu-system:
+  value: 0.000000e+00
+w83df6600/cpu-0/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-0/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-1/cpu-idle:
+  value: 9.990608e+01
+w83df6600/cpu-1/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-1/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-1/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-1/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-1/cpu-system:
+  value: 0.000000e+00
+w83df6600/cpu-1/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-1/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-10/cpu-idle:
+  value: 9.991430e+01
+w83df6600/cpu-10/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-10/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-10/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-10/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-10/cpu-system:
+  value: 0.000000e+00
+w83df6600/cpu-10/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-10/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-11/cpu-idle:
+  value: 1.000143e+02
+w83df6600/cpu-11/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-11/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-11/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-11/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-11/cpu-system:
+  value: 0.000000e+00
+w83df6600/cpu-11/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-11/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-12/cpu-idle:
+  value: 1.000143e+02
+w83df6600/cpu-12/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-12/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-12/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-12/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-12/cpu-system:
+  value: 0.000000e+00
+w83df6600/cpu-12/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-12/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-13/cpu-idle:
+  value: 9.991410e+01
+w83df6600/cpu-13/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-13/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-13/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-13/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-13/cpu-system:
+  value: 0.000000e+00
+w83df6600/cpu-13/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-13/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-14/cpu-idle:
+  value: 1.000141e+02
+w83df6600/cpu-14/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-14/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-14/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-14/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-14/cpu-system:
+  value: 0.000000e+00
+w83df6600/cpu-14/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-14/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-15/cpu-idle:
+  value: 9.998509e+01
+w83df6600/cpu-15/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-15/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-15/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-15/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-15/cpu-system:
+  value: 0.000000e+00
+w83df6600/cpu-15/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-15/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-16/cpu-idle:
+  value: 9.998503e+01
+w83df6600/cpu-16/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-16/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-16/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-16/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-16/cpu-system:
+  value: 0.000000e+00
+w83df6600/cpu-16/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-16/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-17/cpu-idle:
+  value: 9.988509e+01
+w83df6600/cpu-17/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-17/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-17/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-17/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-17/cpu-system:
+  value: 0.000000e+00
+w83df6600/cpu-17/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-17/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-18/cpu-idle:
+  value: 9.988507e+01
+w83df6600/cpu-18/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-18/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-18/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-18/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-18/cpu-system:
+  value: 0.000000e+00
+w83df6600/cpu-18/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-18/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-19/cpu-idle:
+  value: 9.978521e+01
+w83df6600/cpu-19/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-19/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-19/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-19/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-19/cpu-system:
+  value: 0.000000e+00
+w83df6600/cpu-19/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-19/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-2/cpu-idle:
+  value: 9.999391e+01
+w83df6600/cpu-2/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-2/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-2/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-2/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-2/cpu-system:
+  value: 0.000000e+00
+w83df6600/cpu-2/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-2/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-20/cpu-idle:
+  value: 1.000140e+02
+w83df6600/cpu-20/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-20/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-20/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-20/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-20/cpu-system:
+  value: 0.000000e+00
+w83df6600/cpu-20/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-20/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-21/cpu-idle:
+  value: 1.000139e+02
+w83df6600/cpu-21/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-21/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-21/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-21/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-21/cpu-system:
+  value: 0.000000e+00
+w83df6600/cpu-21/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-21/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-22/cpu-idle:
+  value: 1.000138e+02
+w83df6600/cpu-22/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-22/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-22/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-22/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-22/cpu-system:
+  value: 0.000000e+00
+w83df6600/cpu-22/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-22/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-23/cpu-idle:
+  value: 1.000137e+02
+w83df6600/cpu-23/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-23/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-23/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-23/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-23/cpu-system:
+  value: 0.000000e+00
+w83df6600/cpu-23/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-23/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-3/cpu-idle:
+  value: 9.989001e+01
+w83df6600/cpu-3/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-3/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-3/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-3/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-3/cpu-system:
+  value: 0.000000e+00
+w83df6600/cpu-3/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-3/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-4/cpu-idle:
+  value: 9.998791e+01
+w83df6600/cpu-4/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-4/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-4/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-4/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-4/cpu-system:
+  value: 9.998773e-02
+w83df6600/cpu-4/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-4/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-5/cpu-idle:
+  value: 9.988613e+01
+w83df6600/cpu-5/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-5/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-5/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-5/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-5/cpu-system:
+  value: 9.998665e-02
+w83df6600/cpu-5/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-5/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-6/cpu-idle:
+  value: 9.988577e+01
+w83df6600/cpu-6/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-6/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-6/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-6/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-6/cpu-system:
+  value: 0.000000e+00
+w83df6600/cpu-6/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-6/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-7/cpu-idle:
+  value: 9.988529e+01
+w83df6600/cpu-7/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-7/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-7/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-7/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-7/cpu-system:
+  value: 3.999412e-01
+w83df6600/cpu-7/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-7/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-8/cpu-idle:
+  value: 9.998504e+01
+w83df6600/cpu-8/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-8/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-8/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-8/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-8/cpu-system:
+  value: 0.000000e+00
+w83df6600/cpu-8/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-8/cpu-wait:
+  value: 0.000000e+00
+w83df6600/cpu-9/cpu-idle:
+  value: 9.988501e+01
+w83df6600/cpu-9/cpu-interrupt:
+  value: 0.000000e+00
+w83df6600/cpu-9/cpu-nice:
+  value: 0.000000e+00
+w83df6600/cpu-9/cpu-softirq:
+  value: 0.000000e+00
+w83df6600/cpu-9/cpu-steal:
+  value: 0.000000e+00
+w83df6600/cpu-9/cpu-system:
+  value: 9.998501e-02
+w83df6600/cpu-9/cpu-user:
+  value: 0.000000e+00
+w83df6600/cpu-9/cpu-wait:
+  value: 0.000000e+00
+w83df6600/df-boot/df_complex-free:
+  value: 4.793631e+08
+w83df6600/df-boot/df_complex-reserved:
+  value: 2.684109e+07
+w83df6600/df-boot/df_complex-used:
+  value: 2.222080e+07
+w83df6600/df-boot/df_inodes-free:
+  value: 3.273000e+04
+w83df6600/df-boot/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6600/df-boot/df_inodes-used:
+  value: 3.800000e+01
+w83df6600/df-boot/percent_bytes-free:
+  value: 9.071545e+01
+w83df6600/df-boot/percent_bytes-reserved:
+  value: 5.079451e+00
+w83df6600/df-boot/percent_bytes-used:
+  value: 4.205100e+00
+w83df6600/df-boot/percent_inodes-free:
+  value: 9.988403e+01
+w83df6600/df-boot/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6600/df-boot/percent_inodes-used:
+  value: 1.159668e-01
+w83df6600/df-data1/df_complex-free:
+  value: 2.574625e+11
+w83df6600/df-data1/df_complex-reserved:
+  value: 1.378982e+10
+w83df6600/df-data1/df_complex-used:
+  value: 2.165883e+08
+w83df6600/df-data1/df_inodes-free:
+  value: 1.683452e+07
+w83df6600/df-data1/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6600/df-data1/df_inodes-used:
+  value: 4.300000e+01
+w83df6600/df-data1/percent_bytes-free:
+  value: 9.484052e+01
+w83df6600/df-data1/percent_bytes-reserved:
+  value: 5.079707e+00
+w83df6600/df-data1/percent_bytes-used:
+  value: 7.978383e-02
+w83df6600/df-data1/percent_inodes-free:
+  value: 9.999974e+01
+w83df6600/df-data1/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6600/df-data1/percent_inodes-used:
+  value: 2.554269e-04
+w83df6600/df-dev-shm/df_complex-free:
+  value: 3.375709e+10
+w83df6600/df-dev-shm/df_complex-reserved:
+  value: 0.000000e+00
+w83df6600/df-dev-shm/df_complex-used:
+  value: 0.000000e+00
+w83df6600/df-dev-shm/df_inodes-free:
+  value: 8.241475e+06
+w83df6600/df-dev-shm/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6600/df-dev-shm/df_inodes-used:
+  value: 1.000000e+00
+w83df6600/df-dev-shm/percent_bytes-free:
+  value: 1.000000e+02
+w83df6600/df-dev-shm/percent_bytes-reserved:
+  value: 0.000000e+00
+w83df6600/df-dev-shm/percent_bytes-used:
+  value: 0.000000e+00
+w83df6600/df-dev-shm/percent_inodes-free:
+  value: 9.999998e+01
+w83df6600/df-dev-shm/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6600/df-dev-shm/percent_inodes-used:
+  value: 1.213375e-05
+w83df6600/df-root/df_complex-free:
+  value: 1.055849e+10
+w83df6600/df-root/df_complex-reserved:
+  value: 6.442435e+08
+w83df6600/df-root/df_complex-used:
+  value: 1.479975e+09
+w83df6600/df-root/df_inodes-free:
+  value: 7.466050e+05
+w83df6600/df-root/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6600/df-root/df_inodes-used:
+  value: 3.982700e+04
+w83df6600/df-root/percent_bytes-free:
+  value: 8.325107e+01
+w83df6600/df-root/percent_bytes-reserved:
+  value: 5.079700e+00
+w83df6600/df-root/percent_bytes-used:
+  value: 1.166924e+01
+w83df6600/df-root/percent_inodes-free:
+  value: 9.493573e+01
+w83df6600/df-root/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6600/df-root/percent_inodes-used:
+  value: 5.064265e+00
+w83df6600/df-var/df_complex-free:
+  value: 7.642092e+09
+w83df6600/df-var/df_complex-reserved:
+  value: 4.294943e+08
+w83df6600/df-var/df_complex-used:
+  value: 3.835331e+08
+w83df6600/df-var/df_inodes-free:
+  value: 5.229150e+05
+w83df6600/df-var/df_inodes-reserved:
+  value: 0.000000e+00
+w83df6600/df-var/df_inodes-used:
+  value: 1.373000e+03
+w83df6600/df-var/percent_bytes-free:
+  value: 9.038420e+01
+w83df6600/df-var/percent_bytes-reserved:
+  value: 5.079695e+00
+w83df6600/df-var/percent_bytes-used:
+  value: 4.536105e+00
+w83df6600/df-var/percent_inodes-free:
+  value: 9.973812e+01
+w83df6600/df-var/percent_inodes-reserved:
+  value: 0.000000e+00
+w83df6600/df-var/percent_inodes-used:
+  value: 2.618790e-01
+w83df6600/disk-sda/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda1/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda1/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda1/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda1/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda2/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda2/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda2/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda2/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda3/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda3/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda3/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda3/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda4/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda4/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda4/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda4/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda5/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda5/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda5/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda5/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda6/disk_merged:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda6/disk_octets:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda6/disk_ops:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/disk-sda6/disk_time:
+  read: 0.000000e+00
+  write: 0.000000e+00
+w83df6600/load/load:
+  longterm: 0.000000e+00
+  midterm: 0.000000e+00
+  shortterm: 0.000000e+00
+w83df6600/memory/memory-buffered:
+  value: 4.378624e+07
+w83df6600/memory/memory-cached:
+  value: 7.730299e+08
+w83df6600/memory/memory-free:
+  value: 6.607691e+10
+w83df6600/memory/memory-used:
+  value: 6.204498e+08
+w83df6600/network/if_octets:
+  rx: 0.000000e+00
+  tx: 1.043100e+03
+w83df6600/network/if_packets:
+  rx: 0.000000e+00
+  tx: 7.999960e-01
+w83df6600/network/queue_length:
+  value: 0.000000e+00
+w83df6600/network/total_values-dispatch-accepted:
+  value: 0.000000e+00
+w83df6600/network/total_values-dispatch-rejected:
+  value: 0.000000e+00
+w83df6600/network/total_values-send-accepted:
+  value: 2.019973e+01
+w83df6600/network/total_values-send-rejected:
+  value: 0.000000e+00
+w83df6600/swap/swap-cached:
+  value: 0.000000e+00
+w83df6600/swap/swap-free:
+  value: 2.147475e+09
+w83df6600/swap/swap-used:
+  value: 0.000000e+00
+w83df6600/swap/swap_io-in:
+  value: 0.000000e+00
+w83df6600/swap/swap_io-out:
+  value: 0.000000e+00
+w83df6600/vmem/vmpage_faults:
+  majflt: 0.000000e+00
+  minflt: 8.999036e-01
+w83df6600/vmem/vmpage_io-memory:
+  in: 0.000000e+00
+  out: 0.000000e+00
+w83df6600/vmem/vmpage_io-swap:
+  in: 0.000000e+00
+  out: 0.000000e+00
+w83df6600/vmem/vmpage_number-active_anon:
+  value: 1.469200e+04
+w83df6600/vmem/vmpage_number-active_file:
+  value: 6.927600e+04
+w83df6600/vmem/vmpage_number-anon_pages:
+  value: 1.110500e+04
+w83df6600/vmem/vmpage_number-anon_transparent_hugepages:
+  value: 7.000000e+00
+w83df6600/vmem/vmpage_number-boudfe:
+  value: 0.000000e+00
+w83df6600/vmem/vmpage_number-dirty:
+  value: 9.000000e+00
+w83df6600/vmem/vmpage_number-file_pages:
+  value: 1.994180e+05
+w83df6600/vmem/vmpage_number-free_pages:
+  value: 1.613205e+07
+w83df6600/vmem/vmpage_number-inactive_anon:
+  value: 4.300000e+01
+w83df6600/vmem/vmpage_number-inactive_file:
+  value: 1.300980e+05
+w83df6600/vmem/vmpage_number-isolated_anon:
+  value: 0.000000e+00
+w83df6600/vmem/vmpage_number-isolated_file:
+  value: 0.000000e+00
+w83df6600/vmem/vmpage_number-kernel_stack:
+  value: 4.330000e+02
+w83df6600/vmem/vmpage_number-mapped:
+  value: 1.253000e+03
+w83df6600/vmem/vmpage_number-mlock:
+  value: 0.000000e+00
+w83df6600/vmem/vmpage_number-page_table_pages:
+  value: 4.520000e+02
+w83df6600/vmem/vmpage_number-shmem:
+  value: 4.600000e+01
+w83df6600/vmem/vmpage_number-slab_reclaimable:
+  value: 1.905300e+04
+w83df6600/vmem/vmpage_number-slab_unreclaimable:
+  value: 1.455200e+04
+w83df6600/vmem/vmpage_number-unevictable:
+  value: 0.000000e+00
+w83df6600/vmem/vmpage_number-unstable:
+  value: 0.000000e+00
+w83df6600/vmem/vmpage_number-vmscan_write:
+  value: 0.000000e+00
+w83df6600/vmem/vmpage_number-writeback:
+  value: 0.000000e+00
+w83df6600/vmem/vmpage_number-writeback_temp:
+  value: 0.000000e+00
index ea3cee99e16deeedb75b3de3efee0fe1592f15c2..4c7c3fe40f9d7de2b166471d58f1c91e14f792a7 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 199a47c5ae304515d2e1ac5b6c84f796bd55951e..5c6a5f9d24c74179b8c2e3a878619198398bdc73 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;
@@ -28,7 +33,7 @@ collectd's unixsock plugin.
 
 =head1 SYNOPSIS
 
-  use Collectd::Unixsock ();
+  use Collectd::Unixsock;
 
   my $sock = Collectd::Unixsock->new ($path);
 
@@ -51,23 +56,15 @@ programmers to interact with the daemon.
 use strict;
 use warnings;
 
-#use constant { NOTIF_FAILURE => 1, NOTIF_WARNING => 2, NOTIF_OKAY => 4 };
-
-use Carp (qw(cluck confess));
+use Carp qw(cluck confess carp croak);
 use IO::Socket::UNIX;
-use Regexp::Common (qw(number));
+use Scalar::Util qw( looks_like_number );
 
 our $Debug = 0;
 
-return (1);
-
 sub _debug
 {
-       if (!$Debug)
-       {
-               return;
-       }
-       print @_;
+       print @_ if $Debug;
 }
 
 sub _create_socket
@@ -84,88 +81,124 @@ sub _create_socket
 
 =head1 VALUE IDENTIFIERS
 
-The values in the collectd are identified using an five-tuple (host, plugin,
-plugin-instance, type, type-instance) where only plugin-instance and
-type-instance may be NULL (or undefined). Many functions expect an
-I<%identifier> hash that has at least the members B<host>, B<plugin>, and
-B<type>, possibly completed by B<plugin_instance> and B<type_instance>.
+The values in the collectd are identified using a five-tuple (host, plugin,
+plugin-instance, type, type-instance) where only plugin instance and type
+instance may be undef. Many functions expect an I<%identifier> hash that has at
+least the members B<host>, B<plugin>, and B<type>, possibly completed by
+B<plugin_instance> and B<type_instance>.
 
 Usually you can pass this hash as follows:
 
-  $obj->method (host => $host, plugin => $plugin, type => $type, %other_args);
+  $self->method (host => $host, plugin => $plugin, type => $type, %other_args);
 
 =cut
 
 sub _create_identifier
 {
        my $args = shift;
-       my $host;
-       my $plugin;
-       my $type;
+       my ($host, $plugin, $type);
 
-       if (!$args->{'host'} || !$args->{'plugin'} || !$args->{'type'})
+       if (!$args->{host} || !$args->{plugin} || !$args->{type})
        {
                cluck ("Need `host', `plugin' and `type'");
                return;
        }
 
-       $host = $args->{'host'};
-       $plugin = $args->{'plugin'};
-       $plugin .= '-' . $args->{'plugin_instance'} if (defined ($args->{'plugin_instance'}));
-       $type = $args->{'type'};
-       $type .= '-' . $args->{'type_instance'} if (defined ($args->{'type_instance'}));
+       $host = $args->{host};
+       $plugin = $args->{plugin};
+       $plugin .= '-' . $args->{plugin_instance} if defined $args->{plugin_instance};
+       $type = $args->{type};
+       $type .= '-' . $args->{type_instance} if defined $args->{type_instance};
 
-       return ("$host/$plugin/$type");
+       return "$host/$plugin/$type";
 } # _create_identifier
 
 sub _parse_identifier
 {
        my $string = shift;
-       my $host;
-       my $plugin;
-       my $plugin_instance;
-       my $type;
-       my $type_instance;
-       my $ident;
+       my ($plugin_instance, $type_instance);
 
-       ($host, $plugin, $type) = split ('/', $string);
+       my ($host, $plugin, $type) = split /\//, $string;
 
-       ($plugin, $plugin_instance) = split ('-', $plugin, 2);
-       ($type, $type_instance) = split ('-', $type, 2);
+       ($plugin, $plugin_instance) = split /-/, $plugin, 2;
+       ($type, $type_instance) = split /-/, $type, 2;
 
-       $ident =
+       my $ident =
        {
                host => $host,
                plugin => $plugin,
                type => $type
        };
-       $ident->{'plugin_instance'} = $plugin_instance if (defined ($plugin_instance));
-       $ident->{'type_instance'} = $type_instance if (defined ($type_instance));
+       $ident->{plugin_instance} = $plugin_instance if defined $plugin_instance;
+       $ident->{type_instance} = $type_instance if defined $type_instance;
 
-       return ($ident);
+       return $ident;
 } # _parse_identifier
 
 sub _escape_argument
 {
-       my $string = shift;
+       local $_ = shift;
+
+       return $_ if /^\w+$/;
+
+       s#\\#\\\\#g;
+       s#"#\\"#g;
+       return "\"$_\"";
+}
+
+# Send a command on a socket, including any required argument escaping.
+# Return a single line of result.
+sub _socket_command {
+       my ($self, $command, $args) = @_;
+
+       my $fh = $self->{sock} or confess ('object has no filehandle');
+
+    if($args) {
+        my $identifier = _create_identifier ($args) or return;
+           $command .= ' ' . _escape_argument ($identifier) . "\n";
+    } else {
+        $command .= "\n";
+    }
+       _debug "-> $command";
+       $fh->print($command);
+
+       my $response = $fh->getline;
+       chomp $response;
+       _debug "<- $response\n";
+    return $response;
+}
+
+# Read any remaining results from a socket and pass them to
+# a callback for caller-defined mangling.
+sub _socket_chat
+{
+       my ($self, $msg, $callback, $cbdata) = @_;
+       my ($nresults, $ret);
+       my $fh = $self->{sock} or confess ('object has no filehandle');
 
-       if ($string =~ m/^\w+$/)
+       ($nresults, $msg) = split / /, $msg, 2;
+       if ($nresults <= 0)
        {
-               return ("$string");
+               $self->{error} = $msg;
+               return;
        }
 
-       $string =~ s#\\#\\\\#g;
-       $string =~ s#"#\\"#g;
-       $string = "\"$string\"";
-
-       return ($string);
+       for (1 .. $nresults)
+       {
+               my $entry = $fh->getline;
+               chomp $entry;
+               _debug "<- $entry\n";
+        $callback->($entry, $cbdata);
+       }
+       return $cbdata;
 }
 
+
 =head1 PUBLIC METHODS
 
 =over 4
 
-=item I<$obj> = Collectd::Unixsock->B<new> ([I<$path>]);
+=item I<$self> = Collectd::Unixsock->B<new> ([I<$path>]);
 
 Creates a new connection to the daemon. The optional I<$path> argument gives
 the path to the UNIX socket of the C<unixsock plugin> and defaults to
@@ -176,19 +209,18 @@ false on error.
 
 sub new
 {
-       my $pkg = shift;
-       my $path = @_ ? shift : '/var/run/collectd-unixsock';
+       my $class = shift;
+       my $path = shift || '/var/run/collectd-unixsock';
        my $sock = _create_socket ($path) or return;
-       my $obj = bless (
+       return bless
                {
                        path => $path,
                        sock => $sock,
                        error => 'No error'
-               }, $pkg);
-       return ($obj);
+               }, $class;
 } # new
 
-=item I<$res> = I<$obj>-E<gt>B<getval> (I<%identifier>);
+=item I<$res> = I<$self>-E<gt>B<getval> (I<%identifier>);
 
 Requests a value-list from the daemon. On success a hash-ref is returned with
 the name of each data-source as the key and the according value as, well, the
@@ -198,53 +230,22 @@ value. On error false is returned.
 
 sub getval # {{{
 {
-       my $obj = shift;
+       my $self = shift;
        my %args = @_;
-
-       my $status;
-       my $fh = $obj->{'sock'} or confess ('object has no filehandle');
-       my $msg;
-       my $identifier;
-
        my $ret = {};
 
-       $identifier = _create_identifier (\%args) or return;
-
-       $msg = 'GETVAL ' . _escape_argument ($identifier) . "\n";
-       _debug "-> $msg";
-       print $fh $msg;
-
-       $msg = <$fh>;
-       chomp ($msg);
-       _debug "<- $msg\n";
-
-       ($status, $msg) = split (' ', $msg, 2);
-       if ($status <= 0)
-       {
-               $obj->{'error'} = $msg;
-               return;
-       }
-
-       for (my $i = 0; $i < $status; $i++)
-       {
-               my $entry = <$fh>;
-               chomp ($entry);
-               _debug "<- $entry\n";
-
-               if ($entry =~ m/^(\w+)=NaN$/)
-               {
-                       $ret->{$1} = undef;
-               }
-               elsif ($entry =~ m/^(\w+)=($RE{num}{real})$/)
-               {
-                       $ret->{$1} = 0.0 + $2;
-               }
-       }
-
-       return ($ret);
+    my $msg = $self->_socket_command('GETVAL', \%args) or return;
+    $self->_socket_chat($msg, sub {
+            local $_ = shift;
+            my $ret = shift;
+            /^(\w+)=NaN$/ and $ret->{$1} = undef, return;
+            /^(\w+)=(.*)$/ and looks_like_number($2) and $ret->{$1} = 0 + $2, return;
+        }, $ret
+    );
+       return $ret;
 } # }}} sub getval
 
-=item I<$res> = I<$obj>-E<gt>B<getthreshold> (I<%identifier>);
+=item I<$res> = I<$self>-E<gt>B<getthreshold> (I<%identifier>);
 
 Requests a threshold from the daemon. On success a hash-ref is returned with
 the threshold data. On error false is returned.
@@ -253,55 +254,24 @@ the threshold data. On error false is returned.
 
 sub getthreshold # {{{
 {
-       my $obj = shift;
+       my $self = shift;
        my %args = @_;
-
-       my $status;
-       my $fh = $obj->{'sock'} or confess ('object has no filehandle');
-       my $msg;
-       my $identifier;
-
        my $ret = {};
 
-       $identifier = _create_identifier (\%args) or return;
-
-       $msg = 'GETTHRESHOLD ' . _escape_argument ($identifier) . "\n";
-       _debug "-> $msg";
-       print $fh $msg;
-
-       $msg = <$fh>;
-       chomp ($msg);
-       _debug "<- $msg\n";
-
-       ($status, $msg) = split (' ', $msg, 2);
-       if ($status <= 0)
-       {
-               $obj->{'error'} = $msg;
-               return;
-       }
-
-       for (my $i = 0; $i < $status; $i++)
-       {
-               my $entry = <$fh>;
-               chomp ($entry);
-               _debug "<- $entry\n";
-
-               if ($entry =~ m/^([^:]+):\s*(\S.*)$/)
-               {
-                       my $key = $1;
-                       my $value = $2;
-
-                       $key =~ s/^\s+//;
-                       $key =~ s/\s+$//;
-
-                       $ret->{$key} = $value;
-               }
-       }
-
-       return ($ret);
+    my $msg = $self->_socket_command('GETTHRESHOLD', \%args) or return;
+    $self->_socket_chat($msg, sub {
+            local $_ = shift;
+            my $ret = shift;
+                   /^\s*([^:]+):\s*(.*)/ and do {
+                           $1 =~ s/\s*$//;
+                           $ret->{$1} = $2;
+                   };
+        }, $ret
+    );
+       return $ret;
 } # }}} sub getthreshold
 
-=item I<$obj>-E<gt>B<putval> (I<%identifier>, B<time> =E<gt> I<$time>, B<values> =E<gt> [...]);
+=item I<$self>-E<gt>B<putval> (I<%identifier>, B<time> =E<gt> I<$time>, B<values> =E<gt> [...]);
 
 Submits a value-list to the daemon. If the B<time> argument is omitted
 C<time()> is used. The required argument B<values> is a reference to an array
@@ -315,51 +285,44 @@ otherwise.
 
 sub putval
 {
-       my $obj = shift;
+       my $self = shift;
        my %args = @_;
 
-       my $status;
-       my $fh = $obj->{'sock'} or confess;
-       my $msg;
-       my $identifier;
-       my $values;
-       my $interval = "";
+       my ($status, $msg, $identifier, $values);
+       my $fh = $self->{sock} or confess;
 
-       if (defined $args{'interval'})
-       {
-               $interval = ' interval='
-               . _escape_argument ($args{'interval'});
-       }
+       my $interval = defined $args{interval} ?
+    ' interval=' . _escape_argument ($args{interval}) : '';
 
        $identifier = _create_identifier (\%args) or return;
-       if (!$args{'values'})
+       if (!$args{values})
        {
                cluck ("Need argument `values'");
                return;
        }
 
-       if (!ref ($args{'values'}))
-       {
-               $values = $args{'values'};
-       }
-       else
+       if (ref ($args{values}))
        {
                my $time;
 
-               if ("ARRAY" ne ref ($args{'values'}))
+               if ("ARRAY" ne ref ($args{values}))
                {
                        cluck ("Invalid `values' argument (expected an array ref)");
                        return;
                }
 
-               if (! scalar @{$args{'values'}})
+               if (! scalar @{$args{values}})
                {
                        cluck ("Empty `values' array");
                        return;
                }
 
-               $time = $args{'time'} ? $args{'time'} : time ();
-               $values = join (':', $time, map { defined ($_) ? $_ : 'U' } (@{$args{'values'}}));
+               $time = $args{time} || time;
+               $values = join (':', $time, map { defined $_ ? $_ : 'U' } @{$args{values}});
+       }
+       else
+       {
+               $values = $args{values};
        }
 
        $msg = 'PUTVAL '
@@ -367,20 +330,72 @@ sub putval
        . $interval
        . ' ' . _escape_argument ($values) . "\n";
        _debug "-> $msg";
-       print $fh $msg;
+       $fh->print($msg);
 
        $msg = <$fh>;
-       chomp ($msg);
+       chomp $msg;
        _debug "<- $msg\n";
 
-       ($status, $msg) = split (' ', $msg, 2);
-       return (1) if ($status == 0);
+       ($status, $msg) = split / /, $msg, 2;
+       return 1 if $status == 0;
 
-       $obj->{'error'} = $msg;
+       $self->{error} = $msg;
        return;
 } # putval
 
-=item I<$res> = I<$obj>-E<gt>B<listval> ()
+=item I<$res> = I<$self>-E<gt>B<listval_filter> ( C<%identifier> )
+
+Queries a list of values from the daemon while restricting the results to
+certain hosts, plugins etc. The argument may be anything that passes for an
+identifier (cf. L<VALUE IDENTIFIERS>), although all fields are optional.
+The returned data is in the same format as from C<listval>.
+
+=cut
+
+sub listval_filter
+{
+       my $self = shift;
+    my %args = @_;
+       my @ret;
+       my $nresults;
+       my $fh = $self->{sock} or confess;
+
+    my $pattern =
+    (exists $args{host}              ? "$args{host}"             : '[^/]+') .
+    (exists $args{plugin}            ? "/$args{plugin}"          : '/[^/-]+') .
+       (exists $args{plugin_instance}   ? "-$args{plugin_instance}" : '(?:-[^/]+)?') .
+       (exists $args{type}              ? "/$args{type}"            : '/[^/-]+') .
+       (exists $args{type_instance}     ? "-$args{type_instance}"   : '(?:-[^/]+)?');
+    $pattern = qr/^\d+ $pattern$/;
+
+    my $msg = $self->_socket_command('LISTVAL') or return;
+       ($nresults, $msg) = split / /, $msg, 2;
+
+    # This could use _socket_chat() but doesn't for speed reasons
+       if ($nresults < 0)
+       {
+               $self->{error} = $msg;
+               return;
+       }
+
+       for (1 .. $nresults)
+       {
+               $msg = <$fh>;
+               chomp $msg;
+               _debug "<- $msg\n";
+               next unless $msg =~ $pattern;
+               my ($time, $ident) = split / /, $msg, 2;
+
+               $ident = _parse_identifier ($ident);
+               $ident->{time} = int $time;
+
+               push (@ret, $ident);
+       } # for (i = 0 .. $status)
+
+       return @ret;
+} # listval
+
+=item I<$res> = I<$self>-E<gt>B<listval> ()
 
 Queries a list of values from the daemon. The list is returned as an array of
 hash references, where each hash reference is a valid identifier. The C<time>
@@ -390,46 +405,39 @@ member of each hash holds the epoch value of the last update of that value.
 
 sub listval
 {
-       my $obj = shift;
-       my $msg;
-       my @ret = ();
-       my $status;
-       my $fh = $obj->{'sock'} or confess;
+       my $self = shift;
+       my $nresults;
+       my @ret;
+       my $fh = $self->{sock} or confess;
 
-       _debug "LISTVAL\n";
-       print $fh "LISTVAL\n";
+    my $msg = $self->_socket_command('LISTVAL') or return;
+       ($nresults, $msg) = split / /, $msg, 2;
 
-       $msg = <$fh>;
-       chomp ($msg);
-       _debug "<- $msg\n";
-       ($status, $msg) = split (' ', $msg, 2);
-       if ($status < 0)
+    # This could use _socket_chat() but doesn't for speed reasons
+       if ($nresults < 0)
        {
-               $obj->{'error'} = $msg;
+               $self->{error} = $msg;
                return;
        }
 
-       for (my $i = 0; $i < $status; $i++)
+       for (1 .. $nresults)
        {
-               my $time;
-               my $ident;
-
                $msg = <$fh>;
-               chomp ($msg);
+               chomp $msg;
                _debug "<- $msg\n";
 
-               ($time, $ident) = split (' ', $msg, 2);
+               my ($time, $ident) = split / /, $msg, 2;
 
                $ident = _parse_identifier ($ident);
-               $ident->{'time'} = int ($time);
+               $ident->{time} = int $time;
 
                push (@ret, $ident);
        } # for (i = 0 .. $status)
 
-       return (@ret);
+       return @ret;
 } # listval
 
-=item I<$res> = I<$obj>-E<gt>B<putnotif> (B<severity> =E<gt> I<$severity>, B<message> =E<gt> I<$message>, ...);
+=item I<$res> = I<$self>-E<gt>B<putnotif> (B<severity> =E<gt> I<$severity>, B<message> =E<gt> I<$message>, ...);
 
 Submits a notification to the daemon.
 
@@ -464,57 +472,48 @@ For more details, please see L<collectd-unixsock(5)>.
 
 sub putnotif
 {
-       my $obj = shift;
+       my $self = shift;
        my %args = @_;
 
        my $status;
-       my $fh = $obj->{'sock'} or confess;
+       my $fh = $self->{sock} or confess;
 
        my $msg; # message sent to the socket
        
-       if (!$args{'message'})
-       {
-               cluck ("Need argument `message'");
-               return;
-       }
-       if (!$args{'severity'})
-       {
-               cluck ("Need argument `severity'");
-               return;
-       }
-       $args{'severity'} = lc ($args{'severity'});
-       if (($args{'severity'} ne 'failure')
-               && ($args{'severity'} ne 'warning')
-               && ($args{'severity'} ne 'okay'))
+    for my $arg (qw( message severity ))
+    {
+        cluck ("Need argument `$arg'"), return unless $args{$arg};
+    }
+       $args{severity} = lc $args{severity};
+       if (($args{severity} ne 'failure')
+               && ($args{severity} ne 'warning')
+               && ($args{severity} ne 'okay'))
        {
-               cluck ("Invalid `severity: " . $args{'severity'});
+               cluck ("Invalid `severity: " . $args{severity});
                return;
        }
 
-       if (!$args{'time'})
-       {
-               $args{'time'} = time ();
-       }
+       $args{time} ||= time;
        
        $msg = 'PUTNOTIF '
-       . join (' ', map { $_ . '=' . _escape_argument ($args{$_}) } (keys %args))
+       . join (' ', map { $_ . '=' . _escape_argument ($args{$_}) } keys %args)
        . "\n";
 
        _debug "-> $msg";
-       print $fh $msg;
+       $fh->print($msg);
 
        $msg = <$fh>;
-       chomp ($msg);
+       chomp $msg;
        _debug "<- $msg\n";
 
-       ($status, $msg) = split (' ', $msg, 2);
-       return (1) if ($status == 0);
+       ($status, $msg) = split / /, $msg, 2;
+       return 1 if $status == 0;
 
-       $obj->{'error'} = $msg;
+       $self->{error} = $msg;
        return;
 } # putnotif
 
-=item I<$obj>-E<gt>B<flush> (B<timeout> =E<gt> I<$timeout>, B<plugins> =E<gt> [...], B<identifier>  =E<gt> [...]);
+=item I<$self>-E<gt>B<flush> (B<timeout> =E<gt> I<$timeout>, B<plugins> =E<gt> [...], B<identifier>  =E<gt> [...]);
 
 Flush cached data.
 
@@ -544,48 +543,38 @@ are hash references and have the members as outlined in L<VALUE IDENTIFIERS>.
 
 sub flush
 {
-       my $obj  = shift;
+       my $self  = shift;
        my %args = @_;
 
-       my $fh = $obj->{'sock'} or confess;
+       my $fh = $self->{sock} or confess;
 
        my $status = 0;
        my $msg    = "FLUSH";
 
-       if (defined ($args{'timeout'}))
-       {
-               $msg .= " timeout=" . $args{'timeout'};
-       }
+    $msg .= " timeout=$args{timeout}" if defined $args{timeout};
 
-       if ($args{'plugins'})
+       if ($args{plugins})
        {
-               foreach my $plugin (@{$args{'plugins'}})
+               foreach my $plugin (@{$args{plugins}})
                {
                        $msg .= " plugin=" . $plugin;
                }
        }
 
-       if ($args{'identifier'})
+       if ($args{identifier})
        {
-               for (@{$args{'identifier'}})
+               for my $identifier (@{$args{identifier}})
                {
-                       my $identifier = $_;
                        my $ident_str;
 
                        if (ref ($identifier) ne 'HASH')
                        {
                                cluck ("The argument of the `identifier' "
-                                       . "option must be an array reference "
-                                       . "of hash references.");
-                               return;
-                       }
-
-                       $ident_str = _create_identifier ($identifier);
-                       if (!$ident_str)
-                       {
+                                       . "option must be an array of hashrefs.");
                                return;
                        }
 
+                       $ident_str = _create_identifier ($identifier) or return;
                        $msg .= ' identifier=' . _escape_argument ($ident_str);
                }
        }
@@ -593,30 +582,25 @@ sub flush
        $msg .= "\n";
 
        _debug "-> $msg";
-       print $fh $msg;
+       $fh->print($msg);
 
        $msg = <$fh>;
        chomp ($msg);
        _debug "<- $msg\n";
 
-       ($status, $msg) = split (' ', $msg, 2);
-       return (1) if ($status == 0);
+       ($status, $msg) = split / /, $msg, 2;
+       return 1 if $status == 0;
 
-       $obj->{'error'} = $msg;
+       $self->{error} = $msg;
        return;
 }
 
 sub error
 {
-       my $obj = shift;
-       if ($obj->{'error'})
-       {
-               return ($obj->{'error'});
-       }
-       return;
+       return shift->{error};
 }
 
-=item I<$obj>-E<gt>destroy ();
+=item I<$self>-E<gt>destroy ();
 
 Closes the socket before the object is destroyed. This function is also
 automatically called then the object goes out of scope.
@@ -627,18 +611,18 @@ automatically called then the object goes out of scope.
 
 sub destroy
 {
-       my $obj = shift;
-       if ($obj->{'sock'})
+       my $self = shift;
+       if ($self->{sock})
        {
-               close ($obj->{'sock'});
-               delete ($obj->{'sock'});
+               close $self->{sock};
+               delete $self->{sock};
        }
 }
 
 sub DESTROY
 {
-       my $obj = shift;
-       $obj->destroy ();
+       my $self = shift;
+       $self->destroy ();
 }
 
 =head1 SEE ALSO
@@ -649,8 +633,8 @@ 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
-
+1;
 # vim: set fdm=marker :
diff --git a/bindings/perl/t/00_load.t b/bindings/perl/t/00_load.t
new file mode 100644 (file)
index 0000000..b40bbdd
--- /dev/null
@@ -0,0 +1,6 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More tests => 1;
+use_ok 'Collectd::Unixsock';
diff --git a/bindings/perl/t/01_methods.t b/bindings/perl/t/01_methods.t
new file mode 100644 (file)
index 0000000..2f7818b
--- /dev/null
@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More tests => 14;
+use Collectd::Unixsock;
+use Collectd::MockDaemon;
+
+my $path = mockd_start();
+END { mockd_stop(); }
+
+sub filter_time { return map { delete $_->{time}; $_ } @_ }
+
+sub test_query {
+    my ($s, $attr, $results) = @_;
+    my ($nresults, $resultdata) = @$results;
+    my $r = $s->getval(%{Collectd::Unixsock::_parse_identifier($attr)});
+    is(ref $r, 'HASH', "Got a result for $attr");
+    is(scalar keys $r, $nresults, "$nresults result result for $attr");
+    is_deeply($r, $resultdata, "Data or $attr matches");
+}
+
+my $s = Collectd::Unixsock->new($path);
+isnt($s, undef, "Collectd::Unixsock object created");
+
+my %queries = (
+    'w83df6600/vmem/vmpage_number-vmscan_write' => [ 1, { value => 0 } ],
+    'a1d8f6310/load/load' => [ 3, { longterm => '0.07', shortterm => 0, midterm => '0.06' } ],
+    'w83df6600/disk-sda/disk_octets' => [ 2, { read => 0, write => 0 } ],
+);
+
+test_query($s, $_, $queries{$_}) for sort keys %queries;
+
+my @values = $s->listval;
+is(scalar @values, 4984, "Correct number of results from LISTVAL");
+delete $values[1234]{time};     # won't be constant
+is_deeply($values[1234], {
+        type_instance => 'nice',
+        plugin_instance => 21,
+        plugin => 'cpu',
+        type => 'cpu',
+        host => 'h2gdf6120'
+    }, "Correct data returned for select element");
+@values = ();
+
+is_deeply([ filter_time $s->listval_filter() ] , [ filter_time $s->listval ], "listval_filter() w/o filter equivalent to listval()");
+is_deeply(
+    [ filter_time $s->listval_filter(host => 'a1d8f6310', plugin => 'disk', plugin_instance => 'vda6') ],
+    [
+        { 'plugin_instance' => 'vda6', 'type' => 'disk_merged', 'plugin' => 'disk', 'host' => 'a1d8f6310' },
+        { 'host' => 'a1d8f6310', 'plugin' => 'disk', 'plugin_instance' => 'vda6', 'type' => 'disk_octets' },
+        { 'type' => 'disk_ops', 'plugin_instance' => 'vda6', 'plugin' => 'disk', 'host' => 'a1d8f6310' },
+        { 'plugin' => 'disk', 'host' => 'a1d8f6310', 'type' => 'disk_time', 'plugin_instance' => 'vda6' }
+    ],
+    "Correct result from listval_filter on <host>, <plugin> and <plugin_instance>"
+);
+
+# TODO more test for putval() and the like
+
index 46e8c29e54897fe14dd7c25894f7e98de6478ded..6780cdabfc9bc4b134b9bbc39cea998d88e420d3 100755 (executable)
--- a/clean.sh
+++ b/clean.sh
@@ -27,7 +27,6 @@ true \
 && rm -f src/*.o \
 && rm -f src/*.la \
 && rm -f src/*.lo \
-&& rm -f src/collectd \
 && rm -f src/collectd.1 \
 && rm -f src/collectd.conf \
 && rm -f src/collectdctl \
@@ -44,6 +43,21 @@ true \
 && rm -f src/*.pb-c.c \
 && rm -f src/*.pb-c.h \
 && rm -f src/Makefile.in \
+&& rm -f src/test-suite.log \
+&& rm -f src/test_common* \
+&& rm -f src/test_utils* \
+&& rm -f -r src/tests/.deps \
+&& rm -f -r src/tests/mock/.deps \
+&& rm -f src/tests/*.o \
+&& rm -f src/tests/mock/*.o \
+&& rm -f -r src/daemon/.deps \
+&& rm -f -r src/daemon/.libs \
+&& rm -f src/daemon/*.o \
+&& rm -f src/daemon/*.la \
+&& rm -f src/daemon/*.lo \
+&& rm -f src/daemon/collectd \
+&& rm -f src/daemon/Makefile.in \
+&& rm -f src/daemon/Makefile \
 && rm -f src/liboconfig/*.o \
 && rm -f src/liboconfig/*.la \
 && rm -f src/liboconfig/*.lo \
index 22c883893b053ee85206f71e60b117dcb5684291..553aa0ab25ee332c6759fc4246e6857a70fa00f7 100644 (file)
@@ -1,6 +1,6 @@
 dnl Process this file with autoconf to produce a configure script.
 AC_INIT([collectd],[m4_esyscmd(./version-gen.sh)])
-AC_CONFIG_SRCDIR(src/collectd.c)
+AC_CONFIG_SRCDIR(src/)
 AC_CONFIG_HEADERS(src/config.h)
 AC_CONFIG_AUX_DIR([libltdl/config])
 
@@ -70,9 +70,11 @@ case $host_os in
        ac_system="Solaris"
        ;;
        *darwin*)
+       AC_DEFINE([KERNEL_DARWIN], 1, [True if program is to be compiled for a Darwin kernel])
        ac_system="Darwin"
        ;;
        *openbsd*)
+       AC_DEFINE([KERNEL_OPENBSD], 1, [True if program is to be compiled for an OpenBSD kernel])
        ac_system="OpenBSD"
        ;;
        *aix*)
@@ -88,6 +90,13 @@ case $host_os in
 esac
 AC_MSG_RESULT([$ac_system])
 
+AM_CONDITIONAL([BUILD_LINUX],[test "x$x$ac_system" = "xLinux"])
+AM_CONDITIONAL([BUILD_SOLARIS],[test "x$x$ac_system" = "xSolaris"])
+AM_CONDITIONAL([BUILD_DARWIN],[test "x$x$ac_system" = "xDarwin"])
+AM_CONDITIONAL([BUILD_OPENBSD],[test "x$x$ac_system" = "xOpenBSD"])
+AM_CONDITIONAL([BUILD_AIX],[test "x$x$ac_system" = "xAIX"])
+AM_CONDITIONAL([BUILD_FREEBSD],[test "x$x$ac_system" = "xFreeBSD"])
+
 if test "x$ac_system" = "xLinux"
 then
        AC_ARG_VAR([KERNEL_DIR], [path to Linux kernel sources])
@@ -104,7 +113,20 @@ if test "x$ac_system" = "xSolaris"
 then
        AC_DEFINE(_POSIX_PTHREAD_SEMANTICS, 1, [Define to enforce POSIX thread semantics under Solaris.])
        AC_DEFINE(_REENTRANT,               1, [Define to enable reentrancy interfaces.])
+
+       AC_MSG_CHECKING([whether compiler builds 64bit binaries])
+       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
+                          #ifndef _LP64
+                          # error "Compiler not in 64bit mode."
+                          #endif
+                          ])],
+                          [AC_MSG_RESULT([yes])],
+                          [
+                           AC_MSG_RESULT([no])
+                           AC_MSG_NOTICE([Solaris detected. Please consider building a 64-bit binary.])
+                          ])
 fi
+
 if test "x$ac_system" = "xAIX"
 then
        AC_DEFINE(_THREAD_SAFE_ERRNO, 1, [Define to use the thread-safe version of errno under AIX.])
@@ -415,18 +437,6 @@ AC_CHECK_HEADERS(sys/swap.h vm/anon.h, [], [have_sys_swap_h="no"],
 #endif
 ])
 
-if test "x$have_sys_swap_h$ac_system" = "xnoSolaris"
-then
-       hint_64=""
-       if test "x$GCC" = "xyes"
-       then
-               hint_64="CFLAGS='-m64'"
-       else
-               hint_64="CFLAGS='-xarch=v9'"
-       fi
-       AC_MSG_NOTICE([Solaris detected and sys/swap.h not usable. Try building a 64-bit binary ($hint_64 ./configure).])
-fi
-
 # For load module
 # For the processes plugin
 # For users module
@@ -566,7 +576,7 @@ AC_CHECK_HEADERS(linux/un.h, [], [],
 #endif
 ])
 
-AC_CHECK_HEADERS(pwd.h grp.h sys/un.h ctype.h limits.h xfs/xqm.h fs_info.h fshelp.h paths.h mntent.h mnttab.h sys/fstyp.h sys/fs_types.h sys/mntent.h sys/mnttab.h sys/statfs.h sys/statvfs.h sys/vfs.h sys/vfstab.h kvm.h wordexp.h)
+AC_CHECK_HEADERS(pwd.h grp.h sys/un.h ctype.h limits.h xfs/xqm.h fs_info.h fshelp.h paths.h mntent.h mnttab.h sys/fstyp.h sys/fs_types.h sys/mntent.h sys/mnttab.h sys/statfs.h sys/statvfs.h sys/vfs.h sys/vfstab.h sys/vmmeter.h kvm.h wordexp.h locale.h)
 
 # For the dns plugin
 AC_CHECK_HEADERS(arpa/nameser.h)
@@ -628,20 +638,51 @@ AC_CHECK_HEADERS(net/pfvar.h,
 have_termios_h="no"
 AC_CHECK_HEADERS(termios.h, [have_termios_h="yes"])
 
+# For the turbostat plugin
+have_asm_msrindex_h="no"
+AC_CHECK_HEADERS(asm/msr-index.h, [have_asm_msrindex_h="yes"])
+
+if test "x$have_asm_msrindex_h" = "xyes"
+then
+  AC_CACHE_CHECK([whether asm/msr-index.h has MSR_PKG_C10_RESIDENCY],
+                 [c_cv_have_usable_asm_msrindex_h],
+                 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+[[[
+#include<asm/msr-index.h>
+]]],
+[[[
+int y = MSR_PKG_C10_RESIDENCY;
+return(y);
+]]]
+  )],
+                 [c_cv_have_usable_asm_msrindex_h="yes"],
+                 [c_cv_have_usable_asm_msrindex_h="no"],
+                                  )
+                 )
+fi
+
+have_cpuid_h="no"
+AC_CHECK_HEADERS(cpuid.h, [have_cpuid_h="yes"])
+
+AC_CHECK_HEADERS(sys/capability.h)
 #
 # Checks for typedefs, structures, and compiler characteristics.
 #
 AC_C_CONST
+AC_C_INLINE
+AC_TYPE_OFF_T
 AC_TYPE_PID_T
 AC_TYPE_SIZE_T
+AC_TYPE_SSIZE_T
 AC_TYPE_UID_T
+AC_TYPE_UINT32_T
 AC_HEADER_TIME
 
 #
 # Checks for library functions.
 #
 AC_PROG_GCC_TRADITIONAL
-AC_CHECK_FUNCS(gettimeofday select strdup strtol getaddrinfo getnameinfo strchr memcpy strstr strcmp strncmp strncpy strlen strncasecmp strcasecmp openlog closelog sysconf setenv if_indextoname)
+AC_CHECK_FUNCS(gettimeofday select strdup strtol getaddrinfo getnameinfo strchr memcpy strstr strcmp strncmp strncpy strlen strncasecmp strcasecmp openlog closelog sysconf setenv if_indextoname setlocale)
 
 AC_FUNC_STRERROR_R
 
@@ -848,7 +889,9 @@ if test "x$have_swapctl" = "xyes"; then
 #  undef _LARGEFILE64_SOURCE
 #endif
 #include <sys/stat.h>
+#include <sys/param.h>
 #include <sys/swap.h>
+#include <unistd.h>
 ]]],
 [[[
 int num = swapctl(0, NULL);
@@ -868,7 +911,9 @@ int num = swapctl(0, NULL);
 #  undef _LARGEFILE64_SOURCE
 #endif
 #include <sys/stat.h>
+#include <sys/param.h>
 #include <sys/swap.h>
+#include <unistd.h>
 ]]],
 [[[
 int num = swapctl(0, NULL, 0);
@@ -1041,7 +1086,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;
@@ -1096,7 +1141,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);
@@ -1145,7 +1190,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);
@@ -1182,6 +1227,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"
@@ -1285,7 +1341,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
@@ -1341,7 +1397,7 @@ AC_CHECK_MEMBERS([struct kinfo_proc.ki_pid, struct kinfo_proc.ki_rssize, struct
 #include <sys/user.h>
        ])
 
-AC_CHECK_MEMBERS([struct kinfo_proc.kp_proc, struct kinfo_proc.kp_eproc],
+AC_CHECK_MEMBERS([struct kinfo_proc.p_pid, struct kinfo_proc.p_vm_rssize],
        [
                AC_DEFINE(HAVE_STRUCT_KINFO_PROC_OPENBSD, 1,
                        [Define if struct kinfo_proc exists in the OpenBSD variant.])
@@ -1358,6 +1414,7 @@ AC_CHECK_MEMBERS([struct kinfo_proc.kp_proc, struct kinfo_proc.kp_eproc],
 
 AC_CHECK_MEMBERS([struct udphdr.uh_dport, struct udphdr.uh_sport], [], [],
 [#define _BSD_SOURCE
+#define _DEFAULT_SOURCE
 #if HAVE_STDINT_H
 # include <stdint.h>
 #endif
@@ -1379,6 +1436,7 @@ AC_CHECK_MEMBERS([struct udphdr.uh_dport, struct udphdr.uh_sport], [], [],
 ])
 AC_CHECK_MEMBERS([struct udphdr.dest, struct udphdr.source], [], [],
 [#define _BSD_SOURCE
+#define _DEFAULT_SOURCE
 #if HAVE_STDINT_H
 # include <stdint.h>
 #endif
@@ -1437,10 +1495,6 @@ fi
 m4_divert_once([HELP_WITH], [
 collectd additional packages:])
 
-AM_CONDITIONAL([BUILD_FREEBSD],[test "x$x$ac_system" = "xFreeBSD"])
-
-AM_CONDITIONAL([BUILD_AIX],[test "x$x$ac_system" = "xAIX"]) 
-
 if test "x$ac_system" = "xAIX"
 then
        with_perfstat="yes"
@@ -1607,62 +1661,63 @@ fi
 AM_CONDITIONAL(BUILD_WITH_LIBAQUAERO5, test "x$with_libaquaero5" = "xyes")
 # }}}
 
-# --with-libcredis {{{
-AC_ARG_WITH(libcredis, [AS_HELP_STRING([--with-libcredis@<:@=PREFIX@:>@], [Path to libcredis.])],
+# --with-libhiredis {{{
+AC_ARG_WITH(libhiredis, [AS_HELP_STRING([--with-libhiredis@<:@=PREFIX@:>@],
+      [Path to libhiredis.])],
 [
  if test "x$withval" = "xyes"
  then
-        with_libcredis="yes"
+        with_libhiredis="yes"
  else if test "x$withval" = "xno"
  then
-        with_libcredis="no"
+        with_libhiredis="no"
  else
-        with_libcredis="yes"
-        LIBCREDIS_CPPFLAGS="$LIBCREDIS_CPPFLAGS -I$withval/include"
-        LIBCREDIS_LDFLAGS="$LIBCREDIS_LDFLAGS -L$withval/lib"
+        with_libhiredis="yes"
+        LIBHIREDIS_CPPFLAGS="$LIBHIREDIS_CPPFLAGS -I$withval/include"
+        LIBHIREDIS_LDFLAGS="$LIBHIREDIS_LDFLAGS -L$withval/lib"
  fi; fi
 ],
-[with_libcredis="yes"])
+[with_libhiredis="yes"])
 
 SAVE_CPPFLAGS="$CPPFLAGS"
 SAVE_LDFLAGS="$LDFLAGS"
 
-CPPFLAGS="$CPPFLAGS $LIBCREDIS_CPPFLAGS"
-LDFLAGS="$LDFLAGS $LIBCREDIS_LDFLAGS"
+CPPFLAGS="$CPPFLAGS $LIBHIREDIS_CPPFLAGS"
+LDFLAGS="$LDFLAGS $LIBHIREDIS_LDFLAGS"
 
-if test "x$with_libcredis" = "xyes"
+if test "x$with_libhiredis" = "xyes"
 then
-       if test "x$LIBCREDIS_CPPFLAGS" != "x"
+       if test "x$LIBHIREDIS_CPPFLAGS" != "x"
        then
-               AC_MSG_NOTICE([libcredis CPPFLAGS: $LIBCREDIS_CPPFLAGS])
+               AC_MSG_NOTICE([libhiredis CPPFLAGS: $LIBHIREDIS_CPPFLAGS])
        fi
-       AC_CHECK_HEADERS(credis.h,
-       [with_libcredis="yes"],
-       [with_libcredis="no (credis.h not found)"])
+       AC_CHECK_HEADERS(hiredis/hiredis.h,
+       [with_libhiredis="yes"],
+       [with_libhiredis="no (hiredis.h not found)"])
 fi
-if test "x$with_libcredis" = "xyes"
+if test "x$with_libhiredis" = "xyes"
 then
-       if test "x$LIBCREDIS_LDFLAGS" != "x"
+       if test "x$LIBHIREDIS_LDFLAGS" != "x"
        then
-               AC_MSG_NOTICE([libcredis LDFLAGS: $LIBCREDIS_LDFLAGS])
+               AC_MSG_NOTICE([libhiredis LDFLAGS: $LIBHIREDIS_LDFLAGS])
        fi
-       AC_CHECK_LIB(credis, credis_info,
-       [with_libcredis="yes"],
-       [with_libcredis="no (symbol 'credis_info' not found)"])
+       AC_CHECK_LIB(hiredis, redisCommand,
+       [with_libhiredis="yes"],
+       [with_libhiredis="no (symbol 'redisCommand' not found)"])
 
 fi
 
 CPPFLAGS="$SAVE_CPPFLAGS"
 LDFLAGS="$SAVE_LDFLAGS"
 
-if test "x$with_libcredis" = "xyes"
+if test "x$with_libhiredis" = "xyes"
 then
-       BUILD_WITH_LIBCREDIS_CPPFLAGS="$LIBCREDIS_CPPFLAGS"
-       BUILD_WITH_LIBCREDIS_LDFLAGS="$LIBCREDIS_LDFLAGS"
-       AC_SUBST(BUILD_WITH_LIBCREDIS_CPPFLAGS)
-       AC_SUBST(BUILD_WITH_LIBCREDIS_LDFLAGS)
+       BUILD_WITH_LIBHIREDIS_CPPFLAGS="$LIBHIREDIS_CPPFLAGS"
+       BUILD_WITH_LIBHIREDIS_LDFLAGS="$LIBHIREDIS_LDFLAGS"
+       AC_SUBST(BUILD_WITH_LIBHIREDIS_CPPFLAGS)
+       AC_SUBST(BUILD_WITH_LIBHIREDIS_LDFLAGS)
 fi
-AM_CONDITIONAL(BUILD_WITH_LIBCREDIS, test "x$with_libcredis" = "xyes")
+AM_CONDITIONAL(BUILD_WITH_LIBHIREDIS, test "x$with_libhiredis" = "xyes")
 # }}}
 
 # --with-libcurl {{{
@@ -1723,6 +1778,14 @@ then
                 [with_libcurl="yes"],
                 [with_libcurl="no (symbol 'curl_easy_init' not found)"],
                 [$with_curl_libs])
+               AC_CHECK_DECL(CURLOPT_USERNAME,
+                [have_curlopt_username="yes"],
+                [have_curlopt_username="no"],
+                [[#include <curl/curl.h>]])
+               AC_CHECK_DECL(CURLOPT_TIMEOUT_MS,
+                [have_curlopt_timeout="yes"],
+                [have_curlopt_timeout="no"],
+                [[#include <curl/curl.h>]])
        fi
 fi
 if test "x$with_libcurl" = "xyes"
@@ -1731,6 +1794,16 @@ then
        BUILD_WITH_LIBCURL_LIBS="$with_curl_libs"
        AC_SUBST(BUILD_WITH_LIBCURL_CFLAGS)
        AC_SUBST(BUILD_WITH_LIBCURL_LIBS)
+
+       if test "x$have_curlopt_username" = "xyes"
+       then
+               AC_DEFINE(HAVE_CURLOPT_USERNAME, 1, [Define if libcurl supports CURLOPT_USERNAME option.])
+       fi
+
+       if test "x$have_curlopt_timeout" = "xyes"
+       then
+               AC_DEFINE(HAVE_CURLOPT_TIMEOUT_MS, 1, [Define if libcurl supports CURLOPT_TIMEOUT_MS option.])
+       fi
 fi
 AM_CONDITIONAL(BUILD_WITH_LIBCURL, test "x$with_libcurl" = "xyes")
 # }}}
@@ -1999,10 +2072,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"
@@ -2012,7 +2082,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"
@@ -2084,28 +2154,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
@@ -2289,6 +2337,64 @@ AC_SUBST(JAVA_LIBS)
 AM_CONDITIONAL(BUILD_WITH_JAVA, test "x$with_java" = "xyes")
 # }}}
 
+# --with-libldap {{{
+AC_ARG_WITH(libldap, [AS_HELP_STRING([--with-libldap@<:@=PREFIX@:>@], [Path to libldap.])],
+[
+ if test "x$withval" = "xyes"
+ then
+        with_libldap="yes"
+ else if test "x$withval" = "xno"
+ then
+        with_libldap="no"
+ else
+        with_libldap="yes"
+        LIBLDAP_CPPFLAGS="$LIBLDAP_CPPFLAGS -I$withval/include"
+        LIBLDAP_LDFLAGS="$LIBLDAP_LDFLAGS -L$withval/lib"
+ fi; fi
+],
+[with_libldap="yes"])
+
+SAVE_CPPFLAGS="$CPPFLAGS"
+SAVE_LDFLAGS="$LDFLAGS"
+
+CPPFLAGS="$CPPFLAGS $LIBLDAP_CPPFLAGS"
+LDFLAGS="$LDFLAGS $LIBLDAP_LDFLAGS"
+
+if test "x$with_libldap" = "xyes"
+then
+       if test "x$LIBLDAP_CPPFLAGS" != "x"
+       then
+               AC_MSG_NOTICE([libldap CPPFLAGS: $LIBLDAP_CPPFLAGS])
+       fi
+       AC_CHECK_HEADERS(ldap.h,
+       [with_libldap="yes"],
+       [with_libldap="no ('ldap.h' not found)"])
+fi
+if test "x$with_libldap" = "xyes"
+then
+       if test "x$LIBLDAP_LDFLAGS" != "x"
+       then
+               AC_MSG_NOTICE([libldap LDFLAGS: $LIBLDAP_LDFLAGS])
+       fi
+       AC_CHECK_LIB(ldap, ldap_initialize,
+       [with_libldap="yes"],
+       [with_libldap="no (symbol 'ldap_initialize' not found)"])
+
+fi
+
+CPPFLAGS="$SAVE_CPPFLAGS"
+LDFLAGS="$SAVE_LDFLAGS"
+
+if test "x$with_libldap" = "xyes"
+then
+       BUILD_WITH_LIBLDAP_CPPFLAGS="$LIBLDAP_CPPFLAGS"
+       BUILD_WITH_LIBLDAP_LDFLAGS="$LIBLDAP_LDFLAGS"
+       AC_SUBST(BUILD_WITH_LIBLDAP_CPPFLAGS)
+       AC_SUBST(BUILD_WITH_LIBLDAP_LDFLAGS)
+fi
+AM_CONDITIONAL(BUILD_WITH_LIBLDAP, test "x$with_libldap" = "xyes")
+# }}}
+
 # --with-liblvm2app {{{
 with_liblvm2app_cppflags=""
 with_liblvm2app_ldflags=""
@@ -2323,7 +2429,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"
@@ -2724,6 +2830,15 @@ return (retval);
        [AC_DEFINE([HAVE_TCA_STATS], 1, [True if the enum-member TCA_STATS exists])])
 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"],
@@ -2848,7 +2963,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"
@@ -3075,7 +3190,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"
@@ -3086,7 +3201,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"
@@ -3687,6 +3802,68 @@ 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_rpath="$withval/lib"
+    with_librdkafka="yes"
+  else
+    with_librdkafka="$withval"
+  fi
+],
+[
+  with_librdkafka="yes"
+])
+SAVE_CPPFLAGS="$CPPFLAGS"
+SAVE_LDFLAGS="$LDFLAGS"
+
+CPPFLAGS="$CPPFLAGS $with_librdkafka_cppflags"
+LDFLAGS="$LDFLAGS $with_librdkafka_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_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"
+       if test "x$with_librdkafka_rpath" != "x"
+       then
+               BUILD_WITH_LIBRDKAFKA_LIBS="-Wl,-rpath,$with_librdkafka_rpath -lrdkafka"
+       else
+               BUILD_WITH_LIBRDKAFKA_LIBS="-lrdkafka"
+       fi
+       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.])],
 [
@@ -4058,6 +4235,36 @@ then
   LDFLAGS="$SAVE_LDFLAGS"
 fi
 
+if test "x$with_libstatgrab" = "xyes"
+then
+  SAVE_CFLAGS="$CFLAGS"
+  SAVE_LIBS="$LIBS"
+
+  CFLAGS="$CFLAGS $with_libstatgrab_cflags"
+  LDFLAGS="$LDFLAGS $with_libstatgrab_ldflags"
+  LIBS="-lstatgrab $LIBS"
+
+  AC_CACHE_CHECK([if libstatgrab >= 0.90],
+          [c_cv_have_libstatgrab_0_90],
+          AC_LINK_IFELSE([AC_LANG_PROGRAM(
+[[[
+#include <stdio.h>
+#include <statgrab.h>
+]]],
+[[[
+      if (sg_init()) return 0;
+]]]
+    )],
+    [c_cv_have_libstatgrab_0_90="no"],
+    [c_cv_have_libstatgrab_0_90="yes"]
+          )
+  )
+
+  CFLAGS="$SAVE_CFLAGS"
+  LDFLAGS="$SAVE_LDFLAGS"
+  LIBS="$SAVE_LIBS"
+fi
+
 AM_CONDITIONAL(BUILD_WITH_LIBSTATGRAB, test "x$with_libstatgrab" = "xyes")
 if test "x$with_libstatgrab" = "xyes"
 then
@@ -4066,6 +4273,10 @@ then
   BUILD_WITH_LIBSTATGRAB_LDFLAGS="$with_libstatgrab_ldflags"
   AC_SUBST(BUILD_WITH_LIBSTATGRAB_CFLAGS)
   AC_SUBST(BUILD_WITH_LIBSTATGRAB_LDFLAGS)
+  if test "x$c_cv_have_libstatgrab_0_90" = "xyes"
+  then
+        AC_DEFINE(HAVE_LIBSTATGRAB_0_90, 1, [Define to 1 if libstatgrab version >= 0.90])
+  fi
 fi
 # }}}
 
@@ -4131,7 +4342,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"
@@ -4142,6 +4353,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=""
@@ -4516,25 +4788,18 @@ fi
 if test "x$with_libvarnish" = "xyes"
 then
        SAVE_CPPFLAGS="$CPPFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libvarnish_cflags"
-       AC_CHECK_HEADERS(varnish/varnishapi.h, [], [with_libvarnish="no (varnish/varnishapi.h not found)"])
-
-       CPPFLAGS="$SAVE_CPPFLAGS"
-fi
-if test "x$with_libvarnish" = "xyes"
-then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       #SAVE_LDFLAGS="$LDFLAGS"
 
        CPPFLAGS="$CPPFLAGS $with_libvarnish_cflags"
-       #LDFLAGS="$LDFLAGS $with_libvarnish_libs"
 
-    AC_CHECK_HEADERS(varnish/vsc.h,
-        [AC_DEFINE([HAVE_VARNISH_V3], [1], [Varnish 3 API support])],
-        [AC_DEFINE([HAVE_VARNISH_V2], [1], [Varnish 2 API support])])
+       AC_CHECK_HEADERS(varnish/vapi/vsc.h,
+               [AC_DEFINE([HAVE_VARNISH_V4], [1], [Varnish 4 API support])],
+               [AC_CHECK_HEADERS(varnish/vsc.h,
+                       [AC_DEFINE([HAVE_VARNISH_V3], [1], [Varnish 3 API support])],
+                       [AC_CHECK_HEADERS(varnish/varnishapi.h,
+                               [AC_DEFINE([HAVE_VARNISH_V2], [1], [Varnish 2 API support])],
+                               [with_libvarnish="no (found none of the varnish header files)"])])])
 
        CPPFLAGS="$SAVE_CPPFLAGS"
-       #LDFLAGS="$SAVE_LDFLAGS"
 fi
 if test "x$with_libvarnish" = "xyes"
 then
@@ -4743,6 +5008,62 @@ then
 fi
 # }}}
 
+# --with-libatasmart {{{
+with_libatasmart_cppflags=""
+with_libatasmart_ldflags=""
+AC_ARG_WITH(libatasmart, [AS_HELP_STRING([--with-libatasmart@<:@=PREFIX@:>@], [Path to libatasmart.])],
+[
+       if test "x$withval" != "xno" && test "x$withval" != "xyes"
+       then
+               with_libatasmart_cppflags="-I$withval/include"
+               with_libatasmart_ldflags="-L$withval/lib"
+               with_libatasmart="yes"
+       else
+               with_libatasmart="$withval"
+       fi
+],
+[
+       if test "x$ac_system" = "xLinux"
+       then
+               with_libatasmart="yes"
+       else
+               with_libatasmart="no (Linux only library)"
+       fi
+])
+if test "x$with_libatasmart" = "xyes"
+then
+       SAVE_CPPFLAGS="$CPPFLAGS"
+       CPPFLAGS="$CPPFLAGS $with_libatasmart_cppflags"
+
+       AC_CHECK_HEADERS(atasmart.h, [with_libatasmart="yes"], [with_libatasmart="no (atasmart.h not found)"])
+
+       CPPFLAGS="$SAVE_CPPFLAGS"
+fi
+if test "x$with_libatasmart" = "xyes"
+then
+       SAVE_CPPFLAGS="$CPPFLAGS"
+       SAVE_LDFLAGS="$LDFLAGS"
+       CPPFLAGS="$CPPFLAGS $with_libatasmart_cppflags"
+       LDFLAGS="$LDFLAGS $with_libatasmart_ldflags"
+
+       AC_CHECK_LIB(atasmart, sk_disk_open, [with_libatasmart="yes"], [with_libatasmart="no (Symbol 'sk_disk_open' not found)"])
+
+       CPPFLAGS="$SAVE_CPPFLAGS"
+       LDFLAGS="$SAVE_LDFLAGS"
+fi
+if test "x$with_libatasmart" = "xyes"
+then
+       BUILD_WITH_LIBATASMART_CPPFLAGS="$with_libatasmart_cppflags"
+       BUILD_WITH_LIBATASMART_LDFLAGS="$with_libatasmart_ldflags"
+       BUILD_WITH_LIBATASMART_LIBS="-latasmart"
+       AC_SUBST(BUILD_WITH_LIBATASMART_CPPFLAGS)
+       AC_SUBST(BUILD_WITH_LIBATASMART_LDFLAGS)
+       AC_SUBST(BUILD_WITH_LIBATASMART_LIBS)
+       AC_DEFINE(HAVE_LIBATASMART, 1, [Define if libatasmart is present and usable.])
+fi
+AM_CONDITIONAL(BUILD_WITH_LIBATASMART, test "x$with_libatasmart" = "xyes")
+# }}}
+
 PKG_CHECK_MODULES([LIBNOTIFY], [libnotify],
                [with_libnotify="yes"],
                [if test "x$LIBNOTIFY_PKG_ERRORS" = "x"; then
@@ -4878,8 +5199,10 @@ dependency_warning="no"
 dependency_error="no"
 
 plugin_ascent="no"
+plugin_barometer="no"
 plugin_battery="no"
 plugin_bind="no"
+plugin_ceph="no"
 plugin_cgroups="no"
 plugin_conntrack="no"
 plugin_contextswitch="no"
@@ -4889,6 +5212,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"
@@ -4896,8 +5220,8 @@ plugin_interface="no"
 plugin_ipmi="no"
 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"
@@ -4911,12 +5235,15 @@ plugin_tape="no"
 plugin_tcpconns="no"
 plugin_ted="no"
 plugin_thermal="no"
-plugin_users="no"
+plugin_turbostat="no"
 plugin_uptime="no"
+plugin_users="no"
+plugin_virt="no"
 plugin_vmem="no"
 plugin_vserver="no"
 plugin_wireless="no"
 plugin_zfs_arc="no"
+plugin_zookeeper="no"
 
 # Linux
 if test "x$ac_system" = "xLinux"
@@ -4928,9 +5255,11 @@ then
        plugin_cpu="yes"
        plugin_cpufreq="yes"
        plugin_disk="yes"
+       plugin_drbd="yes"
        plugin_entropy="yes"
        plugin_fscache="yes"
        plugin_interface="yes"
+       plugin_ipc="yes"
        plugin_irq="yes"
        plugin_load="yes"
        plugin_lvm="yes"
@@ -4947,11 +5276,16 @@ then
        plugin_vmem="yes"
        plugin_vserver="yes"
        plugin_wireless="yes"
+       plugin_zfs_arc="yes"
 
        if test "x$have_linux_ip_vs_h" = "xyes" || test "x$have_net_ip_vs_h" = "xyes" || test "x$have_ip_vs_h" = "xyes"
        then
                plugin_ipvs="yes"
        fi
+       if test "x$c_cv_have_usable_asm_msrindex_h" = "xyes" && test "x$have_cpuid_h" = "xyes"
+       then
+               plugin_turbostat="yes"
+       fi
 fi
 
 if test "x$ac_system" = "xOpenBSD"
@@ -4971,6 +5305,7 @@ fi
 if test "x$ac_system" = "xAIX"
 then
         plugin_tcpconns="yes"
+        plugin_ipc="yes"
 fi
 
 # FreeBSD
@@ -5016,6 +5351,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
@@ -5052,6 +5404,11 @@ then
        plugin_curl_xml="yes"
 fi
 
+if test "x$with_libyajl" = "xyes"
+then
+       plugin_ceph="yes"
+fi
+
 if test "x$have_processor_info" = "xyes"
 then
        plugin_cpu="yes"
@@ -5119,14 +5476,14 @@ then
        plugin_interface="yes"
 fi
 
-if test "x$with_libxml2" = "xyes" && test "x$with_libvirt" = "xyes"
+if test "x$have_getloadavg" = "xyes"
 then
-       plugin_libvirt="yes"
+       plugin_load="yes"
 fi
 
-if test "x$have_getloadavg" = "xyes"
+if test "x$with_libyajl" = "xyes"
 then
-       plugin_load="yes"
+       plugin_log_logstash="yes"
 fi
 
 if test "x$c_cv_have_libperl$c_cv_have_perl_ithreads" = "xyesyes"
@@ -5142,7 +5499,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
 
@@ -5156,6 +5516,11 @@ then
        plugin_processes="yes"
 fi
 
+if test "x$with_kvm_getprocs" = "xyes" && test "x$have_struct_kinfo_proc_openbsd" = "xyes"
+then
+       plugin_processes="yes"
+fi
+
 if test "x$with_kvm_getswapinfo" = "xyes"
 then
        plugin_swap="yes"
@@ -5180,6 +5545,12 @@ then
        plugin_users="yes"
 fi
 
+if test "x$with_libxml2" = "xyes" && test "x$with_libvirt" = "xyes"
+then
+       plugin_virt="yes"
+fi
+
+
 m4_divert_once([HELP_ENABLE], [
 collectd plugins:])
 
@@ -5207,8 +5578,10 @@ 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([ceph],        [$plugin_ceph],       [Ceph daemon statistics])
 AC_PLUGIN([conntrack],   [$plugin_conntrack],  [nf_conntrack statistics])
 AC_PLUGIN([contextswitch], [$plugin_contextswitch], [context switch statistics])
 AC_PLUGIN([cpufreq],     [$plugin_cpufreq],    [CPU frequency statistics])
@@ -5221,24 +5594,27 @@ 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])
 AC_PLUGIN([ethstat],     [$plugin_ethstat],    [Stats from NIC driver])
 AC_PLUGIN([exec],        [yes],                [Execution of external programs])
+AC_PLUGIN([fhcount],     [yes],                [File handles statistics])
 AC_PLUGIN([filecount],   [yes],                [Count files in directories])
 AC_PLUGIN([fscache],     [$plugin_fscache],    [fscache statistics])
 AC_PLUGIN([gmond],       [$with_libganglia],   [Ganglia plugin])
 AC_PLUGIN([hddtemp],     [yes],                [Query hddtempd])
 AC_PLUGIN([interface],   [$plugin_interface],  [Interface traffic statistics])
+AC_PLUGIN([ipc],         [$plugin_ipc],        [IPC statistics])
 AC_PLUGIN([ipmi],        [$plugin_ipmi],       [IPMI sensor statistics])
 AC_PLUGIN([iptables],    [$with_libiptc],      [IPTables rule counters])
 AC_PLUGIN([ipvs],        [$plugin_ipvs],       [IPVS connection statistics])
 AC_PLUGIN([irq],         [$plugin_irq],        [IRQ statistics])
 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])
@@ -5268,6 +5644,7 @@ AC_PLUGIN([numa],        [$plugin_numa],       [NUMA virtual memory statistics])
 AC_PLUGIN([nut],         [$with_libupsclient], [Network UPS tools statistics])
 AC_PLUGIN([olsrd],       [yes],                [olsrd statistics])
 AC_PLUGIN([onewire],     [$with_libowcapi],    [OneWire sensor statistics])
+AC_PLUGIN([openldap],    [$with_libldap],      [OpenLDAP statistics])
 AC_PLUGIN([openvpn],     [yes],                [OpenVPN client statistics])
 AC_PLUGIN([oracle],      [$with_oracle],       [Oracle plugin])
 AC_PLUGIN([perl],        [$plugin_perl],       [Embed a Perl interpreter])
@@ -5280,13 +5657,14 @@ AC_PLUGIN([powerdns],    [yes],                [PowerDNS statistics])
 AC_PLUGIN([processes],   [$plugin_processes],  [Process statistics])
 AC_PLUGIN([protocols],   [$plugin_protocols],  [Protocol (IP, TCP, ...) statistics])
 AC_PLUGIN([python],      [$with_python],       [Embed a Python interpreter])
-AC_PLUGIN([redis],       [$with_libcredis],    [Redis plugin])
+AC_PLUGIN([redis],       [$with_libhiredis],    [Redis plugin])
 AC_PLUGIN([routeros],    [$with_librouteros],  [RouterOS plugin])
 AC_PLUGIN([rrdcached],   [$librrd_rrdc_update], [RRDTool output plugin])
 AC_PLUGIN([rrdtool],     [$with_librrd],       [RRDTool output plugin])
 AC_PLUGIN([sensors],     [$with_libsensors],   [lm_sensors statistics])
 AC_PLUGIN([serial],      [$plugin_serial],     [serial port traffic])
 AC_PLUGIN([sigrok],      [$with_libsigrok],    [sigrok acquisition sources])
+AC_PLUGIN([smart],       [$with_libatasmart],  [SMART statistics])
 AC_PLUGIN([snmp],        [$with_libnetsnmp],   [SNMP querying plugin])
 AC_PLUGIN([statsd],      [yes],                [StatsD plugin])
 AC_PLUGIN([swap],        [$plugin_swap],       [Swap usage statistics])
@@ -5306,26 +5684,34 @@ AC_PLUGIN([ted],         [$plugin_ted],        [Read The Energy Detective values
 AC_PLUGIN([thermal],     [$plugin_thermal],    [Linux ACPI thermal zone statistics])
 AC_PLUGIN([threshold],   [yes],                [Threshold checking plugin])
 AC_PLUGIN([tokyotyrant], [$with_libtokyotyrant],  [TokyoTyrant database statistics])
+AC_PLUGIN([turbostat],   [$plugin_turbostat],  [Advanced statistic on Intel cpu states])
 AC_PLUGIN([unixsock],    [yes],                [Unixsock communication plugin])
 AC_PLUGIN([uptime],      [$plugin_uptime],     [Uptime statistics])
 AC_PLUGIN([users],       [$plugin_users],      [User statistics])
 AC_PLUGIN([uuid],        [yes],                [UUID as hostname plugin])
 AC_PLUGIN([varnish],     [$with_libvarnish],   [Varnish cache statistics])
+AC_PLUGIN([virt],        [$plugin_virt],       [Virtual machine statistics])
 AC_PLUGIN([vmem],        [$plugin_vmem],       [Virtual memory statistics])
 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_log], [yes],                  [Log output plugin])
 AC_PLUGIN([write_mongodb], [$with_libmongoc],  [MongoDB output plugin])
-AC_PLUGIN([write_redis], [$with_libcredis],    [Redis output plugin])
+AC_PLUGIN([write_redis], [$with_libhiredis],    [Redis output plugin])
 AC_PLUGIN([write_riemann], [$have_protoc_c],   [Riemann output plugin])
+AC_PLUGIN([write_sensu], [yes],                [Sensu 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])
+AC_PLUGIN([zookeeper],   [yes],               [Zookeeper statistics])
 
 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"
@@ -5347,10 +5733,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"
@@ -5460,7 +5856,7 @@ AC_SUBST(LCC_VERSION_STRING)
 
 AC_CONFIG_FILES(src/libcollectdclient/collectd/lcc_features.h)
 
-AC_CONFIG_FILES([Makefile src/Makefile src/collectd.conf src/libcollectdclient/Makefile src/libcollectdclient/libcollectdclient.pc src/liboconfig/Makefile bindings/Makefile bindings/java/Makefile])
+AC_CONFIG_FILES([Makefile src/Makefile src/daemon/Makefile src/collectd.conf src/libcollectdclient/Makefile src/libcollectdclient/libcollectdclient.pc src/liboconfig/Makefile bindings/Makefile bindings/java/Makefile])
 AC_OUTPUT
 
 if test "x$with_librrd" = "xyes" \
@@ -5493,18 +5889,21 @@ Configuration:
   Libraries:
     intel mic . . . . . . $with_mic
     libaquaero5 . . . . . $with_libaquaero5
-    libcredis . . . . . . $with_libcredis
+    libatasmart . . . . . $with_libatasmart
     libcurl . . . . . . . $with_libcurl
     libdbi  . . . . . . . $with_libdbi
     libesmtp  . . . . . . $with_libesmtp
     libganglia  . . . . . $with_libganglia
     libgcrypt . . . . . . $with_libgcrypt
     libhal  . . . . . . . $with_libhal
+    libhiredis  . . . . . $with_libhiredis
+    libi2c-dev  . . . . . $with_libi2c
     libiokit  . . . . . . $with_libiokit
     libiptc . . . . . . . $with_libiptc
     libjvm  . . . . . . . $with_java
     libkstat  . . . . . . $with_kstat
     libkvm  . . . . . . . $with_libkvm
+    libldap . . . . . . . $with_libldap
     liblvm2app  . . . . . $with_liblvm2app
     libmemcached  . . . . $with_libmemcached
     libmnl  . . . . . . . $with_libmnl
@@ -5524,12 +5923,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
@@ -5552,14 +5953,16 @@ Configuration:
     amqp    . . . . . . . $enable_amqp
     apache  . . . . . . . $enable_apache
     apcups  . . . . . . . $enable_apcups
-    aquaero . . . . . . . $enable_aquaero
     apple_sensors . . . . $enable_apple_sensors
+    aquaero . . . . . . . $enable_aquaero
     ascent  . . . . . . . $enable_ascent
+    barometer . . . . . . $enable_barometer
     battery . . . . . . . $enable_battery
     bind  . . . . . . . . $enable_bind
+    ceph  . . . . . . . . $enable_ceph
+    cgroups . . . . . . . $enable_cgroups
     conntrack . . . . . . $enable_conntrack
     contextswitch . . . . $enable_contextswitch
-    cgroups . . . . . . . $enable_cgroups
     cpu . . . . . . . . . $enable_cpu
     cpufreq . . . . . . . $enable_cpufreq
     csv . . . . . . . . . $enable_csv
@@ -5570,23 +5973,26 @@ Configuration:
     df  . . . . . . . . . $enable_df
     disk  . . . . . . . . $enable_disk
     dns . . . . . . . . . $enable_dns
+    drbd  . . . . . . . . $enable_drbd
     email . . . . . . . . $enable_email
     entropy . . . . . . . $enable_entropy
     ethstat . . . . . . . $enable_ethstat
     exec  . . . . . . . . $enable_exec
+    fhcount . . . . . . . $enable_fhcount
     filecount . . . . . . $enable_filecount
     fscache . . . . . . . $enable_fscache
     gmond . . . . . . . . $enable_gmond
     hddtemp . . . . . . . $enable_hddtemp
     interface . . . . . . $enable_interface
+    ipc . . . . . . . . . $enable_ipc
     ipmi  . . . . . . . . $enable_ipmi
     iptables  . . . . . . $enable_iptables
     ipvs  . . . . . . . . $enable_ipvs
     irq . . . . . . . . . $enable_irq
     java  . . . . . . . . $enable_java
-    libvirt . . . . . . . $enable_libvirt
     load  . . . . . . . . $enable_load
     logfile . . . . . . . $enable_logfile
+    log_logstash  . . . . $enable_log_logstash
     lpar  . . . . . . . . $enable_lpar
     lvm . . . . . . . . . $enable_lvm
     madwifi . . . . . . . $enable_madwifi
@@ -5616,6 +6022,7 @@ Configuration:
     nut . . . . . . . . . $enable_nut
     olsrd . . . . . . . . $enable_olsrd
     onewire . . . . . . . $enable_onewire
+    openldap  . . . . . . $enable_openldap
     openvpn . . . . . . . $enable_openvpn
     oracle  . . . . . . . $enable_oracle
     perl  . . . . . . . . $enable_perl
@@ -5634,13 +6041,14 @@ Configuration:
     sensors . . . . . . . $enable_sensors
     serial  . . . . . . . $enable_serial
     sigrok  . . . . . . . $enable_sigrok
+    smart . . . . . . . . $enable_smart
     snmp  . . . . . . . . $enable_snmp
     statsd  . . . . . . . $enable_statsd
     swap  . . . . . . . . $enable_swap
     syslog  . . . . . . . $enable_syslog
     table . . . . . . . . $enable_table
-    tail  . . . . . . . . $enable_tail
     tail_csv  . . . . . . $enable_tail_csv
+    tail  . . . . . . . . $enable_tail
     tape  . . . . . . . . $enable_tape
     target_notification . $enable_target_notification
     target_replace  . . . $enable_target_replace
@@ -5653,21 +6061,28 @@ Configuration:
     thermal . . . . . . . $enable_thermal
     threshold . . . . . . $enable_threshold
     tokyotyrant . . . . . $enable_tokyotyrant
+    turbostat . . . . . . $enable_turbostat
     unixsock  . . . . . . $enable_unixsock
     uptime  . . . . . . . $enable_uptime
     users . . . . . . . . $enable_users
     uuid  . . . . . . . . $enable_uuid
     varnish . . . . . . . $enable_varnish
+    virt  . . . . . . . . $enable_virt
     vmem  . . . . . . . . $enable_vmem
     vserver . . . . . . . $enable_vserver
     wireless  . . . . . . $enable_wireless
     write_graphite  . . . $enable_write_graphite
     write_http  . . . . . $enable_write_http
+    write_kafka . . . . . $enable_write_kafka
+    write_log . . . . . . $enable_write_log
     write_mongodb . . . . $enable_write_mongodb
     write_redis . . . . . $enable_write_redis
     write_riemann . . . . $enable_write_riemann
+    write_sensu . . . . . $enable_write_sensu
+    write_tsdb  . . . . . $enable_write_tsdb
     xmms  . . . . . . . . $enable_xmms
     zfs_arc . . . . . . . $enable_zfs_arc
+    zookeeper . . . . . . $enable_zookeeper
 
 EOF
 
index af64fb1c2749143463c51ac797db6c239c2f3803..5ff259ff0fce178a0bb47bccc5f9a68cf41c155e 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 d20be3598dd2783dc65cb969426fa22163a79e10..a3760027df2d98f882dd2ba6c2ec418f5571244a 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 42582a7ec82bccdd0be044843375606970270f52..36f8706f3feff932e5c2d8ea3f25d13dd993bdc7 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 5a0b522b424270bd9f819023700a048762eece5e..3d6f61e366cd03a70d768478eb8710843a0e0f92 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 f68cc1ac85c090792efa1bfe9433272327b378fa..9539062c9383b88ace7e06954ec60e6bb9fa6684 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 b9fefa6ad479f135e79f7da19cc2cc1d2ac80308..fdfcbaaffe0e1f041f6a5514bf4f31ad273173ab 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 00c5519b7a211cdfde7f283aa528805020f93dc3..bee182cb715f703605c7983a2cccbb2c12f3af37 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 d3f267491df5d67a702290e440c4448dcccc55b7..9d491ff818e88986ca67046607636839019d22d1 100644 (file)
 %{?el6:%global _has_ip_vs_h 1}
 %{?el6:%global _has_lvm2app_h 1}
 %{?el6:%global _has_libmodbus 1}
+%{?el6:%global _has_libudev 1}
 %{?el6:%global _has_iproute 1}
+%{?el6:%global _has_atasmart 1}
+%{?el6:%global _has_hiredis 1}
+%{?el6:%global _has_asm_msr_index 1}
 
 %{?el7:%global _has_libyajl 1}
 %{?el7:%global _has_recent_libpcap 1}
 %{?el7:%global _has_working_libiptc 1}
 %{?el7:%global _has_ip_vs_h 1}
 %{?el7:%global _has_lvm2app_h 1}
+%{?el7:%global _has_libudev 1}
 %{?el7:%global _has_recent_librrd 1}
 %{?el7:%global _has_varnish4 1}
 %{?el7:%global _has_broken_libmemcached 1}
 %{?el7:%global _has_iproute 1}
+%{?el7:%global _has_atasmart 1}
+%{?el7:%global _has_hiredis 1}
+%{?el7:%global _has_asm_msr_index 1}
 
 # plugins enabled by default
 %define with_aggregation 0%{!?_without_aggregation:1}
@@ -69,6 +77,7 @@
 %define with_ascent 0%{!?_without_ascent:1}
 %define with_battery 0%{!?_without_battery:1}
 %define with_bind 0%{!?_without_bind:1}
+%define with_ceph 0%{!?_without_ceph:0%{?_has_libyajl}}
 %define with_cgroups 0%{!?_without_cgroups:1}
 %define with_conntrack 0%{!?_without_conntrack:1}
 %define with_contextswitch 0%{!?_without_contextswitch:1}
 %define with_df 0%{!?_without_df:1}
 %define with_disk 0%{!?_without_disk:1}
 %define with_dns 0%{!?_without_dns:0%{?_has_recent_libpcap}}
+%define with_drbd 0%{!?_without_drbd:1}
 %define with_email 0%{!?_without_email:1}
 %define with_entropy 0%{!?_without_entropy:1}
 %define with_ethstat 0%{!?_without_ethstat:0%{?_has_recent_sockios_h}}
 %define with_exec 0%{!?_without_exec:1}
+%define with_fhcount 0%{!?_without_fhcount:1}
 %define with_filecount 0%{!?_without_filecount:1}
 %define with_fscache 0%{!?_without_fscache:1}
 %define with_gmond 0%{!?_without_gmond:0%{?_has_recent_libganglia}}
 %define with_hddtemp 0%{!?_without_hddtemp:1}
 %define with_interface 0%{!?_without_interface:1}
+%define with_ipc 0%{!?_without_ipc:1}
 %define with_ipmi 0%{!?_without_ipmi:1}
 %define with_iptables 0%{!?_without_iptables:0%{?_has_working_libiptc}}
 %define with_ipvs 0%{!?_without_ipvs:0%{?_has_ip_vs_h}}
 %define with_irq 0%{!?_without_irq:1}
 %define with_java 0%{!?_without_java:1}
-%define with_libvirt 0%{!?_without_libvirt:1}
+%define with_virt 0%{!?_without_virt:1}
 %define with_load 0%{!?_without_load:1}
 %define with_logfile 0%{!?_without_logfile:1}
+%define with_log_logstash 0%{!?_without_log_logstash:0%{?_has_libyajl}}
 %define with_lvm 0%{!?_without_lvm:0%{?_has_lvm2app_h}}
 %define with_madwifi 0%{!?_without_madwifi:1}
 %define with_mbmon 0%{!?_without_mbmon:1}
 %define with_numa 0%{!?_without_numa:1}
 %define with_nut 0%{!?_without_nut:1}
 %define with_olsrd 0%{!?_without_olsrd:1}
+%define with_openldap 0%{!?_without_openldap:1}
 %define with_openvpn 0%{!?_without_openvpn:1}
 %define with_perl 0%{!?_without_perl:1}
 %define with_pinba 0%{!?_without_pinba:1}
 %define with_processes 0%{!?_without_processes:1}
 %define with_protocols 0%{!?_without_protocols:1}
 %define with_python 0%{!?_without_python:1}
+%define with_redis 0%{!?_without_redis:0%{?_has_hiredis}}
 %define with_rrdcached 0%{!?_without_rrdcached:0%{?_has_recent_librrd}}
 %define with_rrdtool 0%{!?_without_rrdtool:1}
 %define with_sensors 0%{!?_without_sensors:1}
 %define with_serial 0%{!?_without_serial:1}
+%define with_smart 0%{!?_without_smart:0%{?_has_atasmart}}
 %define with_snmp 0%{!?_without_snmp:1}
 %define with_statsd 0%{!?_without_statsd:1}
 %define with_swap 0%{!?_without_swap:1}
 %define with_ted 0%{!?_without_ted:1}
 %define with_thermal 0%{!?_without_thermal:1}
 %define with_threshold 0%{!?_without_threshold:1}
+%define with_turbostat 0%{!?_without_turbostat:0%{?_has_asm_msr_index}}
 %define with_unixsock 0%{!?_without_unixsock:1}
 %define with_uptime 0%{!?_without_uptime:1}
 %define with_users 0%{!?_without_users:1}
 %define with_wireless 0%{!?_without_wireless:1}
 %define with_write_graphite 0%{!?_without_write_graphite:1}
 %define with_write_http 0%{!?_without_write_http:1}
+%define with_write_log 0%{!?_without_write_log:1}
+%define with_write_redis 0%{!?_without_write_redis:0%{?_has_hiredis}}
 %define with_write_riemann 0%{!?_without_write_riemann:1}
+%define with_write_sensu 0%{!?_without_write_sensu:1}
+%define with_write_tsdb 0%{!?_without_write_tsdb:1}
+%define with_zfs_arc 0%{!?_without_zfs_arc:1}
+%define with_zookeeper 0%{!?_without_zookeeper:1}
 
 # Plugins not built by default because of dependencies on libraries not
 # available in RHEL or EPEL:
 %define with_apple_sensors 0%{!?_without_apple_sensors:0}
 # plugin aquaero disabled, requires a libaquaero5
 %define with_aquaero 0%{!?_without_aquaero:0}
+# plugin barometer disabled, requires a libi2c
+%define with_barometer 0%{!?_without_barometer:0}
 # plugin lpar disabled, requires AIX
 %define with_lpar 0%{!?_without_lpar:0}
 # plugin mic disabled, requires Mic
 %define with_oracle 0%{!?_without_oracle:0}
 # plugin oracle disabled, requires BSD
 %define with_pf 0%{!?_without_pf:0}
-# plugin redis disabled, requires credis
-%define with_redis 0%{!?_without_redis:0}
 # plugin routeros disabled, requires librouteros
 %define with_routeros 0%{!?_without_routeros:0}
 # plugin sigrok disabled, requires libsigrok
 %define with_tape 0%{!?_without_tape:0}
 # plugin tokyotyrant disabled, requires tcrdb.h
 %define with_tokyotyrant 0%{!?_without_tokyotyrant:0}
+# plugin write_kafka disabled, requires librdkafka
+%define with_write_kafka 0%{!?_without_write_kafka:0}
 # plugin write_mongodb disabled, requires libmongoc
 %define with_write_mongodb 0%{!?_without_write_mongodb:0}
-# plugin write_redis disabled, requires credis
-%define with_write_redis 0%{!?_without_write_redis:0}
 # plugin xmms disabled, requires xmms
 %define with_xmms 0%{!?_without_xmms:0}
-# plugin zfs_arc disabled, requires FreeBSD/Solaris
-%define with_zfs_arc 0%{!?_without_zfs_arc:0}
 
 Summary:       statistics collection and monitoring daemon
 Name:          collectd
-Version:       5.4.2
+Version:       5.5.0
 Release:       1%{?dist}
 URL:           http://collectd.org
 Source:                http://collectd.org/files/%{name}-%{version}.tar.bz2
 License:       GPLv2
 Group:         System Environment/Daemons
 BuildRoot:     %{_tmppath}/%{name}-%{version}-root
-BuildRequires: libgcrypt-devel, kernel-headers, libtool-ltdl-devel
+BuildRequires: libgcrypt-devel, kernel-headers, libtool-ltdl-devel, libcap-devel
 Vendor:                collectd development team <collectd@verplant.org>
 
+%if 0%{?el7:1}
+Requires(pre):         initscripts
+Requires(post):                systemd
+Requires(preun):       systemd
+Requires(postun):      systemd
+%else
 Requires(post):                chkconfig
 Requires(preun):       chkconfig, initscripts
 Requires(postun):      initscripts
+%endif
 
 %description
 collectd is a small daemon which collects system information periodically and
@@ -260,6 +288,15 @@ open-source server software for the game World of Warcraft by Blizzard
 Entertainment.
 %endif
 
+%if %{with_barometer}
+%package barometer
+Summary:       barometer plugin for collectd
+Group:         System Environment/Daemons
+Requires:      %{name}%{?_isa} = %{version}-%{release}
+%description barometer
+Collects pressure and temperature from digital barometers.
+%endif
+
 %if %{with_bind}
 %package bind
 Summary:       Bind plugin for collectd
@@ -271,6 +308,16 @@ The BIND plugin retrieves this information that's encoded in XML and provided
 via HTTP and submits the values to collectd.
 %endif
 
+%if %{with_ceph}
+%package ceph
+Summary:       Ceph plugin for collectd
+Group:         System Environment/Daemons
+Requires:      %{name}%{?_isa} = %{version}-%{release}
+BuildRequires: yajl-devel
+%description ceph
+Ceph plugin for collectd
+%endif
+
 %if %{with_curl}
 %package curl
 Summary:       Curl plugin for collectd
@@ -315,6 +362,17 @@ The DBI plugin uses libdbi, a database abstraction library, to execute SQL
 statements on a database and read back the result.
 %endif
 
+%if %{with_disk}
+%package disk
+Summary:       disk plugin for collectd
+Group:         System Environment/Daemons
+Requires:      %{name}%{?_isa} = %{version}-%{release}
+%{?_has_libudev:BuildRequires:  libudev-devel}
+%description disk
+The "disk" plugin collects information about the usage of physical disks and
+logical disks (partitions).
+%endif
+
 %if %{with_dns}
 %package dns
 Summary:       DNS plugin for collectd
@@ -392,14 +450,14 @@ This plugin for collectd allows plugins to be written in Java and executed
 in an embedded JVM.
 %endif
 
-%if %{with_libvirt}
-%package libvirt
-Summary:       Libvirt plugin for collectd
-Group:         System Environment/Daemons
-Requires:      %{name}%{?_isa} = %{version}-%{release}
-BuildRequires: libvirt-devel
-%description libvirt
-This plugin collects information from virtualized guests.
+%if %{with_log_logstash}
+%package log_logstash
+Summary:       log_logstash plugin for collectd
+Group:         System Environment/Daemons
+Requires:      %{name}%{?_isa} = %{version}-%{release}
+BuildRequires: yajl-devel
+%description log_logstash
+This plugin logs in logstash JSON format
 %endif
 
 %if %{with_lvm}
@@ -508,17 +566,27 @@ BuildRequires:    nut-devel
 This plugin for collectd provides Network UPS Tools support.
 %endif
 
+%if %{with_openldap}
+%package openldap
+Summary:       Openldap plugin for collectd
+Group:         System Environment/Daemons
+Requires:      %{name}%{?_isa} = %{version}-%{release}
+BuildRequires: openldap-devel
+%description openldap
+This plugin reads monitoring information from OpenLDAP's cn=Monitor subtree.
+%endif
+
 %if %{with_perl}
 %package perl
 Summary:       Perl plugin for collectd
 Group:         System Environment/Daemons
 Requires:      %{name}%{?_isa} = %{version}-%{release}
 Requires:      perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version))
-%if 0%{?rhel} >= 6
+       %if 0%{?rhel} >= 6
 BuildRequires: perl-ExtUtils-Embed
-%else
+       %else
 BuildRequires: perl
-%endif
+       %endif
 %description perl
 The Perl plugin embeds a Perl interpreter into collectd and exposes the
 application programming interface (API) to Perl-scripts.
@@ -562,11 +630,11 @@ database.
 Summary:       Python plugin for collectd
 Group:         System Environment/Daemons
 Requires:      %{name}%{?_isa} = %{version}-%{release}
-%if 0%{?rhel} >= 6
+       %if 0%{?rhel} >= 6
 BuildRequires: python-devel
-%else
+       %else
 BuildRequires: python26-devel
-%endif
+       %endif
 %description python
 The Python plugin embeds a Python interpreter into collectd and exposes the
 application programming interface (API) to Python-scripts.
@@ -577,10 +645,10 @@ application programming interface (API) to Python-scripts.
 Summary:       Redis plugin for collectd
 Group:         System Environment/Daemons
 Requires:      %{name}%{?_isa} = %{version}-%{release}
-BuildRequires: credis-devel
+BuildRequires: hiredis-devel
 %description redis
 The Redis plugin connects to one or more instances of Redis, a key-value store,
-and collects usage information using the credis library.
+and collects usage information using the hiredis library.
 %endif
 
 %if %{with_rrdcached}
@@ -625,6 +693,17 @@ measurements fed to collectd. This includes multimeters, sound level meters,
 thermometers, and much more.
 %endif
 
+%if %{with_smart}
+%package smart
+Summary:       SMART plugin for collectd
+Group:         System Environment/Daemons
+Requires:      %{name}%{?_isa} = %{version}-%{release}
+BuildRequires: libatasmart-devel
+%description smart
+Collect SMART statistics, notably load cycle count, temperature and bad
+sectors.
+%endif
+
 %if %{with_snmp}
 %package snmp
 Summary:       SNMP plugin for collectd
@@ -645,6 +724,16 @@ BuildRequires:     varnish-libs-devel
 The Varnish plugin collects information about Varnish, an HTTP accelerator.
 %endif
 
+%if %{with_virt}
+%package virt
+Summary:       Virt plugin for collectd
+Group:         System Environment/Daemons
+Requires:      %{name}%{?_isa} = %{version}-%{release}
+BuildRequires: libvirt-devel
+%description virt
+This plugin collects information from virtualized guests.
+%endif
+
 %if %{with_write_http}
 %package write_http
 Summary:       Write-HTTP plugin for collectd
@@ -656,12 +745,22 @@ The Write-HTTP plugin sends the values collected by collectd to a web-server
 using HTTP POST requests.
 %endif
 
+%if %{with_write_kafka}
+%package write_kafka
+Summary:       Write-kafka plugin for collectd
+Group:         System Environment/Daemons
+Requires:      %{name}%{?_isa} = %{version}-%{release}
+BuildRequires: rdkafka-devel
+%description write_kafka
+The write_kafka plugin sends values to kafka, a distributed messaging system.
+%endif
+
 %if %{with_write_redis}
 %package write_redis
 Summary:       Write-Redis plugin for collectd
 Group:         System Environment/Daemons
 Requires:      %{name}%{?_isa} = %{version}-%{release}
-BuildRequires: credis-devel
+BuildRequires: hiredis-devel
 %description write_redis
 The Write Redis plugin stores values in Redis, a “data structures server”.
 %endif
@@ -718,6 +817,13 @@ Requires:  libcollectdclient%{?_isa} = %{version}-%{release}
 %description -n libcollectdclient-devel
 Development files for libcollectdclient
 
+%package -n collectd-utils
+Summary:       Collectd utilities
+Group:         System Environment/Daemons
+Requires:      libcollectdclient%{?_isa} = %{version}-%{release}
+Requires:      collectd%{?_isa} = %{version}-%{release}
+%description -n collectd-utils
+Collectd utilities
 
 %prep
 %setup -q
@@ -765,6 +871,12 @@ Development files for libcollectdclient
 %define _with_ascent --disable-ascent
 %endif
 
+%if %{with_barometer}
+%define _with_barometer --enable-barometer
+%else
+%define _with_barometer --disable-barometer
+%endif
+
 %if %{with_battery}
 %define _with_battery --enable-battery
 %else
@@ -813,6 +925,12 @@ Development files for libcollectdclient
 %define _with_csv --disable-csv
 %endif
 
+%if %{with_ceph}
+%define _with_ceph --enable-ceph
+%else
+%define _with_ceph --disable-ceph
+%endif
+
 %if %{with_curl}
 %define _with_curl --enable-curl
 %else
@@ -855,6 +973,12 @@ Development files for libcollectdclient
 %define _with_dns --disable-dns
 %endif
 
+%if %{with_drbd}
+%define _with_drbd --enable-drbd
+%else
+%define _with_drbd --disable-drbd
+%endif
+
 %if %{with_email}
 %define _with_email --enable-email
 %else
@@ -879,6 +1003,12 @@ Development files for libcollectdclient
 %define _with_exec --disable-exec
 %endif
 
+%if %{with_fhcount}
+%define _with_fhcount --enable-fhcount
+%else
+%define _with_fhcount --disable-fhcount
+%endif
+
 %if %{with_filecount}
 %define _with_filecount --enable-filecount
 %else
@@ -909,6 +1039,12 @@ Development files for libcollectdclient
 %define _with_interface --disable-interface
 %endif
 
+%if %{with_ipc}
+%define _with_ipc --enable-ipc
+%else
+%define _with_ipc --disable-ipc
+%endif
+
 %if %{with_ipmi}
 %define _with_ipmi --enable-ipmi
 %else
@@ -939,10 +1075,10 @@ Development files for libcollectdclient
 %define _with_java --disable-java
 %endif
 
-%if %{with_libvirt}
-%define _with_libvirt --enable-libvirt
+%if %{with_virt}
+%define _with_virt --enable-virt
 %else
-%define _with_libvirt --disable-libvirt
+%define _with_virt --disable-virt
 %endif
 
 %if %{with_load}
@@ -957,6 +1093,12 @@ Development files for libcollectdclient
 %define _with_logfile --disable-logfile
 %endif
 
+%if %{with_log_logstash}
+%define _with_log_logstash --enable-log_logstash
+%else
+%define _with_log_logstash --disable-log_logstash
+%endif
+
 %if %{with_lpar}
 %define _with_lpar --enable-lpar
 %else
@@ -1101,6 +1243,12 @@ Development files for libcollectdclient
 %define _with_onewire --disable-onewire
 %endif
 
+%if %{with_openldap}
+%define _with_openldap --enable-openldap
+%else
+%define _with_openldap --disable-openldap
+%endif
+
 %if %{with_openvpn}
 %define _with_openvpn --enable-openvpn
 %else
@@ -1162,11 +1310,11 @@ Development files for libcollectdclient
 %endif
 
 %if %{with_python}
-%if 0%{?rhel} >= 6
+       %if 0%{?rhel} >= 6
 %define _with_python --enable-python
-%else
+       %else
 %define _with_python --enable-python --with-python=%{_bindir}/python2.6
-%endif
+       %endif
 %else
 %define _with_python --disable-python
 %endif
@@ -1213,6 +1361,12 @@ Development files for libcollectdclient
 %define _with_sigrok --disable-sigrok
 %endif
 
+%if %{with_smart}
+%define _with_smart --enable-smart
+%else
+%define _with_smart --disable-smart
+%endif
+
 %if %{with_snmp}
 %define _with_snmp --enable-snmp
 %else
@@ -1297,6 +1451,12 @@ Development files for libcollectdclient
 %define _with_tokyotyrant --disable-tokyotyrant
 %endif
 
+%if %{with_turbostat}
+%define _with_turbostat --enable-turbostat
+%else
+%define _with_turbostat --disable-turbostat
+%endif
+
 %if %{with_unixsock}
 %define _with_unixsock --enable-unixsock
 %else
@@ -1357,6 +1517,18 @@ Development files for libcollectdclient
 %define _with_write_http --disable-write_http
 %endif
 
+%if %{with_write_kafka}
+%define _with_write_kafka --enable-write_kafka
+%else
+%define _with_write_kafka --disable-write_kafka
+%endif
+
+%if %{with_write_log}
+%define _with_write_log --enable-write_log
+%else
+%define _with_write_log --disable-write_log
+%endif
+
 %if %{with_write_mongodb}
 %define _with_write_mongodb --enable-write_mongodb
 %else
@@ -1375,6 +1547,18 @@ Development files for libcollectdclient
 %define _with_write_riemann --disable-write_riemann
 %endif
 
+%if %{with_write_sensu}
+%define _with_write_sensu --enable-write_sensu
+%else
+%define _with_write_sensu --disable-write_sensu
+%endif
+
+%if %{with_write_tsdb}
+%define _with_write_tsdb --enable-write_tsdb
+%else
+%define _with_write_tsdb --disable-write_tsdb
+%endif
+
 %if %{with_xmms}
 %define _with_xmms --enable-xmms
 %else
@@ -1387,6 +1571,12 @@ Development files for libcollectdclient
 %define _with_zfs_arc --disable-zfs_arc
 %endif
 
+%if %{with_zookeeper}
+%define _with_zookeeper --enable-zookeeper
+%else
+%define _with_zookeeper --disable-zookeeper
+%endif
+
 %configure CFLAGS="%{optflags} -DLT_LAZY_OR_NOW=\"RTLD_LAZY|RTLD_GLOBAL\"" \
        --disable-static \
        --without-included-ltdl \
@@ -1408,8 +1598,10 @@ Development files for libcollectdclient
        %{?_with_apple_sensors} \
        %{?_with_aquaero} \
        %{?_with_ascent} \
+       %{?_with_barometer} \
        %{?_with_battery} \
        %{?_with_bind} \
+       %{?_with_ceph} \
        %{?_with_cgroups} \
        %{?_with_conntrack} \
        %{?_with_contextswitch} \
@@ -1423,20 +1615,24 @@ Development files for libcollectdclient
        %{?_with_df} \
        %{?_with_disk} \
        %{?_with_dns} \
+       %{?_with_drbd} \
        %{?_with_email} \
        %{?_with_entropy} \
        %{?_with_ethstat} \
        %{?_with_exec} \
+       %{?_with_fhcount} \
        %{?_with_filecount} \
        %{?_with_fscache} \
        %{?_with_gmond} \
        %{?_with_hddtemp} \
        %{?_with_interface} \
+       %{?_with_ipc} \
        %{?_with_ipmi} \
        %{?_with_iptables} \
        %{?_with_ipvs} \
        %{?_with_java} \
-       %{?_with_libvirt} \
+       %{?_with_virt} \
+       %{?_with_log_logstash} \
        %{?_with_lpar} \
        %{?_with_lvm} \
        %{?_with_memcachec} \
@@ -1451,6 +1647,7 @@ Development files for libcollectdclient
        %{?_with_notify_email} \
        %{?_with_nut} \
        %{?_with_onewire} \
+       %{?_with_openldap} \
        %{?_with_oracle} \
        %{?_with_perl} \
        %{?_with_pf} \
@@ -1464,15 +1661,18 @@ Development files for libcollectdclient
        %{?_with_rrdtool} \
        %{?_with_sensors} \
        %{?_with_sigrok} \
+       %{?_with_smart} \
        %{?_with_snmp} \
        %{?_with_tape} \
        %{?_with_tokyotyrant} \
        %{?_with_varnish} \
        %{?_with_write_http} \
+       %{?_with_write_kafka} \
        %{?_with_write_mongodb} \
        %{?_with_write_redis} \
        %{?_with_xmms} \
        %{?_with_zfs_arc} \
+       %{?_with_zookeeper} \
        %{?_with_irq} \
        %{?_with_load} \
        %{?_with_logfile} \
@@ -1502,6 +1702,7 @@ Development files for libcollectdclient
        %{?_with_ted} \
        %{?_with_thermal} \
        %{?_with_threshold} \
+       %{?_with_turbostat} \
        %{?_with_unixsock} \
        %{?_with_uptime} \
        %{?_with_users} \
@@ -1511,7 +1712,10 @@ Development files for libcollectdclient
        %{?_with_wireless}\
        %{?_with_write_graphite} \
        %{?_with_write_http} \
-       %{?_with_write_riemann}
+       %{?_with_write_log} \
+       %{?_with_write_riemann} \
+       %{?_with_write_sensu} \
+       %{?_with_write_tsdb}
 
 
 %{__make} %{?_smp_mflags}
@@ -1520,7 +1724,11 @@ Development files for libcollectdclient
 %install
 rm -rf %{buildroot}
 %{__make} install DESTDIR=%{buildroot}
-%{__install} -Dp -m 0755 contrib/redhat/init.d-collectd %{buildroot}%{_initrddir}/collectd
+%if 0%{?el7:1}
+%{__install} -Dp -m0644 contrib/systemd.collectd.service %{buildroot}%{_unitdir}/collectd.service
+%else
+%{__install} -Dp -m0755 contrib/redhat/init.d-collectd %{buildroot}%{_initrddir}/collectd
+%endif
 %{__install} -Dp -m0644 src/collectd.conf %{buildroot}%{_sysconfdir}/collectd.conf
 %{__install} -d %{buildroot}%{_sharedstatedir}/collectd/
 %{__install} -d %{buildroot}%{_sysconfdir}/collectd.d/
@@ -1572,19 +1780,44 @@ rm -f %{buildroot}%{_mandir}/man5/collectd-snmp.5*
 %clean
 rm -rf %{buildroot}
 
+%pre
+%if 0%{?el7:1}
+# stop sysv-based instance before upgrading to systemd
+if [ $1 -eq 2 ] && [ -f /var/lock/subsys/collectd ]; then
+       SYSTEMCTL_SKIP_REDIRECT=1 %{_initddir}/collectd stop >/dev/null 2>&1 || :
+fi
+%endif
+
 %post
-/sbin/chkconfig --add collectd
+%if 0%{?el7:1}
+if [ $1 -eq 2 ]; then
+       /usr/bin/systemctl daemon-reload >/dev/null 2>&1 || :
+fi
+%systemd_post collectd.service
+%else
+/sbin/chkconfig --add collectd || :
+%endif
 
 %preun
+%if 0%{?el7:1}
+%systemd_preun collectd.service
+%else
+# stop collectd only when uninstalling
 if [ $1 -eq 0 ]; then
-       /sbin/service collectd stop &>/dev/null
-       /sbin/chkconfig --del collectd
+       /sbin/service collectd stop >/dev/null 2>&1 || :
+       /sbin/chkconfig --del collectd || :
 fi
+%endif
 
 %postun
-if [ $1 -ge 1 ]; then
-       /sbin/service collectd condrestart &>/dev/null || :
+%if 0%{?el7:1}
+%systemd_postun_with_restart collectd.service
+%else
+# restart collectd only when upgrading
+if [ $1 -eq 1 ]; then
+       /sbin/service collectd condrestart >/dev/null 2>&1 || :
 fi
+%endif
 
 %post -n libcollectdclient -p /sbin/ldconfig
 %postun -n libcollectdclient -p /sbin/ldconfig
@@ -1593,19 +1826,17 @@ fi
 %files
 %doc AUTHORS COPYING ChangeLog README
 %config(noreplace) %{_sysconfdir}/collectd.conf
+%if 0%{?el7:1}
+%{_unitdir}/collectd.service
+%else
 %{_initrddir}/collectd
+%endif
 %{_sbindir}/collectd
-%{_bindir}/collectd-nagios
-%{_bindir}/collectd-tg
-%{_bindir}/collectdctl
 %{_sbindir}/collectdmon
 %{_datadir}/collectd/types.db
 %{_sharedstatedir}/collectd
-%{_mandir}/man1/collectd-nagios.1*
 %{_mandir}/man1/collectd.1*
-%{_mandir}/man1/collectdctl.1*
 %{_mandir}/man1/collectdmon.1*
-%{_mandir}/man1/collectd-tg.1*
 %{_mandir}/man5/collectd-email.5*
 %{_mandir}/man5/collectd-exec.5*
 %{_mandir}/man5/collectd-threshold.5*
@@ -1655,8 +1886,8 @@ fi
 %if %{with_df}
 %{_libdir}/%{name}/df.so
 %endif
-%if %{with_disk}
-%{_libdir}/%{name}/disk.so
+%if %{with_drbd}
+%{_libdir}/%{name}/drbd.so
 %endif
 %if %{with_ethstat}
 %{_libdir}/%{name}/ethstat.so
@@ -1667,6 +1898,9 @@ fi
 %if %{with_exec}
 %{_libdir}/%{name}/exec.so
 %endif
+%if %{with_fhcount}
+%{_libdir}/%{name}/fhcount.so
+%endif
 %if %{with_filecount}
 %{_libdir}/%{name}/filecount.so
 %endif
@@ -1676,6 +1910,9 @@ fi
 %if %{with_interface}
 %{_libdir}/%{name}/interface.so
 %endif
+%if %{with_ipc}
+%{_libdir}/%{name}/ipc.so
+%endif
 %if %{with_ipvs}
 %{_libdir}/%{name}/ipvs.so
 %endif
@@ -1769,6 +2006,9 @@ fi
 %if %{with_threshold}
 %{_libdir}/%{name}/threshold.so
 %endif
+%if %{with_turbostat}
+%{_libdir}/%{name}/turbostat.so
+%endif
 %if %{with_unixsock}
 %{_libdir}/%{name}/unixsock.so
 %endif
@@ -1793,7 +2033,21 @@ fi
 %if %{with_write_graphite}
 %{_libdir}/%{name}/write_graphite.so
 %endif
-
+%if %{with_write_log}
+%{_libdir}/%{name}/write_log.so
+%endif
+%if %{with_write_sensu}
+%{_libdir}/%{name}/write_sensu.so
+%endif
+%if %{with_write_tsdb}
+%{_libdir}/%{name}/write_tsdb.so
+%endif
+%if %{with_zfs_arc}
+%{_libdir}/%{name}/zfs_arc.so
+%endif
+%if %{with_zookeeper}
+%{_libdir}/%{name}/zookeeper.so
+%endif
 
 %files -n libcollectdclient-devel
 %{_includedir}/collectd/client.h
@@ -1806,6 +2060,14 @@ fi
 %{_libdir}/libcollectdclient.so
 %{_libdir}/libcollectdclient.so.*
 
+%files -n collectd-utils
+%{_bindir}/collectd-nagios
+%{_bindir}/collectd-tg
+%{_bindir}/collectdctl
+%{_mandir}/man1/collectdctl.1*
+%{_mandir}/man1/collectd-nagios.1*
+%{_mandir}/man1/collectd-tg.1*
+
 %if %{with_amqp}
 %files amqp
 %{_libdir}/%{name}/amqp.so
@@ -1826,11 +2088,21 @@ fi
 %{_libdir}/%{name}/ascent.so
 %endif
 
+%if %{with_barometer}
+%files barometer
+%{_libdir}/%{name}/barometer.so
+%endif
+
 %if %{with_bind}
 %files bind
 %{_libdir}/%{name}/bind.so
 %endif
 
+%if %{with_ceph}
+%files ceph
+%{_libdir}/%{name}/ceph.so
+%endif
+
 %if %{with_curl}
 %files curl
 %{_libdir}/%{name}/curl.so
@@ -1846,6 +2118,11 @@ fi
 %{_libdir}/%{name}/curl_xml.so
 %endif
 
+%if %{with_disk}
+%files disk
+%{_libdir}/%{name}/disk.so
+%endif
+
 %if %{with_dns}
 %files dns
 %{_libdir}/%{name}/dns.so
@@ -1889,9 +2166,14 @@ fi
 %{_mandir}/man5/collectd-java.5*
 %endif
 
-%if %{with_libvirt}
-%files libvirt
-%{_libdir}/%{name}/libvirt.so
+%if %{with_virt}
+%files virt
+%{_libdir}/%{name}/virt.so
+%endif
+
+%if %{with_log_logstash}
+%files log_logstash
+%{_libdir}/%{name}/log_logstash.so
 %endif
 
 %if %{with_lvm}
@@ -1944,6 +2226,11 @@ fi
 %{_libdir}/%{name}/nut.so
 %endif
 
+%if %{with_openldap}
+%files openldap
+%{_libdir}/%{name}/openldap.so
+%endif
+
 %if %{with_perl}
 %files perl
 %{perl_vendorlib}/Collectd.pm
@@ -2000,6 +2287,11 @@ fi
 %{_libdir}/%{name}/sigrok.so
 %endif
 
+%if %{with_smart}
+%files smart
+%{_libdir}/%{name}/smart.so
+%endif
+
 %if %{with_snmp}
 %files snmp
 %{_mandir}/man5/collectd-snmp.5*
@@ -2016,6 +2308,11 @@ fi
 %{_libdir}/%{name}/write_http.so
 %endif
 
+%if %{with_write_kafka}
+%files write_kafka
+%{_libdir}/%{name}/write_kafka.so
+%endif
+
 %if %{with_write_redis}
 %files write_redis
 %{_libdir}/%{name}/write_redis.so
@@ -2038,6 +2335,18 @@ fi
 %doc contrib/
 
 %changelog
+* Wed May 27 2015 Marc Fournier <marc.fournier@camptocamp.com> 5.5.0-1
+- New upstream version
+- New plugins enabled by default: ceph, drbd, log_logstash, write_tsdb, smart,
+  openldap, redis, write_redis, zookeeper, write_log, write_sensu, ipc,
+  turbostat, fhcount
+- New plugins disabled by default: barometer, write_kafka
+- Enable zfs_arc, now supported on Linux
+- Install disk plugin in a dedicated package, as it depends on libudev
+- use systemd on EL7, sysvinit on EL6 & EL5
+- Install collectdctl, collectd-tg and collectd-nagios in collectd-utils.rpm
+- Add build-dependency on libcap-devel
+
 * Mon Aug 19 2013 Marc Fournier <marc.fournier@camptocamp.com> 5.4.0-1
 - New upstream version
 - Build netlink plugin by default
@@ -2090,7 +2399,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
 
@@ -2098,7 +2407,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.
diff --git a/contrib/systemd.collectd.service b/contrib/systemd.collectd.service
new file mode 100644 (file)
index 0000000..b046192
--- /dev/null
@@ -0,0 +1,23 @@
+[Unit]
+Description=Collectd
+After=local-fs.target network.target
+Requires=local-fs.target network.target
+
+[Service]
+ExecStart=/usr/sbin/collectd
+
+# Tell systemd it will receive a notification from collectd over it's control
+# socket once the daemon is ready. See systemd.service(5) for more details.
+Type=notify
+NotifyAccess=main
+
+# Restart the collectd daemon after a 10 seconds delay, in case it crashes.
+Restart=always
+RestartSec=10
+
+# Send all console messages to syslog.
+StandardOutput=syslog
+StandardError=syslog
+
+[Install]
+WantedBy=multi-user.target
index 1c7fd9c732956ab166a2bcda51c7e772dd374b96..f833edf63fe8343f77c043eb2c09b6b3d69e3ecf 100644 (file)
@@ -20,6 +20,7 @@ stop on runlevel [!2345]
 # these cannot be started at boot time by the system without
 # arcane trickery. Also a root user will not see these tasks/jobs
 # by default. set*id is a reasonable and secure compromise.
+# These options are not supported on early upstart versions.
 #setuid nobody
 #setgid nobody
 
@@ -31,17 +32,20 @@ stop on runlevel [!2345]
 # shell commands via `sh -e`.
 env DAEMON=/usr/sbin/collectd
 
-# Tell upstart to watch for forking when tracking the pid for us.
-expect fork
+# Tell upstart to wait for collectd to SIGSTOP itself, signaling it is ready
+# to run. Warning: this only works with collectd 5.5 and newer. You'll have to
+# use "expect fork" instead, if using collectd 5.4 and older.
+expect stop
 
 # prevent thrashing - 10 restarts in 5 seconds
 respawn
 respawn limit 10 5
 
-# Make a log available in /var/log/upstart/collectd.log
-console log
+# Uncomment to make a log available in /var/log/upstart/collectd.log
+# (not supported on early upstart versions).
+#console log
 
 # The daemon will not start if the configuration is invalid.
 pre-start exec $DAEMON -t
-# Let's Fork!
+# Let's start!
 exec $DAEMON
diff --git a/contrib/wiki2changelog.pl b/contrib/wiki2changelog.pl
new file mode 100755 (executable)
index 0000000..b8fc965
--- /dev/null
@@ -0,0 +1,75 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+=head1 NAME
+
+wiki2changelog.pl
+
+=head1 DESCRIPTION
+
+This script takes the change log from one of the "Version x.y" pages in
+collectd's wiki and converts it to the format used by the "ChangeLog" file.
+This is usually done as part of the release process.
+
+=cut
+
+our $TextWidth = 80;
+
+sub format_entry
+{
+       my $in = shift;
+       my $out = '';
+
+       my $line = "\t*";
+       my $line_len = 9;
+
+       for (split (' ', $in)) {
+               my $word = $_;
+               my $word_len = 1 + length $word;
+
+               if (($line_len + $word_len) > $TextWidth) {
+                       $out .= "$line\n";
+                       $line = "\t ";
+                       $line_len = 9;
+               }
+
+               $line .= " $word";
+               $line_len += $word_len;
+       }
+
+       if ($line_len != 9) {
+               $out .= "$line\n";
+       }
+
+       return $out;
+}
+
+while (<>)
+{
+       chomp;
+       my $line = $_;
+
+       if ($line =~ m#^\* (.*)#) {
+               $line = $1;
+       } else {
+               next;
+       }
+
+       $line =~ s#&lt;#<#g;
+       $line =~ s#&gt;#>#g;
+       $line =~ s#&nbsp;# #g;
+       $line =~ s#&quot;#"#g;
+
+       $line =~ s#\{\{Plugin\|([^}]+)\}\}#$1 plugin#g;
+       $line =~ s@\{\{Issue\|([^}]+)\}\}@#$1@g;
+       $line =~ s#\[\[[^|]+\|([^\]]+)\]\]#$1#g;
+       $line =~ s#\[\[([^|]+)\]\]#$1#g;
+
+       $line =~ s#'''(.*?)'''#*$1*#g;
+       $line =~ s#''(.*?)''#$1#g;
+       $line =~ s#<code>(.*?)</code>#"$1"#gi;
+
+       print format_entry($line);
+}
index 36b6bd77267d5b6eaf1bda44ea85fee8e0373709..07ffdda9ce58ec20107893a4513bef2d144c2ce1 100644 (file)
@@ -2,12 +2,16 @@ SUBDIRS = libcollectdclient
 if BUILD_WITH_OWN_LIBOCONFIG
 SUBDIRS += liboconfig
 endif
+SUBDIRS += daemon
+
+PLUGIN_LDFLAGS = -module -avoid-version -export-symbols-regex '\<module_register\>'
 
 if COMPILER_IS_GCC
 AM_CFLAGS = -Wall -Werror
 endif
 
-AM_CPPFLAGS = -DPREFIX='"${prefix}"'
+AM_CPPFLAGS = -I$(srcdir)/daemon
+AM_CPPFLAGS += -DPREFIX='"${prefix}"'
 AM_CPPFLAGS += -DCONFIGFILE='"${sysconfdir}/${PACKAGE_NAME}.conf"'
 AM_CPPFLAGS += -DLOCALSTATEDIR='"${localstatedir}"'
 AM_CPPFLAGS += -DPKGLOCALSTATEDIR='"${localstatedir}/lib/${PACKAGE_NAME}"'
@@ -17,81 +21,24 @@ endif
 AM_CPPFLAGS += -DPLUGINDIR='"${pkglibdir}"'
 AM_CPPFLAGS += -DPKGDATADIR='"${pkgdatadir}"'
 
-sbin_PROGRAMS = collectd collectdmon
-bin_PROGRAMS = collectd-nagios collectdctl collectd-tg
+AUTOMAKE_OPTIONS = subdir-objects
 
-collectd_SOURCES = collectd.c collectd.h \
-                  common.c common.h \
-                  configfile.c configfile.h \
-                  filter_chain.c filter_chain.h \
-                  meta_data.c meta_data.h \
-                  plugin.c plugin.h \
-                  utils_avltree.c utils_avltree.h \
-                  utils_cache.c utils_cache.h \
-                  utils_complain.c utils_complain.h \
-                  utils_heap.c utils_heap.h \
-                  utils_ignorelist.c utils_ignorelist.h \
-                  utils_llist.c utils_llist.h \
-                  utils_parse_option.c utils_parse_option.h \
-                  utils_random.c utils_random.h \
-                  utils_tail_match.c utils_tail_match.h \
-                  utils_match.c utils_match.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
-
-collectd_CPPFLAGS =  $(AM_CPPFLAGS) $(LTDLINCL)
-collectd_CFLAGS = $(AM_CFLAGS)
-collectd_LDFLAGS = -export-dynamic
-collectd_LDADD = -lm
-collectd_DEPENDENCIES =
-
-# Link to these libraries..
-if BUILD_WITH_LIBRT
-collectd_LDADD += -lrt
-endif
-if BUILD_WITH_LIBPOSIX4
-collectd_LDADD += -lposix4
-endif
-if BUILD_WITH_LIBSOCKET
-collectd_LDADD += -lsocket
-endif
-if BUILD_WITH_LIBRESOLV
-collectd_LDADD += -lresolv
-endif
-if BUILD_WITH_LIBPTHREAD
-collectd_LDADD += -lpthread
-endif
-if BUILD_WITH_LIBKSTAT
-collectd_LDADD += -lkstat
-endif
-if BUILD_WITH_LIBDEVINFO
-collectd_LDADD += -ldevinfo
-endif
-if BUILD_AIX
-collectd_LDFLAGS += -Wl,-bexpall,-brtllib
-endif
+noinst_LTLIBRARIES = libmount.la liblookup.la
 
-# The daemon needs to call sg_init, so we need to link it against libstatgrab,
-# too. -octo
-if BUILD_WITH_LIBSTATGRAB
-collectd_CFLAGS += $(BUILD_WITH_LIBSTATGRAB_CFLAGS)
-collectd_LDADD += $(BUILD_WITH_LIBSTATGRAB_LDFLAGS)
-endif
+libmount_la_SOURCES = utils_mount.c utils_mount.h
+libmount_la_LIBADD = daemon/libcommon.la
 
-if BUILD_WITH_OWN_LIBOCONFIG
-collectd_LDADD += $(LIBLTDL) liboconfig/liboconfig.la
-collectd_DEPENDENCIES += liboconfig/liboconfig.la
-else
-collectd_LDADD += -loconfig
-endif
+liblookup_la_SOURCES = utils_vl_lookup.c utils_vl_lookup.h
+liblookup_la_LIBADD = daemon/libavltree.la daemon/libcommon.la
+
+sbin_PROGRAMS = collectdmon
+bin_PROGRAMS = collectd-nagios collectdctl collectd-tg
 
 collectdmon_SOURCES = collectdmon.c
 collectdmon_CPPFLAGS = $(AM_CPPFLAGS)
 
 collectd_nagios_SOURCES = collectd-nagios.c
-collectd_nagios_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_builddir)/src/libcollectdclient/collectd
+collectd_nagios_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/src/libcollectdclient/collectd -I$(top_builddir)/src/libcollectdclient/collectd
 collectd_nagios_LDADD =
 if BUILD_WITH_LIBSOCKET
 collectd_nagios_LDADD += -lsocket
@@ -105,7 +52,7 @@ collectd_nagios_DEPENDENCIES = libcollectdclient/libcollectdclient.la
 
 
 collectdctl_SOURCES = collectdctl.c
-collectdctl_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_builddir)/src/libcollectdclient/collectd
+collectdctl_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/src/libcollectdclient/collectd -I$(top_builddir)/src/libcollectdclient/collectd
 collectdctl_LDADD =
 if BUILD_WITH_LIBSOCKET
 collectdctl_LDADD += -lsocket
@@ -116,10 +63,9 @@ endif
 collectdctl_LDADD += libcollectdclient/libcollectdclient.la
 collectdctl_DEPENDENCIES = libcollectdclient/libcollectdclient.la
 
-collectd_tg_SOURCES = collectd-tg.c \
-                     utils_heap.c utils_heap.h
-collectd_tg_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_builddir)/src/libcollectdclient/collectd
-collectd_tg_LDADD =
+collectd_tg_SOURCES = collectd-tg.c
+collectd_tg_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/src/libcollectdclient/collectd -I$(top_builddir)/src/libcollectdclient/collectd
+collectd_tg_LDADD = daemon/libheap.la
 if BUILD_WITH_LIBSOCKET
 collectd_tg_LDADD += -lsocket
 endif
@@ -129,23 +75,24 @@ endif
 if BUILD_AIX
 collectd_tg_LDADD += -lm
 endif
+if BUILD_WITH_LIBPTHREAD
+collectd_tg_LDADD += -lpthread
+endif
 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
 pkglib_LTLIBRARIES += aggregation.la
 aggregation_la_SOURCES = aggregation.c \
                          utils_vl_lookup.c utils_vl_lookup.h
-aggregation_la_LDFLAGS = -module -avoid-version
+aggregation_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 aggregation_la_LIBADD = -lm
-collectd_LDADD += "-dlopen" aggregation.la
-collectd_DEPENDENCIES += aggregation.la
 endif
 
 if BUILD_PLUGIN_AMQP
@@ -155,126 +102,122 @@ amqp_la_SOURCES = amqp.c \
                  utils_parse_option.c utils_parse_option.h \
                  utils_format_graphite.c utils_format_graphite.h \
                  utils_format_json.c utils_format_json.h
-amqp_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_LIBRABBITMQ_LDFLAGS)
+amqp_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBRABBITMQ_LDFLAGS)
 amqp_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBRABBITMQ_CPPFLAGS)
 amqp_la_LIBADD = $(BUILD_WITH_LIBRABBITMQ_LIBS)
-collectd_LDADD += "-dlopen" amqp.la
-collectd_DEPENDENCIES += amqp.la
 endif
 
 if BUILD_PLUGIN_APACHE
 pkglib_LTLIBRARIES += apache.la
 apache_la_SOURCES = apache.c
-apache_la_LDFLAGS = -module -avoid-version
+apache_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 apache_la_CFLAGS = $(AM_CFLAGS)
 apache_la_LIBADD =
-collectd_LDADD += "-dlopen" apache.la
 if BUILD_WITH_LIBCURL
 apache_la_CFLAGS += $(BUILD_WITH_LIBCURL_CFLAGS)
 apache_la_LIBADD += $(BUILD_WITH_LIBCURL_LIBS)
 endif
-collectd_DEPENDENCIES += apache.la
 endif
 
 if BUILD_PLUGIN_APCUPS
 pkglib_LTLIBRARIES += apcups.la
 apcups_la_SOURCES = apcups.c
-apcups_la_LDFLAGS = -module -avoid-version
+apcups_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 apcups_la_LIBADD =
 if BUILD_WITH_LIBSOCKET
 apcups_la_LIBADD += -lsocket
 endif
-collectd_LDADD += "-dlopen" apcups.la
-collectd_DEPENDENCIES += apcups.la
 endif
 
 if BUILD_PLUGIN_APPLE_SENSORS
 pkglib_LTLIBRARIES += apple_sensors.la
 apple_sensors_la_SOURCES = apple_sensors.c
-apple_sensors_la_LDFLAGS = -module -avoid-version
+apple_sensors_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 apple_sensors_la_LDFLAGS += -framework IOKit
-collectd_LDADD += "-dlopen" apple_sensors.la
-collectd_DEPENDENCIES += apple_sensors.la
 endif
 
 if BUILD_PLUGIN_AQUAERO
 pkglib_LTLIBRARIES += aquaero.la
 aquaero_la_SOURCES = aquaero.c
-aquaero_la_LDFLAGS = -module -avoid-version
+aquaero_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 aquaero_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBAQUAERO5_CFLAGS)
 aquaero_la_LIBADD = $(BUILD_WITH_LIBAQUAERO5_LDFLAGS) -laquaero5
-collectd_LDADD += "-dlopen" aquaero.la
-collectd_DEPENDENCIES += aquaero.la
 endif
 
 if BUILD_PLUGIN_ASCENT
 pkglib_LTLIBRARIES += ascent.la
 ascent_la_SOURCES = ascent.c
-ascent_la_LDFLAGS = -module -avoid-version
+ascent_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 ascent_la_CFLAGS = $(AM_CFLAGS) \
                $(BUILD_WITH_LIBCURL_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
 ascent_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS) $(BUILD_WITH_LIBXML2_LIBS)
-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 = $(PLUGIN_LDFLAGS)
+barometer_la_LIBADD = -lm
 endif
 
 if BUILD_PLUGIN_BATTERY
 pkglib_LTLIBRARIES += battery.la
 battery_la_SOURCES = battery.c
-battery_la_LDFLAGS = -module -avoid-version
+battery_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 battery_la_LIBADD =
 if BUILD_WITH_LIBIOKIT
 battery_la_LDFLAGS += -framework IOKit
 endif
-collectd_LDADD += "-dlopen" battery.la
-collectd_DEPENDENCIES += battery.la
 endif
 
 if BUILD_PLUGIN_BIND
 pkglib_LTLIBRARIES += bind.la
 bind_la_SOURCES = bind.c
-bind_la_LDFLAGS = -module -avoid-version
+bind_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 bind_la_CFLAGS = $(AM_CFLAGS) \
-               $(BUILD_WITH_LIBCURL_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
+                $(BUILD_WITH_LIBCURL_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
 bind_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS) $(BUILD_WITH_LIBXML2_LIBS)
-collectd_LDADD += "-dlopen" bind.la
-collectd_DEPENDENCIES += bind.la
+endif
+
+if BUILD_PLUGIN_CEPH
+pkglib_LTLIBRARIES += ceph.la
+ceph_la_SOURCES = ceph.c
+ceph_la_CFLAGS = $(AM_CFLAGS)
+ceph_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBYAJL_LDFLAGS)
+ceph_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBYAJL_CPPFLAGS)
+ceph_la_LIBADD = $(BUILD_WITH_LIBYAJL_LIBS)
 endif
 
 if BUILD_PLUGIN_CGROUPS
 pkglib_LTLIBRARIES += cgroups.la
-cgroups_la_SOURCES = cgroups.c utils_mount.c utils_mount.h
-cgroups_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" cgroups.la
-collectd_DEPENDENCIES += cgroups.la
+cgroups_la_SOURCES = cgroups.c \
+                    utils_ignorelist.c utils_ignorelist.h
+cgroups_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+cgroups_la_LIBADD = libmount.la
 endif
 
 if BUILD_PLUGIN_CONNTRACK
 pkglib_LTLIBRARIES += conntrack.la
 conntrack_la_SOURCES = conntrack.c
-conntrack_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" conntrack.la
-collectd_DEPENDENCIES += conntrack.la
+conntrack_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_CONTEXTSWITCH
 pkglib_LTLIBRARIES += contextswitch.la
 contextswitch_la_SOURCES = contextswitch.c
-contextswitch_la_LDFLAGS = -module -avoid-version
+contextswitch_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 contextswitch_la_LIBADD =
 if BUILD_WITH_PERFSTAT
 contextswitch_la_LIBADD += -lperfstat
 endif
-collectd_LDADD += "-dlopen" contextswitch.la
-collectd_DEPENDENCIES += contextswitch.la
 endif
 
 if BUILD_PLUGIN_CPU
 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_LDFLAGS = $(PLUGIN_LDFLAGS)
+cpu_la_LIBADD =
 if BUILD_WITH_LIBKSTAT
 cpu_la_LIBADD += -lkstat
 endif
@@ -288,64 +231,52 @@ endif
 if BUILD_WITH_PERFSTAT
 cpu_la_LIBADD += -lperfstat
 endif
-collectd_LDADD += "-dlopen" cpu.la
-collectd_DEPENDENCIES += cpu.la
 endif
 
 if BUILD_PLUGIN_CPUFREQ
 pkglib_LTLIBRARIES += cpufreq.la
 cpufreq_la_SOURCES = cpufreq.c
-cpufreq_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" cpufreq.la
-collectd_DEPENDENCIES += cpufreq.la
+cpufreq_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_CSV
 pkglib_LTLIBRARIES += csv.la
 csv_la_SOURCES = csv.c
-csv_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" csv.la
-collectd_DEPENDENCIES += csv.la
+csv_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_CURL
 pkglib_LTLIBRARIES += curl.la
 curl_la_SOURCES = curl.c
-curl_la_LDFLAGS = -module -avoid-version
+curl_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 curl_la_CFLAGS = $(AM_CFLAGS)
 curl_la_LIBADD =
-collectd_LDADD += "-dlopen" curl.la
 if BUILD_WITH_LIBCURL
 curl_la_CFLAGS += $(BUILD_WITH_LIBCURL_CFLAGS)
 curl_la_LIBADD += $(BUILD_WITH_LIBCURL_LIBS)
 endif
-collectd_DEPENDENCIES += curl.la
 endif
 
 if BUILD_PLUGIN_CURL_JSON
 pkglib_LTLIBRARIES += curl_json.la
 curl_json_la_SOURCES = curl_json.c
 curl_json_la_CFLAGS = $(AM_CFLAGS)
-curl_json_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_LIBYAJL_LDFLAGS)
-curl_json_la_CPPFLAGS = $(BUILD_WITH_LIBYAJL_CPPFLAGS)
+curl_json_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBYAJL_LDFLAGS)
+curl_json_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBYAJL_CPPFLAGS)
 curl_json_la_LIBADD = $(BUILD_WITH_LIBYAJL_LIBS)
 if BUILD_WITH_LIBCURL
 curl_json_la_CFLAGS += $(BUILD_WITH_LIBCURL_CFLAGS)
 curl_json_la_LIBADD += $(BUILD_WITH_LIBCURL_LIBS)
 endif
-collectd_LDADD += "-dlopen" curl_json.la
-collectd_DEPENDENCIES += curl_json.la
 endif
 
 if BUILD_PLUGIN_CURL_XML
 pkglib_LTLIBRARIES += curl_xml.la
 curl_xml_la_SOURCES = curl_xml.c
-curl_xml_la_LDFLAGS = -module -avoid-version
+curl_xml_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 curl_xml_la_CFLAGS = $(AM_CFLAGS) \
                $(BUILD_WITH_LIBCURL_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
 curl_xml_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS) $(BUILD_WITH_LIBXML2_LIBS)
-collectd_LDADD += "-dlopen" curl_xml.la
-collectd_DEPENDENCIES += curl_xml.la
 endif
 
 if BUILD_PLUGIN_DBI
@@ -353,26 +284,25 @@ pkglib_LTLIBRARIES += dbi.la
 dbi_la_SOURCES = dbi.c \
                 utils_db_query.c utils_db_query.h
 dbi_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBDBI_CPPFLAGS)
-dbi_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_LIBDBI_LDFLAGS)
+dbi_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBDBI_LDFLAGS)
 dbi_la_LIBADD = $(BUILD_WITH_LIBDBI_LIBS)
-collectd_LDADD += "-dlopen" dbi.la
-collectd_DEPENDENCIES += dbi.la
 endif
 
 if BUILD_PLUGIN_DF
 pkglib_LTLIBRARIES += df.la
-df_la_SOURCES = df.c utils_mount.c utils_mount.h
-df_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" df.la
-collectd_DEPENDENCIES += df.la
+df_la_SOURCES = df.c \
+               utils_ignorelist.c utils_ignorelist.h
+df_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+df_la_LIBADD = libmount.la
 endif
 
 if BUILD_PLUGIN_DISK
 pkglib_LTLIBRARIES += disk.la
-disk_la_SOURCES = disk.c
+disk_la_SOURCES = disk.c \
+                 utils_ignorelist.c utils_ignorelist.h
 disk_la_CFLAGS = $(AM_CFLAGS)
-disk_la_LDFLAGS = -module -avoid-version
-disk_la_LIBADD = 
+disk_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+disk_la_LIBADD =
 if BUILD_WITH_LIBKSTAT
 disk_la_LIBADD += -lkstat
 endif
@@ -383,99 +313,97 @@ 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
-collectd_LDADD += "-dlopen" disk.la
-collectd_DEPENDENCIES += disk.la
 endif
 
 if BUILD_PLUGIN_DNS
 pkglib_LTLIBRARIES += dns.la
 dns_la_SOURCES = dns.c utils_dns.c utils_dns.h
-dns_la_LDFLAGS = -module -avoid-version
+dns_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 dns_la_LIBADD = -lpcap -lpthread
-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 = $(PLUGIN_LDFLAGS)
+drbd_la_LIBADD = -lpthread
 endif
 
 if BUILD_PLUGIN_EMAIL
 pkglib_LTLIBRARIES += email.la
 email_la_SOURCES = email.c
-email_la_LDFLAGS = -module -avoid-version
+email_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 email_la_LIBADD = -lpthread
-collectd_LDADD += "-dlopen" email.la
-collectd_DEPENDENCIES += email.la
 endif
 
 if BUILD_PLUGIN_ENTROPY
 pkglib_LTLIBRARIES += entropy.la
 entropy_la_SOURCES = entropy.c
-entropy_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" entropy.la
-collectd_DEPENDENCIES += entropy.la
+entropy_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_EXEC
 pkglib_LTLIBRARIES += exec.la
 exec_la_SOURCES = exec.c \
                  utils_cmd_putnotif.c utils_cmd_putnotif.h \
-                 utils_cmd_putval.c utils_cmd_putval.h
-exec_la_LDFLAGS = -module -avoid-version
+                 utils_cmd_putval.c utils_cmd_putval.h \
+                 utils_parse_option.h utils_parse_option.c
+exec_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 exec_la_LIBADD = -lpthread
-collectd_LDADD += "-dlopen" exec.la
-collectd_DEPENDENCIES += exec.la
 endif
 
 if BUILD_PLUGIN_ETHSTAT
 pkglib_LTLIBRARIES += ethstat.la
 ethstat_la_SOURCES = ethstat.c
-ethstat_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" ethstat.la
-collectd_DEPENDENCIES += ethstat.la
+ethstat_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+endif
+
+if BUILD_PLUGIN_FHCOUNT
+pkglib_LTLIBRARIES += fhcount.la
+fhcount_la_SOURCES = fhcount.c
+fhcount_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_FILECOUNT
 pkglib_LTLIBRARIES += filecount.la
 filecount_la_SOURCES = filecount.c
-filecount_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" filecount.la
-collectd_DEPENDENCIES += filecount.la
+filecount_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_GMOND
 pkglib_LTLIBRARIES += gmond.la
 gmond_la_SOURCES = gmond.c
 gmond_la_CPPFLAGS = $(AM_CPPFLAGS) $(GANGLIA_CPPFLAGS)
-gmond_la_LDFLAGS = -module -avoid-version $(GANGLIA_LDFLAGS)
+gmond_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(GANGLIA_LDFLAGS)
 gmond_la_LIBADD = $(GANGLIA_LIBS)
-collectd_LDADD += "-dlopen" gmond.la
-collectd_DEPENDENCIES += gmond.la
 endif
 
 if BUILD_PLUGIN_HDDTEMP
 pkglib_LTLIBRARIES += hddtemp.la
 hddtemp_la_SOURCES = hddtemp.c
-hddtemp_la_LDFLAGS = -module -avoid-version
+hddtemp_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 hddtemp_la_LIBADD =
 if BUILD_WITH_LIBSOCKET
 hddtemp_la_LIBADD += -lsocket
 endif
-collectd_LDADD += "-dlopen" hddtemp.la
-collectd_DEPENDENCIES += hddtemp.la
 endif
 
 if BUILD_PLUGIN_INTERFACE
 pkglib_LTLIBRARIES += interface.la
-interface_la_SOURCES = interface.c
+interface_la_SOURCES = interface.c \
+                      utils_ignorelist.c utils_ignorelist.h
 interface_la_CFLAGS = $(AM_CFLAGS)
-interface_la_LDFLAGS = -module -avoid-version
+interface_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 interface_la_LIBADD =
-collectd_LDADD += "-dlopen" interface.la
-collectd_DEPENDENCIES += interface.la
 if BUILD_WITH_LIBSTATGRAB
 interface_la_CFLAGS += $(BUILD_WITH_LIBSTATGRAB_CFLAGS)
 interface_la_LIBADD += $(BUILD_WITH_LIBSTATGRAB_LDFLAGS)
@@ -492,24 +420,28 @@ interface_la_LIBADD += -lperfstat
 endif
 endif # BUILD_PLUGIN_INTERFACE
 
+if BUILD_PLUGIN_IPC
+pkglib_LTLIBRARIES += ipc.la
+ipc_la_SOURCES = ipc.c
+ipc_la_CFLAGS = $(AM_CFLAGS)
+ipc_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+endif
+
 if BUILD_PLUGIN_IPTABLES
 pkglib_LTLIBRARIES += iptables.la
 iptables_la_SOURCES = iptables.c
 iptables_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBIPTC_CPPFLAGS)
-iptables_la_LDFLAGS = -module -avoid-version
+iptables_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 iptables_la_LIBADD = $(BUILD_WITH_LIBIPTC_LDFLAGS)
-collectd_LDADD += "-dlopen" iptables.la
-collectd_DEPENDENCIES += iptables.la
 endif
 
 if BUILD_PLUGIN_IPMI
 pkglib_LTLIBRARIES += ipmi.la
-ipmi_la_SOURCES = ipmi.c
+ipmi_la_SOURCES = ipmi.c \
+                 utils_ignorelist.c utils_ignorelist.h
 ipmi_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_OPENIPMI_CFLAGS)
-ipmi_la_LDFLAGS = -module -avoid-version
+ipmi_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 ipmi_la_LIBADD = $(BUILD_WITH_OPENIPMI_LIBS)
-collectd_LDADD += "-dlopen" ipmi.la
-collectd_DEPENDENCIES += ipmi.la
 endif
 
 if BUILD_PLUGIN_IPVS
@@ -518,17 +450,14 @@ ipvs_la_SOURCES = ipvs.c
 if IP_VS_H_NEEDS_KERNEL_CFLAGS
 ipvs_la_CFLAGS = $(AM_CFLAGS) $(KERNEL_CFLAGS)
 endif
-ipvs_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" ipvs.la
-collectd_DEPENDENCIES += ipvs.la
+ipvs_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_IRQ
 pkglib_LTLIBRARIES += irq.la
-irq_la_SOURCES = irq.c
-irq_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" irq.la
-collectd_DEPENDENCIES += irq.la
+irq_la_SOURCES = irq.c \
+                utils_ignorelist.c utils_ignorelist.h
+irq_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_JAVA
@@ -536,31 +465,16 @@ pkglib_LTLIBRARIES += java.la
 java_la_SOURCES = java.c
 java_la_CPPFLAGS = $(AM_CPPFLAGS) $(JAVA_CPPFLAGS)
 java_la_CFLAGS = $(AM_CFLAGS) $(JAVA_CFLAGS)
-java_la_LDFLAGS = -module -avoid-version $(JAVA_LDFLAGS)
+java_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(JAVA_LDFLAGS)
 java_la_LIBADD = $(JAVA_LIBS)
-collectd_LDADD += "-dlopen" java.la
-collectd_DEPENDENCIES += java.la
-endif
-
-if BUILD_PLUGIN_LIBVIRT
-pkglib_LTLIBRARIES += libvirt.la
-libvirt_la_SOURCES = libvirt.c
-libvirt_la_CFLAGS = $(AM_CFLAGS) \
-               $(BUILD_WITH_LIBVIRT_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
-libvirt_la_LIBADD = $(BUILD_WITH_LIBVIRT_LIBS) $(BUILD_WITH_LIBXML2_LIBS)
-libvirt_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" libvirt.la
-collectd_DEPENDENCIES += libvirt.la
 endif
 
 if BUILD_PLUGIN_LOAD
 pkglib_LTLIBRARIES += load.la
 load_la_SOURCES = load.c
 load_la_CFLAGS = $(AM_CFLAGS)
-load_la_LDFLAGS = -module -avoid-version
+load_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 load_la_LIBADD =
-collectd_LDADD += "-dlopen" load.la
-collectd_DEPENDENCIES += load.la
 if BUILD_WITH_LIBSTATGRAB
 load_la_CFLAGS += $(BUILD_WITH_LIBSTATGRAB_CFLAGS)
 load_la_LIBADD += $(BUILD_WITH_LIBSTATGRAB_LDFLAGS)
@@ -573,127 +487,110 @@ endif # BUILD_PLUGIN_LOAD
 if BUILD_PLUGIN_LOGFILE
 pkglib_LTLIBRARIES += logfile.la
 logfile_la_SOURCES = logfile.c
-logfile_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" logfile.la
-collectd_DEPENDENCIES += logfile.la
+logfile_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+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 = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBYAJL_LDFLAGS)
+log_logstash_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBYAJL_CPPFLAGS)
+log_logstash_la_LIBADD = $(BUILD_WITH_LIBYAJL_LIBS)
 endif
 
 if BUILD_PLUGIN_LPAR
 pkglib_LTLIBRARIES += lpar.la
 lpar_la_SOURCES = lpar.c
-lpar_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" lpar.la
-collectd_DEPENDENCIES += lpar.la
+lpar_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 lpar_la_LIBADD = -lperfstat
 endif
 
 if BUILD_PLUGIN_LVM
 pkglib_LTLIBRARIES += lvm.la
 lvm_la_SOURCES = lvm.c
-lvm_la_LDFLAGS = -module -avoid-version
+lvm_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 lvm_la_LIBADD = $(BUILD_WITH_LIBLVM2APP_LIBS)
-collectd_LDADD += "-dlopen" lvm.la
-collectd_DEPENDENCIES += lvm.la
 endif
 
 if BUILD_PLUGIN_MADWIFI
 pkglib_LTLIBRARIES += madwifi.la
-madwifi_la_SOURCES = madwifi.c madwifi.h
-madwifi_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" madwifi.la
-collectd_DEPENDENCIES += madwifi.la
+madwifi_la_SOURCES = madwifi.c madwifi.h \
+                    utils_ignorelist.c utils_ignorelist.h
+madwifi_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_MATCH_EMPTY_COUNTER
 pkglib_LTLIBRARIES += match_empty_counter.la
 match_empty_counter_la_SOURCES = match_empty_counter.c
-match_empty_counter_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" match_empty_counter.la
-collectd_DEPENDENCIES += match_empty_counter.la
+match_empty_counter_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_MATCH_HASHED
 pkglib_LTLIBRARIES += match_hashed.la
 match_hashed_la_SOURCES = match_hashed.c
-match_hashed_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" match_hashed.la
-collectd_DEPENDENCIES += match_hashed.la
+match_hashed_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_MATCH_REGEX
 pkglib_LTLIBRARIES += match_regex.la
 match_regex_la_SOURCES = match_regex.c
-match_regex_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" match_regex.la
-collectd_DEPENDENCIES += match_regex.la
+match_regex_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_MATCH_TIMEDIFF
 pkglib_LTLIBRARIES += match_timediff.la
 match_timediff_la_SOURCES = match_timediff.c
-match_timediff_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" match_timediff.la
-collectd_DEPENDENCIES += match_timediff.la
+match_timediff_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_MATCH_VALUE
 pkglib_LTLIBRARIES += match_value.la
 match_value_la_SOURCES = match_value.c
-match_value_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" match_value.la
-collectd_DEPENDENCIES += match_value.la
+match_value_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_MBMON
 pkglib_LTLIBRARIES += mbmon.la
 mbmon_la_SOURCES = mbmon.c
-mbmon_la_LDFLAGS = -module -avoid-version
+mbmon_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 mbmon_la_LIBADD =
 if BUILD_WITH_LIBSOCKET
 mbmon_la_LIBADD += -lsocket
 endif
-collectd_LDADD += "-dlopen" mbmon.la
-collectd_DEPENDENCIES += mbmon.la
 endif
 
 if BUILD_PLUGIN_MD
 pkglib_LTLIBRARIES += md.la
-md_la_SOURCES = md.c
-md_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" md.la
-collectd_DEPENDENCIES += md.la
+md_la_SOURCES = md.c \
+               utils_ignorelist.c utils_ignorelist.h
+md_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_MEMCACHEC
 pkglib_LTLIBRARIES += memcachec.la
 memcachec_la_SOURCES = memcachec.c
-memcachec_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_LIBMEMCACHED_LDFLAGS)
-memcachec_la_CPPFLAGS = $(BUILD_WITH_LIBMEMCACHED_CPPFLAGS)
+memcachec_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBMEMCACHED_LDFLAGS)
+memcachec_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBMEMCACHED_CPPFLAGS)
 memcachec_la_LIBADD = $(BUILD_WITH_LIBMEMCACHED_LIBS)
-collectd_LDADD += "-dlopen" memcachec.la
-collectd_DEPENDENCIES += memcachec.la
 endif
 
 if BUILD_PLUGIN_MEMCACHED
 pkglib_LTLIBRARIES += memcached.la
 memcached_la_SOURCES = memcached.c
-memcached_la_LDFLAGS = -module -avoid-version
+memcached_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 memcached_la_LIBADD =
 if BUILD_WITH_LIBSOCKET
 memcached_la_LIBADD += -lsocket
 endif
-collectd_LDADD += "-dlopen" memcached.la
-collectd_DEPENDENCIES += memcached.la
 endif
 
 if BUILD_PLUGIN_MEMORY
 pkglib_LTLIBRARIES += memory.la
 memory_la_SOURCES = memory.c
 memory_la_CFLAGS = $(AM_CFLAGS)
-memory_la_LDFLAGS = -module -avoid-version
+memory_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 memory_la_LIBADD =
-collectd_LDADD += "-dlopen" memory.la
-collectd_DEPENDENCIES += memory.la
 if BUILD_WITH_LIBKSTAT
 memory_la_LIBADD += -lkstat
 endif
@@ -709,56 +606,56 @@ memory_la_LIBADD += -lperfstat
 endif
 endif
 
+if BUILD_PLUGIN_MIC
+pkglib_LTLIBRARIES += mic.la
+mic_la_SOURCES = mic.c \
+                utils_ignorelist.c utils_ignorelist.h
+mic_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_MIC_LIBPATH)
+mic_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_MIC_CPPFLAGS)
+mic_la_LIBADD = $(BUILD_WITH_MIC_LDADD)
+endif
+
 if BUILD_PLUGIN_MODBUS
 pkglib_LTLIBRARIES += modbus.la
 modbus_la_SOURCES = modbus.c
-modbus_la_LDFLAGS = -module -avoid-version
+modbus_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 modbus_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBMODBUS_CFLAGS)
 modbus_la_LIBADD = $(BUILD_WITH_LIBMODBUS_LIBS)
-collectd_LDADD += "-dlopen" modbus.la
-collectd_DEPENDENCIES += modbus.la
 endif
 
 if BUILD_PLUGIN_MULTIMETER
 pkglib_LTLIBRARIES += multimeter.la
 multimeter_la_SOURCES = multimeter.c
-multimeter_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" multimeter.la
-collectd_DEPENDENCIES += multimeter.la
+multimeter_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_MYSQL
 pkglib_LTLIBRARIES += mysql.la
 mysql_la_SOURCES = mysql.c
-mysql_la_LDFLAGS = -module -avoid-version
+mysql_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 mysql_la_CFLAGS = $(AM_CFLAGS)
 mysql_la_LIBADD =
-collectd_LDADD += "-dlopen" mysql.la
 if BUILD_WITH_LIBMYSQL
 mysql_la_CFLAGS += $(BUILD_WITH_LIBMYSQL_CFLAGS)
 mysql_la_LIBADD += $(BUILD_WITH_LIBMYSQL_LIBS)
 endif
-collectd_DEPENDENCIES += mysql.la
 endif
 
 if BUILD_PLUGIN_NETAPP
 pkglib_LTLIBRARIES += netapp.la
-netapp_la_SOURCES = netapp.c
+netapp_la_SOURCES = netapp.c \
+                   utils_ignorelist.c utils_ignorelist.h
 netapp_la_CPPFLAGS = $(AM_CPPFLAGS) $(LIBNETAPP_CPPFLAGS)
-netapp_la_LDFLAGS = -module -avoid-version $(LIBNETAPP_LDFLAGS)
+netapp_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(LIBNETAPP_LDFLAGS)
 netapp_la_LIBADD = $(LIBNETAPP_LIBS)
-collectd_LDADD += "-dlopen" netapp.la
-collectd_DEPENDENCIES += netapp.la
 endif
 
 if BUILD_PLUGIN_NETLINK
 pkglib_LTLIBRARIES += netlink.la
 netlink_la_SOURCES = netlink.c
-netlink_la_LDFLAGS = -module -avoid-version
+netlink_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 netlink_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBMNL_CFLAGS)
 netlink_la_LIBADD = $(BUILD_WITH_LIBMNL_LIBS)
-collectd_LDADD += "-dlopen" netlink.la
-collectd_DEPENDENCIES += netlink.la
 endif
 
 if BUILD_PLUGIN_NETWORK
@@ -766,7 +663,7 @@ pkglib_LTLIBRARIES += network.la
 network_la_SOURCES = network.c network.h \
                     utils_fbhash.c utils_fbhash.h
 network_la_CPPFLAGS = $(AM_CPPFLAGS)
-network_la_LDFLAGS = -module -avoid-version
+network_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 network_la_LIBADD = -lpthread
 if BUILD_WITH_LIBSOCKET
 network_la_LIBADD += -lsocket
@@ -776,24 +673,18 @@ network_la_CPPFLAGS += $(GCRYPT_CPPFLAGS)
 network_la_LDFLAGS += $(GCRYPT_LDFLAGS)
 network_la_LIBADD += $(GCRYPT_LIBS)
 endif
-collectd_LDADD += "-dlopen" network.la
-collectd_DEPENDENCIES += network.la
 endif
 
 if BUILD_PLUGIN_NFS
 pkglib_LTLIBRARIES += nfs.la
 nfs_la_SOURCES = nfs.c
-nfs_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" nfs.la
-collectd_DEPENDENCIES += nfs.la
+nfs_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_FSCACHE
 pkglib_LTLIBRARIES += fscache.la
 fscache_la_SOURCES = fscache.c
-fscache_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" fscache.la
-collectd_DEPENDENCIES += fscache.la
+fscache_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_NGINX
@@ -801,94 +692,85 @@ pkglib_LTLIBRARIES += nginx.la
 nginx_la_SOURCES = nginx.c
 nginx_la_CFLAGS = $(AM_CFLAGS)
 nginx_la_LIBADD =
-nginx_la_LDFLAGS = -module -avoid-version
+nginx_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 if BUILD_WITH_LIBCURL
 nginx_la_CFLAGS += $(BUILD_WITH_LIBCURL_CFLAGS)
 nginx_la_LIBADD += $(BUILD_WITH_LIBCURL_LIBS)
 endif
-collectd_LDADD += "-dlopen" nginx.la
-collectd_DEPENDENCIES += nginx.la
 endif
 
 if BUILD_PLUGIN_NOTIFY_DESKTOP
 pkglib_LTLIBRARIES += notify_desktop.la
 notify_desktop_la_SOURCES = notify_desktop.c
 notify_desktop_la_CFLAGS = $(AM_CFLAGS) $(LIBNOTIFY_CFLAGS)
-notify_desktop_la_LDFLAGS = -module -avoid-version
+notify_desktop_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 notify_desktop_la_LIBADD = $(LIBNOTIFY_LIBS)
-collectd_LDADD += "-dlopen" notify_desktop.la
-collectd_DEPENDENCIES += notify_desktop.la
 endif
 
 if BUILD_PLUGIN_NOTIFY_EMAIL
 pkglib_LTLIBRARIES += notify_email.la
 notify_email_la_SOURCES = notify_email.c
-notify_email_la_LDFLAGS = -module -avoid-version
+notify_email_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 notify_email_la_LIBADD = -lesmtp -lssl -lcrypto -lpthread
-collectd_LDADD += "-dlopen" notify_email.la
-collectd_DEPENDENCIES += notify_email.la
 endif
 
 if BUILD_PLUGIN_NTPD
 pkglib_LTLIBRARIES += ntpd.la
 ntpd_la_SOURCES = ntpd.c
-ntpd_la_LDFLAGS = -module -avoid-version
+ntpd_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 ntpd_la_LIBADD =
 if BUILD_WITH_LIBSOCKET
 ntpd_la_LIBADD += -lsocket
 endif
-collectd_LDADD += "-dlopen" ntpd.la
-collectd_DEPENDENCIES += ntpd.la
 endif
 
 if BUILD_PLUGIN_NUMA
 pkglib_LTLIBRARIES += numa.la
 numa_la_SOURCES = numa.c
-numa_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" numa.la
-collectd_DEPENDENCIES += numa.la
+numa_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_NUT
 pkglib_LTLIBRARIES += nut.la
 nut_la_SOURCES = nut.c
 nut_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBUPSCLIENT_CFLAGS)
-nut_la_LDFLAGS = -module -avoid-version
+nut_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 nut_la_LIBADD = -lpthread $(BUILD_WITH_LIBUPSCLIENT_LIBS)
-collectd_LDADD += "-dlopen" nut.la
-collectd_DEPENDENCIES += nut.la
 endif
 
 if BUILD_PLUGIN_OLSRD
 pkglib_LTLIBRARIES += olsrd.la
 olsrd_la_SOURCES = olsrd.c
-olsrd_la_LDFLAGS = -module -avoid-version
-olsrd_la_LIBADD = 
+olsrd_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+olsrd_la_LIBADD =
 if BUILD_WITH_LIBSOCKET
 olsrd_la_LIBADD += -lsocket
 endif
-collectd_LDADD += "-dlopen" olsrd.la
-collectd_DEPENDENCIES += olsrd.la
 endif
 
 if BUILD_PLUGIN_ONEWIRE
 pkglib_LTLIBRARIES += onewire.la
-onewire_la_SOURCES = onewire.c
+onewire_la_SOURCES = onewire.c \
+                    utils_ignorelist.c utils_ignorelist.h
 onewire_la_CFLAGS = $(AM_CFLAGS)
-onewire_la_CPPFLAGS = $(BUILD_WITH_LIBOWCAPI_CPPFLAGS)
+onewire_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBOWCAPI_CPPFLAGS)
 onewire_la_LIBADD = $(BUILD_WITH_LIBOWCAPI_LIBS)
-onewire_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" onewire.la
-collectd_DEPENDENCIES += onewire.la
+onewire_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+endif
+
+if BUILD_PLUGIN_OPENLDAP
+pkglib_LTLIBRARIES += openldap.la
+openldap_la_SOURCES = openldap.c
+openldap_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_LIBLDAP_LDFLAGS)
+openldap_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBLDAP_CPPFLAGS)
+openldap_la_LIBADD = -lldap
 endif
 
 if BUILD_PLUGIN_OPENVPN
 pkglib_LTLIBRARIES += openvpn.la
 openvpn_la_SOURCES = openvpn.c
 openvpn_la_CFLAGS = $(AM_CFLAGS)
-openvpn_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" openvpn.la
-collectd_DEPENDENCIES += openvpn.la
+openvpn_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_ORACLE
@@ -896,11 +778,9 @@ pkglib_LTLIBRARIES += oracle.la
 oracle_la_SOURCES = oracle.c \
        utils_db_query.c utils_db_query.h
 oracle_la_CFLAGS = $(AM_CFLAGS)
-oracle_la_CPPFLAGS = $(BUILD_WITH_ORACLE_CFLAGS)
+oracle_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_ORACLE_CFLAGS)
 oracle_la_LIBADD = $(BUILD_WITH_ORACLE_LIBS)
-oracle_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" oracle.la
-collectd_DEPENDENCIES += oracle.la
+oracle_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_PERL
@@ -917,39 +797,31 @@ perl_la_CFLAGS  = $(AM_CFLAGS) \
 if HAVE_BROKEN_PERL_LOAD_MODULE
 perl_la_CFLAGS += -Wno-nonnull
 endif
-perl_la_LDFLAGS = -module -avoid-version \
+perl_la_LDFLAGS = $(PLUGIN_LDFLAGS) \
                $(PERL_LDFLAGS)
 perl_la_LIBADD = $(PERL_LIBS)
-collectd_LDADD += "-dlopen" perl.la
-collectd_DEPENDENCIES += perl.la
 endif
 
 if BUILD_PLUGIN_PF
 pkglib_LTLIBRARIES += pf.la
 pf_la_SOURCES = pf.c
-pf_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" pf.la
-collectd_DEPENDENCIES += pf.la
+pf_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_PINBA
 pkglib_LTLIBRARIES += pinba.la
 pinba_la_SOURCES = pinba.c
 nodist_pinba_la_SOURCES = pinba.pb-c.c pinba.pb-c.h
-pinba_la_LDFLAGS = -module -avoid-version
+pinba_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 pinba_la_LIBADD = -lprotobuf-c
-collectd_LDADD += "-dlopen" pinba.la
-collectd_DEPENDENCIES += pinba.la
 endif
 
 if BUILD_PLUGIN_PING
 pkglib_LTLIBRARIES += ping.la
 ping_la_SOURCES = ping.c
 ping_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBOPING_CPPFLAGS)
-ping_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_LIBOPING_LDFLAGS)
+ping_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBOPING_LDFLAGS)
 ping_la_LIBADD = -loping -lm
-collectd_LDADD += "-dlopen" ping.la
-collectd_DEPENDENCIES += ping.la
 endif
 
 if BUILD_PLUGIN_POSTGRESQL
@@ -957,19 +829,15 @@ pkglib_LTLIBRARIES += postgresql.la
 postgresql_la_SOURCES = postgresql.c \
                 utils_db_query.c utils_db_query.h
 postgresql_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBPQ_CPPFLAGS)
-postgresql_la_LDFLAGS = -module -avoid-version \
+postgresql_la_LDFLAGS = $(PLUGIN_LDFLAGS) \
                $(BUILD_WITH_LIBPQ_LDFLAGS)
 postgresql_la_LIBADD = -lpq
-collectd_LDADD += "-dlopen" postgresql.la
-collectd_DEPENDENCIES += postgresql.la
 endif
 
 if BUILD_PLUGIN_POWERDNS
 pkglib_LTLIBRARIES += powerdns.la
 powerdns_la_SOURCES = powerdns.c
-powerdns_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" powerdns.la
-collectd_DEPENDENCIES += powerdns.la
+powerdns_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_PYTHON
@@ -980,19 +848,15 @@ python_la_CFLAGS = $(AM_CFLAGS)
 if COMPILER_IS_GCC
 python_la_CFLAGS += -fno-strict-aliasing -Wno-strict-aliasing
 endif
-python_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_PYTHON_LDFLAGS)
+python_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_PYTHON_LDFLAGS)
 python_la_LIBADD = $(BUILD_WITH_PYTHON_LIBS)
-collectd_LDADD += "-dlopen" python.la
-collectd_DEPENDENCIES += python.la
 endif
 
 if BUILD_PLUGIN_PROCESSES
 pkglib_LTLIBRARIES += processes.la
 processes_la_SOURCES = processes.c
-processes_la_LDFLAGS = -module -avoid-version
+processes_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 processes_la_LIBADD =
-collectd_LDADD += "-dlopen" processes.la
-collectd_DEPENDENCIES += processes.la
 if BUILD_WITH_LIBKVM_GETPROCS
 processes_la_LIBADD += -lkvm
 endif
@@ -1000,84 +864,81 @@ endif
 
 if BUILD_PLUGIN_PROTOCOLS
 pkglib_LTLIBRARIES += protocols.la
-protocols_la_SOURCES = protocols.c
-protocols_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" protocols.la
-collectd_DEPENDENCIES += protocols.la
+protocols_la_SOURCES = protocols.c \
+                      utils_ignorelist.c utils_ignorelist.h
+protocols_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_REDIS
 pkglib_LTLIBRARIES += redis.la
 redis_la_SOURCES = redis.c
-redis_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_LIBCREDIS_LDFLAGS)
-redis_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBCREDIS_CPPFLAGS)
-redis_la_LIBADD = -lcredis
-collectd_LDADD += "-dlopen" redis.la
-collectd_DEPENDENCIES += redis.la
+redis_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBHIREDIS_LDFLAGS)
+redis_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBHIREDIS_CPPFLAGS)
+redis_la_LIBADD = -lhiredis
 endif
 
 if BUILD_PLUGIN_ROUTEROS
 pkglib_LTLIBRARIES += routeros.la
 routeros_la_SOURCES = routeros.c
-routeros_la_CPPFLAGS = $(BUILD_WITH_LIBROUTEROS_CPPFLAGS)
-routeros_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_LIBROUTEROS_LDFLAGS)
+routeros_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBROUTEROS_CPPFLAGS)
+routeros_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBROUTEROS_LDFLAGS)
 routeros_la_LIBADD = -lrouteros
-collectd_LDADD += "-dlopen" routeros.la
-collectd_DEPENDENCIES += routeros.la
 endif
 
 if BUILD_PLUGIN_RRDCACHED
 pkglib_LTLIBRARIES += rrdcached.la
 rrdcached_la_SOURCES = rrdcached.c utils_rrdcreate.c utils_rrdcreate.h
-rrdcached_la_LDFLAGS = -module -avoid-version
+rrdcached_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 rrdcached_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBRRD_CFLAGS)
 rrdcached_la_LIBADD = $(BUILD_WITH_LIBRRD_LDFLAGS)
-collectd_LDADD += "-dlopen" rrdcached.la
-collectd_DEPENDENCIES += rrdcached.la
 endif
 
 if BUILD_PLUGIN_RRDTOOL
 pkglib_LTLIBRARIES += rrdtool.la
 rrdtool_la_SOURCES = rrdtool.c utils_rrdcreate.c utils_rrdcreate.h
-rrdtool_la_LDFLAGS = -module -avoid-version
+rrdtool_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 rrdtool_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBRRD_CFLAGS)
 rrdtool_la_LIBADD = $(BUILD_WITH_LIBRRD_LDFLAGS)
-collectd_LDADD += "-dlopen" rrdtool.la
-collectd_DEPENDENCIES += rrdtool.la
 endif
 
 if BUILD_PLUGIN_SENSORS
 pkglib_LTLIBRARIES += sensors.la
-sensors_la_SOURCES = sensors.c
+sensors_la_SOURCES = sensors.c \
+                    utils_ignorelist.c utils_ignorelist.h
 sensors_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBSENSORS_CFLAGS)
-sensors_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_LIBSENSORS_LDFLAGS)
+sensors_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBSENSORS_LDFLAGS)
 sensors_la_LIBADD = -lsensors
-collectd_LDADD += "-dlopen" sensors.la
-collectd_DEPENDENCIES += sensors.la
 endif
 
 if BUILD_PLUGIN_SERIAL
 pkglib_LTLIBRARIES += serial.la
 serial_la_SOURCES = serial.c
-serial_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" serial.la
-collectd_DEPENDENCIES += serial.la
+serial_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_SIGROK
 pkglib_LTLIBRARIES += sigrok.la
 sigrok_la_SOURCES = sigrok.c
 sigrok_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBSIGROK_CFLAGS)
-sigrok_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_LIBSIGROK_LDFLAGS)
+sigrok_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBSIGROK_LDFLAGS)
 sigrok_la_LIBADD = -lsigrok
-collectd_LDADD += "-dlopen" sigrok.la
-collectd_DEPENDENCIES += sigrok.la
+endif
+
+if BUILD_PLUGIN_SMART
+if BUILD_WITH_LIBUDEV
+pkglib_LTLIBRARIES += smart.la
+smart_la_SOURCES = smart.c \
+                  utils_ignorelist.c utils_ignorelist.h
+smart_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBATASMART_CPPFLAGS)
+smart_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBATASMART_LDFLAGS)
+smart_la_LIBADD = $(BUILD_WITH_LIBATASMART_LIBS) -ludev
+endif
 endif
 
 if BUILD_PLUGIN_SNMP
 pkglib_LTLIBRARIES += snmp.la
 snmp_la_SOURCES = snmp.c
-snmp_la_LDFLAGS = -module -avoid-version
+snmp_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 snmp_la_CFLAGS = $(AM_CFLAGS)
 snmp_la_LIBADD =
 if BUILD_WITH_LIBNETSNMP
@@ -1087,28 +948,22 @@ endif
 if BUILD_WITH_LIBPTHREAD
 snmp_la_LIBADD += -lpthread
 endif
-collectd_LDADD += "-dlopen" snmp.la
-collectd_DEPENDENCIES += snmp.la
 endif
 
 if BUILD_PLUGIN_STATSD
 pkglib_LTLIBRARIES += statsd.la
 statsd_la_SOURCES = statsd.c \
                     utils_latency.h utils_latency.c
-statsd_la_LDFLAGS = -module -avoid-version
+statsd_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 statsd_la_LIBADD = -lpthread -lm
-collectd_LDADD += "-dlopen" statsd.la
-collectd_DEPENDENCIES += statsd.la
 endif
 
 if BUILD_PLUGIN_SWAP
 pkglib_LTLIBRARIES += swap.la
 swap_la_SOURCES = swap.c
 swap_la_CFLAGS = $(AM_CFLAGS)
-swap_la_LDFLAGS = -module -avoid-version
+swap_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 swap_la_LIBADD =
-collectd_LDADD += "-dlopen" swap.la
-collectd_DEPENDENCIES += swap.la
 if BUILD_WITH_LIBKSTAT
 swap_la_LIBADD += -lkstat
 endif
@@ -1131,91 +986,69 @@ endif
 if BUILD_PLUGIN_SYSLOG
 pkglib_LTLIBRARIES += syslog.la
 syslog_la_SOURCES = syslog.c
-syslog_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" syslog.la
-collectd_DEPENDENCIES += syslog.la
+syslog_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_TABLE
 pkglib_LTLIBRARIES += table.la
 table_la_SOURCES = table.c
-table_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" table.la
-collectd_DEPENDENCIES += table.la
+table_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_TAIL
 pkglib_LTLIBRARIES += tail.la
 tail_la_SOURCES = tail.c
-tail_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" tail.la
-collectd_DEPENDENCIES += tail.la
+tail_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_TAIL_CSV
 pkglib_LTLIBRARIES += tail_csv.la
 tail_csv_la_SOURCES = tail_csv.c
-tail_csv_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" tail_csv.la
-collectd_DEPENDENCIES += tail_csv.la
+tail_csv_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_TAPE
 pkglib_LTLIBRARIES += tape.la
 tape_la_SOURCES = tape.c
-tape_la_LDFLAGS = -module -avoid-version
+tape_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 tape_la_LIBADD = -lkstat -ldevinfo
-collectd_LDADD += "-dlopen" tape.la
-collectd_DEPENDENCIES += tape.la
 endif
 
 if BUILD_PLUGIN_TARGET_NOTIFICATION
 pkglib_LTLIBRARIES += target_notification.la
 target_notification_la_SOURCES = target_notification.c
-target_notification_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" target_notification.la
-collectd_DEPENDENCIES += target_notification.la
+target_notification_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_TARGET_REPLACE
 pkglib_LTLIBRARIES += target_replace.la
 target_replace_la_SOURCES = target_replace.c
-target_replace_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" target_replace.la
-collectd_DEPENDENCIES += target_replace.la
+target_replace_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_TARGET_SCALE
 pkglib_LTLIBRARIES += target_scale.la
 target_scale_la_SOURCES = target_scale.c
-target_scale_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" target_scale.la
-collectd_DEPENDENCIES += target_scale.la
+target_scale_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_TARGET_SET
 pkglib_LTLIBRARIES += target_set.la
 target_set_la_SOURCES = target_set.c
-target_set_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" target_set.la
-collectd_DEPENDENCIES += target_set.la
+target_set_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_TARGET_V5UPGRADE
 pkglib_LTLIBRARIES += target_v5upgrade.la
 target_v5upgrade_la_SOURCES = target_v5upgrade.c
-target_v5upgrade_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" target_v5upgrade.la
-collectd_DEPENDENCIES += target_v5upgrade.la
+target_v5upgrade_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_TCPCONNS
 pkglib_LTLIBRARIES += tcpconns.la
 tcpconns_la_SOURCES = tcpconns.c
-tcpconns_la_LDFLAGS = -module -avoid-version
+tcpconns_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 tcpconns_la_LIBADD =
-collectd_LDADD += "-dlopen" tcpconns.la
-collectd_DEPENDENCIES += tcpconns.la
 if BUILD_WITH_LIBKVM_NLIST
 tcpconns_la_LIBADD += -lkvm
 endif
@@ -1224,46 +1057,43 @@ endif
 if BUILD_PLUGIN_TEAMSPEAK2
 pkglib_LTLIBRARIES += teamspeak2.la
 teamspeak2_la_SOURCES = teamspeak2.c
-teamspeak2_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" teamspeak2.la
-collectd_DEPENDENCIES += teamspeak2.la
+teamspeak2_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_TED
 pkglib_LTLIBRARIES += ted.la
 ted_la_SOURCES = ted.c
-ted_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" ted.la
-collectd_DEPENDENCIES += ted.la
+ted_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_THERMAL
 pkglib_LTLIBRARIES += thermal.la
-thermal_la_SOURCES = thermal.c
-thermal_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" thermal.la
-collectd_DEPENDENCIES += thermal.la
+thermal_la_SOURCES = thermal.c \
+                    utils_ignorelist.c utils_ignorelist.h
+thermal_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_THRESHOLD
 pkglib_LTLIBRARIES += threshold.la
 threshold_la_SOURCES = threshold.c
-threshold_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" threshold.la
-collectd_DEPENDENCIES += threshold.la
+threshold_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_TOKYOTYRANT
 pkglib_LTLIBRARIES += tokyotyrant.la
 tokyotyrant_la_SOURCES = tokyotyrant.c
 tokyotyrant_la_CPPFLAGS  = $(AM_CPPFLAGS) $(BUILD_WITH_LIBTOKYOTYRANT_CPPFLAGS)
-tokyotyrant_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_LIBTOKYOTYRANT_LDFLAGS)
+tokyotyrant_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBTOKYOTYRANT_LDFLAGS)
 tokyotyrant_la_LIBADD  = $(BUILD_WITH_LIBTOKYOTYRANT_LIBS)
 if BUILD_WITH_LIBSOCKET
 tokyotyrant_la_LIBADD += -lsocket
 endif
-collectd_LDADD += "-dlopen" tokyotyrant.la
-collectd_DEPENDENCIES += tokyotyrant.la
+endif
+
+if BUILD_PLUGIN_TURBOSTAT
+pkglib_LTLIBRARIES += turbostat.la
+turbostat_la_SOURCES = turbostat.c
+turbostat_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_UNIXSOCK
@@ -1271,20 +1101,20 @@ 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
-unixsock_la_LDFLAGS = -module -avoid-version
+                     utils_cmd_putnotif.h utils_cmd_putnotif.c \
+                     utils_parse_option.h utils_parse_option.c
+unixsock_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 unixsock_la_LIBADD = -lpthread
-collectd_LDADD += "-dlopen" unixsock.la
-collectd_DEPENDENCIES += unixsock.la
 endif
 
 if BUILD_PLUGIN_UPTIME
 pkglib_LTLIBRARIES += uptime.la
 uptime_la_SOURCES = uptime.c
 uptime_la_CFLAGS = $(AM_CFLAGS)
-uptime_la_LDFLAGS = -module -avoid-version
+uptime_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 uptime_la_LIBADD =
 if BUILD_WITH_LIBKSTAT
 uptime_la_LIBADD += -lkstat
@@ -1292,22 +1122,18 @@ endif
 if BUILD_WITH_PERFSTAT
 uptime_la_LIBADD += -lperfstat
 endif
-collectd_LDADD += "-dlopen" uptime.la
-collectd_DEPENDENCIES += uptime.la
 endif
 
 if BUILD_PLUGIN_USERS
 pkglib_LTLIBRARIES += users.la
 users_la_SOURCES = users.c
 users_la_CFLAGS = $(AM_CFLAGS)
-users_la_LDFLAGS = -module -avoid-version
+users_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 users_la_LIBADD =
 if BUILD_WITH_LIBSTATGRAB
 users_la_CFLAGS += $(BUILD_WITH_LIBSTATGRAB_CFLAGS)
 users_la_LIBADD += $(BUILD_WITH_LIBSTATGRAB_LDFLAGS)
 endif
-collectd_LDADD += "-dlopen" users.la
-collectd_DEPENDENCIES += users.la
 endif
 
 if BUILD_PLUGIN_UUID
@@ -1315,53 +1141,43 @@ pkglib_LTLIBRARIES += uuid.la
 uuid_la_SOURCES = uuid.c
 uuid_la_CFLAGS  = $(AM_CFLAGS) $(BUILD_WITH_LIBHAL_CFLAGS)
 uuid_la_LIBADD  = $(BUILD_WITH_LIBHAL_LIBS)
-uuid_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" uuid.la
-collectd_DEPENDENCIES += uuid.la
-endif
-
-if BUILD_PLUGIN_MIC
-pkglib_LTLIBRARIES += mic.la
-mic_la_SOURCES = mic.c
-mic_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_MIC_LIBPATH)
-mic_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_MIC_CPPFLAGS)
-mic_la_LIBADD = $(BUILD_WITH_MIC_LDADD)
-collectd_LDADD += "-dlopen" mic.la
-collectd_DEPENDENCIES += mic.la
+uuid_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_VARNISH
 pkglib_LTLIBRARIES += varnish.la
 varnish_la_SOURCES = varnish.c
-varnish_la_LDFLAGS = -module -avoid-version
+varnish_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 varnish_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBVARNISH_CFLAGS)
 varnish_la_LIBADD = $(BUILD_WITH_LIBVARNISH_LIBS)
-collectd_LDADD += "-dlopen" varnish.la
-collectd_DEPENDENCIES += varnish.la
+endif
+
+if BUILD_PLUGIN_VIRT
+pkglib_LTLIBRARIES += virt.la
+virt_la_SOURCES = virt.c \
+                 utils_ignorelist.c utils_ignorelist.h
+virt_la_CFLAGS = $(AM_CFLAGS) \
+               $(BUILD_WITH_LIBVIRT_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
+virt_la_LIBADD = $(BUILD_WITH_LIBVIRT_LIBS) $(BUILD_WITH_LIBXML2_LIBS)
+virt_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_VMEM
 pkglib_LTLIBRARIES += vmem.la
 vmem_la_SOURCES = vmem.c
-vmem_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" vmem.la
-collectd_DEPENDENCIES += vmem.la
+vmem_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_VSERVER
 pkglib_LTLIBRARIES += vserver.la
 vserver_la_SOURCES = vserver.c
-vserver_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" vserver.la
-collectd_DEPENDENCIES += vserver.la
+vserver_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_WIRELESS
 pkglib_LTLIBRARIES += wireless.la
 wireless_la_SOURCES = wireless.c
-wireless_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" wireless.la
-collectd_DEPENDENCIES += wireless.la
+wireless_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_WRITE_GRAPHITE
@@ -1369,78 +1185,106 @@ pkglib_LTLIBRARIES += write_graphite.la
 write_graphite_la_SOURCES = write_graphite.c \
                         utils_format_graphite.c utils_format_graphite.h \
                         utils_format_json.c utils_format_json.h
-write_graphite_la_LDFLAGS = -module -avoid-version
-collectd_LDADD += "-dlopen" write_graphite.la
-collectd_DEPENDENCIES += write_graphite.la
+write_graphite_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_WRITE_HTTP
 pkglib_LTLIBRARIES += write_http.la
 write_http_la_SOURCES = write_http.c \
                        utils_format_json.c utils_format_json.h
-write_http_la_LDFLAGS = -module -avoid-version
+write_http_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 write_http_la_CFLAGS = $(AM_CFLAGS)
 write_http_la_LIBADD =
-collectd_LDADD += "-dlopen" write_http.la
 if BUILD_WITH_LIBCURL
 write_http_la_CFLAGS += $(BUILD_WITH_LIBCURL_CFLAGS)
 write_http_la_LIBADD += $(BUILD_WITH_LIBCURL_LIBS)
 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_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBRDKAFKA_CPPFLAGS)
+write_kafka_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBRDKAFKA_LDFLAGS)
+write_kafka_la_LIBADD = $(BUILD_WITH_LIBRDKAFKA_LIBS)
+endif
+
+if BUILD_PLUGIN_WRITE_LOG
+pkglib_LTLIBRARIES += write_log.la
+write_log_la_SOURCES = write_log.c \
+                        utils_format_graphite.c utils_format_graphite.h
+write_log_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_WRITE_MONGODB
 pkglib_LTLIBRARIES += write_mongodb.la
 write_mongodb_la_SOURCES = write_mongodb.c
 write_mongodb_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBMONGOC_CPPFLAGS)
-write_mongodb_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_LIBMONGOC_LDFLAGS)
+write_mongodb_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBMONGOC_LDFLAGS)
 write_mongodb_la_LIBADD = -lmongoc
-collectd_LDADD += "-dlopen" write_mongodb.la
-collectd_DEPENDENCIES += write_mongodb.la
 endif
 
 if BUILD_PLUGIN_WRITE_REDIS
 pkglib_LTLIBRARIES += write_redis.la
 write_redis_la_SOURCES = write_redis.c
-write_redis_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_LIBCREDIS_LDFLAGS)
-write_redis_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBCREDIS_CPPFLAGS)
-write_redis_la_LIBADD = -lcredis
-collectd_LDADD += "-dlopen" write_redis.la
-collectd_DEPENDENCIES += write_redis.la
+write_redis_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBHIREDIS_LDFLAGS)
+write_redis_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBHIREDIS_CPPFLAGS)
+write_redis_la_LIBADD = -lhiredis
 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_LDFLAGS = $(PLUGIN_LDFLAGS)
 write_riemann_la_LIBADD = -lprotobuf-c
-collectd_LDADD += "-dlopen" write_riemann.la
-collectd_DEPENDENCIES += write_riemann.la
+endif
+
+if BUILD_PLUGIN_WRITE_SENSU
+pkglib_LTLIBRARIES += write_sensu.la
+write_sensu_la_SOURCES = write_sensu.c
+write_sensu_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+endif
+
+if BUILD_PLUGIN_WRITE_TSDB
+pkglib_LTLIBRARIES += write_tsdb.la
+write_tsdb_la_SOURCES = write_tsdb.c
+write_tsdb_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 if BUILD_PLUGIN_XMMS
 pkglib_LTLIBRARIES += xmms.la
 xmms_la_SOURCES = xmms.c
 xmms_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBXMMS_CFLAGS)
-xmms_la_LDFLAGS = -module -avoid-version
+xmms_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 xmms_la_LIBADD = $(BUILD_WITH_LIBXMMS_LIBS)
-collectd_LDADD += "-dlopen" xmms.la
-collectd_DEPENDENCIES += xmms.la
 endif
 
 if BUILD_PLUGIN_ZFS_ARC
 pkglib_LTLIBRARIES += zfs_arc.la
 zfs_arc_la_SOURCES = zfs_arc.c
 zfs_arc_la_CFLAGS = $(AM_CFLAGS)
-zfs_arc_la_LDFLAGS = -module -avoid-version
+zfs_arc_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 if BUILD_FREEBSD
 zfs_arc_la_LIBADD = -lm
 else
+if BUILD_LINUX
+# zfs_arc requires no library on linux
+else
+# solaris
 zfs_arc_la_LIBADD = -lkstat
 endif
-collectd_LDADD += "-dlopen" zfs_arc.la
-collectd_DEPENDENCIES += zfs_arc.la
+endif
+endif
+
+if BUILD_PLUGIN_ZOOKEEPER
+pkglib_LTLIBRARIES += zookeeper.la
+zookeeper_la_SOURCES = zookeeper.c
+zookeeper_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
 BUILT_SOURCES += $(dist_man_MANS)
@@ -1537,15 +1381,12 @@ 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 \
-                               utils_vl_lookup.h utils_vl_lookup.c \
-                               utils_avltree.c utils_avltree.h \
-                               common.h
+check_PROGRAMS = test_utils_mount test_utils_vl_lookup
 
-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
+test_utils_mount_SOURCES = utils_mount_test.c testing.h
+test_utils_mount_LDADD = libmount.la daemon/libplugin_mock.la
+
+test_utils_vl_lookup_SOURCES = utils_vl_lookup_test.c testing.h
+test_utils_vl_lookup_LDADD = liblookup.la daemon/libplugin_mock.la
+
+TESTS = test_utils_mount test_utils_vl_lookup
index bf0f80f58498867db94f5d4534e343aba3eec001..aba4f0122ca7c87ab4313da6cc3fd318872a9d88 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"
@@ -80,6 +80,9 @@ struct camqp_config_s
     char   *exchange;
     char   *routing_key;
 
+    /* Number of seconds to wait before connection is retried */
+    int     connection_retry_delay;
+
     /* publish only */
     uint8_t delivery_mode;
     _Bool   store_rates;
@@ -93,6 +96,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;
@@ -332,9 +337,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)
     {
@@ -407,6 +412,8 @@ static int camqp_setup_queue (camqp_config_t *conf) /* {{{ */
 
 static int camqp_connect (camqp_config_t *conf) /* {{{ */
 {
+    static time_t last_connect_time = 0;
+
     amqp_rpc_reply_t reply;
     int status;
 #ifdef HAVE_AMQP_TCP_SOCKET
@@ -418,6 +425,19 @@ static int camqp_connect (camqp_config_t *conf) /* {{{ */
     if (conf->connection != NULL)
         return (0);
 
+    time_t now = time(NULL);
+    if (now < (last_connect_time + conf->connection_retry_delay))
+    {
+        DEBUG("amqp plugin: skipping connection retry, "
+            "ConnectionRetryDelay: %d", conf->connection_retry_delay);
+        return(1);
+    }
+    else
+    {
+        DEBUG ("amqp plugin: retrying connection");
+        last_connect_time = now;
+    }
+
     conf->connection = amqp_new_connection ();
     if (conf->connection == NULL)
     {
@@ -791,7 +811,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))
@@ -924,6 +944,8 @@ static int camqp_config_connection (oconfig_item_t *ci, /* {{{ */
     conf->password = NULL;
     conf->exchange = NULL;
     conf->routing_key = NULL;
+    conf->connection_retry_delay = 0;
+
     /* publish only */
     conf->delivery_mode = CAMQP_DM_VOLATILE;
     conf->store_rates = 0;
@@ -935,6 +957,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);
@@ -974,6 +998,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)
@@ -1013,6 +1041,8 @@ static int camqp_config_connection (oconfig_item_t *ci, /* {{{ */
             conf->escape_char = tmp_buff[0];
             sfree (tmp_buff);
         }
+        else if (strcasecmp ("ConnectionRetryDelay", child->key) == 0)
+            status = cf_util_get_int (child, &conf->connection_retry_delay);
         else
             WARNING ("amqp plugin: Ignoring unknown "
                     "configuration option \"%s\".", child->key);
index 16f7acd310e6f098f1e3021a6f8ce5237fc429b0..8910675ad06a67e8f80a322ef75d991123a48b0c 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>
@@ -45,14 +45,16 @@ struct apache_s
        char *url;
        char *user;
        char *pass;
-       int   verify_peer;
-       int   verify_host;
+       _Bool verify_peer;
+       _Bool verify_host;
        char *cacert;
+       char *ssl_ciphers;
        char *server; /* user specific server type */
        char *apache_buffer;
        char apache_curl_error[CURL_ERROR_SIZE];
        size_t apache_buffer_size;
        size_t apache_buffer_fill;
+       int timeout;
        CURL *curl;
 }; /* apache_s */
 
@@ -72,6 +74,7 @@ static void apache_free (apache_t *st)
        sfree (st->user);
        sfree (st->pass);
        sfree (st->cacert);
+       sfree (st->ssl_ciphers);
        sfree (st->server);
        sfree (st->apache_buffer);
        if (st->curl) {
@@ -166,94 +169,23 @@ static size_t apache_header_callback (void *buf, size_t size, size_t nmemb,
  *   URL ...
  * </Plugin>
  */
-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 ("apache 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 ("apache 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 *ret_boolean, /* {{{ */
-                                   oconfig_item_t *ci)
-{
-       if ((ci->values_num != 1)
-                       || ((ci->values[0].type != OCONFIG_TYPE_BOOLEAN)
-                               && (ci->values[0].type != OCONFIG_TYPE_STRING)))
-       {
-               WARNING ("apache plugin: The `%s' config option "
-                               "needs exactly one boolean argument.", ci->key);
-               return (-1);
-       }
-
-       if (ci->values[0].type == OCONFIG_TYPE_BOOLEAN)
-       {
-               if (ci->values[0].value.boolean)
-                       *ret_boolean = 1;
-               else
-                       *ret_boolean = 0;
-       }
-       else /* if (ci->values[0].type != OCONFIG_TYPE_STRING) */
-       {
-               char *string = ci->values[0].value.string;
-               if (IS_TRUE (string))
-                       *ret_boolean = 1;
-               else if (IS_FALSE (string))
-                       *ret_boolean = 0;
-               else
-               {
-                       ERROR ("apache plugin: Cannot parse string "
-                                       "as boolean value: %s", string);
-                       return (-1);
-               }
-       }
-
-       return (0);
-} /* }}} int config_set_boolean */
-
 static int config_add (oconfig_item_t *ci)
 {
        apache_t *st;
        int i;
        int status;
 
-       if ((ci->values_num != 1)
-               || (ci->values[0].type != OCONFIG_TYPE_STRING))
-       {
-               WARNING ("apache plugin: The `%s' config option "
-                       "needs exactly one string argument.", ci->key);
-               return (-1);
-       }
-
-       st = (apache_t *) malloc (sizeof (*st));
+       st = malloc (sizeof (*st));
        if (st == NULL)
        {
                ERROR ("apache plugin: malloc failed.");
                return (-1);
        }
-
        memset (st, 0, sizeof (*st));
 
-       status = config_set_string (&st->name, ci);
+       st->timeout = -1;
+
+       status = cf_util_get_string (ci, &st->name);
        if (status != 0)
        {
                sfree (st);
@@ -266,21 +198,25 @@ static int config_add (oconfig_item_t *ci)
                oconfig_item_t *child = ci->children + i;
 
                if (strcasecmp ("URL", child->key) == 0)
-                       status = config_set_string (&st->url, child);
+                       status = cf_util_get_string (child, &st->url);
                else if (strcasecmp ("Host", child->key) == 0)
-                       status = config_set_string (&st->host, child);
+                       status = cf_util_get_string (child, &st->host);
                else if (strcasecmp ("User", child->key) == 0)
-                       status = config_set_string (&st->user, child);
+                       status = cf_util_get_string (child, &st->user);
                else if (strcasecmp ("Password", child->key) == 0)
-                       status = config_set_string (&st->pass, child);
+                       status = cf_util_get_string (child, &st->pass);
                else if (strcasecmp ("VerifyPeer", child->key) == 0)
-                       status = config_set_boolean (&st->verify_peer, child);
+                       status = cf_util_get_boolean (child, &st->verify_peer);
                else if (strcasecmp ("VerifyHost", child->key) == 0)
-                       status = config_set_boolean (&st->verify_host, child);
+                       status = cf_util_get_boolean (child, &st->verify_host);
                else if (strcasecmp ("CACert", child->key) == 0)
-                       status = config_set_string (&st->cacert, child);
+                       status = cf_util_get_string (child, &st->cacert);
+               else if (strcasecmp ("SSLCiphers", child->key) == 0)
+                       status = cf_util_get_string (child, &st->ssl_ciphers);
                else if (strcasecmp ("Server", child->key) == 0)
-                       status = config_set_string (&st->server, child);
+                       status = cf_util_get_string (child, &st->server);
+               else if (strcasecmp ("Timeout", child->key) == 0)
+                       status = cf_util_get_int (child, &st->timeout);
                else
                {
                        WARNING ("apache plugin: Option `%s' not allowed here.",
@@ -325,7 +261,7 @@ static int config_add (oconfig_item_t *ci)
 
        if (status != 0)
        {
-               apache_free(st);
+               apache_free (st);
                return (-1);
        }
 
@@ -357,8 +293,6 @@ static int config (oconfig_item_t *ci)
 /* initialize curl for each host */
 static int init_host (apache_t *st) /* {{{ */
 {
-       static char credentials[1024];
-
        assert (st->url != NULL);
        /* (Assured by `config_add') */
 
@@ -403,11 +337,17 @@ 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)
        {
+#ifdef HAVE_CURLOPT_USERNAME
+               curl_easy_setopt (st->curl, CURLOPT_USERNAME, st->user);
+               curl_easy_setopt (st->curl, CURLOPT_PASSWORD,
+                               (st->pass == NULL) ? "" : st->pass);
+#else
+               static char credentials[1024];
                int status;
 
                status = ssnprintf (credentials, sizeof (credentials), "%s:%s",
@@ -423,34 +363,29 @@ static int init_host (apache_t *st) /* {{{ */
                }
 
                curl_easy_setopt (st->curl, CURLOPT_USERPWD, credentials);
+#endif
        }
 
        curl_easy_setopt (st->curl, CURLOPT_URL, st->url);
        curl_easy_setopt (st->curl, CURLOPT_FOLLOWLOCATION, 1L);
        curl_easy_setopt (st->curl, CURLOPT_MAXREDIRS, 50L);
 
-       if (st->verify_peer != 0)
-       {
-               curl_easy_setopt (st->curl, CURLOPT_SSL_VERIFYPEER, 1L);
-       }
-       else
-       {
-               curl_easy_setopt (st->curl, CURLOPT_SSL_VERIFYPEER, 0L);
-       }
-
-       if (st->verify_host != 0)
-       {
-               curl_easy_setopt (st->curl, CURLOPT_SSL_VERIFYHOST, 2L);
-       }
-       else
-       {
-               curl_easy_setopt (st->curl, CURLOPT_SSL_VERIFYHOST, 0L);
-       }
-
+       curl_easy_setopt (st->curl, CURLOPT_SSL_VERIFYPEER,
+                       (long) st->verify_peer);
+       curl_easy_setopt (st->curl, CURLOPT_SSL_VERIFYHOST,
+                       st->verify_host ? 2L : 0L);
        if (st->cacert != NULL)
-       {
                curl_easy_setopt (st->curl, CURLOPT_CAINFO, st->cacert);
-       }
+       if (st->ssl_ciphers != NULL)
+               curl_easy_setopt (st->curl, CURLOPT_SSL_CIPHER_LIST,st->ssl_ciphers);
+
+#ifdef HAVE_CURLOPT_TIMEOUT_MS
+       if (st->timeout >= 0)
+               curl_easy_setopt (st->curl, CURLOPT_TIMEOUT_MS, (long) st->timeout);
+       else
+               curl_easy_setopt (st->curl, CURLOPT_TIMEOUT_MS,
+                               CDTIME_T_TO_MS(plugin_get_interval()));
+#endif
 
        return (0);
 } /* }}} int init_host */
index ee15b14f66cf8d1899f767aac09915ee9e895878..be7673c5df9e1854ed1c32e0a2b55f89561dac3c 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 bdba0ff85287745c960c1e5399d813aad2c116e2..19d5a49f31731ead712a4d78409bdd87b492007e 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 94a39386b0a45f74cba03ddd237588c3ba8edfb7..11175af5e6104afa7b39291fd77fd45441a0cb64 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"
@@ -97,6 +102,7 @@ static char *pass        = NULL;
 static char *verify_peer = NULL;
 static char *verify_host = NULL;
 static char *cacert      = NULL;
+static char *timeout     = NULL;
 
 static CURL *curl = NULL;
 
@@ -112,7 +118,8 @@ static const char *config_keys[] =
   "Password",
   "VerifyPeer",
   "VerifyHost",
-  "CACert"
+  "CACert",
+  "Timeout",
 };
 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
 
@@ -513,14 +520,14 @@ static int ascent_config (const char *key, const char *value) /* {{{ */
     return (config_set (&verify_host, value));
   else if (strcasecmp (key, "CACert") == 0)
     return (config_set (&cacert, value));
+  else if (strcasecmp (key, "Timeout") == 0)
+    return (config_set (&timeout, value));
   else
     return (-1);
 } /* }}} int ascent_config */
 
 static int ascent_init (void) /* {{{ */
 {
-  static char credentials[1024];
-
   if (url == NULL)
   {
     WARNING ("ascent plugin: ascent_init: No URL configured, "
@@ -541,11 +548,16 @@ 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)
   {
+#ifdef HAVE_CURLOPT_USERNAME
+    curl_easy_setopt (curl, CURLOPT_USERNAME, user);
+    curl_easy_setopt (curl, CURLOPT_PASSWORD, (pass == NULL) ? "" : pass);
+#else
+    static char credentials[1024];
     int status;
 
     status = ssnprintf (credentials, sizeof (credentials), "%s:%s",
@@ -558,6 +570,7 @@ static int ascent_init (void) /* {{{ */
     }
 
     curl_easy_setopt (curl, CURLOPT_USERPWD, credentials);
+#endif
   }
 
   curl_easy_setopt (curl, CURLOPT_URL, url);
@@ -577,6 +590,14 @@ static int ascent_init (void) /* {{{ */
   if (cacert != NULL)
     curl_easy_setopt (curl, CURLOPT_CAINFO, cacert);
 
+#ifdef HAVE_CURLOPT_TIMEOUT_MS
+  if (timeout != NULL)
+    curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, atol(timeout));
+  else
+    curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS,
+       CDTIME_T_TO_MS(plugin_get_interval()));
+#endif
+
   return (0);
 } /* }}} int ascent_init */
 
diff --git a/src/barometer.c b/src/barometer.c
new file mode 100644 (file)
index 0000000..a6d9835
--- /dev/null
@@ -0,0 +1,1884 @@
+/**
+ * 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
+
+
+/* ------------ BMP085 defines ------------ */
+/* I2C address of the BMP085 sensor */
+#define BMP085_I2C_ADDRESS          0x77
+
+/* register addresses */            
+#define BMP085_ADDR_ID_REG          0xD0
+#define BMP085_ADDR_VERSION         0xD1
+
+#define BMP085_ADDR_CONV            0xF6
+
+#define BMP085_ADDR_CTRL_REG        0xF4
+#define BMP085_ADDR_COEFFS          0xAA
+
+/* register sizes */                
+#define BMP085_NUM_COEFFS           22
+
+/* commands, values */
+#define BMP085_CHIP_ID              0x55
+
+#define BMP085_CMD_CONVERT_TEMP     0x2E
+
+#define BMP085_CMD_CONVERT_PRESS_0  0x34
+#define BMP085_CMD_CONVERT_PRESS_1  0x74
+#define BMP085_CMD_CONVERT_PRESS_2  0xB4
+#define BMP085_CMD_CONVERT_PRESS_3  0xF4
+
+/* in us */
+#define BMP085_TIME_CNV_TEMP        4500
+
+#define BMP085_TIME_CNV_PRESS_0     4500
+#define BMP085_TIME_CNV_PRESS_1     7500
+#define BMP085_TIME_CNV_PRESS_2    13500
+#define BMP085_TIME_CNV_PRESS_3    25500
+
+
+/* ------------ 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
+
+
+/* ------------------------------------------ */
+
+/** Supported sensor types */
+enum Sensor_type {
+    Sensor_none = 0,
+    Sensor_MPL115,
+    Sensor_MPL3115,
+    Sensor_BMP085
+};
+
+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 enum Sensor_type sensor_type = Sensor_none; /**< detected/used sensor type */
+
+static __s32  mpl3115_oversample  = 0;    /**< MPL3115 CTRL1 oversample setting */
+
+// BMP085 configuration
+static unsigned      bmp085_oversampling; /**< BMP085 oversampling (0-3) */
+static unsigned long bmp085_timeCnvPress; /**< BMP085 conversion time for pressure in us */
+static __u8          bmp085_cmdCnvPress;  /**< BMP085 pressure conversion command */
+
+
+/* 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;
+
+/* BMP085 conversion coefficients */
+static short bmp085_AC1;
+static short bmp085_AC2;
+static short bmp085_AC3;
+static unsigned short bmp085_AC4;
+static unsigned short bmp085_AC5;
+static unsigned short bmp085_AC6;
+static short bmp085_B1;
+static short bmp085_B2;
+static short bmp085_MB;
+static short bmp085_MC;
+static short bmp085_MD;
+
+
+
+/* ------------------------ 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)
+{
+    avg->ring_buffer = calloc ((size_t) size, sizeof (*avg->ring_buffer));
+    if (avg->ring_buffer == NULL)
+    {
+        ERROR ("barometer: averaging_create - ring buffer allocation of size %d failed",
+               size);
+        return -1;
+    }
+
+    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 ------------------------ */
+
+/** 
+ * Detect presence of a MPL115 pressure sensor.
+ *
+ * Unfortunately there seems to be no ID register so we just try to read first
+ * conversion coefficient from device at MPL115 address and hope it is really
+ * MPL115. We should use this check as the last resort (which would be the typical
+ * case anyway since MPL115 is the least accurate sensor).
+ * As a sideeffect will leave set I2C slave address.
+ * 
+ * @return 1 if MPL115, 0 otherwise
+ */
+static int MPL115_detect(void)
+{
+    __s32 res;
+    char errbuf[1024];
+
+    if (ioctl(i2c_bus_fd, I2C_SLAVE_FORCE, MPL115_I2C_ADDRESS) < 0)
+    {
+        ERROR("barometer: MPL115_detect problem setting i2c slave address to 0x%02X: %s",
+              MPL115_I2C_ADDRESS,
+              sstrerror (errno, errbuf, sizeof (errbuf)));
+        return 0 ;
+    }
+
+    res = i2c_smbus_read_byte_data(i2c_bus_fd, MPL115_ADDR_COEFFS);
+    if(res >= 0)
+    {
+        DEBUG ("barometer: MPL115_detect - positive detection");
+        return 1;
+    }
+
+    DEBUG ("barometer: MPL115_detect - negative detection");
+    return 0;
+}
+
+/**
+ * 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] = { 0 };
+    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,
+                                        STATIC_ARRAY_SIZE (mpl115_coeffs),
+                                        mpl115_coeffs);
+    if (res < 0)
+    {
+        ERROR ("barometer: MPL115_read_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: MPL115_read_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: MPL115_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] = { 0 };
+    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,
+                                            STATIC_ARRAY_SIZE (mpl115_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"
+ *
+ * As a sideeffect will leave set I2C slave address.
+ * 
+ * @return 1 if MPL3115, 0 otherwise
+ */
+static int MPL3115_detect(void)
+{
+    __s32 res;
+    char errbuf[1024];
+
+    if (ioctl(i2c_bus_fd, I2C_SLAVE_FORCE, MPL3115_I2C_ADDRESS) < 0)
+    {
+        ERROR("barometer: MPL3115_detect problem setting i2c slave address to 0x%02X: %s",
+              MPL3115_I2C_ADDRESS,
+              sstrerror (errno, errbuf, sizeof (errbuf)));
+        return 0 ;
+    }
+
+    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;
+        mpl3115_oversample = MPL3115_CTRL_REG1_OST_128;
+    }
+    else if(config_oversample > 48)
+    {
+        new_val = 64;
+        mpl3115_oversample = MPL3115_CTRL_REG1_OST_64;
+    }
+    else if(config_oversample > 24)
+    {
+        new_val = 32;
+        mpl3115_oversample = MPL3115_CTRL_REG1_OST_32;
+    }
+    else if(config_oversample > 12)
+    {
+        new_val = 16;
+        mpl3115_oversample = MPL3115_CTRL_REG1_OST_16;
+    }
+    else if(config_oversample > 6)
+    {
+        new_val = 8;
+        mpl3115_oversample = MPL3115_CTRL_REG1_OST_8;
+    }
+    else if(config_oversample > 3)
+    {
+        new_val = 4;
+        mpl3115_oversample = MPL3115_CTRL_REG1_OST_4;
+    }
+    else if(config_oversample > 1)
+    {
+        new_val = 2;
+        mpl3115_oversample = MPL3115_CTRL_REG1_OST_2;
+    }
+    else
+    {
+        new_val = 1;
+        mpl3115_oversample = MPL3115_CTRL_REG1_OST_1;
+    }
+
+    DEBUG("barometer: MPL3115_adjust_oversampling - correcting oversampling 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, 
+                                    mpl3115_oversample);
+    if (res < 0)
+    {
+        ERROR ("barometer: MPL3115_init_sensor - problem configuring CTRL_REG1: %s",
+               sstrerror (errno, errbuf, sizeof (errbuf)));
+        return -1;
+    }
+
+    return 0;
+}
+
+/* ------------------------ BMP085 access ------------------------ */
+
+/** 
+ * Detect presence of a BMP085 pressure sensor by checking its ID register
+ *
+ * As a sideeffect will leave set I2C slave address.
+ * 
+ * @return 1 if BMP085, 0 otherwise
+ */
+static int BMP085_detect(void)
+{
+    __s32 res;
+    char errbuf[1024];
+
+    if (ioctl(i2c_bus_fd, I2C_SLAVE_FORCE, BMP085_I2C_ADDRESS) < 0)
+    {
+        ERROR("barometer: BMP085_detect - problem setting i2c slave address to 0x%02X: %s",
+              BMP085_I2C_ADDRESS,
+              sstrerror (errno, errbuf, sizeof (errbuf)));
+        return 0 ;
+    }
+
+    res = i2c_smbus_read_byte_data(i2c_bus_fd, BMP085_ADDR_ID_REG);
+    if(res == BMP085_CHIP_ID)
+    {
+        DEBUG ("barometer: BMP085_detect - positive detection");
+
+        /* get version */
+        res = i2c_smbus_read_byte_data(i2c_bus_fd, BMP085_ADDR_VERSION );
+        if (res < 0)
+        {
+            ERROR("barometer: BMP085_detect - problem checking chip version: %s",
+                  sstrerror (errno, errbuf, sizeof (errbuf)));
+            return 0 ;
+        }
+        DEBUG ("barometer: BMP085_detect - chip version ML:0x%02X AL:0x%02X",
+               res & 0x0f,
+               (res & 0xf0) >> 4);
+        return 1;
+    }
+
+    DEBUG ("barometer: BMP085_detect - negative detection");
+    return 0;
+}
+
+
+/** 
+ * Adjusts oversampling settings to values supported by BMP085
+ *
+ * BMP085 supports only 1,2,4 or 8 samples. 
+ */
+static void BMP085_adjust_oversampling(void)
+{
+    int new_val = 0;
+
+    if( config_oversample > 6 ) /* 8 */
+    {
+        new_val = 8;
+        bmp085_oversampling = 3;
+        bmp085_cmdCnvPress = BMP085_CMD_CONVERT_PRESS_3;
+        bmp085_timeCnvPress = BMP085_TIME_CNV_PRESS_3;
+    }
+    else if( config_oversample > 3 ) /* 4 */
+    {
+        new_val = 4;
+        bmp085_oversampling = 2;
+        bmp085_cmdCnvPress = BMP085_CMD_CONVERT_PRESS_2;
+        bmp085_timeCnvPress = BMP085_TIME_CNV_PRESS_2;
+    }
+    else if( config_oversample > 1 ) /* 2 */
+    {
+        new_val = 2;
+        bmp085_oversampling = 1;
+        bmp085_cmdCnvPress = BMP085_CMD_CONVERT_PRESS_1;
+        bmp085_timeCnvPress = BMP085_TIME_CNV_PRESS_1;
+    }
+    else /* 1 */
+    {
+        new_val = 1;
+        bmp085_oversampling = 0;
+        bmp085_cmdCnvPress = BMP085_CMD_CONVERT_PRESS_0;
+        bmp085_timeCnvPress = BMP085_TIME_CNV_PRESS_0;
+    }
+
+    DEBUG("barometer: BMP085_adjust_oversampling - correcting oversampling from %d to %d",
+          config_oversample, 
+          new_val);
+    config_oversample = new_val;
+}
+
+
+/** 
+ * Read the BMP085 sensor conversion coefficients.
+ *
+ * These are (device specific) constants so we can read them just once.
+ *
+ * @return Zero when successful
+ */
+static int BMP085_read_coeffs(void)
+{
+    __s32 res;
+    __u8 coeffs[BMP085_NUM_COEFFS]; 
+    char errbuf[1024];
+
+    res = i2c_smbus_read_i2c_block_data(i2c_bus_fd, 
+                                        BMP085_ADDR_COEFFS,
+                                        BMP085_NUM_COEFFS, 
+                                        coeffs);
+    if (res < 0)
+    {
+        ERROR ("barometer: BMP085_read_coeffs - problem reading data: %s",
+               sstrerror (errno, errbuf, sizeof (errbuf)));
+        return -1;
+    }
+    
+    bmp085_AC1 = ((int16_t)  coeffs[0]  <<8) | (int16_t)  coeffs[1];
+    bmp085_AC2 = ((int16_t)  coeffs[2]  <<8) | (int16_t)  coeffs[3];
+    bmp085_AC3 = ((int16_t)  coeffs[4]  <<8) | (int16_t)  coeffs[5];
+    bmp085_AC4 = ((uint16_t) coeffs[6]  <<8) | (uint16_t) coeffs[7];
+    bmp085_AC5 = ((uint16_t) coeffs[8]  <<8) | (uint16_t) coeffs[9];
+    bmp085_AC6 = ((uint16_t) coeffs[10] <<8) | (uint16_t) coeffs[11];
+    bmp085_B1 =  ((int16_t)  coeffs[12] <<8) | (int16_t)  coeffs[13];
+    bmp085_B2 =  ((int16_t)  coeffs[14] <<8) | (int16_t)  coeffs[15];
+    bmp085_MB =  ((int16_t)  coeffs[16] <<8) | (int16_t)  coeffs[17];
+    bmp085_MC =  ((int16_t)  coeffs[18] <<8) | (int16_t)  coeffs[19];
+    bmp085_MD =  ((int16_t)  coeffs[20] <<8) | (int16_t)  coeffs[21];
+
+    DEBUG("barometer: BMP085_read_coeffs - AC1=%d, AC2=%d, AC3=%d, AC4=%u,"\
+          " AC5=%u, AC6=%u, B1=%d, B2=%d, MB=%d, MC=%d, MD=%d",
+          bmp085_AC1,
+          bmp085_AC2,
+          bmp085_AC3,
+          bmp085_AC4,
+          bmp085_AC5,
+          bmp085_AC6,
+          bmp085_B1,
+          bmp085_B2,
+          bmp085_MB,
+          bmp085_MC,
+          bmp085_MD);
+
+    return 0;
+}
+
+
+/**
+ * Convert raw BMP085 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 BMP085_convert_adc_to_real(long adc_pressure,
+                                       long adc_temperature,
+                                       double * pressure,
+                                       double * temperature)
+
+{
+    long X1, X2, X3;
+    long B3, B5, B6;
+    unsigned long B4, B7;
+
+    long T;
+    long P;
+
+
+    /* calculate real temperature */
+    X1 = ( (adc_temperature - bmp085_AC6) * bmp085_AC5) >> 15;
+    X2 = (bmp085_MC << 11) / (X1 + bmp085_MD);
+
+    /* B5, T */
+    B5 = X1 + X2;
+    T = (B5 + 8) >> 4;
+    *temperature = (double)T * 0.1;
+
+    /* calculate real pressure */
+    /* in general X1, X2, X3 are recycled while values of B3, B4, B5, B6 are kept */
+
+    /* B6, B3 */
+    B6 = B5 - 4000;
+    X1 = ((bmp085_B2 * ((B6 * B6)>>12)) >> 11 );
+    X2 = (((long)bmp085_AC2 * B6) >> 11);
+    X3 = X1 + X2;
+    B3 = (((((long)bmp085_AC1 * 4) + X3) << bmp085_oversampling) + 2) >> 2;
+    
+    /* B4 */
+    X1 = (((long)bmp085_AC3*B6) >> 13);
+    X2 = (bmp085_B1*((B6*B6) >> 12) ) >> 16;
+    X3 = ((X1 + X2) + 2 ) >> 2;
+    B4 = ((long)bmp085_AC4* (unsigned long)(X3 + 32768)) >> 15;
+    
+    /* B7, P */
+    B7 =  (unsigned long)(adc_pressure - B3)*(50000>>bmp085_oversampling);
+    if( B7 < 0x80000000 )
+    {
+        P = (B7 << 1) / B4;
+    }
+    else
+    {
+        P = (B7/B4) << 1;
+    }
+    X1 = (P >> 8) * (P >> 8);
+    X1 = (X1 * 3038) >> 16;
+    X2 = ((-7357) * P) >> 16;
+    P = P + ( ( X1 + X2 + 3791 ) >> 4);
+    
+    *pressure = P / 100.0; // in [hPa] 
+    DEBUG ("barometer: BMP085_convert_adc_to_real - got %lf hPa, %lf C",
+           *pressure,
+           *temperature);
+}
+
+    
+/** 
+ * Read compensated sensor measurements
+ *
+ * @param pressure    averaged measured pressure
+ * @param temperature averaged measured temperature
+ *
+ * @return Zero when successful
+ */
+static int BMP085_read(double * pressure, double * temperature)
+{
+    __s32 res;
+    __u8 measBuff[3];
+
+    long adc_pressure;
+    long adc_temperature;
+
+    char errbuf[1024];
+
+    /* start conversion of temperature */
+    res = i2c_smbus_write_byte_data( i2c_bus_fd,
+                                     BMP085_ADDR_CTRL_REG,
+                                     BMP085_CMD_CONVERT_TEMP );
+    if (res < 0)
+    {
+        ERROR ("barometer: BMP085_read - problem requesting temperature conversion: %s",
+               sstrerror (errno, errbuf, sizeof (errbuf)));
+        return 1;
+    }
+
+    usleep(BMP085_TIME_CNV_TEMP); /* wait for the conversion */
+
+    res = i2c_smbus_read_i2c_block_data( i2c_bus_fd,
+                                         BMP085_ADDR_CONV, 
+                                         2,
+                                         measBuff); 
+    if (res < 0)
+    {
+        ERROR ("barometer: BMP085_read - problem reading temperature data: %s",
+               sstrerror (errno, errbuf, sizeof (errbuf)));
+        return 1;
+    }
+
+    adc_temperature = ( (unsigned short)measBuff[0] << 8 ) + measBuff[1]; 
+    
+
+    /* get presure */
+    res = i2c_smbus_write_byte_data( i2c_bus_fd,
+                                     BMP085_ADDR_CTRL_REG, 
+                                     bmp085_cmdCnvPress );
+    if (res < 0)
+    {
+        ERROR ("barometer: BMP085_read - problem requesting pressure conversion: %s",
+               sstrerror (errno, errbuf, sizeof (errbuf)));
+        return 1;
+    }
+
+    usleep(bmp085_timeCnvPress); /* wait for the conversion */
+
+    res = i2c_smbus_read_i2c_block_data( i2c_bus_fd,
+                                         BMP085_ADDR_CONV, 
+                                         3,
+                                         measBuff );
+    if (res < 0)
+    {
+        ERROR ("barometer: BMP085_read - problem reading pressure data: %s",
+               sstrerror (errno, errbuf, sizeof (errbuf)));
+        return 1;
+    }
+
+    adc_pressure = (long)((((ulong)measBuff[0]<<16) | ((ulong)measBuff[1]<<8) | (ulong)measBuff[2] ) >> (8 - bmp085_oversampling));
+    
+
+    DEBUG ("barometer: BMP085_read - raw pressure ADC value = %ld, " \
+           "raw temperature ADC value = %ld",
+           adc_pressure,
+           adc_temperature);
+
+    BMP085_convert_adc_to_real(adc_pressure, adc_temperature, pressure, temperature);
+
+    return 0;
+}
+
+
+
+/* ------------------------ Sensor detection ------------------------ */
+/** 
+ * Detect presence of a supported sensor.
+ *
+ * As a sideeffect will leave set I2C slave address.
+ * The detection is done in the order BMP085, MPL3115, MPL115 and stops after
+ * first sensor beeing found.
+ * 
+ * @return detected sensor type
+ */
+enum Sensor_type Detect_sensor_type(void)
+{
+    if(BMP085_detect())
+        return Sensor_BMP085;
+
+    else if(MPL3115_detect())
+        return Sensor_MPL3115;
+
+    else if(MPL115_detect())
+        return Sensor_MPL115;
+
+    return Sensor_none;
+}
+
+/* ------------------------ 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;
+
+    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, 9.80665*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;
+    }
+
+    DEBUG ("barometer: abs_to_mean_sea_level_pressure: absPressure = %lf hPa, method = %d, meanPressure = %lf hPa",
+           abs_pressure,
+           config_normalize,
+           mean);
+
+    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 1 to 128 (for MPL3115) or 1 to 8 (for BMP085).",
+                     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(sensor_type == Sensor_MPL115)
+    {
+        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;
+}
+
+
+/** 
+ * Plugin read callback for BMP085.
+ * 
+ *  Dispatching will create values:
+ *  - <hostname>/barometer-bmp085/pressure-normalized
+ *  - <hostname>/barometer-bmp085/pressure-absolute
+ *  - <hostname>/barometer-bmp085/temperature
+ *
+ * @return Zero when successful.
+ */
+static int BMP085_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: BMP085_collectd_barometer_read");
+    
+    if (!configured)
+    {
+        return -1;
+    }
+    
+    result = BMP085_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, "bmp085", 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;
+    }
+
+    /* detect sensor type - this will also set slave address */
+    sensor_type = Detect_sensor_type();
+
+    /* init correct sensor type */
+    switch(sensor_type)
+    {
+/* MPL3115 */
+    case Sensor_MPL3115:
+    {
+        MPL3115_adjust_oversampling();
+        
+        if(MPL3115_init_sensor())
+            return -1;
+        
+        plugin_register_read ("barometer", MPL3115_collectd_barometer_read);
+    }
+    break;
+
+/* MPL115 */
+    case Sensor_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);
+    }
+    break;
+
+/* BMP085 */
+    case Sensor_BMP085:
+    {
+        BMP085_adjust_oversampling();
+
+        if (BMP085_read_coeffs() < 0)
+            return -1;
+
+        plugin_register_read ("barometer", BMP085_collectd_barometer_read);
+    }
+    break;
+
+/* anything else -> error */
+    default:
+        ERROR("barometer: collectd_barometer_init - no supported sensor found");
+        return -1;
+    }
+        
+
+    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 4178d8b5145f2b728e5c7c949d72ebd8d126a89e..c4c050d7ff1cd11cc70cd2d17323f90da747e542 100644 (file)
@@ -1,7 +1,8 @@
 /**
  * collectd - src/battery.c
- * Copyright (C) 2006,2007  Florian octo Forster
+ * Copyright (C) 2006-2014  Florian octo Forster
  * Copyright (C) 2008       Michał Mirosław
+ * Copyright (C) 2014       Andy Parkins
  *
  * 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>
  *   Michał Mirosław <mirq-linux at rere.qmqm.pl>
+ *   Andy Parkins <andyp at fussylogic.co.uk>
  **/
 
 #include "collectd.h"
 # error "No applicable input method."
 #endif
 
-#define INVALID_VALUE 47841.29
-
 #if HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H
        /* No global variables */
 /* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */
 
 #elif KERNEL_LINUX
-static int   battery_pmu_num = 0;
-static char *battery_pmu_file = "/proc/pmu/battery_%i";
-static const char *battery_acpi_dir = "/proc/acpi/battery";
+# define PROC_PMU_PATH_FORMAT "/proc/pmu/battery_%i"
+# define PROC_ACPI_PATH "/proc/acpi/battery"
+# define PROC_ACPI_FACTOR 0.001
+# define SYSFS_PATH "/sys/class/power_supply"
+# define SYSFS_FACTOR 0.000001
 #endif /* KERNEL_LINUX */
 
-static int battery_init (void)
-{
-#if HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H
-       /* No init neccessary */
-/* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */
-
-#elif KERNEL_LINUX
-       int len;
-       char filename[128];
-
-       for (battery_pmu_num = 0; ; battery_pmu_num++)
-       {
-               len = ssnprintf (filename, sizeof (filename), battery_pmu_file, battery_pmu_num);
-
-               if ((len < 0) || ((unsigned int)len >= sizeof (filename)))
-                       break;
+static _Bool report_percent = 0;
+static _Bool report_degraded = 0;
 
-               if (access (filename, R_OK))
-                       break;
-       }
-#endif /* KERNEL_LINUX */
-
-       return (0);
-}
-
-static void battery_submit (const char *plugin_instance, const char *type, double value)
+static void battery_submit2 (char const *plugin_instance, /* {{{ */
+               char const *type, char const *type_instance, gauge_t value)
 {
        value_t values[1];
        value_list_t vl = VALUE_LIST_INIT;
@@ -106,12 +87,63 @@ static void battery_submit (const char *plugin_instance, const char *type, doubl
        sstrncpy (vl.plugin, "battery", sizeof (vl.plugin));
        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 battery_submit */
+} /* }}} void battery_submit2 */
+
+static void battery_submit (char const *plugin_instance, /* {{{ */
+               char const *type, gauge_t value)
+{
+       battery_submit2 (plugin_instance, type, NULL, value);
+} /* }}} void battery_submit */
+
+static void submit_capacity (char const *plugin_instance, /* {{{ */
+               gauge_t capacity_charged,
+               gauge_t capacity_full,
+               gauge_t capacity_design)
+{
+       if (report_percent && (capacity_charged > capacity_full))
+               return;
+       if (report_degraded && (capacity_full > capacity_design))
+               return;
+
+       if (report_percent)
+       {
+               gauge_t capacity_max;
+
+               if (report_degraded)
+                       capacity_max = capacity_design;
+               else
+                       capacity_max = capacity_full;
+
+               battery_submit2 (plugin_instance, "percent", "charged",
+                               100.0 * capacity_charged / capacity_max);
+               battery_submit2 (plugin_instance, "percent", "discharged",
+                               100.0 * (capacity_full - capacity_charged) / capacity_max);
+
+               if (report_degraded)
+                       battery_submit2 (plugin_instance, "percent", "degraded",
+                                       100.0 * (capacity_design - capacity_full) / capacity_max);
+       }
+       else if (report_degraded) /* && !report_percent */
+       {
+               battery_submit2 (plugin_instance, "capacity", "charged",
+                               capacity_charged);
+               battery_submit2 (plugin_instance, "capacity", "discharged",
+                               (capacity_full - capacity_charged));
+               battery_submit2 (plugin_instance, "capacity", "degraded",
+                               (capacity_design - capacity_full));
+       }
+       else /* !report_percent && !report_degraded */
+       {
+               battery_submit (plugin_instance, "capacity", capacity_charged);
+       }
+} /* }}} void submit_capacity */
 
 #if HAVE_IOKIT_PS_IOPOWERSOURCES_H || HAVE_IOKIT_IOKITLIB_H
-double dict_get_double (CFDictionaryRef dict, char *key_string)
+static double dict_get_double (CFDictionaryRef dict, char *key_string) /* {{{ */
 {
        double      val_double;
        long long   val_int;
@@ -119,18 +151,18 @@ double dict_get_double (CFDictionaryRef dict, char *key_string)
        CFStringRef key_obj;
 
        key_obj = CFStringCreateWithCString (kCFAllocatorDefault, key_string,
-                       kCFStringEncodingASCII);
+                       kCFStringEncodingASCII);
        if (key_obj == NULL)
        {
                DEBUG ("CFStringCreateWithCString (%s) failed.\n", key_string);
-               return (INVALID_VALUE);
+               return (NAN);
        }
 
        if ((val_obj = CFDictionaryGetValue (dict, key_obj)) == NULL)
        {
                DEBUG ("CFDictionaryGetValue (%s) failed.", key_string);
                CFRelease (key_obj);
-               return (INVALID_VALUE);
+               return (NAN);
        }
        CFRelease (key_obj);
 
@@ -153,15 +185,14 @@ double dict_get_double (CFDictionaryRef dict, char *key_string)
        else
        {
                DEBUG ("CFGetTypeID (val_obj) = %i", (int) CFGetTypeID (val_obj));
-               return (INVALID_VALUE);
+               return (NAN);
        }
 
        return (val_double);
-}
-#endif /* HAVE_IOKIT_PS_IOPOWERSOURCES_H || HAVE_IOKIT_IOKITLIB_H */
+} /* }}} double dict_get_double */
 
-#if HAVE_IOKIT_PS_IOPOWERSOURCES_H
-static void get_via_io_power_sources (double *ret_charge,
+# if HAVE_IOKIT_PS_IOPOWERSOURCES_H
+static void get_via_io_power_sources (double *ret_charge, /* {{{ */
                double *ret_current,
                double *ret_voltage)
 {
@@ -199,41 +230,42 @@ static void get_via_io_power_sources (double *ret_charge,
 
                /* FIXME: Check if this is really an internal battery */
 
-               if (*ret_charge == INVALID_VALUE)
+               if (isnan (*ret_charge))
                {
                        /* This is the charge in percent. */
                        temp_double = dict_get_double (ps_dict,
                                        kIOPSCurrentCapacityKey);
-                       if ((temp_double != INVALID_VALUE)
+                       if (!isnan ((temp_double))
                                        && (temp_double >= 0.0)
                                        && (temp_double <= 100.0))
                                *ret_charge = temp_double;
                }
 
-               if (*ret_current == INVALID_VALUE)
+               if (isnan (*ret_current))
                {
                        temp_double = dict_get_double (ps_dict,
                                        kIOPSCurrentKey);
-                       if (temp_double != INVALID_VALUE)
+                       if (!isnan (temp_double))
                                *ret_current = temp_double / 1000.0;
                }
 
-               if (*ret_voltage == INVALID_VALUE)
+               if (isnan (*ret_voltage))
                {
                        temp_double = dict_get_double (ps_dict,
                                        kIOPSVoltageKey);
-                       if (temp_double != INVALID_VALUE)
+                       if (!isnan (temp_double))
                                *ret_voltage = temp_double / 1000.0;
                }
        }
 
        CFRelease(ps_array);
        CFRelease(ps_raw);
-}
-#endif /* HAVE_IOKIT_PS_IOPOWERSOURCES_H */
+} /* }}} void get_via_io_power_sources */
+# endif /* HAVE_IOKIT_PS_IOPOWERSOURCES_H */
 
-#if HAVE_IOKIT_IOKITLIB_H
-static void get_via_generic_iokit (double *ret_charge,
+# if HAVE_IOKIT_IOKITLIB_H
+static void get_via_generic_iokit (double *ret_capacity_full, /* {{{ */
+               double *ret_capacity_design,
                double *ret_current,
                double *ret_voltage)
 {
@@ -280,33 +312,33 @@ static void get_via_generic_iokit (double *ret_charge,
                bat_info_arry_len = CFArrayGetCount (bat_info_arry);
 
                for (bat_info_arry_pos = 0;
-                               bat_info_arry_pos < bat_info_arry_len;
-                               bat_info_arry_pos++)
+                               bat_info_arry_pos < bat_info_arry_len;
+                               bat_info_arry_pos++)
                {
                        bat_info_dict = (CFDictionaryRef) CFArrayGetValueAtIndex (bat_info_arry, bat_info_arry_pos);
 
-                       if (*ret_charge == INVALID_VALUE)
+                       if (isnan (*ret_capacity_full))
                        {
-                               temp_double = dict_get_double (bat_info_dict,
-                                               "Capacity");
-                               if (temp_double != INVALID_VALUE)
-                                       *ret_charge = temp_double / 1000.0;
+                               temp_double = dict_get_double (bat_info_dict, "Capacity");
+                               *ret_capacity_full = temp_double / 1000.0;
                        }
 
-                       if (*ret_current == INVALID_VALUE)
+                       if (isnan (*ret_capacity_design))
                        {
-                               temp_double = dict_get_double (bat_info_dict,
-                                               "Current");
-                               if (temp_double != INVALID_VALUE)
-                                       *ret_current = temp_double / 1000.0;
+                               temp_double = dict_get_double (bat_info_dict, "AbsoluteMaxCapacity");
+                               *ret_capacity_design = temp_double / 1000.0;
                        }
 
-                       if (*ret_voltage == INVALID_VALUE)
+                       if (isnan (*ret_current))
                        {
-                               temp_double = dict_get_double (bat_info_dict,
-                                               "Voltage");
-                               if (temp_double != INVALID_VALUE)
-                                       *ret_voltage = temp_double / 1000.0;
+                               temp_double = dict_get_double (bat_info_dict, "Current");
+                               *ret_current = temp_double / 1000.0;
+                       }
+
+                       if (isnan (*ret_voltage))
+                       {
+                               temp_double = dict_get_double (bat_info_dict, "Voltage");
+                               *ret_voltage = temp_double / 1000.0;
                        }
                }
                
@@ -314,38 +346,281 @@ static void get_via_generic_iokit (double *ret_charge,
        }
 
        IOObjectRelease (iterator);
-}
-#endif /* HAVE_IOKIT_IOKITLIB_H */
+} /* }}} void get_via_generic_iokit */
+# endif /* HAVE_IOKIT_IOKITLIB_H */
 
-#if KERNEL_LINUX
-static int battery_read_acpi (const char __attribute__((unused)) *dir,
-               const char *name, void __attribute__((unused)) *user_data)
+static int battery_read (void) /* {{{ */
 {
-       double  current = INVALID_VALUE;
-       double  voltage = INVALID_VALUE;
-       double  charge  = INVALID_VALUE;
-       double *valptr = NULL;
-       int charging = 0;
+       gauge_t current = NAN; /* Current in A */
+       gauge_t voltage = NAN; /* Voltage in V */
 
-       char filename[256];
-       FILE *fh;
+       /* We only get the charged capacity as a percentage from
+        * IOPowerSources. IOKit, on the other hand, only reports the full
+        * capacity. We use the two to calculate the current charged capacity. */
+       gauge_t charge_rel = NAN; /* Current charge in percent */
+       gauge_t capacity_charged = NAN; /* Charged capacity */
+       gauge_t capacity_full = NAN; /* Total capacity */
+       gauge_t capacity_design = NAN; /* Full design capacity */
+
+#if HAVE_IOKIT_PS_IOPOWERSOURCES_H
+       get_via_io_power_sources (&charge_rel, &current, &voltage);
+#endif
+#if HAVE_IOKIT_IOKITLIB_H
+       get_via_generic_iokit (&capacity_full, &capacity_design, &current, &voltage);
+#endif
+
+       capacity_charged = charge_rel * capacity_full / 100.0;
+       submit_capacity ("0", capacity_charged, capacity_full, capacity_design);
+
+       if (!isnan (current))
+               battery_submit ("0", "current", current);
+       if (!isnan (voltage))
+               battery_submit ("0", "voltage", voltage);
+
+       return (0);
+} /* }}} int battery_read */
+/* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */
+
+#elif KERNEL_LINUX
+/* Reads a file which contains only a number (and optionally a trailing
+ * newline) and parses that number. */
+static int sysfs_file_to_buffer(char const *dir, /* {{{ */
+               char const *power_supply,
+               char const *basename,
+               char *buffer, size_t buffer_size)
+{
+       int status;
+       FILE *fp;
+       char filename[PATH_MAX];
+
+       ssnprintf (filename, sizeof (filename), "%s/%s/%s",
+                       dir, power_supply, basename);
+
+       /* No file isn't the end of the world -- not every system will be
+        * reporting the same set of statistics */
+       if (access (filename, R_OK) != 0)
+               return ENOENT;
+
+       fp = fopen (filename, "r");
+       if (fp == NULL)
+       {
+               status = errno;
+               if (status != ENOENT)
+               {
+                       char errbuf[1024];
+                       WARNING ("battery plugin: fopen (%s) failed: %s", filename,
+                                       sstrerror (status, errbuf, sizeof (errbuf)));
+               }
+               return status;
+       }
+
+       if (fgets (buffer, buffer_size, fp) == NULL)
+       {
+               status = errno;
+               if (status != ENODEV)
+               {
+                       char errbuf[1024];
+                       WARNING ("battery plugin: fgets (%s) failed: %s", filename,
+                                       sstrerror (status, errbuf, sizeof (errbuf)));
+               }
+               fclose (fp);
+               return status;
+       }
+
+       strstripnewline (buffer);
+
+       fclose (fp);
+       return 0;
+} /* }}} int sysfs_file_to_buffer */
+
+/* Reads a file which contains only a number (and optionally a trailing
+ * newline) and parses that number. */
+static int sysfs_file_to_gauge(char const *dir, /* {{{ */
+               char const *power_supply,
+               char const *basename, gauge_t *ret_value)
+{
+       int status;
+       char buffer[32] = "";
+
+       status = sysfs_file_to_buffer (dir, power_supply, basename, buffer, sizeof (buffer));
+       if (status != 0)
+               return (status);
+
+       return (strtogauge (buffer, ret_value));
+} /* }}} sysfs_file_to_gauge */
+
+static int read_sysfs_capacity (char const *dir, /* {{{ */
+               char const *power_supply,
+               char const *plugin_instance)
+{
+       gauge_t capacity_charged = NAN;
+       gauge_t capacity_full = NAN;
+       gauge_t capacity_design = NAN;
+       int status;
+
+       status = sysfs_file_to_gauge (dir, power_supply, "energy_now", &capacity_charged);
+       if (status != 0)
+               return (status);
+
+       status = sysfs_file_to_gauge (dir, power_supply, "energy_full", &capacity_full);
+       if (status != 0)
+               return (status);
+
+       status = sysfs_file_to_gauge (dir, power_supply, "energy_full_design", &capacity_design);
+       if (status != 0)
+               return (status);
+
+       submit_capacity (plugin_instance,
+                       capacity_charged * SYSFS_FACTOR,
+                       capacity_full * SYSFS_FACTOR,
+                       capacity_design * SYSFS_FACTOR);
+       return (0);
+} /* }}} int read_sysfs_capacity */
+
+static int read_sysfs_callback (char const *dir, /* {{{ */
+               char const *power_supply,
+               void *user_data)
+{
+       int *battery_index = user_data;
+
+       char const *plugin_instance;
+       char buffer[32];
+       gauge_t v = NAN;
+       _Bool discharging = 0;
+       int status;
+
+       /* Ignore non-battery directories, such as AC power. */
+       status = sysfs_file_to_buffer (dir, power_supply, "type", buffer, sizeof (buffer));
+       if (status != 0)
+               return (0);
+       if (strcasecmp ("Battery", buffer) != 0)
+               return (0);
+
+       (void) sysfs_file_to_buffer (dir, power_supply, "status", buffer, sizeof (buffer));
+       if (strcasecmp ("Discharging", buffer) == 0)
+               discharging = 1;
+
+       /* FIXME: This is a dirty hack for backwards compatibility: The battery
+        * plugin, for a very long time, has had the plugin_instance
+        * hard-coded to "0". So, to keep backwards compatibility, we'll use
+        * "0" for the first battery we find and the power_supply name for all
+        * following. This should be reverted in a future major version. */
+       plugin_instance = (*battery_index == 0) ? "0" : power_supply;
+       (*battery_index)++;
+
+       read_sysfs_capacity (dir, power_supply, plugin_instance);
+
+       if (sysfs_file_to_gauge (dir, power_supply, "power_now", &v) == 0)
+       {
+               if (discharging)
+                       v *= -1.0;
+               battery_submit (plugin_instance, "power", v * SYSFS_FACTOR);
+       }
+       if (sysfs_file_to_gauge (dir, power_supply, "current_now", &v) == 0)
+       {
+               if (discharging)
+                       v *= -1.0;
+               battery_submit (plugin_instance, "current", v * SYSFS_FACTOR);
+       }
+
+       if (sysfs_file_to_gauge (dir, power_supply, "voltage_now", &v) == 0)
+               battery_submit (plugin_instance, "voltage", v * SYSFS_FACTOR);
+
+       return (0);
+} /* }}} int read_sysfs_callback */
+
+static int read_sysfs (void) /* {{{ */
+{
+       int status;
+       int battery_counter = 0;
+
+       if (access (SYSFS_PATH, R_OK) != 0)
+               return (ENOENT);
 
+       status = walk_directory (SYSFS_PATH, read_sysfs_callback,
+                       /* user_data = */ &battery_counter,
+                       /* include hidden */ 0);
+       return (status);
+} /* }}} int read_sysfs */
+
+static int read_acpi_full_capacity (char const *dir, /* {{{ */
+               char const *power_supply,
+               gauge_t *ret_capacity_full,
+               gauge_t *ret_capacity_design)
+
+{
+       char filename[PATH_MAX];
        char buffer[1024];
-       char *fields[8];
-       int numfields;
-       char *endptr;
-       int len;
 
-       len = ssnprintf (filename, sizeof (filename), "%s/%s/state", battery_acpi_dir, name);
+       FILE *fh;
+
+       ssnprintf (filename, sizeof (filename), "%s/%s/info", dir, power_supply);
+       fh = fopen (filename, "r");
+       if (fh == NULL)
+               return (errno);
 
-       if ((len < 0) || ((unsigned int)len >= sizeof (filename)))
-               return -1;
+       /* last full capacity:      40090 mWh */
+       while (fgets (buffer, sizeof (buffer), fh) != NULL)
+       {
+               gauge_t *value_ptr;
+               int fields_num;
+               char *fields[8];
+               int index;
 
-       if ((fh = fopen (filename, "r")) == NULL) {
-               char errbuf[1024];
-               ERROR ("Cannot open `%s': %s", filename,
-                       sstrerror (errno, errbuf, sizeof (errbuf)));
-               return -1;
+               if (strncmp ("last full capacity:", buffer, strlen ("last full capacity:")) == 0)
+               {
+                       value_ptr = ret_capacity_full;
+                       index = 3;
+               }
+               else if (strncmp ("design capacity:", buffer, strlen ("design capacity:")) == 0)
+               {
+                       value_ptr = ret_capacity_design;
+                       index = 2;
+               }
+               else
+               {
+                       continue;
+               }
+
+               fields_num = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
+               if (fields_num <= index)
+                       continue;
+
+               strtogauge (fields[index], value_ptr);
+       }
+
+       fclose (fh);
+       return (0);
+} /* }}} int read_acpi_full_capacity */
+
+static int read_acpi_callback (char const *dir, /* {{{ */
+               char const *power_supply,
+               void *user_data)
+{
+       int *battery_index = user_data;
+
+       gauge_t power = NAN;
+       gauge_t voltage = NAN;
+       gauge_t capacity_charged = NAN;
+       gauge_t capacity_full = NAN;
+       gauge_t capacity_design = NAN;
+       _Bool charging = 0;
+       _Bool is_current = 0;
+
+       char const *plugin_instance;
+       char filename[PATH_MAX];
+       char buffer[1024];
+
+       FILE *fh;
+
+       ssnprintf (filename, sizeof (filename), "%s/%s/state", dir, power_supply);
+       fh = fopen (filename, "r");
+       if (fh == NULL)
+       {
+               if ((errno == EAGAIN) || (errno == EINTR) || (errno == ENOENT))
+                       return (0);
+               else
+                       return (errno);
        }
 
        /*
@@ -359,8 +634,10 @@ static int battery_read_acpi (const char __attribute__((unused)) *dir,
         */
        while (fgets (buffer, sizeof (buffer), fh) != NULL)
        {
-               numfields = strsplit (buffer, fields, 8);
+               char *fields[8];
+               int numfields;
 
+               numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
                if (numfields < 3)
                        continue;
 
@@ -374,164 +651,180 @@ static int battery_read_acpi (const char __attribute__((unused)) *dir,
                        continue;
                }
 
+               /* The unit of "present rate" depends on the battery. Modern
+                * batteries export power (watts), older batteries (used to)
+                * export current (amperes). We check the fourth column and try
+                * to find old batteries this way. */
                if ((strcmp (fields[0], "present") == 0)
                                && (strcmp (fields[1], "rate:") == 0))
-                       valptr = &current;
+               {
+                       strtogauge (fields[2], &power);
+
+                       if ((numfields >= 4) && (strcmp ("mA", fields[3]) == 0))
+                               is_current = 1;
+               }
                else if ((strcmp (fields[0], "remaining") == 0)
                                && (strcmp (fields[1], "capacity:") == 0))
-                       valptr = &charge;
+                       strtogauge (fields[2], &capacity_charged);
                else if ((strcmp (fields[0], "present") == 0)
                                && (strcmp (fields[1], "voltage:") == 0))
-                       valptr = &voltage;
-               else
-                       continue;
-
-               endptr = NULL;
-               errno  = 0;
-               *valptr = strtod (fields[2], &endptr) / 1000.0;
-
-               if ((fields[2] == endptr) || (errno != 0))
-                       *valptr = INVALID_VALUE;
+                       strtogauge (fields[2], &voltage);
        } /* while (fgets (buffer, sizeof (buffer), fh) != NULL) */
 
        fclose (fh);
 
-       if ((current != INVALID_VALUE) && (charging == 0))
-                       current *= -1;
+       if (!charging)
+               power *= -1.0;
 
-       if (charge != INVALID_VALUE)
-               battery_submit ("0", "charge", charge);
-       if (current != INVALID_VALUE)
-               battery_submit ("0", "current", current);
-       if (voltage != INVALID_VALUE)
-               battery_submit ("0", "voltage", voltage);
+       /* FIXME: This is a dirty hack for backwards compatibility: The battery
+        * plugin, for a very long time, has had the plugin_instance
+        * hard-coded to "0". So, to keep backwards compatibility, we'll use
+        * "0" for the first battery we find and the power_supply name for all
+        * following. This should be reverted in a future major version. */
+       plugin_instance = (*battery_index == 0) ? "0" : power_supply;
+       (*battery_index)++;
 
-       return 0;
-}
-#endif /* KERNEL_LINUX */
-
-
-static int battery_read (void)
-{
-#if HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H
-       double charge  = INVALID_VALUE; /* Current charge in Ah */
-       double current = INVALID_VALUE; /* Current in A */
-       double voltage = INVALID_VALUE; /* Voltage in V */
+       read_acpi_full_capacity (dir, power_supply, &capacity_full, &capacity_design);
 
-       double charge_rel = INVALID_VALUE; /* Current charge in percent */
-       double charge_abs = INVALID_VALUE; /* Total capacity */
+       submit_capacity (plugin_instance,
+                       capacity_charged * PROC_ACPI_FACTOR,
+                       capacity_full * PROC_ACPI_FACTOR,
+                       capacity_design * PROC_ACPI_FACTOR);
 
-#if HAVE_IOKIT_PS_IOPOWERSOURCES_H
-       get_via_io_power_sources (&charge_rel, &current, &voltage);
-#endif
-#if HAVE_IOKIT_IOKITLIB_H
-       get_via_generic_iokit (&charge_abs, &current, &voltage);
-#endif
+       battery_submit (plugin_instance,
+                       is_current ? "current" : "power",
+                       power * PROC_ACPI_FACTOR);
+       battery_submit (plugin_instance, "voltage", voltage * PROC_ACPI_FACTOR);
 
-       if ((charge_rel != INVALID_VALUE) && (charge_abs != INVALID_VALUE))
-               charge = charge_abs * charge_rel / 100.0;
+       return 0;
+} /* }}} int read_acpi_callback */
 
-       if (charge != INVALID_VALUE)
-               battery_submit ("0", "charge", charge);
-       if (current != INVALID_VALUE)
-               battery_submit ("0", "current", current);
-       if (voltage != INVALID_VALUE)
-               battery_submit ("0", "voltage", voltage);
-/* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */
+static int read_acpi (void) /* {{{ */
+{
+       int status;
+       int battery_counter = 0;
 
-#elif KERNEL_LINUX
-       static c_complain_t acpi_dir_complaint = C_COMPLAIN_INIT_STATIC;
+       if (access (PROC_ACPI_PATH, R_OK) != 0)
+               return (ENOENT);
 
-       FILE *fh;
-       char buffer[1024];
-       char filename[256];
-       
-       char *fields[8];
-       int numfields;
+       status = walk_directory (PROC_ACPI_PATH, read_acpi_callback,
+                       /* user_data = */ &battery_counter,
+                       /* include hidden */ 0);
+       return (status);
+} /* }}} int read_acpi */
 
+static int read_pmu (void) /* {{{ */
+{
        int i;
-       int len;
 
-       for (i = 0; i < battery_pmu_num; i++)
+       /* The upper limit here is just a safeguard. If there is a system with
+        * more than 100 batteries, this can easily be increased. */
+       for (i = 0; i < 100; i++)
        {
-               char    batnum_str[256];
-               double  current = INVALID_VALUE;
-               double  voltage = INVALID_VALUE;
-               double  charge  = INVALID_VALUE;
-               double *valptr = NULL;
-
-               len = ssnprintf (filename, sizeof (filename), battery_pmu_file, i);
-               if ((len < 0) || ((unsigned int)len >= sizeof (filename)))
-                       continue;
+               FILE *fh;
 
-               len = ssnprintf (batnum_str, sizeof (batnum_str), "%i", i);
-               if ((len < 0) || ((unsigned int)len >= sizeof (batnum_str)))
-                       continue;
+               char buffer[1024];
+               char filename[PATH_MAX];
+               char plugin_instance[DATA_MAX_NAME_LEN];
 
-               if ((fh = fopen (filename, "r")) == NULL)
-                       continue;
+               gauge_t current = NAN;
+               gauge_t voltage = NAN;
+               gauge_t charge  = NAN;
+
+               ssnprintf (filename, sizeof (filename), PROC_PMU_PATH_FORMAT, i);
+               if (access (filename, R_OK) != 0)
+                       break;
+
+               ssnprintf (plugin_instance, sizeof (plugin_instance), "%i", i);
+
+               fh = fopen (filename, "r");
+               if (fh == NULL)
+               {
+                       if (errno == ENOENT)
+                               break;
+                       else if ((errno == EAGAIN) || (errno == EINTR))
+                               continue;
+                       else
+                               return (errno);
+               }
 
                while (fgets (buffer, sizeof (buffer), fh) != NULL)
                {
-                       numfields = strsplit (buffer, fields, 8);
+                       char *fields[8];
+                       int numfields;
 
+                       numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
                        if (numfields < 3)
                                continue;
 
                        if (strcmp ("current", fields[0]) == 0)
-                               valptr = &current;
+                               strtogauge (fields[2], &current);
                        else if (strcmp ("voltage", fields[0]) == 0)
-                               valptr = &voltage;
+                               strtogauge (fields[2], &voltage);
                        else if (strcmp ("charge", fields[0]) == 0)
-                               valptr = &charge;
-                       else
-                               valptr = NULL;
-
-                       if (valptr != NULL)
-                       {
-                               char *endptr;
-
-                               endptr = NULL;
-                               errno  = 0;
-
-                               *valptr = strtod (fields[2], &endptr) / 1000.0;
-
-                               if ((fields[2] == endptr) || (errno != 0))
-                                       *valptr = INVALID_VALUE;
-                       }
+                               strtogauge (fields[2], &charge);
                }
 
                fclose (fh);
                fh = NULL;
 
-               if (charge != INVALID_VALUE)
-                       battery_submit ("0", "charge", charge);
-               if (current != INVALID_VALUE)
-                       battery_submit ("0", "current", current);
-               if (voltage != INVALID_VALUE)
-                       battery_submit ("0", "voltage", voltage);
+               battery_submit (plugin_instance, "charge", charge / 1000.0);
+               battery_submit (plugin_instance, "current", current / 1000.0);
+               battery_submit (plugin_instance, "voltage", voltage / 1000.0);
        }
 
-       if (0 == access (battery_acpi_dir, R_OK))
-               walk_directory (battery_acpi_dir, battery_read_acpi,
-                               /* user_data = */ NULL,
-                               /* include hidden */ 0);
-       else
-       {
-               char errbuf[1024];
-               c_complain_once (LOG_WARNING, &acpi_dir_complaint,
-                               "battery plugin: Failed to access `%s': %s",
-                               battery_acpi_dir,
-                               sstrerror (errno, errbuf, sizeof (errbuf)));
-       }
+       if (i == 0)
+               return (ENOENT);
+       return (0);
+} /* }}} int read_pmu */
 
+static int battery_read (void) /* {{{ */
+{
+       int status;
+
+       DEBUG ("battery plugin: Trying sysfs ...");
+       status = read_sysfs ();
+       if (status == 0)
+               return (0);
+
+       DEBUG ("battery plugin: Trying acpi ...");
+       status = read_acpi ();
+       if (status == 0)
+               return (0);
+
+       DEBUG ("battery plugin: Trying pmu ...");
+       status = read_pmu ();
+       if (status == 0)
+               return (0);
+
+       ERROR ("battery plugin: Add available input methods failed.");
+       return (-1);
+} /* }}} int battery_read */
 #endif /* KERNEL_LINUX */
 
+static int battery_config (oconfig_item_t *ci)
+{
+       int i;
+
+       for (i = 0; i < ci->children_num; i++)
+       {
+               oconfig_item_t *child = ci->children + i;
+
+               if (strcasecmp ("ValuesPercentage", child->key) == 0)
+                       cf_util_get_boolean (child, &report_percent);
+               else if (strcasecmp ("ReportDegraded", child->key) == 0)
+                       cf_util_get_boolean (child, &report_degraded);
+               else
+                       WARNING ("battery plugin: Ignoring unknown "
+                                       "configuration option \"%s\".",
+                                       child->key);
+       }
+
        return (0);
-}
+} /* }}} int battery_config */
 
 void module_register (void)
 {
-       plugin_register_init ("battery", battery_init);
+       plugin_register_complex_config ("battery", battery_config);
        plugin_register_read ("battery", battery_read);
 } /* void module_register */
index 03dfcc77cd7bf322b7576fe288f0bbb3c6e14191..32b0f16e21f50311d530f934f72964076dfee0ee 100644 (file)
@@ -109,6 +109,7 @@ static int global_server_stats     = 1;
 static int global_zone_maint_stats = 1;
 static int global_resolver_stats   = 0;
 static int global_memory_stats     = 1;
+static int timeout                 = -1;
 
 static cb_view_t *views = NULL;
 static size_t     views_num = 0;
@@ -369,9 +370,11 @@ static int bind_xml_read_derive (xmlDoc *doc, xmlNode *node, /* {{{ */
   {
     ERROR ("bind plugin: Parsing string \"%s\" to derive value failed.",
         str_ptr);
+    xmlFree(str_ptr);
     return (-1);
   }
 
+  xmlFree(str_ptr);
   *ret_value = value.derive;
   return (0);
 } /* }}} int bind_xml_read_derive */
@@ -627,6 +630,84 @@ static int bind_parse_generic_value_list (const char *xpath_expression, /* {{{ *
   return (0);
 } /* }}} int bind_parse_generic_value_list */
 
+/*
+ * bind_parse_generic_name_attr_value_list
+ *
+ * Reads statistics in the form:
+ * <foo>
+ *   <counter name="name0">123</counter>
+ *   <counter name="name1">234</counter>
+ *   <counter name="name2">345</counter>
+ *   :
+ * </foo>
+ */
+static int bind_parse_generic_name_attr_value_list (const char *xpath_expression, /* {{{ */
+    list_callback_t list_callback,
+    void *user_data,
+    xmlDoc *doc, xmlXPathContext *xpathCtx,
+    time_t current_time, int ds_type)
+{
+  xmlXPathObject *xpathObj = NULL;
+  int num_entries;
+  int i;
+
+  xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
+  if (xpathObj == NULL)
+  {
+    ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
+        xpath_expression);
+    return (-1);
+  }
+
+  num_entries = 0;
+  /* Iterate over all matching nodes. */
+  for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
+  {
+    xmlNode *child;
+
+    /* Iterate over all child nodes. */
+    for (child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
+        child != NULL;
+        child = child->next)
+    {
+      if (child->type != XML_ELEMENT_NODE)
+        continue;
+
+      if (strncmp ("counter", (char *) child->name, strlen ("counter")) != 0)
+        continue;
+
+      char *attr_name;
+      value_t value;
+      int status;
+
+      attr_name = (char *) xmlGetProp (child, BAD_CAST "name");
+      if (attr_name == NULL)
+      {
+        DEBUG ("bind plugin: found <counter> without name.");
+        continue;
+      }
+      if (ds_type == DS_TYPE_GAUGE)
+        status = bind_xml_read_gauge (doc, child, &value.gauge);
+      else
+        status = bind_xml_read_derive (doc, child, &value.derive);
+      if (status != 0)
+        continue;
+
+      status = (*list_callback) (attr_name, value, current_time, user_data);
+      if (status == 0)
+        num_entries++;
+    }
+  }
+
+  DEBUG ("bind plugin: Found %d %s for XPath expression `%s'",
+      num_entries, (num_entries == 1) ? "entry" : "entries",
+      xpath_expression);
+
+  xmlXPathFreeObject(xpathObj);
+
+  return (0);
+} /* }}} int bind_parse_generic_name_attr_value_list */
+
 static int bind_xml_stats_handle_zone (int version, xmlDoc *doc, /* {{{ */
     xmlXPathContext *path_ctx, xmlNode *node, cb_view_t *view,
     time_t current_time)
@@ -636,25 +717,40 @@ static int bind_xml_stats_handle_zone (int version, xmlDoc *doc, /* {{{ */
   int i;
   size_t j;
 
-  path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
-  if (path_obj == NULL)
+  if (version >= 3)
   {
-    ERROR ("bind plugin: xmlXPathEvalExpression failed.");
-    return (-1);
+    char *n = (char *) xmlGetProp (node, BAD_CAST "name");
+    char *c = (char *) xmlGetProp (node, BAD_CAST "rdataclass");
+    if (n && c)
+    {
+      zone_name = (char *) xmlMalloc(strlen(n) + strlen(c) + 2);
+      snprintf(zone_name, strlen(n) + strlen(c) + 2, "%s/%s", n, c);
+    }
+    xmlFree(n);
+    xmlFree(c);
   }
-
-  for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
+  else
   {
-    zone_name = (char *) xmlNodeListGetString (doc,
-        path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
-    if (zone_name != NULL)
-      break;
+    path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
+    if (path_obj == NULL)
+    {
+      ERROR ("bind plugin: xmlXPathEvalExpression failed.");
+      return (-1);
+    }
+
+    for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
+    {
+      zone_name = (char *) xmlNodeListGetString (doc,
+          path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
+      if (zone_name != NULL)
+        break;
+    }
+    xmlXPathFreeObject (path_obj);
   }
 
   if (zone_name == NULL)
   {
     ERROR ("bind plugin: Could not determine zone name.");
-    xmlXPathFreeObject (path_obj);
     return (-1);
   }
 
@@ -667,11 +763,8 @@ static int bind_xml_stats_handle_zone (int version, xmlDoc *doc, /* {{{ */
   xmlFree (zone_name);
   zone_name = NULL;
 
-  if (j >= views_num)
-  {
-    xmlXPathFreeObject (path_obj);
+  if (j >= view->zones_num)
     return (0);
-  }
 
   zone_name = view->zones[j];
 
@@ -690,14 +783,31 @@ static int bind_xml_stats_handle_zone (int version, xmlDoc *doc, /* {{{ */
     ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-zone-%s",
         view->name, zone_name);
 
-    bind_parse_generic_value_list (/* xpath = */ "counters",
+    if (version == 3)
+    {
+      list_info_ptr_t list_info =
+      {
+        plugin_instance,
+        /* type = */ "dns_qtype"
+      };
+      bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='rcode']",
         /* callback = */ bind_xml_table_callback,
         /* user_data = */ &table_ptr,
         doc, path_ctx, current_time, DS_TYPE_COUNTER);
+      bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='qtype']",
+        /* callback = */ bind_xml_list_callback,
+        /* user_data = */ &list_info,
+        doc, path_ctx, current_time, DS_TYPE_COUNTER);
+    }
+    else
+    {
+      bind_parse_generic_value_list (/* xpath = */ "counters",
+          /* callback = */ bind_xml_table_callback,
+          /* user_data = */ &table_ptr,
+          doc, path_ctx, current_time, DS_TYPE_COUNTER);
+    }
   } /* }}} */
 
-  xmlXPathFreeObject (path_obj);
-
   return (0);
 } /* }}} int bind_xml_stats_handle_zone */
 
@@ -745,45 +855,68 @@ static int bind_xml_stats_search_zones (int version, xmlDoc *doc, /* {{{ */
 static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */
     xmlXPathContext *path_ctx, xmlNode *node, time_t current_time)
 {
-  xmlXPathObject *path_obj;
   char *view_name = NULL;
   cb_view_t *view;
   int i;
   size_t j;
 
-  path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
-  if (path_obj == NULL)
+  if (version == 3)
   {
-    ERROR ("bind plugin: xmlXPathEvalExpression failed.");
-    return (-1);
-  }
+    view_name = (char*) xmlGetProp(node, BAD_CAST "name");
 
-  for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
-  {
-    view_name = (char *) xmlNodeListGetString (doc,
-        path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
-    if (view_name != NULL)
-      break;
-  }
+    if (view_name == NULL)
+    {
+      ERROR ("bind plugin: Could not determine view name.");
+      return (-1);
+    }
+
+    for (j = 0; j < views_num; j++)
+    {
+      if (strcasecmp (view_name, views[j].name) == 0)
+        break;
+    }
 
-  if (view_name == NULL)
+    xmlFree (view_name);
+    view_name = NULL;
+  }
+  else
   {
-    ERROR ("bind plugin: Could not determine view name.");
+    xmlXPathObject *path_obj;
+    path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
+    if (path_obj == NULL)
+    {
+      ERROR ("bind plugin: xmlXPathEvalExpression failed.");
+      return (-1);
+    }
+
+    for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
+    {
+      view_name = (char *) xmlNodeListGetString (doc,
+          path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
+      if (view_name != NULL)
+        break;
+    }
+
+    if (view_name == NULL)
+    {
+      ERROR ("bind plugin: Could not determine view name.");
+      xmlXPathFreeObject (path_obj);
+      return (-1);
+    }
+
+    for (j = 0; j < views_num; j++)
+    {
+      if (strcasecmp (view_name, views[j].name) == 0)
+        break;
+    }
+
+    xmlFree (view_name);
     xmlXPathFreeObject (path_obj);
-    return (-1);
-  }
 
-  for (j = 0; j < views_num; j++)
-  {
-    if (strcasecmp (view_name, views[j].name) == 0)
-      break;
+    view_name = NULL;
+    path_obj = NULL;
   }
 
-  xmlFree (view_name);
-  xmlXPathFreeObject (path_obj);
-
-  view_name = NULL;
-  path_obj = NULL;
 
   if (j >= views_num)
     return (0);
@@ -804,11 +937,20 @@ static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */
 
     ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-qtypes",
         view->name);
-
-    bind_parse_generic_name_value (/* xpath = */ "rdtype",
+    if (version == 3)
+    {
+      bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='resqtype']",
+        /* callback = */ bind_xml_list_callback,
+        /* user_data = */ &list_info,
+        doc, path_ctx, current_time, DS_TYPE_COUNTER);
+    }
+    else
+    {
+      bind_parse_generic_name_value (/* xpath = */ "rdtype",
         /* callback = */ bind_xml_list_callback,
         /* user_data = */ &list_info,
         doc, path_ctx, current_time, DS_TYPE_COUNTER);
+    }
   } /* }}} */
 
   if (view->resolver_stats != 0) /* {{{ */
@@ -823,11 +965,20 @@ static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */
 
     ssnprintf (plugin_instance, sizeof (plugin_instance),
         "%s-resolver_stats", view->name);
-
-    bind_parse_generic_name_value ("resstat",
-        /* callback = */ bind_xml_table_callback,
-        /* user_data = */ &table_ptr,
-        doc, path_ctx, current_time, DS_TYPE_COUNTER);
+    if (version == 3)
+    {
+      bind_parse_generic_name_attr_value_list ("counters[@type='resstats']",
+          /* callback = */ bind_xml_table_callback,
+          /* user_data = */ &table_ptr,
+          doc, path_ctx, current_time, DS_TYPE_COUNTER);
+    }
+    else
+    {
+      bind_parse_generic_name_value ("resstat",
+          /* callback = */ bind_xml_table_callback,
+          /* user_data = */ &table_ptr,
+          doc, path_ctx, current_time, DS_TYPE_COUNTER);
+    }
   } /* }}} */
 
   /* Record types in the cache */
@@ -896,28 +1047,145 @@ static int bind_xml_stats_search_views (int version, xmlDoc *doc, /* {{{ */
   return (0);
 } /* }}} int bind_xml_stats_search_views */
 
-static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
-    xmlXPathContext *xpathCtx, xmlNode *statsnode)
+static void bind_xml_stats_v3 (xmlDoc *doc, /* {{{ */
+    xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
 {
-  time_t current_time = 0;
-  int status;
+  /* XPath:     server/counters[@type='opcode']
+   * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
+   * Layout v3:
+   *   <counters type="opcode">
+   *     <counter name="A">1</counter>
+   *     :
+   *   </counters>
+   */
+  if (global_opcodes != 0)
+  {
+    list_info_ptr_t list_info =
+    {
+      /* plugin instance = */ "global-opcodes",
+      /* type = */ "dns_opcode"
+    };
+    bind_parse_generic_name_attr_value_list (/* xpath = */ "server/counters[@type='opcode']",
+      /* callback = */ bind_xml_list_callback,
+      /* user_data = */ &list_info,
+      doc, xpathCtx, current_time, DS_TYPE_COUNTER);
+  }
 
-  xpathCtx->node = statsnode;
+  /* XPath:     server/counters[@type='qtype']
+   * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
+   *            X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
+   *            SPF, TKEY, IXFR, AXFR, ANY, ..., Others
+   * Layout v3:
+   *   <counters type="opcode">
+   *     <counter name="A">1</counter>
+   *     :
+   *   </counters>
+   */
+  if (global_qtypes != 0)
+  {
+    list_info_ptr_t list_info =
+    {
+      /* plugin instance = */ "global-qtypes",
+      /* type = */ "dns_qtype"
+    };
 
-  /* TODO: Check `server/boot-time' to recognize server restarts. */
+    bind_parse_generic_name_attr_value_list (/* xpath = */ "server/counters[@type='qtype']",
+        /* callback = */ bind_xml_list_callback,
+        /* user_data = */ &list_info,
+        doc, xpathCtx, current_time, DS_TYPE_COUNTER);
+  }
 
-  status = bind_xml_read_timestamp ("server/current-time",
-      doc, xpathCtx, &current_time);
-  if (status != 0)
+  /* XPath:     server/counters[@type='nsstat']
+   * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
+   *            ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
+   *            UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
+   *            RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
+   *            QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
+   *            QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
+   *            UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
+   *            UpdateBadPrereq
+   * Layout v3:
+   *   <counters type="nsstat"
+   *     <counter name="Requestv4">1</counter>
+   *     <counter name="Requestv6">0</counter>
+   *     :
+   *   </counter>
+   */
+  if (global_server_stats)
   {
-    ERROR ("bind plugin: Reading `server/current-time' failed.");
-    return (-1);
+    translation_table_ptr_t table_ptr =
+    {
+      nsstats_translation_table,
+      nsstats_translation_table_length,
+      /* plugin_instance = */ "global-server_stats"
+    };
+
+    bind_parse_generic_name_attr_value_list ("server/counters[@type='nsstat']",
+        /* callback = */ bind_xml_table_callback,
+        /* user_data = */ &table_ptr,
+        doc, xpathCtx, current_time, DS_TYPE_COUNTER);
   }
-  DEBUG ("bind plugin: Current server time is %i.", (int) current_time);
 
-  /* XPath:     server/requests/opcode
+  /* XPath:     server/zonestats, server/zonestat, server/counters[@type='zonestat']
+   * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
+   *            SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
+   *            XfrSuccess, XfrFail
+   * Layout v3:
+   *   <counters type="zonestat"
+   *     <counter name="NotifyOutv4">0</counter>
+   *     <counter name="NotifyOutv6">0</counter>
+   *     :
+   *   </counter>
+   */
+  if (global_zone_maint_stats)
+  {
+    translation_table_ptr_t table_ptr =
+    {
+      zonestats_translation_table,
+      zonestats_translation_table_length,
+      /* plugin_instance = */ "global-zone_maint_stats"
+    };
+
+    bind_parse_generic_name_attr_value_list ("server/counters[@type='zonestat']",
+        /* callback = */ bind_xml_table_callback,
+        /* user_data = */ &table_ptr,
+        doc, xpathCtx, current_time, DS_TYPE_COUNTER);
+  }
+
+  /* XPath:     server/resstats, server/counters[@type='resstat']
+   * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
+   *            FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
+   *            Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
+   *            GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
+   * Layout v3:
+   *   <counters type="resstat"
+   *     <counter name="Queryv4">0</counter>
+   *     <counter name="Queryv6">0</counter>
+   *     :
+   *   </counter>
+   */
+  if (global_resolver_stats != 0)
+  {
+    translation_table_ptr_t table_ptr =
+    {
+      resstats_translation_table,
+      resstats_translation_table_length,
+      /* plugin_instance = */ "global-resolver_stats"
+    };
+
+    bind_parse_generic_name_attr_value_list ("server/counters[@type='resstat']",
+        /* callback = */ bind_xml_table_callback,
+        /* user_data = */ &table_ptr,
+        doc, xpathCtx, current_time, DS_TYPE_COUNTER);
+  }
+} /* }}} bind_xml_stats_v3 */
+
+static void bind_xml_stats_v1_v2 (int version, xmlDoc *doc, /* {{{ */
+    xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
+{
+  /* XPath:     server/requests/opcode, server/counters[@type='opcode']
    * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
-   * Layout:
+   * Layout V1 and V2:
    *   <opcode>
    *     <name>A</name>
    *     <counter>1</counter>
@@ -938,11 +1206,11 @@ static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
         doc, xpathCtx, current_time, DS_TYPE_COUNTER);
   }
 
-  /* XPath:     server/queries-in/rdtype
+  /* XPath:     server/queries-in/rdtype, server/counters[@type='qtype']
    * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
    *            X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
    *            SPF, TKEY, IXFR, AXFR, ANY, ..., Others
-   * Layout:
+   * Layout v1 or v2:
    *   <rdtype>
    *     <name>A</name>
    *     <counter>1</counter>
@@ -962,8 +1230,8 @@ static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
         /* user_data = */ &list_info,
         doc, xpathCtx, current_time, DS_TYPE_COUNTER);
   }
-  
-  /* XPath:     server/nsstats, server/nsstat
+
+  /* XPath:     server/nsstats, server/nsstat, server/counters[@type='nsstat']
    * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
    *            ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
    *            UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
@@ -992,7 +1260,7 @@ static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
   if (global_server_stats)
   {
     translation_table_ptr_t table_ptr =
-    { 
+    {
       nsstats_translation_table,
       nsstats_translation_table_length,
       /* plugin_instance = */ "global-server_stats"
@@ -1014,7 +1282,7 @@ static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
     }
   }
 
-  /* XPath:     server/zonestats, server/zonestat
+  /* XPath:     server/zonestats, server/zonestat, server/counters[@type='zonestat']
    * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
    *            SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
    *            XfrSuccess, XfrFail
@@ -1038,7 +1306,7 @@ static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
   if (global_zone_maint_stats)
   {
     translation_table_ptr_t table_ptr =
-    { 
+    {
       zonestats_translation_table,
       zonestats_translation_table_length,
       /* plugin_instance = */ "global-zone_maint_stats"
@@ -1060,7 +1328,7 @@ static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
     }
   }
 
-  /* XPath:     server/resstats
+  /* XPath:     server/resstats, server/counters[@type='resstat']
    * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
    *            FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
    *            Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
@@ -1085,7 +1353,7 @@ static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
   if (global_resolver_stats != 0)
   {
     translation_table_ptr_t table_ptr =
-    { 
+    {
       resstats_translation_table,
       resstats_translation_table_length,
       /* plugin_instance = */ "global-resolver_stats"
@@ -1106,10 +1374,39 @@ static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
           doc, xpathCtx, current_time, DS_TYPE_COUNTER);
     }
   }
+} /* }}} bind_xml_stats_v1_v2 */
+
+static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
+    xmlXPathContext *xpathCtx, xmlNode *statsnode)
+{
+  time_t current_time = 0;
+  int status;
+
+  xpathCtx->node = statsnode;
+
+  /* TODO: Check `server/boot-time' to recognize server restarts. */
+
+  status = bind_xml_read_timestamp ("server/current-time",
+      doc, xpathCtx, &current_time);
+  if (status != 0)
+  {
+    ERROR ("bind plugin: Reading `server/current-time' failed.");
+    return (-1);
+  }
+  DEBUG ("bind plugin: Current server time is %i.", (int) current_time);
+
+  if (version == 3)
+  {
+    bind_xml_stats_v3(doc, xpathCtx, statsnode, current_time);
+  }
+  else
+  {
+    bind_xml_stats_v1_v2(version, doc, xpathCtx, statsnode, current_time);
+  }
 
   /* XPath:  memory/summary
    * Variables: TotalUse, InUse, BlockSize, ContextSize, Lost
-   * Layout: v2:
+   * Layout: v2 and v3:
    *   <summary>
    *     <TotalUse>6587096</TotalUse>
    *     <InUse>1345424</InUse>
@@ -1163,6 +1460,64 @@ static int bind_xml (const char *data) /* {{{ */
     return (-1);
   }
 
+  //
+  // version 3.* of statistics XML (since BIND9.9)
+  //
+
+  xpathObj = xmlXPathEvalExpression (BAD_CAST "/statistics", xpathCtx);
+  if (xpathObj == NULL || xpathObj->nodesetval == NULL || xpathObj->nodesetval->nodeNr == 0)
+  {
+    DEBUG ("bind plugin: Statistics appears not to be v3");
+    // we will fallback to v1 or v2 detection
+    if (xpathObj != NULL) { xmlXPathFreeObject (xpathObj); }
+  }
+  else
+  {
+    for (i = 0; i < xpathObj->nodesetval->nodeNr; i++)
+    {
+      xmlNode *node;
+      char *attr_version;
+
+      node = xpathObj->nodesetval->nodeTab[i];
+      assert (node != NULL);
+
+      attr_version = (char *) xmlGetProp (node, BAD_CAST "version");
+      if (attr_version == NULL)
+      {
+        NOTICE ("bind plugin: Found <statistics> tag doesn't have a "
+            "`version' attribute.");
+        continue;
+      }
+      DEBUG ("bind plugin: Found: <statistics version=\"%s\">", attr_version);
+
+      if (strncmp ("3.", attr_version, strlen ("3.")) != 0)
+      {
+        /* TODO: Use the complaint mechanism here. */
+        NOTICE ("bind plugin: Found <statistics> tag with version `%s'. "
+            "Unfortunately I have no clue how to parse that. "
+            "Please open a bug report for this.", attr_version);
+        xmlFree (attr_version);
+        continue;
+      }
+      ret = bind_xml_stats (3, doc, xpathCtx, node);
+
+      xmlFree (attr_version);
+      /* One <statistics> node ought to be enough. */
+      break;
+    }
+
+    // we are finished, early-return
+    xmlXPathFreeObject (xpathObj);
+    xmlXPathFreeContext (xpathCtx);
+    xmlFreeDoc (doc);
+
+    return (ret);
+  }
+
+  //
+  // versions 1.* or 2.* of statistics XML
+  //
+
   xpathObj = xmlXPathEvalExpression (BAD_CAST "/isc/bind/statistics", xpathCtx);
   if (xpathObj == NULL)
   {
@@ -1371,6 +1726,8 @@ static int bind_config (oconfig_item_t *ci) /* {{{ */
       bind_config_add_view (child);
     else if (strcasecmp ("ParseTime", child->key) == 0)
       cf_util_get_boolean (child, &config_parse_time);
+    else if (strcasecmp ("Timeout", child->key) == 0)
+      cf_util_get_int (child, &timeout);
     else
     {
       WARNING ("bind plugin: Unknown configuration option "
@@ -1395,11 +1752,16 @@ 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);
   curl_easy_setopt (curl, CURLOPT_MAXREDIRS, 50L);
+#ifdef HAVE_CURLOPT_TIMEOUT_MS
+  curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, (timeout >= 0) ?
+      (long) timeout : CDTIME_T_TO_MS(plugin_get_interval()));
+#endif
+
 
   return (0);
 } /* }}} int bind_init */
diff --git a/src/ceph.c b/src/ceph.c
new file mode 100644 (file)
index 0000000..d928a7b
--- /dev/null
@@ -0,0 +1,1581 @@
+/**
+ * collectd - src/ceph.c
+ * Copyright (C) 2011  New Dream Network
+ *
+ * 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
+ *
+ * Authors:
+ *   Colin McCabe <cmccabe@alumni.cmu.edu>
+ *   Dennis Zou <yunzou@cisco.com>
+ *   Dan Ryder <daryder@cisco.com>
+ **/
+
+#define _DEFAULT_SOURCE
+#define _BSD_SOURCE
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+#include <arpa/inet.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <yajl/yajl_parse.h>
+#if HAVE_YAJL_YAJL_VERSION_H
+#include <yajl/yajl_version.h>
+#endif
+
+#include <limits.h>
+#include <poll.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/un.h>
+#include <unistd.h>
+#include <math.h>
+#include <inttypes.h>
+
+#define RETRY_AVGCOUNT -1
+
+#if defined(YAJL_MAJOR) && (YAJL_MAJOR > 1)
+# define HAVE_YAJL_V2 1
+#endif
+
+#define RETRY_ON_EINTR(ret, expr) \
+    while(1) { \
+        ret = expr; \
+        if(ret >= 0) \
+            break; \
+        ret = -errno; \
+        if(ret != -EINTR) \
+            break; \
+    }
+
+/** Timeout interval in seconds */
+#define CEPH_TIMEOUT_INTERVAL 1
+
+/** Maximum path length for a UNIX domain socket on this system */
+#define UNIX_DOMAIN_SOCK_PATH_MAX (sizeof(((struct sockaddr_un*)0)->sun_path))
+
+/** Yajl callback returns */
+#define CEPH_CB_CONTINUE 1
+#define CEPH_CB_ABORT 0
+
+#if HAVE_YAJL_V2
+typedef size_t yajl_len_t;
+#else
+typedef unsigned int yajl_len_t;
+#endif
+
+/** Number of types for ceph defined in types.db */
+#define CEPH_DSET_TYPES_NUM 3
+/** ceph types enum */
+enum ceph_dset_type_d
+{
+    DSET_LATENCY = 0,
+    DSET_BYTES = 1,
+    DSET_RATE = 2,
+    DSET_TYPE_UNFOUND = 1000
+};
+
+/** Valid types for ceph defined in types.db */
+const char * ceph_dset_types [CEPH_DSET_TYPES_NUM] =
+                                   {"ceph_latency", "ceph_bytes", "ceph_rate"};
+
+/******* ceph_daemon *******/
+struct ceph_daemon
+{
+    /** Version of the admin_socket interface */
+    uint32_t version;
+    /** daemon name **/
+    char name[DATA_MAX_NAME_LEN];
+
+    /** Path to the socket that we use to talk to the ceph daemon */
+    char asok_path[UNIX_DOMAIN_SOCK_PATH_MAX];
+
+    /** Number of counters */
+    int ds_num;
+    /** Track ds types */
+    uint32_t *ds_types;
+    /** Track ds names to match with types */
+    char **ds_names;
+
+    /**
+     * Keep track of last data for latency values so we can calculate rate
+     * since last poll.
+     */
+    struct last_data **last_poll_data;
+    /** index of last poll data */
+    int last_idx;
+};
+
+/******* JSON parsing *******/
+typedef int (*node_handler_t)(void *, const char*, const char*);
+
+/** Track state and handler while parsing JSON */
+struct yajl_struct
+{
+    node_handler_t handler;
+    void * handler_arg;
+    struct {
+      char key[DATA_MAX_NAME_LEN];
+      int key_len;
+    } state[YAJL_MAX_DEPTH];
+    int depth;
+};
+typedef struct yajl_struct yajl_struct;
+
+enum perfcounter_type_d
+{
+    PERFCOUNTER_LATENCY = 0x4, PERFCOUNTER_DERIVE = 0x8,
+};
+
+/** Give user option to use default (long run = since daemon started) avg */
+static int long_run_latency_avg = 0;
+
+/**
+ * Give user option to use default type for special cases -
+ * filestore.journal_wr_bytes is currently only metric here. Ceph reports the
+ * type as a sum/count pair and will calculate it the same as a latency value.
+ * All other "bytes" metrics (excluding the used/capacity bytes for the OSD)
+ * use the DERIVE type. Unless user specifies to use given type, convert this
+ * metric to use DERIVE.
+ */
+static int convert_special_metrics = 1;
+
+/** Array of daemons to monitor */
+static struct ceph_daemon **g_daemons = NULL;
+
+/** Number of elements in g_daemons */
+static int g_num_daemons = 0;
+
+/**
+ * A set of data that we build up in memory while parsing the JSON.
+ */
+struct values_tmp
+{
+    /** ceph daemon we are processing data for*/
+    struct ceph_daemon *d;
+    /** track avgcount across counters for avgcount/sum latency pairs */
+    uint64_t avgcount;
+    /** current index of counters - used to get type of counter */
+    int index;
+    /** do we already have an avgcount for latency pair */
+    int avgcount_exists;
+    /**
+     * similar to index, but current index of latency type counters -
+     * used to get last poll data of counter
+     */
+    int latency_index;
+    /**
+     * values list - maintain across counters since
+     * host/plugin/plugin instance are always the same
+     */
+    value_list_t vlist;
+};
+
+/**
+ * A set of count/sum pairs to keep track of latency types and get difference
+ * between this poll data and last poll data.
+ */
+struct last_data
+{
+    char ds_name[DATA_MAX_NAME_LEN];
+    double last_sum;
+    uint64_t last_count;
+};
+
+/******* network I/O *******/
+enum cstate_t
+{
+    CSTATE_UNCONNECTED = 0,
+    CSTATE_WRITE_REQUEST,
+    CSTATE_READ_VERSION,
+    CSTATE_READ_AMT,
+    CSTATE_READ_JSON,
+};
+
+enum request_type_t
+{
+    ASOK_REQ_VERSION = 0,
+    ASOK_REQ_DATA = 1,
+    ASOK_REQ_SCHEMA = 2,
+    ASOK_REQ_NONE = 1000,
+};
+
+struct cconn
+{
+    /** The Ceph daemon that we're talking to */
+    struct ceph_daemon *d;
+
+    /** Request type */
+    uint32_t request_type;
+
+    /** The connection state */
+    enum cstate_t state;
+
+    /** The socket we use to talk to this daemon */
+    int asok;
+
+    /** The amount of data remaining to read / write. */
+    uint32_t amt;
+
+    /** Length of the JSON to read */
+    uint32_t json_len;
+
+    /** Buffer containing JSON data */
+    unsigned char *json;
+
+    /** Keep data important to yajl processing */
+    struct yajl_struct yajl;
+};
+
+static int ceph_cb_null(void *ctx)
+{
+    return CEPH_CB_CONTINUE;
+}
+
+static int ceph_cb_boolean(void *ctx, int bool_val)
+{
+    return CEPH_CB_CONTINUE;
+}
+
+static int
+ceph_cb_number(void *ctx, const char *number_val, yajl_len_t number_len)
+{
+    yajl_struct *yajl = (yajl_struct*)ctx;
+    char buffer[number_len+1];
+    int i, latency_type = 0, result;
+    char key[128];
+
+    memcpy(buffer, number_val, number_len);
+    buffer[sizeof(buffer) - 1] = 0;
+
+    ssnprintf(key, yajl->state[0].key_len, "%s", yajl->state[0].key);
+    for(i = 1; i < yajl->depth; i++)
+    {
+        if((i == yajl->depth-1) && ((strcmp(yajl->state[i].key,"avgcount") == 0)
+                || (strcmp(yajl->state[i].key,"sum") == 0)))
+        {
+            if(convert_special_metrics)
+            {
+                /**
+                 * Special case for filestore:JournalWrBytes. For some reason,
+                 * Ceph schema encodes this as a count/sum pair while all
+                 * other "Bytes" data (excluding used/capacity bytes for OSD
+                 * space) uses a single "Derive" type. To spare further
+                 * confusion, keep this KPI as the same type of other "Bytes".
+                 * Instead of keeping an "average" or "rate", use the "sum" in
+                 * the pair and assign that to the derive value.
+                 */
+                if((strcmp(yajl->state[i-1].key, "journal_wr_bytes") == 0) &&
+                        (strcmp(yajl->state[i-2].key,"filestore") == 0) &&
+                        (strcmp(yajl->state[i].key,"avgcount") == 0))
+                {
+                    DEBUG("ceph plugin: Skipping avgcount for filestore.JournalWrBytes");
+                    yajl->depth = (yajl->depth - 1);
+                    return CEPH_CB_CONTINUE;
+                }
+            }
+            //probably a avgcount/sum pair. if not - we'll try full key later
+            latency_type = 1;
+            break;
+        }
+        strncat(key, ".", 1);
+        strncat(key, yajl->state[i].key, yajl->state[i].key_len+1);
+    }
+
+    result = yajl->handler(yajl->handler_arg, buffer, key);
+
+    if((result == RETRY_AVGCOUNT) && latency_type)
+    {
+        strncat(key, ".", 1);
+        strncat(key, yajl->state[yajl->depth-1].key,
+                yajl->state[yajl->depth-1].key_len+1);
+        result = yajl->handler(yajl->handler_arg, buffer, key);
+    }
+
+    if(result == -ENOMEM)
+    {
+        ERROR("ceph plugin: memory allocation failed");
+        return CEPH_CB_ABORT;
+    }
+
+    yajl->depth = (yajl->depth - 1);
+    return CEPH_CB_CONTINUE;
+}
+
+static int ceph_cb_string(void *ctx, const unsigned char *string_val,
+        yajl_len_t string_len)
+{
+    return CEPH_CB_CONTINUE;
+}
+
+static int ceph_cb_start_map(void *ctx)
+{
+    return CEPH_CB_CONTINUE;
+}
+
+static int
+ceph_cb_map_key(void *ctx, const unsigned char *key, yajl_len_t string_len)
+{
+    yajl_struct *yajl = (yajl_struct*)ctx;
+
+    if((yajl->depth+1)  >= YAJL_MAX_DEPTH)
+    {
+        ERROR("ceph plugin: depth exceeds max, aborting.");
+        return CEPH_CB_ABORT;
+    }
+
+    char buffer[string_len+1];
+
+    memcpy(buffer, key, string_len);
+    buffer[sizeof(buffer) - 1] = 0;
+
+    snprintf(yajl->state[yajl->depth].key, sizeof(buffer), "%s", buffer);
+    yajl->state[yajl->depth].key_len = sizeof(buffer);
+    yajl->depth = (yajl->depth + 1);
+
+    return CEPH_CB_CONTINUE;
+}
+
+static int ceph_cb_end_map(void *ctx)
+{
+    yajl_struct *yajl = (yajl_struct*)ctx;
+
+    yajl->depth = (yajl->depth - 1);
+    return CEPH_CB_CONTINUE;
+}
+
+static int ceph_cb_start_array(void *ctx)
+{
+    return CEPH_CB_CONTINUE;
+}
+
+static int ceph_cb_end_array(void *ctx)
+{
+    return CEPH_CB_CONTINUE;
+}
+
+static yajl_callbacks callbacks = {
+        ceph_cb_null,
+        ceph_cb_boolean,
+        NULL,
+        NULL,
+        ceph_cb_number,
+        ceph_cb_string,
+        ceph_cb_start_map,
+        ceph_cb_map_key,
+        ceph_cb_end_map,
+        ceph_cb_start_array,
+        ceph_cb_end_array
+};
+
+static void ceph_daemon_print(const struct ceph_daemon *d)
+{
+    DEBUG("ceph plugin: name=%s, asok_path=%s", d->name, d->asok_path);
+}
+
+static void ceph_daemons_print(void)
+{
+    int i;
+    for(i = 0; i < g_num_daemons; ++i)
+    {
+        ceph_daemon_print(g_daemons[i]);
+    }
+}
+
+static void ceph_daemon_free(struct ceph_daemon *d)
+{
+    int i = 0;
+    for(; i < d->last_idx; i++)
+    {
+        sfree(d->last_poll_data[i]);
+    }
+    sfree(d->last_poll_data);
+    d->last_poll_data = NULL;
+    d->last_idx = 0;
+    for(i = 0; i < d->ds_num; i++)
+    {
+        sfree(d->ds_names[i]);
+    }
+    sfree(d->ds_types);
+    sfree(d->ds_names);
+    sfree(d);
+}
+
+/**
+ * Compact ds name by removing special characters and trimming length to
+ * DATA_MAX_NAME_LEN if necessary
+ */
+static void compact_ds_name(char *source, char *dest)
+{
+    int keys_num = 0, i;
+    char *save_ptr = NULL, *tmp_ptr = source;
+    char *keys[16];
+    char len_str[3];
+    char tmp[DATA_MAX_NAME_LEN];
+    size_t key_chars_remaining = (DATA_MAX_NAME_LEN-1);
+    int reserved = 0;
+    int offset = 0;
+    memset(tmp, 0, sizeof(tmp));
+    if(source == NULL || dest == NULL || source[0] == '\0' || dest[0] != '\0')
+    {
+        return;
+    }
+    size_t src_len = strlen(source);
+    snprintf(len_str, sizeof(len_str), "%zu", src_len);
+    unsigned char append_status = 0x0;
+    append_status |= (source[src_len - 1] == '-') ? 0x1 : 0x0;
+    append_status |= (source[src_len - 1] == '+') ? 0x2 : 0x0;
+    while ((keys[keys_num] = strtok_r(tmp_ptr, ":_-+", &save_ptr)) != NULL)
+    {
+        tmp_ptr = NULL;
+        /** capitalize 1st char **/
+        keys[keys_num][0] = toupper(keys[keys_num][0]);
+        keys_num++;
+        if(keys_num >= 16)
+        {
+            break;
+        }
+    }
+    /** concatenate each part of source string **/
+    for(i = 0; i < keys_num; i++)
+    {
+        strncat(tmp, keys[i], key_chars_remaining);
+        key_chars_remaining -= strlen(keys[i]);
+    }
+    tmp[DATA_MAX_NAME_LEN - 1] = '\0';
+    /** to coordinate limitation of length of type_instance
+     *  we will truncate ds_name
+     *  when the its length is more than
+     *  DATA_MAX_NAME_LEN
+     */
+    if(strlen(tmp) > DATA_MAX_NAME_LEN - 1)
+    {
+        append_status |= 0x4;
+        /** we should reserve space for
+         * len_str
+         */
+        reserved += 2;
+    }
+    if(append_status & 0x1)
+    {
+        /** we should reserve space for
+         * "Minus"
+         */
+        reserved += 5;
+    }
+    if(append_status & 0x2)
+    {
+        /** we should reserve space for
+         * "Plus"
+         */
+        reserved += 4;
+    }
+    snprintf(dest, DATA_MAX_NAME_LEN - reserved, "%s", tmp);
+    offset = strlen(dest);
+    switch (append_status)
+    {
+        case 0x1:
+            memcpy(dest + offset, "Minus", 5);
+            break;
+        case 0x2:
+            memcpy(dest + offset, "Plus", 5);
+            break;
+        case 0x4:
+            memcpy(dest + offset, len_str, 2);
+            break;
+        case 0x5:
+            memcpy(dest + offset, "Minus", 5);
+            memcpy(dest + offset + 5, len_str, 2);
+            break;
+        case 0x6:
+            memcpy(dest + offset, "Plus", 4);
+            memcpy(dest + offset + 4, len_str, 2);
+            break;
+        default:
+            break;
+    }
+}
+
+/**
+ * Parse key to remove "type" if this is for schema and initiate compaction
+ */
+static int parse_keys(const char *key_str, char *ds_name)
+{
+    char *ptr, *rptr;
+    size_t ds_name_len = 0;
+    /**
+     * allow up to 100 characters before compaction - compact_ds_name will not
+     * allow more than DATA_MAX_NAME_LEN chars
+     */
+    int max_str_len = 100;
+    char tmp_ds_name[max_str_len];
+    memset(tmp_ds_name, 0, sizeof(tmp_ds_name));
+    if(ds_name == NULL || key_str == NULL ||  key_str[0] == '\0' ||
+                                                            ds_name[0] != '\0')
+    {
+        return -1;
+    }
+    if((ptr = strchr(key_str, '.')) == NULL
+            || (rptr = strrchr(key_str, '.')) == NULL)
+    {
+        memcpy(tmp_ds_name, key_str, max_str_len - 1);
+        goto compact;
+    }
+
+    ds_name_len = (rptr - ptr) > max_str_len ? max_str_len : (rptr - ptr);
+    if((ds_name_len == 0) || strncmp(rptr + 1, "type", 4))
+    { /** copy whole key **/
+        memcpy(tmp_ds_name, key_str, max_str_len - 1);
+    }
+    else
+    {/** more than two keys **/
+        memcpy(tmp_ds_name, key_str, ((rptr - key_str) > (max_str_len - 1) ?
+                (max_str_len - 1) : (rptr - key_str)));
+    }
+
+    compact: compact_ds_name(tmp_ds_name, ds_name);
+    return 0;
+}
+
+/**
+ * while parsing ceph admin socket schema, save counter name and type for later
+ * data processing
+ */
+static int ceph_daemon_add_ds_entry(struct ceph_daemon *d, const char *name,
+        int pc_type)
+{
+    uint32_t type;
+    char ds_name[DATA_MAX_NAME_LEN];
+    memset(ds_name, 0, sizeof(ds_name));
+
+    if(convert_special_metrics)
+    {
+        /**
+         * Special case for filestore:JournalWrBytes. For some reason, Ceph
+         * schema encodes this as a count/sum pair while all other "Bytes" data
+         * (excluding used/capacity bytes for OSD space) uses a single "Derive"
+         * type. To spare further confusion, keep this KPI as the same type of
+         * other "Bytes". Instead of keeping an "average" or "rate", use the
+         * "sum" in the pair and assign that to the derive value.
+         */
+        if((strcmp(name,"filestore.journal_wr_bytes.type") == 0))
+        {
+            pc_type = 10;
+        }
+    }
+
+    d->ds_names = realloc(d->ds_names, sizeof(char *) * (d->ds_num + 1));
+    if(!d->ds_names)
+    {
+        return -ENOMEM;
+    }
+
+    d->ds_types = realloc(d->ds_types, sizeof(uint32_t) * (d->ds_num + 1));
+    if(!d->ds_types)
+    {
+        return -ENOMEM;
+    }
+
+    d->ds_names[d->ds_num] = malloc(sizeof(char) * DATA_MAX_NAME_LEN);
+    if(!d->ds_names[d->ds_num])
+    {
+        return -ENOMEM;
+    }
+
+    type = (pc_type & PERFCOUNTER_DERIVE) ? DSET_RATE :
+            ((pc_type & PERFCOUNTER_LATENCY) ? DSET_LATENCY : DSET_BYTES);
+    d->ds_types[d->ds_num] = type;
+
+    if(parse_keys(name, ds_name))
+    {
+        return 1;
+    }
+
+    sstrncpy(d->ds_names[d->ds_num], ds_name, DATA_MAX_NAME_LEN -1);
+    d->ds_num = (d->ds_num + 1);
+
+    return 0;
+}
+
+/******* ceph_config *******/
+static int cc_handle_str(struct oconfig_item_s *item, char *dest, int dest_len)
+{
+    const char *val;
+    if(item->values_num != 1)
+    {
+        return -ENOTSUP;
+    }
+    if(item->values[0].type != OCONFIG_TYPE_STRING)
+    {
+        return -ENOTSUP;
+    }
+    val = item->values[0].value.string;
+    if(snprintf(dest, dest_len, "%s", val) > (dest_len - 1))
+    {
+        ERROR("ceph plugin: configuration parameter '%s' is too long.\n",
+                item->key);
+        return -ENAMETOOLONG;
+    }
+    return 0;
+}
+
+static int cc_handle_bool(struct oconfig_item_s *item, int *dest)
+{
+    if(item->values_num != 1)
+    {
+        return -ENOTSUP;
+    }
+
+    if(item->values[0].type != OCONFIG_TYPE_BOOLEAN)
+    {
+        return -ENOTSUP;
+    }
+
+    *dest = (item->values[0].value.boolean) ? 1 : 0;
+    return 0;
+}
+
+static int cc_add_daemon_config(oconfig_item_t *ci)
+{
+    int ret, i;
+    struct ceph_daemon *nd, cd;
+    struct ceph_daemon **tmp;
+    memset(&cd, 0, sizeof(struct ceph_daemon));
+
+    if((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
+    {
+        WARNING("ceph plugin: `Daemon' blocks need exactly one string "
+                "argument.");
+        return (-1);
+    }
+
+    ret = cc_handle_str(ci, cd.name, DATA_MAX_NAME_LEN);
+    if(ret)
+    {
+        return ret;
+    }
+
+    for(i=0; i < ci->children_num; i++)
+    {
+        oconfig_item_t *child = ci->children + i;
+
+        if(strcasecmp("SocketPath", child->key) == 0)
+        {
+            ret = cc_handle_str(child, cd.asok_path, sizeof(cd.asok_path));
+            if(ret)
+            {
+                return ret;
+            }
+        }
+        else
+        {
+            WARNING("ceph plugin: ignoring unknown option %s", child->key);
+        }
+    }
+    if(cd.name[0] == '\0')
+    {
+        ERROR("ceph plugin: you must configure a daemon name.\n");
+        return -EINVAL;
+    }
+    else if(cd.asok_path[0] == '\0')
+    {
+        ERROR("ceph plugin(name=%s): you must configure an administrative "
+        "socket path.\n", cd.name);
+        return -EINVAL;
+    }
+    else if(!((cd.asok_path[0] == '/') ||
+            (cd.asok_path[0] == '.' && cd.asok_path[1] == '/')))
+    {
+        ERROR("ceph plugin(name=%s): administrative socket paths must begin "
+                "with '/' or './' Can't parse: '%s'\n", cd.name, cd.asok_path);
+        return -EINVAL;
+    }
+
+    tmp = realloc(g_daemons, (g_num_daemons+1) * sizeof(*g_daemons));
+    if(tmp == NULL)
+    {
+        /* The positive return value here indicates that this is a
+         * runtime error, not a configuration error.  */
+        return ENOMEM;
+    }
+    g_daemons = tmp;
+
+    nd = malloc(sizeof(*nd));
+    if(!nd)
+    {
+        return ENOMEM;
+    }
+    memcpy(nd, &cd, sizeof(*nd));
+    g_daemons[g_num_daemons++] = nd;
+    return 0;
+}
+
+static int ceph_config(oconfig_item_t *ci)
+{
+    int ret, i;
+
+    for(i = 0; i < ci->children_num; ++i)
+    {
+        oconfig_item_t *child = ci->children + i;
+        if(strcasecmp("Daemon", child->key) == 0)
+        {
+            ret = cc_add_daemon_config(child);
+            if(ret == ENOMEM)
+            {
+                ERROR("ceph plugin: Couldn't allocate memory");
+                return ret;
+            }
+            else if(ret)
+            {
+                //process other daemons and ignore this one
+                continue;
+            }
+        }
+        else if(strcasecmp("LongRunAvgLatency", child->key) == 0)
+        {
+            ret = cc_handle_bool(child, &long_run_latency_avg);
+            if(ret)
+            {
+                return ret;
+            }
+        }
+        else if(strcasecmp("ConvertSpecialMetricTypes", child->key) == 0)
+        {
+            ret = cc_handle_bool(child, &convert_special_metrics);
+            if(ret)
+            {
+                return ret;
+            }
+        }
+        else
+        {
+            WARNING("ceph plugin: ignoring unknown option %s", child->key);
+        }
+    }
+    return 0;
+}
+
+/**
+ * Parse JSON and get error message if present
+ */
+static int
+traverse_json(const unsigned char *json, uint32_t json_len, yajl_handle hand)
+{
+    yajl_status status = yajl_parse(hand, json, json_len);
+    unsigned char *msg;
+
+    switch(status)
+    {
+        case yajl_status_error:
+            msg = yajl_get_error(hand, /* verbose = */ 1,
+                                       /* jsonText = */ (unsigned char *) json,
+                                                      (unsigned int) json_len);
+            ERROR ("ceph plugin: yajl_parse failed: %s", msg);
+            yajl_free_error(hand, msg);
+            return 1;
+        case yajl_status_client_canceled:
+            return 1;
+        default:
+            return 0;
+    }
+}
+
+/**
+ * Add entry for each counter while parsing schema
+ */
+static int
+node_handler_define_schema(void *arg, const char *val, const char *key)
+{
+    struct ceph_daemon *d = (struct ceph_daemon *) arg;
+    int pc_type;
+    pc_type = atoi(val);
+    return ceph_daemon_add_ds_entry(d, key, pc_type);
+}
+
+/**
+ * Latency counter does not yet have an entry in last poll data - add it.
+ */
+static int add_last(struct ceph_daemon *d, const char *ds_n, double cur_sum,
+        uint64_t cur_count)
+{
+    d->last_poll_data[d->last_idx] = malloc(1 * sizeof(struct last_data));
+    if(!d->last_poll_data[d->last_idx])
+    {
+        return -ENOMEM;
+    }
+    sstrncpy(d->last_poll_data[d->last_idx]->ds_name,ds_n,
+            sizeof(d->last_poll_data[d->last_idx]->ds_name));
+    d->last_poll_data[d->last_idx]->last_sum = cur_sum;
+    d->last_poll_data[d->last_idx]->last_count = cur_count;
+    d->last_idx = (d->last_idx + 1);
+    return 0;
+}
+
+/**
+ * Update latency counter or add new entry if it doesn't exist
+ */
+static int update_last(struct ceph_daemon *d, const char *ds_n, int index,
+        double cur_sum, uint64_t cur_count)
+{
+    if((d->last_idx > index) && (strcmp(d->last_poll_data[index]->ds_name, ds_n) == 0))
+    {
+        d->last_poll_data[index]->last_sum = cur_sum;
+        d->last_poll_data[index]->last_count = cur_count;
+        return 0;
+    }
+
+    if(!d->last_poll_data)
+    {
+        d->last_poll_data = malloc(1 * sizeof(struct last_data *));
+        if(!d->last_poll_data)
+        {
+            return -ENOMEM;
+        }
+    }
+    else
+    {
+        struct last_data **tmp_last = realloc(d->last_poll_data,
+                ((d->last_idx+1) * sizeof(struct last_data *)));
+        if(!tmp_last)
+        {
+            return -ENOMEM;
+        }
+        d->last_poll_data = tmp_last;
+    }
+    return add_last(d, ds_n, cur_sum, cur_count);
+}
+
+/**
+ * If using index guess failed (shouldn't happen, but possible if counters
+ * get rearranged), resort to searching for counter name
+ */
+static int backup_search_for_last_avg(struct ceph_daemon *d, const char *ds_n)
+{
+    int i = 0;
+    for(; i < d->last_idx; i++)
+    {
+        if(strcmp(d->last_poll_data[i]->ds_name, ds_n) == 0)
+        {
+            return i;
+        }
+    }
+    return -1;
+}
+
+/**
+ * Calculate average b/t current data and last poll data
+ * if last poll data exists
+ */
+static double get_last_avg(struct ceph_daemon *d, const char *ds_n, int index,
+        double cur_sum, uint64_t cur_count)
+{
+    double result = -1.1, sum_delt = 0.0;
+    uint64_t count_delt = 0;
+    int tmp_index = 0;
+    if(d->last_idx > index)
+    {
+        if(strcmp(d->last_poll_data[index]->ds_name, ds_n) == 0)
+        {
+            tmp_index = index;
+        }
+        //test previous index
+        else if((index > 0) && (strcmp(d->last_poll_data[index-1]->ds_name, ds_n) == 0))
+        {
+            tmp_index = (index - 1);
+        }
+        else
+        {
+            tmp_index = backup_search_for_last_avg(d, ds_n);
+        }
+
+        if((tmp_index > -1) && (cur_count > d->last_poll_data[tmp_index]->last_count))
+        {
+            sum_delt = (cur_sum - d->last_poll_data[tmp_index]->last_sum);
+            count_delt = (cur_count - d->last_poll_data[tmp_index]->last_count);
+            result = (sum_delt / count_delt);
+        }
+    }
+
+    if(result == -1.1)
+    {
+        result = NAN;
+    }
+    if(update_last(d, ds_n, tmp_index, cur_sum, cur_count) == -ENOMEM)
+    {
+        return -ENOMEM;
+    }
+    return result;
+}
+
+/**
+ * If using index guess failed, resort to searching for counter name
+ */
+static uint32_t backup_search_for_type(struct ceph_daemon *d, char *ds_name)
+{
+    int idx = 0;
+    for(; idx < d->ds_num; idx++)
+    {
+        if(strcmp(d->ds_names[idx], ds_name) == 0)
+        {
+            return d->ds_types[idx];
+        }
+    }
+    return DSET_TYPE_UNFOUND;
+}
+
+/**
+ * Process counter data and dispatch values
+ */
+static int node_handler_fetch_data(void *arg, const char *val, const char *key)
+{
+    value_t uv;
+    double tmp_d;
+    uint64_t tmp_u;
+    struct values_tmp *vtmp = (struct values_tmp*) arg;
+    uint32_t type = DSET_TYPE_UNFOUND;
+    int index = vtmp->index;
+
+    char ds_name[DATA_MAX_NAME_LEN];
+    memset(ds_name, 0, sizeof(ds_name));
+
+    if(parse_keys(key, ds_name))
+    {
+        return 1;
+    }
+
+    if(index >= vtmp->d->ds_num)
+    {
+        //don't overflow bounds of array
+        index = (vtmp->d->ds_num - 1);
+    }
+
+    /**
+     * counters should remain in same order we parsed schema... we maintain the
+     * index variable to keep track of current point in list of counters. first
+     * use index to guess point in array for retrieving type. if that doesn't
+     * work, use the old way to get the counter type
+     */
+    if(strcmp(ds_name, vtmp->d->ds_names[index]) == 0)
+    {
+        //found match
+        type = vtmp->d->ds_types[index];
+    }
+    else if((index > 0) && (strcmp(ds_name, vtmp->d->ds_names[index-1]) == 0))
+    {
+        //try previous key
+        type = vtmp->d->ds_types[index-1];
+    }
+
+    if(type == DSET_TYPE_UNFOUND)
+    {
+        //couldn't find right type by guessing, check the old way
+        type = backup_search_for_type(vtmp->d, ds_name);
+    }
+
+    switch(type)
+    {
+        case DSET_LATENCY:
+            if(vtmp->avgcount_exists == -1)
+            {
+                sscanf(val, "%" PRIu64, &vtmp->avgcount);
+                vtmp->avgcount_exists = 0;
+                //return after saving avgcount - don't dispatch value
+                //until latency calculation
+                return 0;
+            }
+            else
+            {
+                double sum, result;
+                sscanf(val, "%lf", &sum);
+
+                if(vtmp->avgcount == 0)
+                {
+                    vtmp->avgcount = 1;
+                }
+
+                /** User wants latency values as long run avg */
+                if(long_run_latency_avg)
+                {
+                    result = (sum / vtmp->avgcount);
+                }
+                else
+                {
+                    result = get_last_avg(vtmp->d, ds_name, vtmp->latency_index, sum, vtmp->avgcount);
+                    if(result == -ENOMEM)
+                    {
+                        return -ENOMEM;
+                    }
+                }
+
+                uv.gauge = result;
+                vtmp->avgcount_exists = -1;
+                vtmp->latency_index = (vtmp->latency_index + 1);
+            }
+            break;
+        case DSET_BYTES:
+            sscanf(val, "%lf", &tmp_d);
+            uv.gauge = tmp_d;
+            break;
+        case DSET_RATE:
+            sscanf(val, "%" PRIu64, &tmp_u);
+            uv.derive = tmp_u;
+            break;
+        case DSET_TYPE_UNFOUND:
+        default:
+            ERROR("ceph plugin: ds %s was not properly initialized.", ds_name);
+            return -1;
+    }
+
+    sstrncpy(vtmp->vlist.type, ceph_dset_types[type], sizeof(vtmp->vlist.type));
+    sstrncpy(vtmp->vlist.type_instance, ds_name, sizeof(vtmp->vlist.type_instance));
+    vtmp->vlist.values = &uv;
+    vtmp->vlist.values_len = 1;
+
+    vtmp->index = (vtmp->index + 1);
+    plugin_dispatch_values(&vtmp->vlist);
+
+    return 0;
+}
+
+static int cconn_connect(struct cconn *io)
+{
+    struct sockaddr_un address;
+    int flags, fd, err;
+    if(io->state != CSTATE_UNCONNECTED)
+    {
+        ERROR("ceph plugin: cconn_connect: io->state != CSTATE_UNCONNECTED");
+        return -EDOM;
+    }
+    fd = socket(PF_UNIX, SOCK_STREAM, 0);
+    if(fd < 0)
+    {
+        int err = -errno;
+        ERROR("ceph plugin: cconn_connect: socket(PF_UNIX, SOCK_STREAM, 0) "
+            "failed: error %d", err);
+        return err;
+    }
+    memset(&address, 0, sizeof(struct sockaddr_un));
+    address.sun_family = AF_UNIX;
+    snprintf(address.sun_path, sizeof(address.sun_path), "%s",
+            io->d->asok_path);
+    RETRY_ON_EINTR(err,
+        connect(fd, (struct sockaddr *) &address, sizeof(struct sockaddr_un)));
+    if(err < 0)
+    {
+        ERROR("ceph plugin: cconn_connect: connect(%d) failed: error %d",
+            fd, err);
+        return err;
+    }
+
+    flags = fcntl(fd, F_GETFL, 0);
+    if(fcntl(fd, F_SETFL, flags | O_NONBLOCK) != 0)
+    {
+        err = -errno;
+        ERROR("ceph plugin: cconn_connect: fcntl(%d, O_NONBLOCK) error %d",
+            fd, err);
+        return err;
+    }
+    io->asok = fd;
+    io->state = CSTATE_WRITE_REQUEST;
+    io->amt = 0;
+    io->json_len = 0;
+    io->json = NULL;
+    return 0;
+}
+
+static void cconn_close(struct cconn *io)
+{
+    io->state = CSTATE_UNCONNECTED;
+    if(io->asok != -1)
+    {
+        int res;
+        RETRY_ON_EINTR(res, close(io->asok));
+    }
+    io->asok = -1;
+    io->amt = 0;
+    io->json_len = 0;
+    sfree(io->json);
+    io->json = NULL;
+}
+
+/* Process incoming JSON counter data */
+static int
+cconn_process_data(struct cconn *io, yajl_struct *yajl, yajl_handle hand)
+{
+    int ret;
+    struct values_tmp *vtmp = calloc(1, sizeof(struct values_tmp) * 1);
+    if(!vtmp)
+    {
+        return -ENOMEM;
+    }
+
+    vtmp->vlist = (value_list_t)VALUE_LIST_INIT;
+    sstrncpy(vtmp->vlist.host, hostname_g, sizeof(vtmp->vlist.host));
+    sstrncpy(vtmp->vlist.plugin, "ceph", sizeof(vtmp->vlist.plugin));
+    sstrncpy(vtmp->vlist.plugin_instance, io->d->name, sizeof(vtmp->vlist.plugin_instance));
+
+    vtmp->d = io->d;
+    vtmp->avgcount_exists = -1;
+    vtmp->latency_index = 0;
+    vtmp->index = 0;
+    yajl->handler_arg = vtmp;
+    ret = traverse_json(io->json, io->json_len, hand);
+    sfree(vtmp);
+    return ret;
+}
+
+/**
+ * Initiate JSON parsing and print error if one occurs
+ */
+static int cconn_process_json(struct cconn *io)
+{
+    if((io->request_type != ASOK_REQ_DATA) &&
+            (io->request_type != ASOK_REQ_SCHEMA))
+    {
+        return -EDOM;
+    }
+
+    int result = 1;
+    yajl_handle hand;
+    yajl_status status;
+
+    hand = yajl_alloc(&callbacks,
+#if HAVE_YAJL_V2
+      /* alloc funcs = */ NULL,
+#else
+      /* alloc funcs = */ NULL, NULL,
+#endif
+      /* context = */ (void *)(&io->yajl));
+
+    if(!hand)
+    {
+        ERROR ("ceph plugin: yajl_alloc failed.");
+        return ENOMEM;
+    }
+
+    io->yajl.depth = 0;
+
+    switch(io->request_type)
+    {
+        case ASOK_REQ_DATA:
+            io->yajl.handler = node_handler_fetch_data;
+            result = cconn_process_data(io, &io->yajl, hand);
+            break;
+        case ASOK_REQ_SCHEMA:
+            //init daemon specific variables
+            io->d->ds_num = 0;
+            io->d->last_idx = 0;
+            io->d->last_poll_data = NULL;
+            io->yajl.handler = node_handler_define_schema;
+            io->yajl.handler_arg = io->d;
+            result = traverse_json(io->json, io->json_len, hand);
+            break;
+    }
+
+    if(result)
+    {
+        goto done;
+    }
+
+#if HAVE_YAJL_V2
+    status = yajl_complete_parse(hand);
+#else
+    status = yajl_parse_complete(hand);
+#endif
+
+    if (status != yajl_status_ok)
+    {
+      unsigned char *errmsg = yajl_get_error (hand, /* verbose = */ 0,
+          /* jsonText = */ NULL, /* jsonTextLen = */ 0);
+      ERROR ("ceph plugin: yajl_parse_complete failed: %s",
+          (char *) errmsg);
+      yajl_free_error (hand, errmsg);
+      yajl_free (hand);
+      return 1;
+    }
+
+    done:
+    yajl_free (hand);
+    return result;
+}
+
+static int cconn_validate_revents(struct cconn *io, int revents)
+{
+    if(revents & POLLERR)
+    {
+        ERROR("ceph plugin: cconn_validate_revents(name=%s): got POLLERR",
+            io->d->name);
+        return -EIO;
+    }
+    switch (io->state)
+    {
+        case CSTATE_WRITE_REQUEST:
+            return (revents & POLLOUT) ? 0 : -EINVAL;
+        case CSTATE_READ_VERSION:
+        case CSTATE_READ_AMT:
+        case CSTATE_READ_JSON:
+            return (revents & POLLIN) ? 0 : -EINVAL;
+        default:
+            ERROR("ceph plugin: cconn_validate_revents(name=%s) got to "
+                "illegal state on line %d", io->d->name, __LINE__);
+            return -EDOM;
+    }
+}
+
+/** Handle a network event for a connection */
+static int cconn_handle_event(struct cconn *io)
+{
+    int ret;
+    switch (io->state)
+    {
+        case CSTATE_UNCONNECTED:
+            ERROR("ceph plugin: cconn_handle_event(name=%s) got to illegal "
+                "state on line %d", io->d->name, __LINE__);
+
+            return -EDOM;
+        case CSTATE_WRITE_REQUEST:
+        {
+            char cmd[32];
+            snprintf(cmd, sizeof(cmd), "%s%d%s", "{ \"prefix\": \"",
+                    io->request_type, "\" }\n");
+            size_t cmd_len = strlen(cmd);
+            RETRY_ON_EINTR(ret,
+                  write(io->asok, ((char*)&cmd) + io->amt, cmd_len - io->amt));
+            DEBUG("ceph plugin: cconn_handle_event(name=%s,state=%d,amt=%d,ret=%d)",
+                    io->d->name, io->state, io->amt, ret);
+            if(ret < 0)
+            {
+                return ret;
+            }
+            io->amt += ret;
+            if(io->amt >= cmd_len)
+            {
+                io->amt = 0;
+                switch (io->request_type)
+                {
+                    case ASOK_REQ_VERSION:
+                        io->state = CSTATE_READ_VERSION;
+                        break;
+                    default:
+                        io->state = CSTATE_READ_AMT;
+                        break;
+                }
+            }
+            return 0;
+        }
+        case CSTATE_READ_VERSION:
+        {
+            RETRY_ON_EINTR(ret,
+                    read(io->asok, ((char*)(&io->d->version)) + io->amt,
+                            sizeof(io->d->version) - io->amt));
+            DEBUG("ceph plugin: cconn_handle_event(name=%s,state=%d,ret=%d)",
+                    io->d->name, io->state, ret);
+            if(ret < 0)
+            {
+                return ret;
+            }
+            io->amt += ret;
+            if(io->amt >= sizeof(io->d->version))
+            {
+                io->d->version = ntohl(io->d->version);
+                if(io->d->version != 1)
+                {
+                    ERROR("ceph plugin: cconn_handle_event(name=%s) not "
+                        "expecting version %d!", io->d->name, io->d->version);
+                    return -ENOTSUP;
+                }
+                DEBUG("ceph plugin: cconn_handle_event(name=%s): identified as "
+                        "version %d", io->d->name, io->d->version);
+                io->amt = 0;
+                cconn_close(io);
+                io->request_type = ASOK_REQ_SCHEMA;
+            }
+            return 0;
+        }
+        case CSTATE_READ_AMT:
+        {
+            RETRY_ON_EINTR(ret,
+                    read(io->asok, ((char*)(&io->json_len)) + io->amt,
+                            sizeof(io->json_len) - io->amt));
+            DEBUG("ceph plugin: cconn_handle_event(name=%s,state=%d,ret=%d)",
+                    io->d->name, io->state, ret);
+            if(ret < 0)
+            {
+                return ret;
+            }
+            io->amt += ret;
+            if(io->amt >= sizeof(io->json_len))
+            {
+                io->json_len = ntohl(io->json_len);
+                io->amt = 0;
+                io->state = CSTATE_READ_JSON;
+                io->json = calloc(1, io->json_len + 1);
+                if(!io->json)
+                {
+                    ERROR("ceph plugin: error callocing io->json");
+                    return -ENOMEM;
+                }
+            }
+            return 0;
+        }
+        case CSTATE_READ_JSON:
+        {
+            RETRY_ON_EINTR(ret,
+                   read(io->asok, io->json + io->amt, io->json_len - io->amt));
+            DEBUG("ceph plugin: cconn_handle_event(name=%s,state=%d,ret=%d)",
+                    io->d->name, io->state, ret);
+            if(ret < 0)
+            {
+                return ret;
+            }
+            io->amt += ret;
+            if(io->amt >= io->json_len)
+            {
+                ret = cconn_process_json(io);
+                if(ret)
+                {
+                    return ret;
+                }
+                cconn_close(io);
+                io->request_type = ASOK_REQ_NONE;
+            }
+            return 0;
+        }
+        default:
+            ERROR("ceph plugin: cconn_handle_event(name=%s) got to illegal "
+                "state on line %d", io->d->name, __LINE__);
+            return -EDOM;
+    }
+}
+
+static int cconn_prepare(struct cconn *io, struct pollfd* fds)
+{
+    int ret;
+    if(io->request_type == ASOK_REQ_NONE)
+    {
+        /* The request has already been serviced. */
+        return 0;
+    }
+    else if((io->request_type == ASOK_REQ_DATA) && (io->d->ds_num == 0))
+    {
+        /* If there are no counters to report on, don't bother
+         * connecting */
+        return 0;
+    }
+
+    switch (io->state)
+    {
+        case CSTATE_UNCONNECTED:
+            ret = cconn_connect(io);
+            if(ret > 0)
+            {
+                return -ret;
+            }
+            else if(ret < 0)
+            {
+                return ret;
+            }
+            fds->fd = io->asok;
+            fds->events = POLLOUT;
+            return 1;
+        case CSTATE_WRITE_REQUEST:
+            fds->fd = io->asok;
+            fds->events = POLLOUT;
+            return 1;
+        case CSTATE_READ_VERSION:
+        case CSTATE_READ_AMT:
+        case CSTATE_READ_JSON:
+            fds->fd = io->asok;
+            fds->events = POLLIN;
+            return 1;
+        default:
+            ERROR("ceph plugin: cconn_prepare(name=%s) got to illegal state "
+                "on line %d", io->d->name, __LINE__);
+            return -EDOM;
+    }
+}
+
+/** Returns the difference between two struct timevals in milliseconds.
+ * On overflow, we return max/min int.
+ */
+static int milli_diff(const struct timeval *t1, const struct timeval *t2)
+{
+    int64_t ret;
+    int sec_diff = t1->tv_sec - t2->tv_sec;
+    int usec_diff = t1->tv_usec - t2->tv_usec;
+    ret = usec_diff / 1000;
+    ret += (sec_diff * 1000);
+    return (ret > INT_MAX) ? INT_MAX : ((ret < INT_MIN) ? INT_MIN : (int)ret);
+}
+
+/** This handles the actual network I/O to talk to the Ceph daemons.
+ */
+static int cconn_main_loop(uint32_t request_type)
+{
+    int i, ret, some_unreachable = 0;
+    struct timeval end_tv;
+    struct cconn io_array[g_num_daemons];
+
+    DEBUG("ceph plugin: entering cconn_main_loop(request_type = %d)", request_type);
+
+    /* create cconn array */
+    memset(io_array, 0, sizeof(io_array));
+    for(i = 0; i < g_num_daemons; ++i)
+    {
+        io_array[i].d = g_daemons[i];
+        io_array[i].request_type = request_type;
+        io_array[i].state = CSTATE_UNCONNECTED;
+    }
+
+    /** Calculate the time at which we should give up */
+    gettimeofday(&end_tv, NULL);
+    end_tv.tv_sec += CEPH_TIMEOUT_INTERVAL;
+
+    while (1)
+    {
+        int nfds, diff;
+        struct timeval tv;
+        struct cconn *polled_io_array[g_num_daemons];
+        struct pollfd fds[g_num_daemons];
+        memset(fds, 0, sizeof(fds));
+        nfds = 0;
+        for(i = 0; i < g_num_daemons; ++i)
+        {
+            struct cconn *io = io_array + i;
+            ret = cconn_prepare(io, fds + nfds);
+            if(ret < 0)
+            {
+                WARNING("ceph plugin: cconn_prepare(name=%s,i=%d,st=%d)=%d",
+                        io->d->name, i, io->state, ret);
+                cconn_close(io);
+                io->request_type = ASOK_REQ_NONE;
+                some_unreachable = 1;
+            }
+            else if(ret == 1)
+            {
+                polled_io_array[nfds++] = io_array + i;
+            }
+        }
+        if(nfds == 0)
+        {
+            /* finished */
+            ret = 0;
+            goto done;
+        }
+        gettimeofday(&tv, NULL);
+        diff = milli_diff(&end_tv, &tv);
+        if(diff <= 0)
+        {
+            /* Timed out */
+            ret = -ETIMEDOUT;
+            WARNING("ceph plugin: cconn_main_loop: timed out.");
+            goto done;
+        }
+        RETRY_ON_EINTR(ret, poll(fds, nfds, diff));
+        if(ret < 0)
+        {
+            ERROR("ceph plugin: poll(2) error: %d", ret);
+            goto done;
+        }
+        for(i = 0; i < nfds; ++i)
+        {
+            struct cconn *io = polled_io_array[i];
+            int revents = fds[i].revents;
+            if(revents == 0)
+            {
+                /* do nothing */
+            }
+            else if(cconn_validate_revents(io, revents))
+            {
+                WARNING("ceph plugin: cconn(name=%s,i=%d,st=%d): "
+                "revents validation error: "
+                "revents=0x%08x", io->d->name, i, io->state, revents);
+                cconn_close(io);
+                io->request_type = ASOK_REQ_NONE;
+                some_unreachable = 1;
+            }
+            else
+            {
+                int ret = cconn_handle_event(io);
+                if(ret)
+                {
+                    WARNING("ceph plugin: cconn_handle_event(name=%s,"
+                    "i=%d,st=%d): error %d", io->d->name, i, io->state, ret);
+                    cconn_close(io);
+                    io->request_type = ASOK_REQ_NONE;
+                    some_unreachable = 1;
+                }
+            }
+        }
+    }
+    done: for(i = 0; i < g_num_daemons; ++i)
+    {
+        cconn_close(io_array + i);
+    }
+    if(some_unreachable)
+    {
+        DEBUG("ceph plugin: cconn_main_loop: some Ceph daemons were unreachable.");
+    }
+    else
+    {
+        DEBUG("ceph plugin: cconn_main_loop: reached all Ceph daemons :)");
+    }
+    return ret;
+}
+
+static int ceph_read(void)
+{
+    return cconn_main_loop(ASOK_REQ_DATA);
+}
+
+/******* lifecycle *******/
+static int ceph_init(void)
+{
+    int ret;
+    ceph_daemons_print();
+
+    ret = cconn_main_loop(ASOK_REQ_VERSION);
+
+    return (ret) ? ret : 0;
+}
+
+static int ceph_shutdown(void)
+{
+    int i;
+    for(i = 0; i < g_num_daemons; ++i)
+    {
+        ceph_daemon_free(g_daemons[i]);
+    }
+    sfree(g_daemons);
+    g_daemons = NULL;
+    g_num_daemons = 0;
+    DEBUG("ceph plugin: finished ceph_shutdown");
+    return 0;
+}
+
+void module_register(void)
+{
+    plugin_register_complex_config("ceph", ceph_config);
+    plugin_register_init("ceph", ceph_init);
+    plugin_register_read("ceph", ceph_read);
+    plugin_register_shutdown("ceph", ceph_shutdown);
+}
index 17b12d0435150189bba3fe15ab9a6fd66d57be76..6d419722b7ef385ea0b8607f2b5b5056c849a408 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 6f58542784d51a206c685eedee1eed488cd3b101..282098efe875f31e32f36efc6e79b05b8121dbf3 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 fd9b3a0c02c7eba4b0fe617d5f759f7b9d424793..10f9f618a2ef976f07222cf69e8edfc8d55727a6 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
@@ -293,6 +306,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 00f209a56b7d69e3f35757f86876e194321dbab0..aade08a456b701aff4fdc94f70f1907617de1127 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 7fda6fc120a3aa4c94eaa640092ab2ff39724f40..8b0f867949e1f09c1b8f015598c8dd08e8d8925c 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 aab753c56539d8c2a9bcb5b2196a9b8ae6c5dfd7..e28ff4b829515f85f89eed971d6fa2cb3fa0419c 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 d4137bb751cc9259a3af4e07d0a69eb384dedf53..7308648fbe6346484f1273688d535339bf32e7d6 100644 (file)
@@ -708,7 +708,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.
 
@@ -788,7 +788,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 b382424b7b0392180219156d18de144f58043b60..0da891f1e47b5aa3dc14eabb7f97fc6b0d7dfc45 100644 (file)
@@ -50,13 +50,15 @@ Loads the Python plugin I<Plugin>.
 =item B<Encoding> I<Name>
 
 The default encoding for Unicode objects you pass to collectd. If you omit this
-option it will default to B<ascii> on I<Python 2> and B<utf-8> on I<Python 3>.
-This is hardcoded in Python and will ignore everything else, including your
-locale.
+option it will default to B<ascii> on I<Python 2>. On I<Python 3> it will
+always be B<utf-8>, as this function was removed, so this will be silently
+ignored.
+These defaults are hardcoded in Python and will ignore everything else,
+including your locale.
 
 =item B<ModulePath> I<Name>
 
-Appends I<Name> to B<sys.path>. You won't be able to import any scripts you
+Prepends I<Name> to B<sys.path>. You won't be able to import any scripts you
 wrote unless they are located in one of the directories in this list. Please
 note that it only has effect on plugins loaded after this option. You can
 use multiple B<ModulePath> lines to add more than one directory.
@@ -555,7 +557,7 @@ receive blocks where your callback identifier matches B<python.>I<blockname>.
 
 The callback will be called without arguments.
 
-=item register_read(callback[, interval][, data][, name]) -> identifier
+=item register_read(callback[, interval][, data][, name]) -> I<identifier>
 
 This function takes an additional parameter: I<interval>. It specifies the
 time between calls to the callback function.
@@ -609,7 +611,33 @@ I<identifier> is either the string that was returned by the register function
 or a callback function. The identifier will be constructed in the same way as
 for the register functions.
 
-=item B<flush>(I<plugin[, I<timeout>][, I<identifier>]) -> None
+=item B<get_dataset>(I<name>) -> I<definition>
+
+Returns the definition of a dataset specified by I<name>. I<definition> is a list
+of tuples, each representing one data source. Each tuple has 4 values:
+
+=over 4
+
+=item name
+
+A string, the name of the data source.
+
+=item type
+
+A string that is equal to either of the variables B<DS_TYPE_COUNTER>,
+B<DS_TYPE_GAUGE>, B<DS_TYPE_DERIVE> or B<DS_TYPE_ABSOLUTE>.
+
+=item min
+
+A float or None, the minimum value.
+
+=item max
+
+A float or None, the maximum value.
+
+=back
+
+=item B<flush>(I<plugin>[, I<timeout>][, I<identifier>]) -> None
 
 Flush one or all plugins. I<timeout> and the specified I<identifiers> are
 passed on to the registered flush-callbacks. If omitted, the timeout defaults
@@ -656,7 +684,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.
 
@@ -723,7 +751,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 fd7a50896486211c3fac9b0ef6d10304738dcb4c..65a9b7c3d320098e40a3b491865e0067d8d53197 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 9fec340214f4505cf96d9ab0d69fa3b1a800a81a..45e788c22206c5c733d696bc6ab778ab732643ec 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 c572df19f47de88fcdbcfc53fb852f0b5c36e3f7..b241a9f3430af3ac33cf2c326a53b691fdaecc1d 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
diff --git a/src/collectd.c b/src/collectd.c
deleted file mode 100644 (file)
index 1ccc1c0..0000000
+++ /dev/null
@@ -1,620 +0,0 @@
-/**
- * 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.
- *
- * 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
- *
- * Authors:
- *   Florian octo Forster <octo at verplant.org>
- *   Alvaro Barcellos <alvaro.barcellos at gmail.com>
- **/
-
-#include "collectd.h"
-#include "common.h"
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-
-#include <pthread.h>
-
-#include "plugin.h"
-#include "configfile.h"
-
-#if HAVE_STATGRAB_H
-# include <statgrab.h>
-#endif
-
-/*
- * Global variables
- */
-char hostname_g[DATA_MAX_NAME_LEN];
-cdtime_t interval_g;
-int  timeout_g;
-#if HAVE_LIBKSTAT
-kstat_ctl_t *kc;
-#endif /* HAVE_LIBKSTAT */
-
-static int loop = 0;
-
-static void *do_flush (void __attribute__((unused)) *arg)
-{
-       INFO ("Flushing all data.");
-       plugin_flush (/* plugin = */ NULL,
-                       /* timeout = */ 0,
-                       /* ident = */ NULL);
-       INFO ("Finished flushing all data.");
-       pthread_exit (NULL);
-       return NULL;
-}
-
-static void sig_int_handler (int __attribute__((unused)) signal)
-{
-       loop++;
-}
-
-static void sig_term_handler (int __attribute__((unused)) signal)
-{
-       loop++;
-}
-
-static void sig_usr1_handler (int __attribute__((unused)) signal)
-{
-       pthread_t      thread;
-       pthread_attr_t attr;
-
-       /* flushing the data might take a while,
-        * so it should be done asynchronously */
-       pthread_attr_init (&attr);
-       pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
-       pthread_create (&thread, &attr, do_flush, NULL);
-       pthread_attr_destroy (&attr);
-}
-
-static int init_hostname (void)
-{
-       const char *str;
-
-       struct addrinfo  ai_hints;
-       struct addrinfo *ai_list;
-       struct addrinfo *ai_ptr;
-       int status;
-
-       str = global_option_get ("Hostname");
-       if (str != NULL)
-       {
-               sstrncpy (hostname_g, str, sizeof (hostname_g));
-               return (0);
-       }
-
-       if (gethostname (hostname_g, sizeof (hostname_g)) != 0)
-       {
-               fprintf (stderr, "`gethostname' failed and no "
-                               "hostname was configured.\n");
-               return (-1);
-       }
-
-       str = global_option_get ("FQDNLookup");
-       if (IS_FALSE (str))
-               return (0);
-
-       memset (&ai_hints, '\0', sizeof (ai_hints));
-       ai_hints.ai_flags = AI_CANONNAME;
-
-       status = getaddrinfo (hostname_g, NULL, &ai_hints, &ai_list);
-       if (status != 0)
-       {
-               ERROR ("Looking up \"%s\" failed. You have set the "
-                               "\"FQDNLookup\" option, but I cannot resolve "
-                               "my hostname to a fully qualified domain "
-                               "name. Please fix the network "
-                               "configuration.", hostname_g);
-               return (-1);
-       }
-
-       for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
-       {
-               if (ai_ptr->ai_canonname == NULL)
-                       continue;
-
-               sstrncpy (hostname_g, ai_ptr->ai_canonname, sizeof (hostname_g));
-               break;
-       }
-
-       freeaddrinfo (ai_list);
-       return (0);
-} /* int init_hostname */
-
-static int init_global_variables (void)
-{
-       char const *str;
-
-       interval_g = cf_get_default_interval ();
-       assert (interval_g > 0);
-       DEBUG ("interval_g = %.3f;", CDTIME_T_TO_DOUBLE (interval_g));
-
-       str = global_option_get ("Timeout");
-       if (str == NULL)
-               str = "2";
-       timeout_g = atoi (str);
-       if (timeout_g <= 1)
-       {
-               fprintf (stderr, "Cannot set the timeout to a correct value.\n"
-                               "Please check your settings.\n");
-               return (-1);
-       }
-       DEBUG ("timeout_g = %i;", timeout_g);
-
-       if (init_hostname () != 0)
-               return (-1);
-       DEBUG ("hostname_g = %s;", hostname_g);
-
-       return (0);
-} /* int init_global_variables */
-
-static int change_basedir (const char *orig_dir)
-{
-       char *dir;
-       size_t dirlen;
-       int status;
-
-       dir = strdup (orig_dir);
-       if (dir == NULL)
-       {
-               char errbuf[1024];
-               ERROR ("strdup failed: %s",
-                               sstrerror (errno, errbuf, sizeof (errbuf)));
-               return (-1);
-       }
-       
-       dirlen = strlen (dir);
-       while ((dirlen > 0) && (dir[dirlen - 1] == '/'))
-               dir[--dirlen] = '\0';
-
-       if (dirlen <= 0) {
-               free (dir);
-               return (-1);
-       }
-
-       status = chdir (dir);
-       if (status == 0)
-       {
-               free (dir);
-               return (0);
-       }
-       else if (errno != ENOENT)
-       {
-               char errbuf[1024];
-               ERROR ("change_basedir: chdir (%s): %s", dir,
-                               sstrerror (errno, errbuf, sizeof (errbuf)));
-               free (dir);
-               return (-1);
-       }
-
-       status = mkdir (dir, S_IRWXU | S_IRWXG | S_IRWXO);
-       if (status != 0)
-       {
-               char errbuf[1024];
-               ERROR ("change_basedir: mkdir (%s): %s", dir,
-                               sstrerror (errno, errbuf, sizeof (errbuf)));
-               free (dir);
-               return (-1);
-       }
-
-       status = chdir (dir);
-       if (status != 0)
-       {
-               char errbuf[1024];
-               ERROR ("change_basedir: chdir (%s): %s", dir,
-                               sstrerror (errno, errbuf, sizeof (errbuf)));
-               free (dir);
-               return (-1);
-       }
-
-       free (dir);
-       return (0);
-} /* static int change_basedir (char *dir) */
-
-#if HAVE_LIBKSTAT
-static void update_kstat (void)
-{
-       if (kc == NULL)
-       {
-               if ((kc = kstat_open ()) == NULL)
-                       ERROR ("Unable to open kstat control structure");
-       }
-       else
-       {
-               kid_t kid;
-               kid = kstat_chain_update (kc);
-               if (kid > 0)
-               {
-                       INFO ("kstat chain has been updated");
-                       plugin_init_all ();
-               }
-               else if (kid < 0)
-                       ERROR ("kstat chain update failed");
-               /* else: everything works as expected */
-       }
-
-       return;
-} /* static void update_kstat (void) */
-#endif /* HAVE_LIBKSTAT */
-
-/* TODO
- * Remove all settings but `-f' and `-C'
- */
-static void exit_usage (int status)
-{
-       printf ("Usage: "PACKAGE" [OPTIONS]\n\n"
-                       
-                       "Available options:\n"
-                       "  General:\n"
-                       "    -C <file>       Configuration file.\n"
-                       "                    Default: "CONFIGFILE"\n"
-                       "    -t              Test config and exit.\n"
-                       "    -T              Test plugin read and exit.\n"
-                       "    -P <file>       PID-file.\n"
-                       "                    Default: "PIDFILE"\n"
-#if COLLECT_DAEMON
-                       "    -f              Don't fork to the background.\n"
-#endif
-                       "    -h              Display help (this message)\n"
-                       "\nBuiltin defaults:\n"
-                       "  Config file       "CONFIGFILE"\n"
-                       "  PID file          "PIDFILE"\n"
-                       "  Plugin directory  "PLUGINDIR"\n"
-                       "  Data directory    "PKGLOCALSTATEDIR"\n"
-                       "\n"PACKAGE" "VERSION", http://collectd.org/\n"
-                       "by Florian octo Forster <octo@verplant.org>\n"
-                       "for contributions see `AUTHORS'\n");
-       exit (status);
-} /* static void exit_usage (int status) */
-
-static int do_init (void)
-{
-#if HAVE_LIBKSTAT
-       kc = NULL;
-       update_kstat ();
-#endif
-
-#if HAVE_LIBSTATGRAB
-       if (sg_init ())
-       {
-               ERROR ("sg_init: %s", sg_str_error (sg_get_error ()));
-               return (-1);
-       }
-
-       if (sg_drop_privileges ())
-       {
-               ERROR ("sg_drop_privileges: %s", sg_str_error (sg_get_error ()));
-               return (-1);
-       }
-#endif
-
-       plugin_init_all ();
-
-       return (0);
-} /* int do_init () */
-
-
-static int do_loop (void)
-{
-       cdtime_t interval = cf_get_default_interval ();
-       cdtime_t wait_until;
-
-       wait_until = cdtime () + interval;
-
-       while (loop == 0)
-       {
-               struct timespec ts_wait = { 0, 0 };
-               cdtime_t now;
-
-#if HAVE_LIBKSTAT
-               update_kstat ();
-#endif
-
-               /* Issue all plugins */
-               plugin_read_all ();
-
-               now = cdtime ();
-               if (now >= wait_until)
-               {
-                       WARNING ("Not sleeping because the next interval is "
-                                       "%.3f seconds in the past!",
-                                       CDTIME_T_TO_DOUBLE (now - wait_until));
-                       wait_until = now + interval;
-                       continue;
-               }
-
-               CDTIME_T_TO_TIMESPEC (wait_until - now, &ts_wait);
-               wait_until = wait_until + interval;
-
-               while ((loop == 0) && (nanosleep (&ts_wait, &ts_wait) != 0))
-               {
-                       if (errno != EINTR)
-                       {
-                               char errbuf[1024];
-                               ERROR ("nanosleep failed: %s",
-                                               sstrerror (errno, errbuf,
-                                                       sizeof (errbuf)));
-                               return (-1);
-                       }
-               }
-       } /* while (loop == 0) */
-
-       return (0);
-} /* int do_loop */
-
-static int do_shutdown (void)
-{
-       plugin_shutdown_all ();
-       return (0);
-} /* int do_shutdown */
-
-#if COLLECT_DAEMON
-static int pidfile_create (void)
-{
-       FILE *fh;
-       const char *file = global_option_get ("PIDFile");
-
-       if ((fh = fopen (file, "w")) == NULL)
-       {
-               char errbuf[1024];
-               ERROR ("fopen (%s): %s", file,
-                               sstrerror (errno, errbuf, sizeof (errbuf)));
-               return (1);
-       }
-
-       fprintf (fh, "%i\n", (int) getpid ());
-       fclose(fh);
-
-       return (0);
-} /* static int pidfile_create (const char *file) */
-
-static int pidfile_remove (void)
-{
-       const char *file = global_option_get ("PIDFile");
-       if (file == NULL)
-               return 0;
-
-       return (unlink (file));
-} /* static int pidfile_remove (const char *file) */
-#endif /* COLLECT_DAEMON */
-
-int main (int argc, char **argv)
-{
-       struct sigaction sig_int_action;
-       struct sigaction sig_term_action;
-       struct sigaction sig_usr1_action;
-       struct sigaction sig_pipe_action;
-       char *configfile = CONFIGFILE;
-       int test_config  = 0;
-       int test_readall = 0;
-       const char *basedir;
-#if COLLECT_DAEMON
-       struct sigaction sig_chld_action;
-       pid_t pid;
-       int daemonize    = 1;
-#endif
-       int exit_status = 0;
-
-       /* read options */
-       while (1)
-       {
-               int c;
-
-               c = getopt (argc, argv, "htTC:"
-#if COLLECT_DAEMON
-                               "fP:"
-#endif
-               );
-
-               if (c == -1)
-                       break;
-
-               switch (c)
-               {
-                       case 'C':
-                               configfile = optarg;
-                               break;
-                       case 't':
-                               test_config = 1;
-                               break;
-                       case 'T':
-                               test_readall = 1;
-                               global_option_set ("ReadThreads", "-1");
-#if COLLECT_DAEMON
-                               daemonize = 0;
-#endif /* COLLECT_DAEMON */
-                               break;
-#if COLLECT_DAEMON
-                       case 'P':
-                               global_option_set ("PIDFile", optarg);
-                               break;
-                       case 'f':
-                               daemonize = 0;
-                               break;
-#endif /* COLLECT_DAEMON */
-                       case 'h':
-                               exit_usage (0);
-                               break;
-                       default:
-                               exit_usage (1);
-               } /* switch (c) */
-       } /* while (1) */
-
-       if (optind < argc)
-               exit_usage (1);
-
-       plugin_init_ctx ();
-
-       /*
-        * Read options from the config file, the environment and the command
-        * line (in that order, with later options overwriting previous ones in
-        * general).
-        * Also, this will automatically load modules.
-        */
-       if (cf_read (configfile))
-       {
-               fprintf (stderr, "Error: Reading the config file failed!\n"
-                               "Read the syslog for details.\n");
-               return (1);
-       }
-
-       /*
-        * Change directory. We do this _after_ reading the config and loading
-        * modules to relative paths work as expected.
-        */
-       if ((basedir = global_option_get ("BaseDir")) == NULL)
-       {
-               fprintf (stderr, "Don't have a basedir to use. This should not happen. Ever.");
-               return (1);
-       }
-       else if (change_basedir (basedir))
-       {
-               fprintf (stderr, "Error: Unable to change to directory `%s'.\n", basedir);
-               return (1);
-       }
-
-       /*
-        * Set global variables or, if that failes, exit. We cannot run with
-        * them being uninitialized. If nothing is configured, then defaults
-        * are being used. So this means that the user has actually done
-        * something wrong.
-        */
-       if (init_global_variables () != 0)
-               return (1);
-
-       if (test_config)
-               return (0);
-
-#if COLLECT_DAEMON
-       /*
-        * fork off child
-        */
-       memset (&sig_chld_action, '\0', sizeof (sig_chld_action));
-       sig_chld_action.sa_handler = SIG_IGN;
-       sigaction (SIGCHLD, &sig_chld_action, NULL);
-
-       if (daemonize)
-       {
-               if ((pid = fork ()) == -1)
-               {
-                       /* error */
-                       char errbuf[1024];
-                       fprintf (stderr, "fork: %s",
-                                       sstrerror (errno, errbuf,
-                                               sizeof (errbuf)));
-                       return (1);
-               }
-               else if (pid != 0)
-               {
-                       /* parent */
-                       /* printf ("Running (PID %i)\n", pid); */
-                       return (0);
-               }
-
-               /* Detach from session */
-               setsid ();
-
-               /* Write pidfile */
-               if (pidfile_create ())
-                       exit (2);
-
-               /* close standard descriptors */
-               close (2);
-               close (1);
-               close (0);
-
-               if (open ("/dev/null", O_RDWR) != 0)
-               {
-                       ERROR ("Error: Could not connect `STDIN' to `/dev/null'");
-                       return (1);
-               }
-               if (dup (0) != 1)
-               {
-                       ERROR ("Error: Could not connect `STDOUT' to `/dev/null'");
-                       return (1);
-               }
-               if (dup (0) != 2)
-               {
-                       ERROR ("Error: Could not connect `STDERR' to `/dev/null'");
-                       return (1);
-               }
-       } /* if (daemonize) */
-#endif /* COLLECT_DAEMON */
-
-       memset (&sig_pipe_action, '\0', sizeof (sig_pipe_action));
-       sig_pipe_action.sa_handler = SIG_IGN;
-       sigaction (SIGPIPE, &sig_pipe_action, NULL);
-
-       /*
-        * install signal handlers
-        */
-       memset (&sig_int_action, '\0', sizeof (sig_int_action));
-       sig_int_action.sa_handler = sig_int_handler;
-       if (0 != sigaction (SIGINT, &sig_int_action, NULL)) {
-               char errbuf[1024];
-               ERROR ("Error: Failed to install a signal handler for signal INT: %s",
-                               sstrerror (errno, errbuf, sizeof (errbuf)));
-               return (1);
-       }
-
-       memset (&sig_term_action, '\0', sizeof (sig_term_action));
-       sig_term_action.sa_handler = sig_term_handler;
-       if (0 != sigaction (SIGTERM, &sig_term_action, NULL)) {
-               char errbuf[1024];
-               ERROR ("Error: Failed to install a signal handler for signal TERM: %s",
-                               sstrerror (errno, errbuf, sizeof (errbuf)));
-               return (1);
-       }
-
-       memset (&sig_usr1_action, '\0', sizeof (sig_usr1_action));
-       sig_usr1_action.sa_handler = sig_usr1_handler;
-       if (0 != sigaction (SIGUSR1, &sig_usr1_action, NULL)) {
-               char errbuf[1024];
-               ERROR ("Error: Failed to install a signal handler for signal USR1: %s",
-                               sstrerror (errno, errbuf, sizeof (errbuf)));
-               return (1);
-       }
-
-       /*
-        * run the actual loops
-        */
-       do_init ();
-
-       if (test_readall)
-       {
-               if (plugin_read_all_once () != 0)
-                       exit_status = 1;
-       }
-       else
-       {
-               INFO ("Initialization complete, entering read-loop.");
-               do_loop ();
-       }
-
-       /* close syslog */
-       INFO ("Exiting normally.");
-
-       do_shutdown ();
-
-#if COLLECT_DAEMON
-       if (daemonize)
-               pidfile_remove ();
-#endif /* COLLECT_DAEMON */
-
-       return (exit_status);
-} /* int main */
index 04d1ab3342aff70ad0baa46d8e0528b6daa7ca21..38a053498f19ee851a8d6a1d75ee0cb7bcc83a3c 100644 (file)
 #----------------------------------------------------------------------------#
 #AutoLoadPlugin false
 
+#----------------------------------------------------------------------------#
+# When enabled, internal statistics are collected, using "collectd" as the   #
+# plugin name.                                                               #
+# Disabled by default.                                                       #
+#----------------------------------------------------------------------------#
+#CollectInternalStats false
+
 #----------------------------------------------------------------------------#
 # Interval at which to query values. This may be overwritten on a per-plugin #
 # base by using the 'Interval' option of the LoadPlugin block:               #
 #----------------------------------------------------------------------------#
 #Interval     10
 
-#Timeout      2
-#ReadThreads  5
-#WriteThreads 5
+#MaxReadInterval 86400
+#Timeout         2
+#ReadThreads     5
+#WriteThreads    5
 
 # Limit the size of the write queue. Default is no limit. Setting up a limit is
 # recommended for servers handling a high volume of traffic.
@@ -52,6 +60,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>
 #@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_CEPH_TRUE@LoadPlugin ceph
+#@BUILD_PLUGIN_CGROUPS_TRUE@LoadPlugin cgroups
 #@BUILD_PLUGIN_CONNTRACK_TRUE@LoadPlugin conntrack
 #@BUILD_PLUGIN_CONTEXTSWITCH_TRUE@LoadPlugin contextswitch
-#@BUILD_PLUGIN_CGROUPS_TRUE@LoadPlugin cgroups
 @BUILD_PLUGIN_CPU_TRUE@@BUILD_PLUGIN_CPU_TRUE@LoadPlugin cpu
 #@BUILD_PLUGIN_CPUFREQ_TRUE@LoadPlugin cpufreq
 @LOAD_PLUGIN_CSV@LoadPlugin csv
 #@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_EXEC_TRUE@LoadPlugin exec
+#@BUILD_PLUGIN_FHCOUNT_TRUE@LoadPlugin fhcount
 #@BUILD_PLUGIN_FILECOUNT_TRUE@LoadPlugin filecount
 #@BUILD_PLUGIN_FSCACHE_TRUE@LoadPlugin fscache
 #@BUILD_PLUGIN_GMOND_TRUE@LoadPlugin gmond
 #@BUILD_PLUGIN_HDDTEMP_TRUE@LoadPlugin hddtemp
 @BUILD_PLUGIN_INTERFACE_TRUE@@BUILD_PLUGIN_INTERFACE_TRUE@LoadPlugin interface
-#@BUILD_PLUGIN_IPTABLES_TRUE@LoadPlugin iptables
+#@BUILD_PLUGIN_IPC_TRUE@@BUILD_PLUGIN_IPC_TRUE@LoadPlugin ipc
 #@BUILD_PLUGIN_IPMI_TRUE@LoadPlugin ipmi
+#@BUILD_PLUGIN_IPTABLES_TRUE@LoadPlugin iptables
 #@BUILD_PLUGIN_IPVS_TRUE@LoadPlugin ipvs
 #@BUILD_PLUGIN_IRQ_TRUE@LoadPlugin irq
 #@BUILD_PLUGIN_JAVA_TRUE@LoadPlugin java
-#@BUILD_PLUGIN_LIBVIRT_TRUE@LoadPlugin libvirt
 @BUILD_PLUGIN_LOAD_TRUE@@BUILD_PLUGIN_LOAD_TRUE@LoadPlugin load
 #@BUILD_PLUGIN_LPAR_TRUE@LoadPlugin lpar
 #@BUILD_PLUGIN_LVM_TRUE@LoadPlugin lvm
 #@BUILD_PLUGIN_MEMCACHEC_TRUE@LoadPlugin memcachec
 #@BUILD_PLUGIN_MEMCACHED_TRUE@LoadPlugin memcached
 @BUILD_PLUGIN_MEMORY_TRUE@@BUILD_PLUGIN_MEMORY_TRUE@LoadPlugin memory
+#@BUILD_PLUGIN_MIC_TRUE@LoadPlugin mic
 #@BUILD_PLUGIN_MODBUS_TRUE@LoadPlugin modbus
 #@BUILD_PLUGIN_MULTIMETER_TRUE@LoadPlugin multimeter
 #@BUILD_PLUGIN_MYSQL_TRUE@LoadPlugin mysql
 #@BUILD_PLUGIN_NUT_TRUE@LoadPlugin nut
 #@BUILD_PLUGIN_OLSRD_TRUE@LoadPlugin olsrd
 #@BUILD_PLUGIN_ONEWIRE_TRUE@LoadPlugin onewire
+#@BUILD_PLUGIN_OPENLDAP_TRUE@LoadPlugin openldap
 #@BUILD_PLUGIN_OPENVPN_TRUE@LoadPlugin openvpn
 #@BUILD_PLUGIN_ORACLE_TRUE@LoadPlugin oracle
 #@BUILD_PLUGIN_PERL_TRUE@LoadPlugin perl
 #@BUILD_PLUGIN_SENSORS_TRUE@LoadPlugin sensors
 #@BUILD_PLUGIN_SERIAL_TRUE@LoadPlugin serial
 #@BUILD_PLUGIN_SIGROK_TRUE@LoadPlugin sigrok
+#@BUILD_PLUGIN_SMART_TRUE@LoadPlugin smart
 #@BUILD_PLUGIN_SNMP_TRUE@LoadPlugin snmp
 #@BUILD_PLUGIN_STATSD_TRUE@LoadPlugin statsd
 #@BUILD_PLUGIN_SWAP_TRUE@LoadPlugin swap
 #@BUILD_PLUGIN_TED_TRUE@LoadPlugin ted
 #@BUILD_PLUGIN_THERMAL_TRUE@LoadPlugin thermal
 #@BUILD_PLUGIN_TOKYOTYRANT_TRUE@LoadPlugin tokyotyrant
+#@BUILD_PLUGIN_TURBOSTAT_TRUE@LoadPlugin turbostat
 #@BUILD_PLUGIN_UNIXSOCK_TRUE@LoadPlugin unixsock
 #@BUILD_PLUGIN_UPTIME_TRUE@LoadPlugin uptime
 #@BUILD_PLUGIN_USERS_TRUE@LoadPlugin users
 #@BUILD_PLUGIN_UUID_TRUE@LoadPlugin uuid
 #@BUILD_PLUGIN_VARNISH_TRUE@LoadPlugin varnish
-#@BUILD_PLUGIN_MIC_TRUE@LoadPlugin mic
+#@BUILD_PLUGIN_VIRT_TRUE@LoadPlugin virt
 #@BUILD_PLUGIN_VMEM_TRUE@LoadPlugin vmem
 #@BUILD_PLUGIN_VSERVER_TRUE@LoadPlugin vserver
 #@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_LOG_TRUE@LoadPlugin write_log
 #@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_SENSU_TRUE@LoadPlugin write_sensu
+#@BUILD_PLUGIN_WRITE_TSDB_TRUE@LoadPlugin write_tsdb
 #@BUILD_PLUGIN_XMMS_TRUE@LoadPlugin xmms
 #@BUILD_PLUGIN_ZFS_ARC_TRUE@LoadPlugin zfs_arc
+#@BUILD_PLUGIN_ZOOKEEPER_TRUE@LoadPlugin zookeeper
 
 ##############################################################################
 # Plugin configuration                                                       #
 # 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"
 #    RoutingKey "collectd"
 #    Persistent false
 #    StoreRates false
+#    ConnectionRetryDelay 0
 #  </Publish>
 #</Plugin>
 
 #      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 "battery">
+#  ValuesPercentage false
+#  ReportDegraded
+#</Plugin>
+
 #<Plugin "bind">
 #  URL "http://localhost:8053/"
 #  ParseTime       false
 #  </View>
 #</Plugin>
 
+#<Plugin ceph>
+#  LongRunAvgLatency false
+#  ConvertSpecialMetricTypes true
+#  <Daemon "osd.0">
+#    SocketPath "/var/run/ceph/ceph-osd.0.asok"
+#  </Daemon>
+#  <Daemon "osd.1">
+#    SocketPath "/var/run/ceph/ceph-osd.1.asok"
+#  </Daemon>
+#  <Daemon "mon.a">
+#    SocketPath "/var/run/ceph/ceph-mon.ceph1.asok"
+#  </Daemon>
+#  <Daemon "mds.a">
+#    SocketPath "/var/run/ceph/ceph-mds.ceph1.asok"
+#  </Daemon>
+#</Plugin>
+
 #<Plugin cgroups>
 #  CGroup "libvirt"
 #  IgnoreSelected false
 #</Plugin>
 
+#<Plugin cpu>
+#  ReportByCpu true
+#  ReportByState true
+#  ValuesPercentage false
+#</Plugin>
+#
 #<Plugin csv>
 #      DataDir "@localstatedir@/lib/@PACKAGE_NAME@/csv"
 #      StoreRates false
 #    URL "http://finance.google.com/finance?q=NYSE%3AAMD"
 #    User "foo"
 #    Password "bar"
+#    Digest false
+#    VerifyPeer true
+#    VerifyHost true
+#    CACert "/path/to/ca.crt"
+#    Header "X-Custom-Header: foobar"
+#    Post "foo=bar"
+#
 #    MeasureResponseTime false
+#    MeasureResponseCode false
 #    <Match>
 #      Regex "<span +class=\"pr\"[^>]*> *([0-9]*\\.[0-9]+) *</span>"
 #      DSType "GaugeAverage"
 #  </URL>
 #</Plugin>
 
-#<Plugin "curl_xml">
+#<Plugin curl_xml>
 #  <URL "http://localhost/stats.xml">
 #    Host "my_host"
 #    Instance "some_instance"
 #    User "collectd"
 #    Password "thaiNg0I"
+#    Digest false
 #    VerifyPeer true
 #    VerifyHost true
 #    CACert "/path/to/ca.crt"
+#    Header "X-Custom-Header: foobar"
+#    Post "foo=bar"
 #
 #    <XPath "table[@id=\"magic_level\"]/tr">
 #      Type "magic_level"
 #<Plugin disk>
 #      Disk "/^[hs]d[a-f][0-9]?$/"
 #      IgnoreSelected false
+#      UseBSDName false
+#      UdevNameAttr "DEVNAME"
 #</Plugin>
 
 #<Plugin dns>
 #      NotificationExec "user:group" "/path/to/exec"
 #</Plugin>
 
+#<Plugin fhcount>
+#      ValuesAbsolute true
+#      ValuesPercentage false
+#</Plugin>
+
 #<Plugin filecount>
 #      <Directory "/path/to/dir">
 #              Instance "foodir"
 #      </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"
 #
 #      </Plugin>
 #</Plugin>
 
-#<Plugin libvirt>
-#      Connection "xen:///"
-#      RefreshInterval 60
-#      Domain "name"
-#      BlockDevice "name:device"
-#      InterfaceDevice "name:device"
-#      IgnoreSelected false
-#      HostnameFormat name
-#      InterfaceFormat name
+#<Plugin load>
+#        ReportRelative true
 #</Plugin>
 
 #<Plugin lpar>
 #      </Instance>
 #</Plugin>
 
+#<Plugin memory>
+#      ValuesAbsolute true
+#      ValuesPercentage false
+#</Plugin>
+
 #<Plugin modbus>
 #      <Data "data_name">
 #              RegisterBase 1234
+#              RegisterCmd ReadHolding
 #              RegisterType float
 #              Type gauge
 #              Instance "..."
 #              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
 #              Username "user"
 #              Password "secret"
 #              Interface "eth0"
+#              ResolveInterval 14400
 @LOAD_PLUGIN_NETWORK@  </Server>
 #      TimeToLive 128
 #
 #      IgnoreSelected false
 #</Plugin>
 
+#<Plugin openldap>
+#  <Instance "localhost">
+#    URL "ldap://localhost:389"
+#    StartTLS false
+#    VerifyHost true
+#    CACert "/path/to/ca.crt"
+#    Timeout -1
+#    Version 3
+#  </Instance>
+#</Plugin>
+
 #<Plugin openvpn>
 #      StatusFile "/etc/openvpn/openvpn-status.log"
 #      ImprovedNamingSchema false
 #  </Device>
 #</Plugin>
 
+#<Plugin smart>
+#  Disk "/^[hs]d[a-f][0-9]?$/"
+#  IgnoreSelected false
+#</Plugin>
+
 #<Plugin snmp>
 #   <Data "powerplus_voltge_input">
 #       Type "voltage"
 #  TimerCount     false
 #</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"
 
 #<Plugin tcpconns>
 #      ListeningPorts false
+#      AllPortsSummary false
 #      LocalPort "25"
 #      RemotePort "25"
 #</Plugin>
 #      Port "1978"
 #</Plugin>
 
+#<Plugin turbostat>
+##     None of the following option should be set manually
+##     This plugin automatically detect most optimal options
+##     Only set values here if:
+##     - The module ask you to
+##     - You want to disable the collection of some data
+##     - Your (intel) CPU is not supported (yet) by the module
+##     - The module generate a lot of errors 'MSR offset 0x... read failed'
+##     In the last two cases, please open a bug request
+#
+#      TCCActivationTemp "100"
+#      CoreCstates "392"
+#      PackageCstates "396"
+#      SystemManagementInterrupt true
+#      DigitalTemperatureSensor true
+#      PackageThermalManagement true
+#      RunningAveragePowerLimit "7"    
+#</Plugin>
+
 #<Plugin unixsock>
 #      SocketFile "@prefix@/var/run/@PACKAGE_NAME@-unixsock"
 #      SocketGroup "collectd"
 #   If you prefer defining another instance you can do
 #   so by using <Instance "myinstance">
 #   <Instance>
-#      CollectCache true
 #      CollectBackend true
-#      CollectBan false           # Varnish 3 only
+#      CollectBan false           # Varnish 3 and above
+#      CollectCache true
 #      CollectConnections true
 #      CollectDirectorDNS false   # Varnish 3 only
-#      CollectSHM true
 #      CollectESI false
 #      CollectFetch false
 #      CollectHCB false
 #      CollectObjects false
 #      CollectPurge false         # Varnish 2 only
 #      CollectSession false
+#      CollectSHM true
 #      CollectSMA false           # Varnish 2 only
 #      CollectSMS false
 #      CollectSM false            # Varnish 2 only
 #      CollectStruct false
 #      CollectTotals false
-#      CollectUptime false
+#      CollectUptime false        # Varnish 3 and above
 #      CollectVCL false
+#      CollectVSM false           # Varnish 4 only
 #      CollectWorkers false
 #   </Instance>
 #</Plugin>
 
+#<Plugin virt>
+#      Connection "xen:///"
+#      RefreshInterval 60
+#      Domain "name"
+#      BlockDevice "name:device"
+#      InterfaceDevice "name:device"
+#      IgnoreSelected false
+#      HostnameFormat name
+#      InterfaceFormat name
+#      PluginInstanceFormat name
+#</Plugin>
+
 #<Plugin vmem>
 #      Verbose false
 #</Plugin>
 #</Plugin>
 
 #<Plugin write_http>
-#      <URL "http://example.com/collectd-post">
+#      <Node "example">
+#              URL "http://example.com/collectd-post"
 #              User "collectd"
 #              Password "weCh3ik0"
 #              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>
+#              BufferSize 4096
+#              LowSpeedLimit 0
+#              Timeout 0
+#      </Node>
+#</Plugin>
+
+#<Plugin write_kafka>
+#  Property "metadata.broker.list" "localhost:9092"
+#  <Topic "collectd">
+#    Format JSON
+#  </Topic>
 #</Plugin>
 
 #<Plugin write_mongodb>
 #      <Node "example">
 #              Host "localhost"
 #              Port 5555
-#              Protocol UDP
+#              Protocol TCP
+#              Batch true
+#              BatchMaxSize 8192
 #              StoreRates true
 #              AlwaysAppendDS false
 #              TTLFactor 2.0
+#              Notifications true
+#              CheckThresholds false
+#              EventServicePrefix ""
+#      </Node>
+#      Tag "foobar"
+#      Attribute "foo" "bar"
+#</Plugin>
+
+#<Plugin write_sensu>
+#      <Node "example">
+#              Host "localhost"
+#              Port 3030
+#              StoreRates true
+#              AlwaysAppendDS false
+#              Notifications true
+#              Metrics true
+#              EventServicePrefix ""
+#              MetricHandler "influx"
+#              MetricHandler "default"
+#              NotificationHandler "flapjack"
+#              NotificationHandler "howling_monkey"
 #      </Node>
 #      Tag "foobar"
+#      Attribute "foo" "bar"
+#</Plugin>
+
+#<Plugin write_tsdb>
+#      <Node>
+#              Host "localhost"
+#              Port "4242"
+#              HostTags "status=production"
+#              StoreRates false
+#              AlwaysAppendDS false
+#      </Node>
+#</Plugin>
+
+#<Plugin zookeeper>
+#    Host "localhost"
+#    Port "2181"
 #</Plugin>
 
 ##############################################################################
 ##############################################################################
 
 #@BUILD_PLUGIN_THRESHOLD_TRUE@LoadPlugin "threshold"
-#<Plugin "threshold">
+#<Plugin threshold>
 #  <Type "foo">
 #    WarningMin    0.00
 #    WarningMax 1000.00
index 25526e9fbcb7f5a0fd3457a65fd868b77da14610..9bb348f71a1cad5500b28da2494bad6e30cd9e70 100644 (file)
@@ -9,17 +9,17 @@ collectd.conf - Configuration for the system statistics collection daemon B<coll
   BaseDir "/var/lib/collectd"
   PIDFile "/run/collectd.pid"
   Interval 10.0
-  
+
   LoadPlugin cpu
   LoadPlugin load
-  
+
   <LoadPlugin df>
     Interval 3600
   </LoadPlugin>
   <Plugin df>
     ValuesPercentage true
   </Plugin>
-  
+
   LoadPlugin ping
   <Plugin ping>
     Host "example.org"
@@ -145,6 +145,18 @@ B<E<lt>PluginE<nbsp>...E<gt>> block acts as if it was immediately preceded by a
 B<LoadPlugin> statement. B<LoadPlugin> statements are still required for
 plugins that don't provide any configuration, e.g. the I<Load plugin>.
 
+=item B<CollectInternalStats> B<false>|B<true>
+
+When set to B<true>, various statistics about the I<collectd> daemon will be
+collected, with "collectd" as the I<plugin name>. Defaults to B<false>.
+
+The "write_queue" I<plugin instance> reports the number of elements currently
+queued and the number of elements dropped off the queue by the
+B<WriteQueueLimitLow>/B<WriteQueueLimitHigh> mechanism.
+
+The "cache" I<plugin instance> reports the number of elements in the value list
+cache (the cache you can interact with using L<collectd-unixsock(5)>).
+
 =item B<Include> I<Path> [I<pattern>]
 
 If I<Path> points to a file, includes that file. If I<Path> points to a
@@ -217,6 +229,14 @@ B<Warning:> You should set this once and then never touch it again. If you do,
 I<you will have to delete all your RRD files> or know some serious RRDtool
 magic! (Assuming you're using the I<RRDtool> or I<RRDCacheD> plugin.)
 
+=item B<MaxReadInterval> I<Seconds>
+
+Read plugin doubles interval between queries after each failed attempt
+to get data.
+
+This options limits the maximum value of the interval. The default value is
+B<86400>.
+
 =item B<Timeout> I<Iterations>
 
 Consider a value list "missing" when no update has been read or received for
@@ -267,8 +287,11 @@ If B<WriteQueueLimitHigh> is set to non-zero and B<WriteQueueLimitLow> is
 unset, the latter will default to half of B<WriteQueueLimitHigh>.
 
 If you do not want to randomly drop values when the queue size is between
-I<LowNum> and I<HighNum>, set If B<WriteQueueLimitHigh> and
-B<WriteQueueLimitLow> to same value.
+I<LowNum> and I<HighNum>, set B<WriteQueueLimitHigh> and B<WriteQueueLimitLow>
+to the same value.
+
+Enabling the B<CollectInternalStats> option is of great help to figure out the
+values to set B<WriteQueueLimitHigh> and B<WriteQueueLimitLow> to.
 
 =item B<Hostname> I<Name>
 
@@ -346,10 +369,10 @@ The full example configuration looks like this:
    <Aggregation>
      Plugin "cpu"
      Type "cpu"
-     
+
      GroupBy "Host"
      GroupBy "TypeInstance"
-     
+
      CalculateSum true
      CalculateAverage true
    </Aggregation>
@@ -425,13 +448,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>
@@ -495,6 +518,7 @@ possibly filtering or messages.
  #   ExchangeType "fanout"
  #   RoutingKey "collectd"
  #   Persistent false
+ #   ConnectionRetryDelay 0
  #   Format "command"
  #   StoreRates false
  #   GraphitePrefix "collectd."
@@ -513,7 +537,10 @@ possibly filtering or messages.
      Exchange "amq.fanout"
  #   ExchangeType "fanout"
  #   Queue "queue_name"
+ #   QueueDurable false
+ #   QueueAutoDelete true
  #   RoutingKey "collectd.#"
+ #   ConnectionRetryDelay 0
    </Subscribe>
  </Plugin>
 
@@ -565,9 +592,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
@@ -590,6 +631,13 @@ mode will be used, i.e. delivery is guaranteed. If set to B<false> (the
 default), the I<transient> delivery mode will be used, i.e. messages may be
 lost due to high load, overflowing queues or similar issues.
 
+=item B<ConnectionRetryDelay> I<Delay>
+
+When the connection to the AMQP broker is lost, defines the time in seconds to
+wait before attempting to reconnect. Defaults to 0, which implies collectd will
+attempt to reconnect at each read interval (in Subscribe mode) or each time
+values are ready for submission (in Publish mode).
+
 =item B<Format> B<Command>|B<JSON>|B<Graphite> (Publish only)
 
 Selects the format in which messages are sent to the broker. If set to
@@ -726,6 +774,18 @@ 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<SSLCiphers> I<list of ciphers>
+
+Specifies which ciphers to use in the connection. The list of ciphers
+must specify valid ciphers. See
+L<http://www.openssl.org/docs/apps/ciphers.html> for details.
+
+=item B<Timeout> I<Milliseconds>
+
+The B<Timeout> option sets the overall timeout for HTTP requests to B<URL>, in
+milliseconds. By default, the configured B<Interval> is used to set the
+timeout.
+
 =back
 
 =head2 Plugin C<apcups>
@@ -814,6 +874,204 @@ 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<Timeout> I<Milliseconds>
+
+The B<Timeout> option sets the overall timeout for HTTP requests to B<URL>, in
+milliseconds. By default, the configured B<Interval> is used to set the
+timeout.
+
+=back
+
+=head2 Plugin C<barometer>
+
+This plugin reads absolute air pressure using digital barometer sensor on a I2C
+bus. Supported sensors are:
+
+=over 5
+
+=item I<MPL115A2> from Freescale,
+see L<http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPL115A>.
+
+
+=item I<MPL3115> from Freescale
+see L<http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPL3115A2>.
+
+
+=item I<BMP085> from Bosch Sensortec
+
+=back
+
+The sensor type - one of the above - is detected automatically by the plugin
+and indicated in the plugin_instance (you will see subdirectory
+"barometer-mpl115" or "barometer-mpl3115", or "barometer-bmp085"). The order of
+detection is BMP085 -> MPL3115 -> MPL115A2, the first one found will be used
+(only one sensor can be used by the plugin).
+
+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 (depending
+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>
+
+The only mandatory configuration parameter.
+
+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>
+
+Optional parameter controlling the oversampling/accuracy. Default value
+is 1 providing fastest and least accurate reading.
+
+For I<MPL115> this is the size of the averaging window. To filter out sensor
+noise a simple averaging using floating window of this 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 I<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.
+
+For I<BMP085> 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. Any other value is adjusted by the plugin to
+the closest supported one.
+
+=item B<PressureOffset> I<offset>
+
+Optional parameter for MPL3115 only.
+
+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>
+
+Optional parameter for MPL3115 only.
+
+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>
+
+Optional parameter, default value is 0.
+
+Normalization method - what approximation/model is used to compute the 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 pressure 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
+L<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 L<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(s) which should be used as a reference when normalizing the
+pressure using C<Normalization> method 2.
+When specified more sensors a minumum is found and used 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<battery>
+
+The I<battery plugin> reports the remaining capacity, power and voltage of
+laptop batteries.
+
+=over 4
+
+=item B<ValuesPercentage> B<false>|B<true>
+
+When enabled, remaining capacity is reported as a percentage, e.g. "42%
+capacity remaining". Otherwise the capacity is stored as reported by the
+battery, most likely in "Wh". This option does not work with all input methods,
+in particular when only C</proc/pmu> is available on an old Linux system.
+Defaults to B<false>.
+
+=item B<ReportDegraded> B<false>|B<true>
+
+Typical laptop batteries degrade over time, meaning the capacity decreases with
+recharge cycles. The maximum charge of the previous charge cycle is tracked as
+"last full capacity" and used to determine that a battery is "fully charged".
+
+When this option is set to B<false>, the default, the I<battery plugin> will
+only report the remaining capacity. If the B<ValuesPercentage> option is
+enabled, the relative remaining capacity is calculated as the ratio of the
+"remaining capacity" and the "last full capacity". This is what most tools,
+such as the status bar of desktop environments, also do.
+
+When set to B<true>, the battery plugin will report three values: B<charged>
+(remaining capacity), B<discharged> (difference between "last full capacity"
+and "remaining capacity") and B<degraded> (difference between "design capacity"
+and "last full capacity").
+
 =back
 
 =head2 Plugin C<bind>
@@ -842,17 +1100,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>
@@ -919,6 +1177,12 @@ Collect global memory statistics.
 
 Default: Enabled.
 
+=item B<Timeout> I<Milliseconds>
+
+The B<Timeout> option sets the overall timeout for HTTP requests to B<URL>, in
+milliseconds. By default, the configured B<Interval> is used to set the
+timeout.
+
 =item B<View> I<Name>
 
 Collect statistics about a specific I<"view">. BIND can behave different,
@@ -970,6 +1234,74 @@ By default no detailed zone information is collected.
 
 =back
 
+=head2 Plugin C<ceph>
+
+The ceph plugin collects values from JSON data to be parsed by B<libyajl>
+(L<https://lloyd.github.io/yajl/>) retrieved from ceph daemon admin sockets.
+
+A separate B<Daemon> block must be configured for each ceph daemon to be
+monitored. The following example will read daemon statistics from four
+separate ceph daemons running on the same device (two OSDs, one MON, one MDS) :
+
+  <Plugin ceph>
+    LongRunAvgLatency false
+    ConvertSpecialMetricTypes true
+    <Daemon "osd.0">
+      SocketPath "/var/run/ceph/ceph-osd.0.asok"
+    </Daemon>
+    <Daemon "osd.1">
+      SocketPath "/var/run/ceph/ceph-osd.1.asok"
+    </Daemon>
+    <Daemon "mon.a">
+      SocketPath "/var/run/ceph/ceph-mon.ceph1.asok"
+    </Daemon>
+    <Daemon "mds.a">
+      SocketPath "/var/run/ceph/ceph-mds.ceph1.asok"
+    </Daemon>
+  </Plugin>
+
+The ceph plugin accepts the following configuration options:
+
+=over 4
+
+=item B<LongRunAvgLatency> B<true>|B<false>
+
+If enabled, latency values(sum,count pairs) are calculated as the long run
+average - average since the ceph daemon was started = (sum / count).
+When disabled, latency values are calculated as the average since the last
+collection = (sum_now - sum_last) / (count_now - count_last).
+
+Default: Disabled
+
+=item B<ConvertSpecialMetricTypes> B<true>|B<false>
+
+If enabled, special metrics (metrics that differ in type from similar counters)
+are converted to the type of those similar counters. This currently only
+applies to filestore.journal_wr_bytes which is a counter for OSD daemons. The
+ceph schema reports this metric type as a sum,count pair while similar counters
+are treated as derive types. When converted, the sum is used as the counter
+value and is treated as a derive type.
+When disabled, all metrics are treated as the types received from the ceph schema.
+
+Default: Enabled
+
+=back
+
+Each B<Daemon> block must have a string argument for the plugin instance name.
+A B<SocketPath> is also required for each B<Daemon> block:
+
+=over 4
+
+=item B<Daemon> I<DaemonName>
+
+Name to be used as the instance name for this daemon.
+
+=item B<SocketPath> I<SocketPath>
+
+Specifies the path to the UNIX admin socket of the ceph daemon.
+
+=back
+
 =head2 Plugin C<cgroups>
 
 This plugin collects the CPU user/system time for each I<cgroup> by reading the
@@ -993,6 +1325,68 @@ 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. By default, CPU usage is reported
+as Jiffies, using the C<cpu> type. Two aggregations are available:
+
+=over 4
+
+=item
+
+Sum, per-state, over all CPUs installed in the system; and
+
+=item
+
+Sum, per-CPU, over all non-idle states of a CPU, creating an "active" state.
+
+=back
+
+The two aggregations can be combined, leading to I<collectd> only emitting a
+single "active" metric for the entire system. As soon as one of these
+aggregations (or both) is enabled, the I<cpu plugin> will report a percentage,
+rather than Jiffies. In addition, you can request individual, per-state,
+per-CPU metrics to be reported as percentage.
+
+The following configuration options are available:
+
+=over 4
+
+=item B<ReportByState> B<true>|B<false>
+
+When set to B<true>, the default, reports per-state metrics, e.g. "system",
+"user" and "idle".
+When set to B<false>, aggregates (sums) all I<non-idle> states into one
+"active" metric.
+
+=item B<ReportByCpu> B<true>|B<false>
+
+When set to B<true>, the default, reports per-CPU (per-core) metrics.
+When set to B<false>, instead of reporting metrics for individual CPUs, only a
+global sum of CPU states is emitted.
+
+=item B<ValuesPercentage> B<false>|B<true>
+
+This option is only considered when both, B<ReportByCpu> and B<ReportByState>
+are set to B<true>. In this case, by default, metrics will be reported as
+Jiffies. By setting this option to B<true>, you can request percentage values
+in the un-aggregated (per-CPU, per-state) mode as well.
+
+=back
+
 =head2 Plugin C<cpufreq>
 
 This plugin doesn't have any options. It reads
@@ -1035,6 +1429,16 @@ finance page and dispatch the value to collectd.
       URL "http://finance.google.com/finance?q=NYSE%3AAMD"
       User "foo"
       Password "bar"
+      Digest false
+      VerifyPeer true
+      VerifyHost true
+      CACert "/path/to/ca.crt"
+      Header "X-Custom-Header: foobar"
+      Post "foo=bar"
+
+      MeasureResponseTime false
+      MeasureResponseCode false
+
       <Match>
         Regex "<span +class=\"pr\"[^>]*> *([0-9]*\\.[0-9]+) *</span>"
         DSType "GaugeAverage"
@@ -1066,6 +1470,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
@@ -1103,13 +1511,35 @@ C<application/x-www-form-urlencoded>).
 Measure response time for the request. If this setting is enabled, B<Match>
 blocks (see below) are optional. Disabled by default.
 
+Beware that requests will get aborted if they take too long to complete. Adjust
+B<Timeout> accordingly if you expect B<MeasureResponseTime> to report such slow
+requests.
+
+=item B<MeasureResponseCode> B<true>|B<false>
+
+Measure response code for the request. If this setting is enabled, B<Match>
+blocks (see below) are optional. Disabled by default.
+
 =item B<E<lt>MatchE<gt>>
 
 One or more B<Match> blocks that define how to match information in the data
 returned by C<libcurl>. The C<curl> plugin uses the same infrastructure that's
 used by the C<tail> plugin, so please see the documentation of the C<tail>
-plugin below on how matches are defined. If the B<MeasureResponseTime> option
-is set to B<true>, B<Match> blocks are optional.
+plugin below on how matches are defined. If the B<MeasureResponseTime> or
+B<MeasureResponseCode> options are set to B<true>, B<Match> blocks are
+optional.
+
+=item B<Timeout> I<Milliseconds>
+
+The B<Timeout> option sets the overall timeout for HTTP requests to B<URL>, in
+milliseconds. By default, the configured B<Interval> is used to set the
+timeout. Prior to version 5.5.0, there was no timeout and requests could hang
+indefinitely. This legacy behaviour can be achieved by setting the value of
+B<Timeout> to 0.
+
+If B<Timeout> is 0 or bigger than the B<Interval>, keep in mind that each slow
+network connection will stall one read thread. Adjust the B<ReadThreads> global
+setting accordingly to prevent this from blocking other plugins.
 
 =back
 
@@ -1176,14 +1606,29 @@ 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>
 
+=item B<Timeout> I<Milliseconds>
+
 These options behave exactly equivalent to the appropriate options of the
 I<cURL> plugin. Please see there for a detailed description.
 
@@ -1219,6 +1664,8 @@ The B<curl_xml plugin> uses B<libcurl> (L<http://curl.haxx.se/>) and B<libxml2>
      VerifyPeer true
      VerifyHost true
      CACert "/path/to/ca.crt"
+     Header "X-Custom-Header: foobar"
+     Post "foo=bar"
 
      <XPath "table[@id=\"magic_level\"]/tr">
        Type "magic_level"
@@ -1270,6 +1717,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>
@@ -1280,6 +1729,8 @@ Examples:
 
 =item B<Post> I<Body>
 
+=item B<Timeout> I<Milliseconds>
+
 These options behave exactly equivalent to the appropriate options of the
 I<cURL plugin>. Please see there for a detailed description.
 
@@ -1509,6 +1960,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
@@ -1623,17 +2084,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
 
@@ -1669,6 +2130,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>
@@ -1789,6 +2264,27 @@ expected from them. This is documented in great detail in L<collectd-exec(5)>.
 
 =back
 
+=head2 Plugin C<fhcount>
+
+The C<fhcount> plugin provides statistics about used, unused and total number of
+file handles.
+
+The I<fhcount plugin> provides the following configuration options:
+
+=over 4
+
+=item B<ValuesAbsolute> B<true>|B<false>
+
+Enables or disables reporting of file handles usage in absolute numbers,
+e.g. file handles used. Defaults to B<true>.
+
+=item B<ValuesPercentage> B<false>|B<true>
+
+Enables or disables reporting of file handles usage in percentages, e.g.
+percent of file handles used. Defaults to B<false>.
+
+=back
+
 =head2 Plugin C<filecount>
 
 The C<filecount> plugin counts the number of files in a certain directory (and
@@ -2132,94 +2628,63 @@ independent from the I<JavaClass> argument passed to B<LoadPlugin>.
 
 =back
 
-=head2 Plugin C<libvirt>
+=head2 Plugin C<load>
 
-This plugin allows CPU, disk and network load to be collected for virtualized
-guests on the machine. This means that these characteristics can be collected
-for guest systems without installing any software on them - collectd only runs
-on the hosting system. The statistics are collected through libvirt
-(L<http://libvirt.org/>).
+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.
 
-Only I<Connection> is required.
+The following configuration options are available:
 
 =over 4
 
-=item B<Connection> I<uri>
+=item B<ReportRelative> B<false>|B<true>
 
-Connect to the hypervisor given by I<uri>. For example if using Xen use:
+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.
 
- Connection "xen:///"
+=back
 
-Details which URIs allowed are given at L<http://libvirt.org/uri.html>.
 
-=item B<RefreshInterval> I<seconds>
+=head2 Plugin C<logfile>
 
-Refresh the list of domains and devices every I<seconds>. The default is 60
-seconds. Setting this to be the same or smaller than the I<Interval> will cause
-the list of domains and devices to be refreshed on every iteration.
+=over 4
 
-Refreshing the devices in particular is quite a costly operation, so if your
-virtualization setup is static you might consider increasing this. If this
-option is set to 0, refreshing is disabled completely.
+=item B<LogLevel> B<debug|info|notice|warning|err>
 
-=item B<Domain> I<name>
+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.
 
-=item B<BlockDevice> I<name:dev>
+Please note that B<debug> is only available if collectd has been compiled with
+debugging support.
 
-=item B<InterfaceDevice> I<name:dev>
+=item B<File> I<File>
 
-=item B<IgnoreSelected> I<true>|I<false>
+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.
 
-Select which domains and devices are collected.
+=item B<Timestamp> B<true>|B<false>
 
-If I<IgnoreSelected> is not given or I<false> then only the listed domains and
-disk/network devices are collected.
+Prefix all lines printed by the current time. Defaults to B<true>.
 
-If I<IgnoreSelected> is I<true> then the test is reversed and the listed
-domains and disk/network devices are ignored, while the rest are collected.
+=item B<PrintSeverity> B<true>|B<false>
 
-The domain name and device names may use a regular expression, if the name is
-surrounded by I</.../> and collectd was compiled with support for regexps.
-
-The default is to collect statistics for all domains and all their devices.
-
-Example:
-
- BlockDevice "/:hdb/"
- IgnoreSelected "true"
-
-Ignore all I<hdb> devices on any domain, but other block devices (eg. I<hda>)
-will be collected.
-
-=item B<HostnameFormat> B<name|uuid|hostname|...>
-
-When the libvirt plugin logs data, it sets the hostname 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. This is useful if you want to track the
-same guest across migrations.
-
-B<hostname> means to use the global B<Hostname> setting, which is probably not
-useful on its own because all guests will appear to have the same name.
-
-You can also specify combinations of these fields. For example B<name uuid>
-means to concatenate the guest name and UUID (with a literal colon character
-between, thus I<"foo:1234-1234-1234-1234">).
-
-=item B<InterfaceFormat> B<name>|B<address>
+When enabled, all lines are prefixed by the severity of the log message, for
+example "warning". Defaults to B<false>.
 
-When the libvirt plugin logs interface data, it sets the name of the collected
-data according to this setting. The default is to use the path as provided by
-the hypervisor (the "dev" property of the target node), which is equal to
-setting B<name>.
+=back
 
-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.
+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.
 
-=back
+=head2 Plugin C<log_logstash>
 
-=head2 Plugin C<logfile>
+The I<log logstash plugin> behaves like the logfile plugin but formats
+messages as JSON events for logstash to parse and input.
 
 =over 4
 
@@ -2238,15 +2703,6 @@ 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.
 
-=item B<Timestamp> B<true>|B<false>
-
-Prefix all lines printed by the current time. Defaults to B<true>.
-
-=item B<PrintSeverity> B<true>|B<false>
-
-When enabled, all lines are prefixed by the severity of the log message, for
-example "warning". Defaults to B<false>.
-
 =back
 
 B<Note>: There is no need to notify the daemon after moving or removing the
@@ -2426,7 +2882,7 @@ B<Synopsis:>
    ShowCPU true
    ShowCPUCores true
    ShowMemory true
-   
+
    ShowTemperatures true
    Temperature vddg
    Temperature vddq
@@ -2435,7 +2891,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:
@@ -2444,7 +2900,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>
 
@@ -2492,7 +2948,7 @@ Fan In
 
 =item fout
 
-Fan Out 
+Fan Out
 
 =item vccp
 
@@ -2533,11 +2989,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
 
@@ -2545,40 +3001,61 @@ 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>
 
-The B<modbus plugin> connects to a Modbus "slave" via Modbus/TCP and reads
-register values. It supports reading single registers (unsigned 16E<nbsp>bit
+The B<modbus plugin> connects to a Modbus "slave" via Modbus/TCP or Modbus/RTU and
+reads register values. It supports reading single registers (unsigned 16E<nbsp>bit
 values), large integer values (unsigned 32E<nbsp>bit values) and floating point
 values (two registers interpreted as IEEE floats in big endian notation).
 
@@ -2587,22 +3064,32 @@ B<Synopsis:>
  <Data "voltage-input-1">
    RegisterBase 0
    RegisterType float
+   RegisterCmd ReadHolding
    Type voltage
    Instance "input-1"
  </Data>
+
  <Data "voltage-input-2">
    RegisterBase 2
    RegisterType float
+   RegisterCmd ReadHolding
    Type voltage
    Instance "input-2"
  </Data>
+
+ <Data "supply-temperature-1">
+   RegisterBase 0
+   RegisterType Int16
+   RegisterCmd ReadHolding
+   Type temperature
+   Instance "temp-1"
+ </Data>
+
  <Host "modbus.example.com">
    Address "192.168.0.42"
    Port    "502"
    Interval 60
-   
+
    <Slave 1>
      Instance "power-supply"
      Collect  "voltage-input-1"
@@ -2610,6 +3097,17 @@ B<Synopsis:>
    </Slave>
  </Host>
 
+ <Host "localhost">
+   Device "/dev/ttyUSB0"
+   Baudrate 38400
+   Interval 20
+
+   <Slave 1>
+     Instance "temperature"
+     Collect  "supply-temperature-1"
+   </Slave>
+ </Host>
+
 =over 4
 
 =item E<lt>B<Data> I<Name>E<gt> blocks
@@ -2633,6 +3131,11 @@ Specifies what kind of data is returned by the device. If the type is B<Int32>,
 B<Uint32> or B<Float>, two 16E<nbsp>bit registers will be read and the data is
 combined into one value. Defaults to B<Uint16>.
 
+=item B<RegisterCmd> B<ReadHolding>|B<ReadInput>
+
+Specifies register type to be collected from device. Works only with libmodbus
+2.9.2 or higher. Defaults to B<ReadHolding>.
+
 =item B<Type> I<Type>
 
 Specifies the "type" (data set) to use when dispatching the value to
@@ -2658,15 +3161,25 @@ Within E<lt>HostE<nbsp>/E<gt> blocks, the following options are allowed:
 
 =item B<Address> I<Hostname>
 
-Specifies the node name (the actual network address) used to connect to the
-host. This may be an IP address or a hostname. Please note that the used
-I<libmodbus> library only supports IPv4 at the moment.
+For Modbus/TCP, specifies the node name (the actual network address) used to
+connect to the host. This may be an IP address or a hostname. Please note that
+the used I<libmodbus> library only supports IPv4 at the moment.
 
 =item B<Port> I<Service>
 
-Specifies the port used to connect to the host. The port can either be given as
-a number or as a service name. Please note that the I<Service> argument must be
-a string, even if ports are given in their numerical form. Defaults to "502".
+for Modbus/TCP, specifies the port used to connect to the host. The port can
+either be given as a number or as a service name. Please note that the
+I<Service> argument must be a string, even if ports are given in their numerical
+form. Defaults to "502".
+
+=item B<Device> I<Devicenode>
+
+For Modbus/RTU, specifies the path to the serial device being used.
+
+=item B<Baudrate> I<Baudrate>
+
+For Modbus/RTU, specifies the baud rate of the serial device.
+Note, connections currently support only 8/N/1.
 
 =item B<Interval> I<Interval>
 
@@ -2675,7 +3188,7 @@ host. By default the global B<Interval> setting will be used.
 
 =item E<lt>B<Slave> I<ID>E<gt>
 
-Over each TCP connection, multiple Modbus devices may be reached. The slave ID
+Over each connection, multiple Modbus devices may be reached. The slave ID
 is used to specify which device should be addressed. For each device you want
 to query, one B<Slave> block must be given.
 
@@ -2733,9 +3246,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
@@ -2750,6 +3265,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>.
@@ -2788,6 +3308,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>
@@ -2801,6 +3326,10 @@ privileges. See the B<User> documentation above. Defaults to B<false>.
 If enabled, the plugin sends a notification if the replication slave I/O and /
 or SQL threads are not running. Defaults to B<false>.
 
+=item B<ConnectTimeout> I<Seconds>
+
+Sets the connect timeout for the MySQL client.
+
 =back
 
 =head2 Plugin C<netapp>
@@ -2835,7 +3364,7 @@ Required capabilities are documented below.
     User          "username"
     Password      "aef4Aebe"
     Interval      30
-    
+
     <WAFL>
       Interval 30
       GetNameCache   true
@@ -2843,12 +3372,12 @@ Required capabilities are documented below.
       GetBufferCache true
       GetInodeCache  true
     </WAFL>
-    
+
     <Disks>
       Interval 30
       GetBusy true
     </Disks>
-    
+
     <VolumePerf>
       Interval 30
       GetIO      "volume0"
@@ -2858,7 +3387,7 @@ Required capabilities are documented below.
       GetLatency "volume0"
       IgnoreSelectedLatency false
     </VolumePerf>
-    
+
     <VolumeUsage>
       Interval 30
       GetCapacity "vol0"
@@ -2868,15 +3397,15 @@ Required capabilities are documented below.
       GetSnapshot "vol3"
       IgnoreSelectedSnapshot false
     </VolumeUsage>
-    
+
     <Quota>
       Interval 60
     </Quota>
-    
+
     <Snapvault>
       Interval 30
     </Snapvault>
-    
+
     <System>
       Interval 30
       GetCPULoad     true
@@ -3437,7 +3966,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">
@@ -3500,6 +4029,12 @@ behavior is to let the kernel choose the appropriate interface. Be warned
 that the manual selection of an interface for unicast traffic is only
 necessary in rare cases.
 
+=item B<ResolveInterval> I<Seconds>
+
+Sets the interval at which to re-resolve the DNS for the I<Host>. This is
+useful to force a regular DNS lookup to support a high availability setup. If
+not specified, re-resolves are never attempted.
+
 =back
 
 =item B<E<lt>Listen> I<Host> [I<Port>]B<E<gt>>
@@ -3644,6 +4179,12 @@ 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<Timeout> I<Milliseconds>
+
+The B<Timeout> option sets the overall timeout for HTTP requests to B<URL>, in
+milliseconds. By default, the configured B<Interval> is used to set the
+timeout.
+
 =back
 
 =head2 Plugin C<notify_desktop>
@@ -3826,13 +4367,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>
@@ -3853,14 +4417,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
@@ -3868,6 +4441,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
@@ -3886,6 +4461,70 @@ short: If it works for you: Great! But keep in mind that the config I<might>
 change, though this is unlikely. Oh, and if you want to help improving this
 plugin, just send a short notice to the mailing list. ThanksE<nbsp>:)
 
+=head2 Plugin C<openldap>
+
+To use the C<openldap> plugin you first need to configure the I<OpenLDAP>
+server correctly. The backend database C<monitor> needs to be loaded and
+working. See slapd-monitor(5) for the details.
+
+The configuration of the C<openldap> plugin consists of one or more B<Instance>
+blocks. Each block requires one string argument as the instance name. For
+example:
+
+ <Plugin "openldap">
+   <Instance "foo">
+     URL "ldap://localhost/"
+   </Instance>
+   <Instance "bar">
+     URL "ldaps://localhost/"
+   </Instance>
+ </Plugin>
+
+The instance name will be used as the I<plugin instance>. To emulate the old
+(versionE<nbsp>4) behavior, you can use an empty string (""). In order for the
+plugin to work correctly, each instance name must be unique. This is not
+enforced by the plugin and it is your responsibility to ensure it is.
+
+The following options are accepted within each B<Instance> block:
+
+=over 4
+
+=item B<URL> I<ldap://host/binddn>
+
+Sets the URL to use to connect to the I<OpenLDAP> server. This option is
+I<mandatory>.
+
+=item B<StartTLS> B<true|false>
+
+Defines whether TLS must be used when connecting to the I<OpenLDAP> server.
+Disabled by default.
+
+=item B<VerifyHost> B<true|false>
+
+Enables or disables peer host name verification. If enabled, the plugin checks
+if the C<Common Name> or a C<Subject Alternate Name> field of the SSL
+certificate matches the host name provided by the B<URL> option. If this
+identity check fails, the connection is aborted. Enabled by default.
+
+=item B<CACert> I<File>
+
+File that holds one or more SSL certificates. If you want to use TLS/SSL you
+may possibly need this option. What CA certificates are checked by default
+depends on the distribution you use and can be changed with the usual ldap
+client configuration mechanisms. See ldap.conf(5) for the details.
+
+=item B<Timeout> I<Seconds>
+
+Sets the timeout value for ldap operations. Defaults to B<-1> which results in
+an infinite timeout.
+
+=item B<Version> I<Version>
+
+An integer which sets the LDAP protocol version number to use when connecting
+to the I<OpenLDAP> server. Defaults to B<3> for using I<LDAPv3>.
+
+=back
+
 =head2 Plugin C<openvpn>
 
 The OpenVPN plugin reads a status file maintained by OpenVPN and gathers
@@ -4546,6 +5185,10 @@ Specify the username to be used when connecting to the server.
 
 Specify the password to be used when connecting to the server.
 
+=item B<ExpireDelay> I<delay>
+
+Skip expired values in query output.
+
 =item B<SSLMode> I<disable>|I<allow>|I<prefer>|I<require>
 
 Specify whether to use an SSL connection when contacting the server. The
@@ -4571,6 +5214,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
@@ -4910,6 +5560,10 @@ which configures the connection parameters for this node.
         Host "localhost"
         Port "6379"
         Timeout 2000
+        <Query "LLEN myqueue">
+          Type "queue_length"
+          Instance "myqueue"
+        <Query>
     </Node>
   </Plugin>
 
@@ -4947,6 +5601,22 @@ read function is blocking, you should keep this value as low as possible. Keep
 in mind that the sum of all B<Timeout> values for all B<Nodes> should be lower
 than B<Interval> defined globally.
 
+=item B<Query> I<Querystring>
+
+The B<Query> block identifies a query to execute against the redis server.
+There may be an arbitrary number of queries to execute.
+
+=item B<Type> I<Collectd type>
+
+Within a query definition, a valid collectd type to use as when submitting
+the result of the query. When not supplied, will default to B<gauge>.
+
+=item B<Instance> I<Type instance>
+
+Within a query definition, an optional type instance to use when submitting
+the result of the query. When not supplied will default to the escaped
+command, up to 64 chars.
+
 =back
 
 =head2 Plugin C<rrdcached>
@@ -5288,6 +5958,40 @@ measurements are discarded.
 
 =back
 
+=head2 Plugin C<smart>
+
+The C<smart> plugin collects SMART information from physical
+disks. Values collectd include temperature, power cycle count, poweron
+time and bad sectors. Also, all SMART attributes are collected along
+with the normalized current value, the worst value, the threshold and
+a human readable value.
+
+Using the following two options you can ignore some disks or configure the
+collection only of specific disks.
+
+=over 4
+
+=item B<Disk> I<Name>
+
+Select the disk I<Name>. Whether it is collected or ignored depends on the
+B<IgnoreSelected> setting, see below. As with other plugins that use the
+daemon's ignorelist functionality, a string that starts and ends with a slash
+is interpreted as a regular expression. Examples:
+
+  Disk "sdd"
+  Disk "/hda[34]/"
+
+=item B<IgnoreSelected> B<true>|B<false>
+
+Sets whether selected disks, i.E<nbsp>e. the ones matches by any of the B<Disk>
+statements, are ignored or if all other disks are ignored. The behavior
+(hopefully) is intuitive: If no B<Disk> option is configured, all disks are
+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.
+
+=back
+
 =head2 Plugin C<snmp>
 
 Since the configuration of the C<snmp plugin> is a little more complicated than
@@ -5378,6 +6082,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>
@@ -5513,6 +6230,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"
@@ -5539,6 +6257,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:
 
@@ -5594,6 +6315,8 @@ Use the last number found.
 The matched number is a counter. Simply I<sets> the internal counter to this
 value. Variants exist for C<COUNTER>, C<DERIVE>, and C<ABSOLUTE> data sources.
 
+=item B<GaugeAdd>
+
 =item B<CounterAdd>
 
 =item B<DeriveAdd>
@@ -5602,6 +6325,8 @@ Add the matched value to the internal counter. In case of B<DeriveAdd>, the
 matched number may be negative, which will effectively subtract from the
 internal counter.
 
+=item B<GaugeInc>
+
 =item B<CounterInc>
 
 =item B<DeriveInc>
@@ -5821,6 +6546,11 @@ connections a mail server or news server has to other mail or news servers, or
 how many connections a web proxy holds to web servers. You have to give the
 port in numeric form.
 
+=item B<AllPortsSummary> I<true>|I<false>
+
+If this option is set to I<true> a summary of statistics from all connections
+are collectd. This option defaults to I<false>.
+
 =back
 
 =head2 Plugin C<thermal>
@@ -5878,6 +6608,79 @@ Default: B<1978>
 
 =back
 
+=head2 Plugin C<turbostat>
+
+The I<Turbostat plugin> reads CPU frequency and C-state residency on modern
+Intel processors by using the new Model Specific Registers.
+
+=over 4
+
+=item B<CoreCstates> I<Bitmask(Integer)>
+
+Bitmask of the list of core C states supported by the processor.
+This option should only be used if the automated detection fails.
+Default value extracted from the cpu model and family.
+
+Currently supported C-states (by this plugin): 3, 6, 7
+
+Example: (1<<3)+(1<<6)+(1<<7) = 392 for all states
+
+=item B<PackageCstates> I<Bitmask(Integer)>
+
+Bitmask of the list of pacages C states supported by the processor.
+This option should only be used if the automated detection fails.
+Default value extracted from the cpu model and family.
+
+Currently supported C-states (by this plugin): 2, 3, 6, 7, 8, 9, 10
+
+Example: (1<<2)+(1<<3)+(1<<6)+(1<<7) = 396 for states 2, 3, 6 and 7
+
+=item B<SystemManagementInterrupt> I<true>|I<false>
+
+Boolean enabling the collection of the I/O System-Management Interrupt
+counter'. This option should only be used if the automated detection
+fails or if you want to disable this feature.
+
+=item B<DigitalTemperatureSensor> I<true>|I<false>
+
+Boolean enabling the collection of the temperature of each core.
+This option should only be used if the automated detectionfails or 
+if you want to disable this feature.
+
+=item B<DigitalTemperatureSensor> I<true>|I<false>
+
+Boolean enabling the collection of the temperature of each package.
+This option should only be used if the automated detectionfails or 
+if you want to disable this feature.
+
+=item B<TCCActivationTemp> I<Temperature>
+
+Thermal Control Circuit Activation Temperature of the installed
+CPU. This temperature is used when collecting the temperature of
+cores or packages. This option should only be used if the automated
+detection fails. Default value extracted from B<MSR_IA32_TEMPERATURE_TARGET>
+
+=item B<RunningAveragePowerLimit> I<Bitmask(Integer)>
+
+Bitmask of the list of elements to be thermally monitored. This option
+should only be used if the automated detection fails or if you want to
+disable some collections. The different bits of this bitmask accepted
+by this plugin are:
+
+=over 4
+
+=item 0 ('1'): Package
+
+=item 1 ('2'): DRAM
+
+=item 2 ('4'): Cores
+
+=item 3 ('8'): Embedded graphic device
+
+=back
+
+=back
+
 =head2 Plugin C<unixsock>
 
 =over 4
@@ -5950,22 +6753,35 @@ Take the UUID from the given file (default I</etc/uuid>).
 =head2 Plugin C<varnish>
 
 The I<varnish plugin> collects information about Varnish, an HTTP accelerator.
+It collects a subset of the values displayed by L<varnishstat(1)>, and
+organizes them in categories which can be enabled or disabled. Currently only
+metrics shown in L<varnishstat(1)>'s I<MAIN> section are collected. The exact
+meaning of each metric can be found in L<varnish-counters(7)>.
 
 Synopsis:
 
  <Plugin "varnish">
    <Instance "example">
+     CollectBackend     true
+     CollectBan         false
      CollectCache       true
      CollectConnections true
-     CollectBackend     true
-     CollectSHM         true
+     CollectDirectorDNS false
      CollectESI         false
      CollectFetch       false
      CollectHCB         false
+     CollectObjects     false
+     CollectPurge       false
+     CollectSession     false
+     CollectSHM         true
      CollectSMA         false
      CollectSMS         false
      CollectSM          false
+     CollectStruct      false
      CollectTotals      false
+     CollectUptime      false
+     CollectVCL         false
+     CollectVSM         false
      CollectWorkers     false
    </Instance>
  </Plugin>
@@ -5979,29 +6795,24 @@ Inside each E<lt>B<Instance>E<gt> blocks, the following options are recognized:
 
 =over 4
 
-=item B<CollectCache> B<true>|B<false>
-
-Cache hits and misses. True by default.
-
-=item B<CollectConnections> B<true>|B<false>
-
-Number of client connections received, accepted and dropped. True by default.
-
 =item B<CollectBackend> B<true>|B<false>
 
 Back-end connection statistics, such as successful, reused,
 and closed connections. True by default.
 
-=item B<CollectSHM> B<true>|B<false>
-
-Statistics about the shared memory log, a memory region to store
-log messages which is flushed to disk when full. True by default.
-
 =item B<CollectBan> B<true>|B<false>
 
 Statistics about ban operations, such as number of bans added, retired, and
 number of objects tested against ban operations. Only available with Varnish
-3.x. False by default.
+3.x and above. False by default.
+
+=item B<CollectCache> B<true>|B<false>
+
+Cache hits and misses. True by default.
+
+=item B<CollectConnections> B<true>|B<false>
+
+Number of client connections received, accepted and dropped. True by default.
 
 =item B<CollectDirectorDNS> B<true>|B<false>
 
@@ -6035,7 +6846,14 @@ number of objects tested against purge operations. Only available with Varnish
 =item B<CollectSession> B<true>|B<false>
 
 Client session statistics. Number of past and current sessions, session herd and
-linger counters, etc. False by default.
+linger counters, etc. False by default. Note that if using Varnish 4.x, some
+metrics found in the Connections and Threads sections with previous versions of
+Varnish have been moved here.
+
+=item B<CollectSHM> B<true>|B<false>
+
+Statistics about the shared memory log, a memory region to store
+log messages which is flushed to disk when full. True by default.
 
 =item B<CollectSMA> B<true>|B<false>
 
@@ -6066,18 +6884,122 @@ the number of requests and bytes transferred. False by default.
 
 =item B<CollectUptime> B<true>|B<false>
 
-Varnish uptime. False by default.
+Varnish uptime. Only available with Varnish 3.x and above. False by default.
 
 =item B<CollectVCL> B<true>|B<false>
 
 Number of total (available + discarded) VCL (config files). False by default.
 
-=item B<CollectWorkers> B<true>|B<false>
+=item B<CollectVSM> B<true>|B<false>
+
+Collect statistics about Varnish's shared memory usage (used by the logging and
+statistics subsystems). Only available with Varnish 4.x. False by default.
+
+=item B<CollectWorkers> B<true>|B<false>
 
 Collect statistics about worker threads. False by default.
 
 =back
 
+=head2 Plugin C<virt>
+
+This plugin allows CPU, disk and network load to be collected for virtualized
+guests on the machine. This means that these metrics can be collected for guest
+systems without installing any software on them - I<collectd> only runs on the
+host system. The statistics are collected through libvirt
+(L<http://libvirt.org/>).
+
+Only I<Connection> is required.
+
+=over 4
+
+=item B<Connection> I<uri>
+
+Connect to the hypervisor given by I<uri>. For example if using Xen use:
+
+ Connection "xen:///"
+
+Details which URIs allowed are given at L<http://libvirt.org/uri.html>.
+
+=item B<RefreshInterval> I<seconds>
+
+Refresh the list of domains and devices every I<seconds>. The default is 60
+seconds. Setting this to be the same or smaller than the I<Interval> will cause
+the list of domains and devices to be refreshed on every iteration.
+
+Refreshing the devices in particular is quite a costly operation, so if your
+virtualization setup is static you might consider increasing this. If this
+option is set to 0, refreshing is disabled completely.
+
+=item B<Domain> I<name>
+
+=item B<BlockDevice> I<name:dev>
+
+=item B<InterfaceDevice> I<name:dev>
+
+=item B<IgnoreSelected> B<true>|B<false>
+
+Select which domains and devices are collected.
+
+If I<IgnoreSelected> is not given or B<false> then only the listed domains and
+disk/network devices are collected.
+
+If I<IgnoreSelected> is B<true> then the test is reversed and the listed
+domains and disk/network devices are ignored, while the rest are collected.
+
+The domain name and device names may use a regular expression, if the name is
+surrounded by I</.../> and collectd was compiled with support for regexps.
+
+The default is to collect statistics for all domains and all their devices.
+
+Example:
+
+ BlockDevice "/:hdb/"
+ IgnoreSelected "true"
+
+Ignore all I<hdb> devices on any domain, but other block devices (eg. I<hda>)
+will be collected.
+
+=item B<HostnameFormat> B<name|uuid|hostname|...>
+
+When the virt plugin logs data, it sets the hostname 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. This is useful if you want to track the
+same guest across migrations.
+
+B<hostname> means to use the global B<Hostname> setting, which is probably not
+useful on its own because all guests will appear to have the same name.
+
+You can also specify combinations of these fields. For example B<name uuid>
+means to concatenate the guest name and UUID (with a literal colon character
+between, thus I<"foo:1234-1234-1234-1234">).
+
+At the moment of writing (collectd-5.5), hostname string is limited to 62
+characters. In case when combination of fields exceeds 62 characters,
+hostname will be truncated without a warning.
+
+=item B<InterfaceFormat> B<name>|B<address>
+
+When the virt plugin logs interface data, it sets the name of the collected
+data according to this setting. The default is to use the path as provided by
+the hypervisor (the "dev" property of the target node), which is equal to
+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 virt 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<vmem>
 
 The C<vmem> plugin collects information about the usage of virtual memory.
@@ -6194,6 +7116,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
@@ -6249,25 +7224,31 @@ want to use authentication all three fields must be set.
 
 =head2 Plugin C<write_http>
 
-This output plugin submits values to an http server by POST them using the
-PUTVAL plain-text protocol. Each destination you want to post data to needs to
-have one B<URL> block, within which the destination can be configured further,
-for example by specifying authentication data.
+This output plugin submits values to an HTTP server using POST requests and
+encoding metrics with JSON or using the C<PUTVAL> command described in
+L<collectd-unixsock(5)>.
 
 Synopsis:
 
  <Plugin "write_http">
-   <URL "http://example.com/post-collectd">
+   <Node "example">
+     URL "http://example.com/post-collectd"
      User "collectd"
      Password "weCh3ik0"
-   </URL>
+     Format JSON
+   </Node>
  </Plugin>
 
-B<URL> blocks need one string argument which is used as the URL to which data
-is posted. The following options are understood within B<URL> blocks.
+The plugin can send values to multiple HTTP servers by specifying one
+E<lt>B<Node>E<nbsp>I<Name>E<gt> block for each server. Within each B<Node>
+block, the following options are available:
 
 =over 4
 
+=item B<URL> I<URL>
+
+URL to which the values are submitted to. Mandatory.
+
 =item B<User> I<Username>
 
 Optional user name needed for authentication.
@@ -6295,6 +7276,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
@@ -6306,8 +7314,143 @@ Defaults to B<Command>.
 =item B<StoreRates> B<true|false>
 
 If set to B<true>, convert counter values to rates. If set to B<false> (the
-default) counter values are stored as is, i.E<nbsp>e. as an increasing integer
-number.
+default) counter values are stored as is, i.e. as an increasing integer number.
+
+=item B<BufferSize> I<Bytes>
+
+Sets the send buffer size to I<Bytes>. By increasing this buffer, less HTTP
+requests will be generated, but more metrics will be batched / metrics are
+cached for longer before being sent, introducing additional delay until they
+are available on the server side. I<Bytes> must be at least 1024 and cannot
+exceed the size of an C<int>, i.e. 2E<nbsp>GByte.
+Defaults to C<4096>.
+
+=item B<LowSpeedLimit> I<Bytes per Second>
+
+Sets the minimal transfer rate in I<Bytes per Second> below which the
+connection with the HTTP server will be considered too slow and aborted. All
+the data submitted over this connection will probably be lost. Defaults to 0,
+which means no minimum transfer rate is enforced.
+
+=item B<Timeout> I<Timeout>
+
+Sets the maximum time in milliseconds given for HTTP POST operations to
+complete. When this limit is reached, the POST operation will be aborted, and
+all the data in the current send buffer will probably be lost. Defaults to 0,
+which means the connection never times out.
+
+The C<write_http> plugin regularly submits the collected values to the HTTP
+server. How frequently this happens depends on how much data you are collecting
+and the size of B<BufferSize>. The optimal value to set B<Timeout> to is
+slightly below this interval, which you can estimate by monitoring the network
+traffic between collectd and the HTTP server.
+
+=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
+C<E<lt>metricE<gt> E<lt>valueE<gt> E<lt>timestampE<gt>\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
+C<E<lt>prefixE<gt>E<lt>hostE<gt>E<lt>postfixE<gt>E<lt>pluginE<gt>E<lt>typeE<gt>E<lt>nameE<gt>>
+
+=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
+C<E<lt>prefixE<gt>E<lt>hostE<gt>E<lt>postfixE<gt>E<lt>pluginE<gt>E<lt>typeE<gt>E<lt>nameE<gt>>
+
+=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 C<_> (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
 
@@ -6368,7 +7511,7 @@ The B<Timeout> option sets the socket connection timeout, in milliseconds.
 
 =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.
 
@@ -6384,6 +7527,7 @@ Synopsis:
      TTLFactor 2.0
    </Node>
    Tag "foobar"
+   Attribute "foo" "bar"
  </Plugin>
 
 The following options are understood by the I<write_riemann plugin>:
@@ -6410,7 +7554,26 @@ Service name or port number to connect to. Defaults to C<5555>.
 =item B<Protocol> B<UDP>|B<TCP>
 
 Specify the protocol to use when communicating with I<Riemann>. Defaults to
-B<UDP>.
+B<TCP>.
+
+=item B<Batch> B<true>|B<false>
+
+If set to B<true> and B<Protocol> is set to B<TCP>,
+events will be batched in memory and flushed at
+regular intervals or when B<BatchMaxSize> is exceeded.
+
+Notifications are not batched and sent as soon as possible.
+
+When enabled, it can occur that events get processed by the Riemann server
+close to or after their expiration time. Tune the B<TTLFactor> and
+B<BatchMaxSize> settings according to the amount of values collected, if this
+is an issue.
+
+Defaults to true
+
+=item B<BatchMaxSize> I<size>
+
+Maximum payload size for a riemann packet. Defaults to 8192
 
 =item B<StoreRates> B<true>|B<false>
 
@@ -6437,6 +7600,23 @@ 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>.
+
+=item B<EventServicePrefix> I<String>
+
+Add the given string as a prefix to the event service name.
+If B<EventServicePrefix> not set or set to an empty string (""),
+no prefix will be used.
+
 =back
 
 =item B<Tag> I<String>
@@ -6444,6 +7624,146 @@ 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
+
+=head2 Plugin C<write_sensu>
+
+The I<write_sensu plugin> will send values to I<Sensu>, a powerful stream
+aggregation and monitoring system. The plugin sends I<JSON> encoded data to
+a local I<Sensu> client using a TCP socket.
+
+At the moment, the I<write_sensu plugin> does not send over a collectd_host
+parameter so it is not possible to use one collectd instance as a gateway for
+others. Each collectd host must pair with one I<Sensu> client.
+
+Synopsis:
+
+ <Plugin "write_sensu">
+   <Node "example">
+     Host "localhost"
+     Port "3030"
+     StoreRates true
+     AlwaysAppendDS false
+     MetricHandler "influx"
+     MetricHandler "default"
+     NotificationHandler "flapjack"
+     NotificationHandler "howling_monkey"
+     Notifications true
+   </Node>
+   Tag "foobar"
+   Attribute "foo" "bar"
+ </Plugin>
+
+The following options are understood by the I<write_sensu plugin>:
+
+=over 4
+
+=item E<lt>B<Node> I<Name>E<gt>
+
+The plugin's configuration consists of one or more B<Node> blocks. Each block
+is given a unique I<Name> and specifies one connection to an instance of
+I<Sensu>. Inside the B<Node> block, the following per-connection options are
+understood:
+
+=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<3030>.
+
+=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<collectd_data_source_type> tag: If
+B<StoreRates> is enabled, converted values will have "rate" appended to the
+data source type, e.g.  C<collectd_data_source_type:derive:rate>.
+
+=item B<AlwaysAppendDS> B<false>|B<true>
+
+If set the B<true>, append the name of the I<Data Source> (DS) to the
+"service", i.e. the field that, together with the "host" field, uniquely
+identifies a metric in I<Sensu>. If set to B<false> (the default), this is
+only done when there is more than one DS.
+
+=item B<Notifications> B<false>|B<true>
+
+If set to B<true>, create I<Sensu> events for notifications. This is B<false>
+by default. At least one of B<Notifications> or B<Metrics> should be enabled.
+
+=item B<Metrics> B<false>|B<true>
+
+If set to B<true>, create I<Sensu> events for metrics. This is B<false>
+by default. At least one of B<Notifications> or B<Metrics> should be enabled.
+
+
+=item B<Separator> I<String>
+
+Sets the separator for I<Sensu> metrics name or checks. Defaults to "/".
+
+=item B<MetricHandler> I<String>
+
+Add a handler that will be set when metrics are sent to I<Sensu>. You can add
+several of them, one per line. Defaults to no handler.
+
+=item B<NotificationHandler> I<String>
+
+Add a handler that will be set when notifications are sent to I<Sensu>. You can
+add several of them, one per line. Defaults to no handler.
+
+=item B<EventServicePrefix> I<String>
+
+Add the given string as a prefix to the event service name.
+If B<EventServicePrefix> not set or set to an empty string (""),
+no prefix will be used.
+
+=back
+
+=item B<Tag> I<String>
+
+Add the given string as an additional tag to the metric being sent to
+I<Sensu>.
+
+=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<Sensu>.
+
+=back
+
+=head2 Plugin C<zookeeper>
+
+The I<zookeeper plugin> will collect statistics from a I<Zookeeper> server
+using the mntr command.  It requires Zookeeper 3.4.0+ and access to the
+client port.
+
+B<Synopsis:>
+
+ <Plugin "zookeeper">
+   Host "127.0.0.1"
+   Port "2181"
+ </Plugin>
+
+=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<2181>.
+
 =back
 
 =head1 THRESHOLD CONFIGURATION
@@ -7115,7 +8435,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
@@ -7297,7 +8617,7 @@ Example:
  <Target "replace">
    # Replace "example.net" with "example.com"
    Host "\\<example.net\\>" "example.com"
+
    # Strip "www." from hostnames
    Host "\\<www\\." ""
  </Target>
@@ -7380,6 +8700,6 @@ L<sensors(1)>
 
 =head1 AUTHOR
 
-Florian Forster E<lt>octo@verplant.orgE<gt>
+Florian Forster E<lt>octo@collectd.orgE<gt>
 
 =cut
diff --git a/src/collectd.h b/src/collectd.h
deleted file mode 100644 (file)
index 1b1bc49..0000000
+++ /dev/null
@@ -1,301 +0,0 @@
-/**
- * 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.
- *
- * 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
- *
- * Authors:
- *   Florian octo Forster <octo at verplant.org>
- **/
-
-#ifndef COLLECTD_H
-#define COLLECTD_H
-
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <stdio.h>
-#if HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-#if HAVE_SYS_STAT_H
-# include <sys/stat.h>
-#endif
-#if STDC_HEADERS
-# include <stdlib.h>
-# include <stddef.h>
-#else
-# if HAVE_STDLIB_H
-#  include <stdlib.h>
-# endif
-#endif
-#if HAVE_STRING_H
-# if !STDC_HEADERS && HAVE_MEMORY_H
-#  include <memory.h>
-# endif
-# include <string.h>
-#endif
-#if HAVE_STRINGS_H
-# include <strings.h>
-#endif
-#if HAVE_INTTYPES_H
-# include <inttypes.h>
-#endif
-#if HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#if HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-#if HAVE_SYS_WAIT_H
-# include <sys/wait.h>
-#endif
-#ifndef WEXITSTATUS
-# define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
-#endif
-#ifndef WIFEXITED
-# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
-#endif
-#if HAVE_SIGNAL_H
-# include <signal.h>
-#endif
-#if HAVE_FCNTL_H
-# include <fcntl.h>
-#endif
-#if HAVE_ERRNO_H
-# include <errno.h>
-#endif
-#if HAVE_LIMITS_H
-# include <limits.h>
-#endif
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
-
-#if HAVE_ASSERT_H
-# include <assert.h>
-#else
-# define assert(...) /* nop */
-#endif
-
-#if !defined(HAVE__BOOL) || !HAVE__BOOL
-typedef int _Bool;
-# undef HAVE__BOOL
-# define HAVE__BOOL 1
-#endif
-
-#if NAN_STATIC_DEFAULT
-# include <math.h>
-/* #endif NAN_STATIC_DEFAULT*/
-#elif NAN_STATIC_ISOC
-# ifndef __USE_ISOC99
-#  define DISABLE_ISOC99 1
-#  define __USE_ISOC99 1
-# endif /* !defined(__USE_ISOC99) */
-# include <math.h>
-# if DISABLE_ISOC99
-#  undef DISABLE_ISOC99
-#  undef __USE_ISOC99
-# endif /* DISABLE_ISOC99 */
-/* #endif NAN_STATIC_ISOC */
-#elif NAN_ZERO_ZERO
-# include <math.h>
-# ifdef NAN
-#  undef NAN
-# endif
-# define NAN (0.0 / 0.0)
-# ifndef isnan
-#  define isnan(f) ((f) != (f))
-# endif /* !defined(isnan) */
-# ifndef isfinite
-#  define isfinite(f) (((f) - (f)) == 0.0)
-# endif
-# ifndef isinf
-#  define isinf(f) (!isfinite(f) && !isnan(f))
-# endif
-#endif /* NAN_ZERO_ZERO */
-
-/* Try really, really hard to determine endianess. Under NexentaStor 1.0.2 this
- * information is in <sys/isa_defs.h>, possibly some other Solaris versions do
- * this too.. */
-#if HAVE_ENDIAN_H
-# include <endian.h>
-#elif HAVE_SYS_ISA_DEFS_H
-# include <sys/isa_defs.h>
-#endif
-
-#ifndef BYTE_ORDER
-# if defined(_BYTE_ORDER)
-#  define BYTE_ORDER _BYTE_ORDER
-# elif defined(__BYTE_ORDER)
-#  define BYTE_ORDER __BYTE_ORDER
-# elif defined(__DARWIN_BYTE_ORDER)
-#  define BYTE_ORDER __DARWIN_BYTE_ORDER
-# endif
-#endif
-#ifndef BIG_ENDIAN
-# if defined(_BIG_ENDIAN)
-#  define BIG_ENDIAN _BIG_ENDIAN
-# elif defined(__BIG_ENDIAN)
-#  define BIG_ENDIAN __BIG_ENDIAN
-# elif defined(__DARWIN_BIG_ENDIAN)
-#  define BIG_ENDIAN __DARWIN_BIG_ENDIAN
-# endif
-#endif
-#ifndef LITTLE_ENDIAN
-# if defined(_LITTLE_ENDIAN)
-#  define LITTLE_ENDIAN _LITTLE_ENDIAN
-# elif defined(__LITTLE_ENDIAN)
-#  define LITTLE_ENDIAN __LITTLE_ENDIAN
-# elif defined(__DARWIN_LITTLE_ENDIAN)
-#  define LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
-# endif
-#endif
-#ifndef BYTE_ORDER
-# if defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN)
-#  undef BIG_ENDIAN
-#  define BIG_ENDIAN 4321
-#  define LITTLE_ENDIAN 1234
-#  define BYTE_ORDER BIG_ENDIAN
-# elif !defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN)
-#  undef LITTLE_ENDIAN
-#  define BIG_ENDIAN 4321
-#  define LITTLE_ENDIAN 1234
-#  define BYTE_ORDER LITTLE_ENDIAN
-# endif
-#endif
-#if !defined(BYTE_ORDER) || !defined(BIG_ENDIAN)
-# error "Cannot determine byte order"
-#endif
-
-#if HAVE_DIRENT_H
-# include <dirent.h>
-# define NAMLEN(dirent) strlen((dirent)->d_name)
-#else
-# define dirent direct
-# define NAMLEN(dirent) (dirent)->d_namlen
-# if HAVE_SYS_NDIR_H
-#  include <sys/ndir.h>
-# endif
-# if HAVE_SYS_DIR_H
-#  include <sys/dir.h>
-# endif
-# if HAVE_NDIR_H
-#  include <ndir.h>
-# endif
-#endif
-
-#if HAVE_STDARG_H
-# include <stdarg.h>
-#endif
-#if HAVE_CTYPE_H
-# include <ctype.h>
-#endif
-#if HAVE_SYS_PARAM_H
-# include <sys/param.h>
-#endif
-
-#if HAVE_KSTAT_H
-# include <kstat.h>
-#endif
-
-#ifndef PACKAGE_NAME
-#define PACKAGE_NAME "collectd"
-#endif
-
-#ifndef PREFIX
-#define PREFIX "/opt/" PACKAGE_NAME
-#endif
-
-#ifndef SYSCONFDIR
-#define SYSCONFDIR PREFIX "/etc"
-#endif
-
-#ifndef CONFIGFILE
-#define CONFIGFILE SYSCONFDIR"/collectd.conf"
-#endif
-
-#ifndef LOCALSTATEDIR
-#define LOCALSTATEDIR PREFIX "/var"
-#endif
-
-#ifndef PKGLOCALSTATEDIR
-#define PKGLOCALSTATEDIR PREFIX "/var/lib/" PACKAGE_NAME
-#endif
-
-#ifndef PIDFILE
-#define PIDFILE PREFIX "/var/run/" PACKAGE_NAME ".pid"
-#endif
-
-#ifndef PLUGINDIR
-#define PLUGINDIR PREFIX "/lib/" PACKAGE_NAME
-#endif
-
-#ifndef PKGDATADIR
-#define PKGDATADIR PREFIX "/share/" PACKAGE_NAME
-#endif
-
-#ifndef COLLECTD_GRP_NAME
-# define COLLECTD_GRP_NAME "collectd"
-#endif
-
-#ifndef COLLECTD_DEFAULT_INTERVAL
-# define COLLECTD_DEFAULT_INTERVAL 10.0
-#endif
-
-/* Remove GNU specific __attribute__ settings when using another compiler */
-#if !__GNUC__
-# define __attribute__(x) /**/
-#endif
-
-#if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
-# undef strcpy
-# undef strcat
-# undef strtok
-# pragma GCC poison strcpy strcat strtok
-#endif
-
-/* 
- * Special hack for the perl plugin: Because the later included perl.h defines
- * a macro which is never used, but contains `sprintf', we cannot poison that
- * identifies just yet. The parl plugin will do that itself once perl.h is
- * included.
- */
-#ifndef DONT_POISON_SPRINTF_YET
-# if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
-#  undef sprintf
-#  pragma GCC poison sprintf
-# endif
-#endif
-
-#ifndef GAUGE_FORMAT
-# define GAUGE_FORMAT "%.15g"
-#endif
-
-/* Type for time as used by "utils_time.h" */
-typedef uint64_t cdtime_t;
-
-extern char     hostname_g[];
-extern cdtime_t interval_g;
-extern int      timeout_g;
-
-#endif /* COLLECTD_H */
index 2f7b9f707439c795fcf85acfaede29ec39821a2e..fb0403bbcb86823c25c67b74a3461b6b85cbde7b 100644 (file)
@@ -49,7 +49,11 @@ config-option.
 
 Don't fork to the background. I<collectd> will also B<not> close standard file
 descriptors, detach from the session nor write a pid file. This is mainly
-thought for 'supervising' init replacements such as I<runit>.
+thought for 'supervising' init replacements such as I<runit>. If using
+I<upstart> or I<systemd> though, starting with version 5.5.0 I<collectd> is
+able to notify these two init replacements, and B<does> require forking to the
+background for process supervision. The F<contrib/> directory has sample
+I<upstart> and I<systemd> configuration files.
 
 =item B<-h>
 
@@ -138,6 +142,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 0b8d0c1e89ee1547f955c0795bf388d1568eb518..8357ce841838cad2f85238b5bbe3ba1758e1db43 100644 (file)
@@ -98,8 +98,8 @@ static void exit_usage (const char *name, int status) {
       "Hostname defaults to the local hostname if omitted (e.g., uptime/uptime).\n"
       "No error is returned if the specified identifier does not exist.\n"
 
-      "\n"PACKAGE" "VERSION", http://collectd.org/\n"
-      "by Florian octo Forster <octo@verplant.org>\n"
+      "\n"PACKAGE_NAME" "PACKAGE_VERSION", http://collectd.org/\n"
+      "by Florian octo Forster <octo@collectd.org>\n"
       "for contributions see `AUTHORS'\n"
       , name);
   exit (status);
index 52b8ef23d625a956bc11ce7dd7e256a9ac1a6a91..d921330464aba9487d7d9caa4fee7480497ad691 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 c81ca3f4fdcb08c7180af7dfe43c47f81e487650..33f02b45694d889d07613a05110230c1b32d7442 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>
  **/
 
@@ -75,8 +80,8 @@ 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"
+                       "\n"PACKAGE_NAME" "PACKAGE_VERSION", http://collectd.org/\n"
+                       "by Florian octo Forster <octo@collectd.org>\n"
                        "for contributions see `AUTHORS'\n", name);
        exit (0);
 } /* exit_usage */
index 3151e1104c9e73b6f251de329a93cb258480cd4c..8fa62f33ede4dfbecb5729e9531a73babdc4ec1a 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>.
diff --git a/src/common.c b/src/common.c
deleted file mode 100644 (file)
index c284942..0000000
+++ /dev/null
@@ -1,1507 +0,0 @@
-/**
- * collectd - src/common.c
- * Copyright (C) 2005-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.
- *
- * 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
- *
- * Authors:
- *   Florian octo Forster <octo at collectd.org>
- *   Niki W. Waibel <niki.waibel@gmx.net>
- *   Sebastian Harl <sh at tokkee.org>
- *   Michał Mirosław <mirq-linux at rere.qmqm.pl>
-**/
-
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "collectd.h"
-#include "common.h"
-#include "plugin.h"
-#include "utils_cache.h"
-
-#if HAVE_PTHREAD_H
-# include <pthread.h>
-#endif
-
-#ifdef HAVE_MATH_H
-# include <math.h>
-#endif
-
-/* for getaddrinfo */
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-
-#if HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-
-/* for ntohl and htonl */
-#if HAVE_ARPA_INET_H
-# include <arpa/inet.h>
-#endif
-
-#ifdef HAVE_LIBKSTAT
-extern kstat_ctl_t *kc;
-#endif
-
-#if !HAVE_GETPWNAM_R
-static pthread_mutex_t getpwnam_r_lock = PTHREAD_MUTEX_INITIALIZER;
-#endif
-
-#if !HAVE_STRERROR_R
-static pthread_mutex_t strerror_r_lock = PTHREAD_MUTEX_INITIALIZER;
-#endif
-
-char *sstrncpy (char *dest, const char *src, size_t n)
-{
-       strncpy (dest, src, n);
-       dest[n - 1] = '\0';
-
-       return (dest);
-} /* char *sstrncpy */
-
-int ssnprintf (char *dest, size_t n, const char *format, ...)
-{
-       int ret = 0;
-       va_list ap;
-
-       va_start (ap, format);
-       ret = vsnprintf (dest, n, format, ap);
-       dest[n - 1] = '\0';
-       va_end (ap);
-
-       return (ret);
-} /* int ssnprintf */
-
-char *ssnprintf_alloc (char const *format, ...) /* {{{ */
-{
-       char static_buffer[1024] = "";
-       char *alloc_buffer;
-       size_t alloc_buffer_size;
-       int status;
-       va_list ap;
-
-       /* Try printing into the static buffer. In many cases it will be
-        * sufficiently large and we can simply return a strdup() of this
-        * buffer. */
-       va_start (ap, format);
-       status = vsnprintf (static_buffer, sizeof (static_buffer), format, ap);
-       va_end (ap);
-       if (status < 0)
-               return (NULL);
-
-       /* "status" does not include the null byte. */
-       alloc_buffer_size = (size_t) (status + 1);
-       if (alloc_buffer_size <= sizeof (static_buffer))
-               return (strdup (static_buffer));
-
-       /* Allocate a buffer large enough to hold the string. */
-       alloc_buffer = malloc (alloc_buffer_size);
-       if (alloc_buffer == NULL)
-               return (NULL);
-       memset (alloc_buffer, 0, alloc_buffer_size);
-
-       /* Print again into this new buffer. */
-       va_start (ap, format);
-       status = vsnprintf (alloc_buffer, alloc_buffer_size, format, ap);
-       va_end (ap);
-       if (status < 0)
-       {
-               sfree (alloc_buffer);
-               return (NULL);
-       }
-
-       return (alloc_buffer);
-} /* }}} char *ssnprintf_alloc */
-
-char *sstrdup (const char *s)
-{
-       char *r;
-       size_t sz;
-
-       if (s == NULL)
-               return (NULL);
-
-       /* Do not use `strdup' here, because it's not specified in POSIX. It's
-        * ``only'' an XSI extension. */
-       sz = strlen (s) + 1;
-       r = (char *) malloc (sizeof (char) * sz);
-       if (r == NULL)
-       {
-               ERROR ("sstrdup: Out of memory.");
-               exit (3);
-       }
-       memcpy (r, s, sizeof (char) * sz);
-
-       return (r);
-} /* char *sstrdup */
-
-/* Even though Posix requires "strerror_r" to return an "int",
- * some systems (e.g. the GNU libc) return a "char *" _and_
- * ignore the second argument ... -tokkee */
-char *sstrerror (int errnum, char *buf, size_t buflen)
-{
-       buf[0] = '\0';
-
-#if !HAVE_STRERROR_R
-       {
-               char *temp;
-
-               pthread_mutex_lock (&strerror_r_lock);
-
-               temp = strerror (errnum);
-               sstrncpy (buf, temp, buflen);
-
-               pthread_mutex_unlock (&strerror_r_lock);
-       }
-/* #endif !HAVE_STRERROR_R */
-
-#elif STRERROR_R_CHAR_P
-       {
-               char *temp;
-               temp = strerror_r (errnum, buf, buflen);
-               if (buf[0] == '\0')
-               {
-                       if ((temp != NULL) && (temp != buf) && (temp[0] != '\0'))
-                               sstrncpy (buf, temp, buflen);
-                       else
-                               sstrncpy (buf, "strerror_r did not return "
-                                               "an error message", buflen);
-               }
-       }
-/* #endif STRERROR_R_CHAR_P */
-
-#else
-       if (strerror_r (errnum, buf, buflen) != 0)
-       {
-               ssnprintf (buf, buflen, "Error #%i; "
-                               "Additionally, strerror_r failed.",
-                               errnum);
-       }
-#endif /* STRERROR_R_CHAR_P */
-
-       return (buf);
-} /* char *sstrerror */
-
-void *smalloc (size_t size)
-{
-       void *r;
-
-       if ((r = malloc (size)) == NULL)
-       {
-               ERROR ("Not enough memory.");
-               exit (3);
-       }
-
-       return (r);
-} /* void *smalloc */
-
-#if 0
-void sfree (void **ptr)
-{
-       if (ptr == NULL)
-               return;
-
-       if (*ptr != NULL)
-               free (*ptr);
-
-       *ptr = NULL;
-}
-#endif
-
-ssize_t sread (int fd, void *buf, size_t count)
-{
-       char    *ptr;
-       size_t   nleft;
-       ssize_t  status;
-
-       ptr   = (char *) buf;
-       nleft = count;
-
-       while (nleft > 0)
-       {
-               status = read (fd, (void *) ptr, nleft);
-
-               if ((status < 0) && ((errno == EAGAIN) || (errno == EINTR)))
-                       continue;
-
-               if (status < 0)
-                       return (status);
-
-               if (status == 0)
-               {
-                       DEBUG ("Received EOF from fd %i. "
-                                       "Closing fd and returning error.",
-                                       fd);
-                       close (fd);
-                       return (-1);
-               }
-
-               assert ((0 > status) || (nleft >= (size_t)status));
-
-               nleft = nleft - status;
-               ptr   = ptr   + status;
-       }
-
-       return (0);
-}
-
-
-ssize_t swrite (int fd, const void *buf, size_t count)
-{
-       const char *ptr;
-       size_t      nleft;
-       ssize_t     status;
-
-       ptr   = (const char *) buf;
-       nleft = count;
-
-       while (nleft > 0)
-       {
-               status = write (fd, (const void *) ptr, nleft);
-
-               if ((status < 0) && ((errno == EAGAIN) || (errno == EINTR)))
-                       continue;
-
-               if (status < 0)
-                       return (status);
-
-               nleft = nleft - status;
-               ptr   = ptr   + status;
-       }
-
-       return (0);
-}
-
-int strsplit (char *string, char **fields, size_t size)
-{
-       size_t i;
-       char *ptr;
-       char *saveptr;
-
-       i = 0;
-       ptr = string;
-       saveptr = NULL;
-       while ((fields[i] = strtok_r (ptr, " \t\r\n", &saveptr)) != NULL)
-       {
-               ptr = NULL;
-               i++;
-
-               if (i >= size)
-                       break;
-       }
-
-       return ((int) i);
-}
-
-int strjoin (char *buffer, size_t buffer_size,
-               char **fields, size_t fields_num,
-               const char *sep)
-{
-       size_t avail;
-       char *ptr;
-       size_t sep_len;
-       size_t i;
-
-       if ((buffer_size < 1) || (fields_num <= 0))
-               return (-1);
-
-       memset (buffer, 0, buffer_size);
-       ptr = buffer;
-       avail = buffer_size - 1;
-
-       sep_len = 0;
-       if (sep != NULL)
-               sep_len = strlen (sep);
-
-       for (i = 0; i < fields_num; i++)
-       {
-               size_t field_len;
-
-               if ((i > 0) && (sep_len > 0))
-               {
-                       if (avail < sep_len)
-                               return (-1);
-
-                       memcpy (ptr, sep, sep_len);
-                       ptr += sep_len;
-                       avail -= sep_len;
-               }
-
-               field_len = strlen (fields[i]);
-               if (avail < field_len)
-                       return (-1);
-
-               memcpy (ptr, fields[i], field_len);
-               ptr += field_len;
-               avail -= field_len;
-       }
-
-       assert (buffer[buffer_size - 1] == 0);
-       return (strlen (buffer));
-}
-
-int strsubstitute (char *str, char c_from, char c_to)
-{
-       int ret;
-
-       if (str == NULL)
-               return (-1);
-
-       ret = 0;
-       while (*str != '\0')
-       {
-               if (*str == c_from)
-               {
-                       *str = c_to;
-                       ret++;
-               }
-               str++;
-       }
-
-       return (ret);
-} /* int strsubstitute */
-
-int strunescape (char *buf, size_t buf_len)
-{
-       size_t i;
-
-       for (i = 0; (i < buf_len) && (buf[i] != '\0'); ++i)
-       {
-               if (buf[i] != '\\')
-                       continue;
-
-               if ((i >= buf_len) || (buf[i + 1] == '\0')) {
-                       ERROR ("string unescape: backslash found at end of string.");
-                       return (-1);
-               }
-
-               switch (buf[i + 1]) {
-                       case 't':
-                               buf[i] = '\t';
-                               break;
-                       case 'n':
-                               buf[i] = '\n';
-                               break;
-                       case 'r':
-                               buf[i] = '\r';
-                               break;
-                       default:
-                               buf[i] = buf[i + 1];
-                               break;
-               }
-
-               memmove (buf + i + 1, buf + i + 2, buf_len - i - 2);
-       }
-       return (0);
-} /* int strunescape */
-
-size_t strstripnewline (char *buffer)
-{
-       size_t buffer_len = strlen (buffer);
-
-       while (buffer_len > 0)
-       {
-               if ((buffer[buffer_len - 1] != '\n')
-                               && (buffer[buffer_len - 1] != '\r'))
-                       break;
-               buffer_len--;
-               buffer[buffer_len] = 0;
-       }
-
-       return (buffer_len);
-} /* size_t strstripnewline */
-
-int escape_slashes (char *buf, int buf_len)
-{
-       int i;
-
-       if (strcmp (buf, "/") == 0)
-       {
-               if (buf_len < 5)
-                       return (-1);
-
-               strncpy (buf, "root", buf_len);
-               return (0);
-       }
-
-       if (buf_len <= 1)
-               return (0);
-
-       /* Move one to the left */
-       if (buf[0] == '/')
-               memmove (buf, buf + 1, buf_len - 1);
-
-       for (i = 0; i < buf_len; i++)
-       {
-               if (buf[i] == '\0')
-                       break;
-               else if (buf[i] == '/')
-                       buf[i] = '_';
-       }
-       buf[i] = '\0';
-
-       return (0);
-} /* int escape_slashes */
-
-void replace_special (char *buffer, size_t buffer_size)
-{
-       size_t i;
-
-       for (i = 0; i < buffer_size; i++)
-       {
-               if (buffer[i] == 0)
-                       return;
-               if ((!isalnum ((int) buffer[i])) && (buffer[i] != '-'))
-                       buffer[i] = '_';
-       }
-} /* void replace_special */
-
-int timeval_cmp (struct timeval tv0, struct timeval tv1, struct timeval *delta)
-{
-       struct timeval *larger;
-       struct timeval *smaller;
-
-       int status;
-
-       NORMALIZE_TIMEVAL (tv0);
-       NORMALIZE_TIMEVAL (tv1);
-
-       if ((tv0.tv_sec == tv1.tv_sec) && (tv0.tv_usec == tv1.tv_usec))
-       {
-               if (delta != NULL) {
-                       delta->tv_sec  = 0;
-                       delta->tv_usec = 0;
-               }
-               return (0);
-       }
-
-       if ((tv0.tv_sec < tv1.tv_sec)
-                       || ((tv0.tv_sec == tv1.tv_sec) && (tv0.tv_usec < tv1.tv_usec)))
-       {
-               larger  = &tv1;
-               smaller = &tv0;
-               status  = -1;
-       }
-       else
-       {
-               larger  = &tv0;
-               smaller = &tv1;
-               status  = 1;
-       }
-
-       if (delta != NULL) {
-               delta->tv_sec = larger->tv_sec - smaller->tv_sec;
-
-               if (smaller->tv_usec <= larger->tv_usec)
-                       delta->tv_usec = larger->tv_usec - smaller->tv_usec;
-               else
-               {
-                       --delta->tv_sec;
-                       delta->tv_usec = 1000000 + larger->tv_usec - smaller->tv_usec;
-               }
-       }
-
-       assert ((delta == NULL)
-                       || ((0 <= delta->tv_usec) && (delta->tv_usec < 1000000)));
-
-       return (status);
-} /* int timeval_cmp */
-
-int check_create_dir (const char *file_orig)
-{
-       struct stat statbuf;
-
-       char  file_copy[512];
-       char  dir[512];
-       int   dir_len = 512;
-       char *fields[16];
-       int   fields_num;
-       char *ptr;
-       char *saveptr;
-       int   last_is_file = 1;
-       int   path_is_absolute = 0;
-       size_t len;
-       int   i;
-
-       /*
-        * Sanity checks first
-        */
-       if (file_orig == NULL)
-               return (-1);
-
-       if ((len = strlen (file_orig)) < 1)
-               return (-1);
-       else if (len >= sizeof (file_copy))
-               return (-1);
-
-       /*
-        * If `file_orig' ends in a slash the last component is a directory,
-        * otherwise it's a file. Act accordingly..
-        */
-       if (file_orig[len - 1] == '/')
-               last_is_file = 0;
-       if (file_orig[0] == '/')
-               path_is_absolute = 1;
-
-       /*
-        * Create a copy for `strtok_r' to destroy
-        */
-       sstrncpy (file_copy, file_orig, sizeof (file_copy));
-
-       /*
-        * Break into components. This will eat up several slashes in a row and
-        * remove leading and trailing slashes..
-        */
-       ptr = file_copy;
-       saveptr = NULL;
-       fields_num = 0;
-       while ((fields[fields_num] = strtok_r (ptr, "/", &saveptr)) != NULL)
-       {
-               ptr = NULL;
-               fields_num++;
-
-               if (fields_num >= 16)
-                       break;
-       }
-
-       /*
-        * For each component, do..
-        */
-       for (i = 0; i < (fields_num - last_is_file); i++)
-       {
-               /*
-                * Do not create directories that start with a dot. This
-                * prevents `../../' attacks and other likely malicious
-                * behavior.
-                */
-               if (fields[i][0] == '.')
-               {
-                       ERROR ("Cowardly refusing to create a directory that "
-                                       "begins with a `.' (dot): `%s'", file_orig);
-                       return (-2);
-               }
-
-               /*
-                * Join the components together again
-                */
-               dir[0] = '/';
-               if (strjoin (dir + path_is_absolute, dir_len - path_is_absolute,
-                                       fields, i + 1, "/") < 0)
-               {
-                       ERROR ("strjoin failed: `%s', component #%i", file_orig, i);
-                       return (-1);
-               }
-
-               while (42) {
-                       if ((stat (dir, &statbuf) == -1)
-                                       && (lstat (dir, &statbuf) == -1))
-                       {
-                               if (errno == ENOENT)
-                               {
-                                       if (mkdir (dir, S_IRWXU | S_IRWXG | S_IRWXO) == 0)
-                                               break;
-
-                                       /* this might happen, if a different thread created
-                                        * the directory in the meantime
-                                        * => call stat() again to check for S_ISDIR() */
-                                       if (EEXIST == errno)
-                                               continue;
-
-                                       char errbuf[1024];
-                                       ERROR ("check_create_dir: mkdir (%s): %s", dir,
-                                                       sstrerror (errno,
-                                                               errbuf, sizeof (errbuf)));
-                                       return (-1);
-                               }
-                               else
-                               {
-                                       char errbuf[1024];
-                                       ERROR ("check_create_dir: stat (%s): %s", dir,
-                                                       sstrerror (errno, errbuf,
-                                                               sizeof (errbuf)));
-                                       return (-1);
-                               }
-                       }
-                       else if (!S_ISDIR (statbuf.st_mode))
-                       {
-                               ERROR ("check_create_dir: `%s' exists but is not "
-                                               "a directory!", dir);
-                               return (-1);
-                       }
-                       break;
-               }
-       }
-
-       return (0);
-} /* check_create_dir */
-
-#ifdef HAVE_LIBKSTAT
-int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name)
-{
-       char ident[128];
-
-       *ksp_ptr = NULL;
-       
-       if (kc == NULL)
-               return (-1);
-
-       ssnprintf (ident, sizeof (ident), "%s,%i,%s", module, instance, name);
-
-       *ksp_ptr = kstat_lookup (kc, module, instance, name);
-       if (*ksp_ptr == NULL)
-       {
-               ERROR ("get_kstat: Cound not find kstat %s", ident);
-               return (-1);
-       }
-
-       if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED)
-       {
-               ERROR ("get_kstat: kstat %s has wrong type", ident);
-               *ksp_ptr = NULL;
-               return (-1);
-       }
-
-#ifdef assert
-       assert (*ksp_ptr != NULL);
-       assert ((*ksp_ptr)->ks_type == KSTAT_TYPE_NAMED);
-#endif
-
-       if (kstat_read (kc, *ksp_ptr, NULL) == -1)
-       {
-               ERROR ("get_kstat: kstat %s could not be read", ident);
-               return (-1);
-       }
-
-       if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED)
-       {
-               ERROR ("get_kstat: kstat %s has wrong type", ident);
-               return (-1);
-       }
-
-       return (0);
-}
-
-long long get_kstat_value (kstat_t *ksp, char *name)
-{
-       kstat_named_t *kn;
-       long long retval = -1LL;
-
-       if (ksp == NULL)
-       {
-               ERROR ("get_kstat_value (\"%s\"): ksp is NULL.", name);
-               return (-1LL);
-       }
-       else if (ksp->ks_type != KSTAT_TYPE_NAMED)
-       {
-               ERROR ("get_kstat_value (\"%s\"): ksp->ks_type (%#x) "
-                               "is not KSTAT_TYPE_NAMED (%#x).",
-                               name,
-                               (unsigned int) ksp->ks_type,
-                               (unsigned int) KSTAT_TYPE_NAMED);
-               return (-1LL);
-       }
-
-       if ((kn = (kstat_named_t *) kstat_data_lookup (ksp, name)) == NULL)
-               return (-1LL);
-
-       if (kn->data_type == KSTAT_DATA_INT32)
-               retval = (long long) kn->value.i32;
-       else if (kn->data_type == KSTAT_DATA_UINT32)
-               retval = (long long) kn->value.ui32;
-       else if (kn->data_type == KSTAT_DATA_INT64)
-               retval = (long long) kn->value.i64; /* According to ANSI C99 `long long' must hold at least 64 bits */
-       else if (kn->data_type == KSTAT_DATA_UINT64)
-               retval = (long long) kn->value.ui64; /* XXX: Might overflow! */
-       else
-               WARNING ("get_kstat_value: Not a numeric value: %s", name);
-
-       return (retval);
-}
-#endif /* HAVE_LIBKSTAT */
-
-#ifndef HAVE_HTONLL
-unsigned long long ntohll (unsigned long long n)
-{
-#if BYTE_ORDER == BIG_ENDIAN
-       return (n);
-#else
-       return (((unsigned long long) ntohl (n)) << 32) + ntohl (n >> 32);
-#endif
-} /* unsigned long long ntohll */
-
-unsigned long long htonll (unsigned long long n)
-{
-#if BYTE_ORDER == BIG_ENDIAN
-       return (n);
-#else
-       return (((unsigned long long) htonl (n)) << 32) + htonl (n >> 32);
-#endif
-} /* unsigned long long htonll */
-#endif /* HAVE_HTONLL */
-
-#if FP_LAYOUT_NEED_NOTHING
-/* Well, we need nothing.. */
-/* #endif FP_LAYOUT_NEED_NOTHING */
-
-#elif FP_LAYOUT_NEED_ENDIANFLIP || FP_LAYOUT_NEED_INTSWAP
-# if FP_LAYOUT_NEED_ENDIANFLIP
-#  define FP_CONVERT(A) ((((uint64_t)(A) & 0xff00000000000000LL) >> 56) | \
-                         (((uint64_t)(A) & 0x00ff000000000000LL) >> 40) | \
-                         (((uint64_t)(A) & 0x0000ff0000000000LL) >> 24) | \
-                         (((uint64_t)(A) & 0x000000ff00000000LL) >> 8)  | \
-                         (((uint64_t)(A) & 0x00000000ff000000LL) << 8)  | \
-                         (((uint64_t)(A) & 0x0000000000ff0000LL) << 24) | \
-                         (((uint64_t)(A) & 0x000000000000ff00LL) << 40) | \
-                         (((uint64_t)(A) & 0x00000000000000ffLL) << 56))
-# else
-#  define FP_CONVERT(A) ((((uint64_t)(A) & 0xffffffff00000000LL) >> 32) | \
-                         (((uint64_t)(A) & 0x00000000ffffffffLL) << 32))
-# endif
-
-double ntohd (double d)
-{
-       union
-       {
-               uint8_t  byte[8];
-               uint64_t integer;
-               double   floating;
-       } ret;
-
-       ret.floating = d;
-
-       /* NAN in x86 byte order */
-       if ((ret.byte[0] == 0x00) && (ret.byte[1] == 0x00)
-                       && (ret.byte[2] == 0x00) && (ret.byte[3] == 0x00)
-                       && (ret.byte[4] == 0x00) && (ret.byte[5] == 0x00)
-                       && (ret.byte[6] == 0xf8) && (ret.byte[7] == 0x7f))
-       {
-               return (NAN);
-       }
-       else
-       {
-               uint64_t tmp;
-
-               tmp = ret.integer;
-               ret.integer = FP_CONVERT (tmp);
-               return (ret.floating);
-       }
-} /* double ntohd */
-
-double htond (double d)
-{
-       union
-       {
-               uint8_t  byte[8];
-               uint64_t integer;
-               double   floating;
-       } ret;
-
-       if (isnan (d))
-       {
-               ret.byte[0] = ret.byte[1] = ret.byte[2] = ret.byte[3] = 0x00;
-               ret.byte[4] = ret.byte[5] = 0x00;
-               ret.byte[6] = 0xf8;
-               ret.byte[7] = 0x7f;
-               return (ret.floating);
-       }
-       else
-       {
-               uint64_t tmp;
-
-               ret.floating = d;
-               tmp = FP_CONVERT (ret.integer);
-               ret.integer = tmp;
-               return (ret.floating);
-       }
-} /* double htond */
-#endif /* FP_LAYOUT_NEED_ENDIANFLIP || FP_LAYOUT_NEED_INTSWAP */
-
-int format_name (char *ret, int ret_len,
-               const char *hostname,
-               const char *plugin, const char *plugin_instance,
-               const char *type, const char *type_instance)
-{
-  char *buffer;
-  size_t buffer_size;
-
-  buffer = ret;
-  buffer_size = (size_t) ret_len;
-
-#define APPEND(str) do {                                               \
-  size_t l = strlen (str);                                             \
-  if (l >= buffer_size)                                                \
-    return (ENOBUFS);                                                  \
-  memcpy (buffer, (str), l);                                           \
-  buffer += l; buffer_size -= l;                                       \
-} while (0)
-
-  assert (plugin != NULL);
-  assert (type != NULL);
-
-  APPEND (hostname);
-  APPEND ("/");
-  APPEND (plugin);
-  if ((plugin_instance != NULL) && (plugin_instance[0] != 0))
-  {
-    APPEND ("-");
-    APPEND (plugin_instance);
-  }
-  APPEND ("/");
-  APPEND (type);
-  if ((type_instance != NULL) && (type_instance[0] != 0))
-  {
-    APPEND ("-");
-    APPEND (type_instance);
-  }
-  assert (buffer_size > 0);
-  buffer[0] = 0;
-
-#undef APPEND
-  return (0);
-} /* int format_name */
-
-int format_values (char *ret, size_t ret_len, /* {{{ */
-               const data_set_t *ds, const value_list_t *vl,
-               _Bool store_rates)
-{
-        size_t offset = 0;
-        int status;
-        int i;
-        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)
-
-        BUFFER_ADD ("%.3f", CDTIME_T_TO_DOUBLE (vl->time));
-
-        for (i = 0; i < ds->ds_num; i++)
-        {
-                if (ds->ds[i].type == DS_TYPE_GAUGE)
-                        BUFFER_ADD (":"GAUGE_FORMAT, vl->values[i].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 (":"GAUGE_FORMAT, rates[i]);
-                }
-                else if (ds->ds[i].type == DS_TYPE_COUNTER)
-                        BUFFER_ADD (":%llu", vl->values[i].counter);
-                else if (ds->ds[i].type == DS_TYPE_DERIVE)
-                        BUFFER_ADD (":%"PRIi64, vl->values[i].derive);
-                else if (ds->ds[i].type == DS_TYPE_ABSOLUTE)
-                        BUFFER_ADD (":%"PRIu64, vl->values[i].absolute);
-                else
-                {
-                        ERROR ("format_values: Unknown data source type: %i",
-                                        ds->ds[i].type);
-                        sfree (rates);
-                        return (-1);
-                }
-        } /* for ds->ds_num */
-
-#undef BUFFER_ADD
-
-        sfree (rates);
-        return (0);
-} /* }}} int format_values */
-
-int parse_identifier (char *str, char **ret_host,
-               char **ret_plugin, char **ret_plugin_instance,
-               char **ret_type, char **ret_type_instance)
-{
-       char *hostname = NULL;
-       char *plugin = NULL;
-       char *plugin_instance = NULL;
-       char *type = NULL;
-       char *type_instance = NULL;
-
-       hostname = str;
-       if (hostname == NULL)
-               return (-1);
-
-       plugin = strchr (hostname, '/');
-       if (plugin == NULL)
-               return (-1);
-       *plugin = '\0'; plugin++;
-
-       type = strchr (plugin, '/');
-       if (type == NULL)
-               return (-1);
-       *type = '\0'; type++;
-
-       plugin_instance = strchr (plugin, '-');
-       if (plugin_instance != NULL)
-       {
-               *plugin_instance = '\0';
-               plugin_instance++;
-       }
-
-       type_instance = strchr (type, '-');
-       if (type_instance != NULL)
-       {
-               *type_instance = '\0';
-               type_instance++;
-       }
-
-       *ret_host = hostname;
-       *ret_plugin = plugin;
-       *ret_plugin_instance = plugin_instance;
-       *ret_type = type;
-       *ret_type_instance = type_instance;
-       return (0);
-} /* int parse_identifier */
-
-int parse_identifier_vl (const char *str, value_list_t *vl) /* {{{ */
-{
-       char str_copy[6 * DATA_MAX_NAME_LEN];
-       char *host = NULL;
-       char *plugin = NULL;
-       char *plugin_instance = NULL;
-       char *type = NULL;
-       char *type_instance = NULL;
-       int status;
-
-       if ((str == NULL) || (vl == NULL))
-               return (EINVAL);
-
-       sstrncpy (str_copy, str, sizeof (str_copy));
-
-       status = parse_identifier (str_copy, &host,
-                       &plugin, &plugin_instance,
-                       &type, &type_instance);
-       if (status != 0)
-               return (status);
-
-       sstrncpy (vl->host, host, sizeof (vl->host));
-       sstrncpy (vl->plugin, plugin, sizeof (vl->plugin));
-       sstrncpy (vl->plugin_instance,
-                       (plugin_instance != NULL) ? plugin_instance : "",
-                       sizeof (vl->plugin_instance));
-       sstrncpy (vl->type, type, sizeof (vl->type));
-       sstrncpy (vl->type_instance,
-                       (type_instance != NULL) ? type_instance : "",
-                       sizeof (vl->type_instance));
-
-       return (0);
-} /* }}} int parse_identifier_vl */
-
-int parse_value (const char *value_orig, value_t *ret_value, int ds_type)
-{
-  char *value;
-  char *endptr = NULL;
-  size_t value_len;
-
-  if (value_orig == NULL)
-    return (EINVAL);
-
-  value = strdup (value_orig);
-  if (value == NULL)
-    return (ENOMEM);
-  value_len = strlen (value);
-
-  while ((value_len > 0) && isspace ((int) value[value_len - 1]))
-  {
-    value[value_len - 1] = 0;
-    value_len--;
-  }
-
-  switch (ds_type)
-  {
-    case DS_TYPE_COUNTER:
-      ret_value->counter = (counter_t) strtoull (value, &endptr, 0);
-      break;
-
-    case DS_TYPE_GAUGE:
-      ret_value->gauge = (gauge_t) strtod (value, &endptr);
-      break;
-
-    case DS_TYPE_DERIVE:
-      ret_value->derive = (derive_t) strtoll (value, &endptr, 0);
-      break;
-
-    case DS_TYPE_ABSOLUTE:
-      ret_value->absolute = (absolute_t) strtoull (value, &endptr, 0);
-      break;
-
-    default:
-      sfree (value);
-      ERROR ("parse_value: Invalid data source type: %i.", ds_type);
-      return -1;
-  }
-
-  if (value == endptr) {
-    ERROR ("parse_value: Failed to parse string as %s: %s.",
-        DS_TYPE_TO_STRING (ds_type), value);
-    sfree (value);
-    return -1;
-  }
-  else if ((NULL != endptr) && ('\0' != *endptr))
-    INFO ("parse_value: Ignoring trailing garbage \"%s\" after %s value. "
-        "Input string was \"%s\".",
-        endptr, DS_TYPE_TO_STRING (ds_type), value_orig);
-
-  sfree (value);
-  return 0;
-} /* int parse_value */
-
-int parse_values (char *buffer, value_list_t *vl, const data_set_t *ds)
-{
-       int i;
-       char *dummy;
-       char *ptr;
-       char *saveptr;
-
-       i = -1;
-       dummy = buffer;
-       saveptr = NULL;
-       while ((ptr = strtok_r (dummy, ":", &saveptr)) != NULL)
-       {
-               dummy = NULL;
-
-               if (i >= vl->values_len)
-               {
-                       /* Make sure i is invalid. */
-                       i = vl->values_len + 1;
-                       break;
-               }
-
-               if (i == -1)
-               {
-                       if (strcmp ("N", ptr) == 0)
-                               vl->time = cdtime ();
-                       else
-                       {
-                               char *endptr = NULL;
-                               double tmp;
-
-                               errno = 0;
-                               tmp = strtod (ptr, &endptr);
-                               if ((errno != 0)                    /* Overflow */
-                                               || (endptr == ptr)  /* Invalid string */
-                                               || (endptr == NULL) /* This should not happen */
-                                               || (*endptr != 0))  /* Trailing chars */
-                                       return (-1);
-
-                               vl->time = DOUBLE_TO_CDTIME_T (tmp);
-                       }
-               }
-               else
-               {
-                       if ((strcmp ("U", ptr) == 0) && (ds->ds[i].type == DS_TYPE_GAUGE))
-                               vl->values[i].gauge = NAN;
-                       else if (0 != parse_value (ptr, &vl->values[i], ds->ds[i].type))
-                               return -1;
-               }
-
-               i++;
-       } /* while (strtok_r) */
-
-       if ((ptr != NULL) || (i != vl->values_len))
-               return (-1);
-       return (0);
-} /* int parse_values */
-
-#if !HAVE_GETPWNAM_R
-int getpwnam_r (const char *name, struct passwd *pwbuf, char *buf,
-               size_t buflen, struct passwd **pwbufp)
-{
-       int status = 0;
-       struct passwd *pw;
-
-       memset (pwbuf, '\0', sizeof (struct passwd));
-
-       pthread_mutex_lock (&getpwnam_r_lock);
-
-       do
-       {
-               pw = getpwnam (name);
-               if (pw == NULL)
-               {
-                       status = (errno != 0) ? errno : ENOENT;
-                       break;
-               }
-
-#define GETPWNAM_COPY_MEMBER(member) \
-               if (pw->member != NULL) \
-               { \
-                       int len = strlen (pw->member); \
-                       if (len >= buflen) \
-                       { \
-                               status = ENOMEM; \
-                               break; \
-                       } \
-                       sstrncpy (buf, pw->member, buflen); \
-                       pwbuf->member = buf; \
-                       buf    += (len + 1); \
-                       buflen -= (len + 1); \
-               }
-               GETPWNAM_COPY_MEMBER(pw_name);
-               GETPWNAM_COPY_MEMBER(pw_passwd);
-               GETPWNAM_COPY_MEMBER(pw_gecos);
-               GETPWNAM_COPY_MEMBER(pw_dir);
-               GETPWNAM_COPY_MEMBER(pw_shell);
-
-               pwbuf->pw_uid = pw->pw_uid;
-               pwbuf->pw_gid = pw->pw_gid;
-
-               if (pwbufp != NULL)
-                       *pwbufp = pwbuf;
-       } while (0);
-
-       pthread_mutex_unlock (&getpwnam_r_lock);
-
-       return (status);
-} /* int getpwnam_r */
-#endif /* !HAVE_GETPWNAM_R */
-
-int notification_init (notification_t *n, int severity, const char *message,
-               const char *host,
-               const char *plugin, const char *plugin_instance,
-               const char *type, const char *type_instance)
-{
-       memset (n, '\0', sizeof (notification_t));
-
-       n->severity = severity;
-
-       if (message != NULL)
-               sstrncpy (n->message, message, sizeof (n->message));
-       if (host != NULL)
-               sstrncpy (n->host, host, sizeof (n->host));
-       if (plugin != NULL)
-               sstrncpy (n->plugin, plugin, sizeof (n->plugin));
-       if (plugin_instance != NULL)
-               sstrncpy (n->plugin_instance, plugin_instance,
-                               sizeof (n->plugin_instance));
-       if (type != NULL)
-               sstrncpy (n->type, type, sizeof (n->type));
-       if (type_instance != NULL)
-               sstrncpy (n->type_instance, type_instance,
-                               sizeof (n->type_instance));
-
-       return (0);
-} /* int notification_init */
-
-int walk_directory (const char *dir, dirwalk_callback_f callback,
-               void *user_data, int include_hidden)
-{
-       struct dirent *ent;
-       DIR *dh;
-       int success;
-       int failure;
-
-       success = 0;
-       failure = 0;
-
-       if ((dh = opendir (dir)) == NULL)
-       {
-               char errbuf[1024];
-               ERROR ("walk_directory: Cannot open '%s': %s", dir,
-                               sstrerror (errno, errbuf, sizeof (errbuf)));
-               return -1;
-       }
-
-       while ((ent = readdir (dh)) != NULL)
-       {
-               int status;
-               
-               if (include_hidden)
-               {
-                       if ((strcmp (".", ent->d_name) == 0)
-                                       || (strcmp ("..", ent->d_name) == 0))
-                               continue;
-               }
-               else /* if (!include_hidden) */
-               {
-                       if (ent->d_name[0]=='.')
-                               continue;
-               }
-
-               status = (*callback) (dir, ent->d_name, user_data);
-               if (status != 0)
-                       failure++;
-               else
-                       success++;
-       }
-
-       closedir (dh);
-
-       if ((success == 0) && (failure > 0))
-               return (-1);
-       return (0);
-}
-
-ssize_t read_file_contents (const char *filename, char *buf, size_t bufsize)
-{
-       FILE *fh;
-       ssize_t ret;
-
-       fh = fopen (filename, "r");
-       if (fh == NULL)
-               return (-1);
-
-       ret = (ssize_t) fread (buf, 1, bufsize, fh);
-       if ((ret == 0) && (ferror (fh) != 0))
-       {
-               ERROR ("read_file_contents: Reading file \"%s\" failed.",
-                               filename);
-               ret = -1;
-       }
-
-       fclose(fh);
-       return (ret);
-}
-
-counter_t counter_diff (counter_t old_value, counter_t new_value)
-{
-       counter_t diff;
-
-       if (old_value > new_value)
-       {
-               if (old_value <= 4294967295U)
-                       diff = (4294967295U - old_value) + new_value;
-               else
-                       diff = (18446744073709551615ULL - old_value)
-                               + new_value;
-       }
-       else
-       {
-               diff = new_value - old_value;
-       }
-
-       return (diff);
-} /* counter_t counter_diff */
-
-int rate_to_value (value_t *ret_value, gauge_t rate, /* {{{ */
-               rate_to_value_state_t *state,
-               int ds_type, cdtime_t t)
-{
-       gauge_t delta_gauge;
-       cdtime_t delta_t;
-
-       if (ds_type == DS_TYPE_GAUGE)
-       {
-               state->last_value.gauge = rate;
-               state->last_time = t;
-
-               *ret_value = state->last_value;
-               return (0);
-       }
-
-       /* Counter and absolute can't handle negative rates. Reset "last time"
-        * to zero, so that the next valid rate will re-initialize the
-        * structure. */
-       if ((rate < 0.0)
-                       && ((ds_type == DS_TYPE_COUNTER)
-                               || (ds_type == DS_TYPE_ABSOLUTE)))
-       {
-               memset (state, 0, sizeof (*state));
-               return (EINVAL);
-       }
-
-       /* Another invalid state: The time is not increasing. */
-       if (t <= state->last_time)
-       {
-               memset (state, 0, sizeof (*state));
-               return (EINVAL);
-       }
-
-       delta_t = t - state->last_time;
-       delta_gauge = (rate * CDTIME_T_TO_DOUBLE (delta_t)) + state->residual;
-
-       /* Previous value is invalid. */
-       if (state->last_time == 0) /* {{{ */
-       {
-               if (ds_type == DS_TYPE_DERIVE)
-               {
-                       state->last_value.derive = (derive_t) rate;
-                       state->residual = rate - ((gauge_t) state->last_value.derive);
-               }
-               else if (ds_type == DS_TYPE_COUNTER)
-               {
-                       state->last_value.counter = (counter_t) rate;
-                       state->residual = rate - ((gauge_t) state->last_value.counter);
-               }
-               else if (ds_type == DS_TYPE_ABSOLUTE)
-               {
-                       state->last_value.absolute = (absolute_t) rate;
-                       state->residual = rate - ((gauge_t) state->last_value.absolute);
-               }
-               else
-               {
-                       assert (23 == 42);
-               }
-
-               state->last_time = t;
-               return (EAGAIN);
-       } /* }}} */
-
-       if (ds_type == DS_TYPE_DERIVE)
-       {
-               derive_t delta_derive = (derive_t) delta_gauge;
-
-               state->last_value.derive += delta_derive;
-               state->residual = delta_gauge - ((gauge_t) delta_derive);
-       }
-       else if (ds_type == DS_TYPE_COUNTER)
-       {
-               counter_t delta_counter = (counter_t) delta_gauge;
-
-               state->last_value.counter += delta_counter;
-               state->residual = delta_gauge - ((gauge_t) delta_counter);
-       }
-       else if (ds_type == DS_TYPE_ABSOLUTE)
-       {
-               absolute_t delta_absolute = (absolute_t) delta_gauge;
-
-               state->last_value.absolute = delta_absolute;
-               state->residual = delta_gauge - ((gauge_t) delta_absolute);
-       }
-       else
-       {
-               assert (23 == 42);
-       }
-
-        state->last_time = t;
-       *ret_value = state->last_value;
-       return (0);
-} /* }}} value_t rate_to_value */
-
-int service_name_to_port_number (const char *service_name)
-{
-       struct addrinfo *ai_list;
-       struct addrinfo *ai_ptr;
-       struct addrinfo ai_hints;
-       int status;
-       int service_number;
-
-       if (service_name == NULL)
-               return (-1);
-
-       ai_list = NULL;
-       memset (&ai_hints, 0, sizeof (ai_hints));
-       ai_hints.ai_family = AF_UNSPEC;
-
-       status = getaddrinfo (/* node = */ NULL, service_name,
-                       &ai_hints, &ai_list);
-       if (status != 0)
-       {
-               ERROR ("service_name_to_port_number: getaddrinfo failed: %s",
-                               gai_strerror (status));
-               return (-1);
-       }
-
-       service_number = -1;
-       for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
-       {
-               if (ai_ptr->ai_family == AF_INET)
-               {
-                       struct sockaddr_in *sa;
-
-                       sa = (void *) ai_ptr->ai_addr;
-                       service_number = (int) ntohs (sa->sin_port);
-               }
-               else if (ai_ptr->ai_family == AF_INET6)
-               {
-                       struct sockaddr_in6 *sa;
-
-                       sa = (void *) ai_ptr->ai_addr;
-                       service_number = (int) ntohs (sa->sin6_port);
-               }
-
-               if ((service_number > 0) && (service_number <= 65535))
-                       break;
-       }
-
-       freeaddrinfo (ai_list);
-
-       if ((service_number > 0) && (service_number <= 65535))
-               return (service_number);
-       return (-1);
-} /* int service_name_to_port_number */
-
-int strtoderive (const char *string, derive_t *ret_value) /* {{{ */
-{
-       derive_t tmp;
-       char *endptr;
-
-       if ((string == NULL) || (ret_value == NULL))
-               return (EINVAL);
-
-       errno = 0;
-       endptr = NULL;
-       tmp = (derive_t) strtoll (string, &endptr, /* base = */ 0);
-       if ((endptr == string) || (errno != 0))
-               return (-1);
-
-       *ret_value = tmp;
-       return (0);
-} /* }}} int strtoderive */
-
-int strarray_add (char ***ret_array, size_t *ret_array_len, char const *str) /* {{{ */
-{
-       char **array;
-       size_t array_len = *ret_array_len;
-
-       if (str == NULL)
-               return (EINVAL);
-
-       array = realloc (*ret_array,
-            (array_len + 1) * sizeof (*array));
-       if (array == NULL)
-               return (ENOMEM);
-       *ret_array = array;
-
-       array[array_len] = strdup (str);
-       if (array[array_len] == NULL)
-               return (ENOMEM);
-
-       array_len++;
-        *ret_array_len = array_len;
-       return (0);
-} /* }}} int strarray_add */
-
-void strarray_free (char **array, size_t array_len) /* {{{ */
-{
-       size_t i;
-
-       for (i = 0; i < array_len; i++)
-               sfree (array[i]);
-       sfree (array);
-} /* }}} void strarray_free */
diff --git a/src/common.h b/src/common.h
deleted file mode 100644 (file)
index 317be8d..0000000
+++ /dev/null
@@ -1,336 +0,0 @@
-/**
- * collectd - src/common.h
- * Copyright (C) 2005-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.
- *
- * 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
- *
- * Authors:
- *   Florian octo Forster <octo at collectd.org>
- *   Niki W. Waibel <niki.waibel@gmx.net>
-**/
-
-#ifndef COMMON_H
-#define COMMON_H
-
-#include "collectd.h"
-#include "plugin.h"
-
-#if HAVE_PWD_H
-# include <pwd.h>
-#endif
-
-#define sfree(ptr) \
-       do { \
-               if((ptr) != NULL) { \
-                       free(ptr); \
-               } \
-               (ptr) = NULL; \
-       } while (0)
-
-#define STATIC_ARRAY_SIZE(a) (sizeof (a) / sizeof (*(a)))
-
-#define IS_TRUE(s) ((strcasecmp ("true", (s)) == 0) \
-               || (strcasecmp ("yes", (s)) == 0) \
-               || (strcasecmp ("on", (s)) == 0))
-#define IS_FALSE(s) ((strcasecmp ("false", (s)) == 0) \
-               || (strcasecmp ("no", (s)) == 0) \
-               || (strcasecmp ("off", (s)) == 0))
-
-struct rate_to_value_state_s
-{
-  value_t last_value;
-  cdtime_t last_time;
-  gauge_t residual;
-};
-typedef struct rate_to_value_state_s rate_to_value_state_t;
-
-char *sstrncpy (char *dest, const char *src, size_t n);
-
-__attribute__ ((format(printf,3,4)))
-int ssnprintf (char *dest, size_t n, const char *format, ...);
-
-__attribute__ ((format(printf,1,2)))
-char *ssnprintf_alloc (char const *format, ...);
-
-char *sstrdup(const char *s);
-void *smalloc(size_t size);
-char *sstrerror (int errnum, char *buf, size_t buflen);
-
-/*
- * NAME
- *   sread
- *
- * DESCRIPTION
- *   Reads exactly `n' bytes or fails. Syntax and other behavior is analogous
- *   to `read(2)'. If EOF is received the file descriptor is closed and an
- *   error is returned.
- *
- * PARAMETERS
- *   `fd'          File descriptor to write to.
- *   `buf'         Buffer that is to be written.
- *   `count'       Number of bytes in the buffer.
- *
- * RETURN VALUE
- *   Zero upon success or non-zero if an error occurred. `errno' is set in this
- *   case.
- */
-ssize_t sread (int fd, void *buf, size_t count);
-
-/*
- * NAME
- *   swrite
- *
- * DESCRIPTION
- *   Writes exactly `n' bytes or fails. Syntax and other behavior is analogous
- *   to `write(2)'.
- *
- * PARAMETERS
- *   `fd'          File descriptor to write to.
- *   `buf'         Buffer that is to be written.
- *   `count'       Number of bytes in the buffer.
- *
- * RETURN VALUE
- *   Zero upon success or non-zero if an error occurred. `errno' is set in this
- *   case.
- */
-ssize_t swrite (int fd, const void *buf, size_t count);
-
-/*
- * NAME
- *   strsplit
- *
- * DESCRIPTION
- *   Splits a string into parts and stores pointers to the parts in `fields'.
- *   The characters split at are: " ", "\t", "\r", and "\n".
- *
- * PARAMETERS
- *   `string'      String to split. This string will be modified. `fields' will
- *                 contain pointers to parts of this string, so free'ing it
- *                 will destroy `fields' as well.
- *   `fields'      Array of strings where pointers to the parts will be stored.
- *   `size'        Number of elements in the array. No more than `size'
- *                 pointers will be stored in `fields'.
- *
- * RETURN VALUE
- *    Returns the number of parts stored in `fields'.
- */
-int strsplit (char *string, char **fields, size_t size);
-
-/*
- * NAME
- *   strjoin
- *
- * DESCRIPTION
- *   Joins together several parts of a string using `sep' as a separator. This
- *   is equivalent to the Perl built-in `join'.
- *
- * PARAMETERS
- *   `dst'         Buffer where the result is stored.
- *   `dst_len'     Length of the destination buffer. No more than this many
- *                 bytes will be written to the memory pointed to by `dst',
- *                 including the trailing null-byte.
- *   `fields'      Array of strings to be joined.
- *   `fields_num'  Number of elements in the `fields' array.
- *   `sep'         String to be inserted between any two elements of `fields'.
- *                 This string is neither prepended nor appended to the result.
- *                 Instead of passing "" (empty string) one can pass NULL.
- *
- * RETURN VALUE
- *   Returns the number of characters in `dst', NOT including the trailing
- *   null-byte. If an error occurred (empty array or `dst' too small) a value
- *   smaller than zero will be returned.
- */
-int strjoin (char *dst, size_t dst_len, char **fields, size_t fields_num, const char *sep);
-
-/*
- * NAME
- *   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.
- *
- * 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.
- *
- * RETURN VALUE
- *   Returns zero upon success and a value smaller than zero upon failure.
- */
-int escape_slashes (char *buf, int buf_len);
-
-/*
- * NAME
- *   replace_special
- *
- * DESCRIPTION
- *   Replaces any special characters (anything that's not alpha-numeric or a
- *   dash) with an underscore.
- *
- *   E.g. "foo$bar&" would become "foo_bar_".
- *
- * PARAMETERS
- *   `buffer'      String to be handled.
- *   `buffer_size' Length of the string. The function returns after
- *                 encountering a null-byte or reading this many bytes.
- */
-void replace_special (char *buffer, size_t buffer_size);
-
-int strsubstitute (char *str, char c_from, char c_to);
-
-/*
- * NAME
- *   strunescape
- *
- * DESCRIPTION
- *   Replaces any escaped characters in a string with the appropriate special
- *   characters. The following escaped characters are recognized:
- *
- *     \t -> <tab>
- *     \n -> <newline>
- *     \r -> <carriage return>
- *
- *   For all other escacped characters only the backslash will be removed.
- *
- * PARAMETERS
- *   `buf'         String to be unescaped.
- *   `buf_len'     Length of the string, including the terminating null-byte.
- *
- * RETURN VALUE
- *   Returns zero upon success, a value less than zero else.
- */
-int strunescape (char *buf, size_t buf_len);
-
-/**
- * Removed trailing newline characters (CR and LF) from buffer, which must be
- * null terminated. Returns the length of the resulting string.
- */
-__attribute__((nonnull (1)))
-size_t strstripnewline (char *buffer);
-
-/*
- * NAME
- *   timeval_cmp
- *
- * DESCRIPTION
- *   Compare the two time values `tv0' and `tv1' and store the absolut value
- *   of the difference in the time value pointed to by `delta' if it does not
- *   equal NULL.
- *
- * RETURN VALUE
- *   Returns an integer less than, equal to, or greater than zero if `tv0' is
- *   less than, equal to, or greater than `tv1' respectively.
- */
-int timeval_cmp (struct timeval tv0, struct timeval tv1, struct timeval *delta);
-
-/* make sure tv_usec stores less than a second */
-#define NORMALIZE_TIMEVAL(tv) \
-       do { \
-               (tv).tv_sec += (tv).tv_usec / 1000000; \
-               (tv).tv_usec = (tv).tv_usec % 1000000; \
-       } while (0)
-
-/* make sure tv_sec stores less than a second */
-#define NORMALIZE_TIMESPEC(tv) \
-       do { \
-               (tv).tv_sec += (tv).tv_nsec / 1000000000; \
-               (tv).tv_nsec = (tv).tv_nsec % 1000000000; \
-       } while (0)
-
-int check_create_dir (const char *file_orig);
-
-#ifdef HAVE_LIBKSTAT
-int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name);
-long long get_kstat_value (kstat_t *ksp, char *name);
-#endif
-
-#ifndef HAVE_HTONLL
-unsigned long long ntohll (unsigned long long n);
-unsigned long long htonll (unsigned long long n);
-#endif
-
-#if FP_LAYOUT_NEED_NOTHING
-# define ntohd(d) (d)
-# define htond(d) (d)
-#elif FP_LAYOUT_NEED_ENDIANFLIP || FP_LAYOUT_NEED_INTSWAP
-double ntohd (double d);
-double htond (double d);
-#else
-# error "Don't know how to convert between host and network representation of doubles."
-#endif
-
-int format_name (char *ret, int ret_len,
-               const char *hostname,
-               const char *plugin, const char *plugin_instance,
-               const char *type, const char *type_instance);
-#define FORMAT_VL(ret, ret_len, vl) \
-       format_name (ret, ret_len, (vl)->host, (vl)->plugin, (vl)->plugin_instance, \
-                       (vl)->type, (vl)->type_instance)
-int format_values (char *ret, size_t ret_len,
-               const data_set_t *ds, const value_list_t *vl,
-               _Bool store_rates);
-
-int parse_identifier (char *str, char **ret_host,
-               char **ret_plugin, char **ret_plugin_instance,
-               char **ret_type, char **ret_type_instance);
-int parse_identifier_vl (const char *str, value_list_t *vl);
-int parse_value (const char *value, value_t *ret_value, int ds_type);
-int parse_values (char *buffer, value_list_t *vl, const data_set_t *ds);
-
-#if !HAVE_GETPWNAM_R
-int getpwnam_r (const char *name, struct passwd *pwbuf, char *buf,
-               size_t buflen, struct passwd **pwbufp);
-#endif
-
-int notification_init (notification_t *n, int severity, const char *message,
-               const char *host,
-               const char *plugin, const char *plugin_instance,
-               const char *type, const char *type_instance);
-#define NOTIFICATION_INIT_VL(n, vl) \
-       notification_init (n, NOTIF_FAILURE, NULL, \
-                       (vl)->host, (vl)->plugin, (vl)->plugin_instance, \
-                       (vl)->type, (vl)->type_instance)
-
-typedef int (*dirwalk_callback_f)(const char *dirname, const char *filename,
-               void *user_data);
-int walk_directory (const char *dir, dirwalk_callback_f callback,
-               void *user_data, int hidden);
-/* Returns the number of bytes read or negative on error. */
-ssize_t read_file_contents (char const *filename, char *buf, size_t bufsize);
-
-counter_t counter_diff (counter_t old_value, counter_t new_value);
-
-/* Convert a rate back to a value_t. When converting to a derive_t, counter_t
- * or absoltue_t, take fractional residuals into account. This is important
- * when scaling counters, for example.
- * Returns zero on success. Returns EAGAIN when called for the first time; in
- * this case the value_t is invalid and the next call should succeed. Other
- * return values indicate an error. */
-int rate_to_value (value_t *ret_value, gauge_t rate,
-               rate_to_value_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);
-
-/** Parse a string to a derive_t value. Returns zero on success or non-zero on
- * failure. If failure is returned, ret_value is not touched. */
-int strtoderive (const char *string, derive_t *ret_value);
-
-int strarray_add (char ***ret_array, size_t *ret_array_len, char const *str);
-void strarray_free (char **array, size_t array_len);
-
-#endif /* COMMON_H */
diff --git a/src/configfile.c b/src/configfile.c
deleted file mode 100644 (file)
index 32629e0..0000000
+++ /dev/null
@@ -1,1349 +0,0 @@
-/**
- * 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.
- *
- * 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
- *
- * Authors:
- *   Florian octo Forster <octo at collectd.org>
- *   Sebastian tokkee Harl <sh at tokkee.org>
- **/
-
-#include "collectd.h"
-
-#include "liboconfig/oconfig.h"
-
-#include "common.h"
-#include "plugin.h"
-#include "configfile.h"
-#include "types_list.h"
-#include "filter_chain.h"
-
-#if HAVE_WORDEXP_H
-# include <wordexp.h>
-#endif /* HAVE_WORDEXP_H */
-
-#if HAVE_FNMATCH_H
-# include <fnmatch.h>
-#endif /* HAVE_FNMATCH_H */
-
-#if HAVE_LIBGEN_H
-# include <libgen.h>
-#endif /* HAVE_LIBGEN_H */
-
-#define ESCAPE_NULL(str) ((str) == NULL ? "(null)" : (str))
-
-/*
- * Private types
- */
-typedef struct cf_callback
-{
-       const char  *type;
-       int  (*callback) (const char *, const char *);
-       const char **keys;
-       int    keys_num;
-       plugin_ctx_t ctx;
-       struct cf_callback *next;
-} cf_callback_t;
-
-typedef struct cf_complex_callback_s
-{
-       char *type;
-       int (*callback) (oconfig_item_t *);
-       plugin_ctx_t ctx;
-       struct cf_complex_callback_s *next;
-} cf_complex_callback_t;
-
-typedef struct cf_value_map_s
-{
-       char *key;
-       int (*func) (oconfig_item_t *);
-} cf_value_map_t;
-
-typedef struct cf_global_option_s
-{
-       char *key;
-       char *value;
-       char *def;
-} cf_global_option_t;
-
-/*
- * Prototypes of callback functions
- */
-static int dispatch_value_typesdb (oconfig_item_t *ci);
-static int dispatch_value_plugindir (oconfig_item_t *ci);
-static int dispatch_loadplugin (oconfig_item_t *ci);
-static int dispatch_block_plugin (oconfig_item_t *ci);
-
-/*
- * Private variables
- */
-static cf_callback_t *first_callback = NULL;
-static cf_complex_callback_t *complex_callback_head = NULL;
-
-static cf_value_map_t cf_value_map[] =
-{
-       {"TypesDB",    dispatch_value_typesdb},
-       {"PluginDir",  dispatch_value_plugindir},
-       {"LoadPlugin", dispatch_loadplugin},
-       {"Plugin",     dispatch_block_plugin}
-};
-static int cf_value_map_num = STATIC_ARRAY_SIZE (cf_value_map);
-
-static cf_global_option_t cf_global_options[] =
-{
-       {"BaseDir",     NULL, PKGLOCALSTATEDIR},
-       {"PIDFile",     NULL, PIDFILE},
-       {"Hostname",    NULL, NULL},
-       {"FQDNLookup",  NULL, "true"},
-       {"Interval",    NULL, NULL},
-       {"ReadThreads", NULL, "5"},
-       {"WriteThreads", NULL, "5"},
-       {"WriteQueueLimitHigh", NULL, NULL},
-       {"WriteQueueLimitLow", NULL, NULL},
-       {"Timeout",     NULL, "2"},
-       {"AutoLoadPlugin", NULL, "false"},
-       {"PreCacheChain",  NULL, "PreCache"},
-       {"PostCacheChain", NULL, "PostCache"}
-};
-static int cf_global_options_num = STATIC_ARRAY_SIZE (cf_global_options);
-
-static int cf_default_typesdb = 1;
-
-/*
- * Functions to handle register/unregister, search, and other plugin related
- * stuff
- */
-static cf_callback_t *cf_search (const char *type)
-{
-       cf_callback_t *cf_cb;
-
-       if (type == NULL)
-               return (NULL);
-
-       for (cf_cb = first_callback; cf_cb != NULL; cf_cb = cf_cb->next)
-               if (strcasecmp (cf_cb->type, type) == 0)
-                       break;
-
-       return (cf_cb);
-}
-
-static int cf_dispatch (const char *type, const char *orig_key,
-               const char *orig_value)
-{
-       cf_callback_t *cf_cb;
-       plugin_ctx_t old_ctx;
-       char *key;
-       char *value;
-       int ret;
-       int i;
-
-       if (orig_key == NULL)
-               return (EINVAL);
-
-       DEBUG ("type = %s, key = %s, value = %s",
-                       ESCAPE_NULL(type),
-                       orig_key,
-                       ESCAPE_NULL(orig_value));
-
-       if ((cf_cb = cf_search (type)) == NULL)
-       {
-               WARNING ("Found a configuration for the `%s' plugin, but "
-                               "the plugin isn't loaded or didn't register "
-                               "a configuration callback.", type);
-               return (-1);
-       }
-
-       if ((key = strdup (orig_key)) == NULL)
-               return (1);
-       if ((value = strdup (orig_value)) == NULL)
-       {
-               free (key);
-               return (2);
-       }
-
-       ret = -1;
-
-       old_ctx = plugin_set_ctx (cf_cb->ctx);
-
-       for (i = 0; i < cf_cb->keys_num; i++)
-       {
-               if ((cf_cb->keys[i] != NULL)
-                               && (strcasecmp (cf_cb->keys[i], key) == 0))
-               {
-                       ret = (*cf_cb->callback) (key, value);
-                       break;
-               }
-       }
-
-       plugin_set_ctx (old_ctx);
-
-       if (i >= cf_cb->keys_num)
-               WARNING ("Plugin `%s' did not register for value `%s'.", type, key);
-
-       free (key);
-       free (value);
-
-       return (ret);
-} /* int cf_dispatch */
-
-static int dispatch_global_option (const oconfig_item_t *ci)
-{
-       if (ci->values_num != 1)
-               return (-1);
-       if (ci->values[0].type == OCONFIG_TYPE_STRING)
-               return (global_option_set (ci->key, ci->values[0].value.string));
-       else if (ci->values[0].type == OCONFIG_TYPE_NUMBER)
-       {
-               char tmp[128];
-               ssnprintf (tmp, sizeof (tmp), "%lf", ci->values[0].value.number);
-               return (global_option_set (ci->key, tmp));
-       }
-       else if (ci->values[0].type == OCONFIG_TYPE_BOOLEAN)
-       {
-               if (ci->values[0].value.boolean)
-                       return (global_option_set (ci->key, "true"));
-               else
-                       return (global_option_set (ci->key, "false"));
-       }
-
-       return (-1);
-} /* int dispatch_global_option */
-
-static int dispatch_value_typesdb (oconfig_item_t *ci)
-{
-       int i = 0;
-
-       assert (strcasecmp (ci->key, "TypesDB") == 0);
-
-       cf_default_typesdb = 0;
-
-       if (ci->values_num < 1) {
-               ERROR ("configfile: `TypesDB' needs at least one argument.");
-               return (-1);
-       }
-
-       for (i = 0; i < ci->values_num; ++i)
-       {
-               if (OCONFIG_TYPE_STRING != ci->values[i].type) {
-                       WARNING ("configfile: TypesDB: Skipping %i. argument which "
-                                       "is not a string.", i + 1);
-                       continue;
-               }
-
-               read_types_list (ci->values[i].value.string);
-       }
-       return (0);
-} /* int dispatch_value_typesdb */
-
-static int dispatch_value_plugindir (oconfig_item_t *ci)
-{
-       assert (strcasecmp (ci->key, "PluginDir") == 0);
-       
-       if (ci->values_num != 1)
-               return (-1);
-       if (ci->values[0].type != OCONFIG_TYPE_STRING)
-               return (-1);
-
-       plugin_set_dir (ci->values[0].value.string);
-       return (0);
-}
-
-static int dispatch_loadplugin (oconfig_item_t *ci)
-{
-       int i;
-       const char *name;
-       unsigned int flags = 0;
-       plugin_ctx_t ctx;
-       plugin_ctx_t old_ctx;
-       int ret_val;
-
-       assert (strcasecmp (ci->key, "LoadPlugin") == 0);
-
-       if (ci->values_num != 1)
-               return (-1);
-       if (ci->values[0].type != OCONFIG_TYPE_STRING)
-               return (-1);
-
-       name = ci->values[0].value.string;
-
-       /* default to the global interval set before loading this plugin */
-       memset (&ctx, 0, sizeof (ctx));
-       ctx.interval = cf_get_default_interval ();
-
-       for (i = 0; i < ci->children_num; ++i) {
-               if (strcasecmp("Globals", ci->children[i].key) == 0)
-                       cf_util_get_flag (ci->children + i, &flags, PLUGIN_FLAGS_GLOBAL);
-               else if (strcasecmp ("Interval", ci->children[i].key) == 0) {
-                       double interval = 0.0;
-
-                       if (cf_util_get_double (ci->children + i, &interval) != 0) {
-                               /* cf_util_get_double will log an error */
-                               continue;
-                       }
-
-                       ctx.interval = DOUBLE_TO_CDTIME_T (interval);
-               }
-               else {
-                       WARNING("Ignoring unknown LoadPlugin option \"%s\" "
-                                       "for plugin \"%s\"",
-                                       ci->children[i].key, ci->values[0].value.string);
-               }
-       }
-
-       old_ctx = plugin_set_ctx (ctx);
-       ret_val = plugin_load (name, (uint32_t) flags);
-       /* reset to the "global" context */
-       plugin_set_ctx (old_ctx);
-
-       return (ret_val);
-} /* int dispatch_value_loadplugin */
-
-static int dispatch_value_plugin (const char *plugin, oconfig_item_t *ci)
-{
-       char  buffer[4096];
-       char *buffer_ptr;
-       int   buffer_free;
-       int i;
-
-       buffer_ptr = buffer;
-       buffer_free = sizeof (buffer);
-
-       for (i = 0; i < ci->values_num; i++)
-       {
-               int status = -1;
-
-               if (ci->values[i].type == OCONFIG_TYPE_STRING)
-                       status = ssnprintf (buffer_ptr, buffer_free, " %s",
-                                       ci->values[i].value.string);
-               else if (ci->values[i].type == OCONFIG_TYPE_NUMBER)
-                       status = ssnprintf (buffer_ptr, buffer_free, " %lf",
-                                       ci->values[i].value.number);
-               else if (ci->values[i].type == OCONFIG_TYPE_BOOLEAN)
-                       status = ssnprintf (buffer_ptr, buffer_free, " %s",
-                                       ci->values[i].value.boolean
-                                       ? "true" : "false");
-
-               if ((status < 0) || (status >= buffer_free))
-                       return (-1);
-               buffer_free -= status;
-               buffer_ptr  += status;
-       }
-       /* skip the initial space */
-       buffer_ptr = buffer + 1;
-
-       return (cf_dispatch (plugin, ci->key, buffer_ptr));
-} /* int dispatch_value_plugin */
-
-static int dispatch_value (oconfig_item_t *ci)
-{
-       int ret = -2;
-       int i;
-
-       for (i = 0; i < cf_value_map_num; i++)
-               if (strcasecmp (cf_value_map[i].key, ci->key) == 0)
-               {
-                       ret = cf_value_map[i].func (ci);
-                       break;
-               }
-
-       for (i = 0; i < cf_global_options_num; i++)
-               if (strcasecmp (cf_global_options[i].key, ci->key) == 0)
-               {
-                       ret = dispatch_global_option (ci);
-                       break;
-               }
-
-       return (ret);
-} /* int dispatch_value */
-
-static int dispatch_block_plugin (oconfig_item_t *ci)
-{
-       int i;
-       char *name;
-
-       cf_complex_callback_t *cb;
-
-       if (strcasecmp (ci->key, "Plugin") != 0)
-               return (-1);
-       if (ci->values_num < 1)
-               return (-1);
-       if (ci->values[0].type != OCONFIG_TYPE_STRING)
-               return (-1);
-
-       name = ci->values[0].value.string;
-
-       if (IS_TRUE (global_option_get ("AutoLoadPlugin")))
-       {
-               plugin_ctx_t ctx;
-               plugin_ctx_t old_ctx;
-               int status;
-
-               /* default to the global interval set before loading this plugin */
-               memset (&ctx, 0, sizeof (ctx));
-               ctx.interval = cf_get_default_interval ();
-
-               old_ctx = plugin_set_ctx (ctx);
-               status = plugin_load (name, /* flags = */ 0);
-               /* reset to the "global" context */
-               plugin_set_ctx (old_ctx);
-
-               if (status != 0)
-               {
-                       ERROR ("Automatically loading plugin \"%s\" failed "
-                                       "with status %i.", name, status);
-                       return (status);
-               }
-       }
-
-       /* Check for a complex callback first */
-       for (cb = complex_callback_head; cb != NULL; cb = cb->next)
-       {
-               if (strcasecmp (name, cb->type) == 0)
-               {
-                       plugin_ctx_t old_ctx;
-                       int ret_val;
-
-                       old_ctx = plugin_set_ctx (cb->ctx);
-                       ret_val = (cb->callback (ci));
-                       plugin_set_ctx (old_ctx);
-                       return (ret_val);
-               }
-       }
-
-       /* Hm, no complex plugin found. Dispatch the values one by one */
-       for (i = 0; i < ci->children_num; i++)
-       {
-               if (ci->children[i].children == NULL)
-                       dispatch_value_plugin (name, ci->children + i);
-               else
-               {
-                       WARNING ("There is a `%s' block within the "
-                                       "configuration for the %s plugin. "
-                                       "The plugin either only expects "
-                                       "\"simple\" configuration statements "
-                                       "or wasn't loaded using `LoadPlugin'."
-                                       " Please check your configuration.",
-                                       ci->children[i].key, name);
-               }
-       }
-
-       return (0);
-}
-
-
-static int dispatch_block (oconfig_item_t *ci)
-{
-       if (strcasecmp (ci->key, "LoadPlugin") == 0)
-               return (dispatch_loadplugin (ci));
-       else if (strcasecmp (ci->key, "Plugin") == 0)
-               return (dispatch_block_plugin (ci));
-       else if (strcasecmp (ci->key, "Chain") == 0)
-               return (fc_configure (ci));
-
-       return (0);
-}
-
-static int cf_ci_replace_child (oconfig_item_t *dst, oconfig_item_t *src,
-               int offset)
-{
-       oconfig_item_t *temp;
-       int i;
-
-       assert (offset >= 0);
-       assert (dst->children_num > offset);
-
-       /* Free the memory used by the replaced child. Usually that's the
-        * `Include "blah"' statement. */
-       temp = dst->children + offset;
-       for (i = 0; i < temp->values_num; i++)
-       {
-               if (temp->values[i].type == OCONFIG_TYPE_STRING)
-               {
-                       sfree (temp->values[i].value.string);
-               }
-       }
-       sfree (temp->values);
-       temp = NULL;
-
-       /* If (src->children_num == 0) the array size is decreased. If offset
-        * is _not_ the last element, (offset < (dst->children_num - 1)), then
-        * we need to move the trailing elements before resizing the array. */
-       if ((src->children_num == 0) && (offset < (dst->children_num - 1)))
-       {
-               int nmemb = dst->children_num - (offset + 1);
-               memmove (dst->children + offset, dst->children + offset + 1,
-                               sizeof (oconfig_item_t) * nmemb);
-       }
-
-       /* Resize the memory containing the children to be big enough to hold
-        * all children. */
-       if (dst->children_num + src->children_num - 1 == 0)
-       {
-               dst->children_num = 0;
-               return (0);
-       }
-
-       temp = (oconfig_item_t *) realloc (dst->children,
-                       sizeof (oconfig_item_t)
-                       * (dst->children_num + src->children_num - 1));
-       if (temp == NULL)
-       {
-               ERROR ("configfile: realloc failed.");
-               return (-1);
-       }
-       dst->children = temp;
-
-       /* If there are children behind the include statement, and they have
-        * not yet been moved because (src->children_num == 0), then move them
-        * to the end of the list, so that the new children have room before
-        * them. */
-       if ((src->children_num > 0)
-                       && ((dst->children_num - (offset + 1)) > 0))
-       {
-               int nmemb = dst->children_num - (offset + 1);
-               int old_offset = offset + 1;
-               int new_offset = offset + src->children_num;
-
-               memmove (dst->children + new_offset,
-                               dst->children + old_offset,
-                               sizeof (oconfig_item_t) * nmemb);
-       }
-
-       /* Last but not least: If there are new children, copy them to the
-        * memory reserved for them. */
-       if (src->children_num > 0)
-       {
-               memcpy (dst->children + offset,
-                               src->children,
-                               sizeof (oconfig_item_t) * src->children_num);
-       }
-
-       /* Update the number of children. */
-       dst->children_num += (src->children_num - 1);
-
-       return (0);
-} /* int cf_ci_replace_child */
-
-static int cf_ci_append_children (oconfig_item_t *dst, oconfig_item_t *src)
-{
-       oconfig_item_t *temp;
-
-       if ((src == NULL) || (src->children_num == 0))
-               return (0);
-
-       temp = (oconfig_item_t *) realloc (dst->children,
-                       sizeof (oconfig_item_t)
-                       * (dst->children_num + src->children_num));
-       if (temp == NULL)
-       {
-               ERROR ("configfile: realloc failed.");
-               return (-1);
-       }
-       dst->children = temp;
-
-       memcpy (dst->children + dst->children_num,
-                       src->children,
-                       sizeof (oconfig_item_t)
-                       * src->children_num);
-       dst->children_num += src->children_num;
-
-       return (0);
-} /* int cf_ci_append_children */
-
-#define CF_MAX_DEPTH 8
-static oconfig_item_t *cf_read_generic (const char *path,
-               const char *pattern, int depth);
-
-static int cf_include_all (oconfig_item_t *root, int depth)
-{
-       int i;
-
-       for (i = 0; i < root->children_num; i++)
-       {
-               oconfig_item_t *new;
-               oconfig_item_t *old;
-
-               char *pattern = NULL;
-
-               int j;
-
-               if (strcasecmp (root->children[i].key, "Include") != 0)
-                       continue;
-
-               old = root->children + i;
-
-               if ((old->values_num != 1)
-                               || (old->values[0].type != OCONFIG_TYPE_STRING))
-               {
-                       ERROR ("configfile: `Include' needs exactly one string argument.");
-                       continue;
-               }
-
-               for (j = 0; j < old->children_num; ++j)
-               {
-                       oconfig_item_t *child = old->children + j;
-
-                       if (strcasecmp (child->key, "Filter") == 0)
-                               cf_util_get_string (child, &pattern);
-                       else
-                               ERROR ("configfile: Option `%s' not allowed in <Include> block.",
-                                               child->key);
-               }
-
-               new = cf_read_generic (old->values[0].value.string, pattern, depth + 1);
-               sfree (pattern);
-
-               if (new == NULL)
-                       return (-1);
-
-               /* Now replace the i'th child in `root' with `new'. */
-               if (cf_ci_replace_child (root, new, i) < 0) {
-                       sfree (new->values);
-                       sfree (new);
-                       return (-1);
-               }
-
-               /* ... and go back to the new i'th child. */
-               --i;
-
-               sfree (new->values);
-               sfree (new);
-       } /* for (i = 0; i < root->children_num; i++) */
-
-       return (0);
-} /* int cf_include_all */
-
-static oconfig_item_t *cf_read_file (const char *file,
-               const char *pattern, int depth)
-{
-       oconfig_item_t *root;
-       int status;
-
-       assert (depth < CF_MAX_DEPTH);
-
-       if (pattern != NULL) {
-#if HAVE_FNMATCH_H && HAVE_LIBGEN_H
-               char *tmp = sstrdup (file);
-               char *filename = basename (tmp);
-
-               if ((filename != NULL) && (fnmatch (pattern, filename, 0) != 0)) {
-                       DEBUG ("configfile: Not including `%s' because it "
-                                       "does not match pattern `%s'.",
-                                       filename, pattern);
-                       free (tmp);
-                       return (NULL);
-               }
-
-               free (tmp);
-#else
-               ERROR ("configfile: Cannot apply pattern filter '%s' "
-                               "to file '%s': functions basename() and / or "
-                               "fnmatch() not available.", pattern, file);
-#endif /* HAVE_FNMATCH_H && HAVE_LIBGEN_H */
-       }
-
-       root = oconfig_parse_file (file);
-       if (root == NULL)
-       {
-               ERROR ("configfile: Cannot read file `%s'.", file);
-               return (NULL);
-       }
-
-       status = cf_include_all (root, depth);
-       if (status != 0)
-       {
-               oconfig_free (root);
-               return (NULL);
-       }
-
-       return (root);
-} /* oconfig_item_t *cf_read_file */
-
-static int cf_compare_string (const void *p1, const void *p2)
-{
-       return strcmp (*(const char **) p1, *(const char **) p2);
-}
-
-static oconfig_item_t *cf_read_dir (const char *dir,
-               const char *pattern, int depth)
-{
-       oconfig_item_t *root = NULL;
-       DIR *dh;
-       struct dirent *de;
-       char **filenames = NULL;
-       int filenames_num = 0;
-       int status;
-       int i;
-
-       assert (depth < CF_MAX_DEPTH);
-
-       dh = opendir (dir);
-       if (dh == NULL)
-       {
-               char errbuf[1024];
-               ERROR ("configfile: opendir failed: %s",
-                               sstrerror (errno, errbuf, sizeof (errbuf)));
-               return (NULL);
-       }
-
-       root = (oconfig_item_t *) malloc (sizeof (oconfig_item_t));
-       if (root == NULL)
-       {
-               ERROR ("configfile: malloc failed.");
-               return (NULL);
-       }
-       memset (root, 0, sizeof (oconfig_item_t));
-
-       while ((de = readdir (dh)) != NULL)
-       {
-               char   name[1024];
-               char **tmp;
-
-               if ((de->d_name[0] == '.') || (de->d_name[0] == 0))
-                       continue;
-
-               status = ssnprintf (name, sizeof (name), "%s/%s",
-                               dir, de->d_name);
-               if ((status < 0) || ((size_t) status >= sizeof (name)))
-               {
-                       ERROR ("configfile: Not including `%s/%s' because its"
-                                       " name is too long.",
-                                       dir, de->d_name);
-                       for (i = 0; i < filenames_num; ++i)
-                               free (filenames[i]);
-                       free (filenames);
-                       free (root);
-                       return (NULL);
-               }
-
-               ++filenames_num;
-               tmp = (char **) realloc (filenames,
-                               filenames_num * sizeof (*filenames));
-               if (tmp == NULL) {
-                       ERROR ("configfile: realloc failed.");
-                       for (i = 0; i < filenames_num - 1; ++i)
-                               free (filenames[i]);
-                       free (filenames);
-                       free (root);
-                       return (NULL);
-               }
-               filenames = tmp;
-
-               filenames[filenames_num - 1] = sstrdup (name);
-       }
-
-       if (filenames == NULL)
-               return (root);
-
-       qsort ((void *) filenames, filenames_num, sizeof (*filenames),
-                       cf_compare_string);
-
-       for (i = 0; i < filenames_num; ++i)
-       {
-               oconfig_item_t *temp;
-               char *name = filenames[i];
-
-               temp = cf_read_generic (name, pattern, depth);
-               if (temp == NULL)
-               {
-                       /* An error should already have been reported. */
-                       sfree (name);
-                       continue;
-               }
-
-               cf_ci_append_children (root, temp);
-               sfree (temp->children);
-               sfree (temp);
-
-               free (name);
-       }
-
-       free(filenames);
-       return (root);
-} /* oconfig_item_t *cf_read_dir */
-
-/* 
- * cf_read_generic
- *
- * Path is stat'ed and either cf_read_file or cf_read_dir is called
- * accordingly.
- *
- * There are two versions of this function: If `wordexp' exists shell wildcards
- * will be expanded and the function will include all matches found. If
- * `wordexp' (or, more precisely, it's header file) is not available the
- * simpler function is used which does not do any such expansion.
- */
-#if HAVE_WORDEXP_H
-static oconfig_item_t *cf_read_generic (const char *path,
-               const char *pattern, int depth)
-{
-       oconfig_item_t *root = NULL;
-       int status;
-       const char *path_ptr;
-       wordexp_t we;
-       size_t i;
-
-       if (depth >= CF_MAX_DEPTH)
-       {
-               ERROR ("configfile: Not including `%s' because the maximum "
-                               "nesting depth has been reached.", path);
-               return (NULL);
-       }
-
-       status = wordexp (path, &we, WRDE_NOCMD);
-       if (status != 0)
-       {
-               ERROR ("configfile: wordexp (%s) failed.", path);
-               return (NULL);
-       }
-
-       root = (oconfig_item_t *) malloc (sizeof (oconfig_item_t));
-       if (root == NULL)
-       {
-               ERROR ("configfile: malloc failed.");
-               return (NULL);
-       }
-       memset (root, '\0', sizeof (oconfig_item_t));
-
-       /* wordexp() might return a sorted list already. That's not
-        * documented though, so let's make sure we get what we want. */
-       qsort ((void *) we.we_wordv, we.we_wordc, sizeof (*we.we_wordv),
-                       cf_compare_string);
-
-       for (i = 0; i < we.we_wordc; i++)
-       {
-               oconfig_item_t *temp;
-               struct stat statbuf;
-
-               path_ptr = we.we_wordv[i];
-
-               status = stat (path_ptr, &statbuf);
-               if (status != 0)
-               {
-                       char errbuf[1024];
-                       WARNING ("configfile: stat (%s) failed: %s",
-                                       path_ptr,
-                                       sstrerror (errno, errbuf, sizeof (errbuf)));
-                       continue;
-               }
-
-               if (S_ISREG (statbuf.st_mode))
-                       temp = cf_read_file (path_ptr, pattern, depth);
-               else if (S_ISDIR (statbuf.st_mode))
-                       temp = cf_read_dir (path_ptr, pattern, depth);
-               else
-               {
-                       WARNING ("configfile: %s is neither a file nor a "
-                                       "directory.", path);
-                       continue;
-               }
-
-               if (temp == NULL) {
-                       oconfig_free (root);
-                       return (NULL);
-               }
-
-               cf_ci_append_children (root, temp);
-               sfree (temp->children);
-               sfree (temp);
-       }
-
-       wordfree (&we);
-
-       return (root);
-} /* oconfig_item_t *cf_read_generic */
-/* #endif HAVE_WORDEXP_H */
-
-#else /* if !HAVE_WORDEXP_H */
-static oconfig_item_t *cf_read_generic (const char *path,
-               const char *pattern, int depth)
-{
-       struct stat statbuf;
-       int status;
-
-       if (depth >= CF_MAX_DEPTH)
-       {
-               ERROR ("configfile: Not including `%s' because the maximum "
-                               "nesting depth has been reached.", path);
-               return (NULL);
-       }
-
-       status = stat (path, &statbuf);
-       if (status != 0)
-       {
-               char errbuf[1024];
-               ERROR ("configfile: stat (%s) failed: %s",
-                               path,
-                               sstrerror (errno, errbuf, sizeof (errbuf)));
-               return (NULL);
-       }
-
-       if (S_ISREG (statbuf.st_mode))
-               return (cf_read_file (path, pattern, depth));
-       else if (S_ISDIR (statbuf.st_mode))
-               return (cf_read_dir (path, pattern, depth));
-
-       ERROR ("configfile: %s is neither a file nor a directory.", path);
-       return (NULL);
-} /* oconfig_item_t *cf_read_generic */
-#endif /* !HAVE_WORDEXP_H */
-
-/* 
- * Public functions
- */
-int global_option_set (const char *option, const char *value)
-{
-       int i;
-
-       DEBUG ("option = %s; value = %s;", option, value);
-
-       for (i = 0; i < cf_global_options_num; i++)
-               if (strcasecmp (cf_global_options[i].key, option) == 0)
-                       break;
-
-       if (i >= cf_global_options_num)
-               return (-1);
-
-       sfree (cf_global_options[i].value);
-
-       if (value != NULL)
-               cf_global_options[i].value = strdup (value);
-       else
-               cf_global_options[i].value = NULL;
-
-       return (0);
-}
-
-const char *global_option_get (const char *option)
-{
-       int i;
-
-       for (i = 0; i < cf_global_options_num; i++)
-               if (strcasecmp (cf_global_options[i].key, option) == 0)
-                       break;
-
-       if (i >= cf_global_options_num)
-               return (NULL);
-       
-       return ((cf_global_options[i].value != NULL)
-                       ? cf_global_options[i].value
-                       : cf_global_options[i].def);
-} /* char *global_option_get */
-
-long global_option_get_long (const char *option, long default_value)
-{
-               const char *str;
-               long value;
-
-               str = global_option_get (option);
-               if (NULL == str)
-                       return (default_value);
-
-               errno = 0;
-               value = strtol (str, /* endptr = */ NULL, /* base = */ 0);
-               if (errno != 0)
-                       return (default_value);
-
-               return (value);
-} /* char *global_option_get_long */
-
-cdtime_t cf_get_default_interval (void)
-{
-  char const *str = global_option_get ("Interval");
-  double interval_double = COLLECTD_DEFAULT_INTERVAL;
-
-  if (str != NULL)
-  {
-    char *endptr = NULL;
-    double tmp = strtod (str, &endptr);
-
-    if ((endptr == NULL) || (endptr == str) || (*endptr != 0))
-      ERROR ("cf_get_default_interval: Unable to parse string \"%s\" "
-          "as number.", str);
-    else if (tmp <= 0.0)
-      ERROR ("cf_get_default_interval: Interval must be a positive number. "
-          "The current number is %g.", tmp);
-    else
-      interval_double = tmp;
-  }
-
-  return (DOUBLE_TO_CDTIME_T (interval_double));
-} /* }}} cdtime_t cf_get_default_interval */
-
-void cf_unregister (const char *type)
-{
-       cf_callback_t *this, *prev;
-
-       for (prev = NULL, this = first_callback;
-                       this != NULL;
-                       prev = this, this = this->next)
-               if (strcasecmp (this->type, type) == 0)
-               {
-                       if (prev == NULL)
-                               first_callback = this->next;
-                       else
-                               prev->next = this->next;
-
-                       free (this);
-                       break;
-               }
-} /* void cf_unregister */
-
-void cf_unregister_complex (const char *type)
-{
-       cf_complex_callback_t *this, *prev;
-
-       for (prev = NULL, this = complex_callback_head;
-                       this != NULL;
-                       prev = this, this = this->next)
-               if (strcasecmp (this->type, type) == 0)
-               {
-                       if (prev == NULL)
-                               complex_callback_head = this->next;
-                       else
-                               prev->next = this->next;
-
-                       sfree (this->type);
-                       sfree (this);
-                       break;
-               }
-} /* void cf_unregister */
-
-void cf_register (const char *type,
-               int (*callback) (const char *, const char *),
-               const char **keys, int keys_num)
-{
-       cf_callback_t *cf_cb;
-
-       /* Remove this module from the list, if it already exists */
-       cf_unregister (type);
-
-       /* This pointer will be free'd in `cf_unregister' */
-       if ((cf_cb = (cf_callback_t *) malloc (sizeof (cf_callback_t))) == NULL)
-               return;
-
-       cf_cb->type     = type;
-       cf_cb->callback = callback;
-       cf_cb->keys     = keys;
-       cf_cb->keys_num = keys_num;
-       cf_cb->ctx      = plugin_get_ctx ();
-
-       cf_cb->next = first_callback;
-       first_callback = cf_cb;
-} /* void cf_register */
-
-int cf_register_complex (const char *type, int (*callback) (oconfig_item_t *))
-{
-       cf_complex_callback_t *new;
-
-       new = (cf_complex_callback_t *) malloc (sizeof (cf_complex_callback_t));
-       if (new == NULL)
-               return (-1);
-
-       new->type = strdup (type);
-       if (new->type == NULL)
-       {
-               sfree (new);
-               return (-1);
-       }
-
-       new->callback = callback;
-       new->next = NULL;
-
-       new->ctx = plugin_get_ctx ();
-
-       if (complex_callback_head == NULL)
-       {
-               complex_callback_head = new;
-       }
-       else
-       {
-               cf_complex_callback_t *last = complex_callback_head;
-               while (last->next != NULL)
-                       last = last->next;
-               last->next = new;
-       }
-
-       return (0);
-} /* int cf_register_complex */
-
-int cf_read (char *filename)
-{
-       oconfig_item_t *conf;
-       int i;
-
-       conf = cf_read_generic (filename, /* pattern = */ NULL, /* depth = */ 0);
-       if (conf == NULL)
-       {
-               ERROR ("Unable to read config file %s.", filename);
-               return (-1);
-       }
-       else if (conf->children_num == 0)
-       {
-               ERROR ("Configuration file %s is empty.", filename);
-               oconfig_free (conf);
-               return (-1);
-       }
-
-       for (i = 0; i < conf->children_num; i++)
-       {
-               if (conf->children[i].children == NULL)
-                       dispatch_value (conf->children + i);
-               else
-                       dispatch_block (conf->children + i);
-       }
-
-       oconfig_free (conf);
-
-       /* Read the default types.db if no `TypesDB' option was given. */
-       if (cf_default_typesdb)
-               read_types_list (PKGDATADIR"/types.db");
-
-       return (0);
-} /* int cf_read */
-
-/* Assures the config option is a string, duplicates it and returns the copy in
- * "ret_string". If necessary "*ret_string" is freed first. Returns zero upon
- * success. */
-int cf_util_get_string (const oconfig_item_t *ci, char **ret_string) /* {{{ */
-{
-       char *string;
-
-       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
-       {
-               ERROR ("cf_util_get_string: The %s option requires "
-                               "exactly one string argument.", ci->key);
-               return (-1);
-       }
-
-       string = strdup (ci->values[0].value.string);
-       if (string == NULL)
-               return (-1);
-
-       if (*ret_string != NULL)
-               sfree (*ret_string);
-       *ret_string = string;
-
-       return (0);
-} /* }}} int cf_util_get_string */
-
-/* Assures the config option is a string and copies it to the provided buffer.
- * Assures null-termination. */
-int cf_util_get_string_buffer (const oconfig_item_t *ci, char *buffer, /* {{{ */
-               size_t buffer_size)
-{
-       if ((ci == NULL) || (buffer == NULL) || (buffer_size < 1))
-               return (EINVAL);
-
-       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
-       {
-               ERROR ("cf_util_get_string_buffer: The %s option requires "
-                               "exactly one string argument.", ci->key);
-               return (-1);
-       }
-
-       strncpy (buffer, ci->values[0].value.string, buffer_size);
-       buffer[buffer_size - 1] = 0;
-
-       return (0);
-} /* }}} int cf_util_get_string_buffer */
-
-/* Assures the config option is a number and returns it as an int. */
-int cf_util_get_int (const oconfig_item_t *ci, int *ret_value) /* {{{ */
-{
-       if ((ci == NULL) || (ret_value == NULL))
-               return (EINVAL);
-
-       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
-       {
-               ERROR ("cf_util_get_int: The %s option requires "
-                               "exactly one numeric argument.", ci->key);
-               return (-1);
-       }
-
-       *ret_value = (int) ci->values[0].value.number;
-
-       return (0);
-} /* }}} int cf_util_get_int */
-
-int cf_util_get_double (const oconfig_item_t *ci, double *ret_value) /* {{{ */
-{
-       if ((ci == NULL) || (ret_value == NULL))
-               return (EINVAL);
-
-       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
-       {
-               ERROR ("cf_util_get_double: The %s option requires "
-                               "exactly one numeric argument.", ci->key);
-               return (-1);
-       }
-
-       *ret_value = ci->values[0].value.number;
-
-       return (0);
-} /* }}} int cf_util_get_double */
-
-int cf_util_get_boolean (const oconfig_item_t *ci, _Bool *ret_bool) /* {{{ */
-{
-       if ((ci == NULL) || (ret_bool == NULL))
-               return (EINVAL);
-
-       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
-       {
-               ERROR ("cf_util_get_boolean: The %s option requires "
-                               "exactly one boolean argument.", ci->key);
-               return (-1);
-       }
-
-       *ret_bool = ci->values[0].value.boolean ? 1 : 0;
-
-       return (0);
-} /* }}} int cf_util_get_boolean */
-
-int cf_util_get_flag (const oconfig_item_t *ci, /* {{{ */
-               unsigned int *ret_value, unsigned int flag)
-{
-       int status;
-       _Bool b;
-
-       if (ret_value == NULL)
-               return (EINVAL);
-
-       b = 0;
-       status = cf_util_get_boolean (ci, &b);
-       if (status != 0)
-               return (status);
-
-       if (b)
-       {
-               *ret_value |= flag;
-       }
-       else
-       {
-               *ret_value &= ~flag;
-       }
-
-       return (0);
-} /* }}} int cf_util_get_flag */
-
-/* Assures that the config option is a string or a number if the correct range
- * of 1-65535. The string is then converted to a port number using
- * `service_name_to_port_number' and returned.
- * Returns the port number in the range [1-65535] or less than zero upon
- * failure. */
-int cf_util_get_port_number (const oconfig_item_t *ci) /* {{{ */
-{
-       int tmp;
-
-       if ((ci->values_num != 1)
-                       || ((ci->values[0].type != OCONFIG_TYPE_STRING)
-                               && (ci->values[0].type != OCONFIG_TYPE_NUMBER)))
-       {
-               ERROR ("cf_util_get_port_number: The \"%s\" option requires "
-                               "exactly one string argument.", ci->key);
-               return (-1);
-       }
-
-       if (ci->values[0].type == OCONFIG_TYPE_STRING)
-               return (service_name_to_port_number (ci->values[0].value.string));
-
-       assert (ci->values[0].type == OCONFIG_TYPE_NUMBER);
-       tmp = (int) (ci->values[0].value.number + 0.5);
-       if ((tmp < 1) || (tmp > 65535))
-       {
-               ERROR ("cf_util_get_port_number: The \"%s\" option requires "
-                               "a service name or a port number. The number "
-                               "you specified, %i, is not in the valid "
-                               "range of 1-65535.",
-                               ci->key, tmp);
-               return (-1);
-       }
-
-       return (tmp);
-} /* }}} int cf_util_get_port_number */
-
-int cf_util_get_service (const oconfig_item_t *ci, char **ret_string) /* {{{ */
-{
-       int port;
-       char *service;
-       int status;
-
-       if (ci->values_num != 1)
-       {
-               ERROR ("cf_util_get_service: The %s option requires exactly "
-                               "one argument.", ci->key);
-               return (-1);
-       }
-
-       if (ci->values[0].type == OCONFIG_TYPE_STRING)
-               return (cf_util_get_string (ci, ret_string));
-       if (ci->values[0].type != OCONFIG_TYPE_NUMBER)
-       {
-               ERROR ("cf_util_get_service: The %s option requires "
-                               "exactly one string or numeric argument.",
-                               ci->key);
-       }
-
-       port = 0;
-       status = cf_util_get_int (ci, &port);
-       if (status != 0)
-               return (status);
-       else if ((port < 1) || (port > 65535))
-       {
-               ERROR ("cf_util_get_service: The port number given "
-                               "for the %s option is out of "
-                               "range (%i).", ci->key, port);
-               return (-1);
-       }
-
-       service = malloc (6);
-       if (service == NULL)
-       {
-               ERROR ("cf_util_get_service: Out of memory.");
-               return (-1);
-       }
-       ssnprintf (service, 6, "%i", port);
-
-       sfree (*ret_string);
-       *ret_string = service;
-
-       return (0);
-} /* }}} int cf_util_get_service */
-
-int cf_util_get_cdtime (const oconfig_item_t *ci, cdtime_t *ret_value) /* {{{ */
-{
-       if ((ci == NULL) || (ret_value == NULL))
-               return (EINVAL);
-
-       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
-       {
-               ERROR ("cf_util_get_cdtime: The %s option requires "
-                               "exactly one numeric argument.", ci->key);
-               return (-1);
-       }
-
-       if (ci->values[0].value.number < 0.0)
-       {
-               ERROR ("cf_util_get_cdtime: The numeric argument of the %s "
-                               "option must not be negative.", ci->key);
-               return (-1);
-       }
-
-       *ret_value = DOUBLE_TO_CDTIME_T (ci->values[0].value.number);
-
-       return (0);
-} /* }}} int cf_util_get_cdtime */
-
diff --git a/src/configfile.h b/src/configfile.h
deleted file mode 100644 (file)
index c91fcd5..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-#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.
- *
- * 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
- *
- * Authors:
- *   Florian octo Forster <octo at collectd.org>
- **/
-
-#include "collectd.h"
-#include "utils_time.h"
-#include "liboconfig/oconfig.h"
-
-/*
- * DESCRIPTION
- *  Remove a registered plugin from the internal data structures.
- * 
- * PARAMETERS
- *  `type'      Name of the plugin (must be the same as passed to
- *              `plugin_register'
- */
-void cf_unregister (const char *type);
-void cf_unregister_complex (const char *type);
-
-/*
- * DESCRIPTION
- *  `cf_register' is called by plugins that wish to receive config keys. The
- *  plugin will then receive all keys it registered for if they're found in a
- *  `<Plugin $type>' section.
- *
- * PARAMETERS
- *  `type'      Name of the plugin (must be the same as passed to
- *              `plugin_register'
- *  `callback'  Pointer to the callback function. The callback must return zero
- *              upon success, a value smaller than zero if it doesn't know how
- *              to handle the `key' passed to it (the first argument) or a
- *              value greater than zero if it knows how to handle the key but
- *              failed.
- *  `keys'      Array of key values this plugin wished to receive. The last
- *              element must be a NULL-pointer.
- *  `keys_num'  Number of elements in the array (not counting the last NULL-
- *              pointer.
- *
- * NOTES
- *  `cf_unregister' will be called for `type' to make sure only one record
- *  exists for each `type' at any time. This means that `cf_register' may be
- *  called multiple times, but only the last call will have an effect.
- */
-void cf_register (const char *type,
-               int (*callback) (const char *, const char *),
-               const char **keys, int keys_num);
-
-int cf_register_complex (const char *type, int (*callback) (oconfig_item_t *));
-
-/*
- * DESCRIPTION
- *  `cf_read' reads the config file `filename' and dispatches the read
- *  information to functions/variables. Most important: Is calls `plugin_load'
- *  to load specific plugins, depending on the current mode of operation.
- *
- * PARAMETERS
- *  `filename'  An additional filename to look for. This function calls
- *              `lc_process' which already searches many standard locations..
- *              If set to NULL will use the `CONFIGFILE' define.
- *
- * RETURN VALUE
- *  Returns zero upon success and non-zero otherwise. A error-message will have
- *  been printed in this case.
- */
-int cf_read (char *filename);
-
-int global_option_set (const char *option, const char *value);
-const char *global_option_get (const char *option);
-long global_option_get_long (const char *option, long default_value);
-long global_option_get_long_in_range (const char *option, long default_value, long min, long max);
-
-cdtime_t cf_get_default_interval (void);
-
-/* Assures the config option is a string, duplicates it and returns the copy in
- * "ret_string". If necessary "*ret_string" is freed first. Returns zero upon
- * success. */
-int cf_util_get_string (const oconfig_item_t *ci, char **ret_string);
-
-/* Assures the config option is a string and copies it to the provided buffer.
- * Assures null-termination. */
-int cf_util_get_string_buffer (const oconfig_item_t *ci, char *buffer,
-               size_t buffer_size);
-
-/* Assures the config option is a number and returns it as an int. */
-int cf_util_get_int (const oconfig_item_t *ci, int *ret_value);
-
-/* Assures the config option is a number and returns it as a double. */
-int cf_util_get_double (const oconfig_item_t *ci, double *ret_value);
-
-/* Assures the config option is a boolean and assignes it to `ret_bool'.
- * Otherwise, `ret_bool' is not changed and non-zero is returned. */
-int cf_util_get_boolean (const oconfig_item_t *ci, _Bool *ret_bool);
-
-/* Assures the config option is a boolean and set or unset the given flag in
- * `ret_value' as appropriate. Returns non-zero on error. */
-int cf_util_get_flag (const oconfig_item_t *ci,
-               unsigned int *ret_value, unsigned int flag);
-
-/* Assures that the config option is a string or a number if the correct range
- * of 1-65535. The string is then converted to a port number using
- * `service_name_to_port_number' and returned.
- * Returns the port number in the range [1-65535] or less than zero upon
- * failure. */
-int cf_util_get_port_number (const oconfig_item_t *ci);
-
-/* Assures that the config option is either a service name (a string) or a port
- * number (an integer in the appropriate range) and returns a newly allocated
- * string. If ret_string points to a non-NULL pointer, it is freed before
- * assigning a new value. */
-int cf_util_get_service (const oconfig_item_t *ci, char **ret_string);
-
-int cf_util_get_cdtime (const oconfig_item_t *ci, cdtime_t *ret_value);
-
-#endif /* defined(CONFIGFILE_H) */
index 33236c45975c4d9c5c519e4defbfcd029c0b0821..49a33551d6ec4167adf9e74171092cb5cfd8a0f9 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 6753397c0ca121fdf62c08b37859c0ca71cb6492..2a2a4a9715d20e9b76055d559edcb1b2f9e55aa1 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -1,9 +1,10 @@
 /**
  * collectd - src/cpu.c
- * Copyright (C) 2005-2010  Florian octo Forster
+ * Copyright (C) 2005-2014  Florian octo Forster
  * Copyright (C) 2008       Oleg King
  * Copyright (C) 2009       Simon Kuhnle
  * Copyright (C) 2009       Manuel Sanmartin
+ * Copyright (C) 2013-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
  * 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
+ *   Pierre-Yves Ritschard <pyr at spootnik.org>
  **/
 
 #include "collectd.h"
 # define CAN_USE_SYSCTL 0
 #endif
 
+#define COLLECTD_CPU_STATE_USER 0
+#define COLLECTD_CPU_STATE_SYSTEM 1
+#define COLLECTD_CPU_STATE_WAIT 2
+#define COLLECTD_CPU_STATE_NICE 3
+#define COLLECTD_CPU_STATE_SWAP 4
+#define COLLECTD_CPU_STATE_INTERRUPT 5
+#define COLLECTD_CPU_STATE_SOFTIRQ 6
+#define COLLECTD_CPU_STATE_STEAL 7
+#define COLLECTD_CPU_STATE_IDLE 8
+#define COLLECTD_CPU_STATE_ACTIVE 9 /* sum of (!idle) */
+#define COLLECTD_CPU_STATE_MAX 10 /* #states */
+
 #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;
@@ -139,6 +166,54 @@ static int numcpu;
 static int pnumcpu;
 #endif /* HAVE_PERFSTAT */
 
+#define RATE_ADD(sum, val) do { \
+       if (isnan (sum))        \
+       (sum) = (val);          \
+       else if (!isnan (val))  \
+       (sum) += (val);         \
+} while (0)
+
+struct cpu_state_s
+{
+       value_to_rate_state_t conv;
+       gauge_t rate;
+       _Bool has_value;
+};
+typedef struct cpu_state_s cpu_state_t;
+
+static cpu_state_t *cpu_states = NULL;
+static size_t cpu_states_num = 0; /* #cpu_states allocated */
+
+/* Highest CPU number in the current iteration. Used by the dispatch logic to
+ * determine how many CPUs there were. Reset to 0 by cpu_reset(). */
+static size_t global_cpu_num = 0;
+
+static _Bool report_by_cpu = 1;
+static _Bool report_by_state = 1;
+static _Bool report_percent = 0;
+
+static const char *config_keys[] =
+{
+       "ReportByCpu",
+       "ReportByState",
+       "ValuesPercentage"
+};
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+
+static int cpu_config (char const *key, char const *value) /* {{{ */
+{
+       if (strcasecmp (key, "ReportByCpu") == 0)
+               report_by_cpu = IS_TRUE (value) ? 1 : 0;
+       else if (strcasecmp (key, "ValuesPercentage") == 0)
+               report_percent = IS_TRUE (value) ? 1 : 0;
+       else if (strcasecmp (key, "ReportByState") == 0)
+               report_by_state = IS_TRUE (value) ? 1 : 0;
+       else
+               return (-1);
+
+       return (0);
+} /* }}} int cpu_config */
+
 static int init (void)
 {
 #if PROCESSOR_CPU_LOAD_INFO
@@ -233,32 +308,261 @@ 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;
+
+       /* This function is called for all known CPU states, but each read
+        * method will only report a subset. The remaining states are left as
+        * NAN and we ignore them here. */
+       if (isnan (percent))
+               return;
+
+       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);
+}
+
+/* Takes the zero-index number of a CPU and makes sure that the module-global
+ * cpu_states buffer is large enough. Returne ENOMEM on erorr. */
+static int cpu_states_alloc (size_t cpu_num) /* {{{ */
+{
+       cpu_state_t *tmp;
+       size_t sz;
+
+       sz = (((size_t) cpu_num) + 1) * COLLECTD_CPU_STATE_MAX;
+       assert (sz > 0);
+
+       /* We already have enough space. */
+       if (cpu_states_num >= sz)
+               return 0;
+
+       tmp = realloc (cpu_states, sz * sizeof (*cpu_states));
+       if (tmp == NULL)
+       {
+               ERROR ("cpu plugin: realloc failed.");
+               return (ENOMEM);
+       }
+       cpu_states = tmp;
+       tmp = cpu_states + cpu_states_num;
+
+       memset (tmp, 0, (sz - cpu_states_num) * sizeof (*cpu_states));
+       cpu_states_num = sz;
+       return 0;
+} /* }}} cpu_states_alloc */
+
+static cpu_state_t *get_cpu_state (size_t cpu_num, size_t state) /* {{{ */
+{
+       size_t index = ((cpu_num * COLLECTD_CPU_STATE_MAX) + state);
+
+       if (index >= cpu_states_num)
+               return (NULL);
+
+       return (&cpu_states[index]);
+} /* }}} cpu_state_t *get_cpu_state */
+
+/* Populates the per-CPU COLLECTD_CPU_STATE_ACTIVE rate and the global rate_by_state
+ * array. */
+static void aggregate (gauge_t *sum_by_state) /* {{{ */
+{
+       size_t cpu_num;
+       size_t state;
+
+       for (state = 0; state < COLLECTD_CPU_STATE_MAX; state++)
+               sum_by_state[state] = NAN;
+
+       for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
+       {
+               cpu_state_t *this_cpu_states = get_cpu_state (cpu_num, 0);
+
+               this_cpu_states[COLLECTD_CPU_STATE_ACTIVE].rate = NAN;
+
+               for (state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++)
+               {
+                       if (!this_cpu_states[state].has_value)
+                               continue;
+
+                       RATE_ADD (sum_by_state[state], this_cpu_states[state].rate);
+                       if (state != COLLECTD_CPU_STATE_IDLE)
+                               RATE_ADD (this_cpu_states[COLLECTD_CPU_STATE_ACTIVE].rate, this_cpu_states[state].rate);
+               }
+
+               if (!isnan (this_cpu_states[COLLECTD_CPU_STATE_ACTIVE].rate))
+                       this_cpu_states[COLLECTD_CPU_STATE_ACTIVE].has_value = 1;
+
+               RATE_ADD (sum_by_state[COLLECTD_CPU_STATE_ACTIVE], this_cpu_states[COLLECTD_CPU_STATE_ACTIVE].rate);
+       }
+} /* }}} void aggregate */
+
+/* Commits (dispatches) the values for one CPU or the global aggregation.
+ * cpu_num is the index of the CPU to be committed or -1 in case of the global
+ * aggregation. rates is a pointer to COLLECTD_CPU_STATE_MAX gauge_t values holding the
+ * current rate; each rate may be NAN. Calculates the percentage of each state
+ * and dispatches the metric. */
+static void cpu_commit_one (int cpu_num, /* {{{ */
+               gauge_t rates[static COLLECTD_CPU_STATE_MAX])
+{
+       size_t state;
+       gauge_t sum;
+
+       sum = rates[COLLECTD_CPU_STATE_ACTIVE];
+       RATE_ADD (sum, rates[COLLECTD_CPU_STATE_IDLE]);
+
+       if (!report_by_state)
+       {
+               gauge_t percent = 100.0 * rates[COLLECTD_CPU_STATE_ACTIVE] / sum;
+               submit_percent (cpu_num, COLLECTD_CPU_STATE_ACTIVE, percent);
+               return;
+       }
+
+       for (state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++)
+       {
+               gauge_t percent = 100.0 * rates[state] / sum;
+               submit_percent (cpu_num, state, percent);
+       }
+} /* }}} void cpu_commit_one */
+
+/* Resets the internal aggregation. This is called by the read callback after
+ * each iteration / after each call to cpu_commit(). */
+static void cpu_reset (void) /* {{{ */
+{
+       size_t i;
+
+       for (i = 0; i < cpu_states_num; i++)
+               cpu_states[i].has_value = 0;
+
+       global_cpu_num = 0;
+} /* }}} void cpu_reset */
+
+/* Legacy behavior: Dispatches the raw derive values without any aggregation. */
+static void cpu_commit_without_aggregation (void) /* {{{ */
+{
+       int state;
+
+       for (state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++)
+       {
+               size_t cpu_num;
+
+               for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
+               {
+                       cpu_state_t *s = get_cpu_state (cpu_num, state);
+
+                       if (!s->has_value)
+                               continue;
+
+                       submit_derive ((int) cpu_num, (int) state, s->conv.last_value.derive);
+               }
+       }
+} /* }}} void cpu_commit_without_aggregation */
+
+/* Aggregates the internal state and dispatches the metrics. */
+static void cpu_commit (void) /* {{{ */
+{
+       gauge_t global_rates[COLLECTD_CPU_STATE_MAX] = {
+               NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN /* Batman! */
+       };
+       size_t cpu_num;
+
+       if (report_by_state && report_by_cpu && !report_percent)
+       {
+               cpu_commit_without_aggregation ();
+               return;
+       }
+
+       aggregate (global_rates);
+
+       if (!report_by_cpu)
+       {
+               cpu_commit_one (-1, global_rates);
+               return;
+       }
+
+       for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
+       {
+               cpu_state_t *this_cpu_states = get_cpu_state (cpu_num, 0);
+               gauge_t local_rates[COLLECTD_CPU_STATE_MAX] = {
+                       NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN
+               };
+               size_t state;
+
+               for (state = 0; state < COLLECTD_CPU_STATE_MAX; state++)
+                       if (this_cpu_states[state].has_value)
+                               local_rates[state] = this_cpu_states[state].rate;
+
+               cpu_commit_one ((int) cpu_num, local_rates);
+       }
+} /* }}} void cpu_commit */
+
+/* Adds a derive value to the internal state. This should be used by each read
+ * function for each state. At the end of the iteration, the read function
+ * should call cpu_commit(). */
+static int cpu_stage (size_t cpu_num, size_t state, derive_t value, cdtime_t now) /* {{{ */
+{
+       int status;
+       cpu_state_t *s;
+       value_t v;
+
+       if (state >= COLLECTD_CPU_STATE_ACTIVE)
+               return (EINVAL);
+
+       status = cpu_states_alloc (cpu_num);
+       if (status != 0)
+               return (status);
+
+       if (global_cpu_num <= cpu_num)
+               global_cpu_num = cpu_num + 1;
+
+       s = get_cpu_state (cpu_num, state);
+
+       v.gauge = NAN;
+       status = value_to_rate (&v, value, &s->conv, DS_TYPE_DERIVE, now);
+       if (status != 0)
+               return (status);
+
+       s->rate = v.gauge;
+       s->has_value = 1;
+       return (0);
+} /* }}} int cpu_stage */
+
 static int cpu_read (void)
 {
-#if PROCESSOR_CPU_LOAD_INFO
+       cdtime_t now = cdtime ();
+
+#if PROCESSOR_CPU_LOAD_INFO /* {{{ */
        int cpu;
 
        kern_return_t status;
-       
+
        processor_cpu_load_info_data_t cpu_info;
        mach_msg_type_number_t         cpu_info_len;
 
@@ -284,17 +588,15 @@ 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]);
+               cpu_stage (cpu, COLLECTD_CPU_STATE_USER,   (derive_t) cpu_info.cpu_ticks[CPU_STATE_USER],   now);
+               cpu_stage (cpu, COLLECTD_CPU_STATE_NICE,   (derive_t) cpu_info.cpu_ticks[CPU_STATE_NICE],   now);
+               cpu_stage (cpu, COLLECTD_CPU_STATE_SYSTEM, (derive_t) cpu_info.cpu_ticks[CPU_STATE_SYSTEM], now);
+               cpu_stage (cpu, COLLECTD_CPU_STATE_IDLE,   (derive_t) cpu_info.cpu_ticks[CPU_STATE_IDLE],   now);
        }
-/* #endif PROCESSOR_CPU_LOAD_INFO */
+/* }}} #endif PROCESSOR_CPU_LOAD_INFO */
 
-#elif defined(KERNEL_LINUX)
+#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];
 
@@ -321,37 +623,27 @@ 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);
+               cpu_stage (cpu, COLLECTD_CPU_STATE_USER,   (derive_t) atoll(fields[1]), now);
+               cpu_stage (cpu, COLLECTD_CPU_STATE_NICE,   (derive_t) atoll(fields[2]), now);
+               cpu_stage (cpu, COLLECTD_CPU_STATE_SYSTEM, (derive_t) atoll(fields[3]), now);
+               cpu_stage (cpu, COLLECTD_CPU_STATE_IDLE,   (derive_t) atoll(fields[4]), now);
 
                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);
+                       cpu_stage (cpu, COLLECTD_CPU_STATE_WAIT,      (derive_t) atoll(fields[5]), now);
+                       cpu_stage (cpu, COLLECTD_CPU_STATE_INTERRUPT, (derive_t) atoll(fields[6]), now);
+                       cpu_stage (cpu, COLLECTD_CPU_STATE_SOFTIRQ,   (derive_t) atoll(fields[7]), now);
 
                        if (numfields >= 9)
-                               submit (cpu, "steal", atoll (fields[8]));
+                               cpu_stage (cpu, COLLECTD_CPU_STATE_STEAL, (derive_t) atoll(fields[8]), now);
                }
        }
-
        fclose (fh);
-/* #endif defined(KERNEL_LINUX) */
+/* }}} #endif defined(KERNEL_LINUX) */
 
-#elif defined(HAVE_LIBKSTAT)
+#elif defined(HAVE_LIBKSTAT) /* {{{ */
        int cpu;
-       derive_t user, syst, idle, wait;
        static cpu_stat_t cs;
 
        if (kc == NULL)
@@ -362,19 +654,14 @@ static int cpu_read (void)
                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);
+               cpu_stage (ksp[cpu]->ks_instance, COLLECTD_CPU_STATE_IDLE,   (derive_t) cs.cpu_sysinfo.cpu[CPU_IDLE],   now);
+               cpu_stage (ksp[cpu]->ks_instance, COLLECTD_CPU_STATE_USER,   (derive_t) cs.cpu_sysinfo.cpu[CPU_USER],   now);
+               cpu_stage (ksp[cpu]->ks_instance, COLLECTD_CPU_STATE_SYSTEM, (derive_t) cs.cpu_sysinfo.cpu[CPU_KERNEL], now);
+               cpu_stage (ksp[cpu]->ks_instance, COLLECTD_CPU_STATE_WAIT,   (derive_t) cs.cpu_sysinfo.cpu[CPU_WAIT],   now);
        }
-/* #endif defined(HAVE_LIBKSTAT) */
+/* }}} #endif defined(HAVE_LIBKSTAT) */
 
-#elif CAN_USE_SYSCTL
+#elif CAN_USE_SYSCTL /* {{{ */
        uint64_t cpuinfo[numcpu][CPUSTATES];
        size_t cpuinfo_size;
        int status;
@@ -430,14 +717,15 @@ 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]);
+               cpu_stage (i, COLLECTD_CPU_STATE_USER,      (derive_t) cpuinfo[i][CP_USER], now);
+               cpu_stage (i, COLLECTD_CPU_STATE_NICE,      (derive_t) cpuinfo[i][CP_NICE], now);
+               cpu_stage (i, COLLECTD_CPU_STATE_SYSTEM,    (derive_t) cpuinfo[i][CP_SYS], now);
+               cpu_stage (i, COLLECTD_CPU_STATE_IDLE,      (derive_t) cpuinfo[i][CP_IDLE], now);
+               cpu_stage (i, COLLECTD_CPU_STATE_INTERRUPT, (derive_t) cpuinfo[i][CP_INTR], now);
        }
-/* #endif CAN_USE_SYSCTL */
-#elif defined(HAVE_SYSCTLBYNAME) && defined(HAVE_SYSCTL_KERN_CP_TIMES)
+/* }}} #endif CAN_USE_SYSCTL */
+
+#elif defined(HAVE_SYSCTLBYNAME) && defined(HAVE_SYSCTL_KERN_CP_TIMES) /* {{{ */
        long cpuinfo[maxcpu][CPUSTATES];
        size_t cpuinfo_size;
        int i;
@@ -454,14 +742,15 @@ 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]);
+               cpu_stage (i, COLLECTD_CPU_STATE_USER,      (derive_t) cpuinfo[i][CP_USER], now);
+               cpu_stage (i, COLLECTD_CPU_STATE_NICE,      (derive_t) cpuinfo[i][CP_NICE], now);
+               cpu_stage (i, COLLECTD_CPU_STATE_SYSTEM,    (derive_t) cpuinfo[i][CP_SYS], now);
+               cpu_stage (i, COLLECTD_CPU_STATE_IDLE,      (derive_t) cpuinfo[i][CP_IDLE], now);
+               cpu_stage (i, COLLECTD_CPU_STATE_INTERRUPT, (derive_t) cpuinfo[i][CP_INTR], now);
        }
-/* #endif HAVE_SYSCTL_KERN_CP_TIMES */
-#elif defined(HAVE_SYSCTLBYNAME)
+/* }}} #endif HAVE_SYSCTL_KERN_CP_TIMES */
+
+#elif defined(HAVE_SYSCTLBYNAME) /* {{{ */
        long cpuinfo[CPUSTATES];
        size_t cpuinfo_size;
 
@@ -475,14 +764,14 @@ 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]);
-/* #endif HAVE_SYSCTLBYNAME */
+       cpu_stage (0, COLLECTD_CPU_STATE_USER,      (derive_t) cpuinfo[CP_USER], now);
+       cpu_stage (0, COLLECTD_CPU_STATE_NICE,      (derive_t) cpuinfo[CP_NICE], now);
+       cpu_stage (0, COLLECTD_CPU_STATE_SYSTEM,    (derive_t) cpuinfo[CP_SYS], now);
+       cpu_stage (0, COLLECTD_CPU_STATE_IDLE,      (derive_t) cpuinfo[CP_IDLE], now);
+       cpu_stage (0, COLLECTD_CPU_STATE_INTERRUPT, (derive_t) cpuinfo[CP_INTR], now);
+/* }}} #endif HAVE_SYSCTLBYNAME */
 
-#elif defined(HAVE_LIBSTATGRAB)
+#elif defined(HAVE_LIBSTATGRAB) /* {{{ */
        sg_cpu_stats *cs;
        cs = sg_get_cpu_stats ();
 
@@ -492,15 +781,15 @@ 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);
-/* #endif HAVE_LIBSTATGRAB */
+       cpu_state (0, COLLECTD_CPU_STATE_IDLE,   (derive_t) cs->idle);
+       cpu_state (0, COLLECTD_CPU_STATE_NICE,   (derive_t) cs->nice);
+       cpu_state (0, COLLECTD_CPU_STATE_SWAP,   (derive_t) cs->swap);
+       cpu_state (0, COLLECTD_CPU_STATE_SYSTEM, (derive_t) cs->kernel);
+       cpu_state (0, COLLECTD_CPU_STATE_USER,   (derive_t) cs->user);
+       cpu_state (0, COLLECTD_CPU_STATE_WAIT,   (derive_t) cs->iowait);
+/* }}} #endif HAVE_LIBSTATGRAB */
 
-#elif defined(HAVE_PERFSTAT)
+#elif defined(HAVE_PERFSTAT) /* {{{ */
        perfstat_id_t id;
        int i, cpus;
 
@@ -512,10 +801,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));
        }
@@ -530,20 +819,25 @@ 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);
+               cpu_stage (i, COLLECTD_CPU_STATE_IDLE,   (derive_t) perfcpu[i].idle, now);
+               cpu_stage (i, COLLECTD_CPU_STATE_SYSTEM, (derive_t) perfcpu[i].sys,  now);
+               cpu_stage (i, COLLECTD_CPU_STATE_USER,   (derive_t) perfcpu[i].user, now);
+               cpu_stage (i, COLLECTD_CPU_STATE_WAIT,   (derive_t) perfcpu[i].wait, now);
        }
-#endif /* HAVE_PERFSTAT */
+#endif /* }}} HAVE_PERFSTAT */
 
+       cpu_commit ();
+       cpu_reset ();
        return (0);
 }
 
 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 */
+
+/* vim: set sw=8 sts=8 noet fdm=marker : */
index 4b8aa72143167864ff575147c5ef19949997ab50..81e580d485c9bd58c625df40b369edd75dd94e75 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 958e34baf0d96d825e8ce9dfa79a21849db6e3d2..b6e535ee6b4c9b44eae4cde70052e877c1c5e2ee 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>
  **/
 
@@ -25,7 +25,6 @@
 #include "plugin.h"
 #include "common.h"
 #include "utils_cache.h"
-#include "utils_parse_option.h"
 
 /*
  * Private variables
index 9d2196ac2c3e57d30858eebcbf83bdb39f4d6970..ac4cc512c63fd51dcdd9190814aca5e0eaf1cc7d 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;
@@ -65,6 +66,7 @@ struct web_page_s /* {{{ */
   char *post_body;
   _Bool response_time;
   _Bool response_code;
+  int timeout;
 
   CURL *curl;
   char curl_errbuf[CURL_ERROR_SIZE];
@@ -367,8 +369,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);
@@ -376,6 +377,11 @@ static int cc_page_init_curl (web_page_t *wp) /* {{{ */
 
   if (wp->user != NULL)
   {
+#ifdef HAVE_CURLOPT_USERNAME
+    curl_easy_setopt (wp->curl, CURLOPT_USERNAME, wp->user);
+    curl_easy_setopt (wp->curl, CURLOPT_PASSWORD,
+        (wp->pass == NULL) ? "" : wp->pass);
+#else
     size_t credentials_size;
 
     credentials_size = strlen (wp->user) + 2;
@@ -392,6 +398,10 @@ 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);
+#endif
+
+    if (wp->digest)
+      curl_easy_setopt (wp->curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
   }
 
   curl_easy_setopt (wp->curl, CURLOPT_SSL_VERIFYPEER, (long) wp->verify_peer);
@@ -404,6 +414,14 @@ static int cc_page_init_curl (web_page_t *wp) /* {{{ */
   if (wp->post_body != NULL)
     curl_easy_setopt (wp->curl, CURLOPT_POSTFIELDS, wp->post_body);
 
+#ifdef HAVE_CURLOPT_TIMEOUT_MS
+  if (wp->timeout >= 0)
+    curl_easy_setopt (wp->curl, CURLOPT_TIMEOUT_MS, (long) wp->timeout);
+  else
+    curl_easy_setopt (wp->curl, CURLOPT_TIMEOUT_MS,
+       CDTIME_T_TO_MS(plugin_get_interval()));
+#endif
+
   return (0);
 } /* }}} int cc_page_init_curl */
 
@@ -429,10 +447,12 @@ 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;
   page->response_code = 0;
+  page->timeout = -1;
 
   page->instance = strdup (ci->values[0].value.string);
   if (page->instance == NULL)
@@ -454,6 +474,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)
@@ -471,6 +493,8 @@ static int cc_config_add_page (oconfig_item_t *ci) /* {{{ */
       status = cc_config_append_string ("Header", &page->headers, child);
     else if (strcasecmp ("Post", child->key) == 0)
       status = cf_util_get_string (child, &page->post_body);
+    else if (strcasecmp ("Timeout", child->key) == 0)
+      status = cf_util_get_int (child, &page->timeout);
     else
     {
       WARNING ("curl plugin: Option `%s' not allowed here.", child->key);
index 6fdae51d2bf74b29ed4028ee2e77e5c66ca33954..3ba55603d329342e6a30fa86b6908531e3e36e73 100644 (file)
@@ -71,11 +71,14 @@ 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;
+  int timeout;
 
   CURL *curl;
   char curl_errbuf[CURL_ERROR_SIZE];
@@ -229,7 +232,7 @@ static int cj_cb_number (void *ctx,
   buffer[sizeof (buffer) - 1] = 0;
 
   if ((key == NULL) || !CJ_IS_KEY (key)) {
-    if (key != NULL)
+    if (key != NULL && !db->state[db->depth].in_array/*can be inhomogeneous*/)
       NOTICE ("curl_json plugin: Found \"%s\", but the configuration expects"
               " a map.", buffer);
     cj_cb_inc_array_index (ctx, /* update_key = */ 1);
@@ -603,13 +606,19 @@ 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);
+  curl_easy_setopt (db->curl, CURLOPT_FOLLOWLOCATION, 1L);
+  curl_easy_setopt (db->curl, CURLOPT_MAXREDIRS, 50L);
 
   if (db->user != NULL)
   {
+#ifdef HAVE_CURLOPT_USERNAME
+    curl_easy_setopt (db->curl, CURLOPT_USERNAME, db->user);
+    curl_easy_setopt (db->curl, CURLOPT_PASSWORD,
+        (db->pass == NULL) ? "" : db->pass);
+#else
     size_t credentials_size;
 
     credentials_size = strlen (db->user) + 2;
@@ -626,6 +635,10 @@ 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);
+#endif
+
+    if (db->digest)
+      curl_easy_setopt (db->curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
   }
 
   curl_easy_setopt (db->curl, CURLOPT_SSL_VERIFYPEER, (long) db->verify_peer);
@@ -638,6 +651,17 @@ static int cj_init_curl (cj_t *db) /* {{{ */
   if (db->post_body != NULL)
     curl_easy_setopt (db->curl, CURLOPT_POSTFIELDS, db->post_body);
 
+#ifdef HAVE_CURLOPT_TIMEOUT_MS
+  if (db->timeout >= 0)
+    curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, (long) db->timeout);
+  else if (db->interval > 0)
+    curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS,
+        CDTIME_T_TO_MS(db->timeout));
+  else
+    curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS,
+        CDTIME_T_TO_MS(plugin_get_interval()));
+#endif
+
   return (0);
 } /* }}} int cj_init_curl */
 
@@ -663,6 +687,8 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */
   }
   memset (db, 0, sizeof (*db));
 
+  db->timeout = -1;
+
   if (strcasecmp ("URL", ci->key) == 0)
     status = cf_util_get_string (ci, &db->url);
   else if (strcasecmp ("Sock", ci->key) == 0)
@@ -693,6 +719,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)
@@ -705,6 +733,10 @@ 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 if (strcasecmp ("Timeout", child->key) == 0)
+      status = cf_util_get_int (child, &db->timeout);
     else
     {
       WARNING ("curl_json plugin: Option `%s' not allowed here.", child->key);
@@ -732,6 +764,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");
@@ -746,8 +781,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
@@ -818,11 +854,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));
@@ -832,6 +867,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 3b1539649100bb6341a7f5aba79d6f3b45c5a119..37a36866c91982345f56b0371fac92ed42a78449 100644 (file)
@@ -76,10 +76,12 @@ struct cx_s /* {{{ */
   char *user;
   char *pass;
   char *credentials;
+  _Bool digest;
   _Bool verify_peer;
   _Bool verify_host;
   char *cacert;
   char *post_body;
+  int timeout;
   struct curl_slist *headers;
 
   cx_namespace_t *namespaces;
@@ -846,13 +848,19 @@ 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);
+  curl_easy_setopt (db->curl, CURLOPT_FOLLOWLOCATION, 1L);
+  curl_easy_setopt (db->curl, CURLOPT_MAXREDIRS, 50L);
 
   if (db->user != NULL)
   {
+#ifdef HAVE_CURLOPT_USERNAME
+    curl_easy_setopt (db->curl, CURLOPT_USERNAME, db->user);
+    curl_easy_setopt (db->curl, CURLOPT_PASSWORD,
+        (db->pass == NULL) ? "" : db->pass);
+#else
     size_t credentials_size;
 
     credentials_size = strlen (db->user) + 2;
@@ -869,6 +877,10 @@ 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);
+#endif
+
+    if (db->digest)
+      curl_easy_setopt (db->curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
   }
 
   curl_easy_setopt (db->curl, CURLOPT_SSL_VERIFYPEER, db->verify_peer ? 1L : 0L);
@@ -881,6 +893,14 @@ static int cx_init_curl (cx_t *db) /* {{{ */
   if (db->post_body != NULL)
     curl_easy_setopt (db->curl, CURLOPT_POSTFIELDS, db->post_body);
 
+#ifdef HAVE_CURLOPT_TIMEOUT_MS
+  if (db->timeout >= 0)
+    curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, (long) db->timeout);
+  else
+    curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS,
+       CDTIME_T_TO_MS(plugin_get_interval()));
+#endif
+
   return (0);
 } /* }}} int cx_init_curl */
 
@@ -906,6 +926,8 @@ static int cx_config_add_url (oconfig_item_t *ci) /* {{{ */
   }
   memset (db, 0, sizeof (*db));
 
+  db->timeout = -1;
+
   if (strcasecmp ("URL", ci->key) == 0)
   {
     status = cf_util_get_string (ci, &db->url);
@@ -936,6 +958,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)
@@ -950,6 +974,8 @@ static int cx_config_add_url (oconfig_item_t *ci) /* {{{ */
       status = cf_util_get_string (child, &db->post_body);
     else if (strcasecmp ("Namespace", child->key) == 0)
       status = cx_config_add_namespace (db, child);
+    else if (strcasecmp ("Timeout", child->key) == 0)
+      status = cf_util_get_int (child, &db->timeout);
     else
     {
       WARNING ("curl_xml plugin: Option `%s' not allowed here.", child->key);
diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am
new file mode 100644 (file)
index 0000000..99dc158
--- /dev/null
@@ -0,0 +1,102 @@
+if COMPILER_IS_GCC
+AM_CFLAGS = -Wall -Werror
+endif
+
+AM_CPPFLAGS = -I$(top_srcdir)/src
+AM_CPPFLAGS += -DPREFIX='"${prefix}"'
+AM_CPPFLAGS += -DCONFIGFILE='"${sysconfdir}/${PACKAGE_NAME}.conf"'
+AM_CPPFLAGS += -DLOCALSTATEDIR='"${localstatedir}"'
+AM_CPPFLAGS += -DPKGLOCALSTATEDIR='"${localstatedir}/lib/${PACKAGE_NAME}"'
+if BUILD_FEATURE_DAEMON
+AM_CPPFLAGS += -DPIDFILE='"${localstatedir}/run/${PACKAGE_NAME}.pid"'
+endif
+AM_CPPFLAGS += -DPLUGINDIR='"${pkglibdir}"'
+AM_CPPFLAGS += -DPKGDATADIR='"${pkgdatadir}"'
+
+# Link to these libraries..
+COMMON_LIBS =
+if BUILD_WITH_LIBRT
+COMMON_LIBS += -lrt
+endif
+if BUILD_WITH_LIBPOSIX4
+COMMON_LIBS += -lposix4
+endif
+if BUILD_WITH_LIBSOCKET
+COMMON_LIBS += -lsocket
+endif
+if BUILD_WITH_LIBRESOLV
+COMMON_LIBS += -lresolv
+endif
+if BUILD_WITH_LIBPTHREAD
+COMMON_LIBS += -lpthread
+endif
+if BUILD_WITH_LIBKSTAT
+COMMON_LIBS += -lkstat
+endif
+if BUILD_WITH_LIBDEVINFO
+COMMON_LIBS += -ldevinfo
+endif
+
+AUTOMAKE_OPTIONS = subdir-objects
+
+sbin_PROGRAMS = collectd
+
+noinst_LTLIBRARIES = libavltree.la libcommon.la libheap.la libplugin_mock.la
+
+libavltree_la_SOURCES = utils_avltree.c utils_avltree.h
+
+libcommon_la_SOURCES = common.c common.h
+
+libheap_la_SOURCES = utils_heap.c utils_heap.h
+
+libplugin_mock_la_SOURCES = plugin_mock.c utils_cache_mock.c utils_time_mock.c
+
+collectd_SOURCES = collectd.c collectd.h \
+                  configfile.c configfile.h \
+                  filter_chain.c filter_chain.h \
+                  meta_data.c meta_data.h \
+                  plugin.c plugin.h \
+                  utils_cache.c utils_cache.h \
+                  utils_complain.c utils_complain.h \
+                  utils_llist.c utils_llist.h \
+                  utils_random.c utils_random.h \
+                  utils_tail_match.c utils_tail_match.h \
+                  utils_match.c utils_match.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 \
+                  utils_threshold.c utils_threshold.h
+
+
+collectd_CPPFLAGS =  $(AM_CPPFLAGS) $(LTDLINCL)
+collectd_CFLAGS = $(AM_CFLAGS)
+collectd_LDFLAGS = -export-dynamic
+collectd_LDADD = libavltree.la libcommon.la libheap.la -lm $(COMMON_LIBS)
+collectd_DEPENDENCIES = libavltree.la libcommon.la libheap.la
+
+# The daemon needs to call sg_init, so we need to link it against libstatgrab,
+# too. -octo
+if BUILD_WITH_LIBSTATGRAB
+collectd_CFLAGS += $(BUILD_WITH_LIBSTATGRAB_CFLAGS)
+collectd_LDADD += $(BUILD_WITH_LIBSTATGRAB_LDFLAGS)
+endif
+
+if BUILD_WITH_OWN_LIBOCONFIG
+collectd_LDADD += $(LIBLTDL) $(top_builddir)/src/liboconfig/liboconfig.la
+collectd_DEPENDENCIES += $(top_builddir)/src/liboconfig/liboconfig.la
+else
+collectd_LDADD += -loconfig
+endif
+
+check_PROGRAMS = test_common test_utils_avltree test_utils_heap
+TESTS = test_common test_utils_avltree test_utils_heap
+
+test_common_SOURCES = common_test.c ../testing.h
+test_common_LDADD = libcommon.la libplugin_mock.la $(COMMON_LIBS)
+
+test_utils_avltree_SOURCES = utils_avltree_test.c ../testing.h
+test_utils_avltree_LDADD = libavltree.la $(COMMON_LIBS)
+
+test_utils_heap_SOURCES = utils_heap_test.c ../testing.h
+test_utils_heap_LDADD = libheap.la $(COMMON_LIBS)
diff --git a/src/daemon/collectd.c b/src/daemon/collectd.c
new file mode 100644 (file)
index 0000000..88c38ac
--- /dev/null
@@ -0,0 +1,721 @@
+/**
+ * collectd - src/collectd.c
+ * Copyright (C) 2005-2007  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>
+ *   Alvaro Barcellos <alvaro.barcellos at gmail.com>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+
+#include "plugin.h"
+#include "configfile.h"
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <netdb.h>
+
+#include <pthread.h>
+
+#if HAVE_LOCALE_H
+# include <locale.h>
+#endif
+
+#if HAVE_STATGRAB_H
+# include <statgrab.h>
+#endif
+
+#ifndef COLLECTD_LOCALE
+# define COLLECTD_LOCALE "C"
+#endif
+
+/*
+ * Global variables
+ */
+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;
+#endif /* HAVE_LIBKSTAT */
+
+static int loop = 0;
+
+static void *do_flush (void __attribute__((unused)) *arg)
+{
+       INFO ("Flushing all data.");
+       plugin_flush (/* plugin = */ NULL,
+                       /* timeout = */ 0,
+                       /* ident = */ NULL);
+       INFO ("Finished flushing all data.");
+       pthread_exit (NULL);
+       return NULL;
+}
+
+static void sig_int_handler (int __attribute__((unused)) signal)
+{
+       loop++;
+}
+
+static void sig_term_handler (int __attribute__((unused)) signal)
+{
+       loop++;
+}
+
+static void sig_usr1_handler (int __attribute__((unused)) signal)
+{
+       pthread_t      thread;
+       pthread_attr_t attr;
+
+       /* flushing the data might take a while,
+        * so it should be done asynchronously */
+       pthread_attr_init (&attr);
+       pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+       pthread_create (&thread, &attr, do_flush, NULL);
+       pthread_attr_destroy (&attr);
+}
+
+static int init_hostname (void)
+{
+       const char *str;
+
+       struct addrinfo  ai_hints;
+       struct addrinfo *ai_list;
+       struct addrinfo *ai_ptr;
+       int status;
+
+       str = global_option_get ("Hostname");
+       if (str != NULL)
+       {
+               sstrncpy (hostname_g, str, sizeof (hostname_g));
+               return (0);
+       }
+
+       if (gethostname (hostname_g, sizeof (hostname_g)) != 0)
+       {
+               fprintf (stderr, "`gethostname' failed and no "
+                               "hostname was configured.\n");
+               return (-1);
+       }
+
+       str = global_option_get ("FQDNLookup");
+       if (IS_FALSE (str))
+               return (0);
+
+       memset (&ai_hints, '\0', sizeof (ai_hints));
+       ai_hints.ai_flags = AI_CANONNAME;
+
+       status = getaddrinfo (hostname_g, NULL, &ai_hints, &ai_list);
+       if (status != 0)
+       {
+               ERROR ("Looking up \"%s\" failed. You have set the "
+                               "\"FQDNLookup\" option, but I cannot resolve "
+                               "my hostname to a fully qualified domain "
+                               "name. Please fix the network "
+                               "configuration.", hostname_g);
+               return (-1);
+       }
+
+       for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+       {
+               if (ai_ptr->ai_canonname == NULL)
+                       continue;
+
+               sstrncpy (hostname_g, ai_ptr->ai_canonname, sizeof (hostname_g));
+               break;
+       }
+
+       freeaddrinfo (ai_list);
+       return (0);
+} /* int init_hostname */
+
+static int init_global_variables (void)
+{
+       char const *str;
+
+       interval_g = cf_get_default_interval ();
+       assert (interval_g > 0);
+       DEBUG ("interval_g = %.3f;", CDTIME_T_TO_DOUBLE (interval_g));
+
+       str = global_option_get ("Timeout");
+       if (str == NULL)
+               str = "2";
+       timeout_g = atoi (str);
+       if (timeout_g <= 1)
+       {
+               fprintf (stderr, "Cannot set the timeout to a correct value.\n"
+                               "Please check your settings.\n");
+               return (-1);
+       }
+       DEBUG ("timeout_g = %i;", timeout_g);
+
+       if (init_hostname () != 0)
+               return (-1);
+       DEBUG ("hostname_g = %s;", hostname_g);
+
+       return (0);
+} /* int init_global_variables */
+
+static int change_basedir (const char *orig_dir)
+{
+       char *dir;
+       size_t dirlen;
+       int status;
+
+       dir = strdup (orig_dir);
+       if (dir == NULL)
+       {
+               char errbuf[1024];
+               ERROR ("strdup failed: %s",
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
+               return (-1);
+       }
+
+       dirlen = strlen (dir);
+       while ((dirlen > 0) && (dir[dirlen - 1] == '/'))
+               dir[--dirlen] = '\0';
+
+       if (dirlen <= 0) {
+               free (dir);
+               return (-1);
+       }
+
+       status = chdir (dir);
+       if (status == 0)
+       {
+               free (dir);
+               return (0);
+       }
+       else if (errno != ENOENT)
+       {
+               char errbuf[1024];
+               ERROR ("change_basedir: chdir (%s): %s", dir,
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
+               free (dir);
+               return (-1);
+       }
+
+       status = mkdir (dir, S_IRWXU | S_IRWXG | S_IRWXO);
+       if (status != 0)
+       {
+               char errbuf[1024];
+               ERROR ("change_basedir: mkdir (%s): %s", dir,
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
+               free (dir);
+               return (-1);
+       }
+
+       status = chdir (dir);
+       if (status != 0)
+       {
+               char errbuf[1024];
+               ERROR ("change_basedir: chdir (%s): %s", dir,
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
+               free (dir);
+               return (-1);
+       }
+
+       free (dir);
+       return (0);
+} /* static int change_basedir (char *dir) */
+
+#if HAVE_LIBKSTAT
+static void update_kstat (void)
+{
+       if (kc == NULL)
+       {
+               if ((kc = kstat_open ()) == NULL)
+                       ERROR ("Unable to open kstat control structure");
+       }
+       else
+       {
+               kid_t kid;
+               kid = kstat_chain_update (kc);
+               if (kid > 0)
+               {
+                       INFO ("kstat chain has been updated");
+                       plugin_init_all ();
+               }
+               else if (kid < 0)
+                       ERROR ("kstat chain update failed");
+               /* else: everything works as expected */
+       }
+
+       return;
+} /* static void update_kstat (void) */
+#endif /* HAVE_LIBKSTAT */
+
+/* TODO
+ * Remove all settings but `-f' and `-C'
+ */
+static void exit_usage (int status)
+{
+       printf ("Usage: "PACKAGE_NAME" [OPTIONS]\n\n"
+
+                       "Available options:\n"
+                       "  General:\n"
+                       "    -C <file>       Configuration file.\n"
+                       "                    Default: "CONFIGFILE"\n"
+                       "    -t              Test config and exit.\n"
+                       "    -T              Test plugin read and exit.\n"
+                       "    -P <file>       PID-file.\n"
+                       "                    Default: "PIDFILE"\n"
+#if COLLECT_DAEMON
+                       "    -f              Don't fork to the background.\n"
+#endif
+                       "    -h              Display help (this message)\n"
+                       "\nBuiltin defaults:\n"
+                       "  Config file       "CONFIGFILE"\n"
+                       "  PID file          "PIDFILE"\n"
+                       "  Plugin directory  "PLUGINDIR"\n"
+                       "  Data directory    "PKGLOCALSTATEDIR"\n"
+                       "\n"PACKAGE_NAME" "PACKAGE_VERSION", http://collectd.org/\n"
+                       "by Florian octo Forster <octo@collectd.org>\n"
+                       "for contributions see `AUTHORS'\n");
+       exit (status);
+} /* static void exit_usage (int status) */
+
+static int do_init (void)
+{
+#if HAVE_SETLOCALE
+       if (setlocale (LC_NUMERIC, COLLECTD_LOCALE) == NULL)
+               WARNING ("setlocale (\"%s\") failed.", COLLECTD_LOCALE);
+#endif
+
+#if HAVE_LIBKSTAT
+       kc = NULL;
+       update_kstat ();
+#endif
+
+#if HAVE_LIBSTATGRAB
+       if (sg_init (
+# if HAVE_LIBSTATGRAB_0_90
+                   0
+# endif
+                   ))
+       {
+               ERROR ("sg_init: %s", sg_str_error (sg_get_error ()));
+               return (-1);
+       }
+
+       if (sg_drop_privileges ())
+       {
+               ERROR ("sg_drop_privileges: %s", sg_str_error (sg_get_error ()));
+               return (-1);
+       }
+#endif
+
+       plugin_init_all ();
+
+       return (0);
+} /* int do_init () */
+
+
+static int do_loop (void)
+{
+       cdtime_t interval = cf_get_default_interval ();
+       cdtime_t wait_until;
+
+       wait_until = cdtime () + interval;
+
+       while (loop == 0)
+       {
+               struct timespec ts_wait = { 0, 0 };
+               cdtime_t now;
+
+#if HAVE_LIBKSTAT
+               update_kstat ();
+#endif
+
+               /* Issue all plugins */
+               plugin_read_all ();
+
+               now = cdtime ();
+               if (now >= wait_until)
+               {
+                       WARNING ("Not sleeping because the next interval is "
+                                       "%.3f seconds in the past!",
+                                       CDTIME_T_TO_DOUBLE (now - wait_until));
+                       wait_until = now + interval;
+                       continue;
+               }
+
+               CDTIME_T_TO_TIMESPEC (wait_until - now, &ts_wait);
+               wait_until = wait_until + interval;
+
+               while ((loop == 0) && (nanosleep (&ts_wait, &ts_wait) != 0))
+               {
+                       if (errno != EINTR)
+                       {
+                               char errbuf[1024];
+                               ERROR ("nanosleep failed: %s",
+                                               sstrerror (errno, errbuf,
+                                                       sizeof (errbuf)));
+                               return (-1);
+                       }
+               }
+       } /* while (loop == 0) */
+
+       return (0);
+} /* int do_loop */
+
+static int do_shutdown (void)
+{
+       plugin_shutdown_all ();
+       return (0);
+} /* int do_shutdown */
+
+#if COLLECT_DAEMON
+static int pidfile_create (void)
+{
+       FILE *fh;
+       const char *file = global_option_get ("PIDFile");
+
+       if ((fh = fopen (file, "w")) == NULL)
+       {
+               char errbuf[1024];
+               ERROR ("fopen (%s): %s", file,
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
+               return (1);
+       }
+
+       fprintf (fh, "%i\n", (int) getpid ());
+       fclose(fh);
+
+       return (0);
+} /* static int pidfile_create (const char *file) */
+
+static int pidfile_remove (void)
+{
+       const char *file = global_option_get ("PIDFile");
+       if (file == NULL)
+               return 0;
+
+       return (unlink (file));
+} /* static int pidfile_remove (const char *file) */
+#endif /* COLLECT_DAEMON */
+
+#ifdef KERNEL_LINUX
+int notify_upstart (void)
+{
+    const char  *upstart_job = getenv("UPSTART_JOB");
+
+    if (upstart_job == NULL)
+        return 0;
+
+    if (strcmp(upstart_job, "collectd") != 0)
+        return 0;
+
+    WARNING ("supervised by upstart, will stop to signal readyness");
+    raise(SIGSTOP);
+    unsetenv("UPSTART_JOB");
+
+    return 1;
+}
+
+int notify_systemd (void)
+{
+    int                  fd = -1;
+    const char          *notifysocket = getenv("NOTIFY_SOCKET");
+    struct sockaddr_un   su;
+    struct iovec         iov;
+    struct msghdr        hdr;
+
+    if (notifysocket == NULL)
+        return 0;
+
+    if ((strchr("@/", notifysocket[0])) == NULL ||
+        strlen(notifysocket) < 2)
+        return 0;
+
+    WARNING ("supervised by systemd, will signal readyness");
+    if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) {
+        WARNING ("cannot contact systemd socket %s", notifysocket);
+        return 0;
+    }
+
+    bzero(&su, sizeof(su));
+    su.sun_family = AF_UNIX;
+    sstrncpy (su.sun_path, notifysocket, sizeof(su.sun_path));
+
+    if (notifysocket[0] == '@')
+        su.sun_path[0] = 0;
+
+    bzero(&iov, sizeof(iov));
+    iov.iov_base = "READY=1";
+    iov.iov_len = strlen("READY=1");
+
+    bzero(&hdr, sizeof(hdr));
+    hdr.msg_name = &su;
+    hdr.msg_namelen = offsetof(struct sockaddr_un, sun_path) +
+        strlen(notifysocket);
+    hdr.msg_iov = &iov;
+    hdr.msg_iovlen = 1;
+
+    unsetenv("NOTIFY_SOCKET");
+    if (sendmsg(fd, &hdr, MSG_NOSIGNAL) < 0) {
+        WARNING ("cannot send notification to systemd");
+        close(fd);
+        return 0;
+    }
+    close(fd);
+    return 1;
+}
+#endif /* KERNEL_LINUX */
+
+int main (int argc, char **argv)
+{
+       struct sigaction sig_int_action;
+       struct sigaction sig_term_action;
+       struct sigaction sig_usr1_action;
+       struct sigaction sig_pipe_action;
+       char *configfile = CONFIGFILE;
+       int test_config  = 0;
+       int test_readall = 0;
+       const char *basedir;
+#if COLLECT_DAEMON
+       struct sigaction sig_chld_action;
+       pid_t pid;
+       int daemonize    = 1;
+#endif
+       int exit_status = 0;
+
+       /* read options */
+       while (1)
+       {
+               int c;
+
+               c = getopt (argc, argv, "htTC:"
+#if COLLECT_DAEMON
+                               "fP:"
+#endif
+               );
+
+               if (c == -1)
+                       break;
+
+               switch (c)
+               {
+                       case 'C':
+                               configfile = optarg;
+                               break;
+                       case 't':
+                               test_config = 1;
+                               break;
+                       case 'T':
+                               test_readall = 1;
+                               global_option_set ("ReadThreads", "-1");
+#if COLLECT_DAEMON
+                               daemonize = 0;
+#endif /* COLLECT_DAEMON */
+                               break;
+#if COLLECT_DAEMON
+                       case 'P':
+                               global_option_set ("PIDFile", optarg);
+                               pidfile_from_cli = 1;
+                               break;
+                       case 'f':
+                               daemonize = 0;
+                               break;
+#endif /* COLLECT_DAEMON */
+                       case 'h':
+                               exit_usage (0);
+                               break;
+                       default:
+                               exit_usage (1);
+               } /* switch (c) */
+       } /* while (1) */
+
+       if (optind < argc)
+               exit_usage (1);
+
+       plugin_init_ctx ();
+
+       /*
+        * Read options from the config file, the environment and the command
+        * line (in that order, with later options overwriting previous ones in
+        * general).
+        * Also, this will automatically load modules.
+        */
+       if (cf_read (configfile))
+       {
+               fprintf (stderr, "Error: Reading the config file failed!\n"
+                               "Read the syslog for details.\n");
+               return (1);
+       }
+
+       /*
+        * Change directory. We do this _after_ reading the config and loading
+        * modules to relative paths work as expected.
+        */
+       if ((basedir = global_option_get ("BaseDir")) == NULL)
+       {
+               fprintf (stderr, "Don't have a basedir to use. This should not happen. Ever.");
+               return (1);
+       }
+       else if (change_basedir (basedir))
+       {
+               fprintf (stderr, "Error: Unable to change to directory `%s'.\n", basedir);
+               return (1);
+       }
+
+       /*
+        * Set global variables or, if that failes, exit. We cannot run with
+        * them being uninitialized. If nothing is configured, then defaults
+        * are being used. So this means that the user has actually done
+        * something wrong.
+        */
+       if (init_global_variables () != 0)
+               return (1);
+
+       if (test_config)
+               return (0);
+
+#if COLLECT_DAEMON
+       /*
+        * fork off child
+        */
+       memset (&sig_chld_action, '\0', sizeof (sig_chld_action));
+       sig_chld_action.sa_handler = SIG_IGN;
+       sigaction (SIGCHLD, &sig_chld_action, NULL);
+
+    /*
+     * Only daemonize if we're not being supervised
+     * by upstart or systemd (when using Linux).
+     */
+       if (daemonize
+#ifdef KERNEL_LINUX
+           && notify_upstart() == 0 && notify_systemd() == 0
+#endif
+       )
+       {
+               if ((pid = fork ()) == -1)
+               {
+                       /* error */
+                       char errbuf[1024];
+                       fprintf (stderr, "fork: %s",
+                                       sstrerror (errno, errbuf,
+                                               sizeof (errbuf)));
+                       return (1);
+               }
+               else if (pid != 0)
+               {
+                       /* parent */
+                       /* printf ("Running (PID %i)\n", pid); */
+                       return (0);
+               }
+
+               /* Detach from session */
+               setsid ();
+
+               /* Write pidfile */
+               if (pidfile_create ())
+                       exit (2);
+
+               /* close standard descriptors */
+               close (2);
+               close (1);
+               close (0);
+
+               if (open ("/dev/null", O_RDWR) != 0)
+               {
+                       ERROR ("Error: Could not connect `STDIN' to `/dev/null'");
+                       return (1);
+               }
+               if (dup (0) != 1)
+               {
+                       ERROR ("Error: Could not connect `STDOUT' to `/dev/null'");
+                       return (1);
+               }
+               if (dup (0) != 2)
+               {
+                       ERROR ("Error: Could not connect `STDERR' to `/dev/null'");
+                       return (1);
+               }
+       } /* if (daemonize) */
+#endif /* COLLECT_DAEMON */
+
+       memset (&sig_pipe_action, '\0', sizeof (sig_pipe_action));
+       sig_pipe_action.sa_handler = SIG_IGN;
+       sigaction (SIGPIPE, &sig_pipe_action, NULL);
+
+       /*
+        * install signal handlers
+        */
+       memset (&sig_int_action, '\0', sizeof (sig_int_action));
+       sig_int_action.sa_handler = sig_int_handler;
+       if (0 != sigaction (SIGINT, &sig_int_action, NULL)) {
+               char errbuf[1024];
+               ERROR ("Error: Failed to install a signal handler for signal INT: %s",
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
+               return (1);
+       }
+
+       memset (&sig_term_action, '\0', sizeof (sig_term_action));
+       sig_term_action.sa_handler = sig_term_handler;
+       if (0 != sigaction (SIGTERM, &sig_term_action, NULL)) {
+               char errbuf[1024];
+               ERROR ("Error: Failed to install a signal handler for signal TERM: %s",
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
+               return (1);
+       }
+
+       memset (&sig_usr1_action, '\0', sizeof (sig_usr1_action));
+       sig_usr1_action.sa_handler = sig_usr1_handler;
+       if (0 != sigaction (SIGUSR1, &sig_usr1_action, NULL)) {
+               char errbuf[1024];
+               ERROR ("Error: Failed to install a signal handler for signal USR1: %s",
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
+               return (1);
+       }
+
+       /*
+        * run the actual loops
+        */
+       do_init ();
+
+       if (test_readall)
+       {
+               if (plugin_read_all_once () != 0)
+                       exit_status = 1;
+       }
+       else
+       {
+               INFO ("Initialization complete, entering read-loop.");
+               do_loop ();
+       }
+
+       /* close syslog */
+       INFO ("Exiting normally.");
+
+       do_shutdown ();
+
+#if COLLECT_DAEMON
+       if (daemonize)
+               pidfile_remove ();
+#endif /* COLLECT_DAEMON */
+
+       return (exit_status);
+} /* int main */
diff --git a/src/daemon/collectd.h b/src/daemon/collectd.h
new file mode 100644 (file)
index 0000000..80b753c
--- /dev/null
@@ -0,0 +1,319 @@
+/**
+ * collectd - src/collectd.h
+ * Copyright (C) 2005,2006  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>
+ **/
+
+#ifndef COLLECTD_H
+#define COLLECTD_H
+
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#if HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#if STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# if HAVE_STDLIB_H
+#  include <stdlib.h>
+# endif
+#endif
+#if HAVE_STRING_H
+# if !STDC_HEADERS && HAVE_MEMORY_H
+#  include <memory.h>
+# endif
+# include <string.h>
+#endif
+#if HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#if HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
+#if HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#if HAVE_SYS_WAIT_H
+# include <sys/wait.h>
+#endif
+#ifndef WEXITSTATUS
+# define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
+#endif
+#ifndef WIFEXITED
+# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
+#endif
+#if HAVE_SIGNAL_H
+# include <signal.h>
+#endif
+#if HAVE_FCNTL_H
+# include <fcntl.h>
+#endif
+#if HAVE_ERRNO_H
+# include <errno.h>
+#endif
+#if HAVE_LIMITS_H
+# include <limits.h>
+#endif
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
+#if HAVE_ASSERT_H
+# include <assert.h>
+#else
+# define assert(...) /* nop */
+#endif
+
+#if !defined(HAVE__BOOL) || !HAVE__BOOL
+typedef int _Bool;
+# undef HAVE__BOOL
+# define HAVE__BOOL 1
+#endif
+
+#if NAN_STATIC_DEFAULT
+# include <math.h>
+/* #endif NAN_STATIC_DEFAULT*/
+#elif NAN_STATIC_ISOC
+# ifndef __USE_ISOC99
+#  define DISABLE_ISOC99 1
+#  define __USE_ISOC99 1
+# endif /* !defined(__USE_ISOC99) */
+# include <math.h>
+# if DISABLE_ISOC99
+#  undef DISABLE_ISOC99
+#  undef __USE_ISOC99
+# endif /* DISABLE_ISOC99 */
+/* #endif NAN_STATIC_ISOC */
+#elif NAN_ZERO_ZERO
+# include <math.h>
+# ifdef NAN
+#  undef NAN
+# endif
+# define NAN (0.0 / 0.0)
+# ifndef isnan
+#  define isnan(f) ((f) != (f))
+# endif /* !defined(isnan) */
+# ifndef isfinite
+#  define isfinite(f) (((f) - (f)) == 0.0)
+# endif
+# ifndef isinf
+#  define isinf(f) (!isfinite(f) && !isnan(f))
+# endif
+#endif /* NAN_ZERO_ZERO */
+
+/* Try really, really hard to determine endianess. Under NexentaStor 1.0.2 this
+ * information is in <sys/isa_defs.h>, possibly some other Solaris versions do
+ * this too.. */
+#if HAVE_ENDIAN_H
+# include <endian.h>
+#elif HAVE_SYS_ISA_DEFS_H
+# include <sys/isa_defs.h>
+#endif
+
+#ifndef BYTE_ORDER
+# if defined(_BYTE_ORDER)
+#  define BYTE_ORDER _BYTE_ORDER
+# elif defined(__BYTE_ORDER)
+#  define BYTE_ORDER __BYTE_ORDER
+# elif defined(__DARWIN_BYTE_ORDER)
+#  define BYTE_ORDER __DARWIN_BYTE_ORDER
+# endif
+#endif
+#ifndef BIG_ENDIAN
+# if defined(_BIG_ENDIAN)
+#  define BIG_ENDIAN _BIG_ENDIAN
+# elif defined(__BIG_ENDIAN)
+#  define BIG_ENDIAN __BIG_ENDIAN
+# elif defined(__DARWIN_BIG_ENDIAN)
+#  define BIG_ENDIAN __DARWIN_BIG_ENDIAN
+# endif
+#endif
+#ifndef LITTLE_ENDIAN
+# if defined(_LITTLE_ENDIAN)
+#  define LITTLE_ENDIAN _LITTLE_ENDIAN
+# elif defined(__LITTLE_ENDIAN)
+#  define LITTLE_ENDIAN __LITTLE_ENDIAN
+# elif defined(__DARWIN_LITTLE_ENDIAN)
+#  define LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
+# endif
+#endif
+#ifndef BYTE_ORDER
+# if defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN)
+#  undef BIG_ENDIAN
+#  define BIG_ENDIAN 4321
+#  define LITTLE_ENDIAN 1234
+#  define BYTE_ORDER BIG_ENDIAN
+# elif !defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN)
+#  undef LITTLE_ENDIAN
+#  define BIG_ENDIAN 4321
+#  define LITTLE_ENDIAN 1234
+#  define BYTE_ORDER LITTLE_ENDIAN
+# endif
+#endif
+#if !defined(BYTE_ORDER) || !defined(BIG_ENDIAN)
+# error "Cannot determine byte order"
+#endif
+
+#if HAVE_DIRENT_H
+# include <dirent.h>
+# define NAMLEN(dirent) strlen((dirent)->d_name)
+#else
+# define dirent direct
+# define NAMLEN(dirent) (dirent)->d_namlen
+# if HAVE_SYS_NDIR_H
+#  include <sys/ndir.h>
+# endif
+# if HAVE_SYS_DIR_H
+#  include <sys/dir.h>
+# endif
+# if HAVE_NDIR_H
+#  include <ndir.h>
+# endif
+#endif
+
+#if HAVE_STDARG_H
+# include <stdarg.h>
+#endif
+#if HAVE_CTYPE_H
+# include <ctype.h>
+#endif
+#if HAVE_SYS_PARAM_H
+# include <sys/param.h>
+#endif
+
+#if HAVE_KSTAT_H
+# include <kstat.h>
+#endif
+
+#ifndef PACKAGE_NAME
+#define PACKAGE_NAME "collectd"
+#endif
+
+#ifndef PREFIX
+#define PREFIX "/opt/" PACKAGE_NAME
+#endif
+
+#ifndef SYSCONFDIR
+#define SYSCONFDIR PREFIX "/etc"
+#endif
+
+#ifndef CONFIGFILE
+#define CONFIGFILE SYSCONFDIR"/collectd.conf"
+#endif
+
+#ifndef LOCALSTATEDIR
+#define LOCALSTATEDIR PREFIX "/var"
+#endif
+
+#ifndef PKGLOCALSTATEDIR
+#define PKGLOCALSTATEDIR PREFIX "/var/lib/" PACKAGE_NAME
+#endif
+
+#ifndef PIDFILE
+#define PIDFILE PREFIX "/var/run/" PACKAGE_NAME ".pid"
+#endif
+
+#ifndef PLUGINDIR
+#define PLUGINDIR PREFIX "/lib/" PACKAGE_NAME
+#endif
+
+#ifndef PKGDATADIR
+#define PKGDATADIR PREFIX "/share/" PACKAGE_NAME
+#endif
+
+#ifndef COLLECTD_GRP_NAME
+# define COLLECTD_GRP_NAME "collectd"
+#endif
+
+#ifndef COLLECTD_DEFAULT_INTERVAL
+# define COLLECTD_DEFAULT_INTERVAL 10.0
+#endif
+
+ #ifndef COLLECTD_USERAGENT
+ # define COLLECTD_USERAGENT PACKAGE_NAME"/"PACKAGE_VERSION
+ #endif
+
+/* Only enable __attribute__() for compilers known to support it. */
+#if defined(__clang__)
+# define clang_attr(x) __attribute__(x)
+# define gcc_attr(x) /**/
+#elif __GNUC__
+# define clang_attr(x) /**/
+# define gcc_attr(x) __attribute__(x)
+#else
+# define clang_attr(x) /**/
+# define gcc_attr(x) /**/
+# define __attribute__(x) /**/
+#endif
+
+#if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
+# undef strcpy
+# undef strcat
+# undef strtok
+# pragma GCC poison strcpy strcat strtok
+#endif
+
+/* 
+ * Special hack for the perl plugin: Because the later included perl.h defines
+ * a macro which is never used, but contains `sprintf', we cannot poison that
+ * identifies just yet. The parl plugin will do that itself once perl.h is
+ * included.
+ */
+#ifndef DONT_POISON_SPRINTF_YET
+# if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
+#  undef sprintf
+#  pragma GCC poison sprintf
+# endif
+#endif
+
+#ifndef GAUGE_FORMAT
+# define GAUGE_FORMAT "%.15g"
+#endif
+
+/* Type for time as used by "utils_time.h" */
+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 */
diff --git a/src/daemon/common.c b/src/daemon/common.c
new file mode 100644 (file)
index 0000000..b244808
--- /dev/null
@@ -0,0 +1,1656 @@
+/**
+ * collectd - src/common.c
+ * Copyright (C) 2005-2014  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>
+ *   Niki W. Waibel <niki.waibel@gmx.net>
+ *   Sebastian Harl <sh at tokkee.org>
+ *   Michał Mirosław <mirq-linux at rere.qmqm.pl>
+**/
+
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+#include "utils_cache.h"
+
+#if HAVE_PTHREAD_H
+# include <pthread.h>
+#endif
+
+#ifdef HAVE_MATH_H
+# include <math.h>
+#endif
+
+/* for getaddrinfo */
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+
+#if HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+
+/* for ntohl and htonl */
+#if HAVE_ARPA_INET_H
+# include <arpa/inet.h>
+#endif
+
+#ifdef HAVE_LIBKSTAT
+extern kstat_ctl_t *kc;
+#endif
+
+#if !HAVE_GETPWNAM_R
+static pthread_mutex_t getpwnam_r_lock = PTHREAD_MUTEX_INITIALIZER;
+#endif
+
+#if !HAVE_STRERROR_R
+static pthread_mutex_t strerror_r_lock = PTHREAD_MUTEX_INITIALIZER;
+#endif
+
+char *sstrncpy (char *dest, const char *src, size_t n)
+{
+       strncpy (dest, src, n);
+       dest[n - 1] = '\0';
+
+       return (dest);
+} /* char *sstrncpy */
+
+int ssnprintf (char *dest, size_t n, const char *format, ...)
+{
+       int ret = 0;
+       va_list ap;
+
+       va_start (ap, format);
+       ret = vsnprintf (dest, n, format, ap);
+       dest[n - 1] = '\0';
+       va_end (ap);
+
+       return (ret);
+} /* int ssnprintf */
+
+char *ssnprintf_alloc (char const *format, ...) /* {{{ */
+{
+       char static_buffer[1024] = "";
+       char *alloc_buffer;
+       size_t alloc_buffer_size;
+       int status;
+       va_list ap;
+
+       /* Try printing into the static buffer. In many cases it will be
+        * sufficiently large and we can simply return a strdup() of this
+        * buffer. */
+       va_start (ap, format);
+       status = vsnprintf (static_buffer, sizeof (static_buffer), format, ap);
+       va_end (ap);
+       if (status < 0)
+               return (NULL);
+
+       /* "status" does not include the null byte. */
+       alloc_buffer_size = (size_t) (status + 1);
+       if (alloc_buffer_size <= sizeof (static_buffer))
+               return (strdup (static_buffer));
+
+       /* Allocate a buffer large enough to hold the string. */
+       alloc_buffer = malloc (alloc_buffer_size);
+       if (alloc_buffer == NULL)
+               return (NULL);
+       memset (alloc_buffer, 0, alloc_buffer_size);
+
+       /* Print again into this new buffer. */
+       va_start (ap, format);
+       status = vsnprintf (alloc_buffer, alloc_buffer_size, format, ap);
+       va_end (ap);
+       if (status < 0)
+       {
+               sfree (alloc_buffer);
+               return (NULL);
+       }
+
+       return (alloc_buffer);
+} /* }}} char *ssnprintf_alloc */
+
+char *sstrdup (const char *s)
+{
+       char *r;
+       size_t sz;
+
+       if (s == NULL)
+               return (NULL);
+
+       /* Do not use `strdup' here, because it's not specified in POSIX. It's
+        * ``only'' an XSI extension. */
+       sz = strlen (s) + 1;
+       r = (char *) malloc (sizeof (char) * sz);
+       if (r == NULL)
+       {
+               ERROR ("sstrdup: Out of memory.");
+               exit (3);
+       }
+       memcpy (r, s, sizeof (char) * sz);
+
+       return (r);
+} /* char *sstrdup */
+
+/* Even though Posix requires "strerror_r" to return an "int",
+ * some systems (e.g. the GNU libc) return a "char *" _and_
+ * ignore the second argument ... -tokkee */
+char *sstrerror (int errnum, char *buf, size_t buflen)
+{
+       buf[0] = '\0';
+
+#if !HAVE_STRERROR_R
+       {
+               char *temp;
+
+               pthread_mutex_lock (&strerror_r_lock);
+
+               temp = strerror (errnum);
+               sstrncpy (buf, temp, buflen);
+
+               pthread_mutex_unlock (&strerror_r_lock);
+       }
+/* #endif !HAVE_STRERROR_R */
+
+#elif STRERROR_R_CHAR_P
+       {
+               char *temp;
+               temp = strerror_r (errnum, buf, buflen);
+               if (buf[0] == '\0')
+               {
+                       if ((temp != NULL) && (temp != buf) && (temp[0] != '\0'))
+                               sstrncpy (buf, temp, buflen);
+                       else
+                               sstrncpy (buf, "strerror_r did not return "
+                                               "an error message", buflen);
+               }
+       }
+/* #endif STRERROR_R_CHAR_P */
+
+#else
+       if (strerror_r (errnum, buf, buflen) != 0)
+       {
+               ssnprintf (buf, buflen, "Error #%i; "
+                               "Additionally, strerror_r failed.",
+                               errnum);
+       }
+#endif /* STRERROR_R_CHAR_P */
+
+       return (buf);
+} /* char *sstrerror */
+
+void *smalloc (size_t size)
+{
+       void *r;
+
+       if ((r = malloc (size)) == NULL)
+       {
+               ERROR ("Not enough memory.");
+               exit (3);
+       }
+
+       return (r);
+} /* void *smalloc */
+
+#if 0
+void sfree (void **ptr)
+{
+       if (ptr == NULL)
+               return;
+
+       if (*ptr != NULL)
+               free (*ptr);
+
+       *ptr = NULL;
+}
+#endif
+
+ssize_t sread (int fd, void *buf, size_t count)
+{
+       char    *ptr;
+       size_t   nleft;
+       ssize_t  status;
+
+       ptr   = (char *) buf;
+       nleft = count;
+
+       while (nleft > 0)
+       {
+               status = read (fd, (void *) ptr, nleft);
+
+               if ((status < 0) && ((errno == EAGAIN) || (errno == EINTR)))
+                       continue;
+
+               if (status < 0)
+                       return (status);
+
+               if (status == 0)
+               {
+                       DEBUG ("Received EOF from fd %i. "
+                                       "Closing fd and returning error.",
+                                       fd);
+                       close (fd);
+                       return (-1);
+               }
+
+               assert ((0 > status) || (nleft >= (size_t)status));
+
+               nleft = nleft - status;
+               ptr   = ptr   + status;
+       }
+
+       return (0);
+}
+
+
+ssize_t swrite (int fd, const void *buf, size_t count)
+{
+       const char *ptr;
+       size_t      nleft;
+       ssize_t     status;
+
+       ptr   = (const char *) buf;
+       nleft = count;
+
+       while (nleft > 0)
+       {
+               status = write (fd, (const void *) ptr, nleft);
+
+               if ((status < 0) && ((errno == EAGAIN) || (errno == EINTR)))
+                       continue;
+
+               if (status < 0)
+                       return (status);
+
+               nleft = nleft - status;
+               ptr   = ptr   + status;
+       }
+
+       return (0);
+}
+
+int strsplit (char *string, char **fields, size_t size)
+{
+       size_t i;
+       char *ptr;
+       char *saveptr;
+
+       i = 0;
+       ptr = string;
+       saveptr = NULL;
+       while ((fields[i] = strtok_r (ptr, " \t\r\n", &saveptr)) != NULL)
+       {
+               ptr = NULL;
+               i++;
+
+               if (i >= size)
+                       break;
+       }
+
+       return ((int) i);
+}
+
+int strjoin (char *buffer, size_t buffer_size,
+               char **fields, size_t fields_num,
+               const char *sep)
+{
+       size_t avail;
+       char *ptr;
+       size_t sep_len;
+       size_t i;
+
+       if ((buffer_size < 1) || (fields_num <= 0))
+               return (-1);
+
+       memset (buffer, 0, buffer_size);
+       ptr = buffer;
+       avail = buffer_size - 1;
+
+       sep_len = 0;
+       if (sep != NULL)
+               sep_len = strlen (sep);
+
+       for (i = 0; i < fields_num; i++)
+       {
+               size_t field_len;
+
+               if ((i > 0) && (sep_len > 0))
+               {
+                       if (avail < sep_len)
+                               return (-1);
+
+                       memcpy (ptr, sep, sep_len);
+                       ptr += sep_len;
+                       avail -= sep_len;
+               }
+
+               field_len = strlen (fields[i]);
+               if (avail < field_len)
+                       return (-1);
+
+               memcpy (ptr, fields[i], field_len);
+               ptr += field_len;
+               avail -= field_len;
+       }
+
+       assert (buffer[buffer_size - 1] == 0);
+       return (strlen (buffer));
+}
+
+int strsubstitute (char *str, char c_from, char c_to)
+{
+       int ret;
+
+       if (str == NULL)
+               return (-1);
+
+       ret = 0;
+       while (*str != '\0')
+       {
+               if (*str == c_from)
+               {
+                       *str = c_to;
+                       ret++;
+               }
+               str++;
+       }
+
+       return (ret);
+} /* int strsubstitute */
+
+int escape_string (char *buffer, size_t buffer_size)
+{
+  char *temp;
+  size_t i;
+  size_t j;
+
+  /* Check if we need to escape at all first */
+  temp = strpbrk (buffer, " \t\"\\");
+  if (temp == NULL)
+    return (0);
+
+  if (buffer_size < 3)
+    return (EINVAL);
+
+  temp = (char *) malloc (buffer_size);
+  if (temp == NULL)
+    return (ENOMEM);
+  memset (temp, 0, buffer_size);
+
+  temp[0] = '"';
+  j = 1;
+
+  for (i = 0; i < buffer_size; i++)
+  {
+    if (buffer[i] == 0)
+    {
+      break;
+    }
+    else if ((buffer[i] == '"') || (buffer[i] == '\\'))
+    {
+      if (j > (buffer_size - 4))
+        break;
+      temp[j] = '\\';
+      temp[j + 1] = buffer[i];
+      j += 2;
+    }
+    else
+    {
+      if (j > (buffer_size - 3))
+        break;
+      temp[j] = buffer[i];
+      j++;
+    }
+  }
+
+  assert ((j + 1) < buffer_size);
+  temp[j] = '"';
+  temp[j + 1] = 0;
+
+  sstrncpy (buffer, temp, buffer_size);
+  sfree (temp);
+  return (0);
+} /* int escape_string */
+
+int strunescape (char *buf, size_t buf_len)
+{
+       size_t i;
+
+       for (i = 0; (i < buf_len) && (buf[i] != '\0'); ++i)
+       {
+               if (buf[i] != '\\')
+                       continue;
+
+               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);
+               }
+
+               switch (buf[i + 1]) {
+                       case 't':
+                               buf[i] = '\t';
+                               break;
+                       case 'n':
+                               buf[i] = '\n';
+                               break;
+                       case 'r':
+                               buf[i] = '\r';
+                               break;
+                       default:
+                               buf[i] = buf[i + 1];
+                               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 */
+
+size_t strstripnewline (char *buffer)
+{
+       size_t buffer_len = strlen (buffer);
+
+       while (buffer_len > 0)
+       {
+               if ((buffer[buffer_len - 1] != '\n')
+                               && (buffer[buffer_len - 1] != '\r'))
+                       break;
+               buffer_len--;
+               buffer[buffer_len] = 0;
+       }
+
+       return (buffer_len);
+} /* size_t strstripnewline */
+
+int escape_slashes (char *buffer, size_t buffer_size)
+{
+       int i;
+       size_t buffer_len;
+
+       buffer_len = strlen (buffer);
+
+       if (buffer_len <= 1)
+       {
+               if (strcmp ("/", buffer) == 0)
+               {
+                       if (buffer_size < 5)
+                               return (-1);
+                       sstrncpy (buffer, "root", buffer_size);
+               }
+               return (0);
+       }
+
+       /* Move one to the left */
+       if (buffer[0] == '/')
+       {
+               memmove (buffer, buffer + 1, buffer_len);
+               buffer_len--;
+       }
+
+       for (i = 0; i < buffer_len; i++)
+       {
+               if (buffer[i] == '/')
+                       buffer[i] = '_';
+       }
+
+       return (0);
+} /* int escape_slashes */
+
+void replace_special (char *buffer, size_t buffer_size)
+{
+       size_t i;
+
+       for (i = 0; i < buffer_size; i++)
+       {
+               if (buffer[i] == 0)
+                       return;
+               if ((!isalnum ((int) buffer[i])) && (buffer[i] != '-'))
+                       buffer[i] = '_';
+       }
+} /* void replace_special */
+
+int timeval_cmp (struct timeval tv0, struct timeval tv1, struct timeval *delta)
+{
+       struct timeval *larger;
+       struct timeval *smaller;
+
+       int status;
+
+       NORMALIZE_TIMEVAL (tv0);
+       NORMALIZE_TIMEVAL (tv1);
+
+       if ((tv0.tv_sec == tv1.tv_sec) && (tv0.tv_usec == tv1.tv_usec))
+       {
+               if (delta != NULL) {
+                       delta->tv_sec  = 0;
+                       delta->tv_usec = 0;
+               }
+               return (0);
+       }
+
+       if ((tv0.tv_sec < tv1.tv_sec)
+                       || ((tv0.tv_sec == tv1.tv_sec) && (tv0.tv_usec < tv1.tv_usec)))
+       {
+               larger  = &tv1;
+               smaller = &tv0;
+               status  = -1;
+       }
+       else
+       {
+               larger  = &tv0;
+               smaller = &tv1;
+               status  = 1;
+       }
+
+       if (delta != NULL) {
+               delta->tv_sec = larger->tv_sec - smaller->tv_sec;
+
+               if (smaller->tv_usec <= larger->tv_usec)
+                       delta->tv_usec = larger->tv_usec - smaller->tv_usec;
+               else
+               {
+                       --delta->tv_sec;
+                       delta->tv_usec = 1000000 + larger->tv_usec - smaller->tv_usec;
+               }
+       }
+
+       assert ((delta == NULL)
+                       || ((0 <= delta->tv_usec) && (delta->tv_usec < 1000000)));
+
+       return (status);
+} /* int timeval_cmp */
+
+int check_create_dir (const char *file_orig)
+{
+       struct stat statbuf;
+
+       char  file_copy[512];
+       char  dir[512];
+       int   dir_len = 512;
+       char *fields[16];
+       int   fields_num;
+       char *ptr;
+       char *saveptr;
+       int   last_is_file = 1;
+       int   path_is_absolute = 0;
+       size_t len;
+       int   i;
+
+       /*
+        * Sanity checks first
+        */
+       if (file_orig == NULL)
+               return (-1);
+
+       if ((len = strlen (file_orig)) < 1)
+               return (-1);
+       else if (len >= sizeof (file_copy))
+               return (-1);
+
+       /*
+        * If `file_orig' ends in a slash the last component is a directory,
+        * otherwise it's a file. Act accordingly..
+        */
+       if (file_orig[len - 1] == '/')
+               last_is_file = 0;
+       if (file_orig[0] == '/')
+               path_is_absolute = 1;
+
+       /*
+        * Create a copy for `strtok_r' to destroy
+        */
+       sstrncpy (file_copy, file_orig, sizeof (file_copy));
+
+       /*
+        * Break into components. This will eat up several slashes in a row and
+        * remove leading and trailing slashes..
+        */
+       ptr = file_copy;
+       saveptr = NULL;
+       fields_num = 0;
+       while ((fields[fields_num] = strtok_r (ptr, "/", &saveptr)) != NULL)
+       {
+               ptr = NULL;
+               fields_num++;
+
+               if (fields_num >= 16)
+                       break;
+       }
+
+       /*
+        * For each component, do..
+        */
+       for (i = 0; i < (fields_num - last_is_file); i++)
+       {
+               /*
+                * Do not create directories that start with a dot. This
+                * prevents `../../' attacks and other likely malicious
+                * behavior.
+                */
+               if (fields[i][0] == '.')
+               {
+                       ERROR ("Cowardly refusing to create a directory that "
+                                       "begins with a `.' (dot): `%s'", file_orig);
+                       return (-2);
+               }
+
+               /*
+                * Join the components together again
+                */
+               dir[0] = '/';
+               if (strjoin (dir + path_is_absolute, dir_len - path_is_absolute,
+                                       fields, i + 1, "/") < 0)
+               {
+                       ERROR ("strjoin failed: `%s', component #%i", file_orig, i);
+                       return (-1);
+               }
+
+               while (42) {
+                       if ((stat (dir, &statbuf) == -1)
+                                       && (lstat (dir, &statbuf) == -1))
+                       {
+                               if (errno == ENOENT)
+                               {
+                                       if (mkdir (dir, S_IRWXU | S_IRWXG | S_IRWXO) == 0)
+                                               break;
+
+                                       /* this might happen, if a different thread created
+                                        * the directory in the meantime
+                                        * => call stat() again to check for S_ISDIR() */
+                                       if (EEXIST == errno)
+                                               continue;
+
+                                       char errbuf[1024];
+                                       ERROR ("check_create_dir: mkdir (%s): %s", dir,
+                                                       sstrerror (errno,
+                                                               errbuf, sizeof (errbuf)));
+                                       return (-1);
+                               }
+                               else
+                               {
+                                       char errbuf[1024];
+                                       ERROR ("check_create_dir: stat (%s): %s", dir,
+                                                       sstrerror (errno, errbuf,
+                                                               sizeof (errbuf)));
+                                       return (-1);
+                               }
+                       }
+                       else if (!S_ISDIR (statbuf.st_mode))
+                       {
+                               ERROR ("check_create_dir: `%s' exists but is not "
+                                               "a directory!", dir);
+                               return (-1);
+                       }
+                       break;
+               }
+       }
+
+       return (0);
+} /* check_create_dir */
+
+#ifdef HAVE_LIBKSTAT
+int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name)
+{
+       char ident[128];
+
+       *ksp_ptr = NULL;
+
+       if (kc == NULL)
+               return (-1);
+
+       ssnprintf (ident, sizeof (ident), "%s,%i,%s", module, instance, name);
+
+       *ksp_ptr = kstat_lookup (kc, module, instance, name);
+       if (*ksp_ptr == NULL)
+       {
+               ERROR ("get_kstat: Cound not find kstat %s", ident);
+               return (-1);
+       }
+
+       if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED)
+       {
+               ERROR ("get_kstat: kstat %s has wrong type", ident);
+               *ksp_ptr = NULL;
+               return (-1);
+       }
+
+#ifdef assert
+       assert (*ksp_ptr != NULL);
+       assert ((*ksp_ptr)->ks_type == KSTAT_TYPE_NAMED);
+#endif
+
+       if (kstat_read (kc, *ksp_ptr, NULL) == -1)
+       {
+               ERROR ("get_kstat: kstat %s could not be read", ident);
+               return (-1);
+       }
+
+       if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED)
+       {
+               ERROR ("get_kstat: kstat %s has wrong type", ident);
+               return (-1);
+       }
+
+       return (0);
+}
+
+long long get_kstat_value (kstat_t *ksp, char *name)
+{
+       kstat_named_t *kn;
+       long long retval = -1LL;
+
+       if (ksp == NULL)
+       {
+               ERROR ("get_kstat_value (\"%s\"): ksp is NULL.", name);
+               return (-1LL);
+       }
+       else if (ksp->ks_type != KSTAT_TYPE_NAMED)
+       {
+               ERROR ("get_kstat_value (\"%s\"): ksp->ks_type (%#x) "
+                               "is not KSTAT_TYPE_NAMED (%#x).",
+                               name,
+                               (unsigned int) ksp->ks_type,
+                               (unsigned int) KSTAT_TYPE_NAMED);
+               return (-1LL);
+       }
+
+       if ((kn = (kstat_named_t *) kstat_data_lookup (ksp, name)) == NULL)
+               return (-1LL);
+
+       if (kn->data_type == KSTAT_DATA_INT32)
+               retval = (long long) kn->value.i32;
+       else if (kn->data_type == KSTAT_DATA_UINT32)
+               retval = (long long) kn->value.ui32;
+       else if (kn->data_type == KSTAT_DATA_INT64)
+               retval = (long long) kn->value.i64; /* According to ANSI C99 `long long' must hold at least 64 bits */
+       else if (kn->data_type == KSTAT_DATA_UINT64)
+               retval = (long long) kn->value.ui64; /* XXX: Might overflow! */
+       else
+               WARNING ("get_kstat_value: Not a numeric value: %s", name);
+
+       return (retval);
+}
+#endif /* HAVE_LIBKSTAT */
+
+#ifndef HAVE_HTONLL
+unsigned long long ntohll (unsigned long long n)
+{
+#if BYTE_ORDER == BIG_ENDIAN
+       return (n);
+#else
+       return (((unsigned long long) ntohl (n)) << 32) + ntohl (n >> 32);
+#endif
+} /* unsigned long long ntohll */
+
+unsigned long long htonll (unsigned long long n)
+{
+#if BYTE_ORDER == BIG_ENDIAN
+       return (n);
+#else
+       return (((unsigned long long) htonl (n)) << 32) + htonl (n >> 32);
+#endif
+} /* unsigned long long htonll */
+#endif /* HAVE_HTONLL */
+
+#if FP_LAYOUT_NEED_NOTHING
+/* Well, we need nothing.. */
+/* #endif FP_LAYOUT_NEED_NOTHING */
+
+#elif FP_LAYOUT_NEED_ENDIANFLIP || FP_LAYOUT_NEED_INTSWAP
+# if FP_LAYOUT_NEED_ENDIANFLIP
+#  define FP_CONVERT(A) ((((uint64_t)(A) & 0xff00000000000000LL) >> 56) | \
+                         (((uint64_t)(A) & 0x00ff000000000000LL) >> 40) | \
+                         (((uint64_t)(A) & 0x0000ff0000000000LL) >> 24) | \
+                         (((uint64_t)(A) & 0x000000ff00000000LL) >> 8)  | \
+                         (((uint64_t)(A) & 0x00000000ff000000LL) << 8)  | \
+                         (((uint64_t)(A) & 0x0000000000ff0000LL) << 24) | \
+                         (((uint64_t)(A) & 0x000000000000ff00LL) << 40) | \
+                         (((uint64_t)(A) & 0x00000000000000ffLL) << 56))
+# else
+#  define FP_CONVERT(A) ((((uint64_t)(A) & 0xffffffff00000000LL) >> 32) | \
+                         (((uint64_t)(A) & 0x00000000ffffffffLL) << 32))
+# endif
+
+double ntohd (double d)
+{
+       union
+       {
+               uint8_t  byte[8];
+               uint64_t integer;
+               double   floating;
+       } ret;
+
+       ret.floating = d;
+
+       /* NAN in x86 byte order */
+       if ((ret.byte[0] == 0x00) && (ret.byte[1] == 0x00)
+                       && (ret.byte[2] == 0x00) && (ret.byte[3] == 0x00)
+                       && (ret.byte[4] == 0x00) && (ret.byte[5] == 0x00)
+                       && (ret.byte[6] == 0xf8) && (ret.byte[7] == 0x7f))
+       {
+               return (NAN);
+       }
+       else
+       {
+               uint64_t tmp;
+
+               tmp = ret.integer;
+               ret.integer = FP_CONVERT (tmp);
+               return (ret.floating);
+       }
+} /* double ntohd */
+
+double htond (double d)
+{
+       union
+       {
+               uint8_t  byte[8];
+               uint64_t integer;
+               double   floating;
+       } ret;
+
+       if (isnan (d))
+       {
+               ret.byte[0] = ret.byte[1] = ret.byte[2] = ret.byte[3] = 0x00;
+               ret.byte[4] = ret.byte[5] = 0x00;
+               ret.byte[6] = 0xf8;
+               ret.byte[7] = 0x7f;
+               return (ret.floating);
+       }
+       else
+       {
+               uint64_t tmp;
+
+               ret.floating = d;
+               tmp = FP_CONVERT (ret.integer);
+               ret.integer = tmp;
+               return (ret.floating);
+       }
+} /* double htond */
+#endif /* FP_LAYOUT_NEED_ENDIANFLIP || FP_LAYOUT_NEED_INTSWAP */
+
+int format_name (char *ret, int ret_len,
+               const char *hostname,
+               const char *plugin, const char *plugin_instance,
+               const char *type, const char *type_instance)
+{
+  char *buffer;
+  size_t buffer_size;
+
+  buffer = ret;
+  buffer_size = (size_t) ret_len;
+
+#define APPEND(str) do {                                               \
+  size_t l = strlen (str);                                             \
+  if (l >= buffer_size)                                                \
+    return (ENOBUFS);                                                  \
+  memcpy (buffer, (str), l);                                           \
+  buffer += l; buffer_size -= l;                                       \
+} while (0)
+
+  assert (plugin != NULL);
+  assert (type != NULL);
+
+  APPEND (hostname);
+  APPEND ("/");
+  APPEND (plugin);
+  if ((plugin_instance != NULL) && (plugin_instance[0] != 0))
+  {
+    APPEND ("-");
+    APPEND (plugin_instance);
+  }
+  APPEND ("/");
+  APPEND (type);
+  if ((type_instance != NULL) && (type_instance[0] != 0))
+  {
+    APPEND ("-");
+    APPEND (type_instance);
+  }
+  assert (buffer_size > 0);
+  buffer[0] = 0;
+
+#undef APPEND
+  return (0);
+} /* int format_name */
+
+int format_values (char *ret, size_t ret_len, /* {{{ */
+               const data_set_t *ds, const value_list_t *vl,
+               _Bool store_rates)
+{
+        size_t offset = 0;
+        int status;
+        int i;
+        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)
+
+        BUFFER_ADD ("%.3f", CDTIME_T_TO_DOUBLE (vl->time));
+
+        for (i = 0; i < ds->ds_num; i++)
+        {
+                if (ds->ds[i].type == DS_TYPE_GAUGE)
+                        BUFFER_ADD (":"GAUGE_FORMAT, vl->values[i].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 (":"GAUGE_FORMAT, rates[i]);
+                }
+                else if (ds->ds[i].type == DS_TYPE_COUNTER)
+                        BUFFER_ADD (":%llu", vl->values[i].counter);
+                else if (ds->ds[i].type == DS_TYPE_DERIVE)
+                        BUFFER_ADD (":%"PRIi64, vl->values[i].derive);
+                else if (ds->ds[i].type == DS_TYPE_ABSOLUTE)
+                        BUFFER_ADD (":%"PRIu64, vl->values[i].absolute);
+                else
+                {
+                        ERROR ("format_values: Unknown data source type: %i",
+                                        ds->ds[i].type);
+                        sfree (rates);
+                        return (-1);
+                }
+        } /* for ds->ds_num */
+
+#undef BUFFER_ADD
+
+        sfree (rates);
+        return (0);
+} /* }}} int format_values */
+
+int parse_identifier (char *str, char **ret_host,
+               char **ret_plugin, char **ret_plugin_instance,
+               char **ret_type, char **ret_type_instance)
+{
+       char *hostname = NULL;
+       char *plugin = NULL;
+       char *plugin_instance = NULL;
+       char *type = NULL;
+       char *type_instance = NULL;
+
+       hostname = str;
+       if (hostname == NULL)
+               return (-1);
+
+       plugin = strchr (hostname, '/');
+       if (plugin == NULL)
+               return (-1);
+       *plugin = '\0'; plugin++;
+
+       type = strchr (plugin, '/');
+       if (type == NULL)
+               return (-1);
+       *type = '\0'; type++;
+
+       plugin_instance = strchr (plugin, '-');
+       if (plugin_instance != NULL)
+       {
+               *plugin_instance = '\0';
+               plugin_instance++;
+       }
+
+       type_instance = strchr (type, '-');
+       if (type_instance != NULL)
+       {
+               *type_instance = '\0';
+               type_instance++;
+       }
+
+       *ret_host = hostname;
+       *ret_plugin = plugin;
+       *ret_plugin_instance = plugin_instance;
+       *ret_type = type;
+       *ret_type_instance = type_instance;
+       return (0);
+} /* int parse_identifier */
+
+int parse_identifier_vl (const char *str, value_list_t *vl) /* {{{ */
+{
+       char str_copy[6 * DATA_MAX_NAME_LEN];
+       char *host = NULL;
+       char *plugin = NULL;
+       char *plugin_instance = NULL;
+       char *type = NULL;
+       char *type_instance = NULL;
+       int status;
+
+       if ((str == NULL) || (vl == NULL))
+               return (EINVAL);
+
+       sstrncpy (str_copy, str, sizeof (str_copy));
+
+       status = parse_identifier (str_copy, &host,
+                       &plugin, &plugin_instance,
+                       &type, &type_instance);
+       if (status != 0)
+               return (status);
+
+       sstrncpy (vl->host, host, sizeof (vl->host));
+       sstrncpy (vl->plugin, plugin, sizeof (vl->plugin));
+       sstrncpy (vl->plugin_instance,
+                       (plugin_instance != NULL) ? plugin_instance : "",
+                       sizeof (vl->plugin_instance));
+       sstrncpy (vl->type, type, sizeof (vl->type));
+       sstrncpy (vl->type_instance,
+                       (type_instance != NULL) ? type_instance : "",
+                       sizeof (vl->type_instance));
+
+       return (0);
+} /* }}} int parse_identifier_vl */
+
+int parse_value (const char *value_orig, value_t *ret_value, int ds_type)
+{
+  char *value;
+  char *endptr = NULL;
+  size_t value_len;
+
+  if (value_orig == NULL)
+    return (EINVAL);
+
+  value = strdup (value_orig);
+  if (value == NULL)
+    return (ENOMEM);
+  value_len = strlen (value);
+
+  while ((value_len > 0) && isspace ((int) value[value_len - 1]))
+  {
+    value[value_len - 1] = 0;
+    value_len--;
+  }
+
+  switch (ds_type)
+  {
+    case DS_TYPE_COUNTER:
+      ret_value->counter = (counter_t) strtoull (value, &endptr, 0);
+      break;
+
+    case DS_TYPE_GAUGE:
+      ret_value->gauge = (gauge_t) strtod (value, &endptr);
+      break;
+
+    case DS_TYPE_DERIVE:
+      ret_value->derive = (derive_t) strtoll (value, &endptr, 0);
+      break;
+
+    case DS_TYPE_ABSOLUTE:
+      ret_value->absolute = (absolute_t) strtoull (value, &endptr, 0);
+      break;
+
+    default:
+      sfree (value);
+      ERROR ("parse_value: Invalid data source type: %i.", ds_type);
+      return -1;
+  }
+
+  if (value == endptr) {
+    ERROR ("parse_value: Failed to parse string as %s: %s.",
+        DS_TYPE_TO_STRING (ds_type), value);
+    sfree (value);
+    return -1;
+  }
+  else if ((NULL != endptr) && ('\0' != *endptr))
+    INFO ("parse_value: Ignoring trailing garbage \"%s\" after %s value. "
+        "Input string was \"%s\".",
+        endptr, DS_TYPE_TO_STRING (ds_type), value_orig);
+
+  sfree (value);
+  return 0;
+} /* int parse_value */
+
+int parse_values (char *buffer, value_list_t *vl, const data_set_t *ds)
+{
+       int i;
+       char *dummy;
+       char *ptr;
+       char *saveptr;
+
+       i = -1;
+       dummy = buffer;
+       saveptr = NULL;
+       while ((ptr = strtok_r (dummy, ":", &saveptr)) != NULL)
+       {
+               dummy = NULL;
+
+               if (i >= vl->values_len)
+               {
+                       /* Make sure i is invalid. */
+                       i = vl->values_len + 1;
+                       break;
+               }
+
+               if (i == -1)
+               {
+                       if (strcmp ("N", ptr) == 0)
+                               vl->time = cdtime ();
+                       else
+                       {
+                               char *endptr = NULL;
+                               double tmp;
+
+                               errno = 0;
+                               tmp = strtod (ptr, &endptr);
+                               if ((errno != 0)                    /* Overflow */
+                                               || (endptr == ptr)  /* Invalid string */
+                                               || (endptr == NULL) /* This should not happen */
+                                               || (*endptr != 0))  /* Trailing chars */
+                                       return (-1);
+
+                               vl->time = DOUBLE_TO_CDTIME_T (tmp);
+                       }
+               }
+               else
+               {
+                       if ((strcmp ("U", ptr) == 0) && (ds->ds[i].type == DS_TYPE_GAUGE))
+                               vl->values[i].gauge = NAN;
+                       else if (0 != parse_value (ptr, &vl->values[i], ds->ds[i].type))
+                               return -1;
+               }
+
+               i++;
+       } /* while (strtok_r) */
+
+       if ((ptr != NULL) || (i != vl->values_len))
+               return (-1);
+       return (0);
+} /* int parse_values */
+
+#if !HAVE_GETPWNAM_R
+int getpwnam_r (const char *name, struct passwd *pwbuf, char *buf,
+               size_t buflen, struct passwd **pwbufp)
+{
+       int status = 0;
+       struct passwd *pw;
+
+       memset (pwbuf, '\0', sizeof (struct passwd));
+
+       pthread_mutex_lock (&getpwnam_r_lock);
+
+       do
+       {
+               pw = getpwnam (name);
+               if (pw == NULL)
+               {
+                       status = (errno != 0) ? errno : ENOENT;
+                       break;
+               }
+
+#define GETPWNAM_COPY_MEMBER(member) \
+               if (pw->member != NULL) \
+               { \
+                       int len = strlen (pw->member); \
+                       if (len >= buflen) \
+                       { \
+                               status = ENOMEM; \
+                               break; \
+                       } \
+                       sstrncpy (buf, pw->member, buflen); \
+                       pwbuf->member = buf; \
+                       buf    += (len + 1); \
+                       buflen -= (len + 1); \
+               }
+               GETPWNAM_COPY_MEMBER(pw_name);
+               GETPWNAM_COPY_MEMBER(pw_passwd);
+               GETPWNAM_COPY_MEMBER(pw_gecos);
+               GETPWNAM_COPY_MEMBER(pw_dir);
+               GETPWNAM_COPY_MEMBER(pw_shell);
+
+               pwbuf->pw_uid = pw->pw_uid;
+               pwbuf->pw_gid = pw->pw_gid;
+
+               if (pwbufp != NULL)
+                       *pwbufp = pwbuf;
+       } while (0);
+
+       pthread_mutex_unlock (&getpwnam_r_lock);
+
+       return (status);
+} /* int getpwnam_r */
+#endif /* !HAVE_GETPWNAM_R */
+
+int notification_init (notification_t *n, int severity, const char *message,
+               const char *host,
+               const char *plugin, const char *plugin_instance,
+               const char *type, const char *type_instance)
+{
+       memset (n, '\0', sizeof (notification_t));
+
+       n->severity = severity;
+
+       if (message != NULL)
+               sstrncpy (n->message, message, sizeof (n->message));
+       if (host != NULL)
+               sstrncpy (n->host, host, sizeof (n->host));
+       if (plugin != NULL)
+               sstrncpy (n->plugin, plugin, sizeof (n->plugin));
+       if (plugin_instance != NULL)
+               sstrncpy (n->plugin_instance, plugin_instance,
+                               sizeof (n->plugin_instance));
+       if (type != NULL)
+               sstrncpy (n->type, type, sizeof (n->type));
+       if (type_instance != NULL)
+               sstrncpy (n->type_instance, type_instance,
+                               sizeof (n->type_instance));
+
+       return (0);
+} /* int notification_init */
+
+int walk_directory (const char *dir, dirwalk_callback_f callback,
+               void *user_data, int include_hidden)
+{
+       struct dirent *ent;
+       DIR *dh;
+       int success;
+       int failure;
+
+       success = 0;
+       failure = 0;
+
+       if ((dh = opendir (dir)) == NULL)
+       {
+               char errbuf[1024];
+               ERROR ("walk_directory: Cannot open '%s': %s", dir,
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
+               return -1;
+       }
+
+       while ((ent = readdir (dh)) != NULL)
+       {
+               int status;
+
+               if (include_hidden)
+               {
+                       if ((strcmp (".", ent->d_name) == 0)
+                                       || (strcmp ("..", ent->d_name) == 0))
+                               continue;
+               }
+               else /* if (!include_hidden) */
+               {
+                       if (ent->d_name[0]=='.')
+                               continue;
+               }
+
+               status = (*callback) (dir, ent->d_name, user_data);
+               if (status != 0)
+                       failure++;
+               else
+                       success++;
+       }
+
+       closedir (dh);
+
+       if ((success == 0) && (failure > 0))
+               return (-1);
+       return (0);
+}
+
+ssize_t read_file_contents (const char *filename, char *buf, size_t bufsize)
+{
+       FILE *fh;
+       ssize_t ret;
+
+       fh = fopen (filename, "r");
+       if (fh == NULL)
+               return (-1);
+
+       ret = (ssize_t) fread (buf, 1, bufsize, fh);
+       if ((ret == 0) && (ferror (fh) != 0))
+       {
+               ERROR ("read_file_contents: Reading file \"%s\" failed.",
+                               filename);
+               ret = -1;
+       }
+
+       fclose(fh);
+       return (ret);
+}
+
+counter_t counter_diff (counter_t old_value, counter_t new_value)
+{
+       counter_t diff;
+
+       if (old_value > new_value)
+       {
+               if (old_value <= 4294967295U)
+                       diff = (4294967295U - old_value) + new_value;
+               else
+                       diff = (18446744073709551615ULL - old_value)
+                               + new_value;
+       }
+       else
+       {
+               diff = new_value - old_value;
+       }
+
+       return (diff);
+} /* counter_t counter_diff */
+
+int rate_to_value (value_t *ret_value, gauge_t rate, /* {{{ */
+               rate_to_value_state_t *state,
+               int ds_type, cdtime_t t)
+{
+       gauge_t delta_gauge;
+       cdtime_t delta_t;
+
+       if (ds_type == DS_TYPE_GAUGE)
+       {
+               state->last_value.gauge = rate;
+               state->last_time = t;
+
+               *ret_value = state->last_value;
+               return (0);
+       }
+
+       /* Counter and absolute can't handle negative rates. Reset "last time"
+        * to zero, so that the next valid rate will re-initialize the
+        * structure. */
+       if ((rate < 0.0)
+                       && ((ds_type == DS_TYPE_COUNTER)
+                               || (ds_type == DS_TYPE_ABSOLUTE)))
+       {
+               memset (state, 0, sizeof (*state));
+               return (EINVAL);
+       }
+
+       /* Another invalid state: The time is not increasing. */
+       if (t <= state->last_time)
+       {
+               memset (state, 0, sizeof (*state));
+               return (EINVAL);
+       }
+
+       delta_t = t - state->last_time;
+       delta_gauge = (rate * CDTIME_T_TO_DOUBLE (delta_t)) + state->residual;
+
+       /* Previous value is invalid. */
+       if (state->last_time == 0) /* {{{ */
+       {
+               if (ds_type == DS_TYPE_DERIVE)
+               {
+                       state->last_value.derive = (derive_t) rate;
+                       state->residual = rate - ((gauge_t) state->last_value.derive);
+               }
+               else if (ds_type == DS_TYPE_COUNTER)
+               {
+                       state->last_value.counter = (counter_t) rate;
+                       state->residual = rate - ((gauge_t) state->last_value.counter);
+               }
+               else if (ds_type == DS_TYPE_ABSOLUTE)
+               {
+                       state->last_value.absolute = (absolute_t) rate;
+                       state->residual = rate - ((gauge_t) state->last_value.absolute);
+               }
+               else
+               {
+                       assert (23 == 42);
+               }
+
+               state->last_time = t;
+               return (EAGAIN);
+       } /* }}} */
+
+       if (ds_type == DS_TYPE_DERIVE)
+       {
+               derive_t delta_derive = (derive_t) delta_gauge;
+
+               state->last_value.derive += delta_derive;
+               state->residual = delta_gauge - ((gauge_t) delta_derive);
+       }
+       else if (ds_type == DS_TYPE_COUNTER)
+       {
+               counter_t delta_counter = (counter_t) delta_gauge;
+
+               state->last_value.counter += delta_counter;
+               state->residual = delta_gauge - ((gauge_t) delta_counter);
+       }
+       else if (ds_type == DS_TYPE_ABSOLUTE)
+       {
+               absolute_t delta_absolute = (absolute_t) delta_gauge;
+
+               state->last_value.absolute = delta_absolute;
+               state->residual = delta_gauge - ((gauge_t) delta_absolute);
+       }
+       else
+       {
+               assert (23 == 42);
+       }
+
+        state->last_time = t;
+       *ret_value = state->last_value;
+       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;
+       struct addrinfo *ai_ptr;
+       struct addrinfo ai_hints;
+       int status;
+       int service_number;
+
+       if (service_name == NULL)
+               return (-1);
+
+       ai_list = NULL;
+       memset (&ai_hints, 0, sizeof (ai_hints));
+       ai_hints.ai_family = AF_UNSPEC;
+
+       status = getaddrinfo (/* node = */ NULL, service_name,
+                       &ai_hints, &ai_list);
+       if (status != 0)
+       {
+               ERROR ("service_name_to_port_number: getaddrinfo failed: %s",
+                               gai_strerror (status));
+               return (-1);
+       }
+
+       service_number = -1;
+       for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+       {
+               if (ai_ptr->ai_family == AF_INET)
+               {
+                       struct sockaddr_in *sa;
+
+                       sa = (void *) ai_ptr->ai_addr;
+                       service_number = (int) ntohs (sa->sin_port);
+               }
+               else if (ai_ptr->ai_family == AF_INET6)
+               {
+                       struct sockaddr_in6 *sa;
+
+                       sa = (void *) ai_ptr->ai_addr;
+                       service_number = (int) ntohs (sa->sin6_port);
+               }
+
+               if ((service_number > 0) && (service_number <= 65535))
+                       break;
+       }
+
+       freeaddrinfo (ai_list);
+
+       if ((service_number > 0) && (service_number <= 65535))
+               return (service_number);
+       return (-1);
+} /* int service_name_to_port_number */
+
+int strtoderive (const char *string, derive_t *ret_value) /* {{{ */
+{
+       derive_t tmp;
+       char *endptr;
+
+       if ((string == NULL) || (ret_value == NULL))
+               return (EINVAL);
+
+       errno = 0;
+       endptr = NULL;
+       tmp = (derive_t) strtoll (string, &endptr, /* base = */ 0);
+       if ((endptr == string) || (errno != 0))
+               return (-1);
+
+       *ret_value = tmp;
+       return (0);
+} /* }}} int strtoderive */
+
+int strtogauge (const char *string, gauge_t *ret_value) /* {{{ */
+{
+       gauge_t tmp;
+       char *endptr = NULL;
+
+       if ((string == NULL) || (ret_value == NULL))
+               return (EINVAL);
+
+       errno = 0;
+       endptr = NULL;
+       tmp = (gauge_t) strtod (string, &endptr);
+       if (errno != 0)
+               return (errno);
+       else if ((endptr == NULL) || (*endptr != 0))
+               return (EINVAL);
+
+       *ret_value = tmp;
+       return (0);
+} /* }}} int strtogauge */
+
+int strarray_add (char ***ret_array, size_t *ret_array_len, char const *str) /* {{{ */
+{
+       char **array;
+       size_t array_len = *ret_array_len;
+
+       if (str == NULL)
+               return (EINVAL);
+
+       array = realloc (*ret_array,
+            (array_len + 1) * sizeof (*array));
+       if (array == NULL)
+               return (ENOMEM);
+       *ret_array = array;
+
+       array[array_len] = strdup (str);
+       if (array[array_len] == NULL)
+               return (ENOMEM);
+
+       array_len++;
+        *ret_array_len = array_len;
+       return (0);
+} /* }}} int strarray_add */
+
+void strarray_free (char **array, size_t array_len) /* {{{ */
+{
+       size_t i;
+
+       for (i = 0; i < array_len; i++)
+               sfree (array[i]);
+       sfree (array);
+} /* }}} void strarray_free */
diff --git a/src/daemon/common.h b/src/daemon/common.h
new file mode 100644 (file)
index 0000000..da21cad
--- /dev/null
@@ -0,0 +1,378 @@
+/**
+ * collectd - src/common.h
+ * Copyright (C) 2005-2014  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>
+ *   Niki W. Waibel <niki.waibel@gmx.net>
+**/
+
+#ifndef COMMON_H
+#define COMMON_H
+
+#include "collectd.h"
+#include "plugin.h"
+
+#if HAVE_PWD_H
+# include <pwd.h>
+#endif
+
+#define sfree(ptr) \
+       do { \
+               if((ptr) != NULL) { \
+                       free(ptr); \
+               } \
+               (ptr) = NULL; \
+       } while (0)
+
+#define STATIC_ARRAY_SIZE(a) (sizeof (a) / sizeof (*(a)))
+
+#define IS_TRUE(s) ((strcasecmp ("true", (s)) == 0) \
+               || (strcasecmp ("yes", (s)) == 0) \
+               || (strcasecmp ("on", (s)) == 0))
+#define IS_FALSE(s) ((strcasecmp ("false", (s)) == 0) \
+               || (strcasecmp ("no", (s)) == 0) \
+               || (strcasecmp ("off", (s)) == 0))
+
+struct rate_to_value_state_s
+{
+  value_t last_value;
+  cdtime_t last_time;
+  gauge_t residual;
+};
+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)))
+int ssnprintf (char *dest, size_t n, const char *format, ...);
+
+__attribute__ ((format(printf,1,2)))
+char *ssnprintf_alloc (char const *format, ...);
+
+char *sstrdup(const char *s);
+void *smalloc(size_t size);
+char *sstrerror (int errnum, char *buf, size_t buflen);
+
+/*
+ * NAME
+ *   sread
+ *
+ * DESCRIPTION
+ *   Reads exactly `n' bytes or fails. Syntax and other behavior is analogous
+ *   to `read(2)'. If EOF is received the file descriptor is closed and an
+ *   error is returned.
+ *
+ * PARAMETERS
+ *   `fd'          File descriptor to write to.
+ *   `buf'         Buffer that is to be written.
+ *   `count'       Number of bytes in the buffer.
+ *
+ * RETURN VALUE
+ *   Zero upon success or non-zero if an error occurred. `errno' is set in this
+ *   case.
+ */
+ssize_t sread (int fd, void *buf, size_t count);
+
+/*
+ * NAME
+ *   swrite
+ *
+ * DESCRIPTION
+ *   Writes exactly `n' bytes or fails. Syntax and other behavior is analogous
+ *   to `write(2)'.
+ *
+ * PARAMETERS
+ *   `fd'          File descriptor to write to.
+ *   `buf'         Buffer that is to be written.
+ *   `count'       Number of bytes in the buffer.
+ *
+ * RETURN VALUE
+ *   Zero upon success or non-zero if an error occurred. `errno' is set in this
+ *   case.
+ */
+ssize_t swrite (int fd, const void *buf, size_t count);
+
+/*
+ * NAME
+ *   strsplit
+ *
+ * DESCRIPTION
+ *   Splits a string into parts and stores pointers to the parts in `fields'.
+ *   The characters split at are: " ", "\t", "\r", and "\n".
+ *
+ * PARAMETERS
+ *   `string'      String to split. This string will be modified. `fields' will
+ *                 contain pointers to parts of this string, so free'ing it
+ *                 will destroy `fields' as well.
+ *   `fields'      Array of strings where pointers to the parts will be stored.
+ *   `size'        Number of elements in the array. No more than `size'
+ *                 pointers will be stored in `fields'.
+ *
+ * RETURN VALUE
+ *    Returns the number of parts stored in `fields'.
+ */
+int strsplit (char *string, char **fields, size_t size);
+
+/*
+ * NAME
+ *   strjoin
+ *
+ * DESCRIPTION
+ *   Joins together several parts of a string using `sep' as a separator. This
+ *   is equivalent to the Perl built-in `join'.
+ *
+ * PARAMETERS
+ *   `dst'         Buffer where the result is stored.
+ *   `dst_len'     Length of the destination buffer. No more than this many
+ *                 bytes will be written to the memory pointed to by `dst',
+ *                 including the trailing null-byte.
+ *   `fields'      Array of strings to be joined.
+ *   `fields_num'  Number of elements in the `fields' array.
+ *   `sep'         String to be inserted between any two elements of `fields'.
+ *                 This string is neither prepended nor appended to the result.
+ *                 Instead of passing "" (empty string) one can pass NULL.
+ *
+ * RETURN VALUE
+ *   Returns the number of characters in `dst', NOT including the trailing
+ *   null-byte. If an error occurred (empty array or `dst' too small) a value
+ *   smaller than zero will be returned.
+ */
+int strjoin (char *dst, size_t dst_len, char **fields, size_t fields_num, const char *sep);
+
+/*
+ * NAME
+ *   escape_slashes
+ *
+ * DESCRIPTION
+ *   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
+ *   `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 *buffer, size_t buffer_size);
+
+/**
+ * NAME
+ *   escape_string
+ *
+ * DESCRIPTION
+ *   escape_string quotes and escapes a string to be usable with collectd's
+ *   plain text protocol. "simple" strings are left as they are, for example if
+ *   buffer is 'simple' before the call, it will remain 'simple'. However, if
+ *   buffer contains 'more "complex"' before the call, the returned buffer will
+ *   contain '"more \"complex\""'.
+ *
+ *   If the buffer is too small to contain the escaped string, the string will
+ *   be truncated. However, leading and trailing double quotes, as well as an
+ *   ending null byte are guaranteed.
+ *
+ * RETURN VALUE
+ *   Returns zero on success, even if the string was truncated. Non-zero on
+ *   failure.
+ */
+int escape_string (char *buffer, size_t buffer_size);
+
+/*
+ * NAME
+ *   replace_special
+ *
+ * DESCRIPTION
+ *   Replaces any special characters (anything that's not alpha-numeric or a
+ *   dash) with an underscore.
+ *
+ *   E.g. "foo$bar&" would become "foo_bar_".
+ *
+ * PARAMETERS
+ *   `buffer'      String to be handled.
+ *   `buffer_size' Length of the string. The function returns after
+ *                 encountering a null-byte or reading this many bytes.
+ */
+void replace_special (char *buffer, size_t buffer_size);
+
+int strsubstitute (char *str, char c_from, char c_to);
+
+/*
+ * NAME
+ *   strunescape
+ *
+ * DESCRIPTION
+ *   Replaces any escaped characters in a string with the appropriate special
+ *   characters. The following escaped characters are recognized:
+ *
+ *     \t -> <tab>
+ *     \n -> <newline>
+ *     \r -> <carriage return>
+ *
+ *   For all other escacped characters only the backslash will be removed.
+ *
+ * PARAMETERS
+ *   `buf'         String to be unescaped.
+ *   `buf_len'     Length of the string, including the terminating null-byte.
+ *
+ * RETURN VALUE
+ *   Returns zero upon success, a value less than zero else.
+ */
+int strunescape (char *buf, size_t buf_len);
+
+/**
+ * Removed trailing newline characters (CR and LF) from buffer, which must be
+ * null terminated. Returns the length of the resulting string.
+ */
+__attribute__((nonnull (1)))
+size_t strstripnewline (char *buffer);
+
+/*
+ * NAME
+ *   timeval_cmp
+ *
+ * DESCRIPTION
+ *   Compare the two time values `tv0' and `tv1' and store the absolut value
+ *   of the difference in the time value pointed to by `delta' if it does not
+ *   equal NULL.
+ *
+ * RETURN VALUE
+ *   Returns an integer less than, equal to, or greater than zero if `tv0' is
+ *   less than, equal to, or greater than `tv1' respectively.
+ */
+int timeval_cmp (struct timeval tv0, struct timeval tv1, struct timeval *delta);
+
+/* make sure tv_usec stores less than a second */
+#define NORMALIZE_TIMEVAL(tv) \
+       do { \
+               (tv).tv_sec += (tv).tv_usec / 1000000; \
+               (tv).tv_usec = (tv).tv_usec % 1000000; \
+       } while (0)
+
+/* make sure tv_sec stores less than a second */
+#define NORMALIZE_TIMESPEC(tv) \
+       do { \
+               (tv).tv_sec += (tv).tv_nsec / 1000000000; \
+               (tv).tv_nsec = (tv).tv_nsec % 1000000000; \
+       } while (0)
+
+int check_create_dir (const char *file_orig);
+
+#ifdef HAVE_LIBKSTAT
+int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name);
+long long get_kstat_value (kstat_t *ksp, char *name);
+#endif
+
+#ifndef HAVE_HTONLL
+unsigned long long ntohll (unsigned long long n);
+unsigned long long htonll (unsigned long long n);
+#endif
+
+#if FP_LAYOUT_NEED_NOTHING
+# define ntohd(d) (d)
+# define htond(d) (d)
+#elif FP_LAYOUT_NEED_ENDIANFLIP || FP_LAYOUT_NEED_INTSWAP
+double ntohd (double d);
+double htond (double d);
+#else
+# error "Don't know how to convert between host and network representation of doubles."
+#endif
+
+int format_name (char *ret, int ret_len,
+               const char *hostname,
+               const char *plugin, const char *plugin_instance,
+               const char *type, const char *type_instance);
+#define FORMAT_VL(ret, ret_len, vl) \
+       format_name (ret, ret_len, (vl)->host, (vl)->plugin, (vl)->plugin_instance, \
+                       (vl)->type, (vl)->type_instance)
+int format_values (char *ret, size_t ret_len,
+               const data_set_t *ds, const value_list_t *vl,
+               _Bool store_rates);
+
+int parse_identifier (char *str, char **ret_host,
+               char **ret_plugin, char **ret_plugin_instance,
+               char **ret_type, char **ret_type_instance);
+int parse_identifier_vl (const char *str, value_list_t *vl);
+int parse_value (const char *value, value_t *ret_value, int ds_type);
+int parse_values (char *buffer, value_list_t *vl, const data_set_t *ds);
+
+#if !HAVE_GETPWNAM_R
+int getpwnam_r (const char *name, struct passwd *pwbuf, char *buf,
+               size_t buflen, struct passwd **pwbufp);
+#endif
+
+int notification_init (notification_t *n, int severity, const char *message,
+               const char *host,
+               const char *plugin, const char *plugin_instance,
+               const char *type, const char *type_instance);
+#define NOTIFICATION_INIT_VL(n, vl) \
+       notification_init (n, NOTIF_FAILURE, NULL, \
+                       (vl)->host, (vl)->plugin, (vl)->plugin_instance, \
+                       (vl)->type, (vl)->type_instance)
+
+typedef int (*dirwalk_callback_f)(const char *dirname, const char *filename,
+               void *user_data);
+int walk_directory (const char *dir, dirwalk_callback_f callback,
+               void *user_data, int hidden);
+/* Returns the number of bytes read or negative on error. */
+ssize_t read_file_contents (char const *filename, char *buf, size_t bufsize);
+
+counter_t counter_diff (counter_t old_value, counter_t new_value);
+
+/* Convert a rate back to a value_t. When converting to a derive_t, counter_t
+ * or absoltue_t, take fractional residuals into account. This is important
+ * when scaling counters, for example.
+ * Returns zero on success. Returns EAGAIN when called for the first time; in
+ * this case the value_t is invalid and the next call should succeed. Other
+ * return values indicate an error. */
+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);
+
+/** Parse a string to a derive_t value. Returns zero on success or non-zero on
+ * failure. If failure is returned, ret_value is not touched. */
+int strtoderive (const char *string, derive_t *ret_value);
+
+/** Parse a string to a gauge_t value. Returns zero on success or non-zero on
+ * failure. If failure is returned, ret_value is not touched. */
+int strtogauge (const char *string, gauge_t *ret_value);
+
+int strarray_add (char ***ret_array, size_t *ret_array_len, char const *str);
+void strarray_free (char **array, size_t array_len);
+
+#endif /* COMMON_H */
diff --git a/src/daemon/common_test.c b/src/daemon/common_test.c
new file mode 100644 (file)
index 0000000..1fa8f32
--- /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 "testing.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/daemon/configfile.c b/src/daemon/configfile.c
new file mode 100644 (file)
index 0000000..ae3e798
--- /dev/null
@@ -0,0 +1,1372 @@
+/**
+ * collectd - src/configfile.c
+ * Copyright (C) 2005-2011  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>
+ *   Sebastian tokkee Harl <sh at tokkee.org>
+ **/
+
+#include "collectd.h"
+
+#include "liboconfig/oconfig.h"
+
+#include "common.h"
+#include "plugin.h"
+#include "configfile.h"
+#include "types_list.h"
+#include "filter_chain.h"
+
+#if HAVE_WORDEXP_H
+# include <wordexp.h>
+#endif /* HAVE_WORDEXP_H */
+
+#if HAVE_FNMATCH_H
+# include <fnmatch.h>
+#endif /* HAVE_FNMATCH_H */
+
+#if HAVE_LIBGEN_H
+# include <libgen.h>
+#endif /* HAVE_LIBGEN_H */
+
+#define ESCAPE_NULL(str) ((str) == NULL ? "(null)" : (str))
+
+/*
+ * Private types
+ */
+typedef struct cf_callback
+{
+       const char  *type;
+       int  (*callback) (const char *, const char *);
+       const char **keys;
+       int    keys_num;
+       plugin_ctx_t ctx;
+       struct cf_callback *next;
+} cf_callback_t;
+
+typedef struct cf_complex_callback_s
+{
+       char *type;
+       int (*callback) (oconfig_item_t *);
+       plugin_ctx_t ctx;
+       struct cf_complex_callback_s *next;
+} cf_complex_callback_t;
+
+typedef struct cf_value_map_s
+{
+       char *key;
+       int (*func) (oconfig_item_t *);
+} cf_value_map_t;
+
+typedef struct cf_global_option_s
+{
+       char *key;
+       char *value;
+       char *def;
+} cf_global_option_t;
+
+/*
+ * Prototypes of callback functions
+ */
+static int dispatch_value_typesdb (oconfig_item_t *ci);
+static int dispatch_value_plugindir (oconfig_item_t *ci);
+static int dispatch_loadplugin (oconfig_item_t *ci);
+static int dispatch_block_plugin (oconfig_item_t *ci);
+
+/*
+ * Private variables
+ */
+static cf_callback_t *first_callback = NULL;
+static cf_complex_callback_t *complex_callback_head = NULL;
+
+static cf_value_map_t cf_value_map[] =
+{
+       {"TypesDB",    dispatch_value_typesdb},
+       {"PluginDir",  dispatch_value_plugindir},
+       {"LoadPlugin", dispatch_loadplugin},
+       {"Plugin",     dispatch_block_plugin}
+};
+static int cf_value_map_num = STATIC_ARRAY_SIZE (cf_value_map);
+
+static cf_global_option_t cf_global_options[] =
+{
+       {"BaseDir",     NULL, PKGLOCALSTATEDIR},
+       {"PIDFile",     NULL, PIDFILE},
+       {"Hostname",    NULL, NULL},
+       {"FQDNLookup",  NULL, "true"},
+       {"Interval",    NULL, NULL},
+       {"ReadThreads", NULL, "5"},
+       {"WriteThreads", NULL, "5"},
+       {"WriteQueueLimitHigh", NULL, NULL},
+       {"WriteQueueLimitLow", NULL, NULL},
+       {"Timeout",     NULL, "2"},
+       {"AutoLoadPlugin", NULL, "false"},
+       {"CollectInternalStats", NULL, "false"},
+       {"PreCacheChain",  NULL, "PreCache"},
+       {"PostCacheChain", NULL, "PostCache"},
+       {"MaxReadInterval", NULL, "86400"}
+};
+static int cf_global_options_num = STATIC_ARRAY_SIZE (cf_global_options);
+
+static int cf_default_typesdb = 1;
+
+/*
+ * Functions to handle register/unregister, search, and other plugin related
+ * stuff
+ */
+static cf_callback_t *cf_search (const char *type)
+{
+       cf_callback_t *cf_cb;
+
+       if (type == NULL)
+               return (NULL);
+
+       for (cf_cb = first_callback; cf_cb != NULL; cf_cb = cf_cb->next)
+               if (strcasecmp (cf_cb->type, type) == 0)
+                       break;
+
+       return (cf_cb);
+}
+
+static int cf_dispatch (const char *type, const char *orig_key,
+               const char *orig_value)
+{
+       cf_callback_t *cf_cb;
+       plugin_ctx_t old_ctx;
+       char *key;
+       char *value;
+       int ret;
+       int i;
+
+       if (orig_key == NULL)
+               return (EINVAL);
+
+       DEBUG ("type = %s, key = %s, value = %s",
+                       ESCAPE_NULL(type),
+                       orig_key,
+                       ESCAPE_NULL(orig_value));
+
+       if ((cf_cb = cf_search (type)) == NULL)
+       {
+               WARNING ("Found a configuration for the `%s' plugin, but "
+                               "the plugin isn't loaded or didn't register "
+                               "a configuration callback.", type);
+               return (-1);
+       }
+
+       if ((key = strdup (orig_key)) == NULL)
+               return (1);
+       if ((value = strdup (orig_value)) == NULL)
+       {
+               free (key);
+               return (2);
+       }
+
+       ret = -1;
+
+       old_ctx = plugin_set_ctx (cf_cb->ctx);
+
+       for (i = 0; i < cf_cb->keys_num; i++)
+       {
+               if ((cf_cb->keys[i] != NULL)
+                               && (strcasecmp (cf_cb->keys[i], key) == 0))
+               {
+                       ret = (*cf_cb->callback) (key, value);
+                       break;
+               }
+       }
+
+       plugin_set_ctx (old_ctx);
+
+       if (i >= cf_cb->keys_num)
+               WARNING ("Plugin `%s' did not register for value `%s'.", type, key);
+
+       free (key);
+       free (value);
+
+       return (ret);
+} /* int cf_dispatch */
+
+static int dispatch_global_option (const oconfig_item_t *ci)
+{
+       if (ci->values_num != 1)
+               return (-1);
+       if (ci->values[0].type == OCONFIG_TYPE_STRING)
+               return (global_option_set (ci->key, ci->values[0].value.string));
+       else if (ci->values[0].type == OCONFIG_TYPE_NUMBER)
+       {
+               char tmp[128];
+               ssnprintf (tmp, sizeof (tmp), "%lf", ci->values[0].value.number);
+               return (global_option_set (ci->key, tmp));
+       }
+       else if (ci->values[0].type == OCONFIG_TYPE_BOOLEAN)
+       {
+               if (ci->values[0].value.boolean)
+                       return (global_option_set (ci->key, "true"));
+               else
+                       return (global_option_set (ci->key, "false"));
+       }
+
+       return (-1);
+} /* int dispatch_global_option */
+
+static int dispatch_value_typesdb (oconfig_item_t *ci)
+{
+       int i = 0;
+
+       assert (strcasecmp (ci->key, "TypesDB") == 0);
+
+       cf_default_typesdb = 0;
+
+       if (ci->values_num < 1) {
+               ERROR ("configfile: `TypesDB' needs at least one argument.");
+               return (-1);
+       }
+
+       for (i = 0; i < ci->values_num; ++i)
+       {
+               if (OCONFIG_TYPE_STRING != ci->values[i].type) {
+                       WARNING ("configfile: TypesDB: Skipping %i. argument which "
+                                       "is not a string.", i + 1);
+                       continue;
+               }
+
+               read_types_list (ci->values[i].value.string);
+       }
+       return (0);
+} /* int dispatch_value_typesdb */
+
+static int dispatch_value_plugindir (oconfig_item_t *ci)
+{
+       assert (strcasecmp (ci->key, "PluginDir") == 0);
+       
+       if (ci->values_num != 1)
+               return (-1);
+       if (ci->values[0].type != OCONFIG_TYPE_STRING)
+               return (-1);
+
+       plugin_set_dir (ci->values[0].value.string);
+       return (0);
+}
+
+static int dispatch_loadplugin (oconfig_item_t *ci)
+{
+       int i;
+       const char *name;
+       unsigned int flags = 0;
+       plugin_ctx_t ctx;
+       plugin_ctx_t old_ctx;
+       int ret_val;
+
+       assert (strcasecmp (ci->key, "LoadPlugin") == 0);
+
+       if (ci->values_num != 1)
+               return (-1);
+       if (ci->values[0].type != OCONFIG_TYPE_STRING)
+               return (-1);
+
+       name = ci->values[0].value.string;
+       if (strcmp ("libvirt", name) == 0)
+               name = "virt";
+
+       /* default to the global interval set before loading this plugin */
+       memset (&ctx, 0, sizeof (ctx));
+       ctx.interval = cf_get_default_interval ();
+
+       for (i = 0; i < ci->children_num; ++i) {
+               if (strcasecmp("Globals", ci->children[i].key) == 0)
+                       cf_util_get_flag (ci->children + i, &flags, PLUGIN_FLAGS_GLOBAL);
+               else if (strcasecmp ("Interval", ci->children[i].key) == 0) {
+                       if (cf_util_get_cdtime (ci->children + i, &ctx.interval) != 0) {
+                               /* cf_util_get_cdtime will log an error */
+                               continue;
+                       }
+               }
+               else {
+                       WARNING("Ignoring unknown LoadPlugin option \"%s\" "
+                                       "for plugin \"%s\"",
+                                       ci->children[i].key, ci->values[0].value.string);
+               }
+       }
+
+       old_ctx = plugin_set_ctx (ctx);
+       ret_val = plugin_load (name, (uint32_t) flags);
+       /* reset to the "global" context */
+       plugin_set_ctx (old_ctx);
+
+       return (ret_val);
+} /* int dispatch_value_loadplugin */
+
+static int dispatch_value_plugin (const char *plugin, oconfig_item_t *ci)
+{
+       char  buffer[4096];
+       char *buffer_ptr;
+       int   buffer_free;
+       int i;
+
+       buffer_ptr = buffer;
+       buffer_free = sizeof (buffer);
+
+       for (i = 0; i < ci->values_num; i++)
+       {
+               int status = -1;
+
+               if (ci->values[i].type == OCONFIG_TYPE_STRING)
+                       status = ssnprintf (buffer_ptr, buffer_free, " %s",
+                                       ci->values[i].value.string);
+               else if (ci->values[i].type == OCONFIG_TYPE_NUMBER)
+                       status = ssnprintf (buffer_ptr, buffer_free, " %lf",
+                                       ci->values[i].value.number);
+               else if (ci->values[i].type == OCONFIG_TYPE_BOOLEAN)
+                       status = ssnprintf (buffer_ptr, buffer_free, " %s",
+                                       ci->values[i].value.boolean
+                                       ? "true" : "false");
+
+               if ((status < 0) || (status >= buffer_free))
+                       return (-1);
+               buffer_free -= status;
+               buffer_ptr  += status;
+       }
+       /* skip the initial space */
+       buffer_ptr = buffer + 1;
+
+       return (cf_dispatch (plugin, ci->key, buffer_ptr));
+} /* int dispatch_value_plugin */
+
+static int dispatch_value (oconfig_item_t *ci)
+{
+       int ret = -2;
+       int i;
+
+       for (i = 0; i < cf_value_map_num; i++)
+               if (strcasecmp (cf_value_map[i].key, ci->key) == 0)
+               {
+                       ret = cf_value_map[i].func (ci);
+                       break;
+               }
+
+       for (i = 0; i < cf_global_options_num; i++)
+               if (strcasecmp (cf_global_options[i].key, ci->key) == 0)
+               {
+                       ret = dispatch_global_option (ci);
+                       break;
+               }
+
+       return (ret);
+} /* int dispatch_value */
+
+static int dispatch_block_plugin (oconfig_item_t *ci)
+{
+       int i;
+       char *name;
+
+       cf_complex_callback_t *cb;
+
+       if (strcasecmp (ci->key, "Plugin") != 0)
+               return (-1);
+       if (ci->values_num < 1)
+               return (-1);
+       if (ci->values[0].type != OCONFIG_TYPE_STRING)
+               return (-1);
+
+       name = ci->values[0].value.string;
+       if (strcmp ("libvirt", name) == 0)
+       {
+               /* TODO(octo): Remove this legacy. */
+               WARNING ("The \"libvirt\" plugin has been renamed to \"virt\" to avoid problems with the build system. "
+                               "Your configuration is still using the old name. "
+                               "Please change it to use \"virt\" as soon as possible. "
+                               "This compatibility code will go away eventually.");
+               name = "virt";
+       }
+
+       if (IS_TRUE (global_option_get ("AutoLoadPlugin")))
+       {
+               plugin_ctx_t ctx;
+               plugin_ctx_t old_ctx;
+               int status;
+
+               /* default to the global interval set before loading this plugin */
+               memset (&ctx, 0, sizeof (ctx));
+               ctx.interval = cf_get_default_interval ();
+
+               old_ctx = plugin_set_ctx (ctx);
+               status = plugin_load (name, /* flags = */ 0);
+               /* reset to the "global" context */
+               plugin_set_ctx (old_ctx);
+
+               if (status != 0)
+               {
+                       ERROR ("Automatically loading plugin \"%s\" failed "
+                                       "with status %i.", name, status);
+                       return (status);
+               }
+       }
+
+       /* Check for a complex callback first */
+       for (cb = complex_callback_head; cb != NULL; cb = cb->next)
+       {
+               if (strcasecmp (name, cb->type) == 0)
+               {
+                       plugin_ctx_t old_ctx;
+                       int ret_val;
+
+                       old_ctx = plugin_set_ctx (cb->ctx);
+                       ret_val = (cb->callback (ci));
+                       plugin_set_ctx (old_ctx);
+                       return (ret_val);
+               }
+       }
+
+       /* Hm, no complex plugin found. Dispatch the values one by one */
+       for (i = 0; i < ci->children_num; i++)
+       {
+               if (ci->children[i].children == NULL)
+                       dispatch_value_plugin (name, ci->children + i);
+               else
+               {
+                       WARNING ("There is a `%s' block within the "
+                                       "configuration for the %s plugin. "
+                                       "The plugin either only expects "
+                                       "\"simple\" configuration statements "
+                                       "or wasn't loaded using `LoadPlugin'."
+                                       " Please check your configuration.",
+                                       ci->children[i].key, name);
+               }
+       }
+
+       return (0);
+}
+
+
+static int dispatch_block (oconfig_item_t *ci)
+{
+       if (strcasecmp (ci->key, "LoadPlugin") == 0)
+               return (dispatch_loadplugin (ci));
+       else if (strcasecmp (ci->key, "Plugin") == 0)
+               return (dispatch_block_plugin (ci));
+       else if (strcasecmp (ci->key, "Chain") == 0)
+               return (fc_configure (ci));
+
+       return (0);
+}
+
+static int cf_ci_replace_child (oconfig_item_t *dst, oconfig_item_t *src,
+               int offset)
+{
+       oconfig_item_t *temp;
+       int i;
+
+       assert (offset >= 0);
+       assert (dst->children_num > offset);
+
+       /* Free the memory used by the replaced child. Usually that's the
+        * `Include "blah"' statement. */
+       temp = dst->children + offset;
+       for (i = 0; i < temp->values_num; i++)
+       {
+               if (temp->values[i].type == OCONFIG_TYPE_STRING)
+               {
+                       sfree (temp->values[i].value.string);
+               }
+       }
+       sfree (temp->values);
+       temp = NULL;
+
+       /* If (src->children_num == 0) the array size is decreased. If offset
+        * is _not_ the last element, (offset < (dst->children_num - 1)), then
+        * we need to move the trailing elements before resizing the array. */
+       if ((src->children_num == 0) && (offset < (dst->children_num - 1)))
+       {
+               int nmemb = dst->children_num - (offset + 1);
+               memmove (dst->children + offset, dst->children + offset + 1,
+                               sizeof (oconfig_item_t) * nmemb);
+       }
+
+       /* Resize the memory containing the children to be big enough to hold
+        * all children. */
+       if (dst->children_num + src->children_num - 1 == 0)
+       {
+               dst->children_num = 0;
+               return (0);
+       }
+
+       temp = (oconfig_item_t *) realloc (dst->children,
+                       sizeof (oconfig_item_t)
+                       * (dst->children_num + src->children_num - 1));
+       if (temp == NULL)
+       {
+               ERROR ("configfile: realloc failed.");
+               return (-1);
+       }
+       dst->children = temp;
+
+       /* If there are children behind the include statement, and they have
+        * not yet been moved because (src->children_num == 0), then move them
+        * to the end of the list, so that the new children have room before
+        * them. */
+       if ((src->children_num > 0)
+                       && ((dst->children_num - (offset + 1)) > 0))
+       {
+               int nmemb = dst->children_num - (offset + 1);
+               int old_offset = offset + 1;
+               int new_offset = offset + src->children_num;
+
+               memmove (dst->children + new_offset,
+                               dst->children + old_offset,
+                               sizeof (oconfig_item_t) * nmemb);
+       }
+
+       /* Last but not least: If there are new children, copy them to the
+        * memory reserved for them. */
+       if (src->children_num > 0)
+       {
+               memcpy (dst->children + offset,
+                               src->children,
+                               sizeof (oconfig_item_t) * src->children_num);
+       }
+
+       /* Update the number of children. */
+       dst->children_num += (src->children_num - 1);
+
+       return (0);
+} /* int cf_ci_replace_child */
+
+static int cf_ci_append_children (oconfig_item_t *dst, oconfig_item_t *src)
+{
+       oconfig_item_t *temp;
+
+       if ((src == NULL) || (src->children_num == 0))
+               return (0);
+
+       temp = (oconfig_item_t *) realloc (dst->children,
+                       sizeof (oconfig_item_t)
+                       * (dst->children_num + src->children_num));
+       if (temp == NULL)
+       {
+               ERROR ("configfile: realloc failed.");
+               return (-1);
+       }
+       dst->children = temp;
+
+       memcpy (dst->children + dst->children_num,
+                       src->children,
+                       sizeof (oconfig_item_t)
+                       * src->children_num);
+       dst->children_num += src->children_num;
+
+       return (0);
+} /* int cf_ci_append_children */
+
+#define CF_MAX_DEPTH 8
+static oconfig_item_t *cf_read_generic (const char *path,
+               const char *pattern, int depth);
+
+static int cf_include_all (oconfig_item_t *root, int depth)
+{
+       int i;
+
+       for (i = 0; i < root->children_num; i++)
+       {
+               oconfig_item_t *new;
+               oconfig_item_t *old;
+
+               char *pattern = NULL;
+
+               int j;
+
+               if (strcasecmp (root->children[i].key, "Include") != 0)
+                       continue;
+
+               old = root->children + i;
+
+               if ((old->values_num != 1)
+                               || (old->values[0].type != OCONFIG_TYPE_STRING))
+               {
+                       ERROR ("configfile: `Include' needs exactly one string argument.");
+                       continue;
+               }
+
+               for (j = 0; j < old->children_num; ++j)
+               {
+                       oconfig_item_t *child = old->children + j;
+
+                       if (strcasecmp (child->key, "Filter") == 0)
+                               cf_util_get_string (child, &pattern);
+                       else
+                               ERROR ("configfile: Option `%s' not allowed in <Include> block.",
+                                               child->key);
+               }
+
+               new = cf_read_generic (old->values[0].value.string, pattern, depth + 1);
+               sfree (pattern);
+
+               if (new == NULL)
+                       return (-1);
+
+               /* Now replace the i'th child in `root' with `new'. */
+               if (cf_ci_replace_child (root, new, i) < 0) {
+                       sfree (new->values);
+                       sfree (new);
+                       return (-1);
+               }
+
+               /* ... and go back to the new i'th child. */
+               --i;
+
+               sfree (new->values);
+               sfree (new);
+       } /* for (i = 0; i < root->children_num; i++) */
+
+       return (0);
+} /* int cf_include_all */
+
+static oconfig_item_t *cf_read_file (const char *file,
+               const char *pattern, int depth)
+{
+       oconfig_item_t *root;
+       int status;
+
+       assert (depth < CF_MAX_DEPTH);
+
+       if (pattern != NULL) {
+#if HAVE_FNMATCH_H && HAVE_LIBGEN_H
+               char *tmp = sstrdup (file);
+               char *filename = basename (tmp);
+
+               if ((filename != NULL) && (fnmatch (pattern, filename, 0) != 0)) {
+                       DEBUG ("configfile: Not including `%s' because it "
+                                       "does not match pattern `%s'.",
+                                       filename, pattern);
+                       free (tmp);
+                       return (NULL);
+               }
+
+               free (tmp);
+#else
+               ERROR ("configfile: Cannot apply pattern filter '%s' "
+                               "to file '%s': functions basename() and / or "
+                               "fnmatch() not available.", pattern, file);
+#endif /* HAVE_FNMATCH_H && HAVE_LIBGEN_H */
+       }
+
+       root = oconfig_parse_file (file);
+       if (root == NULL)
+       {
+               ERROR ("configfile: Cannot read file `%s'.", file);
+               return (NULL);
+       }
+
+       status = cf_include_all (root, depth);
+       if (status != 0)
+       {
+               oconfig_free (root);
+               return (NULL);
+       }
+
+       return (root);
+} /* oconfig_item_t *cf_read_file */
+
+static int cf_compare_string (const void *p1, const void *p2)
+{
+       return strcmp (*(const char **) p1, *(const char **) p2);
+}
+
+static oconfig_item_t *cf_read_dir (const char *dir,
+               const char *pattern, int depth)
+{
+       oconfig_item_t *root = NULL;
+       DIR *dh;
+       struct dirent *de;
+       char **filenames = NULL;
+       int filenames_num = 0;
+       int status;
+       int i;
+
+       assert (depth < CF_MAX_DEPTH);
+
+       dh = opendir (dir);
+       if (dh == NULL)
+       {
+               char errbuf[1024];
+               ERROR ("configfile: opendir failed: %s",
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
+               return (NULL);
+       }
+
+       root = (oconfig_item_t *) malloc (sizeof (oconfig_item_t));
+       if (root == NULL)
+       {
+               ERROR ("configfile: malloc failed.");
+               return (NULL);
+       }
+       memset (root, 0, sizeof (oconfig_item_t));
+
+       while ((de = readdir (dh)) != NULL)
+       {
+               char   name[1024];
+               char **tmp;
+
+               if ((de->d_name[0] == '.') || (de->d_name[0] == 0))
+                       continue;
+
+               status = ssnprintf (name, sizeof (name), "%s/%s",
+                               dir, de->d_name);
+               if ((status < 0) || ((size_t) status >= sizeof (name)))
+               {
+                       ERROR ("configfile: Not including `%s/%s' because its"
+                                       " name is too long.",
+                                       dir, de->d_name);
+                       for (i = 0; i < filenames_num; ++i)
+                               free (filenames[i]);
+                       free (filenames);
+                       free (root);
+                       return (NULL);
+               }
+
+               ++filenames_num;
+               tmp = (char **) realloc (filenames,
+                               filenames_num * sizeof (*filenames));
+               if (tmp == NULL) {
+                       ERROR ("configfile: realloc failed.");
+                       for (i = 0; i < filenames_num - 1; ++i)
+                               free (filenames[i]);
+                       free (filenames);
+                       free (root);
+                       return (NULL);
+               }
+               filenames = tmp;
+
+               filenames[filenames_num - 1] = sstrdup (name);
+       }
+
+       if (filenames == NULL)
+               return (root);
+
+       qsort ((void *) filenames, filenames_num, sizeof (*filenames),
+                       cf_compare_string);
+
+       for (i = 0; i < filenames_num; ++i)
+       {
+               oconfig_item_t *temp;
+               char *name = filenames[i];
+
+               temp = cf_read_generic (name, pattern, depth);
+               if (temp == NULL)
+               {
+                       /* An error should already have been reported. */
+                       sfree (name);
+                       continue;
+               }
+
+               cf_ci_append_children (root, temp);
+               sfree (temp->children);
+               sfree (temp);
+
+               free (name);
+       }
+
+       free(filenames);
+       return (root);
+} /* oconfig_item_t *cf_read_dir */
+
+/* 
+ * cf_read_generic
+ *
+ * Path is stat'ed and either cf_read_file or cf_read_dir is called
+ * accordingly.
+ *
+ * There are two versions of this function: If `wordexp' exists shell wildcards
+ * will be expanded and the function will include all matches found. If
+ * `wordexp' (or, more precisely, it's header file) is not available the
+ * simpler function is used which does not do any such expansion.
+ */
+#if HAVE_WORDEXP_H
+static oconfig_item_t *cf_read_generic (const char *path,
+               const char *pattern, int depth)
+{
+       oconfig_item_t *root = NULL;
+       int status;
+       const char *path_ptr;
+       wordexp_t we;
+       size_t i;
+
+       if (depth >= CF_MAX_DEPTH)
+       {
+               ERROR ("configfile: Not including `%s' because the maximum "
+                               "nesting depth has been reached.", path);
+               return (NULL);
+       }
+
+       status = wordexp (path, &we, WRDE_NOCMD);
+       if (status != 0)
+       {
+               ERROR ("configfile: wordexp (%s) failed.", path);
+               return (NULL);
+       }
+
+       root = (oconfig_item_t *) malloc (sizeof (oconfig_item_t));
+       if (root == NULL)
+       {
+               ERROR ("configfile: malloc failed.");
+               return (NULL);
+       }
+       memset (root, '\0', sizeof (oconfig_item_t));
+
+       /* wordexp() might return a sorted list already. That's not
+        * documented though, so let's make sure we get what we want. */
+       qsort ((void *) we.we_wordv, we.we_wordc, sizeof (*we.we_wordv),
+                       cf_compare_string);
+
+       for (i = 0; i < we.we_wordc; i++)
+       {
+               oconfig_item_t *temp;
+               struct stat statbuf;
+
+               path_ptr = we.we_wordv[i];
+
+               status = stat (path_ptr, &statbuf);
+               if (status != 0)
+               {
+                       char errbuf[1024];
+                       WARNING ("configfile: stat (%s) failed: %s",
+                                       path_ptr,
+                                       sstrerror (errno, errbuf, sizeof (errbuf)));
+                       continue;
+               }
+
+               if (S_ISREG (statbuf.st_mode))
+                       temp = cf_read_file (path_ptr, pattern, depth);
+               else if (S_ISDIR (statbuf.st_mode))
+                       temp = cf_read_dir (path_ptr, pattern, depth);
+               else
+               {
+                       WARNING ("configfile: %s is neither a file nor a "
+                                       "directory.", path);
+                       continue;
+               }
+
+               if (temp == NULL) {
+                       oconfig_free (root);
+                       return (NULL);
+               }
+
+               cf_ci_append_children (root, temp);
+               sfree (temp->children);
+               sfree (temp);
+       }
+
+       wordfree (&we);
+
+       return (root);
+} /* oconfig_item_t *cf_read_generic */
+/* #endif HAVE_WORDEXP_H */
+
+#else /* if !HAVE_WORDEXP_H */
+static oconfig_item_t *cf_read_generic (const char *path,
+               const char *pattern, int depth)
+{
+       struct stat statbuf;
+       int status;
+
+       if (depth >= CF_MAX_DEPTH)
+       {
+               ERROR ("configfile: Not including `%s' because the maximum "
+                               "nesting depth has been reached.", path);
+               return (NULL);
+       }
+
+       status = stat (path, &statbuf);
+       if (status != 0)
+       {
+               char errbuf[1024];
+               ERROR ("configfile: stat (%s) failed: %s",
+                               path,
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
+               return (NULL);
+       }
+
+       if (S_ISREG (statbuf.st_mode))
+               return (cf_read_file (path, pattern, depth));
+       else if (S_ISDIR (statbuf.st_mode))
+               return (cf_read_dir (path, pattern, depth));
+
+       ERROR ("configfile: %s is neither a file nor a directory.", path);
+       return (NULL);
+} /* oconfig_item_t *cf_read_generic */
+#endif /* !HAVE_WORDEXP_H */
+
+/* 
+ * Public functions
+ */
+int global_option_set (const char *option, const char *value)
+{
+       int i;
+
+       DEBUG ("option = %s; value = %s;", option, value);
+
+       for (i = 0; i < cf_global_options_num; i++)
+               if (strcasecmp (cf_global_options[i].key, option) == 0)
+                       break;
+
+       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)
+               cf_global_options[i].value = strdup (value);
+       else
+               cf_global_options[i].value = NULL;
+
+       return (0);
+}
+
+const char *global_option_get (const char *option)
+{
+       int i;
+
+       for (i = 0; i < cf_global_options_num; i++)
+               if (strcasecmp (cf_global_options[i].key, option) == 0)
+                       break;
+
+       if (i >= cf_global_options_num)
+               return (NULL);
+       
+       return ((cf_global_options[i].value != NULL)
+                       ? cf_global_options[i].value
+                       : cf_global_options[i].def);
+} /* char *global_option_get */
+
+long global_option_get_long (const char *option, long default_value)
+{
+       const char *str;
+       long value;
+
+       str = global_option_get (option);
+       if (NULL == str)
+               return (default_value);
+
+       errno = 0;
+       value = strtol (str, /* endptr = */ NULL, /* base = */ 0);
+       if (errno != 0)
+               return (default_value);
+
+       return (value);
+} /* char *global_option_get_long */
+
+cdtime_t global_option_get_time (const char *name, cdtime_t def) /* {{{ */
+{
+       char const *optstr;
+       char *endptr = NULL;
+       double v;
+
+       optstr = global_option_get (name);
+       if (optstr == NULL)
+               return (def);
+
+       errno = 0;
+       v = strtod (optstr, &endptr);
+       if ((endptr == NULL) || (*endptr != 0) || (errno != 0))
+               return (def);
+       else if (v <= 0.0)
+               return (def);
+
+       return (DOUBLE_TO_CDTIME_T (v));
+} /* }}} cdtime_t global_option_get_time */
+
+cdtime_t cf_get_default_interval (void)
+{
+       return (global_option_get_time ("Interval",
+                              DOUBLE_TO_CDTIME_T (COLLECTD_DEFAULT_INTERVAL)));
+}
+
+void cf_unregister (const char *type)
+{
+       cf_callback_t *this, *prev;
+
+       for (prev = NULL, this = first_callback;
+                       this != NULL;
+                       prev = this, this = this->next)
+               if (strcasecmp (this->type, type) == 0)
+               {
+                       if (prev == NULL)
+                               first_callback = this->next;
+                       else
+                               prev->next = this->next;
+
+                       free (this);
+                       break;
+               }
+} /* void cf_unregister */
+
+void cf_unregister_complex (const char *type)
+{
+       cf_complex_callback_t *this, *prev;
+
+       for (prev = NULL, this = complex_callback_head;
+                       this != NULL;
+                       prev = this, this = this->next)
+               if (strcasecmp (this->type, type) == 0)
+               {
+                       if (prev == NULL)
+                               complex_callback_head = this->next;
+                       else
+                               prev->next = this->next;
+
+                       sfree (this->type);
+                       sfree (this);
+                       break;
+               }
+} /* void cf_unregister */
+
+void cf_register (const char *type,
+               int (*callback) (const char *, const char *),
+               const char **keys, int keys_num)
+{
+       cf_callback_t *cf_cb;
+
+       /* Remove this module from the list, if it already exists */
+       cf_unregister (type);
+
+       /* This pointer will be free'd in `cf_unregister' */
+       if ((cf_cb = (cf_callback_t *) malloc (sizeof (cf_callback_t))) == NULL)
+               return;
+
+       cf_cb->type     = type;
+       cf_cb->callback = callback;
+       cf_cb->keys     = keys;
+       cf_cb->keys_num = keys_num;
+       cf_cb->ctx      = plugin_get_ctx ();
+
+       cf_cb->next = first_callback;
+       first_callback = cf_cb;
+} /* void cf_register */
+
+int cf_register_complex (const char *type, int (*callback) (oconfig_item_t *))
+{
+       cf_complex_callback_t *new;
+
+       new = (cf_complex_callback_t *) malloc (sizeof (cf_complex_callback_t));
+       if (new == NULL)
+               return (-1);
+
+       new->type = strdup (type);
+       if (new->type == NULL)
+       {
+               sfree (new);
+               return (-1);
+       }
+
+       new->callback = callback;
+       new->next = NULL;
+
+       new->ctx = plugin_get_ctx ();
+
+       if (complex_callback_head == NULL)
+       {
+               complex_callback_head = new;
+       }
+       else
+       {
+               cf_complex_callback_t *last = complex_callback_head;
+               while (last->next != NULL)
+                       last = last->next;
+               last->next = new;
+       }
+
+       return (0);
+} /* int cf_register_complex */
+
+int cf_read (char *filename)
+{
+       oconfig_item_t *conf;
+       int i;
+
+       conf = cf_read_generic (filename, /* pattern = */ NULL, /* depth = */ 0);
+       if (conf == NULL)
+       {
+               ERROR ("Unable to read config file %s.", filename);
+               return (-1);
+       }
+       else if (conf->children_num == 0)
+       {
+               ERROR ("Configuration file %s is empty.", filename);
+               oconfig_free (conf);
+               return (-1);
+       }
+
+       for (i = 0; i < conf->children_num; i++)
+       {
+               if (conf->children[i].children == NULL)
+                       dispatch_value (conf->children + i);
+               else
+                       dispatch_block (conf->children + i);
+       }
+
+       oconfig_free (conf);
+
+       /* Read the default types.db if no `TypesDB' option was given. */
+       if (cf_default_typesdb)
+               read_types_list (PKGDATADIR"/types.db");
+
+       return (0);
+} /* int cf_read */
+
+/* Assures the config option is a string, duplicates it and returns the copy in
+ * "ret_string". If necessary "*ret_string" is freed first. Returns zero upon
+ * success. */
+int cf_util_get_string (const oconfig_item_t *ci, char **ret_string) /* {{{ */
+{
+       char *string;
+
+       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
+       {
+               ERROR ("cf_util_get_string: The %s option requires "
+                               "exactly one string argument.", ci->key);
+               return (-1);
+       }
+
+       string = strdup (ci->values[0].value.string);
+       if (string == NULL)
+               return (-1);
+
+       if (*ret_string != NULL)
+               sfree (*ret_string);
+       *ret_string = string;
+
+       return (0);
+} /* }}} int cf_util_get_string */
+
+/* Assures the config option is a string and copies it to the provided buffer.
+ * Assures null-termination. */
+int cf_util_get_string_buffer (const oconfig_item_t *ci, char *buffer, /* {{{ */
+               size_t buffer_size)
+{
+       if ((ci == NULL) || (buffer == NULL) || (buffer_size < 1))
+               return (EINVAL);
+
+       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
+       {
+               ERROR ("cf_util_get_string_buffer: The %s option requires "
+                               "exactly one string argument.", ci->key);
+               return (-1);
+       }
+
+       strncpy (buffer, ci->values[0].value.string, buffer_size);
+       buffer[buffer_size - 1] = 0;
+
+       return (0);
+} /* }}} int cf_util_get_string_buffer */
+
+/* Assures the config option is a number and returns it as an int. */
+int cf_util_get_int (const oconfig_item_t *ci, int *ret_value) /* {{{ */
+{
+       if ((ci == NULL) || (ret_value == NULL))
+               return (EINVAL);
+
+       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
+       {
+               ERROR ("cf_util_get_int: The %s option requires "
+                               "exactly one numeric argument.", ci->key);
+               return (-1);
+       }
+
+       *ret_value = (int) ci->values[0].value.number;
+
+       return (0);
+} /* }}} int cf_util_get_int */
+
+int cf_util_get_double (const oconfig_item_t *ci, double *ret_value) /* {{{ */
+{
+       if ((ci == NULL) || (ret_value == NULL))
+               return (EINVAL);
+
+       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
+       {
+               ERROR ("cf_util_get_double: The %s option requires "
+                               "exactly one numeric argument.", ci->key);
+               return (-1);
+       }
+
+       *ret_value = ci->values[0].value.number;
+
+       return (0);
+} /* }}} int cf_util_get_double */
+
+int cf_util_get_boolean (const oconfig_item_t *ci, _Bool *ret_bool) /* {{{ */
+{
+       if ((ci == NULL) || (ret_bool == NULL))
+               return (EINVAL);
+
+       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
+       {
+               ERROR ("cf_util_get_boolean: The %s option requires "
+                               "exactly one boolean argument.", ci->key);
+               return (-1);
+       }
+
+       *ret_bool = ci->values[0].value.boolean ? 1 : 0;
+
+       return (0);
+} /* }}} int cf_util_get_boolean */
+
+int cf_util_get_flag (const oconfig_item_t *ci, /* {{{ */
+               unsigned int *ret_value, unsigned int flag)
+{
+       int status;
+       _Bool b;
+
+       if (ret_value == NULL)
+               return (EINVAL);
+
+       b = 0;
+       status = cf_util_get_boolean (ci, &b);
+       if (status != 0)
+               return (status);
+
+       if (b)
+       {
+               *ret_value |= flag;
+       }
+       else
+       {
+               *ret_value &= ~flag;
+       }
+
+       return (0);
+} /* }}} int cf_util_get_flag */
+
+/* Assures that the config option is a string or a number if the correct range
+ * of 1-65535. The string is then converted to a port number using
+ * `service_name_to_port_number' and returned.
+ * Returns the port number in the range [1-65535] or less than zero upon
+ * failure. */
+int cf_util_get_port_number (const oconfig_item_t *ci) /* {{{ */
+{
+       int tmp;
+
+       if ((ci->values_num != 1)
+                       || ((ci->values[0].type != OCONFIG_TYPE_STRING)
+                               && (ci->values[0].type != OCONFIG_TYPE_NUMBER)))
+       {
+               ERROR ("cf_util_get_port_number: The \"%s\" option requires "
+                               "exactly one string argument.", ci->key);
+               return (-1);
+       }
+
+       if (ci->values[0].type == OCONFIG_TYPE_STRING)
+               return (service_name_to_port_number (ci->values[0].value.string));
+
+       assert (ci->values[0].type == OCONFIG_TYPE_NUMBER);
+       tmp = (int) (ci->values[0].value.number + 0.5);
+       if ((tmp < 1) || (tmp > 65535))
+       {
+               ERROR ("cf_util_get_port_number: The \"%s\" option requires "
+                               "a service name or a port number. The number "
+                               "you specified, %i, is not in the valid "
+                               "range of 1-65535.",
+                               ci->key, tmp);
+               return (-1);
+       }
+
+       return (tmp);
+} /* }}} int cf_util_get_port_number */
+
+int cf_util_get_service (const oconfig_item_t *ci, char **ret_string) /* {{{ */
+{
+       int port;
+       char *service;
+       int status;
+
+       if (ci->values_num != 1)
+       {
+               ERROR ("cf_util_get_service: The %s option requires exactly "
+                               "one argument.", ci->key);
+               return (-1);
+       }
+
+       if (ci->values[0].type == OCONFIG_TYPE_STRING)
+               return (cf_util_get_string (ci, ret_string));
+       if (ci->values[0].type != OCONFIG_TYPE_NUMBER)
+       {
+               ERROR ("cf_util_get_service: The %s option requires "
+                               "exactly one string or numeric argument.",
+                               ci->key);
+       }
+
+       port = 0;
+       status = cf_util_get_int (ci, &port);
+       if (status != 0)
+               return (status);
+       else if ((port < 1) || (port > 65535))
+       {
+               ERROR ("cf_util_get_service: The port number given "
+                               "for the %s option is out of "
+                               "range (%i).", ci->key, port);
+               return (-1);
+       }
+
+       service = malloc (6);
+       if (service == NULL)
+       {
+               ERROR ("cf_util_get_service: Out of memory.");
+               return (-1);
+       }
+       ssnprintf (service, 6, "%i", port);
+
+       sfree (*ret_string);
+       *ret_string = service;
+
+       return (0);
+} /* }}} int cf_util_get_service */
+
+int cf_util_get_cdtime (const oconfig_item_t *ci, cdtime_t *ret_value) /* {{{ */
+{
+       if ((ci == NULL) || (ret_value == NULL))
+               return (EINVAL);
+
+       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
+       {
+               ERROR ("cf_util_get_cdtime: The %s option requires "
+                               "exactly one numeric argument.", ci->key);
+               return (-1);
+       }
+
+       if (ci->values[0].value.number < 0.0)
+       {
+               ERROR ("cf_util_get_cdtime: The numeric argument of the %s "
+                               "option must not be negative.", ci->key);
+               return (-1);
+       }
+
+       *ret_value = DOUBLE_TO_CDTIME_T (ci->values[0].value.number);
+
+       return (0);
+} /* }}} int cf_util_get_cdtime */
+
diff --git a/src/daemon/configfile.h b/src/daemon/configfile.h
new file mode 100644 (file)
index 0000000..5bc9b30
--- /dev/null
@@ -0,0 +1,141 @@
+/**
+ * collectd - src/configfile.h
+ * Copyright (C) 2005-2011  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>
+ **/
+
+#ifndef CONFIGFILE_H
+#define CONFIGFILE_H
+
+#include "collectd.h"
+#include "utils_time.h"
+#include "liboconfig/oconfig.h"
+
+/*
+ * DESCRIPTION
+ *  Remove a registered plugin from the internal data structures.
+ * 
+ * PARAMETERS
+ *  `type'      Name of the plugin (must be the same as passed to
+ *              `plugin_register'
+ */
+void cf_unregister (const char *type);
+void cf_unregister_complex (const char *type);
+
+/*
+ * DESCRIPTION
+ *  `cf_register' is called by plugins that wish to receive config keys. The
+ *  plugin will then receive all keys it registered for if they're found in a
+ *  `<Plugin $type>' section.
+ *
+ * PARAMETERS
+ *  `type'      Name of the plugin (must be the same as passed to
+ *              `plugin_register'
+ *  `callback'  Pointer to the callback function. The callback must return zero
+ *              upon success, a value smaller than zero if it doesn't know how
+ *              to handle the `key' passed to it (the first argument) or a
+ *              value greater than zero if it knows how to handle the key but
+ *              failed.
+ *  `keys'      Array of key values this plugin wished to receive. The last
+ *              element must be a NULL-pointer.
+ *  `keys_num'  Number of elements in the array (not counting the last NULL-
+ *              pointer.
+ *
+ * NOTES
+ *  `cf_unregister' will be called for `type' to make sure only one record
+ *  exists for each `type' at any time. This means that `cf_register' may be
+ *  called multiple times, but only the last call will have an effect.
+ */
+void cf_register (const char *type,
+               int (*callback) (const char *, const char *),
+               const char **keys, int keys_num);
+
+int cf_register_complex (const char *type, int (*callback) (oconfig_item_t *));
+
+/*
+ * DESCRIPTION
+ *  `cf_read' reads the config file `filename' and dispatches the read
+ *  information to functions/variables. Most important: Is calls `plugin_load'
+ *  to load specific plugins, depending on the current mode of operation.
+ *
+ * PARAMETERS
+ *  `filename'  An additional filename to look for. This function calls
+ *              `lc_process' which already searches many standard locations..
+ *              If set to NULL will use the `CONFIGFILE' define.
+ *
+ * RETURN VALUE
+ *  Returns zero upon success and non-zero otherwise. A error-message will have
+ *  been printed in this case.
+ */
+int cf_read (char *filename);
+
+int global_option_set (const char *option, const char *value);
+const char *global_option_get (const char *option);
+long global_option_get_long (const char *option, long default_value);
+long global_option_get_long_in_range (const char *option, long default_value, long min, long max);
+
+cdtime_t global_option_get_time (char const *option, cdtime_t default_value);
+
+cdtime_t cf_get_default_interval (void);
+
+/* Assures the config option is a string, duplicates it and returns the copy in
+ * "ret_string". If necessary "*ret_string" is freed first. Returns zero upon
+ * success. */
+int cf_util_get_string (const oconfig_item_t *ci, char **ret_string);
+
+/* Assures the config option is a string and copies it to the provided buffer.
+ * Assures null-termination. */
+int cf_util_get_string_buffer (const oconfig_item_t *ci, char *buffer,
+               size_t buffer_size);
+
+/* Assures the config option is a number and returns it as an int. */
+int cf_util_get_int (const oconfig_item_t *ci, int *ret_value);
+
+/* Assures the config option is a number and returns it as a double. */
+int cf_util_get_double (const oconfig_item_t *ci, double *ret_value);
+
+/* Assures the config option is a boolean and assignes it to `ret_bool'.
+ * Otherwise, `ret_bool' is not changed and non-zero is returned. */
+int cf_util_get_boolean (const oconfig_item_t *ci, _Bool *ret_bool);
+
+/* Assures the config option is a boolean and set or unset the given flag in
+ * `ret_value' as appropriate. Returns non-zero on error. */
+int cf_util_get_flag (const oconfig_item_t *ci,
+               unsigned int *ret_value, unsigned int flag);
+
+/* Assures that the config option is a string or a number if the correct range
+ * of 1-65535. The string is then converted to a port number using
+ * `service_name_to_port_number' and returned.
+ * Returns the port number in the range [1-65535] or less than zero upon
+ * failure. */
+int cf_util_get_port_number (const oconfig_item_t *ci);
+
+/* Assures that the config option is either a service name (a string) or a port
+ * number (an integer in the appropriate range) and returns a newly allocated
+ * string. If ret_string points to a non-NULL pointer, it is freed before
+ * assigning a new value. */
+int cf_util_get_service (const oconfig_item_t *ci, char **ret_string);
+
+int cf_util_get_cdtime (const oconfig_item_t *ci, cdtime_t *ret_value);
+
+#endif /* defined(CONFIGFILE_H) */
diff --git a/src/daemon/filter_chain.c b/src/daemon/filter_chain.c
new file mode 100644 (file)
index 0000000..5042913
--- /dev/null
@@ -0,0 +1,1081 @@
+/**
+ * collectd - src/filter_chain.c
+ * Copyright (C) 2008-2010  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 "configfile.h"
+#include "plugin.h"
+#include "utils_complain.h"
+#include "common.h"
+#include "filter_chain.h"
+
+/*
+ * Data types
+ */
+/* List of matches, used in fc_rule_t and for the global `match_list_head'
+ * variable. */
+struct fc_match_s;
+typedef struct fc_match_s fc_match_t; /* {{{ */
+struct fc_match_s
+{
+  char name[DATA_MAX_NAME_LEN];
+  match_proc_t proc;
+  void *user_data;
+  fc_match_t *next;
+}; /* }}} */
+
+/* List of targets, used in fc_rule_t and for the global `target_list_head'
+ * variable. */
+struct fc_target_s;
+typedef struct fc_target_s fc_target_t; /* {{{ */
+struct fc_target_s
+{
+  char name[DATA_MAX_NAME_LEN];
+  void *user_data;
+  target_proc_t proc;
+  fc_target_t *next;
+}; /* }}} */
+
+/* List of rules, used in fc_chain_t */
+struct fc_rule_s;
+typedef struct fc_rule_s fc_rule_t; /* {{{ */
+struct fc_rule_s
+{
+  char name[DATA_MAX_NAME_LEN];
+  fc_match_t  *matches;
+  fc_target_t *targets;
+  fc_rule_t *next;
+}; /* }}} */
+
+/* List of chains, used for `chain_list_head' */
+struct fc_chain_s /* {{{ */
+{
+  char name[DATA_MAX_NAME_LEN];
+  fc_rule_t   *rules;
+  fc_target_t *targets;
+  fc_chain_t  *next;
+}; /* }}} */
+
+/* Writer configuration. */
+struct fc_writer_s;
+typedef struct fc_writer_s fc_writer_t; /* {{{ */
+struct fc_writer_s
+{
+  char *plugin;
+  c_complain_t complaint;
+}; /* }}} */
+
+/*
+ * Global variables
+ */
+static fc_match_t  *match_list_head;
+static fc_target_t *target_list_head;
+static fc_chain_t  *chain_list_head;
+
+/*
+ * Private functions
+ */
+static void fc_free_matches (fc_match_t *m) /* {{{ */
+{
+  if (m == NULL)
+    return;
+
+  if (m->proc.destroy != NULL)
+    (*m->proc.destroy) (&m->user_data);
+  else if (m->user_data != NULL)
+  {
+    ERROR ("Filter subsystem: fc_free_matches: There is user data, but no "
+        "destroy functions has been specified. "
+        "Memory will probably be lost!");
+  }
+
+  if (m->next != NULL)
+    fc_free_matches (m->next);
+
+  free (m);
+} /* }}} void fc_free_matches */
+
+static void fc_free_targets (fc_target_t *t) /* {{{ */
+{
+  if (t == NULL)
+    return;
+
+  if (t->proc.destroy != NULL)
+    (*t->proc.destroy) (&t->user_data);
+  else if (t->user_data != NULL)
+  {
+    ERROR ("Filter subsystem: fc_free_targets: There is user data, but no "
+        "destroy functions has been specified. "
+        "Memory will probably be lost!");
+  }
+
+  if (t->next != NULL)
+    fc_free_targets (t->next);
+
+  free (t);
+} /* }}} void fc_free_targets */
+
+static void fc_free_rules (fc_rule_t *r) /* {{{ */
+{
+  if (r == NULL)
+    return;
+
+  fc_free_matches (r->matches);
+  fc_free_targets (r->targets);
+
+  if (r->next != NULL)
+    fc_free_rules (r->next);
+
+  free (r);
+} /* }}} void fc_free_rules */
+
+static void fc_free_chains (fc_chain_t *c) /* {{{ */
+{
+  if (c == NULL)
+    return;
+
+  fc_free_rules (c->rules);
+  fc_free_targets (c->targets);
+
+  if (c->next != NULL)
+    fc_free_chains (c->next);
+
+  free (c);
+} /* }}} void fc_free_chains */
+
+static char *fc_strdup (const char *orig) /* {{{ */
+{
+  size_t sz;
+  char *dest;
+
+  if (orig == NULL)
+    return (NULL);
+
+  sz = strlen (orig) + 1;
+  dest = (char *) malloc (sz);
+  if (dest == NULL)
+    return (NULL);
+
+  memcpy (dest, orig, sz);
+
+  return (dest);
+} /* }}} char *fc_strdup */
+
+/*
+ * Configuration.
+ *
+ * The configuration looks somewhat like this:
+ *
+ *  <Chain "PreCache">
+ *    <Rule>
+ *      <Match "regex">
+ *        Plugin "^mysql$"
+ *        Type "^mysql_command$"
+ *        TypeInstance "^show_"
+ *      </Match>
+ *      <Target "drop">
+ *      </Target>
+ *    </Rule>
+ *
+ *    <Target "write">
+ *      Plugin "rrdtool"
+ *    </Target>
+ *  </Chain>
+ */
+static int fc_config_add_match (fc_match_t **matches_head, /* {{{ */
+    oconfig_item_t *ci)
+{
+  fc_match_t *m;
+  fc_match_t *ptr;
+  int status;
+
+  if ((ci->values_num != 1)
+      || (ci->values[0].type != OCONFIG_TYPE_STRING))
+  {
+    WARNING ("Filter subsystem: `Match' blocks require "
+        "exactly one string argument.");
+    return (-1);
+  }
+
+  ptr = match_list_head;
+  while (ptr != NULL)
+  {
+    if (strcasecmp (ptr->name, ci->values[0].value.string) == 0)
+      break;
+    ptr = ptr->next;
+  }
+
+  if (ptr == NULL)
+  {
+    WARNING ("Filter subsystem: Cannot find a \"%s\" match. "
+        "Did you load the appropriate plugin?",
+        ci->values[0].value.string);
+    return (-1);
+  }
+
+  m = (fc_match_t *) malloc (sizeof (*m));
+  if (m == NULL)
+  {
+    ERROR ("fc_config_add_match: malloc failed.");
+    return (-1);
+  }
+  memset (m, 0, sizeof (*m));
+
+  sstrncpy (m->name, ptr->name, sizeof (m->name));
+  memcpy (&m->proc, &ptr->proc, sizeof (m->proc));
+  m->user_data = NULL;
+  m->next = NULL;
+
+  if (m->proc.create != NULL)
+  {
+    status = (*m->proc.create) (ci, &m->user_data);
+    if (status != 0)
+    {
+      WARNING ("Filter subsystem: Failed to create a %s match.",
+          m->name);
+      fc_free_matches (m);
+      return (-1);
+    }
+  }
+
+  if (*matches_head != NULL)
+  {
+    ptr = *matches_head;
+    while (ptr->next != NULL)
+      ptr = ptr->next;
+
+    ptr->next = m;
+  }
+  else
+  {
+    *matches_head = m;
+  }
+
+  return (0);
+} /* }}} int fc_config_add_match */
+
+static int fc_config_add_target (fc_target_t **targets_head, /* {{{ */
+    oconfig_item_t *ci)
+{
+  fc_target_t *t;
+  fc_target_t *ptr;
+  int status;
+
+  if ((ci->values_num != 1)
+      || (ci->values[0].type != OCONFIG_TYPE_STRING))
+  {
+    WARNING ("Filter subsystem: `Target' blocks require "
+        "exactly one string argument.");
+    return (-1);
+  }
+
+  ptr = target_list_head;
+  while (ptr != NULL)
+  {
+    if (strcasecmp (ptr->name, ci->values[0].value.string) == 0)
+      break;
+    ptr = ptr->next;
+  }
+
+  if (ptr == NULL)
+  {
+    WARNING ("Filter subsystem: Cannot find a \"%s\" target. "
+        "Did you load the appropriate plugin?",
+        ci->values[0].value.string);
+    return (-1);
+  }
+
+  t = (fc_target_t *) malloc (sizeof (*t));
+  if (t == NULL)
+  {
+    ERROR ("fc_config_add_target: malloc failed.");
+    return (-1);
+  }
+  memset (t, 0, sizeof (*t));
+
+  sstrncpy (t->name, ptr->name, sizeof (t->name));
+  memcpy (&t->proc, &ptr->proc, sizeof (t->proc));
+  t->user_data = NULL;
+  t->next = NULL;
+
+  if (t->proc.create != NULL)
+  {
+    status = (*t->proc.create) (ci, &t->user_data);
+    if (status != 0)
+    {
+      WARNING ("Filter subsystem: Failed to create a %s target.",
+          t->name);
+      fc_free_targets (t);
+      return (-1);
+    }
+  }
+  else
+  {
+    t->user_data = NULL;
+  }
+  
+  if (*targets_head != NULL)
+  {
+    ptr = *targets_head;
+    while (ptr->next != NULL)
+      ptr = ptr->next;
+
+    ptr->next = t;
+  }
+  else
+  {
+    *targets_head = t;
+  }
+
+  return (0);
+} /* }}} int fc_config_add_target */
+
+static int fc_config_add_rule (fc_chain_t *chain, /* {{{ */
+    oconfig_item_t *ci)
+{
+  fc_rule_t *rule;
+  char rule_name[2*DATA_MAX_NAME_LEN] = "Unnamed rule";
+  int status = 0;
+  int i;
+
+  if (ci->values_num > 1)
+  {
+    WARNING ("Filter subsystem: `Rule' blocks have at most one argument.");
+    return (-1);
+  }
+  else if ((ci->values_num == 1)
+      && (ci->values[0].type != OCONFIG_TYPE_STRING))
+  {
+    WARNING ("Filter subsystem: `Rule' blocks expect one string argument "
+        "or no argument at all.");
+    return (-1);
+  }
+
+  rule = (fc_rule_t *) malloc (sizeof (*rule));
+  if (rule == NULL)
+  {
+    ERROR ("fc_config_add_rule: malloc failed.");
+    return (-1);
+  }
+  memset (rule, 0, sizeof (*rule));
+  rule->next = NULL;
+
+  if (ci->values_num == 1)
+  {
+    sstrncpy (rule->name, ci->values[0].value.string, sizeof (rule->name));
+    ssnprintf (rule_name, sizeof (rule_name), "Rule \"%s\"",
+        ci->values[0].value.string);
+  }
+
+  for (i = 0; i < ci->children_num; i++)
+  {
+    oconfig_item_t *option = ci->children + i;
+
+    if (strcasecmp ("Match", option->key) == 0)
+      status = fc_config_add_match (&rule->matches, option);
+    else if (strcasecmp ("Target", option->key) == 0)
+      status = fc_config_add_target (&rule->targets, option);
+    else
+    {
+      WARNING ("Filter subsystem: %s: Option `%s' not allowed "
+          "inside a <Rule> block.", rule_name, option->key);
+      status = -1;
+    }
+
+    if (status != 0)
+      break;
+  } /* for (ci->children) */
+
+  /* Additional sanity checking. */
+  while (status == 0)
+  {
+    if (rule->targets == NULL)
+    {
+      WARNING ("Filter subsystem: %s: No target has been specified.",
+          rule_name);
+      status = -1;
+      break;
+    }
+
+    break;
+  } /* while (status == 0) */
+
+  if (status != 0)
+  {
+    fc_free_rules (rule);
+    return (-1);
+  }
+
+  if (chain->rules != NULL)
+  {
+    fc_rule_t *ptr;
+
+    ptr = chain->rules;
+    while (ptr->next != NULL)
+      ptr = ptr->next;
+
+    ptr->next = rule;
+  }
+  else
+  {
+    chain->rules = rule;
+  }
+
+  return (0);
+} /* }}} int fc_config_add_rule */
+
+static int fc_config_add_chain (const oconfig_item_t *ci) /* {{{ */
+{
+  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))
+  {
+    WARNING ("Filter subsystem: <Chain> blocks require exactly one "
+        "string argument.");
+    return (-1);
+  }
+
+  if (chain_list_head != NULL)
+  {
+    if ((chain = fc_chain_get_by_name (ci->values[0].value.string)) != NULL)
+      new_chain = 0;
+  }
+
+  if (chain == NULL)
+  {
+    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;
+  }
+
+  for (i = 0; i < ci->children_num; i++)
+  {
+    oconfig_item_t *option = ci->children + i;
+
+    if (strcasecmp ("Rule", option->key) == 0)
+      status = fc_config_add_rule (chain, option);
+    else if (strcasecmp ("Target", option->key) == 0)
+      status = fc_config_add_target (&chain->targets, option);
+    else
+    {
+      WARNING ("Filter subsystem: Chain %s: Option `%s' not allowed "
+          "inside a <Chain> block.", chain->name, option->key);
+      status = -1;
+    }
+
+    if (status != 0)
+      break;
+  } /* for (ci->children) */
+
+  if (status != 0)
+  {
+    fc_free_chains (chain);
+    return (-1);
+  }
+
+  if (chain_list_head != NULL)
+  {
+    if (!new_chain)
+      return (0);
+
+    fc_chain_t *ptr;
+
+    ptr = chain_list_head;
+    while (ptr->next != NULL)
+      ptr = ptr->next;
+
+    ptr->next = chain;
+  }
+  else
+  {
+    chain_list_head = chain;
+  }
+
+  return (0);
+} /* }}} int fc_config_add_chain */
+
+/*
+ * Built-in target "jump"
+ *
+ * Prefix `bit' like `_b_uilt-_i_n _t_arget'
+ */
+static int fc_bit_jump_create (const oconfig_item_t *ci, /* {{{ */
+    void **user_data)
+{
+  oconfig_item_t *ci_chain;
+
+  if (ci->children_num != 1)
+  {
+    ERROR ("Filter subsystem: The built-in target `jump' needs exactly "
+        "one `Chain' argument!");
+    return (-1);
+  }
+
+  ci_chain = ci->children;
+  if (strcasecmp ("Chain", ci_chain->key) != 0)
+  {
+    ERROR ("Filter subsystem: The built-in target `jump' does not "
+        "support the configuration option `%s'.",
+        ci_chain->key);
+    return (-1);
+  }
+
+  if ((ci_chain->values_num != 1)
+      || (ci_chain->values[0].type != OCONFIG_TYPE_STRING))
+  {
+    ERROR ("Filter subsystem: Built-in target `jump': The `Chain' option "
+        "needs exactly one string argument.");
+    return (-1);
+  }
+
+  *user_data = fc_strdup (ci_chain->values[0].value.string);
+  if (*user_data == NULL)
+  {
+    ERROR ("fc_bit_jump_create: fc_strdup failed.");
+    return (-1);
+  }
+
+  return (0);
+} /* }}} int fc_bit_jump_create */
+
+static int fc_bit_jump_destroy (void **user_data) /* {{{ */
+{
+  if (user_data != NULL)
+  {
+    free (*user_data);
+    *user_data = NULL;
+  }
+
+  return (0);
+} /* }}} int fc_bit_jump_destroy */
+
+static int fc_bit_jump_invoke (const data_set_t *ds, /* {{{ */
+    value_list_t *vl, notification_meta_t __attribute__((unused)) **meta,
+    void **user_data)
+{
+  char *chain_name;
+  fc_chain_t *chain;
+  int status;
+
+  chain_name = *user_data;
+
+  for (chain = chain_list_head; chain != NULL; chain = chain->next)
+    if (strcasecmp (chain_name, chain->name) == 0)
+      break;
+
+  if (chain == NULL)
+  {
+    ERROR ("Filter subsystem: Built-in target `jump': There is no chain "
+        "named `%s'.", chain_name);
+    return (-1);
+  }
+
+  status = fc_process_chain (ds, vl, chain);
+  if (status < 0)
+    return (status);
+  else if (status == FC_TARGET_STOP)
+    return (FC_TARGET_STOP);
+  else
+    return (FC_TARGET_CONTINUE);
+} /* }}} int fc_bit_jump_invoke */
+
+static int fc_bit_stop_invoke (const data_set_t __attribute__((unused)) *ds, /* {{{ */
+    value_list_t __attribute__((unused)) *vl,
+    notification_meta_t __attribute__((unused)) **meta,
+    void __attribute__((unused)) **user_data)
+{
+  return (FC_TARGET_STOP);
+} /* }}} int fc_bit_stop_invoke */
+
+static int fc_bit_return_invoke (const data_set_t __attribute__((unused)) *ds, /* {{{ */
+    value_list_t __attribute__((unused)) *vl,
+    notification_meta_t __attribute__((unused)) **meta,
+    void __attribute__((unused)) **user_data)
+{
+  return (FC_TARGET_RETURN);
+} /* }}} int fc_bit_return_invoke */
+
+static int fc_bit_write_create (const oconfig_item_t *ci, /* {{{ */
+    void **user_data)
+{
+  int i;
+
+  fc_writer_t *plugin_list = NULL;
+  size_t plugin_list_len = 0;
+
+  for (i = 0; i < ci->children_num; i++)
+  {
+    oconfig_item_t *child = ci->children + i;
+    fc_writer_t *temp;
+    int j;
+
+    if (strcasecmp ("Plugin", child->key) != 0)
+    {
+      ERROR ("Filter subsystem: The built-in target `write' does not "
+          "support the configuration option `%s'.",
+          child->key);
+      continue;
+    }
+
+    for (j = 0; j < child->values_num; j++)
+    {
+      char *plugin;
+
+      if (child->values[j].type != OCONFIG_TYPE_STRING)
+      {
+        ERROR ("Filter subsystem: Built-in target `write': "
+            "The `Plugin' option accepts only string arguments.");
+        continue;
+      }
+      plugin = child->values[j].value.string;
+
+      temp = (fc_writer_t *) realloc (plugin_list, (plugin_list_len + 2)
+          * (sizeof (*plugin_list)));
+      if (temp == NULL)
+      {
+        ERROR ("fc_bit_write_create: realloc failed.");
+        continue;
+      }
+      plugin_list = temp;
+
+      plugin_list[plugin_list_len].plugin = fc_strdup (plugin);
+      if (plugin_list[plugin_list_len].plugin == NULL)
+      {
+        ERROR ("fc_bit_write_create: fc_strdup failed.");
+        continue;
+      }
+      C_COMPLAIN_INIT (&plugin_list[plugin_list_len].complaint);
+      plugin_list_len++;
+      plugin_list[plugin_list_len].plugin = NULL;
+    } /* for (j = 0; j < child->values_num; j++) */
+  } /* for (i = 0; i < ci->children_num; i++) */
+
+  *user_data = plugin_list;
+
+  return (0);
+} /* }}} int fc_bit_write_create */
+
+static int fc_bit_write_destroy (void **user_data) /* {{{ */
+{
+  fc_writer_t *plugin_list;
+  size_t i;
+
+  if ((user_data == NULL) || (*user_data == NULL))
+    return (0);
+
+  plugin_list = *user_data;
+
+  for (i = 0; plugin_list[i].plugin != NULL; i++)
+    free (plugin_list[i].plugin);
+  free (plugin_list);
+
+  return (0);
+} /* }}} int fc_bit_write_destroy */
+
+static int fc_bit_write_invoke (const data_set_t *ds, /* {{{ */
+    value_list_t *vl, notification_meta_t __attribute__((unused)) **meta,
+    void **user_data)
+{
+  fc_writer_t *plugin_list;
+  int status;
+
+  plugin_list = NULL;
+  if (user_data != NULL)
+    plugin_list = *user_data;
+
+  if ((plugin_list == NULL) || (plugin_list[0].plugin == NULL))
+  {
+    static c_complain_t write_complaint = C_COMPLAIN_INIT_STATIC;
+
+    status = plugin_write (/* plugin = */ NULL, ds, vl);
+    if (status == ENOENT)
+    {
+      /* in most cases this is a permanent error, so use the complain
+       * mechanism rather than spamming the logs */
+      c_complain (LOG_INFO, &write_complaint,
+          "Filter subsystem: Built-in target `write': Dispatching value to "
+          "all write plugins failed with status %i (ENOENT). "
+          "Most likely this means you didn't load any write plugins.",
+          status);
+
+      plugin_log_available_writers ();
+    }
+    else if (status != 0)
+    {
+      /* often, this is a permanent error (e.g. target system unavailable),
+       * so use the complain mechanism rather than spamming the logs */
+      c_complain (LOG_INFO, &write_complaint,
+          "Filter subsystem: Built-in target `write': Dispatching value to "
+          "all write plugins failed with status %i.", status);
+    }
+    else
+    {
+      assert (status == 0);
+      c_release (LOG_INFO, &write_complaint, "Filter subsystem: "
+          "Built-in target `write': Some write plugin is back to normal "
+          "operation. `write' succeeded.");
+    }
+  }
+  else
+  {
+    size_t i;
+
+    for (i = 0; plugin_list[i].plugin != NULL; i++)
+    {
+      status = plugin_write (plugin_list[i].plugin, ds, vl);
+      if (status != 0)
+      {
+        c_complain (LOG_INFO, &plugin_list[i].complaint,
+            "Filter subsystem: Built-in target `write': Dispatching value to "
+            "the `%s' plugin failed with status %i.",
+            plugin_list[i].plugin, status);
+
+        plugin_log_available_writers ();
+      }
+      else
+      {
+        c_release (LOG_INFO, &plugin_list[i].complaint,
+            "Filter subsystem: Built-in target `write': Plugin `%s' is back "
+            "to normal operation. `write' succeeded.", plugin_list[i].plugin);
+      }
+    } /* for (i = 0; plugin_list[i] != NULL; i++) */
+  }
+
+  return (FC_TARGET_CONTINUE);
+} /* }}} int fc_bit_write_invoke */
+
+static int fc_init_once (void) /* {{{ */
+{
+  static int done = 0;
+  target_proc_t tproc;
+
+  if (done != 0)
+    return (0);
+
+  memset (&tproc, 0, sizeof (tproc));
+  tproc.create  = fc_bit_jump_create;
+  tproc.destroy = fc_bit_jump_destroy;
+  tproc.invoke  = fc_bit_jump_invoke;
+  fc_register_target ("jump", tproc);
+
+  memset (&tproc, 0, sizeof (tproc));
+  tproc.create  = NULL;
+  tproc.destroy = NULL;
+  tproc.invoke  = fc_bit_stop_invoke;
+  fc_register_target ("stop", tproc);
+
+  memset (&tproc, 0, sizeof (tproc));
+  tproc.create  = NULL;
+  tproc.destroy = NULL;
+  tproc.invoke  = fc_bit_return_invoke;
+  fc_register_target ("return", tproc);
+
+  memset (&tproc, 0, sizeof (tproc));
+  tproc.create  = fc_bit_write_create;
+  tproc.destroy = fc_bit_write_destroy;
+  tproc.invoke  = fc_bit_write_invoke;
+  fc_register_target ("write", tproc);
+
+  done++;
+  return (0);
+} /* }}} int fc_init_once */
+
+/*
+ * Public functions
+ */
+/* Add a match to list of available matches. */
+int fc_register_match (const char *name, match_proc_t proc) /* {{{ */
+{
+  fc_match_t *m;
+
+  DEBUG ("fc_register_match (%s);", name);
+
+  m = (fc_match_t *) malloc (sizeof (*m));
+  if (m == NULL)
+    return (-ENOMEM);
+  memset (m, 0, sizeof (*m));
+
+  sstrncpy (m->name, name, sizeof (m->name));
+  memcpy (&m->proc, &proc, sizeof (m->proc));
+  m->next = NULL;
+
+  if (match_list_head == NULL)
+  {
+    match_list_head = m;
+  }
+  else
+  {
+    fc_match_t *ptr;
+
+    ptr = match_list_head;
+    while (ptr->next != NULL)
+      ptr = ptr->next;
+
+    ptr->next = m;
+  }
+
+  return (0);
+} /* }}} int fc_register_match */
+
+/* Add a target to list of available targets. */
+int fc_register_target (const char *name, target_proc_t proc) /* {{{ */
+{
+  fc_target_t *t;
+
+  DEBUG ("fc_register_target (%s);", name);
+
+  t = (fc_target_t *) malloc (sizeof (*t));
+  if (t == NULL)
+    return (-ENOMEM);
+  memset (t, 0, sizeof (*t));
+
+  sstrncpy (t->name, name, sizeof (t->name));
+  memcpy (&t->proc, &proc, sizeof (t->proc));
+  t->next = NULL;
+
+  if (target_list_head == NULL)
+  {
+    target_list_head = t;
+  }
+  else
+  {
+    fc_target_t *ptr;
+
+    ptr = target_list_head;
+    while (ptr->next != NULL)
+      ptr = ptr->next;
+
+    ptr->next = t;
+  }
+
+  return (0);
+} /* }}} int fc_register_target */
+
+fc_chain_t *fc_chain_get_by_name (const char *chain_name) /* {{{ */
+{
+  fc_chain_t *chain;
+
+  if (chain_name == NULL)
+    return (NULL);
+
+  for (chain = chain_list_head; chain != NULL; chain = chain->next)
+    if (strcasecmp (chain_name, chain->name) == 0)
+      return (chain);
+
+  return (NULL);
+} /* }}} int fc_chain_get_by_name */
+
+int fc_process_chain (const data_set_t *ds, value_list_t *vl, /* {{{ */
+    fc_chain_t *chain)
+{
+  fc_rule_t *rule;
+  fc_target_t *target;
+  int status;
+
+  if (chain == NULL)
+    return (-1);
+
+  DEBUG ("fc_process_chain (chain = %s);", chain->name);
+
+  status = FC_TARGET_CONTINUE;
+  for (rule = chain->rules; rule != NULL; rule = rule->next)
+  {
+    fc_match_t *match;
+
+    if (rule->name[0] != 0)
+    {
+      DEBUG ("fc_process_chain (%s): Testing the `%s' rule.",
+          chain->name, rule->name);
+    }
+
+    /* N. B.: rule->matches may be NULL. */
+    for (match = rule->matches; match != NULL; match = match->next)
+    {
+      /* FIXME: Pass the meta-data to match targets here (when implemented). */
+      status = (*match->proc.match) (ds, vl, /* meta = */ NULL,
+          &match->user_data);
+      if (status < 0)
+      {
+        WARNING ("fc_process_chain (%s): A match failed.", chain->name);
+        break;
+      }
+      else if (status != FC_MATCH_MATCHES)
+        break;
+    }
+
+    /* for-loop has been aborted: Either error or no match. */
+    if (match != NULL)
+    {
+      status = FC_TARGET_CONTINUE;
+      continue;
+    }
+
+    if (rule->name[0] != 0)
+    {
+      DEBUG ("fc_process_chain (%s): Rule `%s' matches.",
+          chain->name, rule->name);
+    }
+
+    for (target = rule->targets; target != NULL; target = target->next)
+    {
+      /* If we get here, all matches have matched the value. Execute the
+       * target. */
+      /* FIXME: Pass the meta-data to match targets here (when implemented). */
+      status = (*target->proc.invoke) (ds, vl, /* meta = */ NULL,
+          &target->user_data);
+      if (status < 0)
+      {
+        WARNING ("fc_process_chain (%s): A target failed.", chain->name);
+        continue;
+      }
+      else if (status == FC_TARGET_CONTINUE)
+        continue;
+      else if (status == FC_TARGET_STOP)
+        break;
+      else if (status == FC_TARGET_RETURN)
+        break;
+      else
+      {
+        WARNING ("fc_process_chain (%s): Unknown return value "
+            "from target `%s': %i",
+            chain->name, target->name, status);
+      }
+    }
+
+    if ((status == FC_TARGET_STOP)
+        || (status == FC_TARGET_RETURN))
+    {
+      if (rule->name[0] != 0)
+      {
+        DEBUG ("fc_process_chain (%s): Rule `%s' signaled "
+            "the %s condition.",
+            chain->name, rule->name,
+            (status == FC_TARGET_STOP) ? "stop" : "return");
+      }
+      break;
+    }
+    else
+    {
+      status = FC_TARGET_CONTINUE;
+    }
+  } /* for (rule) */
+
+  if (status == FC_TARGET_STOP)
+    return (FC_TARGET_STOP);
+  else if (status == FC_TARGET_RETURN)
+    return (FC_TARGET_CONTINUE);
+
+  /* for-loop has been aborted: A target returned `FC_TARGET_STOP' */
+  if (rule != NULL)
+    return (FC_TARGET_CONTINUE);
+
+  DEBUG ("fc_process_chain (%s): Executing the default targets.",
+      chain->name);
+
+  status = FC_TARGET_CONTINUE;
+  for (target = chain->targets; target != NULL; target = target->next)
+  {
+    /* If we get here, all matches have matched the value. Execute the
+     * target. */
+    /* FIXME: Pass the meta-data to match targets here (when implemented). */
+    status = (*target->proc.invoke) (ds, vl, /* meta = */ NULL,
+        &target->user_data);
+    if (status < 0)
+    {
+      WARNING ("fc_process_chain (%s): The default target failed.",
+          chain->name);
+    }
+    else if (status == FC_TARGET_CONTINUE)
+      continue;
+    else if (status == FC_TARGET_STOP)
+      break;
+    else if (status == FC_TARGET_RETURN)
+      break;
+    else
+    {
+      WARNING ("fc_process_chain (%s): Unknown return value "
+          "from target `%s': %i",
+          chain->name, target->name, status);
+    }
+  }
+
+  if ((status == FC_TARGET_STOP)
+      || (status == FC_TARGET_RETURN))
+  {
+    assert (target != NULL);
+    DEBUG ("fc_process_chain (%s): Default target `%s' signaled "
+        "the %s condition.",
+        chain->name, target->name,
+        (status == FC_TARGET_STOP) ? "stop" : "return");
+    if (status == FC_TARGET_STOP)
+      return (FC_TARGET_STOP);
+    else
+      return (FC_TARGET_CONTINUE);
+  }
+
+  DEBUG ("fc_process_chain (%s): Signaling `continue' at end of chain.",
+      chain->name);
+
+  return (FC_TARGET_CONTINUE);
+} /* }}} int fc_process_chain */
+
+/* Iterate over all rules in the chain and execute all targets for which all
+ * matches match. */
+int fc_default_action (const data_set_t *ds, value_list_t *vl) /* {{{ */
+{
+  /* FIXME: Pass the meta-data to match targets here (when implemented). */
+  return (fc_bit_write_invoke (ds, vl,
+        /* meta = */ NULL, /* user_data = */ NULL));
+} /* }}} int fc_default_action */
+
+int fc_configure (const oconfig_item_t *ci) /* {{{ */
+{
+  fc_init_once ();
+
+  if (ci == NULL)
+    return (-EINVAL);
+
+  if (strcasecmp ("Chain", ci->key) == 0)
+    return (fc_config_add_chain (ci));
+
+  WARNING ("Filter subsystem: Unknown top level config option `%s'.",
+      ci->key);
+
+  return (-1);
+} /* }}} int fc_configure */
+
+/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/src/daemon/filter_chain.h b/src/daemon/filter_chain.h
new file mode 100644 (file)
index 0000000..2db90db
--- /dev/null
@@ -0,0 +1,106 @@
+/**
+ * collectd - src/filter_chain.h
+ * Copyright (C) 2008,2009  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>
+ **/
+
+#ifndef FILTER_CHAIN_H
+#define FILTER_CHAIN_H 1
+
+#include "collectd.h"
+#include "plugin.h"
+
+#define FC_MATCH_NO_MATCH  0
+#define FC_MATCH_MATCHES   1
+
+#define FC_TARGET_CONTINUE 0
+#define FC_TARGET_STOP     1
+#define FC_TARGET_RETURN   2
+
+/*
+ * Match functions
+ */
+struct match_proc_s
+{
+  int (*create) (const oconfig_item_t *ci, void **user_data);
+  int (*destroy) (void **user_data);
+  int (*match) (const data_set_t *ds, const value_list_t *vl,
+      notification_meta_t **meta, void **user_data);
+};
+typedef struct match_proc_s match_proc_t;
+
+int fc_register_match (const char *name, match_proc_t proc);
+
+/*
+ * Target functions
+ */
+struct target_proc_s
+{
+  int (*create) (const oconfig_item_t *ci, void **user_data);
+  int (*destroy) (void **user_data);
+  int (*invoke) (const data_set_t *ds, value_list_t *vl,
+      notification_meta_t **meta, void **user_data);
+};
+typedef struct target_proc_s target_proc_t;
+
+struct fc_chain_s;
+typedef struct fc_chain_s fc_chain_t;
+
+int fc_register_target (const char *name, target_proc_t proc);
+
+/*
+ * TODO: Chain management
+ */
+#if 0
+int fc_chain_add (const char *chain_name,
+    const char *target_name, int target_argc, char **target_argv);
+int fc_chain_delete (const char *chain_name);
+#endif
+
+/*
+ * TODO: Rule management
+ */
+#if 0
+int fc_rule_add (const char *chain_name, int position,
+    int match_num, const char **match_name, int *match_argc, char ***match_argv,
+    const char *target_name, int target_argc, char **target_argv);
+int fc_rule_delete (const char *chain_name, int position);
+#endif
+
+/*
+ * Processing function
+ */
+fc_chain_t *fc_chain_get_by_name (const char *chain_name);
+
+int fc_process_chain (const data_set_t *ds, value_list_t *vl,
+    fc_chain_t *chain);
+
+int fc_default_action (const data_set_t *ds, value_list_t *vl);
+
+/* 
+ * Shortcut for global configuration
+ */
+int fc_configure (const oconfig_item_t *ci);
+
+#endif /* FILTER_CHAIN_H */
+/* vim: set sw=2 sts=2 et : */
diff --git a/src/daemon/meta_data.c b/src/daemon/meta_data.c
new file mode 100644 (file)
index 0000000..6ee8446
--- /dev/null
@@ -0,0 +1,637 @@
+/**
+ * collectd - src/meta_data.c
+ * Copyright (C) 2008-2011  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 "plugin.h"
+#include "meta_data.h"
+
+#include <pthread.h>
+
+/*
+ * Data types
+ */
+union meta_value_u
+{
+  char    *mv_string;
+  int64_t  mv_signed_int;
+  uint64_t mv_unsigned_int;
+  double   mv_double;
+  _Bool    mv_boolean;
+};
+typedef union meta_value_u meta_value_t;
+
+struct meta_entry_s;
+typedef struct meta_entry_s meta_entry_t;
+struct meta_entry_s
+{
+  char         *key;
+  meta_value_t  value;
+  int           type;
+  meta_entry_t *next;
+};
+
+struct meta_data_s
+{
+  meta_entry_t   *head;
+  pthread_mutex_t lock;
+};
+
+/*
+ * Private functions
+ */
+static char *md_strdup (const char *orig) /* {{{ */
+{
+  size_t sz;
+  char *dest;
+
+  if (orig == NULL)
+    return (NULL);
+
+  sz = strlen (orig) + 1;
+  dest = (char *) malloc (sz);
+  if (dest == NULL)
+    return (NULL);
+
+  memcpy (dest, orig, sz);
+
+  return (dest);
+} /* }}} char *md_strdup */
+
+static meta_entry_t *md_entry_alloc (const char *key) /* {{{ */
+{
+  meta_entry_t *e;
+
+  e = (meta_entry_t *) malloc (sizeof (*e));
+  if (e == NULL)
+  {
+    ERROR ("md_entry_alloc: malloc failed.");
+    return (NULL);
+  }
+  memset (e, 0, sizeof (*e));
+
+  e->key = md_strdup (key);
+  if (e->key == NULL)
+  {
+    free (e);
+    ERROR ("md_entry_alloc: md_strdup failed.");
+    return (NULL);
+  }
+
+  e->type = 0;
+  e->next = NULL;
+
+  return (e);
+} /* }}} meta_entry_t *md_entry_alloc */
+
+static meta_entry_t *md_entry_clone (const meta_entry_t *orig) /* {{{ */
+{
+  meta_entry_t *copy;
+
+  if (orig == NULL)
+    return (NULL);
+
+  copy = md_entry_alloc (orig->key);
+  copy->type = orig->type;
+  if (copy->type == MD_TYPE_STRING)
+    copy->value.mv_string = strdup (orig->value.mv_string);
+  else
+    copy->value = orig->value;
+
+  copy->next = md_entry_clone (orig->next);
+  return (copy);
+} /* }}} meta_entry_t *md_entry_clone */
+
+static void md_entry_free (meta_entry_t *e) /* {{{ */
+{
+  if (e == NULL)
+    return;
+
+  free (e->key);
+
+  if (e->type == MD_TYPE_STRING)
+    free (e->value.mv_string);
+
+  if (e->next != NULL)
+    md_entry_free (e->next);
+
+  free (e);
+} /* }}} void md_entry_free */
+
+static int md_entry_insert (meta_data_t *md, meta_entry_t *e) /* {{{ */
+{
+  meta_entry_t *this;
+  meta_entry_t *prev;
+
+  if ((md == NULL) || (e == NULL))
+    return (-EINVAL);
+
+  pthread_mutex_lock (&md->lock);
+
+  prev = NULL;
+  this = md->head;
+  while (this != NULL)
+  {
+    if (strcasecmp (e->key, this->key) == 0)
+      break;
+
+    prev = this;
+    this = this->next;
+  }
+
+  if (this == NULL)
+  {
+    /* This key does not exist yet. */
+    if (md->head == NULL)
+      md->head = e;
+    else
+    {
+      assert (prev != NULL);
+      prev->next = e;
+    }
+
+    e->next = NULL;
+  }
+  else /* (this != NULL) */
+  {
+    if (prev == NULL)
+      md->head = e;
+    else
+      prev->next = e;
+
+    e->next = this->next;
+  }
+
+  pthread_mutex_unlock (&md->lock);
+
+  if (this != NULL)
+  {
+    this->next = NULL;
+    md_entry_free (this);
+  }
+
+  return (0);
+} /* }}} int md_entry_insert */
+
+/* XXX: The lock on md must be held while calling this function! */
+static meta_entry_t *md_entry_lookup (meta_data_t *md, /* {{{ */
+    const char *key)
+{
+  meta_entry_t *e;
+
+  if ((md == NULL) || (key == NULL))
+    return (NULL);
+
+  for (e = md->head; e != NULL; e = e->next)
+    if (strcasecmp (key, e->key) == 0)
+      break;
+
+  return (e);
+} /* }}} meta_entry_t *md_entry_lookup */
+
+/*
+ * Public functions
+ */
+meta_data_t *meta_data_create (void) /* {{{ */
+{
+  meta_data_t *md;
+
+  md = (meta_data_t *) malloc (sizeof (*md));
+  if (md == NULL)
+  {
+    ERROR ("meta_data_create: malloc failed.");
+    return (NULL);
+  }
+  memset (md, 0, sizeof (*md));
+
+  md->head = NULL;
+  pthread_mutex_init (&md->lock, /* attr = */ NULL);
+
+  return (md);
+} /* }}} meta_data_t *meta_data_create */
+
+meta_data_t *meta_data_clone (meta_data_t *orig) /* {{{ */
+{
+  meta_data_t *copy;
+
+  if (orig == NULL)
+    return (NULL);
+
+  copy = meta_data_create ();
+  if (copy == NULL)
+    return (NULL);
+
+  pthread_mutex_lock (&orig->lock);
+  copy->head = md_entry_clone (orig->head);
+  pthread_mutex_unlock (&orig->lock);
+
+  return (copy);
+} /* }}} meta_data_t *meta_data_clone */
+
+void meta_data_destroy (meta_data_t *md) /* {{{ */
+{
+  if (md == NULL)
+    return;
+
+  pthread_mutex_destroy(&md->lock);
+  md_entry_free (md->head);
+  pthread_mutex_destroy (&md->lock);
+  free (md);
+} /* }}} void meta_data_destroy */
+
+int meta_data_exists (meta_data_t *md, const char *key) /* {{{ */
+{
+  meta_entry_t *e;
+
+  if ((md == NULL) || (key == NULL))
+    return (-EINVAL);
+
+  pthread_mutex_lock (&md->lock);
+
+  for (e = md->head; e != NULL; e = e->next)
+  {
+    if (strcasecmp (key, e->key) == 0)
+    {
+      pthread_mutex_unlock (&md->lock);
+      return (1);
+    }
+  }
+
+  pthread_mutex_unlock (&md->lock);
+  return (0);
+} /* }}} int meta_data_exists */
+
+int meta_data_type (meta_data_t *md, const char *key) /* {{{ */
+{
+  meta_entry_t *e;
+
+  if ((md == NULL) || (key == NULL))
+    return -EINVAL;
+
+  pthread_mutex_lock (&md->lock);
+
+  for (e = md->head; e != NULL; e = e->next)
+  {
+    if (strcasecmp (key, e->key) == 0)
+    {
+      pthread_mutex_unlock (&md->lock);
+      return e->type;
+    }
+  }
+
+  pthread_mutex_unlock (&md->lock);
+  return 0;
+} /* }}} int meta_data_type */
+
+int meta_data_toc (meta_data_t *md, char ***toc) /* {{{ */
+{
+  int i = 0, count = 0;
+  meta_entry_t *e;
+
+  if ((md == NULL) || (toc == NULL))
+    return -EINVAL;
+
+  pthread_mutex_lock (&md->lock);
+
+  for (e = md->head; e != NULL; e = e->next)
+    ++count;    
+
+  if (count == 0)
+  {
+    pthread_mutex_unlock (&md->lock);
+    return (count);
+  }
+
+  *toc = calloc(count, sizeof(**toc));
+  for (e = md->head; e != NULL; e = e->next)
+    (*toc)[i++] = strdup(e->key);
+  
+  pthread_mutex_unlock (&md->lock);
+  return count;
+} /* }}} int meta_data_toc */
+
+int meta_data_delete (meta_data_t *md, const char *key) /* {{{ */
+{
+  meta_entry_t *this;
+  meta_entry_t *prev;
+
+  if ((md == NULL) || (key == NULL))
+    return (-EINVAL);
+
+  pthread_mutex_lock (&md->lock);
+
+  prev = NULL;
+  this = md->head;
+  while (this != NULL)
+  {
+    if (strcasecmp (key, this->key) == 0)
+      break;
+
+    prev = this;
+    this = this->next;
+  }
+
+  if (this == NULL)
+  {
+    pthread_mutex_unlock (&md->lock);
+    return (-ENOENT);
+  }
+
+  if (prev == NULL)
+    md->head = this->next;
+  else
+    prev->next = this->next;
+
+  pthread_mutex_unlock (&md->lock);
+
+  this->next = NULL;
+  md_entry_free (this);
+
+  return (0);
+} /* }}} int meta_data_delete */
+
+/*
+ * Add functions
+ */
+int meta_data_add_string (meta_data_t *md, /* {{{ */
+    const char *key, const char *value)
+{
+  meta_entry_t *e;
+
+  if ((md == NULL) || (key == NULL) || (value == NULL))
+    return (-EINVAL);
+
+  e = md_entry_alloc (key);
+  if (e == NULL)
+    return (-ENOMEM);
+
+  e->value.mv_string = md_strdup (value);
+  if (e->value.mv_string == NULL)
+  {
+    ERROR ("meta_data_add_string: md_strdup failed.");
+    md_entry_free (e);
+    return (-ENOMEM);
+  }
+  e->type = MD_TYPE_STRING;
+
+  return (md_entry_insert (md, e));
+} /* }}} int meta_data_add_string */
+
+int meta_data_add_signed_int (meta_data_t *md, /* {{{ */
+    const char *key, int64_t value)
+{
+  meta_entry_t *e;
+
+  if ((md == NULL) || (key == NULL))
+    return (-EINVAL);
+
+  e = md_entry_alloc (key);
+  if (e == NULL)
+    return (-ENOMEM);
+
+  e->value.mv_signed_int = value;
+  e->type = MD_TYPE_SIGNED_INT;
+
+  return (md_entry_insert (md, e));
+} /* }}} int meta_data_add_signed_int */
+
+int meta_data_add_unsigned_int (meta_data_t *md, /* {{{ */
+    const char *key, uint64_t value)
+{
+  meta_entry_t *e;
+
+  if ((md == NULL) || (key == NULL))
+    return (-EINVAL);
+
+  e = md_entry_alloc (key);
+  if (e == NULL)
+    return (-ENOMEM);
+
+  e->value.mv_unsigned_int = value;
+  e->type = MD_TYPE_UNSIGNED_INT;
+
+  return (md_entry_insert (md, e));
+} /* }}} int meta_data_add_unsigned_int */
+
+int meta_data_add_double (meta_data_t *md, /* {{{ */
+    const char *key, double value)
+{
+  meta_entry_t *e;
+
+  if ((md == NULL) || (key == NULL))
+    return (-EINVAL);
+
+  e = md_entry_alloc (key);
+  if (e == NULL)
+    return (-ENOMEM);
+
+  e->value.mv_double = value;
+  e->type = MD_TYPE_DOUBLE;
+
+  return (md_entry_insert (md, e));
+} /* }}} int meta_data_add_double */
+
+int meta_data_add_boolean (meta_data_t *md, /* {{{ */
+    const char *key, _Bool value)
+{
+  meta_entry_t *e;
+
+  if ((md == NULL) || (key == NULL))
+    return (-EINVAL);
+
+  e = md_entry_alloc (key);
+  if (e == NULL)
+    return (-ENOMEM);
+
+  e->value.mv_boolean = value;
+  e->type = MD_TYPE_BOOLEAN;
+
+  return (md_entry_insert (md, e));
+} /* }}} int meta_data_add_boolean */
+
+/*
+ * Get functions
+ */
+int meta_data_get_string (meta_data_t *md, /* {{{ */
+    const char *key, char **value)
+{
+  meta_entry_t *e;
+  char *temp;
+
+  if ((md == NULL) || (key == NULL) || (value == NULL))
+    return (-EINVAL);
+
+  pthread_mutex_lock (&md->lock);
+
+  e = md_entry_lookup (md, key);
+  if (e == NULL)
+  {
+    pthread_mutex_unlock (&md->lock);
+    return (-ENOENT);
+  }
+
+  if (e->type != MD_TYPE_STRING)
+  {
+    ERROR ("meta_data_get_string: Type mismatch for key `%s'", e->key);
+    pthread_mutex_unlock (&md->lock);
+    return (-ENOENT);
+  }
+
+  temp = md_strdup (e->value.mv_string);
+  if (temp == NULL)
+  {
+    pthread_mutex_unlock (&md->lock);
+    ERROR ("meta_data_get_string: md_strdup failed.");
+    return (-ENOMEM);
+  }
+  pthread_mutex_unlock (&md->lock);
+
+  *value = temp;
+
+  return (0);
+} /* }}} int meta_data_get_string */
+
+int meta_data_get_signed_int (meta_data_t *md, /* {{{ */
+    const char *key, int64_t *value)
+{
+  meta_entry_t *e;
+
+  if ((md == NULL) || (key == NULL) || (value == NULL))
+    return (-EINVAL);
+
+  pthread_mutex_lock (&md->lock);
+
+  e = md_entry_lookup (md, key);
+  if (e == NULL)
+  {
+    pthread_mutex_unlock (&md->lock);
+    return (-ENOENT);
+  }
+
+  if (e->type != MD_TYPE_SIGNED_INT)
+  {
+    ERROR ("meta_data_get_signed_int: Type mismatch for key `%s'", e->key);
+    pthread_mutex_unlock (&md->lock);
+    return (-ENOENT);
+  }
+
+  *value = e->value.mv_signed_int;
+
+  pthread_mutex_unlock (&md->lock);
+  return (0);
+} /* }}} int meta_data_get_signed_int */
+
+int meta_data_get_unsigned_int (meta_data_t *md, /* {{{ */
+    const char *key, uint64_t *value)
+{
+  meta_entry_t *e;
+
+  if ((md == NULL) || (key == NULL) || (value == NULL))
+    return (-EINVAL);
+
+  pthread_mutex_lock (&md->lock);
+
+  e = md_entry_lookup (md, key);
+  if (e == NULL)
+  {
+    pthread_mutex_unlock (&md->lock);
+    return (-ENOENT);
+  }
+
+  if (e->type != MD_TYPE_UNSIGNED_INT)
+  {
+    ERROR ("meta_data_get_unsigned_int: Type mismatch for key `%s'", e->key);
+    pthread_mutex_unlock (&md->lock);
+    return (-ENOENT);
+  }
+
+  *value = e->value.mv_unsigned_int;
+
+  pthread_mutex_unlock (&md->lock);
+  return (0);
+} /* }}} int meta_data_get_unsigned_int */
+
+int meta_data_get_double (meta_data_t *md, /* {{{ */
+    const char *key, double *value)
+{
+  meta_entry_t *e;
+
+  if ((md == NULL) || (key == NULL) || (value == NULL))
+    return (-EINVAL);
+
+  pthread_mutex_lock (&md->lock);
+
+  e = md_entry_lookup (md, key);
+  if (e == NULL)
+  {
+    pthread_mutex_unlock (&md->lock);
+    return (-ENOENT);
+  }
+
+  if (e->type != MD_TYPE_DOUBLE)
+  {
+    ERROR ("meta_data_get_double: Type mismatch for key `%s'", e->key);
+    pthread_mutex_unlock (&md->lock);
+    return (-ENOENT);
+  }
+
+  *value = e->value.mv_double;
+
+  pthread_mutex_unlock (&md->lock);
+  return (0);
+} /* }}} int meta_data_get_double */
+
+int meta_data_get_boolean (meta_data_t *md, /* {{{ */
+    const char *key, _Bool *value)
+{
+  meta_entry_t *e;
+
+  if ((md == NULL) || (key == NULL) || (value == NULL))
+    return (-EINVAL);
+
+  pthread_mutex_lock (&md->lock);
+
+  e = md_entry_lookup (md, key);
+  if (e == NULL)
+  {
+    pthread_mutex_unlock (&md->lock);
+    return (-ENOENT);
+  }
+
+  if (e->type != MD_TYPE_BOOLEAN)
+  {
+    ERROR ("meta_data_get_boolean: Type mismatch for key `%s'", e->key);
+    pthread_mutex_unlock (&md->lock);
+    return (-ENOENT);
+  }
+
+  *value = e->value.mv_boolean;
+
+  pthread_mutex_unlock (&md->lock);
+  return (0);
+} /* }}} int meta_data_get_boolean */
+
+/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/src/daemon/meta_data.h b/src/daemon/meta_data.h
new file mode 100644 (file)
index 0000000..fa48df3
--- /dev/null
@@ -0,0 +1,86 @@
+/**
+ * collectd - src/meta_data.h
+ * Copyright (C) 2008-2011  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>
+ **/
+
+#ifndef META_DATA_H
+#define META_DATA_H
+
+#include "collectd.h"
+
+/*
+ * Defines
+ */
+#define MD_TYPE_STRING       1
+#define MD_TYPE_SIGNED_INT   2
+#define MD_TYPE_UNSIGNED_INT 3
+#define MD_TYPE_DOUBLE       4
+#define MD_TYPE_BOOLEAN      5
+
+struct meta_data_s;
+typedef struct meta_data_s meta_data_t;
+
+meta_data_t *meta_data_create (void);
+meta_data_t *meta_data_clone (meta_data_t *orig);
+void meta_data_destroy (meta_data_t *md);
+
+int meta_data_exists (meta_data_t *md, const char *key);
+int meta_data_type (meta_data_t *md, const char *key);
+int meta_data_toc (meta_data_t *md, char ***toc);
+int meta_data_delete (meta_data_t *md, const char *key);
+
+int meta_data_add_string (meta_data_t *md,
+    const char *key,
+    const char *value);
+int meta_data_add_signed_int (meta_data_t *md,
+    const char *key,
+    int64_t value);
+int meta_data_add_unsigned_int (meta_data_t *md,
+    const char *key,
+    uint64_t value);
+int meta_data_add_double (meta_data_t *md,
+    const char *key,
+    double value);
+int meta_data_add_boolean (meta_data_t *md,
+    const char *key,
+    _Bool value);
+
+int meta_data_get_string (meta_data_t *md,
+    const char *key,
+    char **value);
+int meta_data_get_signed_int (meta_data_t *md,
+    const char *key,
+    int64_t *value);
+int meta_data_get_unsigned_int (meta_data_t *md,
+    const char *key,
+    uint64_t *value);
+int meta_data_get_double (meta_data_t *md,
+    const char *key,
+    double *value);
+int meta_data_get_boolean (meta_data_t *md,
+    const char *key,
+    _Bool *value);
+
+#endif /* META_DATA_H */
+/* vim: set sw=2 sts=2 et : */
diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c
new file mode 100644 (file)
index 0000000..bfd2201
--- /dev/null
@@ -0,0 +1,2732 @@
+/**
+ * collectd - src/plugin.c
+ * Copyright (C) 2005-2014  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>
+ *   Sebastian Harl <sh at tokkee.org>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+#include "configfile.h"
+#include "filter_chain.h"
+#include "utils_avltree.h"
+#include "utils_cache.h"
+#include "utils_complain.h"
+#include "utils_llist.h"
+#include "utils_heap.h"
+#include "utils_time.h"
+#include "utils_random.h"
+
+#include <ltdl.h>
+
+/*
+ * Private structures
+ */
+struct callback_func_s
+{
+       void *cf_callback;
+       user_data_t cf_udata;
+       plugin_ctx_t cf_ctx;
+};
+typedef struct callback_func_s callback_func_t;
+
+#define RF_SIMPLE  0
+#define RF_COMPLEX 1
+#define RF_REMOVE  65535
+struct read_func_s
+{
+       /* `read_func_t' "inherits" from `callback_func_t'.
+        * The `rf_super' member MUST be the first one in this structure! */
+#define rf_callback rf_super.cf_callback
+#define rf_udata rf_super.cf_udata
+#define rf_ctx rf_super.cf_ctx
+       callback_func_t rf_super;
+       char rf_group[DATA_MAX_NAME_LEN];
+       char *rf_name;
+       int rf_type;
+       cdtime_t rf_interval;
+       cdtime_t rf_effective_interval;
+       cdtime_t rf_next_read;
+};
+typedef struct read_func_s read_func_t;
+
+struct write_queue_s;
+typedef struct write_queue_s write_queue_t;
+struct write_queue_s
+{
+       value_list_t *vl;
+       plugin_ctx_t ctx;
+       write_queue_t *next;
+};
+
+/*
+ * Private variables
+ */
+static c_avl_tree_t *plugins_loaded = NULL;
+
+static llist_t *list_init;
+static llist_t *list_write;
+static llist_t *list_flush;
+static llist_t *list_missing;
+static llist_t *list_shutdown;
+static llist_t *list_log;
+static llist_t *list_notification;
+
+static fc_chain_t *pre_cache_chain = NULL;
+static fc_chain_t *post_cache_chain = NULL;
+
+static c_avl_tree_t *data_sets;
+
+static char *plugindir = NULL;
+
+#ifndef DEFAULT_MAX_READ_INTERVAL
+# define DEFAULT_MAX_READ_INTERVAL TIME_T_TO_CDTIME_T (86400)
+#endif
+static c_heap_t       *read_heap = NULL;
+static llist_t        *read_list;
+static int             read_loop = 1;
+static pthread_mutex_t read_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t  read_cond = PTHREAD_COND_INITIALIZER;
+static pthread_t      *read_threads = NULL;
+static int             read_threads_num = 0;
+static cdtime_t        max_read_interval = DEFAULT_MAX_READ_INTERVAL;
+
+static write_queue_t  *write_queue_head;
+static write_queue_t  *write_queue_tail;
+static long            write_queue_length = 0;
+static _Bool           write_loop = 1;
+static pthread_mutex_t write_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t  write_cond = PTHREAD_COND_INITIALIZER;
+static pthread_t      *write_threads = NULL;
+static size_t          write_threads_num = 0;
+
+static pthread_key_t   plugin_ctx_key;
+static _Bool           plugin_ctx_key_initialized = 0;
+
+static long            write_limit_high = 0;
+static long            write_limit_low = 0;
+
+static derive_t        stats_values_dropped = 0;
+static _Bool           record_statistics = 0;
+
+/*
+ * Static functions
+ */
+static int plugin_dispatch_values_internal (value_list_t *vl);
+
+static const char *plugin_get_dir (void)
+{
+       if (plugindir == NULL)
+               return (PLUGINDIR);
+       else
+               return (plugindir);
+}
+
+static void plugin_update_internal_statistics (void) { /* {{{ */
+       derive_t copy_write_queue_length;
+       value_list_t vl = VALUE_LIST_INIT;
+       value_t values[2];
+
+       copy_write_queue_length = write_queue_length;
+
+       /* Initialize `vl' */
+       vl.values = values;
+       vl.values_len = 2;
+       vl.time = 0;
+       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       sstrncpy (vl.plugin, "collectd", sizeof (vl.plugin));
+
+       vl.type_instance[0] = 0;
+       vl.values_len = 1;
+
+       /* Write queue */
+       sstrncpy (vl.plugin_instance, "write_queue",
+                       sizeof (vl.plugin_instance));
+
+       /* Write queue : queue length */
+       vl.values[0].gauge = (gauge_t) copy_write_queue_length;
+       sstrncpy (vl.type, "queue_length", sizeof (vl.type));
+       vl.type_instance[0] = 0;
+       plugin_dispatch_values (&vl);
+
+       /* Write queue : Values dropped (queue length > low limit) */
+       vl.values[0].derive = (derive_t) stats_values_dropped;
+       sstrncpy (vl.type, "derive", sizeof (vl.type));
+       sstrncpy (vl.type_instance, "dropped", sizeof (vl.type_instance));
+       plugin_dispatch_values (&vl);
+
+       /* Cache */
+       sstrncpy (vl.plugin_instance, "cache",
+                       sizeof (vl.plugin_instance));
+
+       /* Cache : Nb entry in cache tree */
+       vl.values[0].gauge = (gauge_t) uc_get_size();
+       sstrncpy (vl.type, "cache_size", sizeof (vl.type));
+       vl.type_instance[0] = 0;
+       plugin_dispatch_values (&vl);
+
+       return;
+} /* }}} void plugin_update_internal_statistics */
+
+static void destroy_callback (callback_func_t *cf) /* {{{ */
+{
+       if (cf == NULL)
+               return;
+
+       if ((cf->cf_udata.data != NULL) && (cf->cf_udata.free_func != NULL))
+       {
+               cf->cf_udata.free_func (cf->cf_udata.data);
+               cf->cf_udata.data = NULL;
+               cf->cf_udata.free_func = NULL;
+       }
+       sfree (cf);
+} /* }}} void destroy_callback */
+
+static void destroy_all_callbacks (llist_t **list) /* {{{ */
+{
+       llentry_t *le;
+
+       if (*list == NULL)
+               return;
+
+       le = llist_head (*list);
+       while (le != NULL)
+       {
+               llentry_t *le_next;
+
+               le_next = le->next;
+
+               sfree (le->key);
+               destroy_callback (le->value);
+               le->value = NULL;
+
+               le = le_next;
+       }
+
+       llist_destroy (*list);
+       *list = NULL;
+} /* }}} void destroy_all_callbacks */
+
+static void destroy_read_heap (void) /* {{{ */
+{
+       if (read_heap == NULL)
+               return;
+
+       while (42)
+       {
+               callback_func_t *cf;
+
+               cf = c_heap_get_root (read_heap);
+               if (cf == NULL)
+                       break;
+
+               destroy_callback (cf);
+       }
+
+       c_heap_destroy (read_heap);
+       read_heap = NULL;
+} /* }}} void destroy_read_heap */
+
+static int register_callback (llist_t **list, /* {{{ */
+               const char *name, callback_func_t *cf)
+{
+       llentry_t *le;
+       char *key;
+
+       if (*list == NULL)
+       {
+               *list = llist_create ();
+               if (*list == NULL)
+               {
+                       ERROR ("plugin: register_callback: "
+                                       "llist_create failed.");
+                       destroy_callback (cf);
+                       return (-1);
+               }
+       }
+
+       key = strdup (name);
+       if (key == NULL)
+       {
+               ERROR ("plugin: register_callback: strdup failed.");
+               destroy_callback (cf);
+               return (-1);
+       }
+
+       le = llist_search (*list, name);
+       if (le == NULL)
+       {
+               le = llentry_create (key, cf);
+               if (le == NULL)
+               {
+                       ERROR ("plugin: register_callback: "
+                                       "llentry_create failed.");
+                       free (key);
+                       destroy_callback (cf);
+                       return (-1);
+               }
+
+               llist_append (*list, le);
+       }
+       else
+       {
+               callback_func_t *old_cf;
+
+               old_cf = le->value;
+               le->value = cf;
+
+               WARNING ("plugin: register_callback: "
+                               "a callback named `%s' already exists - "
+                               "overwriting the old entry!", name);
+
+               destroy_callback (old_cf);
+               sfree (key);
+       }
+
+       return (0);
+} /* }}} int register_callback */
+
+static void log_list_callbacks (llist_t **list, /* {{{ */
+                               const char *comment)
+{
+       char *str;
+       int len;
+       llentry_t *le;
+       int i;
+       int n;
+       char **keys;
+
+       n = llist_size(*list);
+       if (n == 0)
+       {
+               INFO("%s [none]", comment);
+               return;
+       }
+
+       keys = calloc(n, sizeof(char*));
+
+       if (keys == NULL)
+       {
+               ERROR("%s: failed to allocate memory for list of callbacks",
+                     comment);
+
+               return;
+       }
+
+       for (le = llist_head (*list), i = 0, len = 0;
+            le != NULL;
+            le = le->next, i++)
+       {
+               keys[i] = le->key;
+               len += strlen(le->key) + 6;
+       }
+       str = malloc(len + 10);
+       if (str == NULL)
+       {
+               ERROR("%s: failed to allocate memory for list of callbacks",
+                     comment);
+       }
+       else
+       {
+               *str = '\0';
+               strjoin(str, len, keys, n, "', '");
+               INFO("%s ['%s']", comment, str);
+               free(str);
+       }
+       free(keys);
+} /* }}} void log_list_callbacks */
+
+static int create_register_callback (llist_t **list, /* {{{ */
+               const char *name, void *callback, user_data_t *ud)
+{
+       callback_func_t *cf;
+
+       cf = (callback_func_t *) malloc (sizeof (*cf));
+       if (cf == NULL)
+       {
+               ERROR ("plugin: create_register_callback: malloc failed.");
+               return (-1);
+       }
+       memset (cf, 0, sizeof (*cf));
+
+       cf->cf_callback = callback;
+       if (ud == NULL)
+       {
+               cf->cf_udata.data = NULL;
+               cf->cf_udata.free_func = NULL;
+       }
+       else
+       {
+               cf->cf_udata = *ud;
+       }
+
+       cf->cf_ctx = plugin_get_ctx ();
+
+       return (register_callback (list, name, cf));
+} /* }}} int create_register_callback */
+
+static int plugin_unregister (llist_t *list, const char *name) /* {{{ */
+{
+       llentry_t *e;
+
+       if (list == NULL)
+               return (-1);
+
+       e = llist_search (list, name);
+       if (e == NULL)
+               return (-1);
+
+       llist_remove (list, e);
+
+       sfree (e->key);
+       destroy_callback (e->value);
+
+       llentry_destroy (e);
+
+       return (0);
+} /* }}} int plugin_unregister */
+
+/*
+ * (Try to) load the shared object `file'. Won't complain if it isn't a shared
+ * object, but it will bitch about a shared object not having a
+ * ``module_register'' symbol..
+ */
+static int plugin_load_file (char *file, uint32_t flags)
+{
+       lt_dlhandle dlh;
+       void (*reg_handle) (void);
+
+       lt_dlinit ();
+       lt_dlerror (); /* clear errors */
+
+#if LIBTOOL_VERSION == 2
+       if (flags & PLUGIN_FLAGS_GLOBAL) {
+               lt_dladvise advise;
+               lt_dladvise_init(&advise);
+               lt_dladvise_global(&advise);
+               dlh = lt_dlopenadvise(file, advise);
+               lt_dladvise_destroy(&advise);
+       } else {
+               dlh = lt_dlopen (file);
+       }
+#else /* if LIBTOOL_VERSION == 1 */
+       if (flags & PLUGIN_FLAGS_GLOBAL)
+               WARNING ("plugin_load_file: The global flag is not supported, "
+                               "libtool 2 is required for this.");
+       dlh = lt_dlopen (file);
+#endif
+
+       if (dlh == NULL)
+       {
+               char errbuf[1024] = "";
+
+               ssnprintf (errbuf, sizeof (errbuf),
+                               "lt_dlopen (\"%s\") failed: %s. "
+                               "The most common cause for this problem is "
+                               "missing dependencies. Use ldd(1) to check "
+                               "the dependencies of the plugin "
+                               "/ shared object.",
+                               file, lt_dlerror ());
+
+               ERROR ("%s", errbuf);
+               /* Make sure this is printed to STDERR in any case, but also
+                * make sure it's printed only once. */
+               if (list_log != NULL)
+                       fprintf (stderr, "ERROR: %s\n", errbuf);
+
+               return (1);
+       }
+
+       if ((reg_handle = (void (*) (void)) lt_dlsym (dlh, "module_register")) == NULL)
+       {
+               WARNING ("Couldn't find symbol \"module_register\" in \"%s\": %s\n",
+                               file, lt_dlerror ());
+               lt_dlclose (dlh);
+               return (-1);
+       }
+
+       (*reg_handle) ();
+
+       return (0);
+}
+
+static void *plugin_read_thread (void __attribute__((unused)) *args)
+{
+       while (read_loop != 0)
+       {
+               read_func_t *rf;
+               plugin_ctx_t old_ctx;
+               cdtime_t now;
+               int status;
+               int rf_type;
+               int rc;
+
+               /* Get the read function that needs to be read next.
+                * We don't need to hold "read_lock" for the heap, but we need
+                * to call c_heap_get_root() and pthread_cond_wait() in the
+                * same protected block. */
+               pthread_mutex_lock (&read_lock);
+               rf = c_heap_get_root (read_heap);
+               if (rf == NULL)
+               {
+                       pthread_cond_wait (&read_cond, &read_lock);
+                        pthread_mutex_unlock (&read_lock);
+                       continue;
+               }
+               pthread_mutex_unlock (&read_lock);
+
+               if (rf->rf_interval == 0)
+               {
+                       /* this should not happen, because the interval is set
+                        * for each plugin when loading it
+                        * XXX: issue a warning? */
+                       rf->rf_interval = plugin_get_interval ();
+                       rf->rf_effective_interval = rf->rf_interval;
+
+                       rf->rf_next_read = cdtime ();
+               }
+
+               /* sleep until this entry is due,
+                * using pthread_cond_timedwait */
+               pthread_mutex_lock (&read_lock);
+               /* In pthread_cond_timedwait, spurious wakeups are possible
+                * (and really happen, at least on NetBSD with > 1 CPU), thus
+                * we need to re-evaluate the condition every time
+                * pthread_cond_timedwait returns. */
+               rc = 0;
+               while ((read_loop != 0)
+                               && (cdtime () < rf->rf_next_read)
+                               && rc == 0)
+               {
+                       struct timespec ts = { 0 };
+
+                       CDTIME_T_TO_TIMESPEC (rf->rf_next_read, &ts);
+
+                       rc = pthread_cond_timedwait (&read_cond, &read_lock,
+                               &ts);
+               }
+
+               /* Must hold `read_lock' when accessing `rf->rf_type'. */
+               rf_type = rf->rf_type;
+               pthread_mutex_unlock (&read_lock);
+
+               /* Check if we're supposed to stop.. This may have interrupted
+                * the sleep, too. */
+               if (read_loop == 0)
+               {
+                       /* Insert `rf' again, so it can be free'd correctly */
+                       c_heap_insert (read_heap, rf);
+                       break;
+               }
+
+               /* The entry has been marked for deletion. The linked list
+                * entry has already been removed by `plugin_unregister_read'.
+                * All we have to do here is free the `read_func_t' and
+                * continue. */
+               if (rf_type == RF_REMOVE)
+               {
+                       DEBUG ("plugin_read_thread: Destroying the `%s' "
+                                       "callback.", rf->rf_name);
+                       sfree (rf->rf_name);
+                       destroy_callback ((callback_func_t *) rf);
+                       rf = NULL;
+                       continue;
+               }
+
+               DEBUG ("plugin_read_thread: Handling `%s'.", rf->rf_name);
+
+               old_ctx = plugin_set_ctx (rf->rf_ctx);
+
+               if (rf_type == RF_SIMPLE)
+               {
+                       int (*callback) (void);
+
+                       callback = rf->rf_callback;
+                       status = (*callback) ();
+               }
+               else
+               {
+                       plugin_read_cb callback;
+
+                       assert (rf_type == RF_COMPLEX);
+
+                       callback = rf->rf_callback;
+                       status = (*callback) (&rf->rf_udata);
+               }
+
+               plugin_set_ctx (old_ctx);
+
+               /* If the function signals failure, we will increase the
+                * intervals in which it will be called. */
+               if (status != 0)
+               {
+                       rf->rf_effective_interval *= 2;
+                       if (rf->rf_effective_interval > max_read_interval)
+                               rf->rf_effective_interval = max_read_interval;
+
+                       NOTICE ("read-function of plugin `%s' failed. "
+                                       "Will suspend it for %.3f seconds.",
+                                       rf->rf_name,
+                                       CDTIME_T_TO_DOUBLE (rf->rf_effective_interval));
+               }
+               else
+               {
+                       /* Success: Restore the interval, if it was changed. */
+                       rf->rf_effective_interval = rf->rf_interval;
+               }
+
+               /* update the ``next read due'' field */
+               now = cdtime ();
+
+               DEBUG ("plugin_read_thread: Effective interval of the "
+                               "%s plugin is %.3f seconds.",
+                               rf->rf_name,
+                               CDTIME_T_TO_DOUBLE (rf->rf_effective_interval));
+
+               /* Calculate the next (absolute) time at which this function
+                * should be called. */
+               rf->rf_next_read += rf->rf_effective_interval;
+
+               /* Check, if `rf_next_read' is in the past. */
+               if (rf->rf_next_read < now)
+               {
+                       /* `rf_next_read' is in the past. Insert `now'
+                        * so this value doesn't trail off into the
+                        * past too much. */
+                       rf->rf_next_read = now;
+               }
+
+               DEBUG ("plugin_read_thread: Next read of the %s plugin at %.3f.",
+                               rf->rf_name,
+                               CDTIME_T_TO_DOUBLE (rf->rf_next_read));
+
+               /* Re-insert this read function into the heap again. */
+               c_heap_insert (read_heap, rf);
+       } /* while (read_loop) */
+
+       pthread_exit (NULL);
+       return ((void *) 0);
+} /* void *plugin_read_thread */
+
+static void start_read_threads (int num)
+{
+       int i;
+
+       if (read_threads != NULL)
+               return;
+
+       read_threads = (pthread_t *) calloc (num, sizeof (pthread_t));
+       if (read_threads == NULL)
+       {
+               ERROR ("plugin: start_read_threads: calloc failed.");
+               return;
+       }
+
+       read_threads_num = 0;
+       for (i = 0; i < num; i++)
+       {
+               if (pthread_create (read_threads + read_threads_num, NULL,
+                                       plugin_read_thread, NULL) == 0)
+               {
+                       read_threads_num++;
+               }
+               else
+               {
+                       ERROR ("plugin: start_read_threads: pthread_create failed.");
+                       return;
+               }
+       } /* for (i) */
+} /* void start_read_threads */
+
+static void stop_read_threads (void)
+{
+       int i;
+
+       if (read_threads == NULL)
+               return;
+
+       INFO ("collectd: Stopping %i read threads.", read_threads_num);
+
+       pthread_mutex_lock (&read_lock);
+       read_loop = 0;
+       DEBUG ("plugin: stop_read_threads: Signalling `read_cond'");
+       pthread_cond_broadcast (&read_cond);
+       pthread_mutex_unlock (&read_lock);
+
+       for (i = 0; i < read_threads_num; i++)
+       {
+               if (pthread_join (read_threads[i], NULL) != 0)
+               {
+                       ERROR ("plugin: stop_read_threads: pthread_join failed.");
+               }
+               read_threads[i] = (pthread_t) 0;
+       }
+       sfree (read_threads);
+       read_threads_num = 0;
+} /* void stop_read_threads */
+
+static void plugin_value_list_free (value_list_t *vl) /* {{{ */
+{
+       if (vl == NULL)
+               return;
+
+       meta_data_destroy (vl->meta);
+       sfree (vl->values);
+       sfree (vl);
+} /* }}} void plugin_value_list_free */
+
+static value_list_t *plugin_value_list_clone (value_list_t const *vl_orig) /* {{{ */
+{
+       value_list_t *vl;
+
+       if (vl_orig == NULL)
+               return (NULL);
+
+       vl = malloc (sizeof (*vl));
+       if (vl == NULL)
+               return (NULL);
+       memcpy (vl, vl_orig, sizeof (*vl));
+
+       vl->values = calloc (vl_orig->values_len, sizeof (*vl->values));
+       if (vl->values == NULL)
+       {
+               plugin_value_list_free (vl);
+               return (NULL);
+       }
+       memcpy (vl->values, vl_orig->values,
+                       vl_orig->values_len * sizeof (*vl->values));
+
+       vl->meta = meta_data_clone (vl->meta);
+       if ((vl_orig->meta != NULL) && (vl->meta == NULL))
+       {
+               plugin_value_list_free (vl);
+               return (NULL);
+       }
+
+       if (vl->time == 0)
+               vl->time = cdtime ();
+
+       /* Fill in the interval from the thread context, if it is zero. */
+       if (vl->interval == 0)
+       {
+               plugin_ctx_t ctx = plugin_get_ctx ();
+
+               if (ctx.interval != 0)
+                       vl->interval = ctx.interval;
+               else
+               {
+                       char name[6 * DATA_MAX_NAME_LEN];
+                       FORMAT_VL (name, sizeof (name), vl);
+                       ERROR ("plugin_value_list_clone: Unable to determine "
+                                       "interval from context for "
+                                       "value list \"%s\". "
+                                       "This indicates a broken plugin. "
+                                       "Please report this problem to the "
+                                       "collectd mailing list or at "
+                                       "<http://collectd.org/bugs/>.", name);
+                       vl->interval = cf_get_default_interval ();
+               }
+       }
+
+       return (vl);
+} /* }}} value_list_t *plugin_value_list_clone */
+
+static int plugin_write_enqueue (value_list_t const *vl) /* {{{ */
+{
+       write_queue_t *q;
+
+       q = malloc (sizeof (*q));
+       if (q == NULL)
+               return (ENOMEM);
+       q->next = NULL;
+
+       q->vl = plugin_value_list_clone (vl);
+       if (q->vl == NULL)
+       {
+               sfree (q);
+               return (ENOMEM);
+       }
+
+       /* Store context of caller (read plugin); otherwise, it would not be
+        * available to the write plugins when actually dispatching the
+        * value-list later on. */
+       q->ctx = plugin_get_ctx ();
+
+       pthread_mutex_lock (&write_lock);
+
+       if (write_queue_tail == NULL)
+       {
+               write_queue_head = q;
+               write_queue_tail = q;
+               write_queue_length = 1;
+       }
+       else
+       {
+               write_queue_tail->next = q;
+               write_queue_tail = q;
+               write_queue_length += 1;
+       }
+
+       pthread_cond_signal (&write_cond);
+       pthread_mutex_unlock (&write_lock);
+
+       return (0);
+} /* }}} int plugin_write_enqueue */
+
+static value_list_t *plugin_write_dequeue (void) /* {{{ */
+{
+       write_queue_t *q;
+       value_list_t *vl;
+
+       pthread_mutex_lock (&write_lock);
+
+       while (write_loop && (write_queue_head == NULL))
+               pthread_cond_wait (&write_cond, &write_lock);
+
+       if (write_queue_head == NULL)
+       {
+               pthread_mutex_unlock (&write_lock);
+               return (NULL);
+       }
+
+       q = write_queue_head;
+       write_queue_head = q->next;
+       write_queue_length -= 1;
+       if (write_queue_head == NULL) {
+               write_queue_tail = NULL;
+               assert(0 == write_queue_length);
+               }
+
+       pthread_mutex_unlock (&write_lock);
+
+       (void) plugin_set_ctx (q->ctx);
+
+       vl = q->vl;
+       sfree (q);
+       return (vl);
+} /* }}} value_list_t *plugin_write_dequeue */
+
+static void *plugin_write_thread (void __attribute__((unused)) *args) /* {{{ */
+{
+       while (write_loop)
+       {
+               value_list_t *vl = plugin_write_dequeue ();
+               if (vl == NULL)
+                       continue;
+
+               plugin_dispatch_values_internal (vl);
+
+               plugin_value_list_free (vl);
+       }
+
+       pthread_exit (NULL);
+       return ((void *) 0);
+} /* }}} void *plugin_write_thread */
+
+static void start_write_threads (size_t num) /* {{{ */
+{
+       size_t i;
+
+       if (write_threads != NULL)
+               return;
+
+       write_threads = (pthread_t *) calloc (num, sizeof (pthread_t));
+       if (write_threads == NULL)
+       {
+               ERROR ("plugin: start_write_threads: calloc failed.");
+               return;
+       }
+
+       write_threads_num = 0;
+       for (i = 0; i < num; i++)
+       {
+               int status;
+
+               status = pthread_create (write_threads + write_threads_num,
+                               /* attr = */ NULL,
+                               plugin_write_thread,
+                               /* arg = */ NULL);
+               if (status != 0)
+               {
+                       char errbuf[1024];
+                       ERROR ("plugin: start_write_threads: pthread_create failed "
+                                       "with status %i (%s).", status,
+                                       sstrerror (status, errbuf, sizeof (errbuf)));
+                       return;
+               }
+
+               write_threads_num++;
+       } /* for (i) */
+} /* }}} void start_write_threads */
+
+static void stop_write_threads (void) /* {{{ */
+{
+       write_queue_t *q;
+       int i;
+
+       if (write_threads == NULL)
+               return;
+
+       INFO ("collectd: Stopping %zu write threads.", write_threads_num);
+
+       pthread_mutex_lock (&write_lock);
+       write_loop = 0;
+       DEBUG ("plugin: stop_write_threads: Signalling `write_cond'");
+       pthread_cond_broadcast (&write_cond);
+       pthread_mutex_unlock (&write_lock);
+
+       for (i = 0; i < write_threads_num; i++)
+       {
+               if (pthread_join (write_threads[i], NULL) != 0)
+               {
+                       ERROR ("plugin: stop_write_threads: pthread_join failed.");
+               }
+               write_threads[i] = (pthread_t) 0;
+       }
+       sfree (write_threads);
+       write_threads_num = 0;
+
+       pthread_mutex_lock (&write_lock);
+       i = 0;
+       for (q = write_queue_head; q != NULL; )
+       {
+               write_queue_t *q1 = q;
+               plugin_value_list_free (q->vl);
+               q = q->next;
+               sfree (q1);
+               i++;
+       }
+       write_queue_head = NULL;
+       write_queue_tail = NULL;
+       write_queue_length = 0;
+       pthread_mutex_unlock (&write_lock);
+
+       if (i > 0)
+       {
+               WARNING ("plugin: %i value list%s left after shutting down "
+                               "the write threads.",
+                               i, (i == 1) ? " was" : "s were");
+       }
+} /* }}} void stop_write_threads */
+
+/*
+ * Public functions
+ */
+void plugin_set_dir (const char *dir)
+{
+       if (plugindir != NULL)
+               free (plugindir);
+
+       if (dir == NULL)
+               plugindir = NULL;
+       else if ((plugindir = strdup (dir)) == NULL)
+       {
+               char errbuf[1024];
+               ERROR ("strdup failed: %s",
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
+       }
+}
+
+static _Bool plugin_is_loaded (char const *name)
+{
+       int status;
+
+       if (plugins_loaded == NULL)
+               plugins_loaded = c_avl_create ((void *) strcasecmp);
+       assert (plugins_loaded != NULL);
+
+       status = c_avl_get (plugins_loaded, name, /* ret_value = */ NULL);
+       return (status == 0);
+}
+
+static int plugin_mark_loaded (char const *name)
+{
+       char *name_copy;
+       int status;
+
+       name_copy = strdup (name);
+       if (name_copy == NULL)
+               return (ENOMEM);
+
+       status = c_avl_insert (plugins_loaded,
+                       /* key = */ name_copy, /* value = */ NULL);
+       return (status);
+}
+
+static void plugin_free_loaded ()
+{
+       void *key;
+       void *value;
+
+       if (plugins_loaded == NULL)
+               return;
+
+       while (c_avl_pick (plugins_loaded, &key, &value) == 0)
+       {
+               sfree (key);
+               assert (value == NULL);
+       }
+
+       c_avl_destroy (plugins_loaded);
+       plugins_loaded = NULL;
+}
+
+#define BUFSIZE 512
+int plugin_load (char const *plugin_name, uint32_t flags)
+{
+       DIR  *dh;
+       const char *dir;
+       char  filename[BUFSIZE] = "";
+       char  typename[BUFSIZE];
+       int   ret;
+       struct stat    statbuf;
+       struct dirent *de;
+       int status;
+
+       if (plugin_name == NULL)
+               return (EINVAL);
+
+       /* Check if plugin is already loaded and don't do anything in this
+        * case. */
+       if (plugin_is_loaded (plugin_name))
+               return (0);
+
+       dir = plugin_get_dir ();
+       ret = 1;
+
+       /*
+        * XXX: Magic at work:
+        *
+        * Some of the language bindings, for example the Python and Perl
+        * plugins, need to be able to export symbols to the scripts they run.
+        * For this to happen, the "Globals" flag needs to be set.
+        * Unfortunately, this technical detail is hard to explain to the
+        * average user and she shouldn't have to worry about this, ideally.
+        * So in order to save everyone's sanity use a different default for a
+        * handful of special plugins. --octo
+        */
+       if ((strcasecmp ("perl", plugin_name) == 0)
+                       || (strcasecmp ("python", plugin_name) == 0))
+               flags |= PLUGIN_FLAGS_GLOBAL;
+
+       /* `cpu' should not match `cpufreq'. To solve this we add `.so' to the
+        * type when matching the filename */
+       status = ssnprintf (typename, sizeof (typename), "%s.so", plugin_name);
+       if ((status < 0) || ((size_t) status >= sizeof (typename)))
+       {
+               WARNING ("plugin_load: Filename too long: \"%s.so\"", plugin_name);
+               return (-1);
+       }
+
+       if ((dh = opendir (dir)) == NULL)
+       {
+               char errbuf[1024];
+               ERROR ("plugin_load: opendir (%s) failed: %s", dir,
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
+               return (-1);
+       }
+
+       while ((de = readdir (dh)) != NULL)
+       {
+               if (strcasecmp (de->d_name, typename))
+                       continue;
+
+               status = ssnprintf (filename, sizeof (filename),
+                               "%s/%s", dir, de->d_name);
+               if ((status < 0) || ((size_t) status >= sizeof (filename)))
+               {
+                       WARNING ("plugin_load: Filename too long: \"%s/%s\"",
+                                       dir, de->d_name);
+                       continue;
+               }
+
+               if (lstat (filename, &statbuf) == -1)
+               {
+                       char errbuf[1024];
+                       WARNING ("plugin_load: stat (\"%s\") failed: %s",
+                                       filename,
+                                       sstrerror (errno, errbuf, sizeof (errbuf)));
+                       continue;
+               }
+               else if (!S_ISREG (statbuf.st_mode))
+               {
+                       /* don't follow symlinks */
+                       WARNING ("plugin_load: %s is not a regular file.",
+                                       filename);
+                       continue;
+               }
+
+               status = plugin_load_file (filename, flags);
+               if (status == 0)
+               {
+                       /* success */
+                       plugin_mark_loaded (plugin_name);
+                       ret = 0;
+                       break;
+               }
+               else
+               {
+                       ERROR ("plugin_load: Load plugin \"%s\" failed with "
+                                       "status %i.", plugin_name, status);
+               }
+       }
+
+       closedir (dh);
+
+       if (filename[0] == 0)
+               ERROR ("plugin_load: Could not find plugin \"%s\" in %s",
+                               plugin_name, dir);
+
+       return (ret);
+}
+
+/*
+ * The `register_*' functions follow
+ */
+int plugin_register_config (const char *name,
+               int (*callback) (const char *key, const char *val),
+               const char **keys, int keys_num)
+{
+       cf_register (name, callback, keys, keys_num);
+       return (0);
+} /* int plugin_register_config */
+
+int plugin_register_complex_config (const char *type,
+               int (*callback) (oconfig_item_t *))
+{
+       return (cf_register_complex (type, callback));
+} /* int plugin_register_complex_config */
+
+int plugin_register_init (const char *name,
+               int (*callback) (void))
+{
+       return (create_register_callback (&list_init, name, (void *) callback,
+                               /* user_data = */ NULL));
+} /* plugin_register_init */
+
+static int plugin_compare_read_func (const void *arg0, const void *arg1)
+{
+       const read_func_t *rf0;
+       const read_func_t *rf1;
+
+       rf0 = arg0;
+       rf1 = arg1;
+
+       if (rf0->rf_next_read < rf1->rf_next_read)
+               return (-1);
+       else if (rf0->rf_next_read > rf1->rf_next_read)
+               return (1);
+       else
+               return (0);
+} /* int plugin_compare_read_func */
+
+/* Add a read function to both, the heap and a linked list. The linked list if
+ * used to look-up read functions, especially for the remove function. The heap
+ * is used to determine which plugin to read next. */
+static int plugin_insert_read (read_func_t *rf)
+{
+       int status;
+       llentry_t *le;
+
+       rf->rf_next_read = cdtime ();
+       rf->rf_effective_interval = rf->rf_interval;
+
+       pthread_mutex_lock (&read_lock);
+
+       if (read_list == NULL)
+       {
+               read_list = llist_create ();
+               if (read_list == NULL)
+               {
+                       pthread_mutex_unlock (&read_lock);
+                       ERROR ("plugin_insert_read: read_list failed.");
+                       return (-1);
+               }
+       }
+
+       if (read_heap == NULL)
+       {
+               read_heap = c_heap_create (plugin_compare_read_func);
+               if (read_heap == NULL)
+               {
+                       pthread_mutex_unlock (&read_lock);
+                       ERROR ("plugin_insert_read: c_heap_create failed.");
+                       return (-1);
+               }
+       }
+
+       le = llist_search (read_list, rf->rf_name);
+       if (le != NULL)
+       {
+               pthread_mutex_unlock (&read_lock);
+               WARNING ("The read function \"%s\" is already registered. "
+                               "Check for duplicate \"LoadPlugin\" lines "
+                               "in your configuration!",
+                               rf->rf_name);
+               return (EINVAL);
+       }
+
+       le = llentry_create (rf->rf_name, rf);
+       if (le == NULL)
+       {
+               pthread_mutex_unlock (&read_lock);
+               ERROR ("plugin_insert_read: llentry_create failed.");
+               return (-1);
+       }
+
+       status = c_heap_insert (read_heap, rf);
+       if (status != 0)
+       {
+               pthread_mutex_unlock (&read_lock);
+               ERROR ("plugin_insert_read: c_heap_insert failed.");
+               llentry_destroy (le);
+               return (-1);
+       }
+
+       /* This does not fail. */
+       llist_append (read_list, le);
+
+       /* Wake up all the read threads. */
+       pthread_cond_broadcast (&read_cond);
+       pthread_mutex_unlock (&read_lock);
+       return (0);
+} /* int plugin_insert_read */
+
+int plugin_register_read (const char *name,
+               int (*callback) (void))
+{
+       read_func_t *rf;
+       int status;
+
+       rf = malloc (sizeof (*rf));
+       if (rf == NULL)
+       {
+               ERROR ("plugin_register_read: malloc failed.");
+               return (ENOMEM);
+       }
+
+       memset (rf, 0, sizeof (read_func_t));
+       rf->rf_callback = (void *) callback;
+       rf->rf_udata.data = NULL;
+       rf->rf_udata.free_func = NULL;
+       rf->rf_ctx = plugin_get_ctx ();
+       rf->rf_group[0] = '\0';
+       rf->rf_name = strdup (name);
+       rf->rf_type = RF_SIMPLE;
+       rf->rf_interval = plugin_get_interval ();
+
+       status = plugin_insert_read (rf);
+       if (status != 0) {
+               sfree (rf->rf_name);
+               sfree (rf);
+       }
+
+       return (status);
+} /* int plugin_register_read */
+
+int plugin_register_complex_read (const char *group, const char *name,
+               plugin_read_cb callback,
+               const struct timespec *interval,
+               user_data_t *user_data)
+{
+       read_func_t *rf;
+       int status;
+
+       rf = malloc (sizeof (*rf));
+       if (rf == NULL)
+       {
+               ERROR ("plugin_register_complex_read: malloc failed.");
+               return (ENOMEM);
+       }
+
+       memset (rf, 0, sizeof (read_func_t));
+       rf->rf_callback = (void *) callback;
+       if (group != NULL)
+               sstrncpy (rf->rf_group, group, sizeof (rf->rf_group));
+       else
+               rf->rf_group[0] = '\0';
+       rf->rf_name = strdup (name);
+       rf->rf_type = RF_COMPLEX;
+       if (interval != NULL)
+               rf->rf_interval = TIMESPEC_TO_CDTIME_T (interval);
+       else
+               rf->rf_interval = plugin_get_interval ();
+
+       /* Set user data */
+       if (user_data == NULL)
+       {
+               rf->rf_udata.data = NULL;
+               rf->rf_udata.free_func = NULL;
+       }
+       else
+       {
+               rf->rf_udata = *user_data;
+       }
+
+       rf->rf_ctx = plugin_get_ctx ();
+
+       status = plugin_insert_read (rf);
+       if (status != 0) {
+               sfree (rf->rf_name);
+               sfree (rf);
+       }
+
+       return (status);
+} /* int plugin_register_complex_read */
+
+int plugin_register_write (const char *name,
+               plugin_write_cb callback, user_data_t *ud)
+{
+       return (create_register_callback (&list_write, name,
+                               (void *) callback, ud));
+} /* int plugin_register_write */
+
+int plugin_register_flush (const char *name,
+               plugin_flush_cb callback, user_data_t *ud)
+{
+       return (create_register_callback (&list_flush, name,
+                               (void *) callback, ud));
+} /* int plugin_register_flush */
+
+int plugin_register_missing (const char *name,
+               plugin_missing_cb callback, user_data_t *ud)
+{
+       return (create_register_callback (&list_missing, name,
+                               (void *) callback, ud));
+} /* int plugin_register_missing */
+
+int plugin_register_shutdown (const char *name,
+               int (*callback) (void))
+{
+       return (create_register_callback (&list_shutdown, name,
+                               (void *) callback, /* user_data = */ NULL));
+} /* int plugin_register_shutdown */
+
+static void plugin_free_data_sets (void)
+{
+       void *key;
+       void *value;
+
+       if (data_sets == NULL)
+               return;
+
+       while (c_avl_pick (data_sets, &key, &value) == 0)
+       {
+               data_set_t *ds = value;
+               /* key is a pointer to ds->type */
+
+               sfree (ds->ds);
+               sfree (ds);
+       }
+
+       c_avl_destroy (data_sets);
+       data_sets = NULL;
+} /* void plugin_free_data_sets */
+
+int plugin_register_data_set (const data_set_t *ds)
+{
+       data_set_t *ds_copy;
+       int i;
+
+       if ((data_sets != NULL)
+                       && (c_avl_get (data_sets, ds->type, NULL) == 0))
+       {
+               NOTICE ("Replacing DS `%s' with another version.", ds->type);
+               plugin_unregister_data_set (ds->type);
+       }
+       else if (data_sets == NULL)
+       {
+               data_sets = c_avl_create ((int (*) (const void *, const void *)) strcmp);
+               if (data_sets == NULL)
+                       return (-1);
+       }
+
+       ds_copy = (data_set_t *) malloc (sizeof (data_set_t));
+       if (ds_copy == NULL)
+               return (-1);
+       memcpy(ds_copy, ds, sizeof (data_set_t));
+
+       ds_copy->ds = (data_source_t *) malloc (sizeof (data_source_t)
+                       * ds->ds_num);
+       if (ds_copy->ds == NULL)
+       {
+               free (ds_copy);
+               return (-1);
+       }
+
+       for (i = 0; i < ds->ds_num; i++)
+               memcpy (ds_copy->ds + i, ds->ds + i, sizeof (data_source_t));
+
+       return (c_avl_insert (data_sets, (void *) ds_copy->type, (void *) ds_copy));
+} /* int plugin_register_data_set */
+
+int plugin_register_log (const char *name,
+               plugin_log_cb callback, user_data_t *ud)
+{
+       return (create_register_callback (&list_log, name,
+                               (void *) callback, ud));
+} /* int plugin_register_log */
+
+int plugin_register_notification (const char *name,
+               plugin_notification_cb callback, user_data_t *ud)
+{
+       return (create_register_callback (&list_notification, name,
+                               (void *) callback, ud));
+} /* int plugin_register_log */
+
+int plugin_unregister_config (const char *name)
+{
+       cf_unregister (name);
+       return (0);
+} /* int plugin_unregister_config */
+
+int plugin_unregister_complex_config (const char *name)
+{
+       cf_unregister_complex (name);
+       return (0);
+} /* int plugin_unregister_complex_config */
+
+int plugin_unregister_init (const char *name)
+{
+       return (plugin_unregister (list_init, name));
+}
+
+int plugin_unregister_read (const char *name) /* {{{ */
+{
+       llentry_t *le;
+       read_func_t *rf;
+
+       if (name == NULL)
+               return (-ENOENT);
+
+       pthread_mutex_lock (&read_lock);
+
+       if (read_list == NULL)
+       {
+               pthread_mutex_unlock (&read_lock);
+               return (-ENOENT);
+       }
+
+       le = llist_search (read_list, name);
+       if (le == NULL)
+       {
+               pthread_mutex_unlock (&read_lock);
+               WARNING ("plugin_unregister_read: No such read function: %s",
+                               name);
+               return (-ENOENT);
+       }
+
+       llist_remove (read_list, le);
+
+       rf = le->value;
+       assert (rf != NULL);
+       rf->rf_type = RF_REMOVE;
+
+       pthread_mutex_unlock (&read_lock);
+
+       llentry_destroy (le);
+
+       DEBUG ("plugin_unregister_read: Marked `%s' for removal.", name);
+
+       return (0);
+} /* }}} int plugin_unregister_read */
+
+void plugin_log_available_writers (void)
+{
+       log_list_callbacks (&list_write, "Available write targets:");
+}
+
+static int compare_read_func_group (llentry_t *e, void *ud) /* {{{ */
+{
+       read_func_t *rf    = e->value;
+       char        *group = ud;
+
+       return strcmp (rf->rf_group, (const char *)group);
+} /* }}} int compare_read_func_group */
+
+int plugin_unregister_read_group (const char *group) /* {{{ */
+{
+       llentry_t *le;
+       read_func_t *rf;
+
+       int found = 0;
+
+       if (group == NULL)
+               return (-ENOENT);
+
+       pthread_mutex_lock (&read_lock);
+
+       if (read_list == NULL)
+       {
+               pthread_mutex_unlock (&read_lock);
+               return (-ENOENT);
+       }
+
+       while (42)
+       {
+               le = llist_search_custom (read_list,
+                               compare_read_func_group, (void *)group);
+
+               if (le == NULL)
+                       break;
+
+               ++found;
+
+               llist_remove (read_list, le);
+
+               rf = le->value;
+               assert (rf != NULL);
+               rf->rf_type = RF_REMOVE;
+
+               llentry_destroy (le);
+
+               DEBUG ("plugin_unregister_read_group: "
+                               "Marked `%s' (group `%s') for removal.",
+                               rf->rf_name, group);
+       }
+
+       pthread_mutex_unlock (&read_lock);
+
+       if (found == 0)
+       {
+               WARNING ("plugin_unregister_read_group: No such "
+                               "group of read function: %s", group);
+               return (-ENOENT);
+       }
+
+       return (0);
+} /* }}} int plugin_unregister_read_group */
+
+int plugin_unregister_write (const char *name)
+{
+       return (plugin_unregister (list_write, name));
+}
+
+int plugin_unregister_flush (const char *name)
+{
+       return (plugin_unregister (list_flush, name));
+}
+
+int plugin_unregister_missing (const char *name)
+{
+       return (plugin_unregister (list_missing, name));
+}
+
+int plugin_unregister_shutdown (const char *name)
+{
+       return (plugin_unregister (list_shutdown, name));
+}
+
+int plugin_unregister_data_set (const char *name)
+{
+       data_set_t *ds;
+
+       if (data_sets == NULL)
+               return (-1);
+
+       if (c_avl_remove (data_sets, name, NULL, (void *) &ds) != 0)
+               return (-1);
+
+       sfree (ds->ds);
+       sfree (ds);
+
+       return (0);
+} /* int plugin_unregister_data_set */
+
+int plugin_unregister_log (const char *name)
+{
+       return (plugin_unregister (list_log, name));
+}
+
+int plugin_unregister_notification (const char *name)
+{
+       return (plugin_unregister (list_notification, name));
+}
+
+void plugin_init_all (void)
+{
+       char const *chain_name;
+       long write_threads_num;
+       llentry_t *le;
+       int status;
+
+       /* Init the value cache */
+       uc_init ();
+
+       if (IS_TRUE (global_option_get ("CollectInternalStats")))
+               record_statistics = 1;
+
+       chain_name = global_option_get ("PreCacheChain");
+       pre_cache_chain = fc_chain_get_by_name (chain_name);
+
+       chain_name = global_option_get ("PostCacheChain");
+       post_cache_chain = fc_chain_get_by_name (chain_name);
+
+       write_limit_high = global_option_get_long ("WriteQueueLimitHigh",
+                       /* default = */ 0);
+       if (write_limit_high < 0)
+       {
+               ERROR ("WriteQueueLimitHigh must be positive or zero.");
+               write_limit_high = 0;
+       }
+
+       write_limit_low = global_option_get_long ("WriteQueueLimitLow",
+                       /* default = */ write_limit_high / 2);
+       if (write_limit_low < 0)
+       {
+               ERROR ("WriteQueueLimitLow must be positive or zero.");
+               write_limit_low = write_limit_high / 2;
+       }
+       else if (write_limit_low > write_limit_high)
+       {
+               ERROR ("WriteQueueLimitLow must not be larger than "
+                               "WriteQueueLimitHigh.");
+               write_limit_low = write_limit_high;
+       }
+
+       write_threads_num = global_option_get_long ("WriteThreads",
+                       /* default = */ 5);
+       if (write_threads_num < 1)
+       {
+               ERROR ("WriteThreads must be positive.");
+               write_threads_num = 5;
+       }
+
+       start_write_threads ((size_t) write_threads_num);
+
+       if ((list_init == NULL) && (read_heap == NULL))
+               return;
+
+       /* Calling all init callbacks before checking if read callbacks
+        * are available allows the init callbacks to register the read
+        * callback. */
+       le = llist_head (list_init);
+       while (le != NULL)
+       {
+               callback_func_t *cf;
+               plugin_init_cb callback;
+               plugin_ctx_t old_ctx;
+
+               cf = le->value;
+               old_ctx = plugin_set_ctx (cf->cf_ctx);
+               callback = cf->cf_callback;
+               status = (*callback) ();
+               plugin_set_ctx (old_ctx);
+
+               if (status != 0)
+               {
+                       ERROR ("Initialization of plugin `%s' "
+                                       "failed with status %i. "
+                                       "Plugin will be unloaded.",
+                                       le->key, status);
+                       /* Plugins that register read callbacks from the init
+                        * callback should take care of appropriate error
+                        * handling themselves. */
+                       /* FIXME: Unload _all_ functions */
+                       plugin_unregister_read (le->key);
+               }
+
+               le = le->next;
+       }
+
+       max_read_interval = global_option_get_time ("MaxReadInterval",
+                       DEFAULT_MAX_READ_INTERVAL);
+
+       /* Start read-threads */
+       if (read_heap != NULL)
+       {
+               const char *rt;
+               int num;
+
+               rt = global_option_get ("ReadThreads");
+               num = atoi (rt);
+               if (num != -1)
+                       start_read_threads ((num > 0) ? num : 5);
+       }
+} /* void plugin_init_all */
+
+/* TODO: Rename this function. */
+void plugin_read_all (void)
+{
+       if(record_statistics) {
+               plugin_update_internal_statistics ();
+       }
+       uc_check_timeout ();
+
+       return;
+} /* void plugin_read_all */
+
+/* Read function called when the `-T' command line argument is given. */
+int plugin_read_all_once (void)
+{
+       int status;
+       int return_status = 0;
+
+       if (read_heap == NULL)
+       {
+               NOTICE ("No read-functions are registered.");
+               return (0);
+       }
+
+       while (42)
+       {
+               read_func_t *rf;
+               plugin_ctx_t old_ctx;
+
+               rf = c_heap_get_root (read_heap);
+               if (rf == NULL)
+                       break;
+
+               old_ctx = plugin_set_ctx (rf->rf_ctx);
+
+               if (rf->rf_type == RF_SIMPLE)
+               {
+                       int (*callback) (void);
+
+                       callback = rf->rf_callback;
+                       status = (*callback) ();
+               }
+               else
+               {
+                       plugin_read_cb callback;
+
+                       callback = rf->rf_callback;
+                       status = (*callback) (&rf->rf_udata);
+               }
+
+               plugin_set_ctx (old_ctx);
+
+               if (status != 0)
+               {
+                       NOTICE ("read-function of plugin `%s' failed.",
+                                       rf->rf_name);
+                       return_status = -1;
+               }
+
+               sfree (rf->rf_name);
+               destroy_callback ((void *) rf);
+       }
+
+       return (return_status);
+} /* int plugin_read_all_once */
+
+int plugin_write (const char *plugin, /* {{{ */
+               const data_set_t *ds, const value_list_t *vl)
+{
+  llentry_t *le;
+  int status;
+
+  if (vl == NULL)
+    return (EINVAL);
+
+  if (list_write == NULL)
+    return (ENOENT);
+
+  if (ds == NULL)
+  {
+    ds = plugin_get_ds (vl->type);
+    if (ds == NULL)
+    {
+      ERROR ("plugin_write: Unable to lookup type `%s'.", vl->type);
+      return (ENOENT);
+    }
+  }
+
+  if (plugin == NULL)
+  {
+    int success = 0;
+    int failure = 0;
+
+    le = llist_head (list_write);
+    while (le != NULL)
+    {
+      callback_func_t *cf = le->value;
+      plugin_write_cb callback;
+
+      /* do not switch plugin context; rather keep the context (interval)
+       * information of the calling read plugin */
+
+      DEBUG ("plugin: plugin_write: Writing values via %s.", le->key);
+      callback = cf->cf_callback;
+      status = (*callback) (ds, vl, &cf->cf_udata);
+      if (status != 0)
+        failure++;
+      else
+        success++;
+
+      le = le->next;
+    }
+
+    if ((success == 0) && (failure != 0))
+      status = -1;
+    else
+      status = 0;
+  }
+  else /* plugin != NULL */
+  {
+    callback_func_t *cf;
+    plugin_write_cb callback;
+
+    le = llist_head (list_write);
+    while (le != NULL)
+    {
+      if (strcasecmp (plugin, le->key) == 0)
+        break;
+
+      le = le->next;
+    }
+
+    if (le == NULL)
+      return (ENOENT);
+
+    cf = le->value;
+
+    /* do not switch plugin context; rather keep the context (interval)
+     * information of the calling read plugin */
+
+    DEBUG ("plugin: plugin_write: Writing values via %s.", le->key);
+    callback = cf->cf_callback;
+    status = (*callback) (ds, vl, &cf->cf_udata);
+  }
+
+  return (status);
+} /* }}} int plugin_write */
+
+int plugin_flush (const char *plugin, cdtime_t timeout, const char *identifier)
+{
+  llentry_t *le;
+
+  if (list_flush == NULL)
+    return (0);
+
+  le = llist_head (list_flush);
+  while (le != NULL)
+  {
+    callback_func_t *cf;
+    plugin_flush_cb callback;
+    plugin_ctx_t old_ctx;
+
+    if ((plugin != NULL)
+        && (strcmp (plugin, le->key) != 0))
+    {
+      le = le->next;
+      continue;
+    }
+
+    cf = le->value;
+    old_ctx = plugin_set_ctx (cf->cf_ctx);
+    callback = cf->cf_callback;
+
+    (*callback) (timeout, identifier, &cf->cf_udata);
+
+    plugin_set_ctx (old_ctx);
+
+    le = le->next;
+  }
+  return (0);
+} /* int plugin_flush */
+
+void plugin_shutdown_all (void)
+{
+       llentry_t *le;
+
+       stop_read_threads ();
+
+       destroy_all_callbacks (&list_init);
+
+       pthread_mutex_lock (&read_lock);
+       llist_destroy (read_list);
+       read_list = NULL;
+       pthread_mutex_unlock (&read_lock);
+
+       destroy_read_heap ();
+
+       plugin_flush (/* plugin = */ NULL,
+                       /* timeout = */ 0,
+                       /* identifier = */ NULL);
+
+       le = NULL;
+       if (list_shutdown != NULL)
+               le = llist_head (list_shutdown);
+
+       while (le != NULL)
+       {
+               callback_func_t *cf;
+               plugin_shutdown_cb callback;
+               plugin_ctx_t old_ctx;
+
+               cf = le->value;
+               old_ctx = plugin_set_ctx (cf->cf_ctx);
+               callback = cf->cf_callback;
+
+               /* Advance the pointer before calling the callback allows
+                * shutdown functions to unregister themselves. If done the
+                * other way around the memory `le' points to will be freed
+                * after callback returns. */
+               le = le->next;
+
+               (*callback) ();
+
+               plugin_set_ctx (old_ctx);
+       }
+
+       stop_write_threads ();
+
+       /* Write plugins which use the `user_data' pointer usually need the
+        * same data available to the flush callback. If this is the case, set
+        * the free_function to NULL when registering the flush callback and to
+        * the real free function when registering the write callback. This way
+        * the data isn't freed twice. */
+       destroy_all_callbacks (&list_flush);
+       destroy_all_callbacks (&list_missing);
+       destroy_all_callbacks (&list_write);
+
+       destroy_all_callbacks (&list_notification);
+       destroy_all_callbacks (&list_shutdown);
+       destroy_all_callbacks (&list_log);
+
+       plugin_free_loaded ();
+       plugin_free_data_sets ();
+} /* void plugin_shutdown_all */
+
+int plugin_dispatch_missing (const value_list_t *vl) /* {{{ */
+{
+  llentry_t *le;
+
+  if (list_missing == NULL)
+    return (0);
+
+  le = llist_head (list_missing);
+  while (le != NULL)
+  {
+    callback_func_t *cf;
+    plugin_missing_cb callback;
+    plugin_ctx_t old_ctx;
+    int status;
+
+    cf = le->value;
+    old_ctx = plugin_set_ctx (cf->cf_ctx);
+    callback = cf->cf_callback;
+
+    status = (*callback) (vl, &cf->cf_udata);
+    plugin_set_ctx (old_ctx);
+    if (status != 0)
+    {
+      if (status < 0)
+      {
+        ERROR ("plugin_dispatch_missing: Callback function \"%s\" "
+            "failed with status %i.",
+            le->key, status);
+        return (status);
+      }
+      else
+      {
+        return (0);
+      }
+    }
+
+    le = le->next;
+  }
+  return (0);
+} /* int }}} plugin_dispatch_missing */
+
+static int plugin_dispatch_values_internal (value_list_t *vl)
+{
+       int status;
+       static c_complain_t no_write_complaint = C_COMPLAIN_INIT_STATIC;
+
+       value_t *saved_values;
+       int      saved_values_len;
+
+       data_set_t *ds;
+
+       int free_meta_data = 0;
+
+       if ((vl == NULL) || (vl->type[0] == 0)
+                       || (vl->values == NULL) || (vl->values_len < 1))
+       {
+               ERROR ("plugin_dispatch_values: Invalid value list "
+                               "from plugin %s.", vl->plugin);
+               return (-1);
+       }
+
+       /* Free meta data only if the calling function didn't specify any. In
+        * this case matches and targets may add some and the calling function
+        * may not expect (and therefore free) that data. */
+       if (vl->meta == NULL)
+               free_meta_data = 1;
+
+       if (list_write == NULL)
+               c_complain_once (LOG_WARNING, &no_write_complaint,
+                               "plugin_dispatch_values: No write callback has been "
+                               "registered. Please load at least one output plugin, "
+                               "if you want the collected data to be stored.");
+
+       if (data_sets == NULL)
+       {
+               ERROR ("plugin_dispatch_values: No data sets registered. "
+                               "Could the types database be read? Check "
+                               "your `TypesDB' setting!");
+               return (-1);
+       }
+
+       if (c_avl_get (data_sets, vl->type, (void *) &ds) != 0)
+       {
+               char ident[6 * DATA_MAX_NAME_LEN];
+
+               FORMAT_VL (ident, sizeof (ident), vl);
+               INFO ("plugin_dispatch_values: Dataset not found: %s "
+                               "(from \"%s\"), check your types.db!",
+                               vl->type, ident);
+               return (-1);
+       }
+
+       /* Assured by plugin_value_list_clone(). The time is determined at
+        * _enqueue_ time. */
+       assert (vl->time != 0);
+       assert (vl->interval != 0);
+
+       DEBUG ("plugin_dispatch_values: time = %.3f; interval = %.3f; "
+                       "host = %s; "
+                       "plugin = %s; plugin_instance = %s; "
+                       "type = %s; type_instance = %s;",
+                       CDTIME_T_TO_DOUBLE (vl->time),
+                       CDTIME_T_TO_DOUBLE (vl->interval),
+                       vl->host,
+                       vl->plugin, vl->plugin_instance,
+                       vl->type, vl->type_instance);
+
+#if COLLECT_DEBUG
+       assert (0 == strcmp (ds->type, vl->type));
+#else
+       if (0 != strcmp (ds->type, vl->type))
+               WARNING ("plugin_dispatch_values: (ds->type = %s) != (vl->type = %s)",
+                               ds->type, vl->type);
+#endif
+
+#if COLLECT_DEBUG
+       assert (ds->ds_num == vl->values_len);
+#else
+       if (ds->ds_num != vl->values_len)
+       {
+               ERROR ("plugin_dispatch_values: ds->type = %s: "
+                               "(ds->ds_num = %i) != "
+                               "(vl->values_len = %i)",
+                               ds->type, ds->ds_num, vl->values_len);
+               return (-1);
+       }
+#endif
+
+       escape_slashes (vl->host, sizeof (vl->host));
+       escape_slashes (vl->plugin, sizeof (vl->plugin));
+       escape_slashes (vl->plugin_instance, sizeof (vl->plugin_instance));
+       escape_slashes (vl->type, sizeof (vl->type));
+       escape_slashes (vl->type_instance, sizeof (vl->type_instance));
+
+       /* Copy the values. This way, we can assure `targets' that they get
+        * dynamically allocated values, which they can free and replace if
+        * they like. */
+       if ((pre_cache_chain != NULL) || (post_cache_chain != NULL))
+       {
+               saved_values     = vl->values;
+               saved_values_len = vl->values_len;
+
+               vl->values = (value_t *) calloc (vl->values_len,
+                               sizeof (*vl->values));
+               if (vl->values == NULL)
+               {
+                       ERROR ("plugin_dispatch_values: calloc failed.");
+                       vl->values = saved_values;
+                       return (-1);
+               }
+               memcpy (vl->values, saved_values,
+                               vl->values_len * sizeof (*vl->values));
+       }
+       else /* if ((pre == NULL) && (post == NULL)) */
+       {
+               saved_values     = NULL;
+               saved_values_len = 0;
+       }
+
+       if (pre_cache_chain != NULL)
+       {
+               status = fc_process_chain (ds, vl, pre_cache_chain);
+               if (status < 0)
+               {
+                       WARNING ("plugin_dispatch_values: Running the "
+                                       "pre-cache chain failed with "
+                                       "status %i (%#x).",
+                                       status, status);
+               }
+               else if (status == FC_TARGET_STOP)
+               {
+                       /* Restore the state of the value_list so that plugins
+                        * don't get confused.. */
+                       if (saved_values != NULL)
+                       {
+                               free (vl->values);
+                               vl->values     = saved_values;
+                               vl->values_len = saved_values_len;
+                       }
+                       return (0);
+               }
+       }
+
+       /* Update the value cache */
+       uc_update (ds, vl);
+
+       if (post_cache_chain != NULL)
+       {
+               status = fc_process_chain (ds, vl, post_cache_chain);
+               if (status < 0)
+               {
+                       WARNING ("plugin_dispatch_values: Running the "
+                                       "post-cache chain failed with "
+                                       "status %i (%#x).",
+                                       status, status);
+               }
+       }
+       else
+               fc_default_action (ds, vl);
+
+       /* Restore the state of the value_list so that plugins don't get
+        * confused.. */
+       if (saved_values != NULL)
+       {
+               free (vl->values);
+               vl->values     = saved_values;
+               vl->values_len = saved_values_len;
+       }
+
+       if ((free_meta_data != 0) && (vl->meta != NULL))
+       {
+               meta_data_destroy (vl->meta);
+               vl->meta = NULL;
+       }
+
+       return (0);
+} /* int plugin_dispatch_values_internal */
+
+static double get_drop_probability (void) /* {{{ */
+{
+       long pos;
+       long size;
+       long wql;
+
+       pthread_mutex_lock (&write_lock);
+       wql = write_queue_length;
+       pthread_mutex_unlock (&write_lock);
+
+       if (wql < write_limit_low)
+               return (0.0);
+       if (wql >= write_limit_high)
+               return (1.0);
+
+       pos = 1 + wql - write_limit_low;
+       size = 1 + write_limit_high - write_limit_low;
+
+       return (((double) pos) / ((double) size));
+} /* }}} double get_drop_probability */
+
+static _Bool check_drop_value (void) /* {{{ */
+{
+       static cdtime_t last_message_time = 0;
+       static pthread_mutex_t last_message_lock = PTHREAD_MUTEX_INITIALIZER;
+
+       double p;
+       double q;
+       int status;
+
+       if (write_limit_high == 0)
+               return (0);
+
+       p = get_drop_probability ();
+       if (p == 0.0)
+               return (0);
+
+       status = pthread_mutex_trylock (&last_message_lock);
+       if (status == 0)
+       {
+               cdtime_t now;
+
+               now = cdtime ();
+               if ((now - last_message_time) > TIME_T_TO_CDTIME_T (1))
+               {
+                       last_message_time = now;
+                       ERROR ("plugin_dispatch_values: Low water mark "
+                                       "reached. Dropping %.0f%% of metrics.",
+                                       100.0 * p);
+               }
+               pthread_mutex_unlock (&last_message_lock);
+       }
+
+       if (p == 1.0)
+               return (1);
+
+       q = cdrand_d ();
+       if (q > p)
+               return (1);
+       else
+               return (0);
+} /* }}} _Bool check_drop_value */
+
+int plugin_dispatch_values (value_list_t const *vl)
+{
+       int status;
+       static pthread_mutex_t statistics_lock = PTHREAD_MUTEX_INITIALIZER;
+
+       if (check_drop_value ()) {
+               if(record_statistics) {
+                       pthread_mutex_lock(&statistics_lock);
+                       stats_values_dropped++;
+                       pthread_mutex_unlock(&statistics_lock);
+               }
+               return (0);
+       }
+
+       status = plugin_write_enqueue (vl);
+       if (status != 0)
+       {
+               char errbuf[1024];
+               ERROR ("plugin_dispatch_values: plugin_write_enqueue failed "
+                               "with status %i (%s).", status,
+                               sstrerror (status, errbuf, sizeof (errbuf)));
+               return (status);
+       }
+
+       return (0);
+}
+
+__attribute__((sentinel))
+int plugin_dispatch_multivalue (value_list_t const *template, /* {{{ */
+               _Bool store_percentage, int store_type, ...)
+{
+       value_list_t *vl;
+       int failed = 0;
+       gauge_t sum = 0.0;
+       va_list ap;
+
+       assert (template->values_len == 1);
+
+  /* Calculate sum for Gauge to calculate percent if needed */
+       if (DS_TYPE_GAUGE == store_type)        {
+               va_start (ap, store_type);
+               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_type);
+       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. */
+               switch (store_type)
+               {
+               case DS_TYPE_GAUGE:
+                       vl->values[0].gauge = va_arg (ap, gauge_t);
+                       if (store_percentage)
+                               vl->values[0].gauge *= 100.0 / sum;
+                       break;
+               case DS_TYPE_ABSOLUTE:
+                       vl->values[0].absolute = va_arg (ap, absolute_t);
+                       break;
+               case DS_TYPE_COUNTER:
+                       vl->values[0].counter  = va_arg (ap, counter_t);
+                       break;
+               case DS_TYPE_DERIVE:
+                       vl->values[0].derive   = va_arg (ap, derive_t);
+                       break;
+               default:
+                       ERROR ("plugin_dispatch_multivalue: given store_type is incorrect.");
+                       failed++;
+               }
+
+
+               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;
+       /* Possible TODO: Add flap detection here */
+
+       DEBUG ("plugin_dispatch_notification: severity = %i; message = %s; "
+                       "time = %.3f; host = %s;",
+                       notif->severity, notif->message,
+                       CDTIME_T_TO_DOUBLE (notif->time), notif->host);
+
+       /* Nobody cares for notifications */
+       if (list_notification == NULL)
+               return (-1);
+
+       le = llist_head (list_notification);
+       while (le != NULL)
+       {
+               callback_func_t *cf;
+               plugin_notification_cb callback;
+               int status;
+
+               /* do not switch plugin context; rather keep the context
+                * (interval) information of the calling plugin */
+
+               cf = le->value;
+               callback = cf->cf_callback;
+               status = (*callback) (notif, &cf->cf_udata);
+               if (status != 0)
+               {
+                       WARNING ("plugin_dispatch_notification: Notification "
+                                       "callback %s returned %i.",
+                                       le->key, status);
+               }
+
+               le = le->next;
+       }
+
+       return (0);
+} /* int plugin_dispatch_notification */
+
+void plugin_log (int level, const char *format, ...)
+{
+       char msg[1024];
+       va_list ap;
+       llentry_t *le;
+
+#if !COLLECT_DEBUG
+       if (level >= LOG_DEBUG)
+               return;
+#endif
+
+       va_start (ap, format);
+       vsnprintf (msg, sizeof (msg), format, ap);
+       msg[sizeof (msg) - 1] = '\0';
+       va_end (ap);
+
+       if (list_log == NULL)
+       {
+               fprintf (stderr, "%s\n", msg);
+               return;
+       }
+
+       le = llist_head (list_log);
+       while (le != NULL)
+       {
+               callback_func_t *cf;
+               plugin_log_cb callback;
+
+               cf = le->value;
+               callback = cf->cf_callback;
+
+               /* do not switch plugin context; rather keep the context
+                * (interval) information of the calling plugin */
+
+               (*callback) (level, msg, &cf->cf_udata);
+
+               le = le->next;
+       }
+} /* void plugin_log */
+
+int parse_log_severity (const char *severity)
+{
+       int log_level = -1;
+
+       if ((0 == strcasecmp (severity, "emerg"))
+                       || (0 == strcasecmp (severity, "alert"))
+                       || (0 == strcasecmp (severity, "crit"))
+                       || (0 == strcasecmp (severity, "err")))
+               log_level = LOG_ERR;
+       else if (0 == strcasecmp (severity, "warning"))
+               log_level = LOG_WARNING;
+       else if (0 == strcasecmp (severity, "notice"))
+               log_level = LOG_NOTICE;
+       else if (0 == strcasecmp (severity, "info"))
+               log_level = LOG_INFO;
+#if COLLECT_DEBUG
+       else if (0 == strcasecmp (severity, "debug"))
+               log_level = LOG_DEBUG;
+#endif /* COLLECT_DEBUG */
+
+       return (log_level);
+} /* int parse_log_severity */
+
+int parse_notif_severity (const char *severity)
+{
+       int notif_severity = -1;
+
+       if (strcasecmp (severity, "FAILURE") == 0)
+               notif_severity = NOTIF_FAILURE;
+       else if (strcmp (severity, "OKAY") == 0)
+               notif_severity = NOTIF_OKAY;
+       else if ((strcmp (severity, "WARNING") == 0)
+                       || (strcmp (severity, "WARN") == 0))
+               notif_severity = NOTIF_WARNING;
+
+       return (notif_severity);
+} /* int parse_notif_severity */
+
+const data_set_t *plugin_get_ds (const char *name)
+{
+       data_set_t *ds;
+
+       if (data_sets == NULL)
+       {
+               ERROR ("plugin_get_ds: No data sets are defined yet.");
+               return (NULL);
+       }
+
+       if (c_avl_get (data_sets, name, (void *) &ds) != 0)
+       {
+               DEBUG ("No such dataset registered: %s", name);
+               return (NULL);
+       }
+
+       return (ds);
+} /* data_set_t *plugin_get_ds */
+
+static int plugin_notification_meta_add (notification_t *n,
+    const char *name,
+    enum notification_meta_type_e type,
+    const void *value)
+{
+  notification_meta_t *meta;
+  notification_meta_t *tail;
+
+  if ((n == NULL) || (name == NULL) || (value == NULL))
+  {
+    ERROR ("plugin_notification_meta_add: A pointer is NULL!");
+    return (-1);
+  }
+
+  meta = (notification_meta_t *) malloc (sizeof (notification_meta_t));
+  if (meta == NULL)
+  {
+    ERROR ("plugin_notification_meta_add: malloc failed.");
+    return (-1);
+  }
+  memset (meta, 0, sizeof (notification_meta_t));
+
+  sstrncpy (meta->name, name, sizeof (meta->name));
+  meta->type = type;
+
+  switch (type)
+  {
+    case NM_TYPE_STRING:
+    {
+      meta->nm_value.nm_string = strdup ((const char *) value);
+      if (meta->nm_value.nm_string == NULL)
+      {
+        ERROR ("plugin_notification_meta_add: strdup failed.");
+        sfree (meta);
+        return (-1);
+      }
+      break;
+    }
+    case NM_TYPE_SIGNED_INT:
+    {
+      meta->nm_value.nm_signed_int = *((int64_t *) value);
+      break;
+    }
+    case NM_TYPE_UNSIGNED_INT:
+    {
+      meta->nm_value.nm_unsigned_int = *((uint64_t *) value);
+      break;
+    }
+    case NM_TYPE_DOUBLE:
+    {
+      meta->nm_value.nm_double = *((double *) value);
+      break;
+    }
+    case NM_TYPE_BOOLEAN:
+    {
+      meta->nm_value.nm_boolean = *((_Bool *) value);
+      break;
+    }
+    default:
+    {
+      ERROR ("plugin_notification_meta_add: Unknown type: %i", type);
+      sfree (meta);
+      return (-1);
+    }
+  } /* switch (type) */
+
+  meta->next = NULL;
+  tail = n->meta;
+  while ((tail != NULL) && (tail->next != NULL))
+    tail = tail->next;
+
+  if (tail == NULL)
+    n->meta = meta;
+  else
+    tail->next = meta;
+
+  return (0);
+} /* int plugin_notification_meta_add */
+
+int plugin_notification_meta_add_string (notification_t *n,
+    const char *name,
+    const char *value)
+{
+  return (plugin_notification_meta_add (n, name, NM_TYPE_STRING, value));
+}
+
+int plugin_notification_meta_add_signed_int (notification_t *n,
+    const char *name,
+    int64_t value)
+{
+  return (plugin_notification_meta_add (n, name, NM_TYPE_SIGNED_INT, &value));
+}
+
+int plugin_notification_meta_add_unsigned_int (notification_t *n,
+    const char *name,
+    uint64_t value)
+{
+  return (plugin_notification_meta_add (n, name, NM_TYPE_UNSIGNED_INT, &value));
+}
+
+int plugin_notification_meta_add_double (notification_t *n,
+    const char *name,
+    double value)
+{
+  return (plugin_notification_meta_add (n, name, NM_TYPE_DOUBLE, &value));
+}
+
+int plugin_notification_meta_add_boolean (notification_t *n,
+    const char *name,
+    _Bool value)
+{
+  return (plugin_notification_meta_add (n, name, NM_TYPE_BOOLEAN, &value));
+}
+
+int plugin_notification_meta_copy (notification_t *dst,
+    const notification_t *src)
+{
+  notification_meta_t *meta;
+
+  assert (dst != NULL);
+  assert (src != NULL);
+  assert (dst != src);
+  assert ((src->meta == NULL) || (src->meta != dst->meta));
+
+  for (meta = src->meta; meta != NULL; meta = meta->next)
+  {
+    if (meta->type == NM_TYPE_STRING)
+      plugin_notification_meta_add_string (dst, meta->name,
+          meta->nm_value.nm_string);
+    else if (meta->type == NM_TYPE_SIGNED_INT)
+      plugin_notification_meta_add_signed_int (dst, meta->name,
+          meta->nm_value.nm_signed_int);
+    else if (meta->type == NM_TYPE_UNSIGNED_INT)
+      plugin_notification_meta_add_unsigned_int (dst, meta->name,
+          meta->nm_value.nm_unsigned_int);
+    else if (meta->type == NM_TYPE_DOUBLE)
+      plugin_notification_meta_add_double (dst, meta->name,
+          meta->nm_value.nm_double);
+    else if (meta->type == NM_TYPE_BOOLEAN)
+      plugin_notification_meta_add_boolean (dst, meta->name,
+          meta->nm_value.nm_boolean);
+  }
+
+  return (0);
+} /* int plugin_notification_meta_copy */
+
+int plugin_notification_meta_free (notification_meta_t *n)
+{
+  notification_meta_t *this;
+  notification_meta_t *next;
+
+  if (n == NULL)
+  {
+    ERROR ("plugin_notification_meta_free: n == NULL!");
+    return (-1);
+  }
+
+  this = n;
+  while (this != NULL)
+  {
+    next = this->next;
+
+    if (this->type == NM_TYPE_STRING)
+    {
+      free ((char *)this->nm_value.nm_string);
+      this->nm_value.nm_string = NULL;
+    }
+    sfree (this);
+
+    this = next;
+  }
+
+  return (0);
+} /* int plugin_notification_meta_free */
+
+static void plugin_ctx_destructor (void *ctx)
+{
+       sfree (ctx);
+} /* void plugin_ctx_destructor */
+
+static plugin_ctx_t ctx_init = { /* interval = */ 0 };
+
+static plugin_ctx_t *plugin_ctx_create (void)
+{
+       plugin_ctx_t *ctx;
+
+       ctx = malloc (sizeof (*ctx));
+       if (ctx == NULL) {
+               char errbuf[1024];
+               ERROR ("Failed to allocate plugin context: %s",
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
+               return NULL;
+       }
+
+       *ctx = ctx_init;
+       assert (plugin_ctx_key_initialized);
+       pthread_setspecific (plugin_ctx_key, ctx);
+       DEBUG("Created new plugin context.");
+       return (ctx);
+} /* int plugin_ctx_create */
+
+void plugin_init_ctx (void)
+{
+       pthread_key_create (&plugin_ctx_key, plugin_ctx_destructor);
+       plugin_ctx_key_initialized = 1;
+} /* void plugin_init_ctx */
+
+plugin_ctx_t plugin_get_ctx (void)
+{
+       plugin_ctx_t *ctx;
+
+       assert (plugin_ctx_key_initialized);
+       ctx = pthread_getspecific (plugin_ctx_key);
+
+       if (ctx == NULL) {
+               ctx = plugin_ctx_create ();
+               /* this must no happen -- exit() instead? */
+               if (ctx == NULL)
+                       return ctx_init;
+       }
+
+       return (*ctx);
+} /* plugin_ctx_t plugin_get_ctx */
+
+plugin_ctx_t plugin_set_ctx (plugin_ctx_t ctx)
+{
+       plugin_ctx_t *c;
+       plugin_ctx_t old;
+
+       assert (plugin_ctx_key_initialized);
+       c = pthread_getspecific (plugin_ctx_key);
+
+       if (c == NULL) {
+               c = plugin_ctx_create ();
+               /* this must no happen -- exit() instead? */
+               if (c == NULL)
+                       return ctx_init;
+       }
+
+       old = *c;
+       *c = ctx;
+
+       return (old);
+} /* void plugin_set_ctx */
+
+cdtime_t plugin_get_interval (void)
+{
+       cdtime_t interval;
+
+       interval = plugin_get_ctx().interval;
+       if (interval > 0)
+               return interval;
+
+       return cf_get_default_interval ();
+} /* cdtime_t plugin_get_interval */
+
+typedef struct {
+       plugin_ctx_t ctx;
+       void *(*start_routine) (void *);
+       void *arg;
+} plugin_thread_t;
+
+static void *plugin_thread_start (void *arg)
+{
+       plugin_thread_t *plugin_thread = arg;
+
+       void *(*start_routine) (void *) = plugin_thread->start_routine;
+       void *plugin_arg = plugin_thread->arg;
+
+       plugin_set_ctx (plugin_thread->ctx);
+
+       free (plugin_thread);
+
+       return start_routine (plugin_arg);
+} /* void *plugin_thread_start */
+
+int plugin_thread_create (pthread_t *thread, const pthread_attr_t *attr,
+               void *(*start_routine) (void *), void *arg)
+{
+       plugin_thread_t *plugin_thread;
+
+       plugin_thread = malloc (sizeof (*plugin_thread));
+       if (plugin_thread == NULL)
+               return -1;
+
+       plugin_thread->ctx           = plugin_get_ctx ();
+       plugin_thread->start_routine = start_routine;
+       plugin_thread->arg           = arg;
+
+       return pthread_create (thread, attr,
+                       plugin_thread_start, plugin_thread);
+} /* int plugin_thread_create */
+
+/* vim: set sw=8 ts=8 noet fdm=marker : */
diff --git a/src/daemon/plugin.h b/src/daemon/plugin.h
new file mode 100644 (file)
index 0000000..70a2232
--- /dev/null
@@ -0,0 +1,460 @@
+/**
+ * collectd - src/plugin.h
+ * Copyright (C) 2005-2014  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>
+ *   Sebastian Harl <sh at tokkee.org>
+ **/
+
+#ifndef PLUGIN_H
+#define PLUGIN_H
+
+#include "collectd.h"
+#include "configfile.h"
+#include "meta_data.h"
+#include "utils_time.h"
+
+#if HAVE_PTHREAD_H
+# include <pthread.h>
+#endif
+
+#define PLUGIN_FLAGS_GLOBAL 0x0001
+
+#define DATA_MAX_NAME_LEN 64
+
+#define DS_TYPE_COUNTER  0
+#define DS_TYPE_GAUGE    1
+#define DS_TYPE_DERIVE   2
+#define DS_TYPE_ABSOLUTE 3
+
+#define DS_TYPE_TO_STRING(t) (t == DS_TYPE_COUNTER)     ? "counter"  : \
+                               (t == DS_TYPE_GAUGE)    ? "gauge"    : \
+                               (t == DS_TYPE_DERIVE)   ? "derive"   : \
+                               (t == DS_TYPE_ABSOLUTE) ? "absolute" : \
+                               "unknown"
+
+
+#ifndef LOG_ERR
+# define LOG_ERR 3
+#endif
+#ifndef LOG_WARNING
+# define LOG_WARNING 4
+#endif
+#ifndef LOG_NOTICE
+# define LOG_NOTICE 5
+#endif
+#ifndef LOG_INFO
+# define LOG_INFO 6
+#endif
+#ifndef LOG_DEBUG
+# define LOG_DEBUG 7
+#endif
+
+#define NOTIF_MAX_MSG_LEN 256
+
+#define NOTIF_FAILURE 1
+#define NOTIF_WARNING 2
+#define NOTIF_OKAY    4
+
+#define plugin_interval (plugin_get_ctx().interval)
+
+/*
+ * Public data types
+ */
+typedef unsigned long long counter_t;
+typedef double gauge_t;
+typedef int64_t derive_t;
+typedef uint64_t absolute_t;
+
+union value_u
+{
+       counter_t  counter;
+       gauge_t    gauge;
+       derive_t   derive;
+       absolute_t absolute;
+};
+typedef union value_u value_t;
+
+struct value_list_s
+{
+       value_t *values;
+       int      values_len;
+       cdtime_t time;
+       cdtime_t interval;
+       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];
+       meta_data_t *meta;
+};
+typedef struct value_list_s value_list_t;
+
+#define VALUE_LIST_INIT { NULL, 0, 0, plugin_get_interval (), \
+       "localhost", "", "", "", "", NULL }
+#define VALUE_LIST_STATIC { NULL, 0, 0, 0, "localhost", "", "", "", "", NULL }
+
+struct data_source_s
+{
+       char   name[DATA_MAX_NAME_LEN];
+       int    type;
+       double min;
+       double max;
+};
+typedef struct data_source_s data_source_t;
+
+struct data_set_s
+{
+       char           type[DATA_MAX_NAME_LEN];
+       int            ds_num;
+       data_source_t *ds;
+};
+typedef struct data_set_s data_set_t;
+
+enum notification_meta_type_e
+{
+       NM_TYPE_STRING,
+       NM_TYPE_SIGNED_INT,
+       NM_TYPE_UNSIGNED_INT,
+       NM_TYPE_DOUBLE,
+       NM_TYPE_BOOLEAN
+};
+
+typedef struct notification_meta_s
+{
+       char name[DATA_MAX_NAME_LEN];
+       enum notification_meta_type_e type;
+       union
+       {
+               const char *nm_string;
+               int64_t nm_signed_int;
+               uint64_t nm_unsigned_int;
+               double nm_double;
+               _Bool nm_boolean;
+       } nm_value;
+       struct notification_meta_s *next;
+} notification_meta_t;
+
+typedef struct notification_s
+{
+       int    severity;
+       cdtime_t time;
+       char   message[NOTIF_MAX_MSG_LEN];
+       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];
+       notification_meta_t *meta;
+} notification_t;
+
+struct user_data_s
+{
+       void *data;
+       void (*free_func) (void *);
+};
+typedef struct user_data_s user_data_t;
+
+struct plugin_ctx_s
+{
+       cdtime_t interval;
+};
+typedef struct plugin_ctx_s plugin_ctx_t;
+
+/*
+ * Callback types
+ */
+typedef int (*plugin_init_cb) (void);
+typedef int (*plugin_read_cb) (user_data_t *);
+typedef int (*plugin_write_cb) (const data_set_t *, const value_list_t *,
+               user_data_t *);
+typedef int (*plugin_flush_cb) (cdtime_t timeout, const char *identifier,
+               user_data_t *);
+/* "missing" callback. Returns less than zero on failure, zero if other
+ * callbacks should be called, greater than zero if no more callbacks should be
+ * called. */
+typedef int (*plugin_missing_cb) (const value_list_t *, user_data_t *);
+typedef void (*plugin_log_cb) (int severity, const char *message,
+               user_data_t *);
+typedef int (*plugin_shutdown_cb) (void);
+typedef int (*plugin_notification_cb) (const notification_t *,
+               user_data_t *);
+
+/*
+ * NAME
+ *  plugin_set_dir
+ *
+ * DESCRIPTION
+ *  Sets the current `plugindir'
+ *
+ * ARGUMENTS
+ *  `dir'       Path to the plugin directory
+ *
+ * NOTES
+ *  If `dir' is NULL the compiled in default `PLUGINDIR' is used.
+ */
+void plugin_set_dir (const char *dir);
+
+/*
+ * NAME
+ *  plugin_load
+ *
+ * DESCRIPTION
+ *  Searches the current `plugindir' (see `plugin_set_dir') for the plugin
+ *  named $type and loads it. Afterwards the plugin's `module_register'
+ *  function is called, which then calls `plugin_register' to register callback
+ *  functions.
+ *
+ * ARGUMENTS
+ *  `name'      Name of the plugin to load.
+ *  `flags'     Hints on how to handle this plugin.
+ *
+ * RETURN VALUE
+ *  Returns zero upon success, a value greater than zero if no plugin was found
+ *  and a value below zero if an error occurs.
+ *
+ * NOTES
+ *  Re-loading an already loaded module is detected and zero is returned in
+ *  this case.
+ */
+int plugin_load (const char *name, uint32_t flags);
+
+void plugin_init_all (void);
+void plugin_read_all (void);
+int plugin_read_all_once (void);
+void plugin_shutdown_all (void);
+
+/*
+ * NAME
+ *  plugin_write
+ *
+ * DESCRIPTION
+ *  Calls the write function of the given plugin with the provided data set and
+ *  value list. It differs from `plugin_dispatch_value' in that it does not
+ *  update the cache, does not do threshold checking, call the chain subsystem
+ *  and so on. It looks up the requested plugin and invokes the function, end
+ *  of story.
+ *
+ * ARGUMENTS
+ *  plugin     Name of the plugin. If NULL, the value is sent to all registered
+ *             write functions.
+ *  ds         Pointer to the data_set_t structure. If NULL, the data set is
+ *             looked up according to the `type' member in the `vl' argument.
+ *  vl         The actual value to be processed. Must not be NULL.
+ *
+ * RETURN VALUE
+ *  Returns zero upon success or non-zero if an error occurred. If `plugin' is
+ *  NULL and more than one plugin is called, an error is only returned if *all*
+ *  plugins fail.
+ *
+ * NOTES
+ *  This is the function used by the `write' built-in target. May be used by
+ *  other target plugins.
+ */
+int plugin_write (const char *plugin,
+    const data_set_t *ds, const value_list_t *vl);
+
+int plugin_flush (const char *plugin, cdtime_t timeout, const char *identifier);
+
+/*
+ * The `plugin_register_*' functions are used to make `config', `init',
+ * `read', `write' and `shutdown' functions known to the plugin
+ * infrastructure. Also, the data-formats are made public like this.
+ */
+int plugin_register_config (const char *name,
+               int (*callback) (const char *key, const char *val),
+               const char **keys, int keys_num);
+int plugin_register_complex_config (const char *type,
+               int (*callback) (oconfig_item_t *));
+int plugin_register_init (const char *name,
+               plugin_init_cb callback);
+int plugin_register_read (const char *name,
+               int (*callback) (void));
+/* "user_data" will be freed automatically, unless
+ * "plugin_register_complex_read" returns an error (non-zero). */
+int plugin_register_complex_read (const char *group, const char *name,
+               plugin_read_cb callback,
+               const struct timespec *interval,
+               user_data_t *user_data);
+int plugin_register_write (const char *name,
+               plugin_write_cb callback, user_data_t *user_data);
+int plugin_register_flush (const char *name,
+               plugin_flush_cb callback, user_data_t *user_data);
+int plugin_register_missing (const char *name,
+               plugin_missing_cb callback, user_data_t *user_data);
+int plugin_register_shutdown (const char *name,
+               plugin_shutdown_cb callback);
+int plugin_register_data_set (const data_set_t *ds);
+int plugin_register_log (const char *name,
+               plugin_log_cb callback, user_data_t *user_data);
+int plugin_register_notification (const char *name,
+               plugin_notification_cb callback, user_data_t *user_data);
+
+int plugin_unregister_config (const char *name);
+int plugin_unregister_complex_config (const char *name);
+int plugin_unregister_init (const char *name);
+int plugin_unregister_read (const char *name);
+int plugin_unregister_read_group (const char *group);
+int plugin_unregister_write (const char *name);
+int plugin_unregister_flush (const char *name);
+int plugin_unregister_missing (const char *name);
+int plugin_unregister_shutdown (const char *name);
+int plugin_unregister_data_set (const char *name);
+int plugin_unregister_log (const char *name);
+int plugin_unregister_notification (const char *name);
+
+/*
+ * NAME
+ *  plugin_log_available_writers
+ *
+ * DESCRIPTION
+ *  This function can be called to output a list of _all_ registered
+ *  writers to the logfacility.
+ *  Since some writers dynamically build their name it can be hard for
+ *  the configuring person to know it. This function will fill this gap.
+ */
+void plugin_log_available_writers ();
+
+/*
+ * NAME
+ *  plugin_dispatch_values
+ *
+ * DESCRIPTION
+ *  This function is called by reading processes with the values they've
+ *  aquired. The function fetches the data-set definition (that has been
+ *  registered using `plugin_register_data_set') and calls _all_ registered
+ *  write-functions.
+ *
+ * ARGUMENTS
+ *  `vl'        Value list of the values that have been read by a `read'
+ *              function.
+ */
+int plugin_dispatch_values (value_list_t const *vl);
+
+/*
+ * NAME
+ *  plugin_dispatch_multivalue
+ *
+ * SYNOPSIS
+ *  plugin_dispatch_multivalue (vl, 1, DS_TYPE_GAUGE,
+ *                              "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 / type pairs, that are
+ *  interpreted as type "char const *" and type, encoded by their corresponding
+ *  "store_type":
+ *
+ *     - "gauge_t"    when "DS_TYPE_GAUGE"
+ *     - "absolute_t" when "DS_TYPE_ABSOLUTE"
+ *     - "derive_t"   when "DS_TYPE_DERIVE"
+ *     - "counter_t"  when "DS_TYPE_COUNTER"
+ *
+ *  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 store_type, ...);
+
+int plugin_dispatch_missing (const value_list_t *vl);
+
+int plugin_dispatch_notification (const notification_t *notif);
+
+void plugin_log (int level, const char *format, ...)
+       __attribute__ ((format(printf,2,3)));
+
+/* These functions return the parsed severity or less than zero on failure. */
+int parse_log_severity (const char *severity);
+int parse_notif_severity (const char *severity);
+
+#define ERROR(...)   plugin_log (LOG_ERR,     __VA_ARGS__)
+#define WARNING(...) plugin_log (LOG_WARNING, __VA_ARGS__)
+#define NOTICE(...)  plugin_log (LOG_NOTICE,  __VA_ARGS__)
+#define INFO(...)    plugin_log (LOG_INFO,    __VA_ARGS__)
+#if COLLECT_DEBUG
+# define DEBUG(...)  plugin_log (LOG_DEBUG,   __VA_ARGS__)
+#else /* COLLECT_DEBUG */
+# define DEBUG(...)  /* noop */
+#endif /* ! COLLECT_DEBUG */
+
+const data_set_t *plugin_get_ds (const char *name);
+
+int plugin_notification_meta_add_string (notification_t *n,
+    const char *name,
+    const char *value);
+int plugin_notification_meta_add_signed_int (notification_t *n,
+    const char *name,
+    int64_t value);
+int plugin_notification_meta_add_unsigned_int (notification_t *n,
+    const char *name,
+    uint64_t value);
+int plugin_notification_meta_add_double (notification_t *n,
+    const char *name,
+    double value);
+int plugin_notification_meta_add_boolean (notification_t *n,
+    const char *name,
+    _Bool value);
+
+int plugin_notification_meta_copy (notification_t *dst,
+    const notification_t *src);
+
+int plugin_notification_meta_free (notification_meta_t *n);
+
+/*
+ * Plugin context management.
+ */
+
+void plugin_init_ctx (void);
+
+plugin_ctx_t plugin_get_ctx (void);
+plugin_ctx_t plugin_set_ctx (plugin_ctx_t ctx);
+
+/*
+ * NAME
+ *  plugin_get_interval
+ *
+ * DESCRIPTION
+ *  This function returns the current value of the plugin's interval. The
+ *  return value will be strictly greater than zero in all cases. If
+ *  everything else fails, it will fall back to 10 seconds.
+ */
+cdtime_t plugin_get_interval (void);
+
+/*
+ * Context-aware thread management.
+ */
+
+int plugin_thread_create (pthread_t *thread, const pthread_attr_t *attr,
+               void *(*start_routine) (void *), void *arg);
+
+#endif /* PLUGIN_H */
diff --git a/src/daemon/plugin_mock.c b/src/daemon/plugin_mock.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/daemon/types_list.c b/src/daemon/types_list.c
new file mode 100644 (file)
index 0000000..c0e61c5
--- /dev/null
@@ -0,0 +1,207 @@
+/**
+ * collectd - src/types_list.c
+ * Copyright (C) 2007       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 "common.h"
+
+#include "plugin.h"
+#include "configfile.h"
+
+static int parse_ds (data_source_t *dsrc, char *buf, size_t buf_len)
+{
+  char *dummy;
+  char *saveptr;
+  char *fields[8];
+  int   fields_num;
+
+  if (buf_len < 11)
+  {
+    ERROR ("parse_ds: (buf_len = %zu) < 11", buf_len);
+    return (-1);
+  }
+
+  if (buf[buf_len - 1] == ',')
+  {
+    buf_len--;
+    buf[buf_len] = '\0';
+  }
+
+  dummy = buf;
+  saveptr = NULL;
+
+  fields_num = 0;
+  while (fields_num < 8)
+  {
+    if ((fields[fields_num] = strtok_r (dummy, ":", &saveptr)) == NULL)
+      break;
+    dummy = NULL;
+    fields_num++;
+  }
+
+  if (fields_num != 4)
+  {
+    ERROR ("parse_ds: (fields_num = %i) != 4", fields_num);
+    return (-1);
+  }
+
+  sstrncpy (dsrc->name, fields[0], sizeof (dsrc->name));
+
+  if (strcasecmp (fields[1], "GAUGE") == 0)
+    dsrc->type = DS_TYPE_GAUGE;
+  else if (strcasecmp (fields[1], "COUNTER") == 0)
+    dsrc->type = DS_TYPE_COUNTER;
+  else if (strcasecmp (fields[1], "DERIVE") == 0)
+    dsrc->type = DS_TYPE_DERIVE;
+  else if (strcasecmp (fields[1], "ABSOLUTE") == 0)
+    dsrc->type = DS_TYPE_ABSOLUTE;
+  else
+  {
+    ERROR ("(fields[1] = %s) != (GAUGE || COUNTER || DERIVE || ABSOLUTE)", fields[1]);
+    return (-1);
+  }
+
+  if (strcasecmp (fields[2], "U") == 0)
+    dsrc->min = NAN;
+  else
+    dsrc->min = atof (fields[2]);
+
+  if (strcasecmp (fields[3], "U") == 0)
+    dsrc->max = NAN;
+  else
+    dsrc->max = atof (fields[3]);
+
+  return (0);
+} /* int parse_ds */
+
+static void parse_line (char *buf)
+{
+  char  *fields[64];
+  size_t fields_num;
+  data_set_t *ds;
+  int i;
+
+  fields_num = strsplit (buf, fields, 64);
+  if (fields_num < 2)
+    return;
+
+  /* Ignore lines which begin with a hash sign. */
+  if (fields[0][0] == '#')
+    return;
+
+  ds = (data_set_t *) malloc (sizeof (data_set_t));
+  if (ds == NULL)
+    return;
+
+  memset (ds, '\0', sizeof (data_set_t));
+
+  sstrncpy (ds->type, fields[0], sizeof (ds->type));
+
+  ds->ds_num = fields_num - 1;
+  ds->ds = (data_source_t *) calloc (ds->ds_num, sizeof (data_source_t));
+  if (ds->ds == NULL)
+    return;
+
+  for (i = 0; i < ds->ds_num; i++)
+    if (parse_ds (ds->ds + i, fields[i + 1], strlen (fields[i + 1])) != 0)
+    {
+      sfree (ds->ds);
+      ERROR ("types_list: parse_line: Cannot parse data source #%i "
+         "of data set %s", i, ds->type);
+      return;
+    }
+
+  plugin_register_data_set (ds);
+
+  sfree (ds->ds);
+  sfree (ds);
+} /* void parse_line */
+
+static void parse_file (FILE *fh)
+{
+  char buf[4096];
+  size_t buf_len;
+
+  while (fgets (buf, sizeof (buf), fh) != NULL)
+  {
+    buf_len = strlen (buf);
+
+    if (buf_len >= 4095)
+    {
+      NOTICE ("Skipping line with more than 4095 characters.");
+      do
+      {
+       if (fgets (buf, sizeof (buf), fh) == NULL)
+         break;
+       buf_len = strlen (buf);
+      } while (buf_len >= 4095);
+      continue;
+    } /* if (buf_len >= 4095) */
+
+    if ((buf_len == 0) || (buf[0] == '#'))
+      continue;
+
+    while ((buf_len > 0) && ((buf[buf_len - 1] == '\n')
+         || (buf[buf_len - 1] == '\r')))
+      buf[--buf_len] = '\0';
+
+    if (buf_len == 0)
+      continue;
+
+    parse_line (buf);
+  } /* while (fgets) */
+} /* void parse_file */
+
+int read_types_list (const char *file)
+{
+  FILE *fh;
+
+  if (file == NULL)
+    return (-1);
+
+  fh = fopen (file, "r");
+  if (fh == NULL)
+  {
+    char errbuf[1024];
+    fprintf (stderr, "Failed to open types database `%s': %s.\n",
+       file, sstrerror (errno, errbuf, sizeof (errbuf)));
+    ERROR ("Failed to open types database `%s': %s",
+       file, sstrerror (errno, errbuf, sizeof (errbuf)));
+    return (-1);
+  }
+
+  parse_file (fh);
+
+  fclose (fh);
+  fh = NULL;
+
+  DEBUG ("Done parsing `%s'", file);
+
+  return (0);
+} /* int read_types_list */
+
+/*
+ * vim: shiftwidth=2:softtabstop=2:tabstop=8
+ */
diff --git a/src/daemon/types_list.h b/src/daemon/types_list.h
new file mode 100644 (file)
index 0000000..f375a2f
--- /dev/null
@@ -0,0 +1,32 @@
+/**
+ * collectd - src/types_list.h
+ * Copyright (C) 2007       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>
+ **/
+
+#ifndef TYPES_LIST_H
+#define TYPES_LIST_H 1
+
+int read_types_list (const char *file);
+
+#endif /* TYPES_LIST_H */
diff --git a/src/daemon/utils_avltree.c b/src/daemon/utils_avltree.c
new file mode 100644 (file)
index 0000000..e251975
--- /dev/null
@@ -0,0 +1,744 @@
+/**
+ * collectd - src/utils_avltree.c
+ * Copyright (C) 2006,2007  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 "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#include "utils_avltree.h"
+
+#define BALANCE(n) ((((n)->left == NULL) ? 0 : (n)->left->height) \
+               - (((n)->right == NULL) ? 0 : (n)->right->height))
+
+/*
+ * private data types
+ */
+struct c_avl_node_s
+{
+       void *key;
+       void *value;
+
+       int height;
+       struct c_avl_node_s *left;
+       struct c_avl_node_s *right;
+       struct c_avl_node_s *parent;
+};
+typedef struct c_avl_node_s c_avl_node_t;
+
+struct c_avl_tree_s
+{
+       c_avl_node_t *root;
+       int (*compare) (const void *, const void *);
+       int size;
+};
+
+struct c_avl_iterator_s
+{
+       c_avl_tree_t *tree;
+       c_avl_node_t *node;
+};
+
+/*
+ * private functions
+ */
+#if 0
+static void verify_tree (c_avl_node_t *n)
+{
+       if (n == NULL)
+               return;
+
+       verify_tree (n->left);
+       verify_tree (n->right);
+
+       assert ((BALANCE (n) >= -1) && (BALANCE (n) <= 1));
+       assert ((n->parent == NULL) || (n->parent->right == n) || (n->parent->left == n));
+} /* void verify_tree */
+#else
+# define verify_tree(n) /**/
+#endif
+
+static void free_node (c_avl_node_t *n)
+{
+       if (n == NULL)
+               return;
+
+       if (n->left != NULL)
+               free_node (n->left);
+       if (n->right != NULL)
+               free_node (n->right);
+
+       free (n);
+}
+
+static int calc_height (c_avl_node_t *n)
+{
+       int height_left;
+       int height_right;
+
+       if (n == NULL)
+               return (0);
+
+       height_left  = (n->left == NULL)  ? 0 : n->left->height;
+       height_right = (n->right == NULL) ? 0 : n->right->height;
+
+       return (((height_left > height_right)
+                               ? height_left
+                               : height_right) + 1);
+} /* int calc_height */
+
+static c_avl_node_t *search (c_avl_tree_t *t, const void *key)
+{
+       c_avl_node_t *n;
+       int cmp;
+
+       n = t->root;
+       while (n != NULL)
+       {
+               cmp = t->compare (key, n->key);
+               if (cmp == 0)
+                       return (n);
+               else if (cmp < 0)
+                       n = n->left;
+               else
+                       n = n->right;
+       }
+
+       return (NULL);
+}
+
+/*         (x)             (y)
+ *        /   \           /   \
+ *     (y)    /\         /\    (x)
+ *    /   \  /_c\  ==>  / a\  /   \
+ *   /\   /\           /____\/\   /\
+ *  / a\ /_b\               /_b\ /_c\
+ * /____\
+ */
+static c_avl_node_t *rotate_right (c_avl_tree_t *t, c_avl_node_t *x)
+{
+       c_avl_node_t *p;
+       c_avl_node_t *y;
+       c_avl_node_t *b;
+
+       assert (x != NULL);
+       assert (x->left != NULL);
+
+       p = x->parent;
+       y = x->left;
+       b = y->right;
+
+       x->left = b;
+       if (b != NULL)
+               b->parent = x;
+
+       x->parent = y;
+       y->right = x;
+
+       y->parent = p;
+       assert ((p == NULL) || (p->left == x) || (p->right == x));
+       if (p == NULL)
+               t->root = y;
+       else if (p->left == x)
+               p->left = y;
+       else
+               p->right = y;
+
+       x->height = calc_height (x);
+       y->height = calc_height (y);
+
+       return (y);
+} /* void rotate_right */
+
+/*
+ *    (x)                   (y)
+ *   /   \                 /   \
+ *  /\    (y)           (x)    /\
+ * /_a\  /   \   ==>   /   \  / c\
+ *      /\   /\       /\   /\/____\
+ *     /_b\ / c\     /_a\ /_b\
+ *         /____\
+ */
+static c_avl_node_t *rotate_left (c_avl_tree_t *t, c_avl_node_t *x)
+{
+       c_avl_node_t *p;
+       c_avl_node_t *y;
+       c_avl_node_t *b;
+
+       assert (x != NULL);
+       assert (x->right != NULL);
+
+       p = x->parent;
+       y = x->right;
+       b = y->left;
+
+       x->right = b;
+       if (b != NULL)
+               b->parent = x;
+
+       x->parent = y;
+       y->left = x;
+
+       y->parent = p;
+       assert ((p == NULL) || (p->left == x) || (p->right == x));
+       if (p == NULL)
+               t->root = y;
+       else if (p->left == x)
+               p->left = y;
+       else
+               p->right = y;
+
+       x->height = calc_height (x);
+       y->height = calc_height (y);
+
+       return (y);
+} /* void rotate_left */
+
+static c_avl_node_t *rotate_left_right (c_avl_tree_t *t, c_avl_node_t *x)
+{
+       rotate_left (t, x->left);
+       return (rotate_right (t, x));
+} /* void rotate_left_right */
+
+static c_avl_node_t *rotate_right_left (c_avl_tree_t *t, c_avl_node_t *x)
+{
+       rotate_right (t, x->right);
+       return (rotate_left (t, x));
+} /* void rotate_right_left */
+
+static void rebalance (c_avl_tree_t *t, c_avl_node_t *n)
+{
+       int b_top;
+       int b_bottom;
+
+       while (n != NULL)
+       {
+               b_top = BALANCE (n);
+               assert ((b_top >= -2) && (b_top <= 2));
+
+               if (b_top == -2)
+               {
+                       assert (n->right != NULL);
+                       b_bottom = BALANCE (n->right);
+                       assert ((b_bottom >= -1) || (b_bottom <= 1));
+                       if (b_bottom == 1)
+                               n = rotate_right_left (t, n);
+                       else
+                               n = rotate_left (t, n);
+               }
+               else if (b_top == 2)
+               {
+                       assert (n->left != NULL);
+                       b_bottom = BALANCE (n->left);
+                       assert ((b_bottom >= -1) || (b_bottom <= 1));
+                       if (b_bottom == -1)
+                               n = rotate_left_right (t, n);
+                       else
+                               n = rotate_right (t, n);
+               }
+               else
+               {
+                       int height = calc_height (n);
+                       if (height == n->height)
+                               break;
+                       n->height = height;
+               }
+
+               assert (n->height == calc_height (n));
+
+               n = n->parent;
+       } /* while (n != NULL) */
+} /* void rebalance */
+
+static c_avl_node_t *c_avl_node_next (c_avl_node_t *n)
+{
+       c_avl_node_t *r; /* return node */
+
+       if (n == NULL)
+       {
+               return (NULL);
+       }
+
+       /* If we can't descent any further, we have to backtrack to the first
+        * parent that's bigger than we, i. e. who's _left_ child we are. */
+       if (n->right == NULL)
+       {
+               r = n->parent;
+               while ((r != NULL) && (r->parent != NULL))
+               {
+                       if (r->left == n)
+                               break;
+                       n = r;
+                       r = n->parent;
+               }
+
+               /* n->right == NULL && r == NULL => t is root and has no next
+                * r->left != n => r->right = n => r->parent == NULL */
+               if ((r == NULL) || (r->left != n))
+               {
+                       assert ((r == NULL) || (r->parent == NULL));
+                       return (NULL);
+               }
+               else
+               {
+                       assert (r->left == n);
+                       return (r);
+               }
+       }
+       else
+       {
+               r = n->right;
+               while (r->left != NULL)
+                       r = r->left;
+       }
+
+       return (r);
+} /* c_avl_node_t *c_avl_node_next */
+
+static c_avl_node_t *c_avl_node_prev (c_avl_node_t *n)
+{
+       c_avl_node_t *r; /* return node */
+
+       if (n == NULL)
+       {
+               return (NULL);
+       }
+
+       /* If we can't descent any further, we have to backtrack to the first
+        * parent that's smaller than we, i. e. who's _right_ child we are. */
+       if (n->left == NULL)
+       {
+               r = n->parent;
+               while ((r != NULL) && (r->parent != NULL))
+               {
+                       if (r->right == n)
+                               break;
+                       n = r;
+                       r = n->parent;
+               }
+
+               /* n->left == NULL && r == NULL => t is root and has no next
+                * r->right != n => r->left = n => r->parent == NULL */
+               if ((r == NULL) || (r->right != n))
+               {
+                       assert ((r == NULL) || (r->parent == NULL));
+                       return (NULL);
+               }
+               else
+               {
+                       assert (r->right == n);
+                       return (r);
+               }
+       }
+       else
+       {
+               r = n->left;
+               while (r->right != NULL)
+                       r = r->right;
+       }
+
+       return (r);
+} /* c_avl_node_t *c_avl_node_prev */
+
+static int _remove (c_avl_tree_t *t, c_avl_node_t *n)
+{
+       assert ((t != NULL) && (n != NULL));
+
+       if ((n->left != NULL) && (n->right != NULL))
+       {
+               c_avl_node_t *r; /* replacement node */
+               if (BALANCE (n) > 0) /* left subtree is higher */
+               {
+                       assert (n->left != NULL);
+                       r = c_avl_node_prev (n);
+                       
+               }
+               else /* right subtree is higher */
+               {
+                       assert (n->right != NULL);
+                       r = c_avl_node_next (n);
+               }
+
+               assert ((r->left == NULL) || (r->right == NULL));
+
+               /* copy content */
+               n->key   = r->key;
+               n->value = r->value;
+
+               n = r;
+       }
+
+       assert ((n->left == NULL) || (n->right == NULL));
+
+       if ((n->left == NULL) && (n->right == NULL))
+       {
+               /* Deleting a leave is easy */
+               if (n->parent == NULL)
+               {
+                       assert (t->root == n);
+                       t->root = NULL;
+               }
+               else
+               {
+                       assert ((n->parent->left == n)
+                                       || (n->parent->right == n));
+                       if (n->parent->left == n)
+                               n->parent->left = NULL;
+                       else
+                               n->parent->right = NULL;
+
+                       rebalance (t, n->parent);
+               }
+
+               free_node (n);
+       }
+       else if (n->left == NULL)
+       {
+               assert (BALANCE (n) == -1);
+               assert ((n->parent == NULL) || (n->parent->left == n) || (n->parent->right == n));
+               if (n->parent == NULL)
+               {
+                       assert (t->root == n);
+                       t->root = n->right;
+               }
+               else if (n->parent->left == n)
+               {
+                       n->parent->left = n->right;
+               }
+               else
+               {
+                       n->parent->right = n->right;
+               }
+               n->right->parent = n->parent;
+
+               if (n->parent != NULL)
+                       rebalance (t, n->parent);
+
+               n->right = NULL;
+               free_node (n);
+       }
+       else if (n->right == NULL)
+       {
+               assert (BALANCE (n) == 1);
+               assert ((n->parent == NULL) || (n->parent->left == n) || (n->parent->right == n));
+               if (n->parent == NULL)
+               {
+                       assert (t->root == n);
+                       t->root = n->left;
+               }
+               else if (n->parent->left == n)
+               {
+                       n->parent->left = n->left;
+               }
+               else
+               {
+                       n->parent->right = n->left;
+               }
+               n->left->parent = n->parent;
+
+               if (n->parent != NULL)
+                       rebalance (t, n->parent);
+
+               n->left = NULL;
+               free_node (n);
+       }
+       else
+       {
+               assert (0);
+       }
+
+       return (0);
+} /* void *_remove */
+
+/*
+ * public functions
+ */
+c_avl_tree_t *c_avl_create (int (*compare) (const void *, const void *))
+{
+       c_avl_tree_t *t;
+
+       if (compare == NULL)
+               return (NULL);
+
+       if ((t = (c_avl_tree_t *) malloc (sizeof (c_avl_tree_t))) == NULL)
+               return (NULL);
+
+       t->root = NULL;
+       t->compare = compare;
+       t->size = 0;
+
+       return (t);
+}
+
+void c_avl_destroy (c_avl_tree_t *t)
+{
+       if (t == NULL)
+               return;
+       free_node (t->root);
+       free (t);
+}
+
+int c_avl_insert (c_avl_tree_t *t, void *key, void *value)
+{
+       c_avl_node_t *new;
+       c_avl_node_t *nptr;
+       int cmp;
+
+       if ((new = (c_avl_node_t *) malloc (sizeof (c_avl_node_t))) == NULL)
+               return (-1);
+
+       new->key = key;
+       new->value = value;
+       new->height = 1;
+       new->left = NULL;
+       new->right = NULL;
+
+       if (t->root == NULL)
+       {
+               new->parent = NULL;
+               t->root = new;
+               t->size = 1;
+               return (0);
+       }
+
+       nptr = t->root;
+       while (42)
+       {
+               cmp = t->compare (nptr->key, new->key);
+               if (cmp == 0)
+               {
+                       free_node (new);
+                       return (1);
+               }
+               else if (cmp < 0)
+               {
+                       /* nptr < new */
+                       if (nptr->right == NULL)
+                       {
+                               nptr->right = new;
+                               new->parent = nptr;
+                               rebalance (t, nptr);
+                               break;
+                       }
+                       else
+                       {
+                               nptr = nptr->right;
+                       }
+               }
+               else /* if (cmp > 0) */
+               {
+                       /* nptr > new */
+                       if (nptr->left == NULL)
+                       {
+                               nptr->left = new;
+                               new->parent = nptr;
+                               rebalance (t, nptr);
+                               break;
+                       }
+                       else
+                       {
+                               nptr = nptr->left;
+                       }
+               }
+       } /* while (42) */
+
+       verify_tree (t->root);
+       ++t->size;
+       return (0);
+} /* int c_avl_insert */
+
+int c_avl_remove (c_avl_tree_t *t, const void *key, void **rkey, void **rvalue)
+{
+       c_avl_node_t *n;
+       int status;
+
+       assert (t != NULL);
+
+       n = search (t, key);
+       if (n == NULL)
+               return (-1);
+
+       if (rkey != NULL)
+               *rkey = n->key;
+       if (rvalue != NULL)
+               *rvalue = n->value;
+
+       status = _remove (t, n);
+       verify_tree (t->root);
+       --t->size;
+       return (status);
+} /* void *c_avl_remove */
+
+int c_avl_get (c_avl_tree_t *t, const void *key, void **value)
+{
+       c_avl_node_t *n;
+
+       assert (t != NULL);
+
+       n = search (t, key);
+       if (n == NULL)
+               return (-1);
+
+       if (value != NULL)
+               *value = n->value;
+
+       return (0);
+}
+
+int c_avl_pick (c_avl_tree_t *t, void **key, void **value)
+{
+       c_avl_node_t *n;
+       c_avl_node_t *p;
+
+       if ((key == NULL) || (value == NULL))
+               return (-1);
+       if (t->root == NULL)
+               return (-1);
+
+       n = t->root;
+       while ((n->left != NULL) || (n->right != NULL))
+       {
+               if (n->left == NULL)
+               {
+                       n = n->right;
+                       continue;
+               }
+               else if (n->right == NULL)
+               {
+                       n = n->left;
+                       continue;
+               }
+
+               if (n->left->height > n->right->height)
+                       n = n->left;
+               else
+                       n = n->right;
+       }
+
+       p = n->parent;
+       if (p == NULL)
+               t->root = NULL;
+       else if (p->left == n)
+               p->left = NULL;
+       else
+               p->right = NULL;
+
+       *key   = n->key;
+       *value = n->value;
+
+       free_node (n);
+       rebalance (t, p);
+
+       return (0);
+} /* int c_avl_pick */
+
+c_avl_iterator_t *c_avl_get_iterator (c_avl_tree_t *t)
+{
+       c_avl_iterator_t *iter;
+
+       if (t == NULL)
+               return (NULL);
+
+       iter = (c_avl_iterator_t *) malloc (sizeof (c_avl_iterator_t));
+       if (iter == NULL)
+               return (NULL);
+       memset (iter, '\0', sizeof (c_avl_iterator_t));
+       iter->tree = t;
+
+       return (iter);
+} /* c_avl_iterator_t *c_avl_get_iterator */
+
+int c_avl_iterator_next (c_avl_iterator_t *iter, void **key, void **value)
+{
+       c_avl_node_t *n;
+
+       if ((iter == NULL) || (key == NULL) || (value == NULL))
+               return (-1);
+
+       if (iter->node == NULL)
+       {
+               for (n = iter->tree->root; n != NULL; n = n->left)
+                       if (n->left == NULL)
+                               break;
+               iter->node = n;
+       }
+       else
+       {
+               n = c_avl_node_next (iter->node);
+       }
+
+       if (n == NULL)
+               return (-1);
+
+       iter->node = n;
+       *key = n->key;
+       *value = n->value;
+
+       return (0);
+} /* int c_avl_iterator_next */
+
+int c_avl_iterator_prev (c_avl_iterator_t *iter, void **key, void **value)
+{
+       c_avl_node_t *n;
+
+       if ((iter == NULL) || (key == NULL) || (value == NULL))
+               return (-1);
+
+       if (iter->node == NULL)
+       {
+               for (n = iter->tree->root; n != NULL; n = n->left)
+                       if (n->right == NULL)
+                               break;
+               iter->node = n;
+       }
+       else
+       {
+               n = c_avl_node_prev (iter->node);
+       }
+
+       if (n == NULL)
+               return (-1);
+
+       iter->node = n;
+       *key = n->key;
+       *value = n->value;
+
+       return (0);
+} /* int c_avl_iterator_prev */
+
+void c_avl_iterator_destroy (c_avl_iterator_t *iter)
+{
+       free (iter);
+}
+
+int c_avl_size (c_avl_tree_t *t)
+{
+       if (t == NULL)
+               return (0);
+       return (t->size);
+}
diff --git a/src/daemon/utils_avltree.h b/src/daemon/utils_avltree.h
new file mode 100644 (file)
index 0000000..1e0f271
--- /dev/null
@@ -0,0 +1,170 @@
+/**
+ * collectd - src/utils_avltree.h
+ * Copyright (C) 2006,2007  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>
+ **/
+
+#ifndef UTILS_AVLTREE_H
+#define UTILS_AVLTREE_H 1
+
+struct c_avl_tree_s;
+typedef struct c_avl_tree_s c_avl_tree_t;
+
+struct c_avl_iterator_s;
+typedef struct c_avl_iterator_s c_avl_iterator_t;
+
+/*
+ * NAME
+ *   c_avl_create
+ *
+ * DESCRIPTION
+ *   Allocates a new AVL-tree.
+ *
+ * PARAMETERS
+ *   `compare'  The function-pointer `compare' is used to compare two keys. It
+ *              has to return less than zero if it's first argument is smaller
+ *              then the second argument, more than zero if the first argument
+ *              is bigger than the second argument and zero if they are equal.
+ *              If your keys are char-pointers, you can use the `strcmp'
+ *              function from the libc here.
+ *
+ * RETURN VALUE
+ *   A c_avl_tree_t-pointer upon success or NULL upon failure.
+ */
+c_avl_tree_t *c_avl_create (int (*compare) (const void *, const void *));
+
+
+/*
+ * NAME
+ *   c_avl_destroy
+ *
+ * DESCRIPTION
+ *   Deallocates an AVL-tree. Stored value- and key-pointer are lost, but of
+ *   course not freed.
+ */
+void c_avl_destroy (c_avl_tree_t *t);
+
+/*
+ * NAME
+ *   c_avl_insert
+ *
+ * DESCRIPTION
+ *   Stores the key-value-pair in the AVL-tree pointed to by `t'.
+ *
+ * PARAMETERS
+ *   `t'        AVL-tree to store the data in.
+ *   `key'      Key used to store the value under. This is used to get back to
+ *              the value again. The pointer is stored in an internal structure
+ *              and _not_ copied. So the memory pointed to may _not_ be freed
+ *              before this entry is removed. You can use the `rkey' argument
+ *              to `avl_remove' to get the original pointer back and free it.
+ *   `value'    Value to be stored.
+ *
+ * RETURN VALUE
+ *   Zero upon success, non-zero otherwise. It's less than zero if an error
+ *   occurred or greater than zero if the key is already stored in the tree.
+ */
+int c_avl_insert (c_avl_tree_t *t, void *key, void *value);
+
+/*
+ * NAME
+ *   c_avl_remove
+ *
+ * DESCRIPTION
+ *   Removes a key-value-pair from the tree t. The stored key and value may be
+ *   returned in `rkey' and `rvalue'.
+ *
+ * PARAMETERS
+ *   `t'       AVL-tree to remove key-value-pair from.
+ *   `key'      Key to identify the entry.
+ *   `rkey'     Pointer to a pointer in which to store the key. May be NULL.
+ *              Since the `key' pointer is not copied when creating an entry,
+ *              the pointer may not be available anymore from outside the tree.
+ *              You can use this argument to get the actual pointer back and
+ *              free the memory pointed to by it.
+ *   `rvalue'   Pointer to a pointer in which to store the value. May be NULL.
+ *
+ * RETURN VALUE
+ *   Zero upon success or non-zero if the key isn't found in the tree.
+ */
+int c_avl_remove (c_avl_tree_t *t, const void *key, void **rkey, void **rvalue);
+
+/*
+ * NAME
+ *   c_avl_get
+ *
+ * DESCRIPTION
+ *   Retrieve the `value' belonging to `key'.
+ *
+ * PARAMETERS
+ *   `t'       AVL-tree to get the value from.
+ *   `key'      Key to identify the entry.
+ *   `value'    Pointer to a pointer in which to store the value. May be NULL.
+ *
+ * RETURN VALUE
+ *   Zero upon success or non-zero if the key isn't found in the tree.
+ */
+int c_avl_get (c_avl_tree_t *t, const void *key, void **value);
+
+/*
+ * NAME
+ *   c_avl_pick
+ *
+ * DESCRIPTION
+ *   Remove a (pseudo-)random element from the tree and return it's `key' and
+ *   `value'. Entries are not returned in any particular order. This function
+ *   is intended for cache-flushes that don't care about the order but simply
+ *   want to remove all elements, one at a time.
+ *
+ * PARAMETERS
+ *   `t'       AVL-tree to get the value from.
+ *   `key'      Pointer to a pointer in which to store the key.
+ *   `value'    Pointer to a pointer in which to store the value.
+ *
+ * RETURN VALUE
+ *   Zero upon success or non-zero if the tree is empty or key or value is
+ *   NULL.
+ */
+int c_avl_pick (c_avl_tree_t *t, void **key, void **value);
+
+c_avl_iterator_t *c_avl_get_iterator (c_avl_tree_t *t);
+int c_avl_iterator_next (c_avl_iterator_t *iter, void **key, void **value);
+int c_avl_iterator_prev (c_avl_iterator_t *iter, void **key, void **value);
+void c_avl_iterator_destroy (c_avl_iterator_t *iter);
+
+/*
+ * NAME
+ *   c_avl_size
+ *
+ * DESCRIPTION
+ *   Return the size (number of nodes) of the specified tree.
+ *
+ * PARAMETERS
+ *   `t'        AVL-tree to get the size of.
+ *
+ * RETURN VALUE
+ *   Number of nodes in the tree, 0 if the tree is empty or NULL.
+ */
+int c_avl_size (c_avl_tree_t *t);
+
+#endif /* UTILS_AVLTREE_H */
diff --git a/src/daemon/utils_avltree_test.c b/src/daemon/utils_avltree_test.c
new file mode 100644 (file)
index 0000000..2a8244c
--- /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 "testing.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/daemon/utils_cache.c b/src/daemon/utils_cache.c
new file mode 100644 (file)
index 0000000..7621395
--- /dev/null
@@ -0,0 +1,997 @@
+/**
+ * collectd - src/utils_cache.c
+ * Copyright (C) 2007-2010  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 "common.h"
+#include "plugin.h"
+#include "utils_avltree.h"
+#include "utils_cache.h"
+#include "meta_data.h"
+
+#include <assert.h>
+#include <pthread.h>
+
+typedef struct cache_entry_s
+{
+       char name[6 * DATA_MAX_NAME_LEN];
+       int        values_num;
+       gauge_t   *values_gauge;
+       value_t   *values_raw;
+       /* Time contained in the package
+        * (for calculating rates) */
+       cdtime_t last_time;
+       /* Time according to the local clock
+        * (for purging old entries) */
+       cdtime_t last_update;
+       /* Interval in which the data is collected
+        * (for purding old entries) */
+       cdtime_t interval;
+       int state;
+       int hits;
+
+       /*
+        * +-----+-----+-----+-----+-----+-----+-----+-----+-----+----
+        * !  0  !  1  !  2  !  3  !  4  !  5  !  6  !  7  !  8  ! ...
+        * +-----+-----+-----+-----+-----+-----+-----+-----+-----+----
+        * ! ds0 ! ds1 ! ds2 ! ds0 ! ds1 ! ds2 ! ds0 ! ds1 ! ds2 ! ...
+        * +-----+-----+-----+-----+-----+-----+-----+-----+-----+----
+        * !      t = 0      !      t = 1      !      t = 2      ! ...
+        * +-----------------+-----------------+-----------------+----
+        */
+       gauge_t *history;
+       size_t   history_index; /* points to the next position to write to. */
+       size_t   history_length;
+
+       meta_data_t *meta;
+} cache_entry_t;
+
+static c_avl_tree_t   *cache_tree = NULL;
+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 */
+
+static cache_entry_t *cache_alloc (int values_num)
+{
+  cache_entry_t *ce;
+
+  ce = (cache_entry_t *) malloc (sizeof (cache_entry_t));
+  if (ce == NULL)
+  {
+    ERROR ("utils_cache: cache_alloc: malloc failed.");
+    return (NULL);
+  }
+  memset (ce, '\0', sizeof (cache_entry_t));
+  ce->values_num = values_num;
+
+  ce->values_gauge = calloc (values_num, sizeof (*ce->values_gauge));
+  ce->values_raw   = calloc (values_num, sizeof (*ce->values_raw));
+  if ((ce->values_gauge == NULL) || (ce->values_raw == NULL))
+  {
+    sfree (ce->values_gauge);
+    sfree (ce->values_raw);
+    sfree (ce);
+    ERROR ("utils_cache: cache_alloc: calloc failed.");
+    return (NULL);
+  }
+
+  ce->history = NULL;
+  ce->history_length = 0;
+  ce->meta = NULL;
+
+  return (ce);
+} /* cache_entry_t *cache_alloc */
+
+static void cache_free (cache_entry_t *ce)
+{
+  if (ce == NULL)
+    return;
+
+  sfree (ce->values_gauge);
+  sfree (ce->values_raw);
+  sfree (ce->history);
+  if (ce->meta != NULL)
+  {
+    meta_data_destroy (ce->meta);
+    ce->meta = NULL;
+  }
+  sfree (ce);
+} /* void cache_free */
+
+static void uc_check_range (const data_set_t *ds, cache_entry_t *ce)
+{
+  int i;
+
+  for (i = 0; i < ds->ds_num; i++)
+  {
+    if (isnan (ce->values_gauge[i]))
+      continue;
+    else if (ce->values_gauge[i] < ds->ds[i].min)
+      ce->values_gauge[i] = NAN;
+    else if (ce->values_gauge[i] > ds->ds[i].max)
+      ce->values_gauge[i] = NAN;
+  }
+} /* void uc_check_range */
+
+static int uc_insert (const data_set_t *ds, const value_list_t *vl,
+    const char *key)
+{
+  int i;
+  char *key_copy;
+  cache_entry_t *ce;
+
+  /* `cache_lock' has been locked by `uc_update' */
+
+  key_copy = strdup (key);
+  if (key_copy == NULL)
+  {
+    ERROR ("uc_insert: strdup failed.");
+    return (-1);
+  }
+
+  ce = cache_alloc (ds->ds_num);
+  if (ce == NULL)
+  {
+    sfree (key_copy);
+    ERROR ("uc_insert: cache_alloc (%i) failed.", ds->ds_num);
+    return (-1);
+  }
+
+  sstrncpy (ce->name, key, sizeof (ce->name));
+
+  for (i = 0; i < ds->ds_num; i++)
+  {
+    switch (ds->ds[i].type)
+    {
+      case DS_TYPE_COUNTER:
+       ce->values_gauge[i] = NAN;
+       ce->values_raw[i].counter = vl->values[i].counter;
+       break;
+
+      case DS_TYPE_GAUGE:
+       ce->values_gauge[i] = vl->values[i].gauge;
+       ce->values_raw[i].gauge = vl->values[i].gauge;
+       break;
+
+      case DS_TYPE_DERIVE:
+       ce->values_gauge[i] = NAN;
+       ce->values_raw[i].derive = vl->values[i].derive;
+       break;
+
+      case DS_TYPE_ABSOLUTE:
+       ce->values_gauge[i] = NAN;
+       if (vl->interval > 0)
+         ce->values_gauge[i] = ((double) vl->values[i].absolute)
+           / CDTIME_T_TO_DOUBLE (vl->interval);
+       ce->values_raw[i].absolute = vl->values[i].absolute;
+       break;
+       
+      default:
+       /* This shouldn't happen. */
+       ERROR ("uc_insert: Don't know how to handle data source type %i.",
+           ds->ds[i].type);
+       sfree (key_copy);
+       return (-1);
+    } /* switch (ds->ds[i].type) */
+  } /* for (i) */
+
+  /* Prune invalid gauge data */
+  uc_check_range (ds, ce);
+
+  ce->last_time = vl->time;
+  ce->last_update = cdtime ();
+  ce->interval = vl->interval;
+  ce->state = STATE_OKAY;
+
+  if (c_avl_insert (cache_tree, key_copy, ce) != 0)
+  {
+    sfree (key_copy);
+    ERROR ("uc_insert: c_avl_insert failed.");
+    return (-1);
+  }
+
+  DEBUG ("uc_insert: Added %s to the cache.", key);
+  return (0);
+} /* int uc_insert */
+
+int uc_init (void)
+{
+  if (cache_tree == NULL)
+    cache_tree = c_avl_create ((int (*) (const void *, const void *))
+       cache_compare);
+
+  return (0);
+} /* int uc_init */
+
+int uc_check_timeout (void)
+{
+  cdtime_t now;
+  cache_entry_t *ce;
+
+  char **keys = NULL;
+  cdtime_t *keys_time = NULL;
+  cdtime_t *keys_interval = NULL;
+  int keys_len = 0;
+
+  char *key;
+  c_avl_iterator_t *iter;
+
+  int status;
+  int i;
+  
+  pthread_mutex_lock (&cache_lock);
+
+  now = cdtime ();
+
+  /* Build a list of entries to be flushed */
+  iter = c_avl_get_iterator (cache_tree);
+  while (c_avl_iterator_next (iter, (void *) &key, (void *) &ce) == 0)
+  {
+    char **tmp;
+    cdtime_t *tmp_time;
+
+    /* If the entry is fresh enough, continue. */
+    if ((now - ce->last_update) < (ce->interval * timeout_g))
+      continue;
+
+    /* If entry has not been updated, add to `keys' array */
+    tmp = (char **) realloc ((void *) keys,
+       (keys_len + 1) * sizeof (char *));
+    if (tmp == NULL)
+    {
+      ERROR ("uc_check_timeout: realloc failed.");
+      continue;
+    }
+    keys = tmp;
+
+    tmp_time = realloc (keys_time, (keys_len + 1) * sizeof (*keys_time));
+    if (tmp_time == NULL)
+    {
+      ERROR ("uc_check_timeout: realloc failed.");
+      continue;
+    }
+    keys_time = tmp_time;
+
+    tmp_time = realloc (keys_interval, (keys_len + 1) * sizeof (*keys_interval));
+    if (tmp_time == NULL)
+    {
+      ERROR ("uc_check_timeout: realloc failed.");
+      continue;
+    }
+    keys_interval = tmp_time;
+
+    keys[keys_len] = strdup (key);
+    if (keys[keys_len] == NULL)
+    {
+      ERROR ("uc_check_timeout: strdup failed.");
+      continue;
+    }
+    keys_time[keys_len] = ce->last_time;
+    keys_interval[keys_len] = ce->interval;
+
+    keys_len++;
+  } /* while (c_avl_iterator_next) */
+
+  c_avl_iterator_destroy (iter);
+  pthread_mutex_unlock (&cache_lock);
+
+  if (keys_len == 0)
+  {
+    /* realloc() may have been called for these. */
+    sfree (keys);
+    sfree (keys_time);
+    sfree (keys_interval);
+    return (0);
+  }
+
+  /* Call the "missing" callback for each value. Do this before removing the
+   * value from the cache, so that callbacks can still access the data stored,
+   * including plugin specific meta data, rates, history, …. This must be done
+   * without holding the lock, otherwise we will run into a deadlock if a
+   * plugin calls the cache interface. */
+  for (i = 0; i < keys_len; i++)
+  {
+    value_list_t vl = VALUE_LIST_INIT;
+
+    vl.values = NULL;
+    vl.values_len = 0;
+    vl.meta = NULL;
+
+    status = parse_identifier_vl (keys[i], &vl);
+    if (status != 0)
+    {
+      ERROR ("uc_check_timeout: parse_identifier_vl (\"%s\") failed.", keys[i]);
+      continue;
+    }
+
+    vl.time = keys_time[i];
+    vl.interval = keys_interval[i];
+
+    plugin_dispatch_missing (&vl);
+  } /* for (i = 0; i < keys_len; i++) */
+
+  /* Now actually remove all the values from the cache. We don't re-evaluate
+   * the timestamp again, so in theory it is possible we remove a value after
+   * it is updated here. */
+  pthread_mutex_lock (&cache_lock);
+  for (i = 0; i < keys_len; i++)
+  {
+    key = NULL;
+    ce = NULL;
+
+    status = c_avl_remove (cache_tree, keys[i],
+       (void *) &key, (void *) &ce);
+    if (status != 0)
+    {
+      ERROR ("uc_check_timeout: c_avl_remove (\"%s\") failed.", keys[i]);
+      sfree (keys[i]);
+      continue;
+    }
+
+    sfree (keys[i]);
+    sfree (key);
+    cache_free (ce);
+  } /* for (i = 0; i < keys_len; i++) */
+  pthread_mutex_unlock (&cache_lock);
+
+  sfree (keys);
+  sfree (keys_time);
+  sfree (keys_interval);
+
+  return (0);
+} /* int uc_check_timeout */
+
+int uc_update (const data_set_t *ds, const value_list_t *vl)
+{
+  char name[6 * DATA_MAX_NAME_LEN];
+  cache_entry_t *ce = NULL;
+  int status;
+  int i;
+
+  if (FORMAT_VL (name, sizeof (name), vl) != 0)
+  {
+    ERROR ("uc_update: FORMAT_VL failed.");
+    return (-1);
+  }
+
+  pthread_mutex_lock (&cache_lock);
+
+  status = c_avl_get (cache_tree, name, (void *) &ce);
+  if (status != 0) /* entry does not yet exist */
+  {
+    status = uc_insert (ds, vl, name);
+    pthread_mutex_unlock (&cache_lock);
+    return (status);
+  }
+
+  assert (ce != NULL);
+  assert (ce->values_num == ds->ds_num);
+
+  if (ce->last_time >= vl->time)
+  {
+    pthread_mutex_unlock (&cache_lock);
+    NOTICE ("uc_update: Value too old: name = %s; value time = %.3f; "
+       "last cache update = %.3f;",
+       name,
+       CDTIME_T_TO_DOUBLE (vl->time),
+       CDTIME_T_TO_DOUBLE (ce->last_time));
+    return (-1);
+  }
+
+  for (i = 0; i < ds->ds_num; i++)
+  {
+    switch (ds->ds[i].type)
+    {
+      case DS_TYPE_COUNTER:
+       {
+         counter_t diff;
+
+         /* check if the counter has wrapped around */
+         if (vl->values[i].counter < ce->values_raw[i].counter)
+         {
+           if (ce->values_raw[i].counter <= 4294967295U)
+             diff = (4294967295U - ce->values_raw[i].counter)
+               + vl->values[i].counter;
+           else
+             diff = (18446744073709551615ULL - ce->values_raw[i].counter)
+               + vl->values[i].counter;
+         }
+         else /* counter has NOT wrapped around */
+         {
+           diff = vl->values[i].counter - ce->values_raw[i].counter;
+         }
+
+         ce->values_gauge[i] = ((double) diff)
+           / (CDTIME_T_TO_DOUBLE (vl->time - ce->last_time));
+         ce->values_raw[i].counter = vl->values[i].counter;
+       }
+       break;
+
+      case DS_TYPE_GAUGE:
+       ce->values_raw[i].gauge = vl->values[i].gauge;
+       ce->values_gauge[i] = vl->values[i].gauge;
+       break;
+
+      case DS_TYPE_DERIVE:
+       {
+         derive_t diff;
+
+         diff = vl->values[i].derive - ce->values_raw[i].derive;
+
+         ce->values_gauge[i] = ((double) diff)
+           / (CDTIME_T_TO_DOUBLE (vl->time - ce->last_time));
+         ce->values_raw[i].derive = vl->values[i].derive;
+       }
+       break;
+
+      case DS_TYPE_ABSOLUTE:
+       ce->values_gauge[i] = ((double) vl->values[i].absolute)
+         / (CDTIME_T_TO_DOUBLE (vl->time - ce->last_time));
+       ce->values_raw[i].absolute = vl->values[i].absolute;
+       break;
+
+      default:
+       /* This shouldn't happen. */
+       pthread_mutex_unlock (&cache_lock);
+       ERROR ("uc_update: Don't know how to handle data source type %i.",
+           ds->ds[i].type);
+       return (-1);
+    } /* switch (ds->ds[i].type) */
+
+    DEBUG ("uc_update: %s: ds[%i] = %lf", name, i, ce->values_gauge[i]);
+  } /* for (i) */
+
+  /* Update the history if it exists. */
+  if (ce->history != NULL)
+  {
+    assert (ce->history_index < ce->history_length);
+    for (i = 0; i < ce->values_num; i++)
+    {
+      size_t hist_idx = (ce->values_num * ce->history_index) + i;
+      ce->history[hist_idx] = ce->values_gauge[i];
+    }
+
+    assert (ce->history_length > 0);
+    ce->history_index = (ce->history_index + 1) % ce->history_length;
+  }
+
+  /* Prune invalid gauge data */
+  uc_check_range (ds, ce);
+
+  ce->last_time = vl->time;
+  ce->last_update = cdtime ();
+  ce->interval = vl->interval;
+
+  pthread_mutex_unlock (&cache_lock);
+
+  return (0);
+} /* int uc_update */
+
+int uc_get_rate_by_name (const char *name, gauge_t **ret_values, size_t *ret_values_num)
+{
+  gauge_t *ret = NULL;
+  size_t ret_num = 0;
+  cache_entry_t *ce = NULL;
+  int status = 0;
+
+  pthread_mutex_lock (&cache_lock);
+
+  if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
+  {
+    assert (ce != NULL);
+
+    /* remove missing values from getval */
+    if (ce->state == STATE_MISSING)
+    {
+      status = -1;
+    }
+    else
+    {
+      ret_num = ce->values_num;
+      ret = (gauge_t *) malloc (ret_num * sizeof (gauge_t));
+      if (ret == NULL)
+      {
+        ERROR ("utils_cache: uc_get_rate_by_name: malloc failed.");
+        status = -1;
+      }
+      else
+      {
+        memcpy (ret, ce->values_gauge, ret_num * sizeof (gauge_t));
+      }
+    }
+  }
+  else
+  {
+    DEBUG ("utils_cache: uc_get_rate_by_name: No such value: %s", name);
+    status = -1;
+  }
+
+  pthread_mutex_unlock (&cache_lock);
+
+  if (status == 0)
+  {
+    *ret_values = ret;
+    *ret_values_num = ret_num;
+  }
+
+  return (status);
+} /* gauge_t *uc_get_rate_by_name */
+
+gauge_t *uc_get_rate (const data_set_t *ds, const value_list_t *vl)
+{
+  char name[6 * DATA_MAX_NAME_LEN];
+  gauge_t *ret = NULL;
+  size_t ret_num = 0;
+  int status;
+
+  if (FORMAT_VL (name, sizeof (name), vl) != 0)
+  {
+    ERROR ("utils_cache: uc_get_rate: FORMAT_VL failed.");
+    return (NULL);
+  }
+
+  status = uc_get_rate_by_name (name, &ret, &ret_num);
+  if (status != 0)
+    return (NULL);
+
+  /* This is important - the caller has no other way of knowing how many
+   * values are returned. */
+  if (ret_num != (size_t) ds->ds_num)
+  {
+    ERROR ("utils_cache: uc_get_rate: ds[%s] has %i values, "
+       "but uc_get_rate_by_name returned %zu.",
+       ds->type, ds->ds_num, ret_num);
+    sfree (ret);
+    return (NULL);
+  }
+
+  return (ret);
+} /* gauge_t *uc_get_rate */
+
+size_t uc_get_size() {
+  size_t size_arrays = 0;
+
+  pthread_mutex_lock (&cache_lock);
+  size_arrays = (size_t) c_avl_size (cache_tree);
+  pthread_mutex_unlock (&cache_lock);
+
+  return (size_arrays);
+}
+
+int uc_get_names (char ***ret_names, cdtime_t **ret_times, size_t *ret_number)
+{
+  c_avl_iterator_t *iter;
+  char *key;
+  cache_entry_t *value;
+
+  char **names = NULL;
+  cdtime_t *times = NULL;
+  size_t number = 0;
+  size_t size_arrays = 0;
+
+  int status = 0;
+
+  if ((ret_names == NULL) || (ret_number == NULL))
+    return (-1);
+
+  pthread_mutex_lock (&cache_lock);
+
+  size_arrays = (size_t) c_avl_size (cache_tree);
+  if (size_arrays < 1)
+  {
+    /* Handle the "no values" case here, to avoid the error message when
+     * calloc() returns NULL. */
+    pthread_mutex_unlock (&cache_lock);
+    return (0);
+  }
+
+  names = calloc (size_arrays, sizeof (*names));
+  times = calloc (size_arrays, sizeof (*times));
+  if ((names == NULL) || (times == NULL))
+  {
+    ERROR ("uc_get_names: calloc failed.");
+    sfree (names);
+    sfree (times);
+    pthread_mutex_unlock (&cache_lock);
+    return (ENOMEM);
+  }
+
+  iter = c_avl_get_iterator (cache_tree);
+  while (c_avl_iterator_next (iter, (void *) &key, (void *) &value) == 0)
+  {
+    /* remove missing values when list values */
+    if (value->state == STATE_MISSING)
+      continue;
+
+    /* c_avl_size does not return a number smaller than the number of elements
+     * returned by c_avl_iterator_next. */
+    assert (number < size_arrays);
+
+    if (ret_times != NULL)
+      times[number] = value->last_time;
+
+    names[number] = strdup (key);
+    if (names[number] == NULL)
+    {
+      status = -1;
+      break;
+    }
+
+    number++;
+  } /* while (c_avl_iterator_next) */
+
+  c_avl_iterator_destroy (iter);
+  pthread_mutex_unlock (&cache_lock);
+
+  if (status != 0)
+  {
+    size_t i;
+
+    for (i = 0; i < number; i++)
+    {
+      sfree (names[i]);
+    }
+    sfree (names);
+    sfree (times);
+
+    return (-1);
+  }
+
+  *ret_names = names;
+  if (ret_times != NULL)
+    *ret_times = times;
+  else
+    sfree (times);
+  *ret_number = number;
+
+  return (0);
+} /* int uc_get_names */
+
+int uc_get_state (const data_set_t *ds, const value_list_t *vl)
+{
+  char name[6 * DATA_MAX_NAME_LEN];
+  cache_entry_t *ce = NULL;
+  int ret = STATE_ERROR;
+
+  if (FORMAT_VL (name, sizeof (name), vl) != 0)
+  {
+    ERROR ("uc_get_state: FORMAT_VL failed.");
+    return (STATE_ERROR);
+  }
+
+  pthread_mutex_lock (&cache_lock);
+
+  if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
+  {
+    assert (ce != NULL);
+    ret = ce->state;
+  }
+
+  pthread_mutex_unlock (&cache_lock);
+
+  return (ret);
+} /* int uc_get_state */
+
+int uc_set_state (const data_set_t *ds, const value_list_t *vl, int state)
+{
+  char name[6 * DATA_MAX_NAME_LEN];
+  cache_entry_t *ce = NULL;
+  int ret = -1;
+
+  if (FORMAT_VL (name, sizeof (name), vl) != 0)
+  {
+    ERROR ("uc_get_state: FORMAT_VL failed.");
+    return (STATE_ERROR);
+  }
+
+  pthread_mutex_lock (&cache_lock);
+
+  if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
+  {
+    assert (ce != NULL);
+    ret = ce->state;
+    ce->state = state;
+  }
+
+  pthread_mutex_unlock (&cache_lock);
+
+  return (ret);
+} /* int uc_set_state */
+
+int uc_get_history_by_name (const char *name,
+    gauge_t *ret_history, size_t num_steps, size_t num_ds)
+{
+  cache_entry_t *ce = NULL;
+  size_t i;
+  int status = 0;
+
+  pthread_mutex_lock (&cache_lock);
+
+  status = c_avl_get (cache_tree, name, (void *) &ce);
+  if (status != 0)
+  {
+    pthread_mutex_unlock (&cache_lock);
+    return (-ENOENT);
+  }
+
+  if (((size_t) ce->values_num) != num_ds)
+  {
+    pthread_mutex_unlock (&cache_lock);
+    return (-EINVAL);
+  }
+
+  /* Check if there are enough values available. If not, increase the buffer
+   * size. */
+  if (ce->history_length < num_steps)
+  {
+    gauge_t *tmp;
+    size_t i;
+
+    tmp = realloc (ce->history, sizeof (*ce->history)
+       * num_steps * ce->values_num);
+    if (tmp == NULL)
+    {
+      pthread_mutex_unlock (&cache_lock);
+      return (-ENOMEM);
+    }
+
+    for (i = ce->history_length * ce->values_num;
+       i < (num_steps * ce->values_num);
+       i++)
+      tmp[i] = NAN;
+
+    ce->history = tmp;
+    ce->history_length = num_steps;
+  } /* if (ce->history_length < num_steps) */
+
+  /* Copy the values to the output buffer. */
+  for (i = 0; i < num_steps; i++)
+  {
+    size_t src_index;
+    size_t dst_index;
+
+    if (i < ce->history_index)
+      src_index = ce->history_index - (i + 1);
+    else
+      src_index = ce->history_length + ce->history_index - (i + 1);
+    src_index = src_index * num_ds;
+
+    dst_index = i * num_ds;
+
+    memcpy (ret_history + dst_index, ce->history + src_index,
+       sizeof (*ret_history) * num_ds);
+  }
+
+  pthread_mutex_unlock (&cache_lock);
+
+  return (0);
+} /* int uc_get_history_by_name */
+
+int uc_get_history (const data_set_t *ds, const value_list_t *vl,
+    gauge_t *ret_history, size_t num_steps, size_t num_ds)
+{
+  char name[6 * DATA_MAX_NAME_LEN];
+
+  if (FORMAT_VL (name, sizeof (name), vl) != 0)
+  {
+    ERROR ("utils_cache: uc_get_history: FORMAT_VL failed.");
+    return (-1);
+  }
+
+  return (uc_get_history_by_name (name, ret_history, num_steps, num_ds));
+} /* int uc_get_history */
+
+int uc_get_hits (const data_set_t *ds, const value_list_t *vl)
+{
+  char name[6 * DATA_MAX_NAME_LEN];
+  cache_entry_t *ce = NULL;
+  int ret = STATE_ERROR;
+
+  if (FORMAT_VL (name, sizeof (name), vl) != 0)
+  {
+    ERROR ("uc_get_state: FORMAT_VL failed.");
+    return (STATE_ERROR);
+  }
+
+  pthread_mutex_lock (&cache_lock);
+
+  if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
+  {
+    assert (ce != NULL);
+    ret = ce->hits;
+  }
+
+  pthread_mutex_unlock (&cache_lock);
+
+  return (ret);
+} /* int uc_get_hits */
+
+int uc_set_hits (const data_set_t *ds, const value_list_t *vl, int hits)
+{
+  char name[6 * DATA_MAX_NAME_LEN];
+  cache_entry_t *ce = NULL;
+  int ret = -1;
+
+  if (FORMAT_VL (name, sizeof (name), vl) != 0)
+  {
+    ERROR ("uc_get_state: FORMAT_VL failed.");
+    return (STATE_ERROR);
+  }
+
+  pthread_mutex_lock (&cache_lock);
+
+  if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
+  {
+    assert (ce != NULL);
+    ret = ce->hits;
+    ce->hits = hits;
+  }
+
+  pthread_mutex_unlock (&cache_lock);
+
+  return (ret);
+} /* int uc_set_hits */
+
+int uc_inc_hits (const data_set_t *ds, const value_list_t *vl, int step)
+{
+  char name[6 * DATA_MAX_NAME_LEN];
+  cache_entry_t *ce = NULL;
+  int ret = -1;
+
+  if (FORMAT_VL (name, sizeof (name), vl) != 0)
+  {
+    ERROR ("uc_get_state: FORMAT_VL failed.");
+    return (STATE_ERROR);
+  }
+
+  pthread_mutex_lock (&cache_lock);
+
+  if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
+  {
+    assert (ce != NULL);
+    ret = ce->hits;
+    ce->hits = ret + step;
+  }
+
+  pthread_mutex_unlock (&cache_lock);
+
+  return (ret);
+} /* int uc_inc_hits */
+
+/*
+ * Meta data interface
+ */
+/* XXX: This function will acquire `cache_lock' but will not free it! */
+static meta_data_t *uc_get_meta (const value_list_t *vl) /* {{{ */
+{
+  char name[6 * DATA_MAX_NAME_LEN];
+  cache_entry_t *ce = NULL;
+  int status;
+
+  status = FORMAT_VL (name, sizeof (name), vl);
+  if (status != 0)
+  {
+    ERROR ("utils_cache: uc_get_meta: FORMAT_VL failed.");
+    return (NULL);
+  }
+
+  pthread_mutex_lock (&cache_lock);
+
+  status = c_avl_get (cache_tree, name, (void *) &ce);
+  if (status != 0)
+  {
+    pthread_mutex_unlock (&cache_lock);
+    return (NULL);
+  }
+  assert (ce != NULL);
+
+  if (ce->meta == NULL)
+    ce->meta = meta_data_create ();
+
+  if (ce->meta == NULL)
+    pthread_mutex_unlock (&cache_lock);
+
+  return (ce->meta);
+} /* }}} meta_data_t *uc_get_meta */
+
+/* Sorry about this preprocessor magic, but it really makes this file much
+ * shorter.. */
+#define UC_WRAP(wrap_function) { \
+  meta_data_t *meta; \
+  int status; \
+  meta = uc_get_meta (vl); \
+  if (meta == NULL) return (-1); \
+  status = wrap_function (meta, key); \
+  pthread_mutex_unlock (&cache_lock); \
+  return (status); \
+}
+int uc_meta_data_exists (const value_list_t *vl, const char *key)
+  UC_WRAP (meta_data_exists)
+
+int uc_meta_data_delete (const value_list_t *vl, const char *key)
+  UC_WRAP (meta_data_delete)
+#undef UC_WRAP
+
+/* We need a new version of this macro because the following functions take
+ * two argumetns. */
+#define UC_WRAP(wrap_function) { \
+  meta_data_t *meta; \
+  int status; \
+  meta = uc_get_meta (vl); \
+  if (meta == NULL) return (-1); \
+  status = wrap_function (meta, key, value); \
+  pthread_mutex_unlock (&cache_lock); \
+  return (status); \
+}
+int uc_meta_data_add_string (const value_list_t *vl,
+    const char *key,
+    const char *value)
+  UC_WRAP(meta_data_add_string)
+int uc_meta_data_add_signed_int (const value_list_t *vl,
+    const char *key,
+    int64_t value)
+  UC_WRAP(meta_data_add_signed_int)
+int uc_meta_data_add_unsigned_int (const value_list_t *vl,
+    const char *key,
+    uint64_t value)
+  UC_WRAP(meta_data_add_unsigned_int)
+int uc_meta_data_add_double (const value_list_t *vl,
+    const char *key,
+    double value)
+  UC_WRAP(meta_data_add_double)
+int uc_meta_data_add_boolean (const value_list_t *vl,
+    const char *key,
+    _Bool value)
+  UC_WRAP(meta_data_add_boolean)
+
+int uc_meta_data_get_string (const value_list_t *vl,
+    const char *key,
+    char **value)
+  UC_WRAP(meta_data_get_string)
+int uc_meta_data_get_signed_int (const value_list_t *vl,
+    const char *key,
+    int64_t *value)
+  UC_WRAP(meta_data_get_signed_int)
+int uc_meta_data_get_unsigned_int (const value_list_t *vl,
+    const char *key,
+    uint64_t *value)
+  UC_WRAP(meta_data_get_unsigned_int)
+int uc_meta_data_get_double (const value_list_t *vl,
+    const char *key,
+    double *value)
+  UC_WRAP(meta_data_get_double)
+int uc_meta_data_get_boolean (const value_list_t *vl,
+    const char *key,
+    _Bool *value)
+  UC_WRAP(meta_data_get_boolean)
+#undef UC_WRAP
+
+/* vim: set sw=2 ts=8 sts=2 tw=78 : */
diff --git a/src/daemon/utils_cache.h b/src/daemon/utils_cache.h
new file mode 100644 (file)
index 0000000..ea3eb2f
--- /dev/null
@@ -0,0 +1,96 @@
+/**
+ * collectd - src/utils_cache.h
+ * Copyright (C) 2007       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>
+ **/
+
+#ifndef UTILS_CACHE_H
+#define UTILS_CACHE_H 1
+
+#include "plugin.h"
+
+#define STATE_OKAY     0
+#define STATE_WARNING  1
+#define STATE_ERROR    2
+#define STATE_MISSING 15
+
+int uc_init (void);
+int uc_check_timeout (void);
+int uc_update (const data_set_t *ds, const value_list_t *vl);
+int uc_get_rate_by_name (const char *name, gauge_t **ret_values, size_t *ret_values_num);
+gauge_t *uc_get_rate (const data_set_t *ds, const value_list_t *vl);
+
+size_t uc_get_size();
+int uc_get_names (char ***ret_names, cdtime_t **ret_times, size_t *ret_number);
+
+int uc_get_state (const data_set_t *ds, const value_list_t *vl);
+int uc_set_state (const data_set_t *ds, const value_list_t *vl, int state);
+int uc_get_hits (const data_set_t *ds, const value_list_t *vl);
+int uc_set_hits (const data_set_t *ds, const value_list_t *vl, int hits);
+int uc_inc_hits (const data_set_t *ds, const value_list_t *vl, int step);
+
+int uc_get_history (const data_set_t *ds, const value_list_t *vl,
+    gauge_t *ret_history, size_t num_steps, size_t num_ds);
+int uc_get_history_by_name (const char *name,
+    gauge_t *ret_history, size_t num_steps, size_t num_ds);
+
+/*
+ * Meta data interface
+ */
+int uc_meta_data_exists (const value_list_t *vl, const char *key);
+int uc_meta_data_delete (const value_list_t *vl, const char *key);
+
+int uc_meta_data_add_string (const value_list_t *vl,
+    const char *key,
+    const char *value);
+int uc_meta_data_add_signed_int (const value_list_t *vl,
+    const char *key,
+    int64_t value);
+int uc_meta_data_add_unsigned_int (const value_list_t *vl,
+    const char *key,
+    uint64_t value);
+int uc_meta_data_add_double (const value_list_t *vl,
+    const char *key,
+    double value);
+int uc_meta_data_add_boolean (const value_list_t *vl,
+    const char *key,
+    _Bool value);
+
+int uc_meta_data_get_string (const value_list_t *vl,
+    const char *key,
+    char **value);
+int uc_meta_data_get_signed_int (const value_list_t *vl,
+    const char *key,
+    int64_t *value);
+int uc_meta_data_get_unsigned_int (const value_list_t *vl,
+    const char *key,
+    uint64_t *value);
+int uc_meta_data_get_double (const value_list_t *vl,
+    const char *key,
+    double *value);
+int uc_meta_data_get_boolean (const value_list_t *vl,
+    const char *key,
+    _Bool *value);
+
+/* vim: set shiftwidth=2 softtabstop=2 tabstop=8 : */
+#endif /* !UTILS_CACHE_H */
diff --git a/src/daemon/utils_cache_mock.c b/src/daemon/utils_cache_mock.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/daemon/utils_complain.c b/src/daemon/utils_complain.c
new file mode 100644 (file)
index 0000000..6193614
--- /dev/null
@@ -0,0 +1,105 @@
+/**
+ * collectd - src/utils_complain.c
+ * Copyright (C) 2006-2013  Florian octo Forster
+ * Copyright (C) 2008       Sebastian tokkee 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:
+ *   Florian octo Forster <octo at collectd.org>
+ *   Sebastian tokkee Harl <sh at tokkee.org>
+ **/
+
+#include "collectd.h"
+#include "utils_complain.h"
+#include "plugin.h"
+
+/* vcomplain returns 0 if it did not report, 1 else */
+static int vcomplain (int level, c_complain_t *c,
+               const char *format, va_list ap)
+{
+       cdtime_t now;
+       char   message[512];
+
+       now = cdtime ();
+
+       if (c->last + c->interval > now)
+               return 0;
+
+       c->last = now;
+
+       if (c->interval < plugin_get_interval ())
+               c->interval = plugin_get_interval ();
+       else
+               c->interval *= 2;
+
+       if (c->interval > TIME_T_TO_CDTIME_T (86400))
+               c->interval = TIME_T_TO_CDTIME_T (86400);
+
+       vsnprintf (message, sizeof (message), format, ap);
+       message[sizeof (message) - 1] = '\0';
+
+       plugin_log (level, "%s", message);
+       return 1;
+} /* vcomplain */
+
+void c_complain (int level, c_complain_t *c, const char *format, ...)
+{
+       va_list ap;
+
+       va_start (ap, format);
+       if (vcomplain (level, c, format, ap))
+               c->complained_once = 1;
+       va_end (ap);
+} /* c_complain */
+
+void c_complain_once (int level, c_complain_t *c, const char *format, ...)
+{
+       va_list ap;
+
+       if (c->complained_once)
+               return;
+
+       va_start (ap, format);
+       if (vcomplain (level, c, format, ap))
+               c->complained_once = 1;
+       va_end (ap);
+} /* c_complain_once */
+
+void c_do_release (int level, c_complain_t *c, const char *format, ...)
+{
+       char message[512];
+       va_list ap;
+
+       if (c->interval == 0)
+               return;
+
+       c->interval = 0;
+       c->complained_once = 0;
+
+       va_start (ap, format);
+       vsnprintf (message, sizeof (message), format, ap);
+       message[sizeof (message) - 1] = '\0';
+       va_end (ap);
+
+       plugin_log (level, "%s", message);
+} /* c_release */
+
+/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
+
diff --git a/src/daemon/utils_complain.h b/src/daemon/utils_complain.h
new file mode 100644 (file)
index 0000000..390f961
--- /dev/null
@@ -0,0 +1,114 @@
+/**
+ * collectd - src/utils_complain.h
+ * Copyright (C) 2006-2013  Florian octo Forster
+ * Copyright (C) 2008       Sebastian tokkee 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:
+ *   Florian octo Forster <octo at collectd.org>
+ *   Sebastian tokkee Harl <sh at tokkee.org>
+ **/
+
+#ifndef UTILS_COMPLAIN_H
+#define UTILS_COMPLAIN_H 1
+
+#include "utils_time.h"
+
+typedef struct
+{
+       /* time of the last report */
+       cdtime_t last;
+
+       /* How long to wait until reporting again.
+        * 0 indicates that the complaint is no longer valid. */
+       cdtime_t interval;
+
+       _Bool complained_once;
+} c_complain_t;
+
+#define C_COMPLAIN_INIT_STATIC { 0, 0, 0 }
+#define C_COMPLAIN_INIT(c) do { \
+       (c)->last = 0; \
+       (c)->interval = 0; \
+       (c)->complained_once = 0; \
+} while (0)
+
+/*
+ * NAME
+ *   c_complain
+ *
+ * DESCRIPTION
+ *   Complain about something. This function will report a message (usually
+ *   indicating some error condition) using the collectd logging mechanism.
+ *   When this function is called again, reporting the message again will be
+ *   deferred by an increasing interval (up to one day) to prevent flooding
+ *   the logs. A call to `c_release' resets the counter.
+ *
+ * PARAMETERS
+ *   `level'  The log level passed to `plugin_log'.
+ *   `c'      Identifier for the complaint.
+ *   `format' Message format - see the documentation of printf(3).
+ */
+void c_complain (int level, c_complain_t *c, const char *format, ...);
+
+/*
+ * NAME
+ *   c_complain_once
+ *
+ * DESCRIPTION
+ *   Complain about something once. This function will not report anything
+ *   again, unless `c_release' has been called in between. If used after some
+ *   calls to `c_complain', it will report again on the next interval and stop
+ *   after that.
+ *
+ *   See `c_complain' for further details and a description of the parameters.
+ */
+void c_complain_once (int level, c_complain_t *c, const char *format, ...);
+
+/*
+ * NAME
+ *   c_would_release
+ *
+ * DESCRIPTION
+ *   Returns true if the specified complaint would be released, false else.
+ */
+#define c_would_release(c) ((c)->interval != 0)
+
+/*
+ * NAME
+ *   c_release
+ *
+ * DESCRIPTION
+ *   Release a complaint. This will report a message once, marking the
+ *   complaint as released.
+ *
+ *   See `c_complain' for a description of the parameters.
+ */
+void c_do_release (int level, c_complain_t *c, const char *format, ...);
+#define c_release(level, c, ...) \
+       do { \
+               if (c_would_release (c)) \
+                       c_do_release(level, c, __VA_ARGS__); \
+       } while (0)
+
+#endif /* UTILS_COMPLAIN_H */
+
+/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
+
diff --git a/src/daemon/utils_heap.c b/src/daemon/utils_heap.c
new file mode 100644 (file)
index 0000000..1b5dca7
--- /dev/null
@@ -0,0 +1,230 @@
+/**
+ * collectd - src/utils_heap.c
+ * Copyright (C) 2009       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 <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <assert.h>
+#include <pthread.h>
+
+#include "utils_heap.h"
+
+struct c_heap_s
+{
+  pthread_mutex_t lock;
+  int (*compare) (const void *, const void *);
+
+  void **list;
+  size_t list_len; /* # entries used */
+  size_t list_size; /* # entries allocated */
+};
+
+enum reheap_direction
+{
+  DIR_UP,
+  DIR_DOWN
+};
+
+static void reheap (c_heap_t *h, size_t root, enum reheap_direction dir)
+{
+  size_t left;
+  size_t right;
+  size_t min;
+  int status;
+
+  /* Calculate the positions of the children */
+  left = (2 * root) + 1;
+  if (left >= h->list_len)
+    left = 0;
+
+  right = (2 * root) + 2;
+  if (right >= h->list_len)
+    right = 0;
+
+  /* Check which one of the children is smaller. */
+  if ((left == 0) && (right == 0))
+    return;
+  else if (left == 0)
+    min = right;
+  else if (right == 0)
+    min = left;
+  else
+  {
+    status = h->compare (h->list[left], h->list[right]);
+    if (status > 0)
+      min = right;
+    else
+      min = left;
+  }
+
+  status = h->compare (h->list[root], h->list[min]);
+  if (status <= 0)
+  {
+    /* We didn't need to change anything, so the rest of the tree should be
+     * okay now. */
+    return;
+  }
+  else /* if (status > 0) */
+  {
+    void *tmp;
+
+    tmp = h->list[root];
+    h->list[root] = h->list[min];
+    h->list[min] = tmp;
+  }
+
+  if ((dir == DIR_UP) && (root == 0))
+    return;
+
+  if (dir == DIR_UP)
+    reheap (h, (root - 1) / 2, dir);
+  else if (dir == DIR_DOWN)
+    reheap (h, min, dir);
+} /* void reheap */
+
+c_heap_t *c_heap_create (int (*compare) (const void *, const void *))
+{
+  c_heap_t *h;
+
+  if (compare == NULL)
+    return (NULL);
+
+  h = malloc (sizeof (*h));
+  if (h == NULL)
+    return (NULL);
+
+  memset (h, 0, sizeof (*h));
+  pthread_mutex_init (&h->lock, /* attr = */ NULL);
+  h->compare = compare;
+  
+  h->list = NULL;
+  h->list_len = 0;
+  h->list_size = 0;
+
+  return (h);
+} /* c_heap_t *c_heap_create */
+
+void c_heap_destroy (c_heap_t *h)
+{
+  if (h == NULL)
+    return;
+
+  h->list_len = 0;
+  h->list_size = 0;
+  free (h->list);
+  h->list = NULL;
+
+  pthread_mutex_destroy (&h->lock);
+
+  free (h);
+} /* void c_heap_destroy */
+
+int c_heap_insert (c_heap_t *h, void *ptr)
+{
+  size_t index;
+
+  if ((h == NULL) || (ptr == NULL))
+    return (-EINVAL);
+
+  pthread_mutex_lock (&h->lock);
+
+  assert (h->list_len <= h->list_size);
+  if (h->list_len == h->list_size)
+  {
+    void **tmp;
+
+    tmp = realloc (h->list, (h->list_size + 16) * sizeof (*h->list));
+    if (tmp == NULL)
+    {
+      pthread_mutex_unlock (&h->lock);
+      return (-ENOMEM);
+    }
+
+    h->list = tmp;
+    h->list_size += 16;
+  }
+
+  /* Insert the new node as a leaf. */
+  index = h->list_len;
+  h->list[index] = ptr;
+  h->list_len++;
+
+  /* Reorganize the heap from bottom up. */
+  reheap (h, /* parent of this node = */ (index - 1) / 2, DIR_UP);
+  
+  pthread_mutex_unlock (&h->lock);
+  return (0);
+} /* int c_heap_insert */
+
+void *c_heap_get_root (c_heap_t *h)
+{
+  void *ret = NULL;
+
+  if (h == NULL)
+    return (NULL);
+
+  pthread_mutex_lock (&h->lock);
+
+  if (h->list_len == 0)
+  {
+    pthread_mutex_unlock (&h->lock);
+    return (NULL);
+  }
+  else if (h->list_len == 1)
+  {
+    ret = h->list[0];
+    h->list[0] = NULL;
+    h->list_len = 0;
+  }
+  else /* if (h->list_len > 1) */
+  {
+    ret = h->list[0];
+    h->list[0] = h->list[h->list_len - 1];
+    h->list[h->list_len - 1] = NULL;
+    h->list_len--;
+
+    reheap (h, /* root = */ 0, DIR_DOWN);
+  }
+
+  /* free some memory */
+  if ((h->list_len + 32) < h->list_size)
+  {
+    void **tmp;
+
+    tmp = realloc (h->list, (h->list_len + 16) * sizeof (*h->list));
+    if (tmp != NULL)
+    {
+      h->list = tmp;
+      h->list_size = h->list_len + 16;
+    }
+  }
+
+  pthread_mutex_unlock (&h->lock);
+
+  return (ret);
+} /* void *c_heap_get_root */
+
+/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/src/daemon/utils_heap.h b/src/daemon/utils_heap.h
new file mode 100644 (file)
index 0000000..6d71c43
--- /dev/null
@@ -0,0 +1,100 @@
+/**
+ * collectd - src/utils_heap.h
+ * Copyright (C) 2009       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>
+ **/
+
+#ifndef UTILS_HEAP_H
+#define UTILS_HEAP_H 1
+
+struct c_heap_s;
+typedef struct c_heap_s c_heap_t;
+
+/*
+ * NAME
+ *   c_heap_create
+ *
+ * DESCRIPTION
+ *   Allocates a new heap.
+ *
+ * PARAMETERS
+ *   `compare'  The function-pointer `compare' is used to compare two keys. It
+ *              has to return less than zero if it's first argument is smaller
+ *              then the second argument, more than zero if the first argument
+ *              is bigger than the second argument and zero if they are equal.
+ *              If your keys are char-pointers, you can use the `strcmp'
+ *              function from the libc here.
+ *
+ * RETURN VALUE
+ *   A c_heap_t-pointer upon success or NULL upon failure.
+ */
+c_heap_t *c_heap_create (int (*compare) (const void *, const void *));
+
+/*
+ * NAME
+ *   c_heap_destroy
+ *
+ * DESCRIPTION
+ *   Deallocates a heap. Stored value- and key-pointer are lost, but of course
+ *   not freed.
+ */
+void c_heap_destroy (c_heap_t *h);
+
+/*
+ * NAME
+ *   c_heap_insert
+ *
+ * DESCRIPTION
+ *   Stores the key-value-pair in the heap pointed to by `h'.
+ *
+ * PARAMETERS
+ *   `h'        Heap to store the data in.
+ *   `ptr'      Value to be stored. This is typically a pointer to a data
+ *              structure. The data structure is of course *not* copied and may
+ *              not be free'd before the pointer has been removed from the heap
+ *              again.
+ *
+ * RETURN VALUE
+ *   Zero upon success, non-zero otherwise. It's less than zero if an error
+ *   occurred or greater than zero if the key is already stored in the tree.
+ */
+int c_heap_insert (c_heap_t *h, void *ptr);
+
+/*
+ * NAME
+ *   c_heap_get_root
+ *
+ * DESCRIPTION
+ *   Removes the value at the root of the heap and returns both, key and value.
+ *
+ * PARAMETERS
+ *   `h'           Heap to remove key-value-pair from.
+ *
+ * RETURN VALUE
+ *   The pointer passed to `c_heap_insert' or NULL if there are no more
+ *   elements in the heap (or an error occurred).
+ */
+void *c_heap_get_root (c_heap_t *h);
+
+#endif /* UTILS_HEAP_H */
+/* vim: set sw=2 sts=2 et : */
diff --git a/src/daemon/utils_heap_test.c b/src/daemon/utils_heap_test.c
new file mode 100644 (file)
index 0000000..53d0fba
--- /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 "testing.h"
+#include "collectd.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/daemon/utils_llist.c b/src/daemon/utils_llist.c
new file mode 100644 (file)
index 0000000..4265286
--- /dev/null
@@ -0,0 +1,193 @@
+/**
+ * collectd - src/utils_llist.c
+ * Copyright (C) 2006       Florian Forster <octo at collectd.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.
+ *
+ * Authors:
+ *   Florian Forster <octo at collectd.org>
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "utils_llist.h"
+
+/*
+ * Private data types
+ */
+struct llist_s
+{
+       llentry_t *head;
+       llentry_t *tail;
+       int size;
+};
+
+/*
+ * Public functions
+ */
+llist_t *llist_create (void)
+{
+       llist_t *ret;
+
+       ret = (llist_t *) malloc (sizeof (llist_t));
+       if (ret == NULL)
+               return (NULL);
+
+       memset (ret, '\0', sizeof (llist_t));
+
+       return (ret);
+}
+
+void llist_destroy (llist_t *l)
+{
+       llentry_t *e_this;
+       llentry_t *e_next;
+
+       if (l == NULL)
+               return;
+
+       for (e_this = l->head; e_this != NULL; e_this = e_next)
+       {
+               e_next = e_this->next;
+               llentry_destroy (e_this);
+       }
+
+       free (l);
+}
+
+llentry_t *llentry_create (char *key, void *value)
+{
+       llentry_t *e;
+
+       e = (llentry_t *) malloc (sizeof (llentry_t));
+       if (e)
+       {
+               e->key   = key;
+               e->value = value;
+               e->next  = NULL;
+       }
+
+       return (e);
+}
+
+void llentry_destroy (llentry_t *e)
+{
+       free (e);
+}
+
+void llist_append (llist_t *l, llentry_t *e)
+{
+       e->next = NULL;
+
+       if (l->tail == NULL)
+               l->head = e;
+       else
+               l->tail->next = e;
+
+       l->tail = e;
+
+       ++(l->size);
+}
+
+void llist_prepend (llist_t *l, llentry_t *e)
+{
+       e->next = l->head;
+       l->head = e;
+
+       if (l->tail == NULL)
+               l->tail = e;
+
+       ++(l->size);
+}
+
+void llist_remove (llist_t *l, llentry_t *e)
+{
+       llentry_t *prev;
+
+       if ((l == NULL) || (e == NULL))
+               return;
+
+       prev = l->head;
+       while ((prev != NULL) && (prev->next != e))
+               prev = prev->next;
+
+       if (prev != NULL)
+               prev->next = e->next;
+       if (l->head == e)
+               l->head = e->next;
+       if (l->tail == e)
+               l->tail = prev;
+
+       --(l->size);
+}
+
+int llist_size (llist_t *l)
+{
+       return (l ? l->size : 0);
+}
+
+static int llist_strcmp (llentry_t *e, void *ud)
+{
+       if ((e == NULL) || (ud == NULL))
+               return (-1);
+       return (strcmp (e->key, (const char *)ud));
+}
+
+llentry_t *llist_search (llist_t *l, const char *key)
+{
+       return (llist_search_custom (l, llist_strcmp, (void *)key));
+}
+
+llentry_t *llist_search_custom (llist_t *l,
+               int (*compare) (llentry_t *, void *), void *user_data)
+{
+       llentry_t *e;
+
+       if (l == NULL)
+               return (NULL);
+
+       e = l->head;
+       while (e != NULL) {
+               llentry_t *next = e->next;
+
+               if (compare (e, user_data) == 0)
+                       break;
+
+               e = next;
+       }
+
+       return (e);
+}
+
+llentry_t *llist_head (llist_t *l)
+{
+       if (l == NULL)
+               return (NULL);
+       return (l->head);
+}
+
+llentry_t *llist_tail (llist_t *l)
+{
+       if (l == NULL)
+               return (NULL);
+       return (l->tail);
+}
diff --git a/src/daemon/utils_llist.h b/src/daemon/utils_llist.h
new file mode 100644 (file)
index 0000000..59bf2e4
--- /dev/null
@@ -0,0 +1,66 @@
+/**
+ * collectd - src/utils_llist.h
+ * Copyright (C) 2006       Florian Forster <octo at collectd.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.
+ *
+ * Authors:
+ *   Florian Forster <octo at collectd.org>
+ */
+
+#ifndef UTILS_LLIST_H
+#define UTILS_LLIST_H 1
+
+/*
+ * Data types
+ */
+struct llentry_s
+{
+       char *key;
+       void *value;
+       struct llentry_s *next;
+};
+typedef struct llentry_s llentry_t;
+
+struct llist_s;
+typedef struct llist_s llist_t;
+
+/*
+ * Functions
+ */
+llist_t *llist_create (void);
+void llist_destroy (llist_t *l);
+
+llentry_t *llentry_create (char *key, void *value);
+void llentry_destroy (llentry_t *e);
+
+void llist_append (llist_t *l, llentry_t *e);
+void llist_prepend (llist_t *l, llentry_t *e);
+void llist_remove (llist_t *l, llentry_t *e);
+
+int llist_size (llist_t *l);
+
+llentry_t *llist_search (llist_t *l, const char *key);
+llentry_t *llist_search_custom (llist_t *l,
+               int (*compare) (llentry_t *, void *), void *user_data);
+
+llentry_t *llist_head (llist_t *l);
+llentry_t *llist_tail (llist_t *l);
+
+#endif /* UTILS_LLIST_H */
diff --git a/src/daemon/utils_match.c b/src/daemon/utils_match.c
new file mode 100644 (file)
index 0000000..5083b05
--- /dev/null
@@ -0,0 +1,396 @@
+/**
+ * collectd - src/utils_match.c
+ * Copyright (C) 2008-2014  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 "common.h"
+#include "plugin.h"
+
+#include "utils_match.h"
+
+#include <regex.h>
+
+#define UTILS_MATCH_FLAGS_FREE_USER_DATA 0x01
+#define UTILS_MATCH_FLAGS_EXCLUDE_REGEX 0x02
+
+struct cu_match_s
+{
+  regex_t regex;
+  regex_t excluderegex;
+  int flags;
+
+  int (*callback) (const char *str, char * const *matches, size_t matches_num,
+      void *user_data);
+  void *user_data;
+};
+
+/*
+ * Private functions
+ */
+static char *match_substr (const char *str, int begin, int end)
+{
+  char *ret;
+  size_t ret_len;
+
+  if ((begin < 0) || (end < 0) || (begin >= end))
+    return (NULL);
+  if ((size_t) end > (strlen (str) + 1))
+  {
+    ERROR ("utils_match: match_substr: `end' points after end of string.");
+    return (NULL);
+  }
+
+  ret_len = end - begin;
+  ret = (char *) malloc (sizeof (char) * (ret_len + 1));
+  if (ret == NULL)
+  {
+    ERROR ("utils_match: match_substr: malloc failed.");
+    return (NULL);
+  }
+
+  sstrncpy (ret, str + begin, ret_len + 1);
+  return (ret);
+} /* char *match_substr */
+
+static int default_callback (const char __attribute__((unused)) *str,
+    char * const *matches, size_t matches_num, void *user_data)
+{
+  cu_match_value_t *data = (cu_match_value_t *) user_data;
+
+  if (data->ds_type & UTILS_MATCH_DS_TYPE_GAUGE)
+  {
+    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);
+
+    value = (gauge_t) strtod (matches[1], &endptr);
+    if (matches[1] == endptr)
+      return (-1);
+
+    if ((data->values_num == 0)
+       || (data->ds_type & UTILS_MATCH_CF_GAUGE_LAST))
+    {
+      data->value.gauge = value;
+    }
+    else if (data->ds_type & UTILS_MATCH_CF_GAUGE_AVERAGE)
+    {
+      double f = ((double) data->values_num)
+       / ((double) (data->values_num + 1));
+      data->value.gauge = (data->value.gauge * f) + (value * (1.0 - f));
+    }
+    else if (data->ds_type & UTILS_MATCH_CF_GAUGE_MIN)
+    {
+      if (data->value.gauge > value)
+       data->value.gauge = value;
+    }
+    else if (data->ds_type & UTILS_MATCH_CF_GAUGE_MAX)
+    {
+      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!");
+      return (-1);
+    }
+
+    data->values_num++;
+  }
+  else if (data->ds_type & UTILS_MATCH_DS_TYPE_COUNTER)
+  {
+    counter_t value;
+    char *endptr = NULL;
+
+    if (data->ds_type & UTILS_MATCH_CF_COUNTER_INC)
+    {
+      data->value.counter++;
+      data->values_num++;
+      return (0);
+    }
+
+    if (matches_num < 2)
+      return (-1);
+
+    value = (counter_t) strtoull (matches[1], &endptr, 0);
+    if (matches[1] == endptr)
+      return (-1);
+
+    if (data->ds_type & UTILS_MATCH_CF_COUNTER_SET)
+      data->value.counter = value;
+    else if (data->ds_type & UTILS_MATCH_CF_COUNTER_ADD)
+      data->value.counter += value;
+    else
+    {
+      ERROR ("utils_match: default_callback: obj->ds_type is invalid!");
+      return (-1);
+    }
+
+    data->values_num++;
+  }
+  else if (data->ds_type & UTILS_MATCH_DS_TYPE_DERIVE)
+  {
+    derive_t value;
+    char *endptr = NULL;
+
+    if (data->ds_type & UTILS_MATCH_CF_DERIVE_INC)
+    {
+      data->value.counter++;
+      data->values_num++;
+      return (0);
+    }
+
+    if (matches_num < 2)
+      return (-1);
+
+    value = (derive_t) strtoll (matches[1], &endptr, 0);
+    if (matches[1] == endptr)
+      return (-1);
+
+    if (data->ds_type & UTILS_MATCH_CF_DERIVE_SET)
+      data->value.derive = value;
+    else if (data->ds_type & UTILS_MATCH_CF_DERIVE_ADD)
+      data->value.derive += value;
+    else
+    {
+      ERROR ("utils_match: default_callback: obj->ds_type is invalid!");
+      return (-1);
+    }
+
+    data->values_num++;
+  }
+  else if (data->ds_type & UTILS_MATCH_DS_TYPE_ABSOLUTE)
+  {
+    absolute_t value;
+    char *endptr = NULL;
+
+    if (matches_num < 2)
+      return (-1);
+
+    value = (absolute_t) strtoull (matches[1], &endptr, 0);
+    if (matches[1] == endptr)
+      return (-1);
+
+    if (data->ds_type & UTILS_MATCH_CF_ABSOLUTE_SET)
+      data->value.absolute = value;
+    else
+    {
+      ERROR ("utils_match: default_callback: obj->ds_type is invalid!");
+      return (-1);
+    }
+
+    data->values_num++;
+  }
+  else
+  {
+    ERROR ("utils_match: default_callback: obj->ds_type is invalid!");
+    return (-1);
+  }
+
+  return (0);
+} /* int default_callback */
+
+/*
+ * Public functions
+ */
+cu_match_t *match_create_callback (const char *regex, const char *excluderegex,
+               int (*callback) (const char *str,
+                 char * const *matches, size_t matches_num, void *user_data),
+               void *user_data)
+{
+  cu_match_t *obj;
+  int status;
+
+  DEBUG ("utils_match: match_create_callback: regex = %s, excluderegex = %s",
+        regex, excluderegex);
+
+  obj = (cu_match_t *) malloc (sizeof (cu_match_t));
+  if (obj == NULL)
+    return (NULL);
+  memset (obj, '\0', sizeof (cu_match_t));
+
+  status = regcomp (&obj->regex, regex, REG_EXTENDED | REG_NEWLINE);
+  if (status != 0)
+  {
+    ERROR ("Compiling the regular expression \"%s\" failed.", regex);
+    sfree (obj);
+    return (NULL);
+  }
+
+  if (excluderegex && strcmp(excluderegex, "") != 0) {
+    status = regcomp (&obj->excluderegex, excluderegex, REG_EXTENDED);
+    if (status != 0)
+    {
+       ERROR ("Compiling the excluding regular expression \"%s\" failed.",
+              excluderegex);
+       sfree (obj);
+       return (NULL);
+    }
+    obj->flags |= UTILS_MATCH_FLAGS_EXCLUDE_REGEX;
+  }
+
+  obj->callback = callback;
+  obj->user_data = user_data;
+
+  return (obj);
+} /* cu_match_t *match_create_callback */
+
+cu_match_t *match_create_simple (const char *regex,
+                                const char *excluderegex, int match_ds_type)
+{
+  cu_match_value_t *user_data;
+  cu_match_t *obj;
+
+  user_data = (cu_match_value_t *) malloc (sizeof (cu_match_value_t));
+  if (user_data == NULL)
+    return (NULL);
+  memset (user_data, '\0', sizeof (cu_match_value_t));
+  user_data->ds_type = match_ds_type;
+
+  obj = match_create_callback (regex, excluderegex,
+                              default_callback, user_data);
+  if (obj == NULL)
+  {
+    sfree (user_data);
+    return (NULL);
+  }
+
+  obj->flags |= UTILS_MATCH_FLAGS_FREE_USER_DATA;
+
+  return (obj);
+} /* cu_match_t *match_create_simple */
+
+void match_value_reset (cu_match_value_t *mv)
+{
+  if (mv == NULL)
+    return;
+
+  if (mv->ds_type & UTILS_MATCH_DS_TYPE_GAUGE)
+  {
+    mv->value.gauge = NAN;
+    mv->values_num = 0;
+  }
+} /* }}} void match_value_reset */
+
+void match_destroy (cu_match_t *obj)
+{
+  if (obj == NULL)
+    return;
+
+  if (obj->flags & UTILS_MATCH_FLAGS_FREE_USER_DATA)
+  {
+    sfree (obj->user_data);
+  }
+
+  sfree (obj);
+} /* void match_destroy */
+
+int match_apply (cu_match_t *obj, const char *str)
+{
+  int status;
+  regmatch_t re_match[32];
+  char *matches[32];
+  size_t matches_num;
+  size_t i;
+
+  if ((obj == NULL) || (str == NULL))
+    return (-1);
+
+  if (obj->flags & UTILS_MATCH_FLAGS_EXCLUDE_REGEX) {
+    status = regexec (&obj->excluderegex, str,
+                     STATIC_ARRAY_SIZE (re_match), re_match,
+                     /* eflags = */ 0);
+    /* Regex did match, so exclude this line */
+    if (status == 0) {
+      DEBUG("ExludeRegex matched, don't count that line\n");
+      return (0);
+    }
+  }
+
+  status = regexec (&obj->regex, str,
+      STATIC_ARRAY_SIZE (re_match), re_match,
+      /* eflags = */ 0);
+
+  /* Regex did not match */
+  if (status != 0)
+    return (0);
+
+  memset (matches, '\0', sizeof (matches));
+  for (matches_num = 0; matches_num < STATIC_ARRAY_SIZE (matches); matches_num++)
+  {
+    if ((re_match[matches_num].rm_so < 0)
+       || (re_match[matches_num].rm_eo < 0))
+      break;
+
+    matches[matches_num] = match_substr (str,
+       re_match[matches_num].rm_so, re_match[matches_num].rm_eo);
+    if (matches[matches_num] == NULL)
+    {
+      status = -1;
+      break;
+    }
+  }
+
+  if (status != 0)
+  {
+    ERROR ("utils_match: match_apply: match_substr failed.");
+  }
+  else
+  {
+    status = obj->callback (str, matches, matches_num, obj->user_data);
+    if (status != 0)
+    {
+      ERROR ("utils_match: match_apply: callback failed.");
+    }
+  }
+
+  for (i = 0; i < matches_num; i++)
+  {
+    sfree (matches[i]);
+  }
+
+  return (status);
+} /* int match_apply */
+
+void *match_get_user_data (cu_match_t *obj)
+{
+  if (obj == NULL)
+    return (NULL);
+  return (obj->user_data);
+} /* void *match_get_user_data */
+
+/* vim: set sw=2 sts=2 ts=8 : */
diff --git a/src/daemon/utils_match.h b/src/daemon/utils_match.h
new file mode 100644 (file)
index 0000000..a1d1002
--- /dev/null
@@ -0,0 +1,175 @@
+/**
+ * collectd - src/utils_match.h
+ * Copyright (C) 2008-2014  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>
+ **/
+
+#ifndef UTILS_MATCH_H
+#define UTILS_MATCH_H 1
+
+#include "plugin.h"
+
+/*
+ * Each type may have 12 sub-types
+ * 0x1000 = 1000000000000
+ *          ^             <- Type bit
+ *           ^^^^^^^^^^^^ <- Subtype bits
+ */
+#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
+#define UTILS_MATCH_CF_COUNTER_INC   0x04
+
+#define UTILS_MATCH_CF_DERIVE_SET   0x01
+#define UTILS_MATCH_CF_DERIVE_ADD   0x02
+#define UTILS_MATCH_CF_DERIVE_INC   0x04
+
+#define UTILS_MATCH_CF_ABSOLUTE_SET   0x01
+#define UTILS_MATCH_CF_ABSOLUTE_ADD   0x02
+#define UTILS_MATCH_CF_ABSOLUTE_INC   0x04
+
+/*
+ * Data types
+ */
+struct cu_match_s;
+typedef struct cu_match_s cu_match_t;
+
+struct cu_match_value_s
+{
+  int ds_type;
+  value_t value;
+  unsigned int values_num;
+};
+typedef struct cu_match_value_s cu_match_value_t;
+
+/*
+ * Prototypes
+ */
+/*
+ * NAME
+ *  match_create_callback
+ *
+ * DESCRIPTION
+ *  Creates a new `cu_match_t' object which will use the regular expression
+ *  `regex' to match lines, see the `match_apply' method below. If the line
+ *  matches, the callback passed in `callback' will be called along with the
+ *  pointer `user_pointer'.
+ *  The string that's passed to the callback depends on the regular expression:
+ *  If the regular expression includes a sub-match, i. e. something like
+ *    "value=([0-9][0-9]*)"
+ *  then only the submatch (the part in the parenthesis) will be passed to the
+ *  callback. If there is no submatch, then the entire string is passed to the
+ *  callback.
+ *  The optional `excluderegex' allows to exclude the line from the match, if
+ *  the excluderegex matches.
+ */
+cu_match_t *match_create_callback (const char *regex, const char *excluderegex,
+               int (*callback) (const char *str,
+                 char * const *matches, size_t matches_num, void *user_data),
+               void *user_data);
+
+/*
+ * NAME
+ *  match_create_simple
+ *
+ * DESCRIPTION
+ *  Creates a new `cu_match_t' with a default callback. The user data for that
+ *  default callback will be a `cu_match_value_t' structure, with
+ *  `ds_type' copied to the structure. The default callback will handle the
+ *  string as containing a number (see strtoll(3) and strtod(3)) and store that
+ *  number in the `value' member. How that is done depends on `ds_type':
+ *
+ *  UTILS_MATCH_DS_TYPE_GAUGE
+ *    The function will search for a floating point number in the string and
+ *    store it in value.gauge.
+ *  UTILS_MATCH_DS_TYPE_COUNTER_SET
+ *    The function will search for an integer in the string and store it in
+ *    value.counter.
+ *  UTILS_MATCH_DS_TYPE_COUNTER_ADD
+ *    The function will search for an integer in the string and add it to the
+ *    value in value.counter.
+ *  UTILS_MATCH_DS_TYPE_COUNTER_INC
+ *    The function will not search for anything in the string and increase
+ *    value.counter by one.
+ */
+cu_match_t *match_create_simple (const char *regex,
+                                const char *excluderegex, int ds_type);
+
+/*
+ * NAME
+ *  match_value_reset
+ *
+ * DESCRIPTION
+ *   Resets the internal state, if applicable. This function must be called
+ *   after each iteration for "simple" matches, usually after dispatching the
+ *   metrics.
+ */
+void match_value_reset (cu_match_value_t *mv);
+
+/*
+ * NAME
+ *  match_destroy
+ *
+ * DESCRIPTION
+ *  Destroys the object and frees all internal resources.
+ */
+void match_destroy (cu_match_t *obj);
+
+/*
+ * NAME
+ *  match_apply
+ *
+ * DESCRIPTION
+ *  Tries to match the string `str' with the regular expression of `obj'. If
+ *  the string matches, calls the callback in `obj' with the (sub-)match.
+ *
+ *  The user_data pointer passed to `match_create_callback' is NOT freed
+ *  automatically. The `cu_match_value_t' structure allocated by
+ *  `match_create_callback' is freed automatically.
+ */
+int match_apply (cu_match_t *obj, const char *str);
+
+/*
+ * NAME
+ *  match_get_user_data
+ *
+ * DESCRIPTION
+ *  Returns the pointer passed to `match_create_callback' or a pointer to the
+ *  `cu_match_value_t' structure allocated by `match_create_simple'.
+ */
+void *match_get_user_data (cu_match_t *obj);
+
+#endif /* UTILS_MATCH_H */
+
+/* vim: set sw=2 sts=2 ts=8 : */
diff --git a/src/daemon/utils_random.c b/src/daemon/utils_random.c
new file mode 100644 (file)
index 0000000..b873845
--- /dev/null
@@ -0,0 +1,75 @@
+/**
+ * collectd - src/utils_random.c
+ * 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"),
+ * 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_time.h"
+
+#include <pthread.h>
+
+static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+static _Bool have_seed = 0;
+static unsigned short seed[3];
+
+static void cdrand_seed (void)
+{
+  cdtime_t t;
+
+  if (have_seed)
+    return;
+
+  t = cdtime();
+
+  seed[0] = (unsigned short) t;
+  seed[1] = (unsigned short) (t >> 16);
+  seed[2] = (unsigned short) (t >> 32);
+
+  have_seed = 1;
+}
+
+double cdrand_d (void)
+{
+  double r;
+
+  pthread_mutex_lock (&lock);
+  cdrand_seed ();
+  r = erand48 (seed);
+  pthread_mutex_unlock (&lock);
+
+  return (r);
+}
+
+long cdrand_range (long min, long max)
+{
+  long range;
+  long r;
+
+  range = 1 + max - min;
+
+  r = (long) (0.5 + (cdrand_d () * range));
+  r += min;
+
+  return (r);
+}
diff --git a/src/daemon/utils_random.h b/src/daemon/utils_random.h
new file mode 100644 (file)
index 0000000..b05f4c8
--- /dev/null
@@ -0,0 +1,40 @@
+/**
+ * collectd - src/utils_random.h
+ * 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"),
+ * 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>
+ **/
+
+/**
+ * Returns a random double value in the range [0..1), i.e. excluding 1.
+ *
+ * This function is thread- and reentrant-safe.
+ */
+double cdrand_d (void);
+
+/**
+ * Returns a random long between min and max, inclusively.
+ *
+ * If min is larger than max, the result may be rounded incorrectly and may be
+ * outside the intended range. This function is thread- and reentrant-safe.
+ */
+long cdrand_range (long min, long max);
diff --git a/src/daemon/utils_subst.c b/src/daemon/utils_subst.c
new file mode 100644 (file)
index 0000000..2f28eb9
--- /dev/null
@@ -0,0 +1,149 @@
+/**
+ * collectd - src/utils_subst.c
+ * 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>
+ **/
+
+/*
+ * This module provides functions for string substitution.
+ */
+
+#include "collectd.h"
+#include "common.h"
+
+char *subst (char *buf, size_t buflen, const char *string, int off1, int off2,
+               const char *replacement)
+{
+       char  *buf_ptr = buf;
+       size_t len     = buflen;
+
+       if ((NULL == buf) || (0 >= buflen) || (NULL == string)
+                       || (0 > off1) || (0 > off2) || (off1 > off2)
+                       || (NULL == replacement))
+               return NULL;
+
+       sstrncpy (buf_ptr, string,
+                       ((size_t)off1 + 1 > buflen) ? buflen : (size_t)off1 + 1);
+       buf_ptr += off1;
+       len     -= off1;
+
+       if (0 >= len)
+               return buf;
+
+       sstrncpy (buf_ptr, replacement, len);
+       buf_ptr += strlen (replacement);
+       len     -= strlen (replacement);
+
+       if (0 >= len)
+               return buf;
+
+       sstrncpy (buf_ptr, string + off2, len);
+       return buf;
+} /* subst */
+
+char *asubst (const char *string, int off1, int off2, const char *replacement)
+{
+       char *buf;
+       int   len;
+
+       char *ret;
+
+       if ((NULL == string) || (0 > off1) || (0 > off2) || (off1 > off2)
+                       || (NULL ==replacement))
+               return NULL;
+
+       len = off1 + strlen (replacement) + strlen (string) - off2 + 1;
+
+       buf = (char *)malloc (len);
+       if (NULL == buf)
+               return NULL;
+
+       ret = subst (buf, len, string, off1, off2, replacement);
+       if (NULL == ret)
+               free (buf);
+       return ret;
+} /* asubst */
+
+char *subst_string (char *buf, size_t buflen, const char *string,
+               const char *needle, const char *replacement)
+{
+       char *temp;
+       size_t needle_len;
+       size_t i;
+
+       if ((buf == NULL) || (string == NULL)
+                       || (needle == NULL) || (replacement == NULL))
+               return (NULL);
+
+       temp = (char *) malloc (buflen);
+       if (temp == NULL)
+       {
+               ERROR ("subst_string: malloc failed.");
+               return (NULL);
+       }
+
+       needle_len = strlen (needle);
+       strncpy (buf, string, buflen);
+
+       /* Limit the loop to prevent endless loops. */
+       for (i = 0; i < buflen; i++)
+       {
+               char *begin_ptr;
+               size_t begin;
+
+               /* Find `needle' in `buf'. */
+               begin_ptr = strstr (buf, needle);
+               if (begin_ptr == NULL)
+                       break;
+
+               /* Calculate the start offset. */
+               begin = begin_ptr - buf;
+
+               /* Substitute the region using `subst'. The result is stored in
+                * `temp'. */
+               begin_ptr = subst (temp, buflen, buf,
+                               begin, begin + needle_len,
+                               replacement);
+               if (begin_ptr == NULL)
+               {
+                       WARNING ("subst_string: subst failed.");
+                       break;
+               }
+
+               /* Copy the new string in `temp' to `buf' for the next round. */
+               strncpy (buf, temp, buflen);
+       }
+
+       if (i >= buflen)
+       {
+               WARNING ("subst_string: Loop exited after %zu iterations: "
+                               "string = %s; needle = %s; replacement = %s;",
+                               i, string, needle, replacement);
+       }
+
+       sfree (temp);
+       return (buf);
+} /* char *subst_string */
+
+/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
+
diff --git a/src/daemon/utils_subst.h b/src/daemon/utils_subst.h
new file mode 100644 (file)
index 0000000..9085286
--- /dev/null
@@ -0,0 +1,105 @@
+/**
+ * collectd - src/utils_subst.h
+ * 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>
+ **/
+
+/*
+ * This module provides functions for string substitution.
+ */
+
+#ifndef UTILS_SUBST_H
+#define UTILS_SUBST_H 1
+
+#include <stddef.h>
+
+/*
+ * subst:
+ *
+ * Replace a substring of a string with the specified replacement text. The
+ * resulting string is stored in the buffer pointed to by 'buf' of length
+ * 'buflen'. Upon success, the buffer will always be null-terminated. The
+ * result may be truncated if the buffer is too small.
+ *
+ * The substring to be replaces is identified by the two offsets 'off1' and
+ * 'off2' where 'off1' specifies the offset to the beginning of the substring
+ * and 'off2' specifies the offset to the first byte after the substring.
+ *
+ * The minimum buffer size to store the complete return value (including the
+ * terminating '\0' character) thus has to be:
+ * off1 + strlen(replacement) + strlen(string) - off2 + 1
+ *
+ * Example:
+ *
+ *             01234567890
+ *   string = "foo_____bar"
+ *                ^    ^
+ *                |    |
+ *              off1  off2
+ *
+ *   off1 = 3
+ *   off2 = 8
+ *
+ *   replacement = " - "
+ *
+ *   -> "foo - bar"
+ *
+ * The function returns 'buf' on success, NULL else.
+ */
+char *subst (char *buf, size_t buflen, const char *string, int off1, int off2,
+               const char *replacement);
+
+/*
+ * asubst:
+ *
+ * This function is very similar to subst(). It differs in that it
+ * automatically allocates the memory required for the return value which the
+ * user then has to free himself.
+ *
+ * Returns the newly allocated result string on success, NULL else.
+ */
+char *asubst (const char *string, int off1, int off2, const char *replacement);
+
+/*
+ * subst_string:
+ *
+ * Works like `subst', but instead of specifying start and end offsets you
+ * specify `needle', the string that is to be replaced. If `needle' is found
+ * in `string' (using strstr(3)), the offset is calculated and `subst' is
+ * called with the determined parameters.
+ *
+ * If the substring is not found, no error will be indicated and
+ * `subst_string' works mostly like `strncpy'.
+ *
+ * If the substring appears multiple times, all appearances will be replaced.
+ * If the substring has been found `buflen' times, an endless loop is assumed
+ * and the loop is broken. A warning is printed and the function returns
+ * success.
+ */
+char *subst_string (char *buf, size_t buflen, const char *string,
+               const char *needle, const char *replacement);
+
+#endif /* UTILS_SUBST_H */
+
+/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
+
diff --git a/src/daemon/utils_tail.c b/src/daemon/utils_tail.c
new file mode 100644 (file)
index 0000000..fe5dca8
--- /dev/null
@@ -0,0 +1,260 @@
+/**
+ * collectd - src/utils_tail.c
+ * Copyright (C) 2007-2008  C-Ware, Inc.
+ * Copyright (C) 2008       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.
+ *
+ * Author:
+ *   Luke Heberling <lukeh at c-ware.com>
+ *   Florian Forster <octo at collectd.org>
+ *
+ * Description:
+ *   Encapsulates useful code for plugins which must watch for appends to
+ *   the end of a file.
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "utils_tail.h"
+
+struct cu_tail_s
+{
+       char  *file;
+       FILE  *fh;
+       struct stat stat;
+};
+
+static int cu_tail_reopen (cu_tail_t *obj)
+{
+  int seek_end = 0;
+  FILE *fh;
+  struct stat stat_buf;
+  int status;
+
+  memset (&stat_buf, 0, sizeof (stat_buf));
+  status = stat (obj->file, &stat_buf);
+  if (status != 0)
+  {
+    char errbuf[1024];
+    ERROR ("utils_tail: stat (%s) failed: %s", obj->file,
+       sstrerror (errno, errbuf, sizeof (errbuf)));
+    return (-1);
+  }
+
+  /* The file is already open.. */
+  if ((obj->fh != NULL) && (stat_buf.st_ino == obj->stat.st_ino))
+  {
+    /* Seek to the beginning if file was truncated */
+    if (stat_buf.st_size < obj->stat.st_size)
+    {
+      INFO ("utils_tail: File `%s' was truncated.", obj->file);
+      status = fseek (obj->fh, 0, SEEK_SET);
+      if (status != 0)
+      {
+       char errbuf[1024];
+       ERROR ("utils_tail: fseek (%s) failed: %s", obj->file,
+           sstrerror (errno, errbuf, sizeof (errbuf)));
+       fclose (obj->fh);
+       obj->fh = NULL;
+       return (-1);
+      }
+    }
+    memcpy (&obj->stat, &stat_buf, sizeof (struct stat));
+    return (1);
+  }
+
+  /* Seek to the end if we re-open the same file again or the file opened
+   * is the first at all or the first after an error */
+  if ((obj->stat.st_ino == 0) || (obj->stat.st_ino == stat_buf.st_ino))
+    seek_end = 1;
+
+  fh = fopen (obj->file, "r");
+  if (fh == NULL)
+  {
+    char errbuf[1024];
+    ERROR ("utils_tail: fopen (%s) failed: %s", obj->file,
+       sstrerror (errno, errbuf, sizeof (errbuf)));
+    return (-1);
+  }
+
+  if (seek_end != 0)
+  {
+    status = fseek (fh, 0, SEEK_END);
+    if (status != 0)
+    {
+      char errbuf[1024];
+      ERROR ("utils_tail: fseek (%s) failed: %s", obj->file,
+         sstrerror (errno, errbuf, sizeof (errbuf)));
+      fclose (fh);
+      return (-1);
+    }
+  }
+
+  if (obj->fh != NULL)
+    fclose (obj->fh);
+  obj->fh = fh;
+  memcpy (&obj->stat, &stat_buf, sizeof (struct stat));
+
+  return (0);
+} /* int cu_tail_reopen */
+
+cu_tail_t *cu_tail_create (const char *file)
+{
+       cu_tail_t *obj;
+
+       obj = (cu_tail_t *) malloc (sizeof (cu_tail_t));
+       if (obj == NULL)
+               return (NULL);
+       memset (obj, '\0', sizeof (cu_tail_t));
+
+       obj->file = strdup (file);
+       if (obj->file == NULL)
+       {
+               free (obj);
+               return (NULL);
+       }
+
+       obj->fh = NULL;
+
+       return (obj);
+} /* cu_tail_t *cu_tail_create */
+
+int cu_tail_destroy (cu_tail_t *obj)
+{
+       if (obj->fh != NULL)
+               fclose (obj->fh);
+       free (obj->file);
+       free (obj);
+
+       return (0);
+} /* int cu_tail_destroy */
+
+int cu_tail_readline (cu_tail_t *obj, char *buf, int buflen)
+{
+  int status;
+
+  if (buflen < 1)
+  {
+    ERROR ("utils_tail: cu_tail_readline: buflen too small: %i bytes.",
+       buflen);
+    return (-1);
+  }
+
+  if (obj->fh == NULL)
+  {
+    status = cu_tail_reopen (obj);
+    if (status < 0)
+      return (status);
+  }
+  assert (obj->fh != NULL);
+
+  /* Try to read from the filehandle. If that succeeds, everything appears to
+   * be fine and we can return. */
+  clearerr (obj->fh);
+  if (fgets (buf, buflen, obj->fh) != NULL)
+  {
+    buf[buflen - 1] = 0;
+    return (0);
+  }
+
+  /* Check if we encountered an error */
+  if (ferror (obj->fh) != 0)
+  {
+    /* Jupp, error. Force `cu_tail_reopen' to reopen the file.. */
+    fclose (obj->fh);
+    obj->fh = NULL;
+  }
+  /* else: eof -> check if the file was moved away and reopen the new file if
+   * so.. */
+
+  status = cu_tail_reopen (obj);
+  /* error -> return with error */
+  if (status < 0)
+    return (status);
+  /* file end reached and file not reopened -> nothing more to read */
+  else if (status > 0)
+  {
+    buf[0] = 0;
+    return (0);
+  }
+
+  /* If we get here: file was re-opened and there may be more to read.. Let's
+   * try again. */
+  if (fgets (buf, buflen, obj->fh) != NULL)
+  {
+    buf[buflen - 1] = 0;
+    return (0);
+  }
+
+  if (ferror (obj->fh) != 0)
+  {
+    char errbuf[1024];
+    WARNING ("utils_tail: fgets (%s) returned an error: %s", obj->file,
+       sstrerror (errno, errbuf, sizeof (errbuf)));
+    fclose (obj->fh);
+    obj->fh = NULL;
+    return (-1);
+  }
+
+  /* EOf, well, apparently the new file is empty.. */
+  buf[0] = 0;
+  return (0);
+} /* int cu_tail_readline */
+
+int cu_tail_read (cu_tail_t *obj, char *buf, int buflen, tailfunc_t *callback,
+               void *data)
+{
+       int status;
+
+       while (42)
+       {
+               size_t len;
+
+               status = cu_tail_readline (obj, buf, buflen);
+               if (status != 0)
+               {
+                       ERROR ("utils_tail: cu_tail_read: cu_tail_readline "
+                                       "failed.");
+                       break;
+               }
+
+               /* check for EOF */
+               if (buf[0] == 0)
+                       break;
+
+               len = strlen (buf);
+               while (len > 0) {
+                       if (buf[len - 1] != '\n')
+                               break;
+                       buf[len - 1] = '\0';
+                       len--;
+               }
+
+               status = callback (data, buf, buflen);
+               if (status != 0)
+               {
+                       ERROR ("utils_tail: cu_tail_read: callback returned "
+                                       "status %i.", status);
+                       break;
+               }
+       }
+
+       return status;
+} /* int cu_tail_read */
diff --git a/src/daemon/utils_tail.h b/src/daemon/utils_tail.h
new file mode 100644 (file)
index 0000000..6fb7013
--- /dev/null
@@ -0,0 +1,88 @@
+/**
+ * collectd - src/utils_tail.h
+ * Copyright (C) 2007-2008  C-Ware, Inc.
+ *
+ * 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.
+ *
+ * Author:
+ *   Luke Heberling <lukeh at c-ware.com>
+ *
+ * DESCRIPTION
+ *   Facilitates reading information that is appended to a file, taking into
+ *   account that the file may be rotated and a new file created under the
+ *   same name.
+ **/
+
+#ifndef UTILS_TAIL_H
+#define UTILS_TAIL_H 1
+
+struct cu_tail_s;
+typedef struct cu_tail_s cu_tail_t;
+
+typedef int tailfunc_t(void *data, char *buf, int buflen);
+
+/*
+ * NAME
+ *   cu_tail_create
+ *
+ * DESCRIPTION
+ *   Allocates a new tail object..
+ *
+ * PARAMETERS
+ *   `file'       The name of the file to be tailed.
+ */
+cu_tail_t *cu_tail_create (const char *file);
+
+/*
+ * cu_tail_destroy
+ *
+ * Takes a tail object returned by `cu_tail_create' and destroys it, freeing
+ * all internal memory.
+ *
+ * Returns 0 when successful and non-zero otherwise.
+ */
+int cu_tail_destroy (cu_tail_t *obj);
+
+/*
+ * cu_tail_readline
+ *
+ * Reads from the file until `buflen' characters are read, a newline
+ * character is read, or an eof condition is encountered. `buf' is
+ * always null-terminated on successful return and isn't touched when non-zero
+ * is returned.
+ *
+ * You can check if the EOF condition is reached by looking at the buffer: If
+ * the length of the string stored in the buffer is zero, EOF occurred.
+ * Otherwise at least the newline character will be in the buffer.
+ *
+ * Returns 0 when successful and non-zero otherwise.
+ */
+int cu_tail_readline (cu_tail_t *obj, char *buf, int buflen);
+
+/*
+ * cu_tail_readline
+ *
+ * Reads from the file until eof condition or an error is encountered.
+ *
+ * Returns 0 when successful and non-zero otherwise.
+ */
+int cu_tail_read (cu_tail_t *obj, char *buf, int buflen, tailfunc_t *callback,
+               void *data);
+
+#endif /* UTILS_TAIL_H */
diff --git a/src/daemon/utils_tail_match.c b/src/daemon/utils_tail_match.c
new file mode 100644 (file)
index 0000000..8776ad1
--- /dev/null
@@ -0,0 +1,274 @@
+/*
+ * collectd - src/utils_tail_match.c
+ * Copyright (C) 2007-2008  C-Ware, Inc.
+ * Copyright (C) 2008       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.
+ *
+ * Author:
+ *   Luke Heberling <lukeh at c-ware.com>
+ *   Florian Forster <octo at collectd.org>
+ *
+ * Description:
+ *   Encapsulates useful code to plugins which must parse a log file.
+ */
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+#include "utils_match.h"
+#include "utils_tail.h"
+#include "utils_tail_match.h"
+
+struct cu_tail_match_simple_s
+{
+  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];
+  cdtime_t interval;
+};
+typedef struct cu_tail_match_simple_s cu_tail_match_simple_t;
+
+struct cu_tail_match_match_s
+{
+  cu_match_t *match;
+  void *user_data;
+  int (*submit) (cu_match_t *match, void *user_data);
+  void (*free) (void *user_data);
+};
+typedef struct cu_tail_match_match_s cu_tail_match_match_t;
+
+struct cu_tail_match_s
+{
+  int flags;
+  cu_tail_t *tail;
+
+  cdtime_t interval;
+  cu_tail_match_match_t *matches;
+  size_t matches_num;
+};
+
+/*
+ * Private functions
+ */
+static int simple_submit_match (cu_match_t *match, void *user_data)
+{
+  cu_tail_match_simple_t *data = (cu_tail_match_simple_t *) user_data;
+  cu_match_value_t *match_value;
+  value_list_t vl = VALUE_LIST_INIT;
+  value_t values[1];
+
+  match_value = (cu_match_value_t *) match_get_user_data (match);
+  if (match_value == NULL)
+    return (-1);
+
+  if ((match_value->ds_type & UTILS_MATCH_DS_TYPE_GAUGE)
+      && (match_value->values_num == 0))
+    values[0].gauge = NAN;
+  else
+    values[0] = match_value->value;
+
+  vl.values = values;
+  vl.values_len = 1;
+  sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+  sstrncpy (vl.plugin, data->plugin, sizeof (vl.plugin));
+  sstrncpy (vl.plugin_instance, data->plugin_instance,
+      sizeof (vl.plugin_instance));
+  sstrncpy (vl.type, data->type, sizeof (vl.type));
+  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)
+  {
+    match_value->value.gauge = NAN;
+    match_value->values_num = 0;
+  }
+
+  return (0);
+} /* int simple_submit_match */
+
+static int tail_callback (void *data, char *buf,
+    int __attribute__((unused)) buflen)
+{
+  cu_tail_match_t *obj = (cu_tail_match_t *) data;
+  size_t i;
+
+  for (i = 0; i < obj->matches_num; i++)
+    match_apply (obj->matches[i].match, buf);
+
+  return (0);
+} /* int tail_callback */
+
+/*
+ * Public functions
+ */
+cu_tail_match_t *tail_match_create (const char *filename)
+{
+  cu_tail_match_t *obj;
+
+  obj = (cu_tail_match_t *) malloc (sizeof (cu_tail_match_t));
+  if (obj == NULL)
+    return (NULL);
+  memset (obj, '\0', sizeof (cu_tail_match_t));
+
+  obj->tail = cu_tail_create (filename);
+  if (obj->tail == NULL)
+  {
+    sfree (obj);
+    return (NULL);
+  }
+
+  return (obj);
+} /* cu_tail_match_t *tail_match_create */
+
+void tail_match_destroy (cu_tail_match_t *obj)
+{
+  size_t i;
+
+  if (obj == NULL)
+    return;
+
+  if (obj->tail != NULL)
+  {
+    cu_tail_destroy (obj->tail);
+    obj->tail = NULL;
+  }
+
+  for (i = 0; i < obj->matches_num; i++)
+  {
+    cu_tail_match_match_t *match = obj->matches + i;
+    if (match->match != NULL)
+    {
+      match_destroy (match->match);
+      match->match = NULL;
+    }
+
+    if ((match->user_data != NULL)
+       && (match->free != NULL))
+      (*match->free) (match->user_data);
+    match->user_data = NULL;
+  }
+
+  sfree (obj->matches);
+  sfree (obj);
+} /* void tail_match_destroy */
+
+int tail_match_add_match (cu_tail_match_t *obj, cu_match_t *match,
+    int (*submit_match) (cu_match_t *match, void *user_data),
+    void *user_data,
+    void (*free_user_data) (void *user_data))
+{
+  cu_tail_match_match_t *temp;
+
+  temp = (cu_tail_match_match_t *) realloc (obj->matches,
+      sizeof (cu_tail_match_match_t) * (obj->matches_num + 1));
+  if (temp == NULL)
+    return (-1);
+
+  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;
+  temp->user_data = user_data;
+  temp->submit = submit_match;
+  temp->free = free_user_data;
+
+  return (0);
+} /* int tail_match_add_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 cdtime_t interval)
+{
+  cu_match_t *match;
+  cu_tail_match_simple_t *user_data;
+  int status;
+
+  match = match_create_simple (regex, excluderegex, ds_type);
+  if (match == NULL)
+    return (-1);
+
+  user_data = (cu_tail_match_simple_t *) malloc (sizeof (cu_tail_match_simple_t));
+  if (user_data == NULL)
+  {
+    match_destroy (match);
+    return (-1);
+  }
+  memset (user_data, '\0', sizeof (cu_tail_match_simple_t));
+
+  sstrncpy (user_data->plugin, plugin, sizeof (user_data->plugin));
+  if (plugin_instance != NULL)
+    sstrncpy (user_data->plugin_instance, plugin_instance,
+       sizeof (user_data->plugin_instance));
+
+  sstrncpy (user_data->type, type, sizeof (user_data->type));
+  if (type_instance != NULL)
+    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);
+
+  if (status != 0)
+  {
+    match_destroy (match);
+    sfree (user_data);
+  }
+
+  return (status);
+} /* int tail_match_add_match_simple */
+
+int tail_match_read (cu_tail_match_t *obj)
+{
+  char buffer[4096];
+  int status;
+  size_t i;
+
+  status = cu_tail_read (obj->tail, buffer, sizeof (buffer), tail_callback,
+      (void *) obj);
+  if (status != 0)
+  {
+    ERROR ("tail_match: cu_tail_read failed.");
+    return (status);
+  }
+
+  for (i = 0; i < obj->matches_num; i++)
+  {
+    cu_tail_match_match_t *lt_match = obj->matches + i;
+
+    if (lt_match->submit == NULL)
+      continue;
+
+    (*lt_match->submit) (lt_match->match, lt_match->user_data);
+  }
+
+  return (0);
+} /* int tail_match_read */
+
+/* vim: set sw=2 sts=2 ts=8 : */
diff --git a/src/daemon/utils_tail_match.h b/src/daemon/utils_tail_match.h
new file mode 100644 (file)
index 0000000..0404de2
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * collectd - src/utils_tail_match.h
+ * Copyright (C) 2007-2008  C-Ware, Inc.
+ * Copyright (C) 2008       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:
+ *   Luke Heberling <lukeh at c-ware.com>
+ *   Florian Forster <octo at collectd.org>
+ *
+ * Description:
+ *   `tail_match' uses `utils_tail' and `utils_match' to tail a file and try to
+ *   match it using several regular expressions. Matches are then passed to
+ *   user-provided callback functions or default handlers. This should keep all
+ *   of the parsing logic out of the actual plugin, which only operate with
+ *   regular expressions.
+ */
+
+#include "utils_match.h"
+
+struct cu_tail_match_s;
+typedef struct cu_tail_match_s cu_tail_match_t;
+
+/*
+ * NAME
+ *   tail_match_create
+ *
+ * DESCRIPTION
+ *   Allocates, initializes and returns a new `cu_tail_match_t' object.
+ *
+ * PARAMETERS
+ *   `filename'  The name to read data from.
+ *
+ * RETURN VALUE
+ *   Returns NULL upon failure, non-NULL otherwise.
+ */
+cu_tail_match_t *tail_match_create (const char *filename);
+
+/*
+ * NAME
+ *   tail_match_destroy
+ *
+ * DESCRIPTION
+ *   Releases resources used by the `cu_tail_match_t' object.
+ *
+ * PARAMETERS
+ *   The object to destroy.
+ */
+void tail_match_destroy (cu_tail_match_t *obj);
+
+/*
+ * NAME
+ *   tail_match_add_match
+ *
+ * DESCRIPTION
+ *   Adds a match, in form of a `cu_match_t' object, to the object.
+ *   After data has been read from the logfile (using utils_tail) the callback
+ *   function `submit_match' is called with the match object and the user
+ *   supplied data.
+ *   Please note that his function is called regardless whether this match
+ *   matched any lines recently or not.
+ *   When `tail_match_destroy' is called the `user_data' pointer is freed using
+ *   the `free_user_data' callback - if it is not NULL.
+ *   When using this interface the `tail_match' module doesn't dispatch any values
+ *   itself - all that has to happen in either the match-callbacks or the
+ *   submit_match callback.
+ *
+ * RETURN VALUE
+ *   Zero upon success, non-zero otherwise.
+ */
+int tail_match_add_match (cu_tail_match_t *obj, cu_match_t *match,
+    int (*submit_match) (cu_match_t *match, void *user_data),
+    void *user_data,
+    void (*free_user_data) (void *user_data));
+
+/*
+ * NAME
+ *  tail_match_add_match_simple
+ *
+ * DESCRIPTION
+ *  A simplified version of `tail_match_add_match'. The regular expressen `regex'
+ *  must match a number, which is then dispatched according to `ds_type'. See
+ *  the `match_create_simple' function in utils_match.h for a description how
+ *  this flag effects calculation of a new value.
+ *  The values gathered are dispatched by the tail_match module in this case. The
+ *  passed `plugin', `plugin_instance', `type', and `type_instance' are
+ *  directly used when submitting these values.
+ *  With excluderegex it is possible to exlude lines from the match.
+ *
+ * RETURN VALUE
+ *   Zero upon success, non-zero otherwise.
+ */
+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 cdtime_t interval);
+
+/*
+ * NAME
+ *   tail_match_read
+ *
+ * DESCRIPTION
+ *   This function should be called periodically by plugins. It reads new lines
+ *   from the logfile using `utils_tail' and tries to match them using all
+ *   added `utils_match' objects.
+ *   After all lines have been read and processed, the submit_match callback is
+ *   called or, in case of tail_match_add_match_simple, the data is dispatched to
+ *   the daemon directly.
+ *
+ * RETURN VALUE
+ *   Zero on success, nonzero on failure.
+*/
+int tail_match_read (cu_tail_match_t *obj);
+
+/* vim: set sw=2 sts=2 ts=8 : */
diff --git a/src/daemon/utils_threshold.c b/src/daemon/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/daemon/utils_threshold.h b/src/daemon/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 : */
diff --git a/src/daemon/utils_time.c b/src/daemon/utils_time.c
new file mode 100644 (file)
index 0000000..6603c15
--- /dev/null
@@ -0,0 +1,104 @@
+/**
+ * collectd - src/utils_time.c
+ * Copyright (C) 2010       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 <ff at octo.it>
+ **/
+
+#include "collectd.h"
+#include "utils_time.h"
+#include "plugin.h"
+#include "common.h"
+
+#if HAVE_CLOCK_GETTIME
+cdtime_t cdtime (void) /* {{{ */
+{
+  int status;
+  struct timespec ts = { 0, 0 };
+
+  status = clock_gettime (CLOCK_REALTIME, &ts);
+  if (status != 0)
+  {
+    char errbuf[1024];
+    ERROR ("cdtime: clock_gettime failed: %s",
+        sstrerror (errno, errbuf, sizeof (errbuf)));
+    return (0);
+  }
+
+  return (TIMESPEC_TO_CDTIME_T (&ts));
+} /* }}} cdtime_t cdtime */
+#else
+/* Work around for Mac OS X which doesn't have clock_gettime(2). *sigh* */
+cdtime_t cdtime (void) /* {{{ */
+{
+  int status;
+  struct timeval tv = { 0, 0 };
+
+  status = gettimeofday (&tv, /* struct timezone = */ NULL);
+  if (status != 0)
+  {
+    char errbuf[1024];
+    ERROR ("cdtime: gettimeofday failed: %s",
+        sstrerror (errno, errbuf, sizeof (errbuf)));
+    return (0);
+  }
+
+  return (TIMEVAL_TO_CDTIME_T (&tv));
+} /* }}} cdtime_t cdtime */
+#endif
+
+size_t cdtime_to_iso8601 (char *s, size_t max, cdtime_t t) /* {{{ */
+{
+  struct timespec t_spec;
+  struct tm t_tm;
+
+  size_t len;
+
+  CDTIME_T_TO_TIMESPEC (t, &t_spec);
+  NORMALIZE_TIMESPEC (t_spec);
+
+  if (localtime_r ((time_t *)&t_spec.tv_sec, &t_tm) == NULL) {
+    char errbuf[1024];
+    ERROR ("cdtime_to_iso8601: localtime_r failed: %s",
+        sstrerror (errno, errbuf, sizeof (errbuf)));
+    return (0);
+  }
+
+  len = strftime (s, max, "%Y-%m-%dT%H:%M:%S", &t_tm);
+  if (len == 0)
+    return 0;
+
+  if (max - len > 2) {
+    int n = snprintf (s + len, max - len, ".%09i", (int)t_spec.tv_nsec);
+    len += (n < max - len) ? n : max - len;
+  }
+
+  if (max - len > 3) {
+    int n = strftime (s + len, max - len, "%z", &t_tm);
+    len += (n < max - len) ? n : max - len;
+  }
+
+  s[max - 1] = '\0';
+  return len;
+} /* }}} size_t cdtime_to_iso8601 */
+
+/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/src/daemon/utils_time.h b/src/daemon/utils_time.h
new file mode 100644 (file)
index 0000000..9b08e8e
--- /dev/null
@@ -0,0 +1,81 @@
+/**
+ * collectd - src/utils_time.h
+ * Copyright (C) 2010       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 <ff at octo.it>
+ **/
+
+#ifndef UTILS_TIME_H
+#define UTILS_TIME_H 1
+
+#include "collectd.h"
+
+/*
+ * "cdtime_t" is a 64bit unsigned integer. The time is stored at a 2^-30 second
+ * resolution, i.e. the most significant 34 bit are used to store the time in
+ * seconds, the least significant bits store the sub-second part in something
+ * very close to nanoseconds. *The* big advantage of storing time in this
+ * manner is that comparing times and calculating differences is as simple as
+ * it is with "time_t", i.e. a simple integer comparison / subtraction works.
+ */
+/* 
+ * cdtime_t is defined in "collectd.h" */
+/* typedef uint64_t cdtime_t; */
+
+/* 2^30 = 1073741824 */
+#define TIME_T_TO_CDTIME_T(t) (((cdtime_t) (t)) * 1073741824)
+#define CDTIME_T_TO_TIME_T(t) ((time_t) ((t) / 1073741824))
+
+#define CDTIME_T_TO_DOUBLE(t) (((double) (t)) / 1073741824.0)
+#define DOUBLE_TO_CDTIME_T(d) ((cdtime_t) ((d) * 1073741824.0))
+
+#define MS_TO_CDTIME_T(ms) ((cdtime_t)    (((double) (ms)) * 1073741.824))
+#define CDTIME_T_TO_MS(t)  ((long)        (((double) (t))  / 1073741.824))
+#define US_TO_CDTIME_T(us) ((cdtime_t)    (((double) (us)) * 1073.741824))
+#define CDTIME_T_TO_US(t)  ((suseconds_t) (((double) (t))  / 1073.741824))
+#define NS_TO_CDTIME_T(ns) ((cdtime_t)    (((double) (ns)) * 1.073741824))
+#define CDTIME_T_TO_NS(t)  ((long)        (((double) (t))  / 1.073741824))
+
+#define CDTIME_T_TO_TIMEVAL(cdt,tvp) do {                                    \
+        (tvp)->tv_sec = CDTIME_T_TO_TIME_T (cdt);                            \
+        (tvp)->tv_usec = CDTIME_T_TO_US ((cdt) % 1073741824);                \
+} while (0)
+#define TIMEVAL_TO_CDTIME_T(tv) (TIME_T_TO_CDTIME_T ((tv)->tv_sec)           \
+    + US_TO_CDTIME_T ((tv)->tv_usec))
+
+#define CDTIME_T_TO_TIMESPEC(cdt,tsp) do {                                   \
+  (tsp)->tv_sec = CDTIME_T_TO_TIME_T (cdt);                                  \
+  (tsp)->tv_nsec = CDTIME_T_TO_NS ((cdt) % 1073741824);                      \
+} while (0)
+#define TIMESPEC_TO_CDTIME_T(ts) (TIME_T_TO_CDTIME_T ((ts)->tv_sec)           \
+    + NS_TO_CDTIME_T ((ts)->tv_nsec))
+
+cdtime_t cdtime (void);
+
+/* format a cdtime_t value in ISO 8601 format:
+ * returns the number of characters written to the string (not including the
+ * terminating null byte or 0 on error; the function ensures that the string
+ * is null terminated */
+size_t cdtime_to_iso8601 (char *s, size_t max, cdtime_t t);
+
+#endif /* UTILS_TIME_H */
+/* vim: set sw=2 sts=2 et : */
diff --git a/src/daemon/utils_time_mock.c b/src/daemon/utils_time_mock.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);
+}
+
index 29cf5bd52c7783beca315b9e9bd2a0dd649b02d5..a7963ea223371f5d70a4ef63f2d0a3a6263db22a 100644 (file)
--- a/src/dbi.c
+++ b/src/dbi.c
@@ -2,18 +2,23 @@
  * collectd - src/dbi.c
  * Copyright (C) 2008-2015  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>
@@ -83,6 +88,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
  */
@@ -384,9 +391,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);
     }
   }
 
@@ -773,8 +795,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;
@@ -813,32 +836,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;
-
-  /* TODO(octo): Starting with libdbi 0.9.0, there is an "instance" argument to
-   * the *_r-functions. We should probably have multiple read callbacks instead
-   * of this loop. */
-  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;
@@ -866,7 +863,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 3b0c995b2f0fed286f47d8d80e94b10fe75dd828..cb0ff2ffe2ba5bfcefb046c0502021b27f4411c6 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 36d0a0c3450cc46b46d8a5d3725dedbaad9c2231..1c3dd98d7d2a93318e8ce0318fbd8acbbd15e016 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);
 
@@ -163,6 +171,21 @@ static int disk_config (const char *key, const char *value)
 #else
     WARNING ("disk plugin: The \"UseBSDName\" option is only supported "
         "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
@@ -249,6 +272,48 @@ static void disk_submit (const char *plugin_instance,
 } /* void disk_submit */
 
 #if KERNEL_LINUX
+static void submit_in_progress (char const *disk_name, gauge_t in_progress)
+{
+       value_t v;
+       value_list_t vl = VALUE_LIST_INIT;
+
+       if (ignorelist_match (ignorelist, disk_name) != 0)
+         return;
+
+       v.gauge = in_progress;
+
+       vl.values = &v;
+       vl.values_len = 1;
+       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       sstrncpy (vl.plugin, "disk", sizeof (vl.plugin));
+       sstrncpy (vl.plugin_instance, disk_name, sizeof (vl.plugin_instance));
+       sstrncpy (vl.type, "pending_operations", sizeof (vl.type));
+
+       plugin_dispatch_values (&vl);
+}
+
+static void submit_io_time (char const *plugin_instance, derive_t io_time, derive_t weighted_time)
+{
+       value_t values[2];
+       value_list_t vl = VALUE_LIST_INIT;
+
+       if (ignorelist_match (ignorelist, plugin_instance) != 0)
+         return;
+
+       values[0].derive = io_time;
+       values[1].derive = weighted_time;
+
+       vl.values = values;
+       vl.values_len = 2;
+       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       sstrncpy (vl.plugin, "disk", sizeof (vl.plugin));
+       sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
+       sstrncpy (vl.type, "disk_io_time", sizeof (vl.type));
+
+       plugin_dispatch_values (&vl);
+}
+
+
 static counter_t disk_calc_time_incr (counter_t delta_time, counter_t delta_ops)
 {
        double interval = CDTIME_T_TO_DOUBLE (plugin_get_interval ());
@@ -259,6 +324,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)
 {
@@ -302,169 +395,112 @@ static int disk_read (void)
        io_registry_entry_t     disk;
        io_registry_entry_t     disk_child;
        io_iterator_t           disk_list;
-       CFDictionaryRef         props_dict;
+       CFMutableDictionaryRef  props_dict, child_dict;
        CFDictionaryRef         stats_dict;
-       CFDictionaryRef         child_dict;
        CFStringRef             tmp_cf_string_ref;
        kern_return_t           status;
 
-       signed long long read_ops;
-       signed long long read_byt;
-       signed long long read_tme;
-       signed long long write_ops;
-       signed long long write_byt;
-       signed long long write_tme;
+       signed long long read_ops, read_byt, read_tme;
+       signed long long write_ops, write_byt, write_tme;
 
-       int  disk_major;
-       int  disk_minor;
+       int  disk_major, disk_minor;
        char disk_name[DATA_MAX_NAME_LEN];
-       char disk_name_bsd[DATA_MAX_NAME_LEN];
+       char child_disk_name_bsd[DATA_MAX_NAME_LEN], props_disk_name_bsd[DATA_MAX_NAME_LEN];
 
        /* Get the list of all disk objects. */
-       if (IOServiceGetMatchingServices (io_master_port,
-                               IOServiceMatching (kIOBlockStorageDriverClass),
-                               &disk_list) != kIOReturnSuccess)
-       {
+       if (IOServiceGetMatchingServices (io_master_port, IOServiceMatching (kIOBlockStorageDriverClass), &disk_list) != kIOReturnSuccess) {
                ERROR ("disk plugin: IOServiceGetMatchingServices failed.");
                return (-1);
        }
 
-       while ((disk = IOIteratorNext (disk_list)) != 0)
-       {
+       while ((disk = IOIteratorNext (disk_list)) != 0) {
                props_dict = NULL;
                stats_dict = NULL;
                child_dict = NULL;
 
-               /* `disk_child' must be released */
-               if ((status = IORegistryEntryGetChildEntry (disk, kIOServicePlane, &disk_child))
-                               != kIOReturnSuccess)
-               {
-                       /* This fails for example for DVD/CD drives.. */
+               /* get child of disk entry and corresponding property dictionary */
+               if ((status = IORegistryEntryGetChildEntry (disk, kIOServicePlane, &disk_child)) != kIOReturnSuccess) {
+                       /* This fails for example for DVD/CD drives, which we want to ignore anyway */
                        DEBUG ("IORegistryEntryGetChildEntry (disk) failed: 0x%08x", status);
                        IOObjectRelease (disk);
                        continue;
                }
-
-               /* We create `props_dict' => we need to release it later */
-               if (IORegistryEntryCreateCFProperties (disk,
-                                       (CFMutableDictionaryRef *) &props_dict,
-                                       kCFAllocatorDefault,
-                                       kNilOptions)
-                               != kIOReturnSuccess)
-               {
-                       ERROR ("disk-plugin: IORegistryEntryCreateCFProperties failed.");
+               if (IORegistryEntryCreateCFProperties (disk_child, (CFMutableDictionaryRef *) &child_dict, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess || child_dict == NULL) {
+                       ERROR ("disk plugin: IORegistryEntryCreateCFProperties (disk_child) failed.");
                        IOObjectRelease (disk_child);
                        IOObjectRelease (disk);
                        continue;
                }
 
-               if (props_dict == NULL)
-               {
-                       DEBUG ("IORegistryEntryCreateCFProperties (disk) failed.");
-                       IOObjectRelease (disk_child);
-                       IOObjectRelease (disk);
-                       continue;
+               /* extract name and major/minor numbers */
+               memset (child_disk_name_bsd, 0, sizeof (child_disk_name_bsd));
+               tmp_cf_string_ref = (CFStringRef) CFDictionaryGetValue (child_dict, CFSTR(kIOBSDNameKey));
+               if (tmp_cf_string_ref) {
+                       assert (CFGetTypeID (tmp_cf_string_ref) == CFStringGetTypeID ());
+                       CFStringGetCString (tmp_cf_string_ref, child_disk_name_bsd, sizeof (child_disk_name_bsd), kCFStringEncodingUTF8);
                }
+               disk_major = (int) dict_get_value (child_dict, kIOBSDMajorKey);
+               disk_minor = (int) dict_get_value (child_dict, kIOBSDMinorKey);
+               DEBUG ("disk plugin: child_disk_name_bsd=\"%s\" major=%d minor=%d", child_disk_name_bsd, disk_major, disk_minor);
+               CFRelease (child_dict);
+               IOObjectRelease (disk_child);
 
-               /* tmp_cf_string_ref doesn't need to be released. */
-               tmp_cf_string_ref = (CFStringRef) CFDictionaryGetValue (props_dict,
-                               CFSTR(kIOBSDNameKey));
-               if (!tmp_cf_string_ref)
-               {
-                       DEBUG ("disk plugin: CFDictionaryGetValue("
-                                       "kIOBSDNameKey) failed.");
-                       CFRelease (props_dict);
-                       IOObjectRelease (disk_child);
+               /* get property dictionary of the disk entry itself */
+               if (IORegistryEntryCreateCFProperties (disk, (CFMutableDictionaryRef *) &props_dict, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess || props_dict == NULL) {
+                       ERROR ("disk-plugin: IORegistryEntryCreateCFProperties failed.");
                        IOObjectRelease (disk);
                        continue;
                }
-               assert (CFGetTypeID (tmp_cf_string_ref) == CFStringGetTypeID ());
 
-               memset (disk_name_bsd, 0, sizeof (disk_name_bsd));
-               CFStringGetCString (tmp_cf_string_ref,
-                               disk_name_bsd, sizeof (disk_name_bsd),
-                               kCFStringEncodingUTF8);
-               if (disk_name_bsd[0] == 0)
-               {
-                       ERROR ("disk plugin: CFStringGetCString() failed.");
-                       CFRelease (props_dict);
-                       IOObjectRelease (disk_child);
-                       IOObjectRelease (disk);
-                       continue;
+               /* extract name and stats dictionary */
+               memset (props_disk_name_bsd, 0, sizeof (props_disk_name_bsd));
+               tmp_cf_string_ref = (CFStringRef) CFDictionaryGetValue (props_dict, CFSTR(kIOBSDNameKey));
+               if (tmp_cf_string_ref) {
+                       assert (CFGetTypeID (tmp_cf_string_ref) == CFStringGetTypeID ());
+                       CFStringGetCString (tmp_cf_string_ref, props_disk_name_bsd, sizeof (props_disk_name_bsd), kCFStringEncodingUTF8);
                }
-               DEBUG ("disk plugin: disk_name_bsd = \"%s\"", disk_name_bsd);
-
-               stats_dict = (CFDictionaryRef) CFDictionaryGetValue (props_dict,
-                               CFSTR (kIOBlockStorageDriverStatisticsKey));
-
-               if (stats_dict == NULL)
-               {
-                       DEBUG ("disk plugin: CFDictionaryGetValue ("
-                                       "%s) failed.",
-                                       kIOBlockStorageDriverStatisticsKey);
+               stats_dict = (CFDictionaryRef) CFDictionaryGetValue (props_dict, CFSTR (kIOBlockStorageDriverStatisticsKey));
+               if (stats_dict == NULL) {
+                       ERROR ("disk plugin: CFDictionaryGetValue (%s) failed.", kIOBlockStorageDriverStatisticsKey);
                        CFRelease (props_dict);
-                       IOObjectRelease (disk_child);
                        IOObjectRelease (disk);
                        continue;
                }
-
-               if (IORegistryEntryCreateCFProperties (disk_child,
-                                       (CFMutableDictionaryRef *) &child_dict,
-                                       kCFAllocatorDefault,
-                                       kNilOptions)
-                               != kIOReturnSuccess)
-               {
-                       DEBUG ("disk plugin: IORegistryEntryCreateCFProperties ("
-                                       "disk_child) failed.");
-                       IOObjectRelease (disk_child);
-                       CFRelease (props_dict);
-                       IOObjectRelease (disk);
-                       continue;
+               DEBUG ("disk plugin: props_disk_name_bsd=\"%s\"", props_disk_name_bsd);
+
+               /* choose name */
+               if (use_bsd_name) {
+                       if (child_disk_name_bsd[0] != 0)
+                               sstrncpy (disk_name, child_disk_name_bsd, sizeof (disk_name));
+                       else if (props_disk_name_bsd[0] != 0)
+                               sstrncpy (disk_name, props_disk_name_bsd, sizeof (disk_name));
+                       else {
+                               ERROR ("disk plugin: can't find bsd disk name.");
+                               ssnprintf (disk_name, sizeof (disk_name), "%i-%i", disk_major, disk_minor);
+                       }
                }
-
-               /* kIOBSDNameKey */
-               disk_major = (int) dict_get_value (child_dict,
-                               kIOBSDMajorKey);
-               disk_minor = (int) dict_get_value (child_dict,
-                               kIOBSDMinorKey);
-               read_ops  = dict_get_value (stats_dict,
-                               kIOBlockStorageDriverStatisticsReadsKey);
-               read_byt  = dict_get_value (stats_dict,
-                               kIOBlockStorageDriverStatisticsBytesReadKey);
-               read_tme  = dict_get_value (stats_dict,
-                               kIOBlockStorageDriverStatisticsTotalReadTimeKey);
-               write_ops = dict_get_value (stats_dict,
-                               kIOBlockStorageDriverStatisticsWritesKey);
-               write_byt = dict_get_value (stats_dict,
-                               kIOBlockStorageDriverStatisticsBytesWrittenKey);
-               /* This property describes the number of nanoseconds spent
-                * performing writes since the block storage driver was
-                * instantiated. It is one of the statistic entries listed
-                * under the top-level kIOBlockStorageDriverStatisticsKey
-                * property table. It has an OSNumber value. */
-               write_tme = dict_get_value (stats_dict,
-                               kIOBlockStorageDriverStatisticsTotalWriteTimeKey);
-
-               if (use_bsd_name)
-                       sstrncpy (disk_name, disk_name_bsd, sizeof (disk_name));
                else
-                       ssnprintf (disk_name, sizeof (disk_name), "%i-%i",
-                                       disk_major, disk_minor);
-               DEBUG ("disk plugin: disk_name = \"%s\"", disk_name);
+                       ssnprintf (disk_name, sizeof (disk_name), "%i-%i", disk_major, disk_minor);
+
+               /* extract the stats */
+               read_ops  = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsReadsKey);
+               read_byt  = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsBytesReadKey);
+               read_tme  = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsTotalReadTimeKey);
+               write_ops = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsWritesKey);
+               write_byt = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsBytesWrittenKey);
+               write_tme = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsTotalWriteTimeKey);
+               CFRelease (props_dict);
+               IOObjectRelease (disk);
 
+               /* and submit */
+               DEBUG ("disk plugin: disk_name = \"%s\"", disk_name);
                if ((read_byt != -1LL) || (write_byt != -1LL))
                        disk_submit (disk_name, "disk_octets", read_byt, write_byt);
                if ((read_ops != -1LL) || (write_ops != -1LL))
                        disk_submit (disk_name, "disk_ops", read_ops, write_ops);
                if ((read_tme != -1LL) || (write_tme != -1LL))
-                       disk_submit (disk_name, "disk_time",
-                                       read_tme / 1000,
-                                       write_tme / 1000);
+                       disk_submit (disk_name, "disk_time", read_tme / 1000, write_tme / 1000);
 
-               CFRelease (child_dict);
-               IOObjectRelease (disk_child);
-               CFRelease (props_dict);
-               IOObjectRelease (disk);
        }
        IOObjectRelease (disk_list);
 /* #endif HAVE_IOKIT_IOKITLIB_H */
@@ -488,6 +524,9 @@ static int disk_read (void)
        derive_t write_ops     = 0;
        derive_t write_merged  = 0;
        derive_t write_time    = 0;
+       gauge_t in_progress    = NAN;
+       derive_t io_time       = 0;
+       derive_t weighted_time = 0;
        int is_disk = 0;
 
        diskstats_t *ds, *pre_ds;
@@ -505,9 +544,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);
 
@@ -563,6 +608,11 @@ static int disk_read (void)
                                read_time    = atoll (fields[6 + fieldshift]);
                                write_merged = atoll (fields[8 + fieldshift]);
                                write_time   = atoll (fields[10+ fieldshift]);
+
+                               in_progress = atof (fields[11 + fieldshift]);
+
+                               io_time       = atof (fields[12 + fieldshift]);
+                               weighted_time = atof (fields[13 + fieldshift]);
                        }
                }
                else
@@ -659,25 +709,45 @@ 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);
+                       submit_in_progress (output_name, in_progress);
+                       submit_io_time (output_name, io_time, weighted_time);
                } /* 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) */
 
@@ -732,7 +802,12 @@ static int disk_read (void)
 
 #elif defined(HAVE_LIBSTATGRAB)
        sg_disk_io_stats *ds;
-       int disks, counter;
+# if HAVE_LIBSTATGRAB_0_90
+       size_t disks;
+# else
+       int disks;
+#endif
+       int counter;
        char name[DATA_MAX_NAME_LEN];
        
        if ((ds = sg_get_disk_io_stats(&disks)) == NULL)
index 00fcff191e0ccf0177ec7bea309eb2964b331228..fd75dc93a9437fb9bd0d7a580c1937e26f19b859 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -21,6 +21,7 @@
  *   Mirko Buffoni <briareos at eswat.org>
  **/
 
+#define _DEFAULT_SOURCE
 #define _BSD_SOURCE
 
 #include "collectd.h"
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 fdcf0677837e25cb27e50e78ad6c69f17be7bc3c..365af274d4274cb70d42215e04c11e2fb08c3851 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 d56be6dc1df8f4645eb7c4f04a820ee978d87a8b..03de9efb48175dccecf7bdd6ab3a53ddf730e33d 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 18124002b23dbdd89192024770b87753bceb3934..8d737cea0354e2490bd801c350fdac63a7dbf650 100644 (file)
  * 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>
  **/
 
+#define _DEFAULT_SOURCE
 #define _BSD_SOURCE /* For setgroups */
 
 #include "collectd.h"
diff --git a/src/fhcount.c b/src/fhcount.c
new file mode 100644 (file)
index 0000000..4c409b5
--- /dev/null
@@ -0,0 +1,139 @@
+/**
+ *
+ * collectd - src/fhcount.c
+ * Copyright (c) 2015, Jiri Tyr <jiri.tyr at gmail.com>
+ *
+ * Permission to use, copy, modify, and/or 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.
+ *
+ * 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 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.
+ *
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+#include "configfile.h"
+
+
+static const char *config_keys[] = {
+  "ValuesAbsolute",
+  "ValuesPercentage"
+};
+static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
+
+static _Bool values_absolute = 1;
+static _Bool values_percentage = 0;
+
+
+static int fhcount_config(const char *key, const char *value) {
+  int ret = -1;
+
+  if (strcasecmp(key, "ValuesAbsolute") == 0) {
+    if (IS_TRUE(value)) {
+      values_absolute = 1;
+    } else {
+      values_absolute = 0;
+    }
+
+    ret = 0;
+  } else if (strcasecmp(key, "ValuesPercentage") == 0) {
+    if (IS_TRUE(value)) {
+      values_percentage = 1;
+    } else {
+      values_percentage = 0;
+    }
+
+    ret = 0;
+  }
+
+  return(ret);
+}
+
+
+static void fhcount_submit(
+    const char *type, 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;
+
+  // Compose the metric
+  sstrncpy(vl.host, hostname_g, sizeof(vl.host));
+  sstrncpy(vl.plugin, "fhcount", sizeof(vl.plugin));
+  sstrncpy(vl.type, type, sizeof(vl.type));
+  sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
+
+  // Dispatch the metric
+  plugin_dispatch_values(&vl);
+}
+
+
+static int fhcount_read(void) {
+  int numfields = 0;
+  int buffer_len = 60;
+  gauge_t used, unused, max;
+  int prc_used, prc_unused;
+  char *fields[3];
+  char buffer[buffer_len];
+  char errbuf[1024];
+  FILE *fp;
+
+  // Open file
+  fp = fopen("/proc/sys/fs/file-nr" , "r");
+  if (fp == NULL) {
+    ERROR("fhcount: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+    return(EXIT_FAILURE);
+  }
+  if (fgets(buffer, buffer_len, fp) == NULL) {
+    ERROR("fhcount: fgets: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+    return(EXIT_FAILURE);
+  }
+  fclose(fp);
+
+  // Tokenize string
+  numfields = strsplit(buffer, fields, STATIC_ARRAY_SIZE(fields));
+
+  if (numfields != 3) {
+    ERROR("fhcount: Line doesn't contain 3 fields");
+    return(EXIT_FAILURE);
+  }
+
+  // Define the values
+  strtogauge(fields[0], &used);
+  strtogauge(fields[1], &unused);
+  strtogauge(fields[2], &max);
+  prc_used = (gauge_t) used/max*100;
+  prc_unused = (gauge_t) unused/max*100;
+
+  // Submit values
+  if (values_absolute) {
+    fhcount_submit("file_handles", "used", (gauge_t) used);
+    fhcount_submit("file_handles", "unused", (gauge_t) unused);
+    fhcount_submit("file_handles", "max", (gauge_t) max);
+  }
+  if (values_percentage) {
+    fhcount_submit("percent", "used", (gauge_t) prc_used);
+    fhcount_submit("percent", "unused", (gauge_t) prc_unused);
+  }
+
+  return(0);
+}
+
+
+void module_register(void) {
+  plugin_register_config(
+    "fhcount", fhcount_config, config_keys, config_keys_num);
+  plugin_register_read("fhcount", fhcount_read);
+}
index 47f99e91c8e3df2a502208ba6f99f6596afe10e1..47caf93f264af693e0e011634abbf62345b62908 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"
diff --git a/src/filter_chain.c b/src/filter_chain.c
deleted file mode 100644 (file)
index c9be097..0000000
+++ /dev/null
@@ -1,1059 +0,0 @@
-/**
- * collectd - src/filter_chain.h
- * 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.
- *
- * 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
- *
- * Authors:
- *   Florian octo Forster <octo at verplant.org>
- **/
-
-#include "collectd.h"
-#include "configfile.h"
-#include "plugin.h"
-#include "utils_complain.h"
-#include "common.h"
-#include "filter_chain.h"
-
-/*
- * Data types
- */
-/* List of matches, used in fc_rule_t and for the global `match_list_head'
- * variable. */
-struct fc_match_s;
-typedef struct fc_match_s fc_match_t; /* {{{ */
-struct fc_match_s
-{
-  char name[DATA_MAX_NAME_LEN];
-  match_proc_t proc;
-  void *user_data;
-  fc_match_t *next;
-}; /* }}} */
-
-/* List of targets, used in fc_rule_t and for the global `target_list_head'
- * variable. */
-struct fc_target_s;
-typedef struct fc_target_s fc_target_t; /* {{{ */
-struct fc_target_s
-{
-  char name[DATA_MAX_NAME_LEN];
-  void *user_data;
-  target_proc_t proc;
-  fc_target_t *next;
-}; /* }}} */
-
-/* List of rules, used in fc_chain_t */
-struct fc_rule_s;
-typedef struct fc_rule_s fc_rule_t; /* {{{ */
-struct fc_rule_s
-{
-  char name[DATA_MAX_NAME_LEN];
-  fc_match_t  *matches;
-  fc_target_t *targets;
-  fc_rule_t *next;
-}; /* }}} */
-
-/* List of chains, used for `chain_list_head' */
-struct fc_chain_s /* {{{ */
-{
-  char name[DATA_MAX_NAME_LEN];
-  fc_rule_t   *rules;
-  fc_target_t *targets;
-  fc_chain_t  *next;
-}; /* }}} */
-
-/* Writer configuration. */
-struct fc_writer_s;
-typedef struct fc_writer_s fc_writer_t; /* {{{ */
-struct fc_writer_s
-{
-  char *plugin;
-  c_complain_t complaint;
-}; /* }}} */
-
-/*
- * Global variables
- */
-static fc_match_t  *match_list_head;
-static fc_target_t *target_list_head;
-static fc_chain_t  *chain_list_head;
-
-/*
- * Private functions
- */
-static void fc_free_matches (fc_match_t *m) /* {{{ */
-{
-  if (m == NULL)
-    return;
-
-  if (m->proc.destroy != NULL)
-    (*m->proc.destroy) (&m->user_data);
-  else if (m->user_data != NULL)
-  {
-    ERROR ("Filter subsystem: fc_free_matches: There is user data, but no "
-        "destroy functions has been specified. "
-        "Memory will probably be lost!");
-  }
-
-  if (m->next != NULL)
-    fc_free_matches (m->next);
-
-  free (m);
-} /* }}} void fc_free_matches */
-
-static void fc_free_targets (fc_target_t *t) /* {{{ */
-{
-  if (t == NULL)
-    return;
-
-  if (t->proc.destroy != NULL)
-    (*t->proc.destroy) (&t->user_data);
-  else if (t->user_data != NULL)
-  {
-    ERROR ("Filter subsystem: fc_free_targets: There is user data, but no "
-        "destroy functions has been specified. "
-        "Memory will probably be lost!");
-  }
-
-  if (t->next != NULL)
-    fc_free_targets (t->next);
-
-  free (t);
-} /* }}} void fc_free_targets */
-
-static void fc_free_rules (fc_rule_t *r) /* {{{ */
-{
-  if (r == NULL)
-    return;
-
-  fc_free_matches (r->matches);
-  fc_free_targets (r->targets);
-
-  if (r->next != NULL)
-    fc_free_rules (r->next);
-
-  free (r);
-} /* }}} void fc_free_rules */
-
-static void fc_free_chains (fc_chain_t *c) /* {{{ */
-{
-  if (c == NULL)
-    return;
-
-  fc_free_rules (c->rules);
-  fc_free_targets (c->targets);
-
-  if (c->next != NULL)
-    fc_free_chains (c->next);
-
-  free (c);
-} /* }}} void fc_free_chains */
-
-static char *fc_strdup (const char *orig) /* {{{ */
-{
-  size_t sz;
-  char *dest;
-
-  if (orig == NULL)
-    return (NULL);
-
-  sz = strlen (orig) + 1;
-  dest = (char *) malloc (sz);
-  if (dest == NULL)
-    return (NULL);
-
-  memcpy (dest, orig, sz);
-
-  return (dest);
-} /* }}} char *fc_strdup */
-
-/*
- * Configuration.
- *
- * The configuration looks somewhat like this:
- *
- *  <Chain "PreCache">
- *    <Rule>
- *      <Match "regex">
- *        Plugin "^mysql$"
- *        Type "^mysql_command$"
- *        TypeInstance "^show_"
- *      </Match>
- *      <Target "drop">
- *      </Target>
- *    </Rule>
- *
- *    <Target "write">
- *      Plugin "rrdtool"
- *    </Target>
- *  </Chain>
- */
-static int fc_config_add_match (fc_match_t **matches_head, /* {{{ */
-    oconfig_item_t *ci)
-{
-  fc_match_t *m;
-  fc_match_t *ptr;
-  int status;
-
-  if ((ci->values_num != 1)
-      || (ci->values[0].type != OCONFIG_TYPE_STRING))
-  {
-    WARNING ("Filter subsystem: `Match' blocks require "
-        "exactly one string argument.");
-    return (-1);
-  }
-
-  ptr = match_list_head;
-  while (ptr != NULL)
-  {
-    if (strcasecmp (ptr->name, ci->values[0].value.string) == 0)
-      break;
-    ptr = ptr->next;
-  }
-
-  if (ptr == NULL)
-  {
-    WARNING ("Filter subsystem: Cannot find a \"%s\" match. "
-        "Did you load the appropriate plugin?",
-        ci->values[0].value.string);
-    return (-1);
-  }
-
-  m = (fc_match_t *) malloc (sizeof (*m));
-  if (m == NULL)
-  {
-    ERROR ("fc_config_add_match: malloc failed.");
-    return (-1);
-  }
-  memset (m, 0, sizeof (*m));
-
-  sstrncpy (m->name, ptr->name, sizeof (m->name));
-  memcpy (&m->proc, &ptr->proc, sizeof (m->proc));
-  m->user_data = NULL;
-  m->next = NULL;
-
-  if (m->proc.create != NULL)
-  {
-    status = (*m->proc.create) (ci, &m->user_data);
-    if (status != 0)
-    {
-      WARNING ("Filter subsystem: Failed to create a %s match.",
-          m->name);
-      fc_free_matches (m);
-      return (-1);
-    }
-  }
-
-  if (*matches_head != NULL)
-  {
-    ptr = *matches_head;
-    while (ptr->next != NULL)
-      ptr = ptr->next;
-
-    ptr->next = m;
-  }
-  else
-  {
-    *matches_head = m;
-  }
-
-  return (0);
-} /* }}} int fc_config_add_match */
-
-static int fc_config_add_target (fc_target_t **targets_head, /* {{{ */
-    oconfig_item_t *ci)
-{
-  fc_target_t *t;
-  fc_target_t *ptr;
-  int status;
-
-  if ((ci->values_num != 1)
-      || (ci->values[0].type != OCONFIG_TYPE_STRING))
-  {
-    WARNING ("Filter subsystem: `Target' blocks require "
-        "exactly one string argument.");
-    return (-1);
-  }
-
-  ptr = target_list_head;
-  while (ptr != NULL)
-  {
-    if (strcasecmp (ptr->name, ci->values[0].value.string) == 0)
-      break;
-    ptr = ptr->next;
-  }
-
-  if (ptr == NULL)
-  {
-    WARNING ("Filter subsystem: Cannot find a \"%s\" target. "
-        "Did you load the appropriate plugin?",
-        ci->values[0].value.string);
-    return (-1);
-  }
-
-  t = (fc_target_t *) malloc (sizeof (*t));
-  if (t == NULL)
-  {
-    ERROR ("fc_config_add_target: malloc failed.");
-    return (-1);
-  }
-  memset (t, 0, sizeof (*t));
-
-  sstrncpy (t->name, ptr->name, sizeof (t->name));
-  memcpy (&t->proc, &ptr->proc, sizeof (t->proc));
-  t->user_data = NULL;
-  t->next = NULL;
-
-  if (t->proc.create != NULL)
-  {
-    status = (*t->proc.create) (ci, &t->user_data);
-    if (status != 0)
-    {
-      WARNING ("Filter subsystem: Failed to create a %s target.",
-          t->name);
-      fc_free_targets (t);
-      return (-1);
-    }
-  }
-  else
-  {
-    t->user_data = NULL;
-  }
-  
-  if (*targets_head != NULL)
-  {
-    ptr = *targets_head;
-    while (ptr->next != NULL)
-      ptr = ptr->next;
-
-    ptr->next = t;
-  }
-  else
-  {
-    *targets_head = t;
-  }
-
-  return (0);
-} /* }}} int fc_config_add_target */
-
-static int fc_config_add_rule (fc_chain_t *chain, /* {{{ */
-    oconfig_item_t *ci)
-{
-  fc_rule_t *rule;
-  char rule_name[2*DATA_MAX_NAME_LEN] = "Unnamed rule";
-  int status = 0;
-  int i;
-
-  if (ci->values_num > 1)
-  {
-    WARNING ("Filter subsystem: `Rule' blocks have at most one argument.");
-    return (-1);
-  }
-  else if ((ci->values_num == 1)
-      && (ci->values[0].type != OCONFIG_TYPE_STRING))
-  {
-    WARNING ("Filter subsystem: `Rule' blocks expect one string argument "
-        "or no argument at all.");
-    return (-1);
-  }
-
-  rule = (fc_rule_t *) malloc (sizeof (*rule));
-  if (rule == NULL)
-  {
-    ERROR ("fc_config_add_rule: malloc failed.");
-    return (-1);
-  }
-  memset (rule, 0, sizeof (*rule));
-  rule->next = NULL;
-
-  if (ci->values_num == 1)
-  {
-    sstrncpy (rule->name, ci->values[0].value.string, sizeof (rule->name));
-    ssnprintf (rule_name, sizeof (rule_name), "Rule \"%s\"",
-        ci->values[0].value.string);
-  }
-
-  for (i = 0; i < ci->children_num; i++)
-  {
-    oconfig_item_t *option = ci->children + i;
-
-    if (strcasecmp ("Match", option->key) == 0)
-      status = fc_config_add_match (&rule->matches, option);
-    else if (strcasecmp ("Target", option->key) == 0)
-      status = fc_config_add_target (&rule->targets, option);
-    else
-    {
-      WARNING ("Filter subsystem: %s: Option `%s' not allowed "
-          "inside a <Rule> block.", rule_name, option->key);
-      status = -1;
-    }
-
-    if (status != 0)
-      break;
-  } /* for (ci->children) */
-
-  /* Additional sanity checking. */
-  while (status == 0)
-  {
-    if (rule->targets == NULL)
-    {
-      WARNING ("Filter subsystem: %s: No target has been specified.",
-          rule_name);
-      status = -1;
-      break;
-    }
-
-    break;
-  } /* while (status == 0) */
-
-  if (status != 0)
-  {
-    fc_free_rules (rule);
-    return (-1);
-  }
-
-  if (chain->rules != NULL)
-  {
-    fc_rule_t *ptr;
-
-    ptr = chain->rules;
-    while (ptr->next != NULL)
-      ptr = ptr->next;
-
-    ptr->next = rule;
-  }
-  else
-  {
-    chain->rules = rule;
-  }
-
-  return (0);
-} /* }}} int fc_config_add_rule */
-
-static int fc_config_add_chain (const oconfig_item_t *ci) /* {{{ */
-{
-  fc_chain_t *chain;
-  int status = 0;
-  int i;
-
-  if ((ci->values_num != 1)
-      || (ci->values[0].type != OCONFIG_TYPE_STRING))
-  {
-    WARNING ("Filter subsystem: <Chain> blocks require exactly one "
-        "string argument.");
-    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;
-
-  for (i = 0; i < ci->children_num; i++)
-  {
-    oconfig_item_t *option = ci->children + i;
-
-    if (strcasecmp ("Rule", option->key) == 0)
-      status = fc_config_add_rule (chain, option);
-    else if (strcasecmp ("Target", option->key) == 0)
-      status = fc_config_add_target (&chain->targets, option);
-    else
-    {
-      WARNING ("Filter subsystem: Chain %s: Option `%s' not allowed "
-          "inside a <Chain> block.", chain->name, option->key);
-      status = -1;
-    }
-
-    if (status != 0)
-      break;
-  } /* for (ci->children) */
-
-  if (status != 0)
-  {
-    fc_free_chains (chain);
-    return (-1);
-  }
-
-  if (chain_list_head != NULL)
-  {
-    fc_chain_t *ptr;
-
-    ptr = chain_list_head;
-    while (ptr->next != NULL)
-      ptr = ptr->next;
-
-    ptr->next = chain;
-  }
-  else
-  {
-    chain_list_head = chain;
-  }
-
-  return (0);
-} /* }}} int fc_config_add_chain */
-
-/*
- * Built-in target "jump"
- *
- * Prefix `bit' like `_b_uilt-_i_n _t_arget'
- */
-static int fc_bit_jump_create (const oconfig_item_t *ci, /* {{{ */
-    void **user_data)
-{
-  oconfig_item_t *ci_chain;
-
-  if (ci->children_num != 1)
-  {
-    ERROR ("Filter subsystem: The built-in target `jump' needs exactly "
-        "one `Chain' argument!");
-    return (-1);
-  }
-
-  ci_chain = ci->children;
-  if (strcasecmp ("Chain", ci_chain->key) != 0)
-  {
-    ERROR ("Filter subsystem: The built-in target `jump' does not "
-        "support the configuration option `%s'.",
-        ci_chain->key);
-    return (-1);
-  }
-
-  if ((ci_chain->values_num != 1)
-      || (ci_chain->values[0].type != OCONFIG_TYPE_STRING))
-  {
-    ERROR ("Filter subsystem: Built-in target `jump': The `Chain' option "
-        "needs exactly one string argument.");
-    return (-1);
-  }
-
-  *user_data = fc_strdup (ci_chain->values[0].value.string);
-  if (*user_data == NULL)
-  {
-    ERROR ("fc_bit_jump_create: fc_strdup failed.");
-    return (-1);
-  }
-
-  return (0);
-} /* }}} int fc_bit_jump_create */
-
-static int fc_bit_jump_destroy (void **user_data) /* {{{ */
-{
-  if (user_data != NULL)
-  {
-    free (*user_data);
-    *user_data = NULL;
-  }
-
-  return (0);
-} /* }}} int fc_bit_jump_destroy */
-
-static int fc_bit_jump_invoke (const data_set_t *ds, /* {{{ */
-    value_list_t *vl, notification_meta_t __attribute__((unused)) **meta,
-    void **user_data)
-{
-  char *chain_name;
-  fc_chain_t *chain;
-  int status;
-
-  chain_name = *user_data;
-
-  for (chain = chain_list_head; chain != NULL; chain = chain->next)
-    if (strcasecmp (chain_name, chain->name) == 0)
-      break;
-
-  if (chain == NULL)
-  {
-    ERROR ("Filter subsystem: Built-in target `jump': There is no chain "
-        "named `%s'.", chain_name);
-    return (-1);
-  }
-
-  status = fc_process_chain (ds, vl, chain);
-  if (status < 0)
-    return (status);
-  else if (status == FC_TARGET_STOP)
-    return (FC_TARGET_STOP);
-  else
-    return (FC_TARGET_CONTINUE);
-} /* }}} int fc_bit_jump_invoke */
-
-static int fc_bit_stop_invoke (const data_set_t __attribute__((unused)) *ds, /* {{{ */
-    value_list_t __attribute__((unused)) *vl,
-    notification_meta_t __attribute__((unused)) **meta,
-    void __attribute__((unused)) **user_data)
-{
-  return (FC_TARGET_STOP);
-} /* }}} int fc_bit_stop_invoke */
-
-static int fc_bit_return_invoke (const data_set_t __attribute__((unused)) *ds, /* {{{ */
-    value_list_t __attribute__((unused)) *vl,
-    notification_meta_t __attribute__((unused)) **meta,
-    void __attribute__((unused)) **user_data)
-{
-  return (FC_TARGET_RETURN);
-} /* }}} int fc_bit_return_invoke */
-
-static int fc_bit_write_create (const oconfig_item_t *ci, /* {{{ */
-    void **user_data)
-{
-  int i;
-
-  fc_writer_t *plugin_list = NULL;
-  size_t plugin_list_len = 0;
-
-  for (i = 0; i < ci->children_num; i++)
-  {
-    oconfig_item_t *child = ci->children + i;
-    fc_writer_t *temp;
-    int j;
-
-    if (strcasecmp ("Plugin", child->key) != 0)
-    {
-      ERROR ("Filter subsystem: The built-in target `write' does not "
-          "support the configuration option `%s'.",
-          child->key);
-      continue;
-    }
-
-    for (j = 0; j < child->values_num; j++)
-    {
-      char *plugin;
-
-      if (child->values[j].type != OCONFIG_TYPE_STRING)
-      {
-        ERROR ("Filter subsystem: Built-in target `write': "
-            "The `Plugin' option accepts only string arguments.");
-        continue;
-      }
-      plugin = child->values[j].value.string;
-
-      temp = (fc_writer_t *) realloc (plugin_list, (plugin_list_len + 2)
-          * (sizeof (*plugin_list)));
-      if (temp == NULL)
-      {
-        ERROR ("fc_bit_write_create: realloc failed.");
-        continue;
-      }
-      plugin_list = temp;
-
-      plugin_list[plugin_list_len].plugin = fc_strdup (plugin);
-      if (plugin_list[plugin_list_len].plugin == NULL)
-      {
-        ERROR ("fc_bit_write_create: fc_strdup failed.");
-        continue;
-      }
-      C_COMPLAIN_INIT (&plugin_list[plugin_list_len].complaint);
-      plugin_list_len++;
-      plugin_list[plugin_list_len].plugin = NULL;
-    } /* for (j = 0; j < child->values_num; j++) */
-  } /* for (i = 0; i < ci->children_num; i++) */
-
-  *user_data = plugin_list;
-
-  return (0);
-} /* }}} int fc_bit_write_create */
-
-static int fc_bit_write_destroy (void **user_data) /* {{{ */
-{
-  fc_writer_t *plugin_list;
-  size_t i;
-
-  if ((user_data == NULL) || (*user_data == NULL))
-    return (0);
-
-  plugin_list = *user_data;
-
-  for (i = 0; plugin_list[i].plugin != NULL; i++)
-    free (plugin_list[i].plugin);
-  free (plugin_list);
-
-  return (0);
-} /* }}} int fc_bit_write_destroy */
-
-static int fc_bit_write_invoke (const data_set_t *ds, /* {{{ */
-    value_list_t *vl, notification_meta_t __attribute__((unused)) **meta,
-    void **user_data)
-{
-  fc_writer_t *plugin_list;
-  int status;
-
-  plugin_list = NULL;
-  if (user_data != NULL)
-    plugin_list = *user_data;
-
-  if ((plugin_list == NULL) || (plugin_list[0].plugin == NULL))
-  {
-    static c_complain_t write_complaint = C_COMPLAIN_INIT_STATIC;
-
-    status = plugin_write (/* plugin = */ NULL, ds, vl);
-    if (status == ENOENT)
-    {
-      /* in most cases this is a permanent error, so use the complain
-       * mechanism rather than spamming the logs */
-      c_complain (LOG_INFO, &write_complaint,
-          "Filter subsystem: Built-in target `write': Dispatching value to "
-          "all write plugins failed with status %i (ENOENT). "
-          "Most likely this means you didn't load any write plugins.",
-          status);
-    }
-    else if (status != 0)
-    {
-      /* often, this is a permanent error (e.g. target system unavailable),
-       * so use the complain mechanism rather than spamming the logs */
-      c_complain (LOG_INFO, &write_complaint,
-          "Filter subsystem: Built-in target `write': Dispatching value to "
-          "all write plugins failed with status %i.", status);
-    }
-    else
-    {
-      assert (status == 0);
-      c_release (LOG_INFO, &write_complaint, "Filter subsystem: "
-          "Built-in target `write': Some write plugin is back to normal "
-          "operation. `write' succeeded.");
-    }
-  }
-  else
-  {
-    size_t i;
-
-    for (i = 0; plugin_list[i].plugin != NULL; i++)
-    {
-      status = plugin_write (plugin_list[i].plugin, ds, vl);
-      if (status != 0)
-      {
-        c_complain (LOG_INFO, &plugin_list[i].complaint,
-            "Filter subsystem: Built-in target `write': Dispatching value to "
-            "the `%s' plugin failed with status %i.",
-            plugin_list[i].plugin, status);
-      }
-      else
-      {
-        c_release (LOG_INFO, &plugin_list[i].complaint,
-            "Filter subsystem: Built-in target `write': Plugin `%s' is back "
-            "to normal operation. `write' succeeded.", plugin_list[i].plugin);
-      }
-    } /* for (i = 0; plugin_list[i] != NULL; i++) */
-  }
-
-  return (FC_TARGET_CONTINUE);
-} /* }}} int fc_bit_write_invoke */
-
-static int fc_init_once (void) /* {{{ */
-{
-  static int done = 0;
-  target_proc_t tproc;
-
-  if (done != 0)
-    return (0);
-
-  memset (&tproc, 0, sizeof (tproc));
-  tproc.create  = fc_bit_jump_create;
-  tproc.destroy = fc_bit_jump_destroy;
-  tproc.invoke  = fc_bit_jump_invoke;
-  fc_register_target ("jump", tproc);
-
-  memset (&tproc, 0, sizeof (tproc));
-  tproc.create  = NULL;
-  tproc.destroy = NULL;
-  tproc.invoke  = fc_bit_stop_invoke;
-  fc_register_target ("stop", tproc);
-
-  memset (&tproc, 0, sizeof (tproc));
-  tproc.create  = NULL;
-  tproc.destroy = NULL;
-  tproc.invoke  = fc_bit_return_invoke;
-  fc_register_target ("return", tproc);
-
-  memset (&tproc, 0, sizeof (tproc));
-  tproc.create  = fc_bit_write_create;
-  tproc.destroy = fc_bit_write_destroy;
-  tproc.invoke  = fc_bit_write_invoke;
-  fc_register_target ("write", tproc);
-
-  done++;
-  return (0);
-} /* }}} int fc_init_once */
-
-/*
- * Public functions
- */
-/* Add a match to list of available matches. */
-int fc_register_match (const char *name, match_proc_t proc) /* {{{ */
-{
-  fc_match_t *m;
-
-  DEBUG ("fc_register_match (%s);", name);
-
-  m = (fc_match_t *) malloc (sizeof (*m));
-  if (m == NULL)
-    return (-ENOMEM);
-  memset (m, 0, sizeof (*m));
-
-  sstrncpy (m->name, name, sizeof (m->name));
-  memcpy (&m->proc, &proc, sizeof (m->proc));
-  m->next = NULL;
-
-  if (match_list_head == NULL)
-  {
-    match_list_head = m;
-  }
-  else
-  {
-    fc_match_t *ptr;
-
-    ptr = match_list_head;
-    while (ptr->next != NULL)
-      ptr = ptr->next;
-
-    ptr->next = m;
-  }
-
-  return (0);
-} /* }}} int fc_register_match */
-
-/* Add a target to list of available targets. */
-int fc_register_target (const char *name, target_proc_t proc) /* {{{ */
-{
-  fc_target_t *t;
-
-  DEBUG ("fc_register_target (%s);", name);
-
-  t = (fc_target_t *) malloc (sizeof (*t));
-  if (t == NULL)
-    return (-ENOMEM);
-  memset (t, 0, sizeof (*t));
-
-  sstrncpy (t->name, name, sizeof (t->name));
-  memcpy (&t->proc, &proc, sizeof (t->proc));
-  t->next = NULL;
-
-  if (target_list_head == NULL)
-  {
-    target_list_head = t;
-  }
-  else
-  {
-    fc_target_t *ptr;
-
-    ptr = target_list_head;
-    while (ptr->next != NULL)
-      ptr = ptr->next;
-
-    ptr->next = t;
-  }
-
-  return (0);
-} /* }}} int fc_register_target */
-
-fc_chain_t *fc_chain_get_by_name (const char *chain_name) /* {{{ */
-{
-  fc_chain_t *chain;
-
-  if (chain_name == NULL)
-    return (NULL);
-
-  for (chain = chain_list_head; chain != NULL; chain = chain->next)
-    if (strcasecmp (chain_name, chain->name) == 0)
-      return (chain);
-
-  return (NULL);
-} /* }}} int fc_chain_get_by_name */
-
-int fc_process_chain (const data_set_t *ds, value_list_t *vl, /* {{{ */
-    fc_chain_t *chain)
-{
-  fc_rule_t *rule;
-  fc_target_t *target;
-  int status;
-
-  if (chain == NULL)
-    return (-1);
-
-  DEBUG ("fc_process_chain (chain = %s);", chain->name);
-
-  status = FC_TARGET_CONTINUE;
-  for (rule = chain->rules; rule != NULL; rule = rule->next)
-  {
-    fc_match_t *match;
-
-    if (rule->name[0] != 0)
-    {
-      DEBUG ("fc_process_chain (%s): Testing the `%s' rule.",
-          chain->name, rule->name);
-    }
-
-    /* N. B.: rule->matches may be NULL. */
-    for (match = rule->matches; match != NULL; match = match->next)
-    {
-      /* FIXME: Pass the meta-data to match targets here (when implemented). */
-      status = (*match->proc.match) (ds, vl, /* meta = */ NULL,
-          &match->user_data);
-      if (status < 0)
-      {
-        WARNING ("fc_process_chain (%s): A match failed.", chain->name);
-        break;
-      }
-      else if (status != FC_MATCH_MATCHES)
-        break;
-    }
-
-    /* for-loop has been aborted: Either error or no match. */
-    if (match != NULL)
-    {
-      status = FC_TARGET_CONTINUE;
-      continue;
-    }
-
-    if (rule->name[0] != 0)
-    {
-      DEBUG ("fc_process_chain (%s): Rule `%s' matches.",
-          chain->name, rule->name);
-    }
-
-    for (target = rule->targets; target != NULL; target = target->next)
-    {
-      /* If we get here, all matches have matched the value. Execute the
-       * target. */
-      /* FIXME: Pass the meta-data to match targets here (when implemented). */
-      status = (*target->proc.invoke) (ds, vl, /* meta = */ NULL,
-          &target->user_data);
-      if (status < 0)
-      {
-        WARNING ("fc_process_chain (%s): A target failed.", chain->name);
-        continue;
-      }
-      else if (status == FC_TARGET_CONTINUE)
-        continue;
-      else if (status == FC_TARGET_STOP)
-        break;
-      else if (status == FC_TARGET_RETURN)
-        break;
-      else
-      {
-        WARNING ("fc_process_chain (%s): Unknown return value "
-            "from target `%s': %i",
-            chain->name, target->name, status);
-      }
-    }
-
-    if ((status == FC_TARGET_STOP)
-        || (status == FC_TARGET_RETURN))
-    {
-      if (rule->name[0] != 0)
-      {
-        DEBUG ("fc_process_chain (%s): Rule `%s' signaled "
-            "the %s condition.",
-            chain->name, rule->name,
-            (status == FC_TARGET_STOP) ? "stop" : "return");
-      }
-      break;
-    }
-    else
-    {
-      status = FC_TARGET_CONTINUE;
-    }
-  } /* for (rule) */
-
-  if (status == FC_TARGET_STOP)
-    return (FC_TARGET_STOP);
-  else if (status == FC_TARGET_RETURN)
-    return (FC_TARGET_CONTINUE);
-
-  /* for-loop has been aborted: A target returned `FC_TARGET_STOP' */
-  if (rule != NULL)
-    return (FC_TARGET_CONTINUE);
-
-  DEBUG ("fc_process_chain (%s): Executing the default targets.",
-      chain->name);
-
-  status = FC_TARGET_CONTINUE;
-  for (target = chain->targets; target != NULL; target = target->next)
-  {
-    /* If we get here, all matches have matched the value. Execute the
-     * target. */
-    /* FIXME: Pass the meta-data to match targets here (when implemented). */
-    status = (*target->proc.invoke) (ds, vl, /* meta = */ NULL,
-        &target->user_data);
-    if (status < 0)
-    {
-      WARNING ("fc_process_chain (%s): The default target failed.",
-          chain->name);
-    }
-    else if (status == FC_TARGET_CONTINUE)
-      continue;
-    else if (status == FC_TARGET_STOP)
-      break;
-    else if (status == FC_TARGET_RETURN)
-      break;
-    else
-    {
-      WARNING ("fc_process_chain (%s): Unknown return value "
-          "from target `%s': %i",
-          chain->name, target->name, status);
-    }
-  }
-
-  if ((status == FC_TARGET_STOP)
-      || (status == FC_TARGET_RETURN))
-  {
-    assert (target != NULL);
-    DEBUG ("fc_process_chain (%s): Default target `%s' signaled "
-        "the %s condition.",
-        chain->name, target->name,
-        (status == FC_TARGET_STOP) ? "stop" : "return");
-    if (status == FC_TARGET_STOP)
-      return (FC_TARGET_STOP);
-    else
-      return (FC_TARGET_CONTINUE);
-  }
-
-  DEBUG ("fc_process_chain (%s): Signaling `continue' at end of chain.",
-      chain->name);
-
-  return (FC_TARGET_CONTINUE);
-} /* }}} int fc_process_chain */
-
-/* Iterate over all rules in the chain and execute all targets for which all
- * matches match. */
-int fc_default_action (const data_set_t *ds, value_list_t *vl) /* {{{ */
-{
-  /* FIXME: Pass the meta-data to match targets here (when implemented). */
-  return (fc_bit_write_invoke (ds, vl,
-        /* meta = */ NULL, /* user_data = */ NULL));
-} /* }}} int fc_default_action */
-
-int fc_configure (const oconfig_item_t *ci) /* {{{ */
-{
-  fc_init_once ();
-
-  if (ci == NULL)
-    return (-EINVAL);
-
-  if (strcasecmp ("Chain", ci->key) == 0)
-    return (fc_config_add_chain (ci));
-
-  WARNING ("Filter subsystem: Unknown top level config option `%s'.",
-      ci->key);
-
-  return (-1);
-} /* }}} int fc_configure */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/src/filter_chain.h b/src/filter_chain.h
deleted file mode 100644 (file)
index 187fe22..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * 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.
- *
- * 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
- *
- * Authors:
- *   Florian octo Forster <octo at verplant.org>
- **/
-
-#ifndef FILTER_CHAIN_H
-#define FILTER_CHAIN_H 1
-
-#include "collectd.h"
-#include "plugin.h"
-
-#define FC_MATCH_NO_MATCH  0
-#define FC_MATCH_MATCHES   1
-
-#define FC_TARGET_CONTINUE 0
-#define FC_TARGET_STOP     1
-#define FC_TARGET_RETURN   2
-
-/*
- * Match functions
- */
-struct match_proc_s
-{
-  int (*create) (const oconfig_item_t *ci, void **user_data);
-  int (*destroy) (void **user_data);
-  int (*match) (const data_set_t *ds, const value_list_t *vl,
-      notification_meta_t **meta, void **user_data);
-};
-typedef struct match_proc_s match_proc_t;
-
-int fc_register_match (const char *name, match_proc_t proc);
-
-/*
- * Target functions
- */
-struct target_proc_s
-{
-  int (*create) (const oconfig_item_t *ci, void **user_data);
-  int (*destroy) (void **user_data);
-  int (*invoke) (const data_set_t *ds, value_list_t *vl,
-      notification_meta_t **meta, void **user_data);
-};
-typedef struct target_proc_s target_proc_t;
-
-struct fc_chain_s;
-typedef struct fc_chain_s fc_chain_t;
-
-int fc_register_target (const char *name, target_proc_t proc);
-
-/*
- * TODO: Chain management
- */
-#if 0
-int fc_chain_add (const char *chain_name,
-    const char *target_name, int target_argc, char **target_argv);
-int fc_chain_delete (const char *chain_name);
-#endif
-
-/*
- * TODO: Rule management
- */
-#if 0
-int fc_rule_add (const char *chain_name, int position,
-    int match_num, const char **match_name, int *match_argc, char ***match_argv,
-    const char *target_name, int target_argc, char **target_argv);
-int fc_rule_delete (const char *chain_name, int position);
-#endif
-
-/*
- * Processing function
- */
-fc_chain_t *fc_chain_get_by_name (const char *chain_name);
-
-int fc_process_chain (const data_set_t *ds, value_list_t *vl,
-    fc_chain_t *chain);
-
-int fc_default_action (const data_set_t *ds, value_list_t *vl);
-
-/* 
- * Shortcut for global configuration
- */
-int fc_configure (const oconfig_item_t *ci);
-
-#endif /* FILTER_CHAIN_H */
-/* vim: set sw=2 sts=2 et : */
index a1fa9ea4967285824eecb4a6f5e696ca94fc0938..336fbb9468b8eeb6c1002fc79dea02136829390d 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 4428b75ddc086db0be4e8cff39f95f6437e09e89..82c158cab17180dc18a4d5e878d1704b60e081ce 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 c618af98c0016dacb5950aad50b017c3e0858c34..df8ffb46c34522ee5696b22a3409a687c37161e4 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
  **/
diff --git a/src/ipc.c b/src/ipc.c
new file mode 100644 (file)
index 0000000..3763f24
--- /dev/null
+++ b/src/ipc.c
@@ -0,0 +1,330 @@
+/**
+ * collectd - src/ipc.c, based on src/memcached.c
+ * Copyright (C) 2010       Andres J. Diaz <ajdiaz@connectical.com>
+ * Copyright (C) 2010       Manuel L. Sanmartin <manuel.luis@gmail.com>
+ *
+ * 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
+ *
+ * Authors:
+ *   Andres J. Diaz <ajdiaz@connectical.com>
+ *   Manuel L. Sanmartin <manuel.luis@gmail>
+ **/
+
+/* Many of this code is based on busybox ipc implementation, which is:
+ *   (C) Rodney Radford <rradford@mindspring.com> and distributed under GPLv2.
+ */
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+#include "configfile.h"
+
+#if KERNEL_LINUX
+  /* X/OPEN tells us to use <sys/{types,ipc,sem}.h> for semctl() */
+  /* X/OPEN tells us to use <sys/{types,ipc,msg}.h> for msgctl() */
+  /* X/OPEN tells us to use <sys/{types,ipc,shm}.h> for shmctl() */
+# include <sys/types.h>
+# include <sys/ipc.h>
+# include <sys/sem.h>
+# include <sys/msg.h>
+# include <sys/shm.h>
+
+  /* For older kernels the same holds for the defines below */
+# ifndef MSG_STAT
+#  define MSG_STAT    11
+#  define MSG_INFO    12
+# endif
+
+# ifndef SHM_STAT
+#   define SHM_STAT        13
+#   define SHM_INFO        14
+    struct shm_info {
+        int used_ids;
+        ulong shm_tot;      /* total allocated shm */
+        ulong shm_rss;      /* total resident shm */
+        ulong shm_swp;      /* total swapped shm */
+        ulong swap_attempts;
+        ulong swap_successes;
+    };
+# endif
+
+# ifndef SEM_STAT
+#  define SEM_STAT    18
+#  define SEM_INFO    19
+# endif
+
+  /* The last arg of semctl is a union semun, but where is it defined?
+     X/OPEN tells us to define it ourselves, but until recently
+     Linux include files would also define it. */
+# if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
+    /* union semun is defined by including <sys/sem.h> */
+# else
+    /* according to X/OPEN we have to define it ourselves */
+    union semun {
+      int val;
+      struct semid_ds *buf;
+      unsigned short *array;
+      struct seminfo *__buf;
+    };
+# endif
+static long pagesize_g;
+/* #endif  KERNEL_LINUX */
+#elif KERNEL_AIX
+# include <sys/ipc_info.h>
+/* #endif KERNEL_AIX */
+#else
+# error "No applicable input method."
+#endif
+
+__attribute__ ((nonnull(1)))
+static void ipc_submit_g (const char *plugin_instance,
+                          const char *type,
+                          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, "ipc", sizeof (vl.plugin));
+  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);
+} /* }}} */
+
+#if KERNEL_LINUX
+static int ipc_read_sem (void) /* {{{ */
+{
+  struct seminfo seminfo;
+  union semun arg;
+  int status;
+
+  arg.array = (void *) &seminfo;
+
+  status = semctl (/* id = */ 0, /* num = */ 0, SEM_INFO, arg);
+  if (status == -1)
+  {
+    char errbuf[1024];
+    ERROR("ipc plugin: semctl(2) failed: %s. "
+        "Maybe the kernel is not configured for semaphores?",
+        sstrerror (errno, errbuf, sizeof (errbuf)));
+    return (-1);
+  }
+
+  ipc_submit_g("sem", "count", "arrays", seminfo.semusz);
+  ipc_submit_g("sem", "count", "total", seminfo.semaem);
+
+  return (0);
+} /* }}} int ipc_read_sem */
+
+static int ipc_read_shm (void) /* {{{ */
+{
+  struct shm_info shm_info;
+  int status;
+
+  status = shmctl (/* id = */ 0, SHM_INFO, (void *) &shm_info);
+  if (status == -1)
+  {
+    char errbuf[1024];
+    ERROR("ipc plugin: shmctl(2) failed: %s. "
+        "Maybe the kernel is not configured for shared memory?",
+        sstrerror (errno, errbuf, sizeof (errbuf)));
+    return (-1);
+  }
+
+  ipc_submit_g("shm", "segments", NULL, shm_info.used_ids);
+  ipc_submit_g("shm", "bytes", "total", shm_info.shm_tot * pagesize_g);
+  ipc_submit_g("shm", "bytes", "rss", shm_info.shm_rss * pagesize_g);
+  ipc_submit_g("shm", "bytes", "swapped", shm_info.shm_swp * pagesize_g);
+  return (0);
+}
+/* }}} int ipc_read_shm */
+
+static int ipc_read_msg (void) /* {{{ */
+{
+  struct msginfo msginfo;
+
+  if ( msgctl(0, MSG_INFO, (struct msqid_ds *) (void *) &msginfo) < 0 )
+  {
+    ERROR("Kernel is not configured for message queues");
+    return (-1);
+  }
+  ipc_submit_g("msg", "count", "queues", msginfo.msgmni);
+  ipc_submit_g("msg", "count", "headers", msginfo.msgmap);
+  ipc_submit_g("msg", "count", "space", msginfo.msgtql);
+
+  return (0);
+}
+/* }}} int ipc_read_msg */
+
+static int ipc_init (void) /* {{{ */
+{
+  pagesize_g = sysconf(_SC_PAGESIZE);
+  return (0);
+}
+/* }}} */
+/* #endif KERNEL_LINUX */
+
+#elif KERNEL_AIX
+static caddr_t ipc_get_info (cid_t cid, int cmd, int version, int stsize, int *nmemb) /* {{{ */
+{
+  int size = 0;
+  caddr_t buff = NULL;
+
+  if (get_ipc_info(cid, cmd, version, buff, &size) < 0)
+  {
+    if (errno != ENOSPC) {
+      char errbuf[1024];
+      WARNING ("ipc plugin: get_ipc_info: %s",
+        sstrerror (errno, errbuf, sizeof (errbuf)));
+      return (NULL);
+    }
+  }
+
+  if (size == 0)
+    return NULL;
+
+  if (size % stsize) {
+    ERROR ("ipc plugin: ipc_get_info: missmatch struct size and buffer size");
+    return (NULL);
+  }
+
+  *nmemb = size / stsize;
+
+  buff = (caddr_t)malloc (size);
+  if (buff == NULL)  {
+    ERROR ("ipc plugin: ipc_get_info malloc failed.");
+    return (NULL);
+  }
+
+  if (get_ipc_info(cid, cmd, version, buff, &size) < 0)
+  {
+    char errbuf[1024];
+    WARNING ("ipc plugin: get_ipc_info: %s",
+      sstrerror (errno, errbuf, sizeof (errbuf)));
+    free(buff);
+    return (NULL);
+  }
+
+  return buff;
+} /* }}} */
+
+static int ipc_read_sem (void) /* {{{ */
+{
+  ipcinfo_sem_t *ipcinfo_sem;
+  unsigned short sem_nsems=0;
+  unsigned short sems=0;
+  int i,n;
+
+  ipcinfo_sem = (ipcinfo_sem_t *)ipc_get_info(0,
+    GET_IPCINFO_SEM_ALL, IPCINFO_SEM_VERSION, sizeof(ipcinfo_sem_t), &n);
+  if (ipcinfo_sem == NULL)
+    return -1;
+
+  for (i=0; i<n; i++) {
+    sem_nsems += ipcinfo_sem[i].sem_nsems;
+    sems++;
+  }
+  free(ipcinfo_sem);
+
+  ipc_submit_g("sem", "count", "arrays", sem_nsems);
+  ipc_submit_g("sem", "count", "total", sems);
+
+  return (0);
+} /* }}} int ipc_read_sem */
+
+static int ipc_read_shm (void) /* {{{ */
+{
+  ipcinfo_shm_t *ipcinfo_shm;
+  ipcinfo_shm_t *pshm;
+  unsigned int shm_segments=0;
+  size64_t shm_bytes=0;
+  int i,n;
+
+  ipcinfo_shm = (ipcinfo_shm_t *)ipc_get_info(0,
+    GET_IPCINFO_SHM_ALL, IPCINFO_SHM_VERSION, sizeof(ipcinfo_shm_t), &n);
+  if (ipcinfo_shm == NULL)
+    return -1;
+
+  for (i=0, pshm=ipcinfo_shm; i<n; i++, pshm++) {
+    shm_segments++;
+    shm_bytes += pshm->shm_segsz;
+  }
+  free(ipcinfo_shm);
+
+  ipc_submit_g("shm", "segments", NULL, shm_segments);
+  ipc_submit_g("shm", "bytes", "total", shm_bytes);
+
+  return (0);
+}
+/* }}} int ipc_read_shm */
+
+static int ipc_read_msg (void) /* {{{ */
+{
+  ipcinfo_msg_t *ipcinfo_msg;
+  uint32_t msg_used_space=0;
+  uint32_t msg_alloc_queues=0;
+  msgqnum32_t msg_qnum=0;
+  int i,n;
+
+  ipcinfo_msg = (ipcinfo_msg_t *)ipc_get_info(0,
+    GET_IPCINFO_MSG_ALL, IPCINFO_MSG_VERSION, sizeof(ipcinfo_msg_t), &n);
+  if (ipcinfo_msg == NULL)
+    return -1;
+
+  for (i=0; i<n; i++) {
+    msg_alloc_queues++;
+    msg_used_space += ipcinfo_msg[i].msg_cbytes;
+    msg_qnum += ipcinfo_msg[i].msg_qnum;
+
+  free(ipcinfo_msg);
+
+  ipc_submit_g("msg", "count", "queues", msg_alloc_queues);
+  ipc_submit_g("msg", "count", "headers", msg_qnum);
+  ipc_submit_g("msg", "count", "space", msg_used_space);
+
+  return (0);
+}
+/* }}} */
+#endif /* KERNEL_AIX */
+
+static int ipc_read (void) /* {{{ */
+{
+  int x = 0;
+  x |= ipc_read_shm();
+  x |= ipc_read_sem();
+  x |= ipc_read_msg();
+
+  return (x);
+}
+/* }}} */
+
+void module_register (void) /* {{{ */
+{
+#ifdef KERNEL_LINUX
+  plugin_register_init ("ipc", ipc_init);
+#endif
+  plugin_register_read ("ipc", ipc_read);
+}
+/* }}} */
+
+/* vim: set sw=2 sts=2 et fdm=marker : */
index f23601eaede6cc98bb139f80c21e3f112cfbe484..51d33dcb79635733d395fec6338c3ec4a7fe0036 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 ee14373ed9f75485a91b9dc3b93283f8e4eafcd9..c74fe6c79de8fee4a3e80cd3a6fd7f15ea7dcb62 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]);
@@ -2442,7 +2469,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 1d4dff59fccc29e180aa67544285ee0a8b2330b4..5abee2f1a44f1fd0abdce185c1cb390ffd00aeab 100644 (file)
@@ -11,7 +11,10 @@ nodist_pkgconfig_DATA = libcollectdclient.pc
 BUILT_SOURCES = collectd/lcc_features.h
 
 libcollectdclient_la_SOURCES = client.c network.c network_buffer.c
-libcollectdclient_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_builddir)/src/libcollectdclient/collectd -I$(top_srcdir)/src
+libcollectdclient_la_CPPFLAGS = $(AM_CPPFLAGS) \
+                               -I$(top_srcdir)/src/libcollectdclient/collectd \
+                               -I$(top_builddir)/src/libcollectdclient/collectd \
+                               -I$(top_srcdir)/src/daemon
 libcollectdclient_la_LDFLAGS = -version-info 1:0:0
 libcollectdclient_la_LIBADD = 
 if BUILD_WITH_LIBGCRYPT
index 5db98e58b6fdf60af9c6a37299fbda85c68b05d3..a97dc509e4d7ff7e94b491f28244ad9e9e1d10cc 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 39626667526c76b08eb0c26b379d88ff02838028..049f7f0283fc16bf6f3baacba8c7cbb55c2b662c 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 6b6450c9b785171547c3fef30a50e28acd02340f..c390a1ce7cada8de9b029cb5d088de05ad0c8c3e 100644 (file)
@@ -1,6 +1,7 @@
 /**
  * collectd - src/libcollectdclient/network.c
- * Copyright (C) 2005-2012  Florian octo Forster
+ * Copyright (C) 2005-2015  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"
 
@@ -213,7 +219,13 @@ static int server_send_buffer (lcc_server_t *srv) /* {{{ */
   memset (buffer, 0, sizeof (buffer));
   buffer_size = sizeof (buffer);
 
-  lcc_network_buffer_finalize (srv->buffer);
+  status = lcc_network_buffer_finalize (srv->buffer);
+  if (status != 0)
+  {
+    lcc_network_buffer_initialize (srv->buffer);
+    return (status);
+  }
+
   status = lcc_network_buffer_get (srv->buffer, buffer, &buffer_size);
   lcc_network_buffer_initialize (srv->buffer);
 
@@ -379,6 +391,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 61c7c22e2d7ab963a2d98977f8c0c3747ad18723..343c285ad9ec35e95fcdcce23420d84b05a959de 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * collectd - src/libcollectdclient/network_buffer.c
- * Copyright (C) 2010-2012  Florian octo Forster
+ * Copyright (C) 2010-2015  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"),
@@ -792,9 +792,9 @@ int lcc_network_buffer_finalize (lcc_network_buffer_t *nb) /* {{{ */
 
 #if HAVE_LIBGCRYPT
   if (nb->seclevel == SIGN)
-    nb_add_signature (nb);
+    return nb_add_signature (nb);
   else if (nb->seclevel == ENCRYPT)
-    nb_add_encryption (nb);
+    return nb_add_encryption (nb);
 #endif
 
   return (0);
index 56ccefbf4e26e0e51f77c74f77e376f395db8ef8..f422f5adcb905e1d2bb5abed011ba10424c779a6 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 70fc6230fc5753916c8c03d211c78695fda3b0f7..840137cc25a7f4a59f5bceee43856d257e7c7795 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 764212f7ee611f5ea8273628f0414c31fef41bfa..f0e886cc1a1e28ab5f1c277eb830c54896410d59 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 e38cf3039f8d80c336baabc9afe1a45f755f36bb..638e3a232b3c688970194231b938c911a58b4186 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>
  */
 
 %{
@@ -58,9 +67,20 @@ BOOL_TRUE (true|yes|on)
 BOOL_FALSE (false|no|off)
 COMMENT #.*
 PORT (6(5(5(3[0-5]|[0-2][0-9])|[0-4][0-9][0-9])|[0-4][0-9][0-9][0-9])|[1-5][0-9][0-9][0-9][0-9]|[1-9][0-9]?[0-9]?[0-9]?)
+
 IP_BYTE (2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])
 IPV4_ADDR {IP_BYTE}\.{IP_BYTE}\.{IP_BYTE}\.{IP_BYTE}(:{PORT})?
 
+/* IPv6 address according to http://www.ietf.org/rfc/rfc2373.txt
+ * This supports embedded IPv4 addresses as well but does not strictly check
+ * for the right prefix (::0:<v4> or ::FFFF:<v4>) because there are too many
+ * ways to correctly represent the zero bytes. It's up to the user to check
+ * for valid addresses. */
+HEX16 ([0-9A-Fa-f]{1,4})
+V6_PART ({HEX16}:{HEX16}|{IPV4_ADDR})
+IPV6_BASE ({HEX16}:){6}{V6_PART}|::({HEX16}:){5}{V6_PART}|({HEX16})?::({HEX16}:){4}{V6_PART}|(({HEX16}:){0,1}{HEX16})?::({HEX16}:){3}{V6_PART}|(({HEX16}:){0,2}{HEX16})?::({HEX16}:){2}{V6_PART}|(({HEX16}:){0,3}{HEX16})?::{HEX16}:{V6_PART}|(({HEX16}:){0,4}{HEX16})?::{V6_PART}|(({HEX16}:){0,5}{HEX16})?::{HEX16}|(({HEX16}:){0,6}{HEX16})?::
+IPV6_ADDR ({IPV6_BASE})|(\[{IPV6_BASE}\](:{PORT})?)
+
 %%
 {WHITE_SPACE}          |
 {COMMENT}              {/* ignore */}
@@ -75,6 +95,7 @@ IPV4_ADDR {IP_BYTE}\.{IP_BYTE}\.{IP_BYTE}\.{IP_BYTE}(:{PORT})?
 {BOOL_FALSE}           {yylval.boolean = 0; return (BFALSE);}
 
 {IPV4_ADDR}            {yylval.string = yytext; return (UNQUOTED_STRING);}
+{IPV6_ADDR}            {yylval.string = yytext; return (UNQUOTED_STRING);}
 
 {NUMBER}               {yylval.number = strtod (yytext, NULL); return (NUMBER);}
 
diff --git a/src/libvirt.c b/src/libvirt.c
deleted file mode 100644 (file)
index 6a397db..0000000
+++ /dev/null
@@ -1,888 +0,0 @@
-/**
- * collectd - src/libvirt.c
- * Copyright (C) 2006-2008  Red Hat 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
- *
- * Authors:
- *   Richard W.M. Jones <rjones@redhat.com>
- **/
-
-#include "collectd.h"
-#include "common.h"
-#include "plugin.h"
-#include "configfile.h"
-#include "utils_ignorelist.h"
-#include "utils_complain.h"
-
-#include <libvirt/libvirt.h>
-#include <libvirt/virterror.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include <libxml/xpath.h>
-
-static const char *config_keys[] = {
-    "Connection",
-
-    "RefreshInterval",
-
-    "Domain",
-    "BlockDevice",
-    "InterfaceDevice",
-    "IgnoreSelected",
-
-    "HostnameFormat",
-    "InterfaceFormat",
-
-    NULL
-};
-#define NR_CONFIG_KEYS ((sizeof config_keys / sizeof config_keys[0]) - 1)
-
-/* Connection. */
-static virConnectPtr conn = 0;
-static char *conn_string = NULL;
-static c_complain_t conn_complain = C_COMPLAIN_INIT_STATIC;
-
-/* Seconds between list refreshes, 0 disables completely. */
-static int interval = 60;
-
-/* List of domains, if specified. */
-static ignorelist_t *il_domains = NULL;
-/* List of block devices, if specified. */
-static ignorelist_t *il_block_devices = NULL;
-/* List of network interface devices, if specified. */
-static ignorelist_t *il_interface_devices = NULL;
-
-static int ignore_device_match (ignorelist_t *,
-                                const char *domname, const char *devpath);
-
-/* Actual list of domains found on last refresh. */
-static virDomainPtr *domains = NULL;
-static int nr_domains = 0;
-
-static void free_domains (void);
-static int add_domain (virDomainPtr dom);
-
-/* Actual list of block devices found on last refresh. */
-struct block_device {
-    virDomainPtr dom;           /* domain */
-    char *path;                 /* name of block device */
-};
-
-static struct block_device *block_devices = NULL;
-static int nr_block_devices = 0;
-
-static void free_block_devices (void);
-static int add_block_device (virDomainPtr dom, const char *path);
-
-/* Actual list of network interfaces found on last refresh. */
-struct interface_device {
-    virDomainPtr dom;           /* domain */
-    char *path;                 /* name of interface device */
-    char *address;              /* mac address of interface device */
-    char *number;               /* interface device number */
-};
-
-static struct interface_device *interface_devices = NULL;
-static int nr_interface_devices = 0;
-
-static void free_interface_devices (void);
-static int add_interface_device (virDomainPtr dom, const char *path, const char *address, unsigned int number);
-
-/* HostnameFormat. */
-#define HF_MAX_FIELDS 3
-
-enum hf_field {
-    hf_none = 0,
-    hf_hostname,
-    hf_name,
-    hf_uuid
-};
-
-static enum hf_field hostname_format[HF_MAX_FIELDS] =
-    { hf_name };
-
-/* InterfaceFormat. */
-enum if_field {
-    if_address,
-    if_name,
-    if_number
-};
-
-static enum if_field interface_format = if_name;
-
-/* Time that we last refreshed. */
-static time_t last_refresh = (time_t) 0;
-
-static int refresh_lists (void);
-
-/* ERROR(...) macro for virterrors. */
-#define VIRT_ERROR(conn,s) do {                 \
-        virErrorPtr err;                        \
-        err = (conn) ? virConnGetLastError ((conn)) : virGetLastError (); \
-        if (err) ERROR ("%s: %s", (s), err->message);                   \
-    } while(0)
-
-static void
-init_value_list (value_list_t *vl, virDomainPtr dom)
-{
-    int i, n;
-    const char *name;
-    char uuid[VIR_UUID_STRING_BUFLEN];
-
-    sstrncpy (vl->plugin, "libvirt", sizeof (vl->plugin));
-
-    vl->host[0] = '\0';
-
-    /* Construct the hostname field according to HostnameFormat. */
-    for (i = 0; i < HF_MAX_FIELDS; ++i) {
-        if (hostname_format[i] == hf_none)
-            continue;
-
-        n = DATA_MAX_NAME_LEN - strlen (vl->host) - 2;
-
-        if (i > 0 && n >= 1) {
-            strncat (vl->host, ":", 1);
-            n--;
-        }
-
-        switch (hostname_format[i]) {
-        case hf_none: break;
-        case hf_hostname:
-            strncat (vl->host, hostname_g, n);
-            break;
-        case hf_name:
-            name = virDomainGetName (dom);
-            if (name)
-                strncat (vl->host, name, n);
-            break;
-        case hf_uuid:
-            if (virDomainGetUUIDString (dom, uuid) == 0)
-                strncat (vl->host, uuid, n);
-            break;
-        }
-    }
-
-    vl->host[sizeof (vl->host) - 1] = '\0';
-} /* void init_value_list */
-
-static void
-memory_submit (gauge_t memory, virDomainPtr dom)
-{
-    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, "total", sizeof (vl.type_instance));
-
-    plugin_dispatch_values (&vl);
-}
-
-static void
-cpu_submit (unsigned long long cpu_time,
-            virDomainPtr dom, const char *type)
-{
-    value_t values[1];
-    value_list_t vl = VALUE_LIST_INIT;
-
-    init_value_list (&vl, dom);
-
-    values[0].derive = cpu_time;
-
-    vl.values = values;
-    vl.values_len = 1;
-
-    sstrncpy (vl.type, type, sizeof (vl.type));
-
-    plugin_dispatch_values (&vl);
-}
-
-static void
-vcpu_submit (derive_t cpu_time,
-             virDomainPtr dom, int vcpu_nr, const char *type)
-{
-    value_t values[1];
-    value_list_t vl = VALUE_LIST_INIT;
-
-    init_value_list (&vl, dom);
-
-    values[0].derive = cpu_time;
-    vl.values = values;
-    vl.values_len = 1;
-
-    sstrncpy (vl.type, type, sizeof (vl.type));
-    ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%d", vcpu_nr);
-
-    plugin_dispatch_values (&vl);
-}
-
-static void
-submit_derive2 (const char *type, derive_t v0, derive_t v1,
-             virDomainPtr dom, const char *devname)
-{
-    value_t values[2];
-    value_list_t vl = VALUE_LIST_INIT;
-
-    init_value_list (&vl, dom);
-
-    values[0].derive = v0;
-    values[1].derive = v1;
-    vl.values = values;
-    vl.values_len = 2;
-
-    sstrncpy (vl.type, type, sizeof (vl.type));
-    sstrncpy (vl.type_instance, devname, sizeof (vl.type_instance));
-
-    plugin_dispatch_values (&vl);
-} /* void submit_derive2 */
-
-static int
-lv_init (void)
-{
-    if (virInitialize () != 0)
-        return -1;
-
-       return 0;
-}
-
-static int
-lv_config (const char *key, const char *value)
-{
-    if (virInitialize () != 0)
-        return 1;
-
-    if (il_domains == NULL)
-        il_domains = ignorelist_create (1);
-    if (il_block_devices == NULL)
-        il_block_devices = ignorelist_create (1);
-    if (il_interface_devices == NULL)
-        il_interface_devices = ignorelist_create (1);
-
-    if (strcasecmp (key, "Connection") == 0) {
-        char *tmp = strdup (value);
-        if (tmp == NULL) {
-            ERROR ("libvirt plugin: Connection strdup failed.");
-            return 1;
-        }
-        sfree (conn_string);
-        conn_string = tmp;
-        return 0;
-    }
-
-    if (strcasecmp (key, "RefreshInterval") == 0) {
-        char *eptr = NULL;
-        interval = strtol (value, &eptr, 10);
-        if (eptr == NULL || *eptr != '\0') return 1;
-        return 0;
-    }
-
-    if (strcasecmp (key, "Domain") == 0) {
-        if (ignorelist_add (il_domains, value)) return 1;
-        return 0;
-    }
-    if (strcasecmp (key, "BlockDevice") == 0) {
-        if (ignorelist_add (il_block_devices, value)) return 1;
-        return 0;
-    }
-    if (strcasecmp (key, "InterfaceDevice") == 0) {
-        if (ignorelist_add (il_interface_devices, value)) return 1;
-        return 0;
-    }
-
-    if (strcasecmp (key, "IgnoreSelected") == 0) {
-        if (IS_TRUE (value))
-        {
-            ignorelist_set_invert (il_domains, 0);
-            ignorelist_set_invert (il_block_devices, 0);
-            ignorelist_set_invert (il_interface_devices, 0);
-        }
-        else
-        {
-            ignorelist_set_invert (il_domains, 1);
-            ignorelist_set_invert (il_block_devices, 1);
-            ignorelist_set_invert (il_interface_devices, 1);
-        }
-        return 0;
-    }
-
-    if (strcasecmp (key, "HostnameFormat") == 0) {
-        char *value_copy;
-        char *fields[HF_MAX_FIELDS];
-        int i, n;
-
-        value_copy = strdup (value);
-        if (value_copy == NULL) {
-            ERROR ("libvirt plugin: strdup failed.");
-            return -1;
-        }
-
-        n = strsplit (value_copy, fields, HF_MAX_FIELDS);
-        if (n < 1) {
-            sfree (value_copy);
-            ERROR ("HostnameFormat: no fields");
-            return -1;
-        }
-
-        for (i = 0; i < n; ++i) {
-            if (strcasecmp (fields[i], "hostname") == 0)
-                hostname_format[i] = hf_hostname;
-            else if (strcasecmp (fields[i], "name") == 0)
-                hostname_format[i] = hf_name;
-            else if (strcasecmp (fields[i], "uuid") == 0)
-                hostname_format[i] = hf_uuid;
-            else {
-                sfree (value_copy);
-                ERROR ("unknown HostnameFormat field: %s", fields[i]);
-                return -1;
-            }
-        }
-        sfree (value_copy);
-
-        for (i = n; i < HF_MAX_FIELDS; ++i)
-            hostname_format[i] = hf_none;
-
-        return 0;
-    }
-
-    if (strcasecmp (key, "InterfaceFormat") == 0) {
-        if (strcasecmp (value, "name") == 0)
-            interface_format = if_name;
-        else if (strcasecmp (value, "address") == 0)
-            interface_format = if_address;
-        else if (strcasecmp (value, "number") == 0)
-            interface_format = if_number;
-        else {
-            ERROR ("unknown InterfaceFormat: %s", value);
-            return -1;
-        }
-        return 0;
-    }
-
-    /* Unrecognised option. */
-    return -1;
-}
-
-static int
-lv_read (void)
-{
-    time_t t;
-    int i;
-
-    if (conn == NULL) {
-        /* `conn_string == NULL' is acceptable. */
-        conn = virConnectOpenReadOnly (conn_string);
-        if (conn == NULL) {
-            c_complain (LOG_ERR, &conn_complain,
-                    "libvirt plugin: Unable to connect: "
-                    "virConnectOpenReadOnly failed.");
-            return -1;
-        }
-    }
-    c_release (LOG_NOTICE, &conn_complain,
-            "libvirt plugin: Connection established.");
-
-    time (&t);
-
-    /* Need to refresh domain or device lists? */
-    if ((last_refresh == (time_t) 0) ||
-            ((interval > 0) && ((last_refresh + interval) <= t))) {
-        if (refresh_lists () != 0) {
-            if (conn != NULL)
-                virConnectClose (conn);
-            conn = NULL;
-            return -1;
-        }
-        last_refresh = t;
-    }
-
-#if 0
-    for (i = 0; i < nr_domains; ++i)
-        fprintf (stderr, "domain %s\n", virDomainGetName (domains[i]));
-    for (i = 0; i < nr_block_devices; ++i)
-        fprintf  (stderr, "block device %d %s:%s\n",
-                  i, virDomainGetName (block_devices[i].dom),
-                  block_devices[i].path);
-    for (i = 0; i < nr_interface_devices; ++i)
-        fprintf (stderr, "interface device %d %s:%s\n",
-                 i, virDomainGetName (interface_devices[i].dom),
-                 interface_devices[i].path);
-#endif
-
-    /* Get CPU usage, memory, VCPU usage for each domain. */
-    for (i = 0; i < nr_domains; ++i) {
-        virDomainInfo info;
-        virVcpuInfoPtr vinfo = NULL;
-        int status;
-        int j;
-
-        status = virDomainGetInfo (domains[i], &info);
-        if (status != 0)
-        {
-            ERROR ("libvirt plugin: virDomainGetInfo failed with status %i.",
-                    status);
-            continue;
-        }
-
-        if (info.state != VIR_DOMAIN_RUNNING)
-        {
-            /* only gather stats for running domains */
-            continue;
-        }
-
-        cpu_submit (info.cpuTime, domains[i], "virt_cpu_total");
-        memory_submit ((gauge_t) info.memory * 1024, domains[i]);
-
-        vinfo = malloc (info.nrVirtCpu * sizeof (vinfo[0]));
-        if (vinfo == NULL) {
-            ERROR ("libvirt plugin: malloc failed.");
-            continue;
-        }
-
-        status = virDomainGetVcpus (domains[i], vinfo, info.nrVirtCpu,
-                /* cpu map = */ NULL, /* cpu map length = */ 0);
-        if (status < 0)
-        {
-            ERROR ("libvirt plugin: virDomainGetVcpus failed with status %i.",
-                    status);
-            free (vinfo);
-            continue;
-        }
-
-        for (j = 0; j < info.nrVirtCpu; ++j)
-            vcpu_submit (vinfo[j].cpuTime,
-                    domains[i], vinfo[j].number, "virt_vcpu");
-
-        sfree (vinfo);
-    }
-
-    /* Get block device stats for each domain. */
-    for (i = 0; i < nr_block_devices; ++i) {
-        struct _virDomainBlockStats stats;
-
-        if (virDomainBlockStats (block_devices[i].dom, block_devices[i].path,
-                    &stats, sizeof stats) != 0)
-            continue;
-
-        if ((stats.rd_req != -1) && (stats.wr_req != -1))
-            submit_derive2 ("disk_ops",
-                    (derive_t) stats.rd_req, (derive_t) stats.wr_req,
-                    block_devices[i].dom, block_devices[i].path);
-
-        if ((stats.rd_bytes != -1) && (stats.wr_bytes != -1))
-            submit_derive2 ("disk_octets",
-                    (derive_t) stats.rd_bytes, (derive_t) stats.wr_bytes,
-                    block_devices[i].dom, block_devices[i].path);
-    } /* for (nr_block_devices) */
-
-    /* Get interface stats for each domain. */
-    for (i = 0; i < nr_interface_devices; ++i) {
-        struct _virDomainInterfaceStats stats;
-        char *display_name = NULL;
-
-
-        switch (interface_format) {
-            case if_address:
-                display_name = interface_devices[i].address;
-                break;
-            case if_number:
-                display_name = interface_devices[i].number;
-                break;
-            case if_name:
-            default:
-                display_name = interface_devices[i].path;
-        }
-
-        if (virDomainInterfaceStats (interface_devices[i].dom,
-                    interface_devices[i].path,
-                    &stats, sizeof stats) != 0)
-            continue;
-
-       if ((stats.rx_bytes != -1) && (stats.tx_bytes != -1))
-           submit_derive2 ("if_octets",
-                   (derive_t) stats.rx_bytes, (derive_t) stats.tx_bytes,
-                   interface_devices[i].dom, display_name);
-
-       if ((stats.rx_packets != -1) && (stats.tx_packets != -1))
-           submit_derive2 ("if_packets",
-                   (derive_t) stats.rx_packets, (derive_t) stats.tx_packets,
-                   interface_devices[i].dom, display_name);
-
-       if ((stats.rx_errs != -1) && (stats.tx_errs != -1))
-           submit_derive2 ("if_errors",
-                   (derive_t) stats.rx_errs, (derive_t) stats.tx_errs,
-                   interface_devices[i].dom, display_name);
-
-       if ((stats.rx_drop != -1) && (stats.tx_drop != -1))
-           submit_derive2 ("if_dropped",
-                   (derive_t) stats.rx_drop, (derive_t) stats.tx_drop,
-                   interface_devices[i].dom, display_name);
-    } /* for (nr_interface_devices) */
-
-    return 0;
-}
-
-static int
-refresh_lists (void)
-{
-    int n;
-
-    n = virConnectNumOfDomains (conn);
-    if (n < 0) {
-        VIRT_ERROR (conn, "reading number of domains");
-        return -1;
-    }
-
-    if (n > 0) {
-        int i;
-        int *domids;
-
-        /* Get list of domains. */
-        domids = malloc (sizeof (int) * n);
-        if (domids == 0) {
-            ERROR ("libvirt plugin: malloc failed.");
-            return -1;
-        }
-
-        n = virConnectListDomains (conn, domids, n);
-        if (n < 0) {
-            VIRT_ERROR (conn, "reading list of domains");
-            sfree (domids);
-            return -1;
-        }
-
-        free_block_devices ();
-        free_interface_devices ();
-        free_domains ();
-
-        /* Fetch each domain and add it to the list, unless ignore. */
-        for (i = 0; i < n; ++i) {
-            virDomainPtr dom = NULL;
-            const char *name;
-            char *xml = NULL;
-            xmlDocPtr xml_doc = NULL;
-            xmlXPathContextPtr xpath_ctx = NULL;
-            xmlXPathObjectPtr xpath_obj = NULL;
-            int j;
-
-            dom = virDomainLookupByID (conn, domids[i]);
-            if (dom == NULL) {
-                VIRT_ERROR (conn, "virDomainLookupByID");
-                /* Could be that the domain went away -- ignore it anyway. */
-                continue;
-            }
-
-            name = virDomainGetName (dom);
-            if (name == NULL) {
-                VIRT_ERROR (conn, "virDomainGetName");
-                goto cont;
-            }
-
-            if (il_domains && ignorelist_match (il_domains, name) != 0)
-                goto cont;
-
-            if (add_domain (dom) < 0) {
-                ERROR ("libvirt plugin: malloc failed.");
-                goto cont;
-            }
-
-            /* Get a list of devices for this domain. */
-            xml = virDomainGetXMLDesc (dom, 0);
-            if (!xml) {
-                VIRT_ERROR (conn, "virDomainGetXMLDesc");
-                goto cont;
-            }
-
-            /* Yuck, XML.  Parse out the devices. */
-            xml_doc = xmlReadDoc ((xmlChar *) xml, NULL, NULL, XML_PARSE_NONET);
-            if (xml_doc == NULL) {
-                VIRT_ERROR (conn, "xmlReadDoc");
-                goto cont;
-            }
-
-            xpath_ctx = xmlXPathNewContext (xml_doc);
-
-            /* Block devices. */
-            xpath_obj = xmlXPathEval
-                ((xmlChar *) "/domain/devices/disk/target[@dev]",
-                 xpath_ctx);
-            if (xpath_obj == NULL || xpath_obj->type != XPATH_NODESET ||
-                xpath_obj->nodesetval == NULL)
-                goto cont;
-
-            for (j = 0; j < xpath_obj->nodesetval->nodeNr; ++j) {
-                xmlNodePtr node;
-                char *path = NULL;
-
-                node = xpath_obj->nodesetval->nodeTab[j];
-                if (!node) continue;
-                path = (char *) xmlGetProp (node, (xmlChar *) "dev");
-                if (!path) continue;
-
-                if (il_block_devices &&
-                    ignore_device_match (il_block_devices, name, path) != 0)
-                    goto cont2;
-
-                add_block_device (dom, path);
-            cont2:
-                if (path) xmlFree (path);
-            }
-            xmlXPathFreeObject (xpath_obj);
-
-            /* Network interfaces. */
-            xpath_obj = xmlXPathEval
-                ((xmlChar *) "/domain/devices/interface[target[@dev]]",
-                 xpath_ctx);
-            if (xpath_obj == NULL || xpath_obj->type != XPATH_NODESET ||
-                xpath_obj->nodesetval == NULL)
-                goto cont;
-
-            xmlNodeSetPtr xml_interfaces = xpath_obj->nodesetval;
-
-            for (j = 0; j < xml_interfaces->nodeNr; ++j) {
-                char *path = NULL;
-                char *address = NULL;
-                xmlNodePtr xml_interface;
-
-                xml_interface = xml_interfaces->nodeTab[j];
-                if (!xml_interface) continue;
-                xmlNodePtr child = NULL;
-
-                for (child = xml_interface->children; child; child = child->next) {
-                    if (child->type != XML_ELEMENT_NODE) continue;
-
-                    if (xmlStrEqual(child->name, (const xmlChar *) "target")) {
-                        path = (char *) xmlGetProp (child, (const xmlChar *) "dev");
-                        if (!path) continue;
-                    } else if (xmlStrEqual(child->name, (const xmlChar *) "mac")) {
-                        address = (char *) xmlGetProp (child, (const xmlChar *) "address");
-                        if (!address) continue;
-                    }
-                }
-
-                if (il_interface_devices &&
-                    (ignore_device_match (il_interface_devices, name, path) != 0 ||
-                     ignore_device_match (il_interface_devices, name, address) != 0))
-                    goto cont3;
-
-                add_interface_device (dom, path, address, j+1);
-                cont3:
-                    if (path) xmlFree (path);
-                    if (address) xmlFree (address);
-            }
-
-        cont:
-            if (xpath_obj) xmlXPathFreeObject (xpath_obj);
-            if (xpath_ctx) xmlXPathFreeContext (xpath_ctx);
-            if (xml_doc) xmlFreeDoc (xml_doc);
-            sfree (xml);
-        }
-
-        sfree (domids);
-    }
-
-    return 0;
-}
-
-static void
-free_domains ()
-{
-    int i;
-
-    if (domains) {
-        for (i = 0; i < nr_domains; ++i)
-            virDomainFree (domains[i]);
-        sfree (domains);
-    }
-    domains = NULL;
-    nr_domains = 0;
-}
-
-static int
-add_domain (virDomainPtr dom)
-{
-    virDomainPtr *new_ptr;
-    int new_size = sizeof (domains[0]) * (nr_domains+1);
-
-    if (domains)
-        new_ptr = realloc (domains, new_size);
-    else
-        new_ptr = malloc (new_size);
-
-    if (new_ptr == NULL)
-        return -1;
-
-    domains = new_ptr;
-    domains[nr_domains] = dom;
-    return nr_domains++;
-}
-
-static void
-free_block_devices ()
-{
-    int i;
-
-    if (block_devices) {
-        for (i = 0; i < nr_block_devices; ++i)
-            sfree (block_devices[i].path);
-        sfree (block_devices);
-    }
-    block_devices = NULL;
-    nr_block_devices = 0;
-}
-
-static int
-add_block_device (virDomainPtr dom, const char *path)
-{
-    struct block_device *new_ptr;
-    int new_size = sizeof (block_devices[0]) * (nr_block_devices+1);
-    char *path_copy;
-
-    path_copy = strdup (path);
-    if (!path_copy)
-        return -1;
-
-    if (block_devices)
-        new_ptr = realloc (block_devices, new_size);
-    else
-        new_ptr = malloc (new_size);
-
-    if (new_ptr == NULL) {
-        sfree (path_copy);
-        return -1;
-    }
-    block_devices = new_ptr;
-    block_devices[nr_block_devices].dom = dom;
-    block_devices[nr_block_devices].path = path_copy;
-    return nr_block_devices++;
-}
-
-static void
-free_interface_devices ()
-{
-    int i;
-
-    if (interface_devices) {
-        for (i = 0; i < nr_interface_devices; ++i) {
-            sfree (interface_devices[i].path);
-            sfree (interface_devices[i].address);
-            sfree (interface_devices[i].number);
-        }
-        sfree (interface_devices);
-    }
-    interface_devices = NULL;
-    nr_interface_devices = 0;
-}
-
-static int
-add_interface_device (virDomainPtr dom, const char *path, const char *address, unsigned int number)
-{
-    struct interface_device *new_ptr;
-    int new_size = sizeof (interface_devices[0]) * (nr_interface_devices+1);
-    char *path_copy, *address_copy, number_string[15];
-
-    if ((path == NULL) || (address == NULL))
-        return EINVAL;
-
-    path_copy = strdup (path);
-    if (!path_copy) return -1;
-
-    address_copy = strdup (address);
-    if (!address_copy) {
-        sfree(path_copy);
-        return -1;
-    }
-
-    snprintf(number_string, sizeof (number_string), "interface-%u", number);
-
-    if (interface_devices)
-        new_ptr = realloc (interface_devices, new_size);
-    else
-        new_ptr = malloc (new_size);
-
-    if (new_ptr == NULL) {
-        sfree (path_copy);
-        sfree (address_copy);
-        return -1;
-    }
-    interface_devices = new_ptr;
-    interface_devices[nr_interface_devices].dom = dom;
-    interface_devices[nr_interface_devices].path = path_copy;
-    interface_devices[nr_interface_devices].address = address_copy;
-    interface_devices[nr_interface_devices].number = strdup(number_string);
-    return nr_interface_devices++;
-}
-
-static int
-ignore_device_match (ignorelist_t *il, const char *domname, const char *devpath)
-{
-    char *name;
-    int n, r;
-
-    if ((domname == NULL) || (devpath == NULL))
-        return 0;
-
-    n = sizeof (char) * (strlen (domname) + strlen (devpath) + 2);
-    name = malloc (n);
-    if (name == NULL) {
-        ERROR ("libvirt plugin: malloc failed.");
-        return 0;
-    }
-    ssnprintf (name, n, "%s:%s", domname, devpath);
-    r = ignorelist_match (il, name);
-    sfree (name);
-    return r;
-}
-
-static int
-lv_shutdown (void)
-{
-    free_block_devices ();
-    free_interface_devices ();
-    free_domains ();
-
-    if (conn != NULL)
-        virConnectClose (conn);
-    conn = NULL;
-
-    ignorelist_free (il_domains);
-    il_domains = NULL;
-    ignorelist_free (il_block_devices);
-    il_block_devices = NULL;
-    ignorelist_free (il_interface_devices);
-    il_interface_devices = NULL;
-
-    return 0;
-}
-
-void
-module_register (void)
-{
-    plugin_register_config ("libvirt",
-    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);
-}
-
-/*
- * vim: shiftwidth=4 tabstop=8 softtabstop=4 expandtab fdm=marker
- */
index 0188da7ef38407972f5570f47fabcf622db41b4b..18b5f8e87457b2f9dbdc9e723e9f6b6da9967843 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
  * 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 _DEFAULT_SOURCE
 #define _BSD_SOURCE
 
 #include "collectd.h"
 #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 +102,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 +121,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 +171,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 +184,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 +202,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 +214,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..61e7f48
--- /dev/null
@@ -0,0 +1,384 @@
+/**
+ * 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 (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;
+       }
+
+       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 63448cb6c4e9f61cc611c71ed2c37840d160e17e..b75ecb8b39878843b5ca4abf21d89db38e2fa155 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"
index 12c621d0569f7b9d05eabdab9c9f043974cd5e28..9e245423fef2c829d842619a3a77ee8213864ae4 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,91 @@ 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));
-    }
+        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;
 
-    return (0);
+        /* 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 1ab445a7af0d793a825da5e72fd1465dbc59ebad..abde2b3495f818bf25b3188b4dadfd090210d6c9 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 ee3101a23190c3f2848994ca90ab6900c6eb03a5..ba0c47c3f30275ce422f30b6fa717b0bb0d761cf 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 1defc18026241e6580e777b6ec8324c84c1411b7..4fa6ce78d5d0c0007629a98e43fe4c5b3fbc2973 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 2e2741550c46e63882fd162d31caf8264cbfce21..996201adfab746f28883865b05f6932572e756ce 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 ae6282c4afa4a54083a745ba14bcaa01873d3eca..4d49984f618173b48323634a3ed34a1b85cde048 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 90226bbf6e7403eda02919b8b9e02fb008215ba2..d23062db2d54734551789c76cac837c9915c43f2 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 72544fcf6de00b8afd4b9bbb16f35fd766501c26..013b6c4ed6f83053fa42ace7848218fcaaf5448c 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 e5540d15d2e8aeca313251ec6098cc02abb3faed..f6af4fc77c2019e3152f26af5aa77ac4b43cc26d 100644 (file)
@@ -388,7 +388,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>
      */
 
     /*
@@ -438,6 +438,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 6a50161017bf22e7d384bc597589ad48f97a1e4e..fb2f3d38a4045fd8790160a1155ed04cda33ab23 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
  **/
@@ -30,6 +30,9 @@
 #ifdef HAVE_SYS_SYSCTL_H
 # include <sys/sysctl.h>
 #endif
+#ifdef HAVE_SYS_VMMETER_H
+# include <sys/vmmeter.h>
+#endif
 
 #ifdef HAVE_MACH_KERN_RETURN_H
 # include <mach/kern_return.h>
@@ -84,12 +87,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 +158,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));
+#define MEMORY_SUBMIT(...) do { \
+       if (values_absolute) \
+               plugin_dispatch_multivalue (vl, 0, DS_TYPE_GAUGE, __VA_ARGS__, NULL); \
+       if (values_percentage) \
+               plugin_dispatch_multivalue (vl, 1, DS_TYPE_GAUGE, __VA_ARGS__, NULL); \
+} while (0)
 
-       plugin_dispatch_values (&vl);
-}
-
-static int memory_read (void)
+static int memory_read_internal (value_list_t *vl)
 {
 #if HAVE_HOST_STATISTICS
        kern_return_t status;
@@ -200,10 +214,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 +267,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 +281,16 @@ 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;
+       _Bool detailed_slab_info = 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;
+       gauge_t mem_slab_total = 0;
+       gauge_t mem_slab_reclaimable = 0;
+       gauge_t mem_slab_unreclaimable = 0;
 
        if ((fh = fopen ("/proc/meminfo", "r")) == NULL)
        {
@@ -280,27 +300,36 @@ 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)
                        val = &mem_buffered;
                else if (strncasecmp (buffer, "Cached:", 7) == 0)
                        val = &mem_cached;
+               else if (strncasecmp (buffer, "Slab:", 5) == 0)
+                       val = &mem_slab_total;
+               else if (strncasecmp (buffer, "SReclaimable:", 13) == 0) {
+                       val = &mem_slab_reclaimable;
+                       detailed_slab_info = 1;
+               }
+               else if (strncasecmp (buffer, "SUnreclaim:", 11) == 0) {
+                       val = &mem_slab_unreclaimable;
+                       detailed_slab_info = 1;
+               }
                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 +339,33 @@ 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 + mem_slab_total))
+               return (-1);
+
+       mem_used = mem_total - (mem_free + mem_buffered + mem_cached + mem_slab_total);
+
+       /* SReclaimable and SUnreclaim were introduced in kernel 2.6.19
+        * They sum up to the value of Slab, which is available on older & newer
+        * kernels. So SReclaimable/SUnreclaim are submitted if available, and Slab
+        * if not. */
+       if (detailed_slab_info)
+               MEMORY_SUBMIT ("used",        mem_used,
+                              "buffered",    mem_buffered,
+                              "cached",      mem_cached,
+                              "free",        mem_free,
+                              "slab_unrecl", mem_slab_unreclaimable,
+                              "slab_recl",   mem_slab_reclaimable);
+       else
+               MEMORY_SUBMIT ("used",     mem_used,
+                              "buffered", mem_buffered,
+                              "cached",   mem_cached,
+                              "free",     mem_free,
+                              "slab",     mem_slab_total);
 /* #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 +415,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 +432,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 +458,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 */
diff --git a/src/meta_data.c b/src/meta_data.c
deleted file mode 100644 (file)
index 48dcabc..0000000
+++ /dev/null
@@ -1,632 +0,0 @@
-/**
- * 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.
- *
- * 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
- *
- * Authors:
- *   Florian octo Forster <octo at verplant.org>
- **/
-
-#include "collectd.h"
-#include "plugin.h"
-#include "meta_data.h"
-
-#include <pthread.h>
-
-/*
- * Data types
- */
-union meta_value_u
-{
-  char    *mv_string;
-  int64_t  mv_signed_int;
-  uint64_t mv_unsigned_int;
-  double   mv_double;
-  _Bool    mv_boolean;
-};
-typedef union meta_value_u meta_value_t;
-
-struct meta_entry_s;
-typedef struct meta_entry_s meta_entry_t;
-struct meta_entry_s
-{
-  char         *key;
-  meta_value_t  value;
-  int           type;
-  meta_entry_t *next;
-};
-
-struct meta_data_s
-{
-  meta_entry_t   *head;
-  pthread_mutex_t lock;
-};
-
-/*
- * Private functions
- */
-static char *md_strdup (const char *orig) /* {{{ */
-{
-  size_t sz;
-  char *dest;
-
-  if (orig == NULL)
-    return (NULL);
-
-  sz = strlen (orig) + 1;
-  dest = (char *) malloc (sz);
-  if (dest == NULL)
-    return (NULL);
-
-  memcpy (dest, orig, sz);
-
-  return (dest);
-} /* }}} char *md_strdup */
-
-static meta_entry_t *md_entry_alloc (const char *key) /* {{{ */
-{
-  meta_entry_t *e;
-
-  e = (meta_entry_t *) malloc (sizeof (*e));
-  if (e == NULL)
-  {
-    ERROR ("md_entry_alloc: malloc failed.");
-    return (NULL);
-  }
-  memset (e, 0, sizeof (*e));
-
-  e->key = md_strdup (key);
-  if (e->key == NULL)
-  {
-    free (e);
-    ERROR ("md_entry_alloc: md_strdup failed.");
-    return (NULL);
-  }
-
-  e->type = 0;
-  e->next = NULL;
-
-  return (e);
-} /* }}} meta_entry_t *md_entry_alloc */
-
-static meta_entry_t *md_entry_clone (const meta_entry_t *orig) /* {{{ */
-{
-  meta_entry_t *copy;
-
-  if (orig == NULL)
-    return (NULL);
-
-  copy = md_entry_alloc (orig->key);
-  copy->type = orig->type;
-  if (copy->type == MD_TYPE_STRING)
-    copy->value.mv_string = strdup (orig->value.mv_string);
-  else
-    copy->value = orig->value;
-
-  copy->next = md_entry_clone (orig->next);
-  return (copy);
-} /* }}} meta_entry_t *md_entry_clone */
-
-static void md_entry_free (meta_entry_t *e) /* {{{ */
-{
-  if (e == NULL)
-    return;
-
-  free (e->key);
-
-  if (e->type == MD_TYPE_STRING)
-    free (e->value.mv_string);
-
-  if (e->next != NULL)
-    md_entry_free (e->next);
-
-  free (e);
-} /* }}} void md_entry_free */
-
-static int md_entry_insert (meta_data_t *md, meta_entry_t *e) /* {{{ */
-{
-  meta_entry_t *this;
-  meta_entry_t *prev;
-
-  if ((md == NULL) || (e == NULL))
-    return (-EINVAL);
-
-  pthread_mutex_lock (&md->lock);
-
-  prev = NULL;
-  this = md->head;
-  while (this != NULL)
-  {
-    if (strcasecmp (e->key, this->key) == 0)
-      break;
-
-    prev = this;
-    this = this->next;
-  }
-
-  if (this == NULL)
-  {
-    /* This key does not exist yet. */
-    if (md->head == NULL)
-      md->head = e;
-    else
-    {
-      assert (prev != NULL);
-      prev->next = e;
-    }
-
-    e->next = NULL;
-  }
-  else /* (this != NULL) */
-  {
-    if (prev == NULL)
-      md->head = e;
-    else
-      prev->next = e;
-
-    e->next = this->next;
-  }
-
-  pthread_mutex_unlock (&md->lock);
-
-  if (this != NULL)
-  {
-    this->next = NULL;
-    md_entry_free (this);
-  }
-
-  return (0);
-} /* }}} int md_entry_insert */
-
-/* XXX: The lock on md must be held while calling this function! */
-static meta_entry_t *md_entry_lookup (meta_data_t *md, /* {{{ */
-    const char *key)
-{
-  meta_entry_t *e;
-
-  if ((md == NULL) || (key == NULL))
-    return (NULL);
-
-  for (e = md->head; e != NULL; e = e->next)
-    if (strcasecmp (key, e->key) == 0)
-      break;
-
-  return (e);
-} /* }}} meta_entry_t *md_entry_lookup */
-
-/*
- * Public functions
- */
-meta_data_t *meta_data_create (void) /* {{{ */
-{
-  meta_data_t *md;
-
-  md = (meta_data_t *) malloc (sizeof (*md));
-  if (md == NULL)
-  {
-    ERROR ("meta_data_create: malloc failed.");
-    return (NULL);
-  }
-  memset (md, 0, sizeof (*md));
-
-  md->head = NULL;
-  pthread_mutex_init (&md->lock, /* attr = */ NULL);
-
-  return (md);
-} /* }}} meta_data_t *meta_data_create */
-
-meta_data_t *meta_data_clone (meta_data_t *orig) /* {{{ */
-{
-  meta_data_t *copy;
-
-  if (orig == NULL)
-    return (NULL);
-
-  copy = meta_data_create ();
-  if (copy == NULL)
-    return (NULL);
-
-  pthread_mutex_lock (&orig->lock);
-  copy->head = md_entry_clone (orig->head);
-  pthread_mutex_unlock (&orig->lock);
-
-  return (copy);
-} /* }}} meta_data_t *meta_data_clone */
-
-void meta_data_destroy (meta_data_t *md) /* {{{ */
-{
-  if (md == NULL)
-    return;
-
-  pthread_mutex_destroy(&md->lock);
-  md_entry_free (md->head);
-  pthread_mutex_destroy (&md->lock);
-  free (md);
-} /* }}} void meta_data_destroy */
-
-int meta_data_exists (meta_data_t *md, const char *key) /* {{{ */
-{
-  meta_entry_t *e;
-
-  if ((md == NULL) || (key == NULL))
-    return (-EINVAL);
-
-  pthread_mutex_lock (&md->lock);
-
-  for (e = md->head; e != NULL; e = e->next)
-  {
-    if (strcasecmp (key, e->key) == 0)
-    {
-      pthread_mutex_unlock (&md->lock);
-      return (1);
-    }
-  }
-
-  pthread_mutex_unlock (&md->lock);
-  return (0);
-} /* }}} int meta_data_exists */
-
-int meta_data_type (meta_data_t *md, const char *key) /* {{{ */
-{
-  meta_entry_t *e;
-
-  if ((md == NULL) || (key == NULL))
-    return -EINVAL;
-
-  pthread_mutex_lock (&md->lock);
-
-  for (e = md->head; e != NULL; e = e->next)
-  {
-    if (strcasecmp (key, e->key) == 0)
-    {
-      pthread_mutex_unlock (&md->lock);
-      return e->type;
-    }
-  }
-
-  pthread_mutex_unlock (&md->lock);
-  return 0;
-} /* }}} int meta_data_type */
-
-int meta_data_toc (meta_data_t *md, char ***toc) /* {{{ */
-{
-  int i = 0, count = 0;
-  meta_entry_t *e;
-
-  if ((md == NULL) || (toc == NULL))
-    return -EINVAL;
-
-  pthread_mutex_lock (&md->lock);
-
-  for (e = md->head; e != NULL; e = e->next)
-    ++count;    
-
-  if (count == 0)
-  {
-    pthread_mutex_unlock (&md->lock);
-    return (count);
-  }
-
-  *toc = calloc(count, sizeof(**toc));
-  for (e = md->head; e != NULL; e = e->next)
-    (*toc)[i++] = strdup(e->key);
-  
-  pthread_mutex_unlock (&md->lock);
-  return count;
-} /* }}} int meta_data_toc */
-
-int meta_data_delete (meta_data_t *md, const char *key) /* {{{ */
-{
-  meta_entry_t *this;
-  meta_entry_t *prev;
-
-  if ((md == NULL) || (key == NULL))
-    return (-EINVAL);
-
-  pthread_mutex_lock (&md->lock);
-
-  prev = NULL;
-  this = md->head;
-  while (this != NULL)
-  {
-    if (strcasecmp (key, this->key) == 0)
-      break;
-
-    prev = this;
-    this = this->next;
-  }
-
-  if (this == NULL)
-  {
-    pthread_mutex_unlock (&md->lock);
-    return (-ENOENT);
-  }
-
-  if (prev == NULL)
-    md->head = this->next;
-  else
-    prev->next = this->next;
-
-  pthread_mutex_unlock (&md->lock);
-
-  this->next = NULL;
-  md_entry_free (this);
-
-  return (0);
-} /* }}} int meta_data_delete */
-
-/*
- * Add functions
- */
-int meta_data_add_string (meta_data_t *md, /* {{{ */
-    const char *key, const char *value)
-{
-  meta_entry_t *e;
-
-  if ((md == NULL) || (key == NULL) || (value == NULL))
-    return (-EINVAL);
-
-  e = md_entry_alloc (key);
-  if (e == NULL)
-    return (-ENOMEM);
-
-  e->value.mv_string = md_strdup (value);
-  if (e->value.mv_string == NULL)
-  {
-    ERROR ("meta_data_add_string: md_strdup failed.");
-    md_entry_free (e);
-    return (-ENOMEM);
-  }
-  e->type = MD_TYPE_STRING;
-
-  return (md_entry_insert (md, e));
-} /* }}} int meta_data_add_string */
-
-int meta_data_add_signed_int (meta_data_t *md, /* {{{ */
-    const char *key, int64_t value)
-{
-  meta_entry_t *e;
-
-  if ((md == NULL) || (key == NULL))
-    return (-EINVAL);
-
-  e = md_entry_alloc (key);
-  if (e == NULL)
-    return (-ENOMEM);
-
-  e->value.mv_signed_int = value;
-  e->type = MD_TYPE_SIGNED_INT;
-
-  return (md_entry_insert (md, e));
-} /* }}} int meta_data_add_signed_int */
-
-int meta_data_add_unsigned_int (meta_data_t *md, /* {{{ */
-    const char *key, uint64_t value)
-{
-  meta_entry_t *e;
-
-  if ((md == NULL) || (key == NULL))
-    return (-EINVAL);
-
-  e = md_entry_alloc (key);
-  if (e == NULL)
-    return (-ENOMEM);
-
-  e->value.mv_unsigned_int = value;
-  e->type = MD_TYPE_UNSIGNED_INT;
-
-  return (md_entry_insert (md, e));
-} /* }}} int meta_data_add_unsigned_int */
-
-int meta_data_add_double (meta_data_t *md, /* {{{ */
-    const char *key, double value)
-{
-  meta_entry_t *e;
-
-  if ((md == NULL) || (key == NULL))
-    return (-EINVAL);
-
-  e = md_entry_alloc (key);
-  if (e == NULL)
-    return (-ENOMEM);
-
-  e->value.mv_double = value;
-  e->type = MD_TYPE_DOUBLE;
-
-  return (md_entry_insert (md, e));
-} /* }}} int meta_data_add_double */
-
-int meta_data_add_boolean (meta_data_t *md, /* {{{ */
-    const char *key, _Bool value)
-{
-  meta_entry_t *e;
-
-  if ((md == NULL) || (key == NULL))
-    return (-EINVAL);
-
-  e = md_entry_alloc (key);
-  if (e == NULL)
-    return (-ENOMEM);
-
-  e->value.mv_boolean = value;
-  e->type = MD_TYPE_BOOLEAN;
-
-  return (md_entry_insert (md, e));
-} /* }}} int meta_data_add_boolean */
-
-/*
- * Get functions
- */
-int meta_data_get_string (meta_data_t *md, /* {{{ */
-    const char *key, char **value)
-{
-  meta_entry_t *e;
-  char *temp;
-
-  if ((md == NULL) || (key == NULL) || (value == NULL))
-    return (-EINVAL);
-
-  pthread_mutex_lock (&md->lock);
-
-  e = md_entry_lookup (md, key);
-  if (e == NULL)
-  {
-    pthread_mutex_unlock (&md->lock);
-    return (-ENOENT);
-  }
-
-  if (e->type != MD_TYPE_STRING)
-  {
-    ERROR ("meta_data_get_string: Type mismatch for key `%s'", e->key);
-    pthread_mutex_unlock (&md->lock);
-    return (-ENOENT);
-  }
-
-  temp = md_strdup (e->value.mv_string);
-  if (temp == NULL)
-  {
-    pthread_mutex_unlock (&md->lock);
-    ERROR ("meta_data_get_string: md_strdup failed.");
-    return (-ENOMEM);
-  }
-  pthread_mutex_unlock (&md->lock);
-
-  *value = temp;
-
-  return (0);
-} /* }}} int meta_data_get_string */
-
-int meta_data_get_signed_int (meta_data_t *md, /* {{{ */
-    const char *key, int64_t *value)
-{
-  meta_entry_t *e;
-
-  if ((md == NULL) || (key == NULL) || (value == NULL))
-    return (-EINVAL);
-
-  pthread_mutex_lock (&md->lock);
-
-  e = md_entry_lookup (md, key);
-  if (e == NULL)
-  {
-    pthread_mutex_unlock (&md->lock);
-    return (-ENOENT);
-  }
-
-  if (e->type != MD_TYPE_SIGNED_INT)
-  {
-    ERROR ("meta_data_get_signed_int: Type mismatch for key `%s'", e->key);
-    pthread_mutex_unlock (&md->lock);
-    return (-ENOENT);
-  }
-
-  *value = e->value.mv_signed_int;
-
-  pthread_mutex_unlock (&md->lock);
-  return (0);
-} /* }}} int meta_data_get_signed_int */
-
-int meta_data_get_unsigned_int (meta_data_t *md, /* {{{ */
-    const char *key, uint64_t *value)
-{
-  meta_entry_t *e;
-
-  if ((md == NULL) || (key == NULL) || (value == NULL))
-    return (-EINVAL);
-
-  pthread_mutex_lock (&md->lock);
-
-  e = md_entry_lookup (md, key);
-  if (e == NULL)
-  {
-    pthread_mutex_unlock (&md->lock);
-    return (-ENOENT);
-  }
-
-  if (e->type != MD_TYPE_UNSIGNED_INT)
-  {
-    ERROR ("meta_data_get_unsigned_int: Type mismatch for key `%s'", e->key);
-    pthread_mutex_unlock (&md->lock);
-    return (-ENOENT);
-  }
-
-  *value = e->value.mv_unsigned_int;
-
-  pthread_mutex_unlock (&md->lock);
-  return (0);
-} /* }}} int meta_data_get_unsigned_int */
-
-int meta_data_get_double (meta_data_t *md, /* {{{ */
-    const char *key, double *value)
-{
-  meta_entry_t *e;
-
-  if ((md == NULL) || (key == NULL) || (value == NULL))
-    return (-EINVAL);
-
-  pthread_mutex_lock (&md->lock);
-
-  e = md_entry_lookup (md, key);
-  if (e == NULL)
-  {
-    pthread_mutex_unlock (&md->lock);
-    return (-ENOENT);
-  }
-
-  if (e->type != MD_TYPE_DOUBLE)
-  {
-    ERROR ("meta_data_get_double: Type mismatch for key `%s'", e->key);
-    pthread_mutex_unlock (&md->lock);
-    return (-ENOENT);
-  }
-
-  *value = e->value.mv_double;
-
-  pthread_mutex_unlock (&md->lock);
-  return (0);
-} /* }}} int meta_data_get_double */
-
-int meta_data_get_boolean (meta_data_t *md, /* {{{ */
-    const char *key, _Bool *value)
-{
-  meta_entry_t *e;
-
-  if ((md == NULL) || (key == NULL) || (value == NULL))
-    return (-EINVAL);
-
-  pthread_mutex_lock (&md->lock);
-
-  e = md_entry_lookup (md, key);
-  if (e == NULL)
-  {
-    pthread_mutex_unlock (&md->lock);
-    return (-ENOENT);
-  }
-
-  if (e->type != MD_TYPE_BOOLEAN)
-  {
-    ERROR ("meta_data_get_boolean: Type mismatch for key `%s'", e->key);
-    pthread_mutex_unlock (&md->lock);
-    return (-ENOENT);
-  }
-
-  *value = e->value.mv_boolean;
-
-  pthread_mutex_unlock (&md->lock);
-  return (0);
-} /* }}} int meta_data_get_boolean */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/src/meta_data.h b/src/meta_data.h
deleted file mode 100644 (file)
index f1af40e..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * 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.
- *
- * 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
- *
- * Authors:
- *   Florian octo Forster <octo at verplant.org>
- **/
-
-#ifndef META_DATA_H
-#define META_DATA_H
-
-#include "collectd.h"
-
-/*
- * Defines
- */
-#define MD_TYPE_STRING       1
-#define MD_TYPE_SIGNED_INT   2
-#define MD_TYPE_UNSIGNED_INT 3
-#define MD_TYPE_DOUBLE       4
-#define MD_TYPE_BOOLEAN      5
-
-struct meta_data_s;
-typedef struct meta_data_s meta_data_t;
-
-meta_data_t *meta_data_create (void);
-meta_data_t *meta_data_clone (meta_data_t *orig);
-void meta_data_destroy (meta_data_t *md);
-
-int meta_data_exists (meta_data_t *md, const char *key);
-int meta_data_type (meta_data_t *md, const char *key);
-int meta_data_toc (meta_data_t *md, char ***toc);
-int meta_data_delete (meta_data_t *md, const char *key);
-
-int meta_data_add_string (meta_data_t *md,
-    const char *key,
-    const char *value);
-int meta_data_add_signed_int (meta_data_t *md,
-    const char *key,
-    int64_t value);
-int meta_data_add_unsigned_int (meta_data_t *md,
-    const char *key,
-    uint64_t value);
-int meta_data_add_double (meta_data_t *md,
-    const char *key,
-    double value);
-int meta_data_add_boolean (meta_data_t *md,
-    const char *key,
-    _Bool value);
-
-int meta_data_get_string (meta_data_t *md,
-    const char *key,
-    char **value);
-int meta_data_get_signed_int (meta_data_t *md,
-    const char *key,
-    int64_t *value);
-int meta_data_get_unsigned_int (meta_data_t *md,
-    const char *key,
-    uint64_t *value);
-int meta_data_get_double (meta_data_t *md,
-    const char *key,
-    double *value);
-int meta_data_get_boolean (meta_data_t *md,
-    const char *key,
-    _Bool *value);
-
-#endif /* META_DATA_H */
-/* vim: set sw=2 sts=2 et : */
index df169825706a9bde4d2d06fa22d3ed63ed883d1f..f18b0afb0d373ad911b6726052d7fb97a8ed0c0e 100644 (file)
@@ -47,6 +47,7 @@
 /*
  * <Data "data_name">
  *   RegisterBase 1234
+ *   RegisterCmd ReadHolding
  *   RegisterType float
  *   Type gauge
  *   Instance "..."
  * <Host "name">
  *   Address "addr"
  *   Port "1234"
+ *   # Or:
+ *   # Device "/dev/ttyUSB0"
+ *   # Baudrate 38400
+ *   # (Assumes 8N1)
  *   Interval 60
  *
  *   <Slave 1>
@@ -75,7 +80,21 @@ enum mb_register_type_e /* {{{ */
   REG_TYPE_UINT32,
   REG_TYPE_FLOAT
 }; /* }}} */
+enum mb_mreg_type_e /* {{{ */ 
+{
+  MREG_HOLDING,
+  MREG_INPUT
+}; /* }}} */
 typedef enum mb_register_type_e mb_register_type_t;
+typedef enum mb_mreg_type_e mb_mreg_type_t;
+
+/* TCP or RTU depending on what is specified in host config block */
+enum mb_conntype_e /* {{{ */
+{
+  MBCONN_TCP,
+  MBCONN_RTU
+}; /* }}} */
+typedef enum mb_conntype_e mb_conntype_t;
 
 struct mb_data_s;
 typedef struct mb_data_s mb_data_t;
@@ -84,6 +103,7 @@ struct mb_data_s /* {{{ */
   char *name;
   int register_base;
   mb_register_type_t register_type;
+  mb_mreg_type_t modbus_register_type;
   char type[DATA_MAX_NAME_LEN];
   char instance[DATA_MAX_NAME_LEN];
 
@@ -101,9 +121,11 @@ typedef struct mb_slave_s mb_slave_t;
 struct mb_host_s /* {{{ */
 {
   char host[DATA_MAX_NAME_LEN];
-  char node[NI_MAXHOST];
+  char node[NI_MAXHOST];       /* TCP hostname or RTU serial device */
   /* char service[NI_MAXSERV]; */
-  int port;
+  int port;                    /* for Modbus/TCP */
+  int baudrate;                        /* for Modbus/RTU */
+  mb_conntype_t conntype;
   cdtime_t interval;
 
   mb_slave_t *slaves;
@@ -293,21 +315,33 @@ static int mb_init_connection (mb_host_t *host) /* {{{ */
   /* We'll do the error handling ourselves. */
   modbus_set_error_handling (&host->connection, NOP_ON_ERROR);
 
-  if ((host->port < 1) || (host->port > 65535))
-    host->port = MODBUS_TCP_DEFAULT_PORT;
+  if (host->conntype == MBCONN_TCP)
+  {
+    if ((host->port < 1) || (host->port > 65535))
+      host->port = MODBUS_TCP_DEFAULT_PORT;
+
+    DEBUG ("Modbus plugin: Trying to connect to \"%s\", port %i.",
+        host->node, host->port);
 
-  DEBUG ("Modbus plugin: Trying to connect to \"%s\", port %i.",
-      host->node, host->port);
+    modbus_init_tcp (&host->connection,
+        /* host = */ host->node,
+        /* port = */ host->port);
+  }
+  else /* MBCONN_RTU */
+  {
+    DEBUG ("Modbus plugin: Trying to connect to \"%s\".", host->node);
 
-  modbus_init_tcp (&host->connection,
-      /* host = */ host->node,
-      /* port = */ host->port);
+    modbus_init_rtu (&host->connection,
+       /* device = */ host->node,
+     /* baudrate = */ host->baudrate,
+                      'N', 8, 1, 0);
+  }
 
   status = modbus_connect (&host->connection);
   if (status != 0)
   {
     ERROR ("Modbus plugin: modbus_connect (%s, %i) failed with status %i.",
-        host->node, host->port, status);
+        host->node, host->port ? host->port : host->baudrate, status);
     return (status);
   }
 
@@ -328,17 +362,32 @@ static int mb_init_connection (mb_host_t *host) /* {{{ */
   if (host->connection != NULL)
     return (0);
 
-  if ((host->port < 1) || (host->port > 65535))
-    host->port = MODBUS_TCP_DEFAULT_PORT;
+  if (host->conntype == MBCONN_TCP)
+  {
+    if ((host->port < 1) || (host->port > 65535))
+      host->port = MODBUS_TCP_DEFAULT_PORT;
 
-  DEBUG ("Modbus plugin: Trying to connect to \"%s\", port %i.",
-      host->node, host->port);
+    DEBUG ("Modbus plugin: Trying to connect to \"%s\", port %i.",
+        host->node, host->port);
 
-  host->connection = modbus_new_tcp (host->node, host->port);
-  if (host->connection == NULL)
+    host->connection = modbus_new_tcp (host->node, host->port);
+    if (host->connection == NULL)
+    {
+      ERROR ("Modbus plugin: Creating new Modbus/TCP object failed.");
+      return (-1);
+    }
+  }
+  else
   {
-    ERROR ("Modbus plugin: Creating new Modbus/TCP object failed.");
-    return (-1);
+    DEBUG ("Modbus plugin: Trying to connect to \"%s\", baudrate %i.",
+        host->node, host->baudrate);
+
+    host->connection = modbus_new_rtu (host->node, host->baudrate, 'N', 8, 1);
+    if (host->connection == NULL)
+    {
+      ERROR ("Modbus plugin: Creating new Modbus/RTU object failed.");
+      return (-1);
+    }
   }
 
   modbus_set_debug (host->connection, 1);
@@ -350,7 +399,7 @@ static int mb_init_connection (mb_host_t *host) /* {{{ */
   if (status != 0)
   {
     ERROR ("Modbus plugin: modbus_connect (%s, %i) failed with status %i.",
-        host->node, host->port, status);
+        host->node, host->port ? host->port : host->baudrate, status);
     modbus_free (host->connection);
     host->connection = NULL;
     return (status);
@@ -377,7 +426,7 @@ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */
   uint16_t values[2];
   int values_num;
   const data_set_t *ds;
-  int status;
+  int status = 0;
 
   if ((host == NULL) || (slave == NULL) || (data == NULL))
     return (EINVAL);
@@ -418,7 +467,7 @@ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */
   {
     status = EBADF;
   }
-  else
+  else if (host->conntype == MBCONN_TCP)
   {
     struct sockaddr sockaddr;
     socklen_t saddrlen = sizeof (sockaddr);
@@ -466,14 +515,21 @@ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */
     return (-1);
   }
 #endif
-
-  status = modbus_read_registers (host->connection,
+  if (data->modbus_register_type == MREG_INPUT){
+    status = modbus_read_input_registers (host->connection,
+        /* start_addr = */ data->register_base,
+        /* num_registers = */ values_num, /* buffer = */ values);
+  }
+  else{
+    status = modbus_read_registers (host->connection,
         /* start_addr = */ data->register_base,
         /* num_registers = */ values_num, /* buffer = */ values);
+  }
   if (status != values_num)
   {
-    ERROR ("Modbus plugin: modbus_read_registers (%s/%s) failed. status = %i, values_num = %i "
-        "Giving up.", host->host, host->node, status, values_num);
+    ERROR ("Modbus plugin: modbus read function (%s/%s) failed. "
+           " status = %i, values_num = %i. Giving up.",
+           host->host, host->node, status, values_num);
 #if LEGACY_LIBMODBUS
     modbus_close (&host->connection);
 #else
@@ -707,6 +763,28 @@ static int mb_config_add_data (oconfig_item_t *ci) /* {{{ */
         status = -1;
       }
     }
+    else if (strcasecmp ("RegisterCmd", child->key) == 0)
+    {
+#if LEGACY_LIBMODBUS
+      ERROR("Modbus plugin: RegisterCmd parameter can not be used "
+            "with your libmodbus version");
+#else
+      char tmp[16];
+      status = cf_util_get_string_buffer (child, tmp, sizeof (tmp));
+      if (status != 0)
+        /* do nothing */;
+      else if (strcasecmp ("ReadHolding", tmp) == 0)
+        data.modbus_register_type = MREG_HOLDING;
+      else if (strcasecmp ("ReadInput", tmp) == 0)
+        data.modbus_register_type = MREG_INPUT;
+      else
+      {
+        ERROR ("Modbus plugin: The modbus_register_type \"%s\" is unknown.",
+               tmp);
+        status = -1;
+      }
+#endif
+    }
     else
     {
       ERROR ("Modbus plugin: Unknown configuration option: %s", child->key);
@@ -879,6 +957,8 @@ static int mb_config_add_host (oconfig_item_t *ci) /* {{{ */
       status = cf_util_get_string_buffer (child, buffer, sizeof (buffer));
       if (status == 0)
         status = mb_config_set_host_address (host, buffer);
+      if (status == 0)
+        host->conntype = MBCONN_TCP;
     }
     else if (strcasecmp ("Port", child->key) == 0)
     {
@@ -886,6 +966,14 @@ static int mb_config_add_host (oconfig_item_t *ci) /* {{{ */
       if (host->port <= 0)
         status = -1;
     }
+    else if (strcasecmp ("Device", child->key) == 0)
+    {
+      status = cf_util_get_string_buffer (child, host->node, sizeof (host->node));
+      if (status == 0)
+        host->conntype = MBCONN_RTU;
+    }
+    else if (strcasecmp ("Baudrate", child->key) == 0)
+      status = cf_util_get_int(child, &host->baudrate);
     else if (strcasecmp ("Interval", child->key) == 0)
       status = cf_util_get_cdtime (child, &host->interval);
     else if (strcasecmp ("Slave", child->key) == 0)
@@ -902,9 +990,22 @@ static int mb_config_add_host (oconfig_item_t *ci) /* {{{ */
   } /* for (i = 0; i < ci->children_num; i++) */
 
   assert (host->host[0] != 0);
-  if (host->host[0] == 0)
+  if (host->node[0] == 0)
   {
-    ERROR ("Modbus plugin: Data block \"%s\": No type has been specified.",
+    ERROR ("Modbus plugin: Data block \"%s\": No address or device has been specified.",
+        host->host);
+    status = -1;
+  }
+  if (host->conntype == MBCONN_RTU && !host->baudrate)
+  {
+    ERROR ("Modbus plugin: Data block \"%s\": No serial baudrate has been specified.",
+        host->host);
+    status = -1;
+  }
+  if ((host->conntype == MBCONN_TCP && host->baudrate) ||
+      (host->conntype == MBCONN_RTU && host->port))
+  {
+    ERROR ("Modbus plugin: Data block \"%s\": You've mixed up RTU and TCP options.",
         host->host);
     status = -1;
   }
index d15a055fe3296f70835e8e6daed68a46b37965bc..eaa03719c5216b23ba316273af40aa654bc891e3 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
@@ -548,6 +567,130 @@ static int mysql_read_slave_stats (mysql_database_t *db, MYSQL *con)
        return (0);
 } /* mysql_read_slave_stats */
 
+static int mysql_read_innodb_stats (mysql_database_t *db, MYSQL *con)
+{
+       MYSQL_RES *res;
+       MYSQL_ROW  row;
+
+       char *query;
+    struct {
+        char *key;
+        char *type;
+        int ds_type;
+    } metrics[] = {
+        { "metadata_mem_pool_size",         "bytes",        DS_TYPE_GAUGE },
+        { "lock_deadlocks",                 "mysql_locks",  DS_TYPE_DERIVE },
+        { "lock_timeouts",                  "mysql_locks",  DS_TYPE_DERIVE },
+        { "lock_row_lock_current_waits",    "mysql_locks",  DS_TYPE_DERIVE },
+        { "buffer_pool_size",               "bytes",        DS_TYPE_GAUGE },
+
+        { "buffer_pool_reads",              "operations",   DS_TYPE_DERIVE },
+        { "buffer_pool_read_requests",      "operations",   DS_TYPE_DERIVE },
+        { "buffer_pool_write_requests",     "operations",   DS_TYPE_DERIVE },
+        { "buffer_pool_wait_free",          "operations",   DS_TYPE_DERIVE },
+        { "buffer_pool_read_ahead",         "operations",   DS_TYPE_DERIVE },
+        { "buffer_pool_read_ahead_evicted", "operations",   DS_TYPE_DERIVE },
+
+        { "buffer_pool_pages_total",        "gauge",        DS_TYPE_GAUGE },
+        { "buffer_pool_pages_misc",         "gauge",        DS_TYPE_GAUGE },
+        { "buffer_pool_pages_data",         "gauge",        DS_TYPE_GAUGE },
+        { "buffer_pool_bytes_data",         "gauge",        DS_TYPE_GAUGE },
+        { "buffer_pool_pages_dirty",        "gauge",        DS_TYPE_GAUGE },
+        { "buffer_pool_bytes_dirty",        "gauge",        DS_TYPE_GAUGE },
+        { "buffer_pool_pages_free",         "gauge",        DS_TYPE_GAUGE },
+
+        { "buffer_pages_created",           "operations",   DS_TYPE_DERIVE },
+        { "buffer_pages_written",           "operations",   DS_TYPE_DERIVE },
+        { "buffer_pages_read",              "operations",   DS_TYPE_DERIVE },
+        { "buffer_data_reads",              "operations",   DS_TYPE_DERIVE },
+        { "buffer_data_written",            "operations",   DS_TYPE_DERIVE },
+
+        { "os_data_reads",                  "operations",   DS_TYPE_DERIVE },
+        { "os_data_writes",                 "operations",   DS_TYPE_DERIVE },
+        { "os_data_fsyncs",                 "operations",   DS_TYPE_DERIVE },
+        { "os_log_bytes_written",           "operations",   DS_TYPE_DERIVE },
+        { "os_log_fsyncs",                  "operations",   DS_TYPE_DERIVE },
+        { "os_log_pending_fsyncs",          "operations",   DS_TYPE_DERIVE },
+        { "os_log_pending_writes",          "operations",   DS_TYPE_DERIVE },
+
+        { "trx_rseg_history_len",           "gauge",        DS_TYPE_GAUGE },
+
+        { "log_waits",                      "operations",   DS_TYPE_DERIVE },
+        { "log_write_requests",             "operations",   DS_TYPE_DERIVE },
+        { "log_writes",                     "operations",   DS_TYPE_DERIVE },
+        { "adaptive_hash_searches",         "operations",   DS_TYPE_DERIVE },
+
+        { "file_num_open_files",            "gauge",        DS_TYPE_GAUGE },
+
+        { "ibuf_merges_insert",             "operations",   DS_TYPE_DERIVE },
+        { "ibuf_merges_delete_mark",        "operations",   DS_TYPE_DERIVE },
+        { "ibuf_merges_delete",             "operations",   DS_TYPE_DERIVE },
+        { "ibuf_merges_discard_insert",     "operations",   DS_TYPE_DERIVE },
+        { "ibuf_merges_discard_delete_mark","operations",   DS_TYPE_DERIVE },
+        { "ibuf_merges_discard_delete",     "operations",   DS_TYPE_DERIVE },
+        { "ibuf_merges_discard_merges",     "operations",   DS_TYPE_DERIVE },
+        { "ibuf_size",                      "bytes",        DS_TYPE_GAUGE },
+
+        { "innodb_activity_count",          "gauge",        DS_TYPE_GAUGE },
+        { "innodb_dblwr_writes",            "operations",   DS_TYPE_DERIVE },
+        { "innodb_dblwr_pages_written",     "operations",   DS_TYPE_DERIVE },
+        { "innodb_dblwr_page_size",         "gauge",        DS_TYPE_GAUGE },
+
+        { "innodb_rwlock_s_spin_waits",     "operations",   DS_TYPE_DERIVE },
+        { "innodb_rwlock_x_spin_waits",     "operations",   DS_TYPE_DERIVE },
+        { "innodb_rwlock_s_spin_rounds",    "operations",   DS_TYPE_DERIVE },
+        { "innodb_rwlock_x_spin_rounds",    "operations",   DS_TYPE_DERIVE },
+        { "innodb_rwlock_s_os_waits",       "operations",   DS_TYPE_DERIVE },
+        { "innodb_rwlock_x_os_waits",       "operations",   DS_TYPE_DERIVE },
+
+        { "dml_reads",                      "operations",   DS_TYPE_DERIVE },
+        { "dml_inserts",                    "operations",   DS_TYPE_DERIVE },
+        { "dml_deletes",                    "operations",   DS_TYPE_DERIVE },
+        { "dml_updates",                    "operations",   DS_TYPE_DERIVE },
+
+        { NULL,                     NULL,           0}
+    };
+
+       query = "SELECT name, count, type FROM information_schema.innodb_metrics WHERE status = 'enabled'";
+
+       res = exec_query (con, query);
+       if (res == NULL)
+               return (-1);
+
+       while ((row = mysql_fetch_row (res)))
+       {
+        int i;
+               char *key;
+               unsigned long long val;
+
+               key = row[0];
+               val = atoll (row[1]);
+
+        for (i = 0;
+             metrics[i].key != NULL && strcmp(metrics[i].key, key) != 0;
+             i++)
+            ;
+
+        if (metrics[i].key == NULL)
+            continue;
+
+        switch (metrics[i].ds_type) {
+        case DS_TYPE_COUNTER:
+            counter_submit(metrics[i].type, key, (counter_t)val, db);
+            break;
+        case DS_TYPE_GAUGE:
+            gauge_submit(metrics[i].type, key, (gauge_t)val, db);
+            break;
+        case DS_TYPE_DERIVE:
+            derive_submit(metrics[i].type, key, (derive_t)val, db);
+            break;
+        }
+    }
+
+    mysql_free_result(res);
+    return (0);
+}
+
 static int mysql_read (user_data_t *ud)
 {
        mysql_database_t *db;
@@ -569,6 +712,7 @@ static int mysql_read (user_data_t *ud)
 
        unsigned long long traffic_incoming = 0ULL;
        unsigned long long traffic_outgoing = 0ULL;
+    unsigned long mysql_version = 0ULL;
 
        if ((ud == NULL) || (ud->data == NULL))
        {
@@ -582,8 +726,10 @@ static int mysql_read (user_data_t *ud)
        if ((con = getconnection (db)) == NULL)
                return (-1);
 
+  mysql_version = mysql_get_server_version(con);
+
        query = "SHOW STATUS";
-       if (mysql_get_server_version (con) >= 50002)
+       if (mysql_version >= 50002)
                query = "SHOW GLOBAL STATUS";
 
        res = exec_query (con, query);
@@ -661,6 +807,102 @@ 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", "pages_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);
+                       else if (strcmp (key, "Innodb_buffer_pool_bytes_data") == 0)
+                               gauge_submit ("mysql_bpool_bytes", "data", val, db);
+                       else if (strcmp (key, "Innodb_buffer_pool_bytes_dirty") == 0)
+                               gauge_submit ("mysql_bpool_bytes", "dirty", 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_innodb_data", "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);
+
+                       /* log */
+                       else if (strcmp (key, "Innodb_log_waits") == 0)
+                               counter_submit ("mysql_innodb_log", "waits", val, db);
+                       else if (strcmp (key, "Innodb_log_write_requests") == 0)
+                               counter_submit ("mysql_innodb_log", "write_requests", val, db);
+                       else if (strcmp (key, "Innodb_log_writes") == 0)
+                               counter_submit ("mysql_innodb_log", "writes", val, db);
+                       else if (strcmp (key, "Innodb_os_log_fsyncs") == 0)
+                               counter_submit ("mysql_innodb_log", "fsyncs", val, db);
+                       else if (strcmp (key, "Innodb_os_log_written") == 0)
+                               counter_submit ("mysql_innodb_log", "written", val, db);
+
+                       /* pages */
+                       else if (strcmp (key, "Innodb_pages_created") == 0)
+                               counter_submit ("mysql_innodb_pages", "created", val, db);
+                       else if (strcmp (key, "Innodb_pages_read") == 0)
+                               counter_submit ("mysql_innodb_pages", "read", val, db);
+                       else if (strcmp (key, "Innodb_pages_written") == 0)
+                               counter_submit ("mysql_innodb_pages", "written", val, db);
+
+                       /* row lock */
+                       else if (strcmp (key, "Innodb_row_lock_time") == 0)
+                               counter_submit ("mysql_innodb_row_lock", "time", val, db);
+                       else if (strcmp (key, "Innodb_row_lock_waits") == 0)
+                               counter_submit ("mysql_innodb_row_lock", "waits", 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;
 
@@ -697,6 +939,9 @@ static int mysql_read (user_data_t *ud)
 
        traffic_submit  (traffic_incoming, traffic_outgoing, db);
 
+       if (mysql_version >= 50600 && db->innodb_stats)
+        mysql_read_innodb_stats (db, con);
+
        if (db->master_stats)
                mysql_read_master_stats (db, con);
 
index 3c4642c296f82ea32c32a80e81db426225188d32..aa9760f9328b78eb87e14f70501bc1622a57f12d 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 ae5ed09652729b2fd7b679d8f90936c07eec59f3..af24911ee365b1ae512000cce93103ffdaf86a94 100644 (file)
@@ -22,6 +22,7 @@
  *   Aman Gupta <aman at tmm1.net>
  **/
 
+#define _DEFAULT_SOURCE
 #define _BSD_SOURCE /* For struct ip_mreq */
 
 #include "collectd.h"
@@ -119,6 +120,8 @@ struct sockent_client
        gcry_cipher_hd_t cypher;
        unsigned char password_hash[32];
 #endif
+       cdtime_t next_resolve_reconnect;
+       cdtime_t resolve_interval;
 };
 
 struct sockent_server
@@ -921,15 +924,19 @@ static int parse_part_number (void **ret_buffer, size_t *ret_buffer_len,
 } /* int parse_part_number */
 
 static int parse_part_string (void **ret_buffer, size_t *ret_buffer_len,
-               char *output, int output_len)
+               char *output, size_t const output_len)
 {
        char *buffer = *ret_buffer;
        size_t buffer_len = *ret_buffer_len;
 
        uint16_t tmp16;
-       size_t header_size = 2 * sizeof (uint16_t);
+       size_t const header_size = 2 * sizeof (uint16_t);
 
        uint16_t pkg_length;
+       size_t payload_size;
+
+       if (output_len <= 0)
+               return (EINVAL);
 
        if (buffer_len < header_size)
        {
@@ -948,6 +955,7 @@ static int parse_part_string (void **ret_buffer, size_t *ret_buffer_len,
        memcpy ((void *) &tmp16, buffer, sizeof (tmp16));
        buffer += sizeof (tmp16);
        pkg_length = ntohs (tmp16);
+       payload_size = ((size_t) pkg_length) - header_size;
 
        /* Check that packet fits in the input buffer */
        if (pkg_length > buffer_len)
@@ -973,22 +981,24 @@ static int parse_part_string (void **ret_buffer, size_t *ret_buffer_len,
        /* Check that the package data fits into the output buffer.
         * The previous if-statement ensures that:
         * `pkg_length > header_size' */
-       if ((output_len < 0)
-                       || ((size_t) output_len < ((size_t) pkg_length - header_size)))
+       if (output_len < payload_size)
        {
                WARNING ("network plugin: parse_part_string: "
-                               "Output buffer too small.");
+                               "Buffer too small: "
+                               "Output buffer holds %zu bytes, "
+                               "which is too small to hold the received "
+                               "%zu byte string.",
+                               output_len, payload_size);
                return (-1);
        }
 
        /* All sanity checks successfull, let's copy the data over */
-       output_len = pkg_length - header_size;
-       memcpy ((void *) output, (void *) buffer, output_len);
-       buffer += output_len;
+       memcpy ((void *) output, (void *) buffer, payload_size);
+       buffer += payload_size;
 
        /* For some very weird reason '\0' doesn't do the trick on SPARC in
         * this statement. */
-       if (output[output_len - 1] != 0)
+       if (output[payload_size - 1] != 0)
        {
                WARNING ("network plugin: parse_part_string: "
                                "Received string does not end "
@@ -2029,6 +2039,8 @@ static sockent_t *sockent_create (int type) /* {{{ */
        {
                se->data.client.fd = -1;
                se->data.client.addr = NULL;
+               se->data.client.resolve_interval = 0;
+               se->data.client.next_resolve_reconnect = 0;
 #if HAVE_LIBGCRYPT
                se->data.client.security_level = SECURITY_LEVEL_NONE;
                se->data.client.username = NULL;
@@ -2095,6 +2107,26 @@ static int sockent_init_crypto (sockent_t *se) /* {{{ */
        return (0);
 } /* }}} int sockent_init_crypto */
 
+static int sockent_client_disconnect (sockent_t *se) /* {{{ */
+{
+       struct sockent_client *client;
+
+       if ((se == NULL) || (se->type != SOCKENT_TYPE_CLIENT))
+               return (EINVAL);
+
+       client = &se->data.client;
+       if (client->fd >= 0) /* connected */
+       {
+               close (client->fd);
+               client->fd = -1;
+       }
+
+       sfree (client->addr);
+       client->addrlen = 0;
+
+       return (0);
+} /* }}} int sockent_client_disconnect */
+
 static int sockent_client_connect (sockent_t *se) /* {{{ */
 {
        static c_complain_t complaint = C_COMPLAIN_INIT_STATIC;
@@ -2103,12 +2135,22 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */
        struct addrinfo  ai_hints;
        struct addrinfo *ai_list = NULL, *ai_ptr;
        int status;
+       _Bool reconnect = 0;
+       cdtime_t now;
 
        if ((se == NULL) || (se->type != SOCKENT_TYPE_CLIENT))
                return (EINVAL);
 
        client = &se->data.client;
-       if (client->fd >= 0) /* already connected */
+
+       now = cdtime ();
+       if (client->resolve_interval != 0 && client->next_resolve_reconnect < now) {
+               DEBUG("network plugin: Reconnecting socket, resolve_interval = %lf, next_resolve_reconnect = %lf",
+                       CDTIME_T_TO_DOUBLE(client->resolve_interval), CDTIME_T_TO_DOUBLE(client->next_resolve_reconnect));
+               reconnect = 1;
+       }
+
+       if (client->fd >= 0 && !reconnect) /* already connected and not stale*/
                return (0);
 
        memset (&ai_hints, 0, sizeof (ai_hints));
@@ -2140,6 +2182,9 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */
 
        for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
        {
+               if (client->fd >= 0) /* when we reconnect */
+                       sockent_client_disconnect(se);
+
                client->fd = socket (ai_ptr->ai_family,
                                ai_ptr->ai_socktype,
                                ai_ptr->ai_protocol);
@@ -2177,28 +2222,11 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */
        freeaddrinfo (ai_list);
        if (client->fd < 0)
                return (-1);
-       return (0);
-} /* }}} int sockent_client_connect */
-
-static int sockent_client_disconnect (sockent_t *se) /* {{{ */
-{
-       struct sockent_client *client;
-
-       if ((se == NULL) || (se->type != SOCKENT_TYPE_CLIENT))
-               return (EINVAL);
-
-       client = &se->data.client;
-       if (client->fd >= 0) /* connected */
-       {
-               close (client->fd);
-               client->fd = -1;
-       }
-
-       sfree (client->addr);
-       client->addrlen = 0;
 
+       if (client->resolve_interval > 0)
+               client->next_resolve_reconnect = now + client->resolve_interval;
        return (0);
-} /* }}} int sockent_client_disconnect */
+} /* }}} int sockent_client_connect */
 
 /* Open the file descriptors for a initialized sockent structure. */
 static int sockent_server_listen (sockent_t *se) /* {{{ */
@@ -2985,7 +3013,7 @@ static int network_config_set_ttl (const oconfig_item_t *ci) /* {{{ */
     network_config_ttl = tmp;
   else {
     WARNING ("network plugin: The `TimeToLive' must be between 1 and 255.");
-    return (-1);    
+    return (-1);
   }
 
   return (0);
@@ -3212,6 +3240,8 @@ static int network_config_add_server (const oconfig_item_t *ci) /* {{{ */
     if (strcasecmp ("Interface", child->key) == 0)
       network_config_set_interface (child,
           &se->interface);
+               else if (strcasecmp ("ResolveInterval", child->key) == 0)
+                       cf_util_get_cdtime(child, &se->data.client.resolve_interval);
     else
     {
       WARNING ("network plugin: Option `%s' is not allowed here.",
index 1b354561ec7e8a2ab6e7a29cb1f6106445cca28f..5457722095884caef54bfae0ffeed66fc477ffc9 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 f5b579e1384e0d8d186c8e5c8ff3c098e48ee15d..be823720b489ec3ddd8f1f75d7976b28469fd5ab 100644 (file)
--- a/src/nfs.c
+++ b/src/nfs.c
@@ -171,6 +171,160 @@ static const char *nfs4_procedures_names[] =
 static size_t nfs4_procedures_names_num = STATIC_ARRAY_SIZE (nfs4_procedures_names);
 #endif
 
+#if KERNEL_LINUX
+static const char *nfs4_server40_procedures_names[] =
+{
+       "null",
+       "compound",
+       "reserved",
+       "access",
+       "close",
+       "commit",
+       "create",
+       "delegpurge",
+       "delegreturn",
+       "getattr",
+       "getfh",
+       "link",
+       "lock",
+       "lockt",
+       "locku",
+       "lookup",
+       "lookupp",
+       "nverify",
+       "open",
+       "openattr",
+       "open_confirm",
+       "open_downgrade",
+       "putfh",
+       "putpubfh",
+       "putrootfh",
+       "read",
+       "readdir",
+       "readlink",
+       "remove",
+       "rename",
+       "renew",
+       "restorefh",
+       "savefh",
+       "secinfo",
+       "setattr",
+       "setclientid",
+       "setcltid_confirm",
+       "verify",
+       "write",
+       "release_lockowner"
+};
+
+static size_t nfs4_server40_procedures_names_num = STATIC_ARRAY_SIZE (nfs4_server40_procedures_names);
+
+static const char *nfs4_server41_procedures_names[] =
+{
+       "backchannel_ctl",
+       "bind_conn_to_session", 
+       "exchange_id",
+       "create_session",
+       "destroy_session",
+       "free_stateid",
+       "get_dir_delegation",
+       "getdeviceinfo",
+       "getdevicelist",
+       "layoutcommit",
+       "layoutget",
+       "layoutreturn",
+       "secinfo_no_name",
+       "sequence",
+       "set_ssv",
+       "test_stateid",
+       "want_delegation",
+       "destroy_clientid",
+       "reclaim_complete",
+};
+
+static size_t nfs4_server41_procedures_names_num = STATIC_ARRAY_SIZE (nfs4_server41_procedures_names);
+
+#define NFS4_SERVER40_NUM_PROC ( \
+       STATIC_ARRAY_SIZE (nfs4_server40_procedures_names) )
+
+#define NFS4_SERVER41_NUM_PROC ( \
+       STATIC_ARRAY_SIZE (nfs4_server40_procedures_names) + \
+       STATIC_ARRAY_SIZE (nfs4_server41_procedures_names) )
+
+#define NFS4_SERVER_MAX_PROC (NFS4_SERVER41_NUM_PROC)
+
+static const char *nfs4_client40_procedures_names[] =
+{
+       "null",
+       "read",
+       "write",
+       "commit",
+       "open",
+       "open_confirm",
+       "open_noattr",
+       "open_downgrade",
+       "close",
+       "setattr",
+       "fsinfo",
+       "renew",
+       "setclientid",
+       "setclientid_confirm",
+       "lock",
+       "lockt",
+       "locku",
+       "access",
+       "getattr",
+       "lookup",
+       "lookupp",
+       "remove",
+       "rename",
+       "link",
+       "symlink",
+       "create",
+       "pathconf",
+       "statfs",
+       "readlink",
+       "readdir",
+       "server_caps",
+       "delegreturn",
+       "getacl",
+       "setacl",
+       "fs_locations",         /* |35| 2.6.18 */
+       "release_lockowner",    /* |42| 2.6.36 */
+       "secinfo",              /* |46| 2.6.39 */
+       "fsid_present"          /* |54| 3.13 */
+};
+
+static const char *nfs4_client41_procedures_names[] =
+{
+       "exchange_id",          /* |40| 2.6.30 */
+       "create_session",       /* |40| 2.6.30 */
+       "destroy_session",      /* |40| 2.6.30 */
+       "sequence",             /* |40| 2.6.30 */
+       "get_lease_time",       /* |40| 2.6.30 */
+       "reclaim_complete",     /* |41| 2.6.33 */
+       "layoutget",            /* |44| 2.6.37 */
+       "getdeviceinfo",        /* |44| 2.6.37 */
+       "layoutcommit",         /* |46| 2.6.39 */
+       "layoutreturn",         /* |47| 3.0 */
+       "secinfo_no_name",      /* |51| 3.1 */
+       "test_stateid",         /* |51| 3.1 */
+       "free_stateid",         /* |51| 3.1 */
+       "getdevicelist",        /* |51| 3.1 */
+       "bind_conn_to_session", /* |53| 3.5 */
+       "destroy_clientid"      /* |53| 3.5 */
+};
+
+#define NFS4_CLIENT40_NUM_PROC ( \
+       STATIC_ARRAY_SIZE (nfs4_client40_procedures_names) )
+
+#define NFS4_CLIENT41_NUM_PROC ( \
+       STATIC_ARRAY_SIZE (nfs4_client40_procedures_names) + \
+       STATIC_ARRAY_SIZE (nfs4_client41_procedures_names) )
+
+#define NFS4_CLIENT_MAX_PROC (NFS4_CLIENT41_NUM_PROC)
+
+#endif
+
 #if HAVE_LIBKSTAT
 extern kstat_ctl_t *kc;
 static kstat_t *nfs2_ksp_client;
@@ -181,8 +335,6 @@ static kstat_t *nfs4_ksp_client;
 static kstat_t *nfs4_ksp_server;
 #endif
 
-/* Possibly TODO: NFSv4 statistics */
-
 #if KERNEL_LINUX
 static int nfs_init (void)
 {
@@ -252,14 +404,27 @@ static void nfs_procedures_submit (const char *plugin_instance,
 } /* void nfs_procedures_submit */
 
 #if KERNEL_LINUX
-static int nfs_submit_fields (int nfs_version, const char *instance,
-               char **fields, size_t fields_num,
-               const char **proc_names, size_t proc_names_num)
+static void nfs_submit_fields (int nfs_version, const char *instance, 
+               char **fields, size_t fields_num, const char **proc_names)
 {
        char plugin_instance[DATA_MAX_NAME_LEN];
        value_t values[fields_num];
        size_t i;
 
+       ssnprintf (plugin_instance, sizeof (plugin_instance), "v%i%s",
+                       nfs_version, instance);
+
+       for (i = 0; i < fields_num; i++)
+               (void) parse_value (fields[i], &values[i], DS_TYPE_DERIVE);
+
+       nfs_procedures_submit (plugin_instance, proc_names, values,
+                       fields_num);
+}
+
+static int nfs_submit_fields_safe (int nfs_version, const char *instance,
+               char **fields, size_t fields_num,
+               const char **proc_names, size_t proc_names_num)
+{
        if (fields_num != proc_names_num)
        {
                WARNING ("nfs plugin: Wrong number of fields for "
@@ -269,14 +434,122 @@ static int nfs_submit_fields (int nfs_version, const char *instance,
                return (EINVAL);
        }
 
-       ssnprintf (plugin_instance, sizeof (plugin_instance), "v%i%s",
-                       nfs_version, instance);
+       nfs_submit_fields (nfs_version, instance, fields, fields_num, 
+                       proc_names);
 
-       for (i = 0; i < proc_names_num; i++)
-               (void) parse_value (fields[i], &values[i], DS_TYPE_DERIVE);
+       return (0);
+}
 
-       nfs_procedures_submit (plugin_instance, proc_names, values,
-                       proc_names_num);
+static int nfs_submit_nfs4_server (const char *instance, char **fields, 
+               size_t fields_num)
+{
+       static int suppress_warning = 0;
+
+       if (fields_num != NFS4_SERVER40_NUM_PROC &&
+               fields_num != NFS4_SERVER41_NUM_PROC) 
+       {
+               if (!suppress_warning)
+               {
+                       WARNING ("nfs plugin: Unexpected number of fields for "
+                                       "NFSv4 %s statistics: %zu. ",
+                                       instance, fields_num);
+               }
+
+               if (fields_num > NFS4_SERVER_MAX_PROC)
+               {
+                       fields_num = NFS4_SERVER_MAX_PROC;
+                       suppress_warning = 1;
+               }
+               else
+               {
+                       return (EINVAL);
+               }
+       }
+
+        nfs_submit_fields (4, instance, fields, 
+                       nfs4_server40_procedures_names_num,
+                       nfs4_server40_procedures_names);
+
+       if (fields_num >= NFS4_SERVER41_NUM_PROC)
+       {
+               fields += nfs4_server40_procedures_names_num;
+
+               nfs_submit_fields (4, instance, fields, 
+                               nfs4_server41_procedures_names_num, 
+                               nfs4_server41_procedures_names);
+       }
+
+       return (0);
+}
+
+static int nfs_submit_nfs4_client (const char *instance, char **fields, 
+               size_t fields_num)
+{
+       size_t proc40_names_num, proc41_names_num;
+
+       static int suppress_warning = 0;
+
+       switch (fields_num)
+       {
+               case 34:
+               case 35:
+               case 36:
+               case 37:
+               case 38:
+                       /* 4.0-only configuration */
+                       proc40_names_num = fields_num;
+                       break;
+               case 40:
+               case 41:
+                       proc40_names_num = 35;
+                       break;
+               case 42:
+               case 44:
+                       proc40_names_num = 36;
+                       break;
+               case 46:
+               case 47:
+               case 51:
+               case 53:
+                       proc40_names_num = 37;
+                       break;
+               case 54:
+                       proc40_names_num = 38;
+                       break;
+               default:
+                       if (!suppress_warning)
+                       {
+                               WARNING ("nfs plugin: Unexpected number of "
+                                               "fields for NFSv4 %s "
+                                               "statistics: %zu. ",
+                                               instance, fields_num);
+                       }
+
+                       if (fields_num > 34)
+                       {
+                               /* safe fallback to basic nfs40 procedures */
+                               fields_num = 34;
+                               proc40_names_num = 34;
+
+                               suppress_warning = 1;
+                       }
+                       else
+                       {
+                               return (EINVAL);
+                       }
+       }
+
+       nfs_submit_fields (4, instance, fields, proc40_names_num,
+                       nfs4_client40_procedures_names);
+
+       if (fields_num > proc40_names_num)
+       {
+               proc41_names_num = fields_num - proc40_names_num;
+               fields += proc40_names_num;
+
+               nfs_submit_fields (4, instance, fields,proc41_names_num,
+                                nfs4_client41_procedures_names);
+       }
 
        return (0);
 }
@@ -285,7 +558,7 @@ static void nfs_read_linux (FILE *fh, char *inst)
 {
        char buffer[1024];
 
-       char *fields[48];
+       char *fields[64];
        int fields_num = 0;
 
        if (fh == NULL)
@@ -301,18 +574,30 @@ static void nfs_read_linux (FILE *fh, char *inst)
 
                if (strcmp (fields[0], "proc2") == 0)
                {
-                       nfs_submit_fields (/* version = */ 2, inst,
+                       nfs_submit_fields_safe (/* version = */ 2, inst,
                                        fields + 2, (size_t) (fields_num - 2),
                                        nfs2_procedures_names,
                                        nfs2_procedures_names_num);
                }
                else if (strncmp (fields[0], "proc3", 5) == 0)
                {
-                       nfs_submit_fields (/* version = */ 3, inst,
+                       nfs_submit_fields_safe (/* version = */ 3, inst,
                                        fields + 2, (size_t) (fields_num - 2),
                                        nfs3_procedures_names,
                                        nfs3_procedures_names_num);
                }
+               else if (strcmp (fields[0], "proc4ops") == 0)
+               {
+                       if (inst[0] == 's')
+                               nfs_submit_nfs4_server (inst, fields + 2, 
+                                               (size_t) (fields_num - 2));
+               }
+               else if (strcmp (fields[0], "proc4") == 0)
+               {
+                       if (inst[0] == 'c')
+                               nfs_submit_nfs4_client (inst, fields + 2,
+                                               (size_t) (fields_num - 2));                     
+               }
        } /* while (fgets) */
 } /* void nfs_read_linux */
 #endif /* KERNEL_LINUX */
index de52262f4ec817b1b54ca876652b02e06a845252..4e4ce3bbc6115572873668a76507f80ccd82b316 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>
@@ -35,6 +39,7 @@ static char *pass        = NULL;
 static char *verify_peer = NULL;
 static char *verify_host = NULL;
 static char *cacert      = NULL;
+static char *timeout     = NULL;
 
 static CURL *curl = NULL;
 
@@ -49,7 +54,8 @@ static const char *config_keys[] =
   "Password",
   "VerifyPeer",
   "VerifyHost",
-  "CACert"
+  "CACert",
+  "Timeout"
 };
 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
 
@@ -103,14 +109,14 @@ static int config (const char *key, const char *value)
     return (config_set (&verify_host, value));
   else if (strcasecmp (key, "cacert") == 0)
     return (config_set (&cacert, value));
+  else if (strcasecmp (key, "timeout") == 0)
+    return (config_set (&timeout, value));
   else
     return (-1);
 } /* int config */
 
 static int init (void)
 {
-  static char credentials[1024];
-
   if (curl != NULL)
     curl_easy_cleanup (curl);
 
@@ -122,11 +128,16 @@ 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)
   {
+#ifdef HAVE_CURLOPT_USERNAME
+    curl_easy_setopt (curl, CURLOPT_USERNAME, user);
+    curl_easy_setopt (curl, CURLOPT_PASSWORD, (pass == NULL) ? "" : pass);
+#else
+    static char credentials[1024];
     int status = ssnprintf (credentials, sizeof (credentials),
        "%s:%s", user, pass == NULL ? "" : pass);
     if ((status < 0) || ((size_t) status >= sizeof (credentials)))
@@ -136,6 +147,7 @@ static int init (void)
     }
 
     curl_easy_setopt (curl, CURLOPT_USERPWD, credentials);
+#endif
   }
 
   if (url != NULL)
@@ -169,6 +181,18 @@ static int init (void)
     curl_easy_setopt (curl, CURLOPT_CAINFO, cacert);
   }
 
+#ifdef HAVE_CURLOPT_TIMEOUT_MS
+  if (timeout != NULL)
+  {
+    curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, atol(timeout));
+  }
+  else
+  {
+    curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS,
+       CDTIME_T_TO_MS(plugin_get_interval()));
+  }
+#endif
+
   return (0);
 } /* void init */
 
index 3f3c6dfc9bf62c3ac0dc356295f0e68faf5879a8..c2d97520ed99c9bcbb8839900ea1858ba39731bf 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 540eb788e0b67e3e481be0b382373de5e5d96218..5fdfef3f0db415c0bae5634ac69b5af64e31518f 100644 (file)
@@ -2,23 +2,29 @@
  * 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>
  **/
 
+#define _DEFAULT_SOURCE
 #define _BSD_SOURCE /* For NI_MAXHOST */
 
 #include "collectd.h"
@@ -481,7 +487,7 @@ static int ntpd_receive_response (int *res_items, int *res_size,
                poll_s.fd      = sd;
                poll_s.events  = POLLIN | POLLPRI;
                poll_s.revents = 0;
-               
+
                DEBUG ("Polling for %ims", timeout);
                status = poll (&poll_s, 1, timeout);
 
@@ -521,7 +527,7 @@ static int ntpd_receive_response (int *res_items, int *res_size,
 
                DEBUG ("recv'd %i bytes", status);
 
-               /* 
+               /*
                 * Do some sanity checks first
                 */
                if (status < RESP_HEADER_SIZE)
@@ -730,7 +736,7 @@ static int ntpd_send_request (int req_code, int req_items, int req_size, char *r
 
        req.err_nitems   = ERR_NITEMS (0, req_items);
        req.mbz_itemsize = MBZ_ITEMSIZE (req_size);
-       
+
        if (req_data != NULL)
                memcpy ((void *) req.data, (const void *) req_data, req_data_len);
 
index 4b4ef2085ebef0f15f1299342ec20e002d7688fc..a87a17e9df7c7c0780aa730a280b30c984a94995 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 edc48c61510ab6e716abe17b52d222136ee7ceba..d5ecc98de12b13a811f7e36fc131eaf36dfb6c19 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 be422ab61068d284ef5f1bbc9455bb7e9a214db4..6d0576cf7bc7d26e39567646f40fa1ebd49262cc 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 0266e9b76cedfab62b0b1184ecea7e757644b871..51e6407137b0f2c8bc64598f822cac804c5a9fab 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);
@@ -275,16 +488,103 @@ 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);
+          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)
@@ -298,6 +598,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)
   {
@@ -319,7 +620,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 : */
diff --git a/src/openldap.c b/src/openldap.c
new file mode 100644 (file)
index 0000000..8667058
--- /dev/null
@@ -0,0 +1,683 @@
+/**
+ * collectd - src/openldap.c
+ * Copyright (C) 2011       Kimo Rosenbaum
+ * Copyright (C) 2014       Marc Fournier
+ *
+ * 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:
+ *   Kimo Rosenbaum <kimor79 at yahoo.com>
+ *   Marc Fournier <marc.fournier at camptocamp.com>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+#include "configfile.h"
+
+#include <lber.h>
+#include <ldap.h>
+
+struct cldap_s /* {{{ */
+{
+       char *name;
+
+       char *cacert;
+       char *host;
+       int   state;
+       _Bool starttls;
+       int   timeout;
+       char *url;
+       _Bool verifyhost;
+       int   version;
+
+       LDAP *ld;
+};
+typedef struct cldap_s cldap_t; /* }}} */
+
+static void cldap_free (cldap_t *st) /* {{{ */
+{
+       if (st == NULL)
+               return;
+
+       sfree (st->cacert);
+       sfree (st->host);
+       sfree (st->name);
+       sfree (st->url);
+       if (st->ld)
+               ldap_memfree (st->ld);
+       sfree (st);
+} /* }}} void cldap_free */
+
+/* initialize ldap for each host */
+static int cldap_init_host (cldap_t *st) /* {{{ */
+{
+       LDAP *ld;
+       int rc;
+       rc = ldap_initialize (&ld, st->url);
+       if (rc != LDAP_SUCCESS)
+       {
+               ERROR ("openldap plugin: ldap_initialize failed: %s",
+                       ldap_err2string (rc));
+               st->state = 0;
+               ldap_unbind_ext_s (ld, NULL, NULL);
+               return (-1);
+       }
+
+       st->ld = ld;
+
+       ldap_set_option (st->ld, LDAP_OPT_PROTOCOL_VERSION, &st->version);
+
+       ldap_set_option (st->ld, LDAP_OPT_TIMEOUT,
+               &(const struct timeval){st->timeout, 0});
+
+       if (st->cacert != NULL)
+               ldap_set_option (st->ld, LDAP_OPT_X_TLS_CACERTFILE, st->cacert);
+
+       if (st->verifyhost == 0)
+       {
+               int never = LDAP_OPT_X_TLS_NEVER;
+               ldap_set_option (st->ld, LDAP_OPT_X_TLS_REQUIRE_CERT, &never);
+       }
+
+       if (st->starttls != 0)
+       {
+               rc = ldap_start_tls_s (ld, NULL, NULL);
+               if (rc != LDAP_SUCCESS)
+               {
+                       ERROR ("openldap plugin: Failed to start tls on %s: %s",
+                                       st->url, ldap_err2string (rc));
+                       st->state = 0;
+                       ldap_unbind_ext_s (st->ld, NULL, NULL);
+                       return (-1);
+               }
+       }
+
+       struct berval cred;
+       cred.bv_val = "";
+       cred.bv_len = 0;
+
+       rc = ldap_sasl_bind_s (st->ld, NULL, NULL, &cred, NULL, NULL, NULL);
+       if (rc != LDAP_SUCCESS)
+       {
+               ERROR ("openldap plugin: Failed to bind to %s: %s",
+                               st->url, ldap_err2string (rc));
+               st->state = 0;
+               ldap_unbind_ext_s (st->ld, NULL, NULL);
+               return (-1);
+       }
+       else
+       {
+               DEBUG ("openldap plugin: Successfully connected to %s",
+                               st->url);
+               st->state = 1;
+               return (0);
+       }
+} /* }}} static cldap_init_host */
+
+static void cldap_submit_value (const char *type, const char *type_instance, /* {{{ */
+               value_t value, cldap_t *st)
+{
+       value_list_t vl = VALUE_LIST_INIT;
+
+       vl.values     = &value;
+       vl.values_len = 1;
+
+       if ((st->host == NULL)
+                       || (strcmp ("", st->host) == 0)
+                       || (strcmp ("localhost", st->host) == 0))
+       {
+               sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       }
+       else
+       {
+               sstrncpy (vl.host, st->host, sizeof (vl.host));
+       }
+
+       sstrncpy (vl.plugin, "openldap", sizeof (vl.plugin));
+       if (st->name != NULL)
+               sstrncpy (vl.plugin_instance, st->name,
+                               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 cldap_submit_value */
+
+static void cldap_submit_derive (const char *type, const char *type_instance, /* {{{ */
+               derive_t d, cldap_t *st)
+{
+       value_t v;
+       v.derive = d;
+       cldap_submit_value (type, type_instance, v, st);
+} /* }}} void cldap_submit_derive */
+
+static void cldap_submit_gauge (const char *type, const char *type_instance, /* {{{ */
+               gauge_t g, cldap_t *st)
+{
+       value_t v;
+       v.gauge = g;
+       cldap_submit_value (type, type_instance, v, st);
+} /* }}} void cldap_submit_gauge */
+
+static int cldap_read_host (user_data_t *ud) /* {{{ */
+{
+       cldap_t *st;
+       LDAPMessage *e, *result;
+       char *dn;
+       int rc;
+       int status;
+
+       char *attrs[9] = { "monitorCounter",
+                               "monitorOpCompleted",
+                               "monitorOpInitiated",
+                               "monitoredInfo",
+                               "olmBDBEntryCache",
+                               "olmBDBDNCache",
+                               "olmBDBIDLCache",
+                               "namingContexts",
+                               NULL };
+
+       if ((ud == NULL) || (ud->data == NULL))
+       {
+               ERROR ("openldap plugin: cldap_read_host: Invalid user data.");
+               return (-1);
+       }
+
+       st = (cldap_t *) ud->data;
+
+       status = cldap_init_host (st);
+       if (status != 0)
+               return (-1);
+
+       rc = ldap_search_ext_s (st->ld, "cn=Monitor", LDAP_SCOPE_SUBTREE,
+               "(|(!(cn=* *))(cn=Database*))", attrs, 0,
+               NULL, NULL, NULL, 0, &result);
+
+       if (rc != LDAP_SUCCESS)
+       {
+               ERROR ("openldap plugin: Failed to execute search: %s",
+                               ldap_err2string (rc));
+               ldap_msgfree (result);
+               ldap_unbind_ext_s (st->ld, NULL, NULL);
+               return (-1);
+       }
+
+       for (e = ldap_first_entry (st->ld, result); e != NULL;
+               e = ldap_next_entry (st->ld, e))
+       {
+               if ((dn = ldap_get_dn (st->ld, e)) != NULL)
+               {
+                       unsigned long long counter = 0;
+                       unsigned long long opc = 0;
+                       unsigned long long opi = 0;
+                       unsigned long long info = 0;
+
+                       struct berval counter_data;
+                       struct berval opc_data;
+                       struct berval opi_data;
+                       struct berval info_data;
+                       struct berval olmbdb_data;
+                       struct berval nc_data;
+
+                       struct berval **counter_list;
+                       struct berval **opc_list;
+                       struct berval **opi_list;
+                       struct berval **info_list;
+                       struct berval **olmbdb_list;
+                       struct berval **nc_list;
+
+                       if ((counter_list = ldap_get_values_len (st->ld, e,
+                               "monitorCounter")) != NULL)
+                       {
+                               counter_data = *counter_list[0];
+                               counter = atoll (counter_data.bv_val);
+                       }
+
+                       if ((opc_list = ldap_get_values_len (st->ld, e,
+                               "monitorOpCompleted")) != NULL)
+                       {
+                               opc_data = *opc_list[0];
+                               opc = atoll (opc_data.bv_val);
+                       }
+
+                       if ((opi_list = ldap_get_values_len (st->ld, e,
+                               "monitorOpInitiated")) != NULL)
+                       {
+                               opi_data = *opi_list[0];
+                               opi = atoll (opi_data.bv_val);
+                       }
+
+                       if ((info_list = ldap_get_values_len (st->ld, e,
+                               "monitoredInfo")) != NULL)
+                       {
+                               info_data = *info_list[0];
+                               info = atoll (info_data.bv_val);
+                       }
+
+                       if (strcmp (dn, "cn=Total,cn=Connections,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_derive ("total_connections", NULL,
+                                       counter, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Current,cn=Connections,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_gauge ("current_connections", NULL,
+                                       counter, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Operations,cn=Monitor") == 0)
+                       {
+                               cldap_submit_derive ("operations",
+                                       "completed", opc, st);
+                               cldap_submit_derive ("operations",
+                                       "initiated", opi, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Bind,cn=Operations,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_derive ("operations",
+                                       "bind-completed", opc, st);
+                               cldap_submit_derive ("operations",
+                                       "bind-initiated", opi, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=UnBind,cn=Operations,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_derive ("operations",
+                                       "unbind-completed", opc, st);
+                               cldap_submit_derive ("operations",
+                                       "unbind-initiated", opi, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Search,cn=Operations,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_derive ("operations",
+                                       "search-completed", opc, st);
+                               cldap_submit_derive ("operations",
+                                       "search-initiated", opi, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Compare,cn=Operations,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_derive ("operations",
+                                       "compare-completed", opc, st);
+                               cldap_submit_derive ("operations",
+                                       "compare-initiated", opi, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Modify,cn=Operations,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_derive ("operations",
+                                       "modify-completed", opc, st);
+                               cldap_submit_derive ("operations",
+                                       "modify-initiated", opi, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Modrdn,cn=Operations,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_derive ("operations",
+                                       "modrdn-completed", opc, st);
+                               cldap_submit_derive ("operations",
+                                       "modrdn-initiated", opi, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Add,cn=Operations,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_derive ("operations",
+                                       "add-completed", opc, st);
+                               cldap_submit_derive ("operations",
+                                       "add-initiated", opi, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Delete,cn=Operations,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_derive ("operations",
+                                       "delete-completed", opc, st);
+                               cldap_submit_derive ("operations",
+                                       "delete-initiated", opi, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Abandon,cn=Operations,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_derive ("operations",
+                                       "abandon-completed", opc, st);
+                               cldap_submit_derive ("operations",
+                                       "abandon-initiated", opi, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Extended,cn=Operations,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_derive ("operations",
+                                       "extended-completed", opc, st);
+                               cldap_submit_derive ("operations",
+                                       "extended-initiated", opi, st);
+                       }
+                       else if ((strncmp (dn, "cn=Database", 11) == 0)
+                               && ((nc_list = ldap_get_values_len
+                                               (st->ld, e, "namingContexts")) != NULL))
+                       {
+                               nc_data = *nc_list[0];
+                               char typeinst[DATA_MAX_NAME_LEN];
+
+                               if ((olmbdb_list = ldap_get_values_len (st->ld, e,
+                                       "olmBDBEntryCache")) != NULL)
+                               {
+                                       olmbdb_data = *olmbdb_list[0];
+                                       ssnprintf (typeinst, sizeof (typeinst),
+                                               "bdbentrycache-%s", nc_data.bv_val);
+                                       cldap_submit_gauge ("cache_size", typeinst,
+                                               atoll (olmbdb_data.bv_val), st);
+                                       ldap_value_free_len (olmbdb_list);
+                               }
+
+                               if ((olmbdb_list = ldap_get_values_len (st->ld, e,
+                                       "olmBDBDNCache")) != NULL)
+                               {
+                                       olmbdb_data = *olmbdb_list[0];
+                                       ssnprintf (typeinst, sizeof (typeinst),
+                                               "bdbdncache-%s", nc_data.bv_val);
+                                       cldap_submit_gauge ("cache_size", typeinst,
+                                               atoll (olmbdb_data.bv_val), st);
+                                       ldap_value_free_len (olmbdb_list);
+                               }
+
+                               if ((olmbdb_list = ldap_get_values_len (st->ld, e,
+                                       "olmBDBIDLCache")) != NULL)
+                               {
+                                       olmbdb_data = *olmbdb_list[0];
+                                       ssnprintf (typeinst, sizeof (typeinst),
+                                               "bdbidlcache-%s", nc_data.bv_val);
+                                       cldap_submit_gauge ("cache_size", typeinst,
+                                               atoll (olmbdb_data.bv_val), st);
+                                       ldap_value_free_len (olmbdb_list);
+                               }
+
+                               ldap_value_free_len (nc_list);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Bytes,cn=Statistics,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_derive ("derive", "statistics-bytes",
+                                       counter, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=PDU,cn=Statistics,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_derive ("derive", "statistics-pdu",
+                                       counter, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Entries,cn=Statistics,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_derive ("derive", "statistics-entries",
+                                       counter, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Referrals,cn=Statistics,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_derive ("derive", "statistics-referrals",
+                                       counter, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Open,cn=Threads,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_gauge ("threads", "threads-open",
+                                       info, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Starting,cn=Threads,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_gauge ("threads", "threads-starting",
+                                       info, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Active,cn=Threads,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_gauge ("threads", "threads-active",
+                                       info, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Pending,cn=Threads,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_gauge ("threads", "threads-pending",
+                                       info, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Backload,cn=Threads,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_gauge ("threads", "threads-backload",
+                                       info, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Read,cn=Waiters,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_derive ("derive", "waiters-read",
+                                       counter, st);
+                       }
+                       else if (strcmp (dn,
+                                       "cn=Write,cn=Waiters,cn=Monitor")
+                                       == 0)
+                       {
+                               cldap_submit_derive ("derive", "waiters-write",
+                                       counter, st);
+                       }
+
+                       ldap_value_free_len (counter_list);
+                       ldap_value_free_len (opc_list);
+                       ldap_value_free_len (opi_list);
+                       ldap_value_free_len (info_list);
+               }
+
+               ldap_memfree (dn);
+       }
+
+       ldap_msgfree (result);
+       ldap_unbind_ext_s (st->ld, NULL, NULL);
+       return (0);
+} /* }}} int cldap_read_host */
+
+/* Configuration handling functions {{{
+ *
+ * <Plugin ldap>
+ *   <Instance "plugin_instance1">
+ *     URL "ldap://localhost"
+ *     ...
+ *   </Instance>
+ * </Plugin>
+ */
+
+static int cldap_config_add (oconfig_item_t *ci) /* {{{ */
+{
+       cldap_t *st;
+       int i;
+       int status;
+
+       st = malloc (sizeof (*st));
+       if (st == NULL)
+       {
+               ERROR ("openldap plugin: malloc failed.");
+               return (-1);
+       }
+       memset (st, 0, sizeof (*st));
+
+       status = cf_util_get_string (ci, &st->name);
+       if (status != 0)
+       {
+               sfree (st);
+               return (status);
+       }
+
+       st->starttls = 0;
+       st->timeout = -1;
+       st->verifyhost = 1;
+       st->version = LDAP_VERSION3;
+
+       for (i = 0; i < ci->children_num; i++)
+       {
+               oconfig_item_t *child = ci->children + i;
+
+               if (strcasecmp ("CACert", child->key) == 0)
+                       status = cf_util_get_string (child, &st->cacert);
+               else if (strcasecmp ("StartTLS", child->key) == 0)
+                       status = cf_util_get_boolean (child, &st->starttls);
+               else if (strcasecmp ("Timeout", child->key) == 0)
+                       status = cf_util_get_int (child, &st->timeout);
+               else if (strcasecmp ("URL", child->key) == 0)
+                       status = cf_util_get_string (child, &st->url);
+               else if (strcasecmp ("VerifyHost", child->key) == 0)
+                       status = cf_util_get_boolean (child, &st->verifyhost);
+               else if (strcasecmp ("Version", child->key) == 0)
+                       status = cf_util_get_int (child, &st->version);
+               else
+               {
+                       WARNING ("openldap plugin: Option `%s' not allowed here.",
+                                       child->key);
+                       status = -1;
+               }
+
+               if (status != 0)
+                       break;
+       }
+
+       /* Check if struct is complete.. */
+       if ((status == 0) && (st->url == NULL))
+       {
+               ERROR ("openldap plugin: Instance `%s': "
+                               "No URL has been configured.",
+                               st->name);
+               status = -1;
+       }
+
+       /* Check if URL is valid */
+       if ((status == 0) && (st->url != NULL))
+       {
+               LDAPURLDesc *ludpp;
+               int rc;
+
+               if ((rc = ldap_url_parse (st->url, &ludpp)) != 0)
+               {
+                       ERROR ("openldap plugin: Instance `%s': "
+                               "Invalid URL: `%s'",
+                               st->name, st->url);
+                       status = -1;
+               }
+
+               if ((status == 0) && (ludpp->lud_host != NULL))
+               {
+                       st->host = strdup (ludpp->lud_host);
+               }
+
+               ldap_free_urldesc (ludpp);
+       }
+
+       if (status == 0)
+       {
+               user_data_t ud;
+               char callback_name[3*DATA_MAX_NAME_LEN];
+
+               memset (&ud, 0, sizeof (ud));
+               ud.data = st;
+
+               memset (callback_name, 0, sizeof (callback_name));
+               ssnprintf (callback_name, sizeof (callback_name),
+                               "openldap/%s/%s",
+                               (st->host != NULL) ? st->host : hostname_g,
+                               (st->name != NULL) ? st->name : "default"),
+
+               status = plugin_register_complex_read (/* group = */ NULL,
+                               /* name      = */ callback_name,
+                               /* callback  = */ cldap_read_host,
+                               /* interval  = */ NULL,
+                               /* user_data = */ &ud);
+       }
+
+       if (status != 0)
+       {
+               cldap_free (st);
+               return (-1);
+       }
+
+       return (0);
+} /* }}} int cldap_config_add */
+
+static int cldap_config (oconfig_item_t *ci) /* {{{ */
+{
+       int i;
+       int status = 0;
+
+       for (i = 0; i < ci->children_num; i++)
+       {
+               oconfig_item_t *child = ci->children + i;
+
+               if (strcasecmp ("Instance", child->key) == 0)
+                       cldap_config_add (child);
+               else
+                       WARNING ("openldap plugin: The configuration option "
+                                       "\"%s\" is not allowed here. Did you "
+                                       "forget to add an <Instance /> block "
+                                       "around the configuration?",
+                                       child->key);
+       } /* for (ci->children) */
+
+       return (status);
+} /* }}} int cldap_config */
+
+/* }}} End of configuration handling functions */
+
+static int cldap_init (void) /* {{{ */
+{
+       /* Initialize LDAP library while still single-threaded as recommended in
+        * ldap_initialize(3) */
+       int debug_level;
+       ldap_get_option (NULL, LDAP_OPT_DEBUG_LEVEL, &debug_level);
+       return (0);
+} /* }}} int cldap_init */
+
+void module_register (void) /* {{{ */
+{
+       plugin_register_complex_config ("openldap", cldap_config);
+       plugin_register_init ("openldap", cldap_init);
+} /* }}} void module_register */
index cf8c2123e9a249fb47481c88bd25d0139fdea167..663a82d8fd9221fd6b138361efb03b340dc3666f 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;
@@ -448,6 +450,70 @@ 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)
 {
@@ -459,6 +525,8 @@ static int openvpn_read (void)
        /* call the right read function for every status entry in the list */
        for (i = 0; i < vpn_num; i++)
        {
+               int vpn_read = 0;
+
                fh = fopen (vpn_list[i]->file, "r");
                if (fh == NULL)
                {
@@ -472,23 +540,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);
@@ -545,6 +618,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 5aa96c355b2494ace34fc361c42197f0df3cb0a6..a964cce4eb58b548e2842063ef38afb6664e5e44 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>
  **/
 
@@ -41,6 +46,7 @@
 #include <perl.h>
 
 #if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
+# undef sprintf
 # pragma GCC poison sprintf
 #endif
 
index 44f0c7bcdec158b3244ec6f7b0d9212b9cd652d5..29f3a3d539f19ecefceb6d5f9c09201ef7fb8dd3 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 e7bf2aac36c41fd5d7b52cc7478791e29ccae3d7..9f0a80023324d55c00871c2299a22aa484978f74 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 c70096c76a76037fec1a7f70a9e70d47e215ec58..d669aa937d4b15f187e7d3c69edd4f2d341b25f9 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>
diff --git a/src/plugin.c b/src/plugin.c
deleted file mode 100644 (file)
index 5d31e46..0000000
+++ /dev/null
@@ -1,2525 +0,0 @@
-/**
- * collectd - src/plugin.c
- * Copyright (C) 2005-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.
- *
- * 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
- *
- * Authors:
- *   Florian octo Forster <octo at collectd.org>
- *   Sebastian Harl <sh at tokkee.org>
- **/
-
-#include "collectd.h"
-#include "common.h"
-#include "plugin.h"
-#include "configfile.h"
-#include "filter_chain.h"
-#include "utils_avltree.h"
-#include "utils_cache.h"
-#include "utils_complain.h"
-#include "utils_llist.h"
-#include "utils_heap.h"
-#include "utils_time.h"
-#include "utils_random.h"
-
-#if HAVE_PTHREAD_H
-# include <pthread.h>
-#endif
-
-#include <ltdl.h>
-
-/*
- * Private structures
- */
-struct callback_func_s
-{
-       void *cf_callback;
-       user_data_t cf_udata;
-       plugin_ctx_t cf_ctx;
-};
-typedef struct callback_func_s callback_func_t;
-
-#define RF_SIMPLE  0
-#define RF_COMPLEX 1
-#define RF_REMOVE  65535
-struct read_func_s
-{
-       /* `read_func_t' "inherits" from `callback_func_t'.
-        * The `rf_super' member MUST be the first one in this structure! */
-#define rf_callback rf_super.cf_callback
-#define rf_udata rf_super.cf_udata
-#define rf_ctx rf_super.cf_ctx
-       callback_func_t rf_super;
-       char rf_group[DATA_MAX_NAME_LEN];
-       char *rf_name;
-       int rf_type;
-       cdtime_t rf_interval;
-       cdtime_t rf_effective_interval;
-       cdtime_t rf_next_read;
-};
-typedef struct read_func_s read_func_t;
-
-struct write_queue_s;
-typedef struct write_queue_s write_queue_t;
-struct write_queue_s
-{
-       value_list_t *vl;
-       plugin_ctx_t ctx;
-       write_queue_t *next;
-};
-
-/*
- * Private variables
- */
-static c_avl_tree_t *plugins_loaded = NULL;
-
-static llist_t *list_init;
-static llist_t *list_write;
-static llist_t *list_flush;
-static llist_t *list_missing;
-static llist_t *list_shutdown;
-static llist_t *list_log;
-static llist_t *list_notification;
-
-static fc_chain_t *pre_cache_chain = NULL;
-static fc_chain_t *post_cache_chain = NULL;
-
-static c_avl_tree_t *data_sets;
-
-static char *plugindir = NULL;
-
-static c_heap_t       *read_heap = NULL;
-static llist_t        *read_list;
-static int             read_loop = 1;
-static pthread_mutex_t read_lock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t  read_cond = PTHREAD_COND_INITIALIZER;
-static pthread_t      *read_threads = NULL;
-static int             read_threads_num = 0;
-
-static write_queue_t  *write_queue_head;
-static write_queue_t  *write_queue_tail;
-static long            write_queue_length = 0;
-static _Bool           write_loop = 1;
-static pthread_mutex_t write_lock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t  write_cond = PTHREAD_COND_INITIALIZER;
-static pthread_t      *write_threads = NULL;
-static size_t          write_threads_num = 0;
-
-static pthread_key_t   plugin_ctx_key;
-static _Bool           plugin_ctx_key_initialized = 0;
-
-static long            write_limit_high = 0;
-static long            write_limit_low = 0;
-
-/*
- * Static functions
- */
-static int plugin_dispatch_values_internal (value_list_t *vl);
-
-static const char *plugin_get_dir (void)
-{
-       if (plugindir == NULL)
-               return (PLUGINDIR);
-       else
-               return (plugindir);
-}
-
-static void destroy_callback (callback_func_t *cf) /* {{{ */
-{
-       if (cf == NULL)
-               return;
-
-       if ((cf->cf_udata.data != NULL) && (cf->cf_udata.free_func != NULL))
-       {
-               cf->cf_udata.free_func (cf->cf_udata.data);
-               cf->cf_udata.data = NULL;
-               cf->cf_udata.free_func = NULL;
-       }
-       sfree (cf);
-} /* }}} void destroy_callback */
-
-static void destroy_all_callbacks (llist_t **list) /* {{{ */
-{
-       llentry_t *le;
-
-       if (*list == NULL)
-               return;
-
-       le = llist_head (*list);
-       while (le != NULL)
-       {
-               llentry_t *le_next;
-
-               le_next = le->next;
-
-               sfree (le->key);
-               destroy_callback (le->value);
-               le->value = NULL;
-
-               le = le_next;
-       }
-
-       llist_destroy (*list);
-       *list = NULL;
-} /* }}} void destroy_all_callbacks */
-
-static void destroy_read_heap (void) /* {{{ */
-{
-       if (read_heap == NULL)
-               return;
-
-       while (42)
-       {
-               callback_func_t *cf;
-
-               cf = c_heap_get_root (read_heap);
-               if (cf == NULL)
-                       break;
-
-               destroy_callback (cf);
-       }
-
-       c_heap_destroy (read_heap);
-       read_heap = NULL;
-} /* }}} void destroy_read_heap */
-
-static int register_callback (llist_t **list, /* {{{ */
-               const char *name, callback_func_t *cf)
-{
-       llentry_t *le;
-       char *key;
-
-       if (*list == NULL)
-       {
-               *list = llist_create ();
-               if (*list == NULL)
-               {
-                       ERROR ("plugin: register_callback: "
-                                       "llist_create failed.");
-                       destroy_callback (cf);
-                       return (-1);
-               }
-       }
-
-       key = strdup (name);
-       if (key == NULL)
-       {
-               ERROR ("plugin: register_callback: strdup failed.");
-               destroy_callback (cf);
-               return (-1);
-       }
-
-       le = llist_search (*list, name);
-       if (le == NULL)
-       {
-               le = llentry_create (key, cf);
-               if (le == NULL)
-               {
-                       ERROR ("plugin: register_callback: "
-                                       "llentry_create failed.");
-                       free (key);
-                       destroy_callback (cf);
-                       return (-1);
-               }
-
-               llist_append (*list, le);
-       }
-       else
-       {
-               callback_func_t *old_cf;
-
-               old_cf = le->value;
-               le->value = cf;
-
-               WARNING ("plugin: register_callback: "
-                               "a callback named `%s' already exists - "
-                               "overwriting the old entry!", name);
-
-               destroy_callback (old_cf);
-               sfree (key);
-       }
-
-       return (0);
-} /* }}} int register_callback */
-
-static int create_register_callback (llist_t **list, /* {{{ */
-               const char *name, void *callback, user_data_t *ud)
-{
-       callback_func_t *cf;
-
-       cf = (callback_func_t *) malloc (sizeof (*cf));
-       if (cf == NULL)
-       {
-               ERROR ("plugin: create_register_callback: malloc failed.");
-               return (-1);
-       }
-       memset (cf, 0, sizeof (*cf));
-
-       cf->cf_callback = callback;
-       if (ud == NULL)
-       {
-               cf->cf_udata.data = NULL;
-               cf->cf_udata.free_func = NULL;
-       }
-       else
-       {
-               cf->cf_udata = *ud;
-       }
-
-       cf->cf_ctx = plugin_get_ctx ();
-
-       return (register_callback (list, name, cf));
-} /* }}} int create_register_callback */
-
-static int plugin_unregister (llist_t *list, const char *name) /* {{{ */
-{
-       llentry_t *e;
-
-       if (list == NULL)
-               return (-1);
-
-       e = llist_search (list, name);
-       if (e == NULL)
-               return (-1);
-
-       llist_remove (list, e);
-
-       sfree (e->key);
-       destroy_callback (e->value);
-
-       llentry_destroy (e);
-
-       return (0);
-} /* }}} int plugin_unregister */
-
-/*
- * (Try to) load the shared object `file'. Won't complain if it isn't a shared
- * object, but it will bitch about a shared object not having a
- * ``module_register'' symbol..
- */
-static int plugin_load_file (char *file, uint32_t flags)
-{
-       lt_dlhandle dlh;
-       void (*reg_handle) (void);
-
-       lt_dlinit ();
-       lt_dlerror (); /* clear errors */
-
-#if LIBTOOL_VERSION == 2
-       if (flags & PLUGIN_FLAGS_GLOBAL) {
-               lt_dladvise advise;
-               lt_dladvise_init(&advise);
-               lt_dladvise_global(&advise);
-               dlh = lt_dlopenadvise(file, advise);
-               lt_dladvise_destroy(&advise);
-       } else {
-               dlh = lt_dlopen (file);
-       }
-#else /* if LIBTOOL_VERSION == 1 */
-       if (flags & PLUGIN_FLAGS_GLOBAL)
-               WARNING ("plugin_load_file: The global flag is not supported, "
-                               "libtool 2 is required for this.");
-       dlh = lt_dlopen (file);
-#endif
-
-       if (dlh == NULL)
-       {
-               char errbuf[1024] = "";
-
-               ssnprintf (errbuf, sizeof (errbuf),
-                               "lt_dlopen (\"%s\") failed: %s. "
-                               "The most common cause for this problem is "
-                               "missing dependencies. Use ldd(1) to check "
-                               "the dependencies of the plugin "
-                               "/ shared object.",
-                               file, lt_dlerror ());
-
-               ERROR ("%s", errbuf);
-               /* Make sure this is printed to STDERR in any case, but also
-                * make sure it's printed only once. */
-               if (list_log != NULL)
-                       fprintf (stderr, "ERROR: %s\n", errbuf);
-
-               return (1);
-       }
-
-       if ((reg_handle = (void (*) (void)) lt_dlsym (dlh, "module_register")) == NULL)
-       {
-               WARNING ("Couldn't find symbol \"module_register\" in \"%s\": %s\n",
-                               file, lt_dlerror ());
-               lt_dlclose (dlh);
-               return (-1);
-       }
-
-       (*reg_handle) ();
-
-       return (0);
-}
-
-static void *plugin_read_thread (void __attribute__((unused)) *args)
-{
-       while (read_loop != 0)
-       {
-               read_func_t *rf;
-               plugin_ctx_t old_ctx;
-               cdtime_t now;
-               int status;
-               int rf_type;
-               int rc;
-
-               /* Get the read function that needs to be read next.
-                * We don't need to hold "read_lock" for the heap, but we need
-                * to call c_heap_get_root() and pthread_cond_wait() in the
-                * same protected block. */
-               pthread_mutex_lock (&read_lock);
-               rf = c_heap_get_root (read_heap);
-               if (rf == NULL)
-               {
-                       pthread_cond_wait (&read_cond, &read_lock);
-                        pthread_mutex_unlock (&read_lock);
-                       continue;
-               }
-               pthread_mutex_unlock (&read_lock);
-
-               if (rf->rf_interval == 0)
-               {
-                       /* this should not happen, because the interval is set
-                        * for each plugin when loading it
-                        * XXX: issue a warning? */
-                       rf->rf_interval = plugin_get_interval ();
-                       rf->rf_effective_interval = rf->rf_interval;
-
-                       rf->rf_next_read = cdtime ();
-               }
-
-               /* sleep until this entry is due,
-                * using pthread_cond_timedwait */
-               pthread_mutex_lock (&read_lock);
-               /* In pthread_cond_timedwait, spurious wakeups are possible
-                * (and really happen, at least on NetBSD with > 1 CPU), thus
-                * we need to re-evaluate the condition every time
-                * pthread_cond_timedwait returns. */
-               rc = 0;
-               while ((read_loop != 0)
-                               && (cdtime () < rf->rf_next_read)
-                               && rc == 0)
-               {
-                       struct timespec ts = { 0 };
-
-                       CDTIME_T_TO_TIMESPEC (rf->rf_next_read, &ts);
-
-                       rc = pthread_cond_timedwait (&read_cond, &read_lock,
-                               &ts);
-               }
-
-               /* Must hold `read_lock' when accessing `rf->rf_type'. */
-               rf_type = rf->rf_type;
-               pthread_mutex_unlock (&read_lock);
-
-               /* Check if we're supposed to stop.. This may have interrupted
-                * the sleep, too. */
-               if (read_loop == 0)
-               {
-                       /* Insert `rf' again, so it can be free'd correctly */
-                       c_heap_insert (read_heap, rf);
-                       break;
-               }
-
-               /* The entry has been marked for deletion. The linked list
-                * entry has already been removed by `plugin_unregister_read'.
-                * All we have to do here is free the `read_func_t' and
-                * continue. */
-               if (rf_type == RF_REMOVE)
-               {
-                       DEBUG ("plugin_read_thread: Destroying the `%s' "
-                                       "callback.", rf->rf_name);
-                       sfree (rf->rf_name);
-                       destroy_callback ((callback_func_t *) rf);
-                       rf = NULL;
-                       continue;
-               }
-
-               DEBUG ("plugin_read_thread: Handling `%s'.", rf->rf_name);
-
-               old_ctx = plugin_set_ctx (rf->rf_ctx);
-
-               if (rf_type == RF_SIMPLE)
-               {
-                       int (*callback) (void);
-
-                       callback = rf->rf_callback;
-                       status = (*callback) ();
-               }
-               else
-               {
-                       plugin_read_cb callback;
-
-                       assert (rf_type == RF_COMPLEX);
-
-                       callback = rf->rf_callback;
-                       status = (*callback) (&rf->rf_udata);
-               }
-
-               plugin_set_ctx (old_ctx);
-
-               /* If the function signals failure, we will increase the
-                * intervals in which it will be called. */
-               if (status != 0)
-               {
-                       rf->rf_effective_interval *= 2;
-                       if (rf->rf_effective_interval > TIME_T_TO_CDTIME_T (86400))
-                               rf->rf_effective_interval = TIME_T_TO_CDTIME_T (86400);
-
-                       NOTICE ("read-function of plugin `%s' failed. "
-                                       "Will suspend it for %.3f seconds.",
-                                       rf->rf_name,
-                                       CDTIME_T_TO_DOUBLE (rf->rf_effective_interval));
-               }
-               else
-               {
-                       /* Success: Restore the interval, if it was changed. */
-                       rf->rf_effective_interval = rf->rf_interval;
-               }
-
-               /* update the ``next read due'' field */
-               now = cdtime ();
-
-               DEBUG ("plugin_read_thread: Effective interval of the "
-                               "%s plugin is %.3f seconds.",
-                               rf->rf_name,
-                               CDTIME_T_TO_DOUBLE (rf->rf_effective_interval));
-
-               /* Calculate the next (absolute) time at which this function
-                * should be called. */
-               rf->rf_next_read += rf->rf_effective_interval;
-
-               /* Check, if `rf_next_read' is in the past. */
-               if (rf->rf_next_read < now)
-               {
-                       /* `rf_next_read' is in the past. Insert `now'
-                        * so this value doesn't trail off into the
-                        * past too much. */
-                       rf->rf_next_read = now;
-               }
-
-               DEBUG ("plugin_read_thread: Next read of the %s plugin at %.3f.",
-                               rf->rf_name,
-                               CDTIME_T_TO_DOUBLE (rf->rf_next_read));
-
-               /* Re-insert this read function into the heap again. */
-               c_heap_insert (read_heap, rf);
-       } /* while (read_loop) */
-
-       pthread_exit (NULL);
-       return ((void *) 0);
-} /* void *plugin_read_thread */
-
-static void start_read_threads (int num)
-{
-       int i;
-
-       if (read_threads != NULL)
-               return;
-
-       read_threads = (pthread_t *) calloc (num, sizeof (pthread_t));
-       if (read_threads == NULL)
-       {
-               ERROR ("plugin: start_read_threads: calloc failed.");
-               return;
-       }
-
-       read_threads_num = 0;
-       for (i = 0; i < num; i++)
-       {
-               if (pthread_create (read_threads + read_threads_num, NULL,
-                                       plugin_read_thread, NULL) == 0)
-               {
-                       read_threads_num++;
-               }
-               else
-               {
-                       ERROR ("plugin: start_read_threads: pthread_create failed.");
-                       return;
-               }
-       } /* for (i) */
-} /* void start_read_threads */
-
-static void stop_read_threads (void)
-{
-       int i;
-
-       if (read_threads == NULL)
-               return;
-
-       INFO ("collectd: Stopping %i read threads.", read_threads_num);
-
-       pthread_mutex_lock (&read_lock);
-       read_loop = 0;
-       DEBUG ("plugin: stop_read_threads: Signalling `read_cond'");
-       pthread_cond_broadcast (&read_cond);
-       pthread_mutex_unlock (&read_lock);
-
-       for (i = 0; i < read_threads_num; i++)
-       {
-               if (pthread_join (read_threads[i], NULL) != 0)
-               {
-                       ERROR ("plugin: stop_read_threads: pthread_join failed.");
-               }
-               read_threads[i] = (pthread_t) 0;
-       }
-       sfree (read_threads);
-       read_threads_num = 0;
-} /* void stop_read_threads */
-
-static void plugin_value_list_free (value_list_t *vl) /* {{{ */
-{
-       if (vl == NULL)
-               return;
-
-       meta_data_destroy (vl->meta);
-       sfree (vl->values);
-       sfree (vl);
-} /* }}} void plugin_value_list_free */
-
-static value_list_t *plugin_value_list_clone (value_list_t const *vl_orig) /* {{{ */
-{
-       value_list_t *vl;
-
-       if (vl_orig == NULL)
-               return (NULL);
-
-       vl = malloc (sizeof (*vl));
-       if (vl == NULL)
-               return (NULL);
-       memcpy (vl, vl_orig, sizeof (*vl));
-
-       vl->values = calloc (vl_orig->values_len, sizeof (*vl->values));
-       if (vl->values == NULL)
-       {
-               plugin_value_list_free (vl);
-               return (NULL);
-       }
-       memcpy (vl->values, vl_orig->values,
-                       vl_orig->values_len * sizeof (*vl->values));
-
-       vl->meta = meta_data_clone (vl->meta);
-       if ((vl_orig->meta != NULL) && (vl->meta == NULL))
-       {
-               plugin_value_list_free (vl);
-               return (NULL);
-       }
-
-       if (vl->time == 0)
-               vl->time = cdtime ();
-
-       /* Fill in the interval from the thread context, if it is zero. */
-       if (vl->interval == 0)
-       {
-               plugin_ctx_t ctx = plugin_get_ctx ();
-
-               if (ctx.interval != 0)
-                       vl->interval = ctx.interval;
-               else
-               {
-                       char name[6 * DATA_MAX_NAME_LEN];
-                       FORMAT_VL (name, sizeof (name), vl);
-                       ERROR ("plugin_value_list_clone: Unable to determine "
-                                       "interval from context for "
-                                       "value list \"%s\". "
-                                       "This indicates a broken plugin. "
-                                       "Please report this problem to the "
-                                       "collectd mailing list or at "
-                                       "<http://collectd.org/bugs/>.", name);
-                       vl->interval = cf_get_default_interval ();
-               }
-       }
-
-       return (vl);
-} /* }}} value_list_t *plugin_value_list_clone */
-
-static int plugin_write_enqueue (value_list_t const *vl) /* {{{ */
-{
-       write_queue_t *q;
-
-       q = malloc (sizeof (*q));
-       if (q == NULL)
-               return (ENOMEM);
-       q->next = NULL;
-
-       q->vl = plugin_value_list_clone (vl);
-       if (q->vl == NULL)
-       {
-               sfree (q);
-               return (ENOMEM);
-       }
-
-       /* Store context of caller (read plugin); otherwise, it would not be
-        * available to the write plugins when actually dispatching the
-        * value-list later on. */
-       q->ctx = plugin_get_ctx ();
-
-       pthread_mutex_lock (&write_lock);
-
-       if (write_queue_tail == NULL)
-       {
-               write_queue_head = q;
-               write_queue_tail = q;
-               write_queue_length = 1;
-       }
-       else
-       {
-               write_queue_tail->next = q;
-               write_queue_tail = q;
-               write_queue_length += 1;
-       }
-
-       pthread_cond_signal (&write_cond);
-       pthread_mutex_unlock (&write_lock);
-
-       return (0);
-} /* }}} int plugin_write_enqueue */
-
-static value_list_t *plugin_write_dequeue (void) /* {{{ */
-{
-       write_queue_t *q;
-       value_list_t *vl;
-
-       pthread_mutex_lock (&write_lock);
-
-       while (write_loop && (write_queue_head == NULL))
-               pthread_cond_wait (&write_cond, &write_lock);
-
-       if (write_queue_head == NULL)
-       {
-               pthread_mutex_unlock (&write_lock);
-               return (NULL);
-       }
-
-       q = write_queue_head;
-       write_queue_head = q->next;
-       write_queue_length -= 1;
-       if (write_queue_head == NULL) {
-               write_queue_tail = NULL;
-               assert(0 == write_queue_length);
-               }
-
-       pthread_mutex_unlock (&write_lock);
-
-       (void) plugin_set_ctx (q->ctx);
-
-       vl = q->vl;
-       sfree (q);
-       return (vl);
-} /* }}} value_list_t *plugin_write_dequeue */
-
-static void *plugin_write_thread (void __attribute__((unused)) *args) /* {{{ */
-{
-       while (write_loop)
-       {
-               value_list_t *vl = plugin_write_dequeue ();
-               if (vl == NULL)
-                       continue;
-
-               plugin_dispatch_values_internal (vl);
-
-               plugin_value_list_free (vl);
-       }
-
-       pthread_exit (NULL);
-       return ((void *) 0);
-} /* }}} void *plugin_write_thread */
-
-static void start_write_threads (size_t num) /* {{{ */
-{
-       size_t i;
-
-       if (write_threads != NULL)
-               return;
-
-       write_threads = (pthread_t *) calloc (num, sizeof (pthread_t));
-       if (write_threads == NULL)
-       {
-               ERROR ("plugin: start_write_threads: calloc failed.");
-               return;
-       }
-
-       write_threads_num = 0;
-       for (i = 0; i < num; i++)
-       {
-               int status;
-
-               status = pthread_create (write_threads + write_threads_num,
-                               /* attr = */ NULL,
-                               plugin_write_thread,
-                               /* arg = */ NULL);
-               if (status != 0)
-               {
-                       char errbuf[1024];
-                       ERROR ("plugin: start_write_threads: pthread_create failed "
-                                       "with status %i (%s).", status,
-                                       sstrerror (status, errbuf, sizeof (errbuf)));
-                       return;
-               }
-
-               write_threads_num++;
-       } /* for (i) */
-} /* }}} void start_write_threads */
-
-static void stop_write_threads (void) /* {{{ */
-{
-       write_queue_t *q;
-       int i;
-
-       if (write_threads == NULL)
-               return;
-
-       INFO ("collectd: Stopping %zu write threads.", write_threads_num);
-
-       pthread_mutex_lock (&write_lock);
-       write_loop = 0;
-       DEBUG ("plugin: stop_write_threads: Signalling `write_cond'");
-       pthread_cond_broadcast (&write_cond);
-       pthread_mutex_unlock (&write_lock);
-
-       for (i = 0; i < write_threads_num; i++)
-       {
-               if (pthread_join (write_threads[i], NULL) != 0)
-               {
-                       ERROR ("plugin: stop_write_threads: pthread_join failed.");
-               }
-               write_threads[i] = (pthread_t) 0;
-       }
-       sfree (write_threads);
-       write_threads_num = 0;
-
-       pthread_mutex_lock (&write_lock);
-       i = 0;
-       for (q = write_queue_head; q != NULL; )
-       {
-               write_queue_t *q1 = q;
-               plugin_value_list_free (q->vl);
-               q = q->next;
-               sfree (q1);
-               i++;
-       }
-       write_queue_head = NULL;
-       write_queue_tail = NULL;
-       write_queue_length = 0;
-       pthread_mutex_unlock (&write_lock);
-
-       if (i > 0)
-       {
-               WARNING ("plugin: %i value list%s left after shutting down "
-                               "the write threads.",
-                               i, (i == 1) ? " was" : "s were");
-       }
-} /* }}} void stop_write_threads */
-
-/*
- * Public functions
- */
-void plugin_set_dir (const char *dir)
-{
-       if (plugindir != NULL)
-               free (plugindir);
-
-       if (dir == NULL)
-               plugindir = NULL;
-       else if ((plugindir = strdup (dir)) == NULL)
-       {
-               char errbuf[1024];
-               ERROR ("strdup failed: %s",
-                               sstrerror (errno, errbuf, sizeof (errbuf)));
-       }
-}
-
-static _Bool plugin_is_loaded (char const *name)
-{
-       int status;
-
-       if (plugins_loaded == NULL)
-               plugins_loaded = c_avl_create ((void *) strcasecmp);
-       assert (plugins_loaded != NULL);
-
-       status = c_avl_get (plugins_loaded, name, /* ret_value = */ NULL);
-       return (status == 0);
-}
-
-static int plugin_mark_loaded (char const *name)
-{
-       char *name_copy;
-       int status;
-
-       name_copy = strdup (name);
-       if (name_copy == NULL)
-               return (ENOMEM);
-
-       status = c_avl_insert (plugins_loaded,
-                       /* key = */ name_copy, /* value = */ NULL);
-       return (status);
-}
-
-static void plugin_free_loaded ()
-{
-       void *key;
-       void *value;
-
-       if (plugins_loaded == NULL)
-               return;
-
-       while (c_avl_pick (plugins_loaded, &key, &value) == 0)
-       {
-               sfree (key);
-               assert (value == NULL);
-       }
-
-       c_avl_destroy (plugins_loaded);
-       plugins_loaded = NULL;
-}
-
-#define BUFSIZE 512
-int plugin_load (char const *plugin_name, uint32_t flags)
-{
-       DIR  *dh;
-       const char *dir;
-       char  filename[BUFSIZE] = "";
-       char  typename[BUFSIZE];
-       int   ret;
-       struct stat    statbuf;
-       struct dirent *de;
-       int status;
-
-       if (plugin_name == NULL)
-               return (EINVAL);
-
-       /* Check if plugin is already loaded and don't do anything in this
-        * case. */
-       if (plugin_is_loaded (plugin_name))
-               return (0);
-
-       dir = plugin_get_dir ();
-       ret = 1;
-
-       /*
-        * XXX: Magic at work:
-        *
-        * Some of the language bindings, for example the Python and Perl
-        * plugins, need to be able to export symbols to the scripts they run.
-        * For this to happen, the "Globals" flag needs to be set.
-        * Unfortunately, this technical detail is hard to explain to the
-        * average user and she shouldn't have to worry about this, ideally.
-        * So in order to save everyone's sanity use a different default for a
-        * handful of special plugins. --octo
-        */
-       if ((strcasecmp ("perl", plugin_name) == 0)
-                       || (strcasecmp ("python", plugin_name) == 0))
-               flags |= PLUGIN_FLAGS_GLOBAL;
-
-       /* `cpu' should not match `cpufreq'. To solve this we add `.so' to the
-        * type when matching the filename */
-       status = ssnprintf (typename, sizeof (typename), "%s.so", plugin_name);
-       if ((status < 0) || ((size_t) status >= sizeof (typename)))
-       {
-               WARNING ("plugin_load: Filename too long: \"%s.so\"", plugin_name);
-               return (-1);
-       }
-
-       if ((dh = opendir (dir)) == NULL)
-       {
-               char errbuf[1024];
-               ERROR ("plugin_load: opendir (%s) failed: %s", dir,
-                               sstrerror (errno, errbuf, sizeof (errbuf)));
-               return (-1);
-       }
-
-       while ((de = readdir (dh)) != NULL)
-       {
-               if (strcasecmp (de->d_name, typename))
-                       continue;
-
-               status = ssnprintf (filename, sizeof (filename),
-                               "%s/%s", dir, de->d_name);
-               if ((status < 0) || ((size_t) status >= sizeof (filename)))
-               {
-                       WARNING ("plugin_load: Filename too long: \"%s/%s\"",
-                                       dir, de->d_name);
-                       continue;
-               }
-
-               if (lstat (filename, &statbuf) == -1)
-               {
-                       char errbuf[1024];
-                       WARNING ("plugin_load: stat (\"%s\") failed: %s",
-                                       filename,
-                                       sstrerror (errno, errbuf, sizeof (errbuf)));
-                       continue;
-               }
-               else if (!S_ISREG (statbuf.st_mode))
-               {
-                       /* don't follow symlinks */
-                       WARNING ("plugin_load: %s is not a regular file.",
-                                       filename);
-                       continue;
-               }
-
-               status = plugin_load_file (filename, flags);
-               if (status == 0)
-               {
-                       /* success */
-                       plugin_mark_loaded (plugin_name);
-                       ret = 0;
-                       break;
-               }
-               else
-               {
-                       ERROR ("plugin_load: Load plugin \"%s\" failed with "
-                                       "status %i.", plugin_name, status);
-               }
-       }
-
-       closedir (dh);
-
-       if (filename[0] == 0)
-               ERROR ("plugin_load: Could not find plugin \"%s\" in %s",
-                               plugin_name, dir);
-
-       return (ret);
-}
-
-/*
- * The `register_*' functions follow
- */
-int plugin_register_config (const char *name,
-               int (*callback) (const char *key, const char *val),
-               const char **keys, int keys_num)
-{
-       cf_register (name, callback, keys, keys_num);
-       return (0);
-} /* int plugin_register_config */
-
-int plugin_register_complex_config (const char *type,
-               int (*callback) (oconfig_item_t *))
-{
-       return (cf_register_complex (type, callback));
-} /* int plugin_register_complex_config */
-
-int plugin_register_init (const char *name,
-               int (*callback) (void))
-{
-       return (create_register_callback (&list_init, name, (void *) callback,
-                               /* user_data = */ NULL));
-} /* plugin_register_init */
-
-static int plugin_compare_read_func (const void *arg0, const void *arg1)
-{
-       const read_func_t *rf0;
-       const read_func_t *rf1;
-
-       rf0 = arg0;
-       rf1 = arg1;
-
-       if (rf0->rf_next_read < rf1->rf_next_read)
-               return (-1);
-       else if (rf0->rf_next_read > rf1->rf_next_read)
-               return (1);
-       else
-               return (0);
-} /* int plugin_compare_read_func */
-
-/* Add a read function to both, the heap and a linked list. The linked list if
- * used to look-up read functions, especially for the remove function. The heap
- * is used to determine which plugin to read next. */
-static int plugin_insert_read (read_func_t *rf)
-{
-       int status;
-       llentry_t *le;
-
-       rf->rf_next_read = cdtime ();
-       rf->rf_effective_interval = rf->rf_interval;
-
-       pthread_mutex_lock (&read_lock);
-
-       if (read_list == NULL)
-       {
-               read_list = llist_create ();
-               if (read_list == NULL)
-               {
-                       pthread_mutex_unlock (&read_lock);
-                       ERROR ("plugin_insert_read: read_list failed.");
-                       return (-1);
-               }
-       }
-
-       if (read_heap == NULL)
-       {
-               read_heap = c_heap_create (plugin_compare_read_func);
-               if (read_heap == NULL)
-               {
-                       pthread_mutex_unlock (&read_lock);
-                       ERROR ("plugin_insert_read: c_heap_create failed.");
-                       return (-1);
-               }
-       }
-
-       le = llist_search (read_list, rf->rf_name);
-       if (le != NULL)
-       {
-               pthread_mutex_unlock (&read_lock);
-               WARNING ("The read function \"%s\" is already registered. "
-                               "Check for duplicate \"LoadPlugin\" lines "
-                               "in your configuration!",
-                               rf->rf_name);
-               return (EINVAL);
-       }
-
-       le = llentry_create (rf->rf_name, rf);
-       if (le == NULL)
-       {
-               pthread_mutex_unlock (&read_lock);
-               ERROR ("plugin_insert_read: llentry_create failed.");
-               return (-1);
-       }
-
-       status = c_heap_insert (read_heap, rf);
-       if (status != 0)
-       {
-               pthread_mutex_unlock (&read_lock);
-               ERROR ("plugin_insert_read: c_heap_insert failed.");
-               llentry_destroy (le);
-               return (-1);
-       }
-
-       /* This does not fail. */
-       llist_append (read_list, le);
-
-       /* Wake up all the read threads. */
-       pthread_cond_broadcast (&read_cond);
-       pthread_mutex_unlock (&read_lock);
-       return (0);
-} /* int plugin_insert_read */
-
-int plugin_register_read (const char *name,
-               int (*callback) (void))
-{
-       read_func_t *rf;
-       int status;
-
-       rf = malloc (sizeof (*rf));
-       if (rf == NULL)
-       {
-               ERROR ("plugin_register_read: malloc failed.");
-               return (ENOMEM);
-       }
-
-       memset (rf, 0, sizeof (read_func_t));
-       rf->rf_callback = (void *) callback;
-       rf->rf_udata.data = NULL;
-       rf->rf_udata.free_func = NULL;
-       rf->rf_ctx = plugin_get_ctx ();
-       rf->rf_group[0] = '\0';
-       rf->rf_name = strdup (name);
-       rf->rf_type = RF_SIMPLE;
-       rf->rf_interval = plugin_get_interval ();
-
-       status = plugin_insert_read (rf);
-       if (status != 0) {
-               sfree (rf->rf_name);
-               sfree (rf);
-       }
-
-       return (status);
-} /* int plugin_register_read */
-
-int plugin_register_complex_read (const char *group, const char *name,
-               plugin_read_cb callback,
-               const struct timespec *interval,
-               user_data_t *user_data)
-{
-       read_func_t *rf;
-       int status;
-
-       rf = malloc (sizeof (*rf));
-       if (rf == NULL)
-       {
-               ERROR ("plugin_register_complex_read: malloc failed.");
-               return (ENOMEM);
-       }
-
-       memset (rf, 0, sizeof (read_func_t));
-       rf->rf_callback = (void *) callback;
-       if (group != NULL)
-               sstrncpy (rf->rf_group, group, sizeof (rf->rf_group));
-       else
-               rf->rf_group[0] = '\0';
-       rf->rf_name = strdup (name);
-       rf->rf_type = RF_COMPLEX;
-       if (interval != NULL)
-               rf->rf_interval = TIMESPEC_TO_CDTIME_T (interval);
-       else
-               rf->rf_interval = plugin_get_interval ();
-
-       /* Set user data */
-       if (user_data == NULL)
-       {
-               rf->rf_udata.data = NULL;
-               rf->rf_udata.free_func = NULL;
-       }
-       else
-       {
-               rf->rf_udata = *user_data;
-       }
-
-       rf->rf_ctx = plugin_get_ctx ();
-
-       status = plugin_insert_read (rf);
-       if (status != 0) {
-               sfree (rf->rf_name);
-               sfree (rf);
-       }
-
-       return (status);
-} /* int plugin_register_complex_read */
-
-int plugin_register_write (const char *name,
-               plugin_write_cb callback, user_data_t *ud)
-{
-       return (create_register_callback (&list_write, name,
-                               (void *) callback, ud));
-} /* int plugin_register_write */
-
-int plugin_register_flush (const char *name,
-               plugin_flush_cb callback, user_data_t *ud)
-{
-       return (create_register_callback (&list_flush, name,
-                               (void *) callback, ud));
-} /* int plugin_register_flush */
-
-int plugin_register_missing (const char *name,
-               plugin_missing_cb callback, user_data_t *ud)
-{
-       return (create_register_callback (&list_missing, name,
-                               (void *) callback, ud));
-} /* int plugin_register_missing */
-
-int plugin_register_shutdown (const char *name,
-               int (*callback) (void))
-{
-       return (create_register_callback (&list_shutdown, name,
-                               (void *) callback, /* user_data = */ NULL));
-} /* int plugin_register_shutdown */
-
-static void plugin_free_data_sets (void)
-{
-       void *key;
-       void *value;
-
-       if (data_sets == NULL)
-               return;
-
-       while (c_avl_pick (data_sets, &key, &value) == 0)
-       {
-               data_set_t *ds = value;
-               /* key is a pointer to ds->type */
-
-               sfree (ds->ds);
-               sfree (ds);
-       }
-
-       c_avl_destroy (data_sets);
-       data_sets = NULL;
-} /* void plugin_free_data_sets */
-
-int plugin_register_data_set (const data_set_t *ds)
-{
-       data_set_t *ds_copy;
-       int i;
-
-       if ((data_sets != NULL)
-                       && (c_avl_get (data_sets, ds->type, NULL) == 0))
-       {
-               NOTICE ("Replacing DS `%s' with another version.", ds->type);
-               plugin_unregister_data_set (ds->type);
-       }
-       else if (data_sets == NULL)
-       {
-               data_sets = c_avl_create ((int (*) (const void *, const void *)) strcmp);
-               if (data_sets == NULL)
-                       return (-1);
-       }
-
-       ds_copy = (data_set_t *) malloc (sizeof (data_set_t));
-       if (ds_copy == NULL)
-               return (-1);
-       memcpy(ds_copy, ds, sizeof (data_set_t));
-
-       ds_copy->ds = (data_source_t *) malloc (sizeof (data_source_t)
-                       * ds->ds_num);
-       if (ds_copy->ds == NULL)
-       {
-               free (ds_copy);
-               return (-1);
-       }
-
-       for (i = 0; i < ds->ds_num; i++)
-               memcpy (ds_copy->ds + i, ds->ds + i, sizeof (data_source_t));
-
-       return (c_avl_insert (data_sets, (void *) ds_copy->type, (void *) ds_copy));
-} /* int plugin_register_data_set */
-
-int plugin_register_log (const char *name,
-               plugin_log_cb callback, user_data_t *ud)
-{
-       return (create_register_callback (&list_log, name,
-                               (void *) callback, ud));
-} /* int plugin_register_log */
-
-int plugin_register_notification (const char *name,
-               plugin_notification_cb callback, user_data_t *ud)
-{
-       return (create_register_callback (&list_notification, name,
-                               (void *) callback, ud));
-} /* int plugin_register_log */
-
-int plugin_unregister_config (const char *name)
-{
-       cf_unregister (name);
-       return (0);
-} /* int plugin_unregister_config */
-
-int plugin_unregister_complex_config (const char *name)
-{
-       cf_unregister_complex (name);
-       return (0);
-} /* int plugin_unregister_complex_config */
-
-int plugin_unregister_init (const char *name)
-{
-       return (plugin_unregister (list_init, name));
-}
-
-int plugin_unregister_read (const char *name) /* {{{ */
-{
-       llentry_t *le;
-       read_func_t *rf;
-
-       if (name == NULL)
-               return (-ENOENT);
-
-       pthread_mutex_lock (&read_lock);
-
-       if (read_list == NULL)
-       {
-               pthread_mutex_unlock (&read_lock);
-               return (-ENOENT);
-       }
-
-       le = llist_search (read_list, name);
-       if (le == NULL)
-       {
-               pthread_mutex_unlock (&read_lock);
-               WARNING ("plugin_unregister_read: No such read function: %s",
-                               name);
-               return (-ENOENT);
-       }
-
-       llist_remove (read_list, le);
-
-       rf = le->value;
-       assert (rf != NULL);
-       rf->rf_type = RF_REMOVE;
-
-       pthread_mutex_unlock (&read_lock);
-
-       llentry_destroy (le);
-
-       DEBUG ("plugin_unregister_read: Marked `%s' for removal.", name);
-
-       return (0);
-} /* }}} int plugin_unregister_read */
-
-static int compare_read_func_group (llentry_t *e, void *ud) /* {{{ */
-{
-       read_func_t *rf    = e->value;
-       char        *group = ud;
-
-       return strcmp (rf->rf_group, (const char *)group);
-} /* }}} int compare_read_func_group */
-
-int plugin_unregister_read_group (const char *group) /* {{{ */
-{
-       llentry_t *le;
-       read_func_t *rf;
-
-       int found = 0;
-
-       if (group == NULL)
-               return (-ENOENT);
-
-       pthread_mutex_lock (&read_lock);
-
-       if (read_list == NULL)
-       {
-               pthread_mutex_unlock (&read_lock);
-               return (-ENOENT);
-       }
-
-       while (42)
-       {
-               le = llist_search_custom (read_list,
-                               compare_read_func_group, (void *)group);
-
-               if (le == NULL)
-                       break;
-
-               ++found;
-
-               llist_remove (read_list, le);
-
-               rf = le->value;
-               assert (rf != NULL);
-               rf->rf_type = RF_REMOVE;
-
-               llentry_destroy (le);
-
-               DEBUG ("plugin_unregister_read_group: "
-                               "Marked `%s' (group `%s') for removal.",
-                               rf->rf_name, group);
-       }
-
-       pthread_mutex_unlock (&read_lock);
-
-       if (found == 0)
-       {
-               WARNING ("plugin_unregister_read_group: No such "
-                               "group of read function: %s", group);
-               return (-ENOENT);
-       }
-
-       return (0);
-} /* }}} int plugin_unregister_read_group */
-
-int plugin_unregister_write (const char *name)
-{
-       return (plugin_unregister (list_write, name));
-}
-
-int plugin_unregister_flush (const char *name)
-{
-       return (plugin_unregister (list_flush, name));
-}
-
-int plugin_unregister_missing (const char *name)
-{
-       return (plugin_unregister (list_missing, name));
-}
-
-int plugin_unregister_shutdown (const char *name)
-{
-       return (plugin_unregister (list_shutdown, name));
-}
-
-int plugin_unregister_data_set (const char *name)
-{
-       data_set_t *ds;
-
-       if (data_sets == NULL)
-               return (-1);
-
-       if (c_avl_remove (data_sets, name, NULL, (void *) &ds) != 0)
-               return (-1);
-
-       sfree (ds->ds);
-       sfree (ds);
-
-       return (0);
-} /* int plugin_unregister_data_set */
-
-int plugin_unregister_log (const char *name)
-{
-       return (plugin_unregister (list_log, name));
-}
-
-int plugin_unregister_notification (const char *name)
-{
-       return (plugin_unregister (list_notification, name));
-}
-
-void plugin_init_all (void)
-{
-       char const *chain_name;
-       long write_threads_num;
-       llentry_t *le;
-       int status;
-
-       /* Init the value cache */
-       uc_init ();
-
-       chain_name = global_option_get ("PreCacheChain");
-       pre_cache_chain = fc_chain_get_by_name (chain_name);
-
-       chain_name = global_option_get ("PostCacheChain");
-       post_cache_chain = fc_chain_get_by_name (chain_name);
-
-       write_limit_high = global_option_get_long ("WriteQueueLimitHigh",
-                       /* default = */ 0);
-       if (write_limit_high < 0)
-       {
-               ERROR ("WriteQueueLimitHigh must be positive or zero.");
-               write_limit_high = 0;
-       }
-
-       write_limit_low = global_option_get_long ("WriteQueueLimitLow",
-                       /* default = */ write_limit_high / 2);
-       if (write_limit_low < 0)
-       {
-               ERROR ("WriteQueueLimitLow must be positive or zero.");
-               write_limit_low = write_limit_high / 2;
-       }
-       else if (write_limit_low > write_limit_high)
-       {
-               ERROR ("WriteQueueLimitLow must not be larger than "
-                               "WriteQueueLimitHigh.");
-               write_limit_low = write_limit_high;
-       }
-
-       write_threads_num = global_option_get_long ("WriteThreads",
-                       /* default = */ 5);
-       if (write_threads_num < 1)
-       {
-               ERROR ("WriteThreads must be positive.");
-               write_threads_num = 5;
-       }
-
-       start_write_threads ((size_t) write_threads_num);
-
-       if ((list_init == NULL) && (read_heap == NULL))
-               return;
-
-       /* Calling all init callbacks before checking if read callbacks
-        * are available allows the init callbacks to register the read
-        * callback. */
-       le = llist_head (list_init);
-       while (le != NULL)
-       {
-               callback_func_t *cf;
-               plugin_init_cb callback;
-               plugin_ctx_t old_ctx;
-
-               cf = le->value;
-               old_ctx = plugin_set_ctx (cf->cf_ctx);
-               callback = cf->cf_callback;
-               status = (*callback) ();
-               plugin_set_ctx (old_ctx);
-
-               if (status != 0)
-               {
-                       ERROR ("Initialization of plugin `%s' "
-                                       "failed with status %i. "
-                                       "Plugin will be unloaded.",
-                                       le->key, status);
-                       /* Plugins that register read callbacks from the init
-                        * callback should take care of appropriate error
-                        * handling themselves. */
-                       /* FIXME: Unload _all_ functions */
-                       plugin_unregister_read (le->key);
-               }
-
-               le = le->next;
-       }
-
-       /* Start read-threads */
-       if (read_heap != NULL)
-       {
-               const char *rt;
-               int num;
-               rt = global_option_get ("ReadThreads");
-               num = atoi (rt);
-               if (num != -1)
-                       start_read_threads ((num > 0) ? num : 5);
-       }
-} /* void plugin_init_all */
-
-/* TODO: Rename this function. */
-void plugin_read_all (void)
-{
-       uc_check_timeout ();
-
-       return;
-} /* void plugin_read_all */
-
-/* Read function called when the `-T' command line argument is given. */
-int plugin_read_all_once (void)
-{
-       int status;
-       int return_status = 0;
-
-       if (read_heap == NULL)
-       {
-               NOTICE ("No read-functions are registered.");
-               return (0);
-       }
-
-       while (42)
-       {
-               read_func_t *rf;
-               plugin_ctx_t old_ctx;
-
-               rf = c_heap_get_root (read_heap);
-               if (rf == NULL)
-                       break;
-
-               old_ctx = plugin_set_ctx (rf->rf_ctx);
-
-               if (rf->rf_type == RF_SIMPLE)
-               {
-                       int (*callback) (void);
-
-                       callback = rf->rf_callback;
-                       status = (*callback) ();
-               }
-               else
-               {
-                       plugin_read_cb callback;
-
-                       callback = rf->rf_callback;
-                       status = (*callback) (&rf->rf_udata);
-               }
-
-               plugin_set_ctx (old_ctx);
-
-               if (status != 0)
-               {
-                       NOTICE ("read-function of plugin `%s' failed.",
-                                       rf->rf_name);
-                       return_status = -1;
-               }
-
-               sfree (rf->rf_name);
-               destroy_callback ((void *) rf);
-       }
-
-       return (return_status);
-} /* int plugin_read_all_once */
-
-int plugin_write (const char *plugin, /* {{{ */
-               const data_set_t *ds, const value_list_t *vl)
-{
-  llentry_t *le;
-  int status;
-
-  if (vl == NULL)
-    return (EINVAL);
-
-  if (list_write == NULL)
-    return (ENOENT);
-
-  if (ds == NULL)
-  {
-    ds = plugin_get_ds (vl->type);
-    if (ds == NULL)
-    {
-      ERROR ("plugin_write: Unable to lookup type `%s'.", vl->type);
-      return (ENOENT);
-    }
-  }
-
-  if (plugin == NULL)
-  {
-    int success = 0;
-    int failure = 0;
-
-    le = llist_head (list_write);
-    while (le != NULL)
-    {
-      callback_func_t *cf = le->value;
-      plugin_write_cb callback;
-
-      /* do not switch plugin context; rather keep the context (interval)
-       * information of the calling read plugin */
-
-      DEBUG ("plugin: plugin_write: Writing values via %s.", le->key);
-      callback = cf->cf_callback;
-      status = (*callback) (ds, vl, &cf->cf_udata);
-      if (status != 0)
-        failure++;
-      else
-        success++;
-
-      le = le->next;
-    }
-
-    if ((success == 0) && (failure != 0))
-      status = -1;
-    else
-      status = 0;
-  }
-  else /* plugin != NULL */
-  {
-    callback_func_t *cf;
-    plugin_write_cb callback;
-
-    le = llist_head (list_write);
-    while (le != NULL)
-    {
-      if (strcasecmp (plugin, le->key) == 0)
-        break;
-
-      le = le->next;
-    }
-
-    if (le == NULL)
-      return (ENOENT);
-
-    cf = le->value;
-
-    /* do not switch plugin context; rather keep the context (interval)
-     * information of the calling read plugin */
-
-    DEBUG ("plugin: plugin_write: Writing values via %s.", le->key);
-    callback = cf->cf_callback;
-    status = (*callback) (ds, vl, &cf->cf_udata);
-  }
-
-  return (status);
-} /* }}} int plugin_write */
-
-int plugin_flush (const char *plugin, cdtime_t timeout, const char *identifier)
-{
-  llentry_t *le;
-
-  if (list_flush == NULL)
-    return (0);
-
-  le = llist_head (list_flush);
-  while (le != NULL)
-  {
-    callback_func_t *cf;
-    plugin_flush_cb callback;
-    plugin_ctx_t old_ctx;
-
-    if ((plugin != NULL)
-        && (strcmp (plugin, le->key) != 0))
-    {
-      le = le->next;
-      continue;
-    }
-
-    cf = le->value;
-    old_ctx = plugin_set_ctx (cf->cf_ctx);
-    callback = cf->cf_callback;
-
-    (*callback) (timeout, identifier, &cf->cf_udata);
-
-    plugin_set_ctx (old_ctx);
-
-    le = le->next;
-  }
-  return (0);
-} /* int plugin_flush */
-
-void plugin_shutdown_all (void)
-{
-       llentry_t *le;
-
-       stop_read_threads ();
-
-       destroy_all_callbacks (&list_init);
-
-       pthread_mutex_lock (&read_lock);
-       llist_destroy (read_list);
-       read_list = NULL;
-       pthread_mutex_unlock (&read_lock);
-
-       destroy_read_heap ();
-
-       plugin_flush (/* plugin = */ NULL,
-                       /* timeout = */ 0,
-                       /* identifier = */ NULL);
-
-       le = NULL;
-       if (list_shutdown != NULL)
-               le = llist_head (list_shutdown);
-
-       while (le != NULL)
-       {
-               callback_func_t *cf;
-               plugin_shutdown_cb callback;
-               plugin_ctx_t old_ctx;
-
-               cf = le->value;
-               old_ctx = plugin_set_ctx (cf->cf_ctx);
-               callback = cf->cf_callback;
-
-               /* Advance the pointer before calling the callback allows
-                * shutdown functions to unregister themselves. If done the
-                * other way around the memory `le' points to will be freed
-                * after callback returns. */
-               le = le->next;
-
-               (*callback) ();
-
-               plugin_set_ctx (old_ctx);
-       }
-
-       stop_write_threads ();
-
-       /* Write plugins which use the `user_data' pointer usually need the
-        * same data available to the flush callback. If this is the case, set
-        * the free_function to NULL when registering the flush callback and to
-        * the real free function when registering the write callback. This way
-        * the data isn't freed twice. */
-       destroy_all_callbacks (&list_flush);
-       destroy_all_callbacks (&list_missing);
-       destroy_all_callbacks (&list_write);
-
-       destroy_all_callbacks (&list_notification);
-       destroy_all_callbacks (&list_shutdown);
-       destroy_all_callbacks (&list_log);
-
-       plugin_free_loaded ();
-       plugin_free_data_sets ();
-} /* void plugin_shutdown_all */
-
-int plugin_dispatch_missing (const value_list_t *vl) /* {{{ */
-{
-  llentry_t *le;
-
-  if (list_missing == NULL)
-    return (0);
-
-  le = llist_head (list_missing);
-  while (le != NULL)
-  {
-    callback_func_t *cf;
-    plugin_missing_cb callback;
-    plugin_ctx_t old_ctx;
-    int status;
-
-    cf = le->value;
-    old_ctx = plugin_set_ctx (cf->cf_ctx);
-    callback = cf->cf_callback;
-
-    status = (*callback) (vl, &cf->cf_udata);
-    plugin_set_ctx (old_ctx);
-    if (status != 0)
-    {
-      if (status < 0)
-      {
-        ERROR ("plugin_dispatch_missing: Callback function \"%s\" "
-            "failed with status %i.",
-            le->key, status);
-        return (status);
-      }
-      else
-      {
-        return (0);
-      }
-    }
-
-    le = le->next;
-  }
-  return (0);
-} /* int }}} plugin_dispatch_missing */
-
-static int plugin_dispatch_values_internal (value_list_t *vl)
-{
-       int status;
-       static c_complain_t no_write_complaint = C_COMPLAIN_INIT_STATIC;
-
-       value_t *saved_values;
-       int      saved_values_len;
-
-       data_set_t *ds;
-
-       int free_meta_data = 0;
-
-       if ((vl == NULL) || (vl->type[0] == 0)
-                       || (vl->values == NULL) || (vl->values_len < 1))
-       {
-               ERROR ("plugin_dispatch_values: Invalid value list "
-                               "from plugin %s.", vl->plugin);
-               return (-1);
-       }
-
-       /* Free meta data only if the calling function didn't specify any. In
-        * this case matches and targets may add some and the calling function
-        * may not expect (and therefore free) that data. */
-       if (vl->meta == NULL)
-               free_meta_data = 1;
-
-       if (list_write == NULL)
-               c_complain_once (LOG_WARNING, &no_write_complaint,
-                               "plugin_dispatch_values: No write callback has been "
-                               "registered. Please load at least one output plugin, "
-                               "if you want the collected data to be stored.");
-
-       if (data_sets == NULL)
-       {
-               ERROR ("plugin_dispatch_values: No data sets registered. "
-                               "Could the types database be read? Check "
-                               "your `TypesDB' setting!");
-               return (-1);
-       }
-
-       if (c_avl_get (data_sets, vl->type, (void *) &ds) != 0)
-       {
-               char ident[6 * DATA_MAX_NAME_LEN];
-
-               FORMAT_VL (ident, sizeof (ident), vl);
-               INFO ("plugin_dispatch_values: Dataset not found: %s "
-                               "(from \"%s\"), check your types.db!",
-                               vl->type, ident);
-               return (-1);
-       }
-
-       /* Assured by plugin_value_list_clone(). The time is determined at
-        * _enqueue_ time. */
-       assert (vl->time != 0);
-       assert (vl->interval != 0);
-
-       DEBUG ("plugin_dispatch_values: time = %.3f; interval = %.3f; "
-                       "host = %s; "
-                       "plugin = %s; plugin_instance = %s; "
-                       "type = %s; type_instance = %s;",
-                       CDTIME_T_TO_DOUBLE (vl->time),
-                       CDTIME_T_TO_DOUBLE (vl->interval),
-                       vl->host,
-                       vl->plugin, vl->plugin_instance,
-                       vl->type, vl->type_instance);
-
-#if COLLECT_DEBUG
-       assert (0 == strcmp (ds->type, vl->type));
-#else
-       if (0 != strcmp (ds->type, vl->type))
-               WARNING ("plugin_dispatch_values: (ds->type = %s) != (vl->type = %s)",
-                               ds->type, vl->type);
-#endif
-
-#if COLLECT_DEBUG
-       assert (ds->ds_num == vl->values_len);
-#else
-       if (ds->ds_num != vl->values_len)
-       {
-               ERROR ("plugin_dispatch_values: ds->type = %s: "
-                               "(ds->ds_num = %i) != "
-                               "(vl->values_len = %i)",
-                               ds->type, ds->ds_num, vl->values_len);
-               return (-1);
-       }
-#endif
-
-       escape_slashes (vl->host, sizeof (vl->host));
-       escape_slashes (vl->plugin, sizeof (vl->plugin));
-       escape_slashes (vl->plugin_instance, sizeof (vl->plugin_instance));
-       escape_slashes (vl->type, sizeof (vl->type));
-       escape_slashes (vl->type_instance, sizeof (vl->type_instance));
-
-       /* Copy the values. This way, we can assure `targets' that they get
-        * dynamically allocated values, which they can free and replace if
-        * they like. */
-       if ((pre_cache_chain != NULL) || (post_cache_chain != NULL))
-       {
-               saved_values     = vl->values;
-               saved_values_len = vl->values_len;
-
-               vl->values = (value_t *) calloc (vl->values_len,
-                               sizeof (*vl->values));
-               if (vl->values == NULL)
-               {
-                       ERROR ("plugin_dispatch_values: calloc failed.");
-                       vl->values = saved_values;
-                       return (-1);
-               }
-               memcpy (vl->values, saved_values,
-                               vl->values_len * sizeof (*vl->values));
-       }
-       else /* if ((pre == NULL) && (post == NULL)) */
-       {
-               saved_values     = NULL;
-               saved_values_len = 0;
-       }
-
-       if (pre_cache_chain != NULL)
-       {
-               status = fc_process_chain (ds, vl, pre_cache_chain);
-               if (status < 0)
-               {
-                       WARNING ("plugin_dispatch_values: Running the "
-                                       "pre-cache chain failed with "
-                                       "status %i (%#x).",
-                                       status, status);
-               }
-               else if (status == FC_TARGET_STOP)
-               {
-                       /* Restore the state of the value_list so that plugins
-                        * don't get confused.. */
-                       if (saved_values != NULL)
-                       {
-                               free (vl->values);
-                               vl->values     = saved_values;
-                               vl->values_len = saved_values_len;
-                       }
-                       return (0);
-               }
-       }
-
-       /* Update the value cache */
-       uc_update (ds, vl);
-
-       if (post_cache_chain != NULL)
-       {
-               status = fc_process_chain (ds, vl, post_cache_chain);
-               if (status < 0)
-               {
-                       WARNING ("plugin_dispatch_values: Running the "
-                                       "post-cache chain failed with "
-                                       "status %i (%#x).",
-                                       status, status);
-               }
-       }
-       else
-               fc_default_action (ds, vl);
-
-       /* Restore the state of the value_list so that plugins don't get
-        * confused.. */
-       if (saved_values != NULL)
-       {
-               free (vl->values);
-               vl->values     = saved_values;
-               vl->values_len = saved_values_len;
-       }
-
-       if ((free_meta_data != 0) && (vl->meta != NULL))
-       {
-               meta_data_destroy (vl->meta);
-               vl->meta = NULL;
-       }
-
-       return (0);
-} /* int plugin_dispatch_values_internal */
-
-static double get_drop_probability (void) /* {{{ */
-{
-       long pos;
-       long size;
-       long wql;
-
-       pthread_mutex_lock (&write_lock);
-       wql = write_queue_length;
-       pthread_mutex_unlock (&write_lock);
-
-       if (wql < write_limit_low)
-               return (0.0);
-       if (wql >= write_limit_high)
-               return (1.0);
-
-       pos = 1 + wql - write_limit_low;
-       size = 1 + write_limit_high - write_limit_low;
-
-       return (((double) pos) / ((double) size));
-} /* }}} double get_drop_probability */
-
-static _Bool check_drop_value (void) /* {{{ */
-{
-       static cdtime_t last_message_time = 0;
-       static pthread_mutex_t last_message_lock = PTHREAD_MUTEX_INITIALIZER;
-
-       double p;
-       double q;
-       int status;
-
-       if (write_limit_high == 0)
-               return (0);
-
-       p = get_drop_probability ();
-       if (p == 0.0)
-               return (0);
-
-       status = pthread_mutex_trylock (&last_message_lock);
-       if (status == 0)
-       {
-               cdtime_t now;
-
-               now = cdtime ();
-               if ((now - last_message_time) > TIME_T_TO_CDTIME_T (1))
-               {
-                       last_message_time = now;
-                       ERROR ("plugin_dispatch_values: Low water mark "
-                                       "reached. Dropping %.0f%% of metrics.",
-                                       100.0 * p);
-               }
-               pthread_mutex_unlock (&last_message_lock);
-       }
-
-       if (p == 1.0)
-               return (1);
-
-       q = cdrand_d ();
-       if (q > p)
-               return (1);
-       else
-               return (0);
-} /* }}} _Bool check_drop_value */
-
-int plugin_dispatch_values (value_list_t const *vl)
-{
-       int status;
-
-       if (check_drop_value ())
-               return (0);
-
-       status = plugin_write_enqueue (vl);
-       if (status != 0)
-       {
-               char errbuf[1024];
-               ERROR ("plugin_dispatch_values: plugin_write_enqueue failed "
-                               "with status %i (%s).", status,
-                               sstrerror (status, errbuf, sizeof (errbuf)));
-               return (status);
-       }
-
-       return (0);
-}
-
-int plugin_dispatch_notification (const notification_t *notif)
-{
-       llentry_t *le;
-       /* Possible TODO: Add flap detection here */
-
-       DEBUG ("plugin_dispatch_notification: severity = %i; message = %s; "
-                       "time = %.3f; host = %s;",
-                       notif->severity, notif->message,
-                       CDTIME_T_TO_DOUBLE (notif->time), notif->host);
-
-       /* Nobody cares for notifications */
-       if (list_notification == NULL)
-               return (-1);
-
-       le = llist_head (list_notification);
-       while (le != NULL)
-       {
-               callback_func_t *cf;
-               plugin_notification_cb callback;
-               int status;
-
-               /* do not switch plugin context; rather keep the context
-                * (interval) information of the calling plugin */
-
-               cf = le->value;
-               callback = cf->cf_callback;
-               status = (*callback) (notif, &cf->cf_udata);
-               if (status != 0)
-               {
-                       WARNING ("plugin_dispatch_notification: Notification "
-                                       "callback %s returned %i.",
-                                       le->key, status);
-               }
-
-               le = le->next;
-       }
-
-       return (0);
-} /* int plugin_dispatch_notification */
-
-void plugin_log (int level, const char *format, ...)
-{
-       char msg[1024];
-       va_list ap;
-       llentry_t *le;
-
-#if !COLLECT_DEBUG
-       if (level >= LOG_DEBUG)
-               return;
-#endif
-
-       va_start (ap, format);
-       vsnprintf (msg, sizeof (msg), format, ap);
-       msg[sizeof (msg) - 1] = '\0';
-       va_end (ap);
-
-       if (list_log == NULL)
-       {
-               fprintf (stderr, "%s\n", msg);
-               return;
-       }
-
-       le = llist_head (list_log);
-       while (le != NULL)
-       {
-               callback_func_t *cf;
-               plugin_log_cb callback;
-
-               cf = le->value;
-               callback = cf->cf_callback;
-
-               /* do not switch plugin context; rather keep the context
-                * (interval) information of the calling plugin */
-
-               (*callback) (level, msg, &cf->cf_udata);
-
-               le = le->next;
-       }
-} /* void plugin_log */
-
-int parse_log_severity (const char *severity)
-{
-       int log_level = -1;
-
-       if ((0 == strcasecmp (severity, "emerg"))
-                       || (0 == strcasecmp (severity, "alert"))
-                       || (0 == strcasecmp (severity, "crit"))
-                       || (0 == strcasecmp (severity, "err")))
-               log_level = LOG_ERR;
-       else if (0 == strcasecmp (severity, "warning"))
-               log_level = LOG_WARNING;
-       else if (0 == strcasecmp (severity, "notice"))
-               log_level = LOG_NOTICE;
-       else if (0 == strcasecmp (severity, "info"))
-               log_level = LOG_INFO;
-#if COLLECT_DEBUG
-       else if (0 == strcasecmp (severity, "debug"))
-               log_level = LOG_DEBUG;
-#endif /* COLLECT_DEBUG */
-
-       return (log_level);
-} /* int parse_log_severity */
-
-int parse_notif_severity (const char *severity)
-{
-       int notif_severity = -1;
-
-       if (strcasecmp (severity, "FAILURE") == 0)
-               notif_severity = NOTIF_FAILURE;
-       else if (strcmp (severity, "OKAY") == 0)
-               notif_severity = NOTIF_OKAY;
-       else if ((strcmp (severity, "WARNING") == 0)
-                       || (strcmp (severity, "WARN") == 0))
-               notif_severity = NOTIF_WARNING;
-
-       return (notif_severity);
-} /* int parse_notif_severity */
-
-const data_set_t *plugin_get_ds (const char *name)
-{
-       data_set_t *ds;
-
-       if (data_sets == NULL)
-       {
-               ERROR ("plugin_get_ds: No data sets are defined yet.");
-               return (NULL);
-       }
-
-       if (c_avl_get (data_sets, name, (void *) &ds) != 0)
-       {
-               DEBUG ("No such dataset registered: %s", name);
-               return (NULL);
-       }
-
-       return (ds);
-} /* data_set_t *plugin_get_ds */
-
-static int plugin_notification_meta_add (notification_t *n,
-    const char *name,
-    enum notification_meta_type_e type,
-    const void *value)
-{
-  notification_meta_t *meta;
-  notification_meta_t *tail;
-
-  if ((n == NULL) || (name == NULL) || (value == NULL))
-  {
-    ERROR ("plugin_notification_meta_add: A pointer is NULL!");
-    return (-1);
-  }
-
-  meta = (notification_meta_t *) malloc (sizeof (notification_meta_t));
-  if (meta == NULL)
-  {
-    ERROR ("plugin_notification_meta_add: malloc failed.");
-    return (-1);
-  }
-  memset (meta, 0, sizeof (notification_meta_t));
-
-  sstrncpy (meta->name, name, sizeof (meta->name));
-  meta->type = type;
-
-  switch (type)
-  {
-    case NM_TYPE_STRING:
-    {
-      meta->nm_value.nm_string = strdup ((const char *) value);
-      if (meta->nm_value.nm_string == NULL)
-      {
-        ERROR ("plugin_notification_meta_add: strdup failed.");
-        sfree (meta);
-        return (-1);
-      }
-      break;
-    }
-    case NM_TYPE_SIGNED_INT:
-    {
-      meta->nm_value.nm_signed_int = *((int64_t *) value);
-      break;
-    }
-    case NM_TYPE_UNSIGNED_INT:
-    {
-      meta->nm_value.nm_unsigned_int = *((uint64_t *) value);
-      break;
-    }
-    case NM_TYPE_DOUBLE:
-    {
-      meta->nm_value.nm_double = *((double *) value);
-      break;
-    }
-    case NM_TYPE_BOOLEAN:
-    {
-      meta->nm_value.nm_boolean = *((_Bool *) value);
-      break;
-    }
-    default:
-    {
-      ERROR ("plugin_notification_meta_add: Unknown type: %i", type);
-      sfree (meta);
-      return (-1);
-    }
-  } /* switch (type) */
-
-  meta->next = NULL;
-  tail = n->meta;
-  while ((tail != NULL) && (tail->next != NULL))
-    tail = tail->next;
-
-  if (tail == NULL)
-    n->meta = meta;
-  else
-    tail->next = meta;
-
-  return (0);
-} /* int plugin_notification_meta_add */
-
-int plugin_notification_meta_add_string (notification_t *n,
-    const char *name,
-    const char *value)
-{
-  return (plugin_notification_meta_add (n, name, NM_TYPE_STRING, value));
-}
-
-int plugin_notification_meta_add_signed_int (notification_t *n,
-    const char *name,
-    int64_t value)
-{
-  return (plugin_notification_meta_add (n, name, NM_TYPE_SIGNED_INT, &value));
-}
-
-int plugin_notification_meta_add_unsigned_int (notification_t *n,
-    const char *name,
-    uint64_t value)
-{
-  return (plugin_notification_meta_add (n, name, NM_TYPE_UNSIGNED_INT, &value));
-}
-
-int plugin_notification_meta_add_double (notification_t *n,
-    const char *name,
-    double value)
-{
-  return (plugin_notification_meta_add (n, name, NM_TYPE_DOUBLE, &value));
-}
-
-int plugin_notification_meta_add_boolean (notification_t *n,
-    const char *name,
-    _Bool value)
-{
-  return (plugin_notification_meta_add (n, name, NM_TYPE_BOOLEAN, &value));
-}
-
-int plugin_notification_meta_copy (notification_t *dst,
-    const notification_t *src)
-{
-  notification_meta_t *meta;
-
-  assert (dst != NULL);
-  assert (src != NULL);
-  assert (dst != src);
-  assert ((src->meta == NULL) || (src->meta != dst->meta));
-
-  for (meta = src->meta; meta != NULL; meta = meta->next)
-  {
-    if (meta->type == NM_TYPE_STRING)
-      plugin_notification_meta_add_string (dst, meta->name,
-          meta->nm_value.nm_string);
-    else if (meta->type == NM_TYPE_SIGNED_INT)
-      plugin_notification_meta_add_signed_int (dst, meta->name,
-          meta->nm_value.nm_signed_int);
-    else if (meta->type == NM_TYPE_UNSIGNED_INT)
-      plugin_notification_meta_add_unsigned_int (dst, meta->name,
-          meta->nm_value.nm_unsigned_int);
-    else if (meta->type == NM_TYPE_DOUBLE)
-      plugin_notification_meta_add_double (dst, meta->name,
-          meta->nm_value.nm_double);
-    else if (meta->type == NM_TYPE_BOOLEAN)
-      plugin_notification_meta_add_boolean (dst, meta->name,
-          meta->nm_value.nm_boolean);
-  }
-
-  return (0);
-} /* int plugin_notification_meta_copy */
-
-int plugin_notification_meta_free (notification_meta_t *n)
-{
-  notification_meta_t *this;
-  notification_meta_t *next;
-
-  if (n == NULL)
-  {
-    ERROR ("plugin_notification_meta_free: n == NULL!");
-    return (-1);
-  }
-
-  this = n;
-  while (this != NULL)
-  {
-    next = this->next;
-
-    if (this->type == NM_TYPE_STRING)
-    {
-      free ((char *)this->nm_value.nm_string);
-      this->nm_value.nm_string = NULL;
-    }
-    sfree (this);
-
-    this = next;
-  }
-
-  return (0);
-} /* int plugin_notification_meta_free */
-
-static void plugin_ctx_destructor (void *ctx)
-{
-       sfree (ctx);
-} /* void plugin_ctx_destructor */
-
-static plugin_ctx_t ctx_init = { /* interval = */ 0 };
-
-static plugin_ctx_t *plugin_ctx_create (void)
-{
-       plugin_ctx_t *ctx;
-
-       ctx = malloc (sizeof (*ctx));
-       if (ctx == NULL) {
-               char errbuf[1024];
-               ERROR ("Failed to allocate plugin context: %s",
-                               sstrerror (errno, errbuf, sizeof (errbuf)));
-               return NULL;
-       }
-
-       *ctx = ctx_init;
-       assert (plugin_ctx_key_initialized);
-       pthread_setspecific (plugin_ctx_key, ctx);
-       DEBUG("Created new plugin context.");
-       return (ctx);
-} /* int plugin_ctx_create */
-
-void plugin_init_ctx (void)
-{
-       pthread_key_create (&plugin_ctx_key, plugin_ctx_destructor);
-       plugin_ctx_key_initialized = 1;
-} /* void plugin_init_ctx */
-
-plugin_ctx_t plugin_get_ctx (void)
-{
-       plugin_ctx_t *ctx;
-
-       assert (plugin_ctx_key_initialized);
-       ctx = pthread_getspecific (plugin_ctx_key);
-
-       if (ctx == NULL) {
-               ctx = plugin_ctx_create ();
-               /* this must no happen -- exit() instead? */
-               if (ctx == NULL)
-                       return ctx_init;
-       }
-
-       return (*ctx);
-} /* plugin_ctx_t plugin_get_ctx */
-
-plugin_ctx_t plugin_set_ctx (plugin_ctx_t ctx)
-{
-       plugin_ctx_t *c;
-       plugin_ctx_t old;
-
-       assert (plugin_ctx_key_initialized);
-       c = pthread_getspecific (plugin_ctx_key);
-
-       if (c == NULL) {
-               c = plugin_ctx_create ();
-               /* this must no happen -- exit() instead? */
-               if (c == NULL)
-                       return ctx_init;
-       }
-
-       old = *c;
-       *c = ctx;
-
-       return (old);
-} /* void plugin_set_ctx */
-
-cdtime_t plugin_get_interval (void)
-{
-       cdtime_t interval;
-
-       interval = plugin_get_ctx().interval;
-       if (interval > 0)
-               return interval;
-
-       return cf_get_default_interval ();
-} /* cdtime_t plugin_get_interval */
-
-typedef struct {
-       plugin_ctx_t ctx;
-       void *(*start_routine) (void *);
-       void *arg;
-} plugin_thread_t;
-
-static void *plugin_thread_start (void *arg)
-{
-       plugin_thread_t *plugin_thread = arg;
-
-       void *(*start_routine) (void *) = plugin_thread->start_routine;
-       void *plugin_arg = plugin_thread->arg;
-
-       plugin_set_ctx (plugin_thread->ctx);
-
-       free (plugin_thread);
-
-       return start_routine (plugin_arg);
-} /* void *plugin_thread_start */
-
-int plugin_thread_create (pthread_t *thread, const pthread_attr_t *attr,
-               void *(*start_routine) (void *), void *arg)
-{
-       plugin_thread_t *plugin_thread;
-
-       plugin_thread = malloc (sizeof (*plugin_thread));
-       if (plugin_thread == NULL)
-               return -1;
-
-       plugin_thread->ctx           = plugin_get_ctx ();
-       plugin_thread->start_routine = start_routine;
-       plugin_thread->arg           = arg;
-
-       return pthread_create (thread, attr,
-                       plugin_thread_start, plugin_thread);
-} /* int plugin_thread_create */
-
-/* vim: set sw=8 ts=8 noet fdm=marker : */
diff --git a/src/plugin.h b/src/plugin.h
deleted file mode 100644 (file)
index 8f0c6d8..0000000
+++ /dev/null
@@ -1,402 +0,0 @@
-#ifndef PLUGIN_H
-#define PLUGIN_H
-/**
- * collectd - src/plugin.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; 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
- *
- * Authors:
- *   Florian octo Forster <octo at collectd.org>
- *   Sebastian Harl <sh at tokkee.org>
- **/
-
-#include "collectd.h"
-#include "configfile.h"
-#include "meta_data.h"
-#include "utils_time.h"
-
-#define PLUGIN_FLAGS_GLOBAL 0x0001
-
-#define DATA_MAX_NAME_LEN 64
-
-#define DS_TYPE_COUNTER  0
-#define DS_TYPE_GAUGE    1
-#define DS_TYPE_DERIVE   2
-#define DS_TYPE_ABSOLUTE 3
-
-#define DS_TYPE_TO_STRING(t) (t == DS_TYPE_COUNTER)     ? "counter"  : \
-                               (t == DS_TYPE_GAUGE)    ? "gauge"    : \
-                               (t == DS_TYPE_DERIVE)   ? "derive"   : \
-                               (t == DS_TYPE_ABSOLUTE) ? "absolute" : \
-                               "unknown"
-
-
-#ifndef LOG_ERR
-# define LOG_ERR 3
-#endif
-#ifndef LOG_WARNING
-# define LOG_WARNING 4
-#endif
-#ifndef LOG_NOTICE
-# define LOG_NOTICE 5
-#endif
-#ifndef LOG_INFO
-# define LOG_INFO 6
-#endif
-#ifndef LOG_DEBUG
-# define LOG_DEBUG 7
-#endif
-
-#define NOTIF_MAX_MSG_LEN 256
-
-#define NOTIF_FAILURE 1
-#define NOTIF_WARNING 2
-#define NOTIF_OKAY    4
-
-#define plugin_interval (plugin_get_ctx().interval)
-
-/*
- * Public data types
- */
-typedef unsigned long long counter_t;
-typedef double gauge_t;
-typedef int64_t derive_t;
-typedef uint64_t absolute_t;
-
-union value_u
-{
-       counter_t  counter;
-       gauge_t    gauge;
-       derive_t   derive;
-       absolute_t absolute;
-};
-typedef union value_u value_t;
-
-struct value_list_s
-{
-       value_t *values;
-       int      values_len;
-       cdtime_t time;
-       cdtime_t interval;
-       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];
-       meta_data_t *meta;
-};
-typedef struct value_list_s value_list_t;
-
-#define VALUE_LIST_INIT { NULL, 0, 0, plugin_get_interval (), \
-       "localhost", "", "", "", "", NULL }
-#define VALUE_LIST_STATIC { NULL, 0, 0, 0, "localhost", "", "", "", "", NULL }
-
-struct data_source_s
-{
-       char   name[DATA_MAX_NAME_LEN];
-       int    type;
-       double min;
-       double max;
-};
-typedef struct data_source_s data_source_t;
-
-struct data_set_s
-{
-       char           type[DATA_MAX_NAME_LEN];
-       int            ds_num;
-       data_source_t *ds;
-};
-typedef struct data_set_s data_set_t;
-
-enum notification_meta_type_e
-{
-       NM_TYPE_STRING,
-       NM_TYPE_SIGNED_INT,
-       NM_TYPE_UNSIGNED_INT,
-       NM_TYPE_DOUBLE,
-       NM_TYPE_BOOLEAN
-};
-
-typedef struct notification_meta_s
-{
-       char name[DATA_MAX_NAME_LEN];
-       enum notification_meta_type_e type;
-       union
-       {
-               const char *nm_string;
-               int64_t nm_signed_int;
-               uint64_t nm_unsigned_int;
-               double nm_double;
-               _Bool nm_boolean;
-       } nm_value;
-       struct notification_meta_s *next;
-} notification_meta_t;
-
-typedef struct notification_s
-{
-       int    severity;
-       cdtime_t time;
-       char   message[NOTIF_MAX_MSG_LEN];
-       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];
-       notification_meta_t *meta;
-} notification_t;
-
-struct user_data_s
-{
-       void *data;
-       void (*free_func) (void *);
-};
-typedef struct user_data_s user_data_t;
-
-struct plugin_ctx_s
-{
-       cdtime_t interval;
-};
-typedef struct plugin_ctx_s plugin_ctx_t;
-
-/*
- * Callback types
- */
-typedef int (*plugin_init_cb) (void);
-typedef int (*plugin_read_cb) (user_data_t *);
-typedef int (*plugin_write_cb) (const data_set_t *, const value_list_t *,
-               user_data_t *);
-typedef int (*plugin_flush_cb) (cdtime_t timeout, const char *identifier,
-               user_data_t *);
-/* "missing" callback. Returns less than zero on failure, zero if other
- * callbacks should be called, greater than zero if no more callbacks should be
- * called. */
-typedef int (*plugin_missing_cb) (const value_list_t *, user_data_t *);
-typedef void (*plugin_log_cb) (int severity, const char *message,
-               user_data_t *);
-typedef int (*plugin_shutdown_cb) (void);
-typedef int (*plugin_notification_cb) (const notification_t *,
-               user_data_t *);
-
-/*
- * NAME
- *  plugin_set_dir
- *
- * DESCRIPTION
- *  Sets the current `plugindir'
- *
- * ARGUMENTS
- *  `dir'       Path to the plugin directory
- *
- * NOTES
- *  If `dir' is NULL the compiled in default `PLUGINDIR' is used.
- */
-void plugin_set_dir (const char *dir);
-
-/*
- * NAME
- *  plugin_load
- *
- * DESCRIPTION
- *  Searches the current `plugindir' (see `plugin_set_dir') for the plugin
- *  named $type and loads it. Afterwards the plugin's `module_register'
- *  function is called, which then calls `plugin_register' to register callback
- *  functions.
- *
- * ARGUMENTS
- *  `name'      Name of the plugin to load.
- *  `flags'     Hints on how to handle this plugin.
- *
- * RETURN VALUE
- *  Returns zero upon success, a value greater than zero if no plugin was found
- *  and a value below zero if an error occurs.
- *
- * NOTES
- *  Re-loading an already loaded module is detected and zero is returned in
- *  this case.
- */
-int plugin_load (const char *name, uint32_t flags);
-
-void plugin_init_all (void);
-void plugin_read_all (void);
-int plugin_read_all_once (void);
-void plugin_shutdown_all (void);
-
-/*
- * NAME
- *  plugin_write
- *
- * DESCRIPTION
- *  Calls the write function of the given plugin with the provided data set and
- *  value list. It differs from `plugin_dispatch_value' in that it does not
- *  update the cache, does not do threshold checking, call the chain subsystem
- *  and so on. It looks up the requested plugin and invokes the function, end
- *  of story.
- *
- * ARGUMENTS
- *  plugin     Name of the plugin. If NULL, the value is sent to all registered
- *             write functions.
- *  ds         Pointer to the data_set_t structure. If NULL, the data set is
- *             looked up according to the `type' member in the `vl' argument.
- *  vl         The actual value to be processed. Must not be NULL.
- *
- * RETURN VALUE
- *  Returns zero upon success or non-zero if an error occurred. If `plugin' is
- *  NULL and more than one plugin is called, an error is only returned if *all*
- *  plugins fail.
- *
- * NOTES
- *  This is the function used by the `write' built-in target. May be used by
- *  other target plugins.
- */
-int plugin_write (const char *plugin,
-    const data_set_t *ds, const value_list_t *vl);
-
-int plugin_flush (const char *plugin, cdtime_t timeout, const char *identifier);
-
-/*
- * The `plugin_register_*' functions are used to make `config', `init',
- * `read', `write' and `shutdown' functions known to the plugin
- * infrastructure. Also, the data-formats are made public like this.
- */
-int plugin_register_config (const char *name,
-               int (*callback) (const char *key, const char *val),
-               const char **keys, int keys_num);
-int plugin_register_complex_config (const char *type,
-               int (*callback) (oconfig_item_t *));
-int plugin_register_init (const char *name,
-               plugin_init_cb callback);
-int plugin_register_read (const char *name,
-               int (*callback) (void));
-/* "user_data" will be freed automatically, unless
- * "plugin_register_complex_read" returns an error (non-zero). */
-int plugin_register_complex_read (const char *group, const char *name,
-               plugin_read_cb callback,
-               const struct timespec *interval,
-               user_data_t *user_data);
-int plugin_register_write (const char *name,
-               plugin_write_cb callback, user_data_t *user_data);
-int plugin_register_flush (const char *name,
-               plugin_flush_cb callback, user_data_t *user_data);
-int plugin_register_missing (const char *name,
-               plugin_missing_cb callback, user_data_t *user_data);
-int plugin_register_shutdown (const char *name,
-               plugin_shutdown_cb callback);
-int plugin_register_data_set (const data_set_t *ds);
-int plugin_register_log (const char *name,
-               plugin_log_cb callback, user_data_t *user_data);
-int plugin_register_notification (const char *name,
-               plugin_notification_cb callback, user_data_t *user_data);
-
-int plugin_unregister_config (const char *name);
-int plugin_unregister_complex_config (const char *name);
-int plugin_unregister_init (const char *name);
-int plugin_unregister_read (const char *name);
-int plugin_unregister_read_group (const char *group);
-int plugin_unregister_write (const char *name);
-int plugin_unregister_flush (const char *name);
-int plugin_unregister_missing (const char *name);
-int plugin_unregister_shutdown (const char *name);
-int plugin_unregister_data_set (const char *name);
-int plugin_unregister_log (const char *name);
-int plugin_unregister_notification (const char *name);
-
-
-/*
- * NAME
- *  plugin_dispatch_values
- *
- * DESCRIPTION
- *  This function is called by reading processes with the values they've
- *  aquired. The function fetches the data-set definition (that has been
- *  registered using `plugin_register_data_set') and calls _all_ registered
- *  write-functions.
- *
- * ARGUMENTS
- *  `vl'        Value list of the values that have been read by a `read'
- *              function.
- */
-int plugin_dispatch_values (value_list_t const *vl);
-int plugin_dispatch_missing (const value_list_t *vl);
-
-int plugin_dispatch_notification (const notification_t *notif);
-
-void plugin_log (int level, const char *format, ...)
-       __attribute__ ((format(printf,2,3)));
-
-/* These functions return the parsed severity or less than zero on failure. */
-int parse_log_severity (const char *severity);
-int parse_notif_severity (const char *severity);
-
-#define ERROR(...)   plugin_log (LOG_ERR,     __VA_ARGS__)
-#define WARNING(...) plugin_log (LOG_WARNING, __VA_ARGS__)
-#define NOTICE(...)  plugin_log (LOG_NOTICE,  __VA_ARGS__)
-#define INFO(...)    plugin_log (LOG_INFO,    __VA_ARGS__)
-#if COLLECT_DEBUG
-# define DEBUG(...)  plugin_log (LOG_DEBUG,   __VA_ARGS__)
-#else /* COLLECT_DEBUG */
-# define DEBUG(...)  /* noop */
-#endif /* ! COLLECT_DEBUG */
-
-const data_set_t *plugin_get_ds (const char *name);
-
-int plugin_notification_meta_add_string (notification_t *n,
-    const char *name,
-    const char *value);
-int plugin_notification_meta_add_signed_int (notification_t *n,
-    const char *name,
-    int64_t value);
-int plugin_notification_meta_add_unsigned_int (notification_t *n,
-    const char *name,
-    uint64_t value);
-int plugin_notification_meta_add_double (notification_t *n,
-    const char *name,
-    double value);
-int plugin_notification_meta_add_boolean (notification_t *n,
-    const char *name,
-    _Bool value);
-
-int plugin_notification_meta_copy (notification_t *dst,
-    const notification_t *src);
-
-int plugin_notification_meta_free (notification_meta_t *n);
-
-/*
- * Plugin context management.
- */
-
-void plugin_init_ctx (void);
-
-plugin_ctx_t plugin_get_ctx (void);
-plugin_ctx_t plugin_set_ctx (plugin_ctx_t ctx);
-
-/*
- * NAME
- *  plugin_get_interval
- *
- * DESCRIPTION
- *  This function returns the current value of the plugin's interval. The
- *  return value will be strictly greater than zero in all cases. If
- *  everything else fails, it will fall back to 10 seconds.
- */
-cdtime_t plugin_get_interval (void);
-
-/*
- * Context-aware thread management.
- */
-
-int plugin_thread_create (pthread_t *thread, const pthread_attr_t *attr,
-               void *(*start_routine) (void *), void *arg);
-
-#endif /* PLUGIN_H */
index c240e5438297b28e29e7b04d7f1180dd102a979b..54c856d66464f68f9683a16c5c73cb630c180cbf 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>
  **/
 
 /*
@@ -141,6 +135,7 @@ typedef struct {
        /* writer "caching" settings */
        cdtime_t commit_interval;
        cdtime_t next_commit;
+       cdtime_t expire_delay;
 
        char *host;
        char *port;
@@ -263,6 +258,7 @@ static c_psql_database_t *c_psql_database_new (const char *name)
 
        db->commit_interval = 0;
        db->next_commit     = 0;
+       db->expire_delay    = 0;
 
        db->database   = sstrdup (name);
        db->host       = NULL;
@@ -571,6 +567,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
@@ -872,6 +869,12 @@ static int c_psql_write (const data_set_t *ds, const value_list_t *vl,
 
 #undef VALUE_OR_NULL
 
+       if( db->expire_delay > 0 && vl->time < (cdtime() - vl->interval - db->expire_delay) ) {
+               log_info ("c_psql_write: Skipped expired value @ %s - %s/%s-%s/%s-%s/%s", 
+                       params[0], params[1], params[2], params[3], params[4], params[5], params[6] );
+               return 0;
+        }
+
        pthread_mutex_lock (&db->db_lock);
 
        if (0 != c_psql_check_connection (db)) {
@@ -1241,6 +1244,8 @@ static int c_psql_config_database (oconfig_item_t *ci)
                        cf_util_get_cdtime (c, &db->interval);
                else if (strcasecmp ("CommitInterval", c->key) == 0)
                        cf_util_get_cdtime (c, &db->commit_interval);
+               else if (strcasecmp ("ExpireDelay", c->key) == 0)
+                       cf_util_get_cdtime (c, &db->expire_delay);
                else
                        log_warn ("Ignoring unknown config key \"%s\".", c->key);
        }
index c8e72cbff8965f0d886a328937618ec2fbb7a58a..f9f291aed08b924cf6c9940e1020bc1b80ec647a 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
@@ -147,22 +147,34 @@ statname_lookup_t lookup_table[] = /* {{{ */
   {"recursing-questions",    "dns_question", "recurse"},
   {"tcp-queries",            "dns_question", "tcp"},
   {"udp-queries",            "dns_question", "udp"},
+  {"rd-queries",             "dns_question", "rd"},
 
   /* Answers */
   {"recursing-answers",      "dns_answer",   "recurse"},
   {"tcp-answers",            "dns_answer",   "tcp"},
   {"udp-answers",            "dns_answer",   "udp"},
+  {"recursion-unanswered",   "dns_answer",   "recursion-unanswered"},
+  {"udp-answers-bytes",      "total_bytes",  "udp-answers-bytes"},
 
   /* Cache stuff */
   {"packetcache-hit",        "cache_result", "packet-hit"},
   {"packetcache-miss",       "cache_result", "packet-miss"},
   {"packetcache-size",       "cache_size",   "packet"},
+  {"key-cache-size",         "cache_size",   "key"},
+  {"meta-cache-size",        "cache_size",   "meta"},
+  {"signature-cache-size",   "cache_size",   "signature"},
   {"query-cache-hit",        "cache_result", "query-hit"},
   {"query-cache-miss",       "cache_result", "query-miss"},
 
   /* Latency */
   {"latency",                "latency",      NULL},
 
+  /* DNS updates */
+  {"dnsupdate-answers",      "dns_answer",   "dnsupdate-answer"},
+  {"dnsupdate-changes",      "dns_question", "dnsupdate-changes"},
+  {"dnsupdate-queries",      "dns_question", "dnsupdate-queries"},
+  {"dnsupdate-refused",      "dns_answer",   "dnsupdate-refused"},
+
   /* Other stuff.. */
   {"corrupt-packets",        "ipt_packets",  "corrupt"},
   {"deferred-cache-inserts", "counter",      "cache-deferred_insert"},
@@ -175,6 +187,9 @@ statname_lookup_t lookup_table[] = /* {{{ */
   {"udp4-queries",           "dns_question", "queries-udp4"},
   {"udp6-answers",           "dns_answer",   "udp6"},
   {"udp6-queries",           "dns_question", "queries-udp6"},
+  {"security-status",        "dns_question", "security-status"},
+  {"udp-do-queries",         "dns_question", "udp-do_queries"},
+  {"signatures",             "counter",      "signatures"},
 
   /***********************
    * Recursor statistics *
@@ -224,8 +239,8 @@ statname_lookup_t lookup_table[] = /* {{{ */
   {"throttle-entries",    "gauge",        "entries-throttle"},
   {"unauthorized-tcp",    "counter",      "denied-unauthorized_tcp"},
   {"unauthorized-udp",    "counter",      "denied-unauthorized_udp"},
-  {"unexpected-packets",  "dns_answer",   "unexpected"}
-  /* {"uptime", "", ""} */
+  {"unexpected-packets",  "dns_answer",   "unexpected"},
+  {"uptime",              "uptime",       NULL}
 }; /* }}} */
 int lookup_table_length = STATIC_ARRAY_SIZE (lookup_table);
 
index e8839df429b0f117d77ab6ac710466462f8698de..fde96f89d245c3b79d3a6c5a5239f1d76052cae0 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>
 #  endif
 /* #endif KERNEL_LINUX */
 
-#elif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD
+#elif HAVE_LIBKVM_GETPROCS && (HAVE_STRUCT_KINFO_PROC_FREEBSD || HAVE_STRUCT_KINFO_PROC_OPENBSD)
 #  include <kvm.h>
 #  include <sys/param.h>
 #  include <sys/sysctl.h>
 #  include <sys/user.h>
 #  include <sys/proc.h>
-/* #endif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD */
+/* #endif HAVE_LIBKVM_GETPROCS && (HAVE_STRUCT_KINFO_PROC_FREEBSD || HAVE_STRUCT_KINFO_PROC_OPENBSD) */
 
 #elif HAVE_PROCINFO_H
 #  include <procinfo.h>
 # include <kstat.h>
 #endif
 
-#ifndef ARG_MAX
-#  define ARG_MAX 4096
+#ifndef CMDLINE_BUFFER_SIZE
+# if defined(ARG_MAX) && (ARG_MAX < 4096)
+#  define CMDLINE_BUFFER_SIZE ARG_MAX
+# else
+#  define CMDLINE_BUFFER_SIZE 4096
+# endif
 #endif
 
 typedef struct procstat_entry_s
@@ -225,9 +229,9 @@ static mach_msg_type_number_t     pset_list_len;
 static long pagesize_g;
 /* #endif KERNEL_LINUX */
 
-#elif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD
+#elif HAVE_LIBKVM_GETPROCS && (HAVE_STRUCT_KINFO_PROC_FREEBSD || HAVE_STRUCT_KINFO_PROC_OPENBSD)
 static int pagesize;
-/* #endif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD */
+/* #endif HAVE_LIBKVM_GETPROCS && (HAVE_STRUCT_KINFO_PROC_FREEBSD || HAVE_STRUCT_KINFO_PROC_OPENBSD) */
 
 #elif HAVE_PROCINFO_H
 static  struct procentry64 procentry[MAXPROCENTRY];
@@ -634,9 +638,9 @@ static int ps_init (void)
                        pagesize_g, CONFIG_HZ);
 /* #endif KERNEL_LINUX */
 
-#elif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD
+#elif HAVE_LIBKVM_GETPROCS && (HAVE_STRUCT_KINFO_PROC_FREEBSD || HAVE_STRUCT_KINFO_PROC_OPENBSD)
        pagesize = getpagesize();
-/* #endif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD */
+/* #endif HAVE_LIBKVM_GETPROCS && (HAVE_STRUCT_KINFO_PROC_FREEBSD || HAVE_STRUCT_KINFO_PROC_OPENBSD) */
 
 #elif HAVE_PROCINFO_H
        pagesize = getpagesize();
@@ -1701,7 +1705,7 @@ static int ps_read (void)
        DIR           *proc;
        int            pid;
 
-       char cmdline[ARG_MAX];
+       char cmdline[CMDLINE_BUFFER_SIZE];
 
        int        status;
        procstat_t ps;
@@ -1736,6 +1740,7 @@ static int ps_read (void)
                        continue;
                }
 
+               memset (&pse, 0, sizeof (pse));
                pse.id       = pid;
                pse.age      = 0;
 
@@ -1839,7 +1844,7 @@ static int ps_read (void)
                 * filter out threads (duplicate PID entries). */
                if ((proc_ptr == NULL) || (proc_ptr->ki_pid != procs[i].ki_pid))
                {
-                       char cmdline[ARG_MAX] = "";
+                       char cmdline[CMDLINE_BUFFER_SIZE] = "";
                        _Bool have_cmdline = 0;
 
                        proc_ptr = &(procs[i]);
@@ -1936,6 +1941,142 @@ static int ps_read (void)
                ps_submit_proc_list (ps_ptr);
 /* #endif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD */
 
+#elif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_OPENBSD
+       int running  = 0;
+       int sleeping = 0;
+       int zombies  = 0;
+       int stopped  = 0;
+       int onproc   = 0;
+       int idle     = 0;
+       int dead     = 0;
+
+       kvm_t *kd;
+       char errbuf[1024];
+       struct kinfo_proc *procs;          /* array of processes */
+       struct kinfo_proc *proc_ptr = NULL;
+       int count;                         /* returns number of processes */
+       int i;
+
+       procstat_t *ps_ptr;
+       procstat_entry_t pse;
+
+       ps_list_reset ();
+
+       /* Open the kvm interface, get a descriptor */
+       kd = kvm_open (NULL, NULL, NULL, 0, errbuf);
+       if (kd == NULL)
+       {
+               ERROR ("processes plugin: Cannot open kvm interface: %s",
+                               errbuf);
+               return (0);
+       }
+
+       /* Get the list of processes. */
+       procs = kvm_getprocs(kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc), &count);
+       if (procs == NULL)
+       {
+               ERROR ("processes plugin: Cannot get kvm processes list: %s",
+                               kvm_geterr(kd));
+               kvm_close (kd);
+               return (0);
+       }
+
+       /* Iterate through the processes in kinfo_proc */
+       for (i = 0; i < count; i++)
+       {
+               /* Create only one process list entry per _process_, i.e.
+                * filter out threads (duplicate PID entries). */
+               if ((proc_ptr == NULL) || (proc_ptr->p_pid != procs[i].p_pid))
+               {
+                       char cmdline[CMDLINE_BUFFER_SIZE] = "";
+                       _Bool have_cmdline = 0;
+
+                       proc_ptr = &(procs[i]);
+                       /* Don't probe zombie processes  */
+                       if (!P_ZOMBIE(proc_ptr))
+                       {
+                               char **argv;
+                               int argc;
+                               int status;
+
+                               /* retrieve the arguments */
+                               argv = kvm_getargv (kd, proc_ptr, /* nchr = */ 0);
+                               argc = 0;
+                               if ((argv != NULL) && (argv[0] != NULL))
+                               {
+                                       while (argv[argc] != NULL)
+                                               argc++;
+
+                                       status = strjoin (cmdline, sizeof (cmdline), argv, argc, " ");
+                                       if (status < 0)
+                                               WARNING ("processes plugin: Command line did not fit into buffer.");
+                                       else
+                                               have_cmdline = 1;
+                               }
+                       } /* if (process has argument list) */
+
+                       memset (&pse, 0, sizeof (pse));
+                       pse.id       = procs[i].p_pid;
+                       pse.age      = 0;
+
+                       pse.num_proc = 1;
+                       pse.num_lwp  = 1; /* XXX: accumulate p_tid values for a single p_pid ? */
+
+                       pse.vmem_rss = procs[i].p_vm_rssize * pagesize;
+                       pse.vmem_data = procs[i].p_vm_dsize * pagesize;
+                       pse.vmem_code = procs[i].p_vm_tsize * pagesize;
+                       pse.stack_size = procs[i].p_vm_ssize * pagesize;
+                       pse.vmem_size = pse.stack_size + pse.vmem_code + pse.vmem_data;
+                       pse.vmem_minflt = 0;
+                       pse.vmem_minflt_counter = procs[i].p_uru_minflt;
+                       pse.vmem_majflt = 0;
+                       pse.vmem_majflt_counter = procs[i].p_uru_majflt;
+
+                       pse.cpu_user = 0;
+                       pse.cpu_system = 0;
+                       pse.cpu_user_counter = procs[i].p_uutime_usec +
+                                               (1000000lu * procs[i].p_uutime_sec);
+                       pse.cpu_system_counter = procs[i].p_ustime_usec +
+                                               (1000000lu * procs[i].p_ustime_sec);
+
+                       /* no I/O data */
+                       pse.io_rchar = -1;
+                       pse.io_wchar = -1;
+                       pse.io_syscr = -1;
+                       pse.io_syscw = -1;
+
+                       pse.cswitch_vol = -1;
+                       pse.cswitch_invol = -1;
+
+                       ps_list_add (procs[i].p_comm, have_cmdline ? cmdline : NULL, &pse);
+               } /* if ((proc_ptr == NULL) || (proc_ptr->p_pid != procs[i].p_pid)) */
+
+               switch (procs[i].p_stat)
+               {
+                       case SSTOP:     stopped++;      break;
+                       case SSLEEP:    sleeping++;     break;
+                       case SRUN:      running++;      break;
+                       case SIDL:      idle++;         break;
+                       case SONPROC:   onproc++;       break;
+                       case SDEAD:     dead++;         break;
+                       case SZOMB:     zombies++;      break;
+               }
+       }
+
+       kvm_close(kd);
+
+       ps_submit_state ("running",  running);
+       ps_submit_state ("sleeping", sleeping);
+       ps_submit_state ("zombies",  zombies);
+       ps_submit_state ("stopped",  stopped);
+       ps_submit_state ("onproc",   onproc);
+       ps_submit_state ("idle",     idle);
+       ps_submit_state ("dead",     dead);
+
+       for (ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next)
+               ps_submit_proc_list (ps_ptr);
+/* #endif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_OPENBSD */
+
 #elif HAVE_PROCINFO_H
        /* AIX */
        int running  = 0;
@@ -2122,6 +2263,7 @@ static int ps_read (void)
                        continue;
                }
 
+               memset (&pse, 0, sizeof (pse));
                pse.id = pid;
                pse.age = 0;
 
@@ -2148,6 +2290,9 @@ static int ps_read (void)
                pse.io_syscr = ps.io_syscr;
                pse.io_syscw = ps.io_syscw;
 
+               pse.cswitch_vol = -1;
+               pse.cswitch_invol = -1;
+
                switch (state)
                {
                        case 'R': running++;  break;
index 0dfba2101fa578e92c56c360b795f1e989ff1a29..1a39aad3ef93c4eeecfb1b00ba22487869232751 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 10ac8f0d149f815fa9d00e54bdda3e0123246029..8b378a299994105f9a7584e0e247d7a2710e2558 100644 (file)
@@ -46,6 +46,19 @@ typedef struct cpy_callback_s {
 
 static char log_doc[] = "This function sends a string to all logging plugins.";
 
+static char get_ds_doc[] = "get_dataset(name) -> definition\n"
+               "\n"
+               "Returns the definition of a dataset specified by name.\n"
+               "\n"
+               "'name' is a string specifying the dataset to query.\n"
+               "'definition' is a list of 4-tuples. Every tuple represents a \n"
+               "    data source within the data set and its 4 values are the \n"
+               "    name, type, min and max value.\n"
+               "    'name' is a string.\n"
+               "    'type' is a string that is equal to either DS_TYPE_COUNTER,\n"
+               "        DS_TYPE_GAUGE, DS_TYPE_DERIVE or DS_TYPE_ABSOLUTE.\n"
+               "    'min' and 'max' are either a float or None.";
+
 static char flush_doc[] = "flush([plugin][, timeout][, identifier]) -> None\n"
                "\n"
                "Flushes the cache of another plugin.";
@@ -548,7 +561,39 @@ static PyObject *cpy_register_generic(cpy_callback_t **list_head, PyObject *args
        return cpy_string_to_unicode_or_bytes(buf);
 }
 
-static PyObject *cpy_flush(cpy_callback_t **list_head, PyObject *args, PyObject *kwds) {
+static PyObject *float_or_none(float number) {
+       if (isnan(number)) {
+               Py_RETURN_NONE;
+       }
+       return PyFloat_FromDouble(number);
+}
+
+static PyObject *cpy_get_dataset(PyObject *self, PyObject *args) {
+       int i;
+       char *name;
+       const data_set_t *ds;
+       PyObject *list, *tuple;
+
+       if (PyArg_ParseTuple(args, "et", NULL, &name) == 0) return NULL;
+       ds = plugin_get_ds(name);
+       PyMem_Free(name);
+       if (ds == NULL) {
+               PyErr_Format(PyExc_TypeError, "Dataset %s not found", name);
+               return NULL;
+       }
+       list = PyList_New(ds->ds_num); /* New reference. */
+       for (i = 0; i < ds->ds_num; ++i) {
+               tuple = PyTuple_New(4);
+               PyTuple_SET_ITEM(tuple, 0, cpy_string_to_unicode_or_bytes(ds->ds[i].name));
+               PyTuple_SET_ITEM(tuple, 1, cpy_string_to_unicode_or_bytes(DS_TYPE_TO_STRING(ds->ds[i].type)));
+               PyTuple_SET_ITEM(tuple, 2, float_or_none(ds->ds[i].min));
+               PyTuple_SET_ITEM(tuple, 3, float_or_none(ds->ds[i].max));
+               PyList_SET_ITEM(list, i, tuple);
+       }
+       return list;
+}
+
+static PyObject *cpy_flush(PyObject *self, PyObject *args, PyObject *kwds) {
        int timeout = -1;
        char *plugin = NULL, *identifier = NULL;
        static char *kwlist[] = {"plugin", "timeout", "identifier", NULL};
@@ -817,6 +862,7 @@ static PyMethodDef cpy_methods[] = {
        {"notice", cpy_notice, METH_VARARGS, log_doc},
        {"warning", cpy_warning, METH_VARARGS, log_doc},
        {"error", cpy_error, METH_VARARGS, log_doc},
+       {"get_dataset", (PyCFunction) cpy_get_dataset, METH_VARARGS, get_ds_doc},
        {"flush", (PyCFunction) cpy_flush, METH_VARARGS | METH_KEYWORDS, flush_doc},
        {"register_log", (PyCFunction) cpy_register_log, METH_VARARGS | METH_KEYWORDS, reg_log_doc},
        {"register_init", (PyCFunction) cpy_register_init, METH_VARARGS | METH_KEYWORDS, reg_init_doc},
@@ -988,13 +1034,15 @@ PyMODINIT_FUNC PyInit_collectd(void) {
 #endif
 
 static int cpy_init_python() {
-       char *argv = "";
        PyObject *sys;
        PyObject *module;
 
 #ifdef IS_PY3K
+       wchar_t *argv = L"";
        /* Add a builtin module, before Py_Initialize */
        PyImport_AppendInittab("collectd", PyInit_collectd);
+#else
+       char *argv = "";
 #endif
        
        Py_Initialize();
@@ -1041,6 +1089,10 @@ static int cpy_init_python() {
        PyModule_AddIntConstant(module, "NOTIF_FAILURE", NOTIF_FAILURE);
        PyModule_AddIntConstant(module, "NOTIF_WARNING", NOTIF_WARNING);
        PyModule_AddIntConstant(module, "NOTIF_OKAY", NOTIF_OKAY);
+       PyModule_AddStringConstant(module, "DS_TYPE_COUNTER", DS_TYPE_TO_STRING(DS_TYPE_COUNTER));
+       PyModule_AddStringConstant(module, "DS_TYPE_GAUGE", DS_TYPE_TO_STRING(DS_TYPE_GAUGE));
+       PyModule_AddStringConstant(module, "DS_TYPE_DERIVE", DS_TYPE_TO_STRING(DS_TYPE_DERIVE));
+       PyModule_AddStringConstant(module, "DS_TYPE_ABSOLUTE", DS_TYPE_TO_STRING(DS_TYPE_ABSOLUTE));
        return 0;
 }
 
@@ -1067,9 +1119,13 @@ static int cpy_config(oconfig_item_t *ci) {
                } else if (strcasecmp(item->key, "Encoding") == 0) {
                        if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_STRING)
                                continue;
+#ifdef IS_PY3K
+                       NOTICE("python: \"Encoding\" was used in the config file but Python3 was used, which does not support changing encodings. Ignoring this.");
+#else
                        /* Why is this even necessary? And undocumented? */
                        if (PyUnicode_SetDefaultEncoding(item->values[0].value.string))
                                cpy_log_exception("setting default encoding");
+#endif
                } else if (strcasecmp(item->key, "LogTraces") == 0) {
                        if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN)
                                continue;
@@ -1103,8 +1159,8 @@ static int cpy_config(oconfig_item_t *ci) {
                                cpy_log_exception("python initialization");
                                continue;
                        }
-                       if (PyList_Append(sys_path, dir_object) != 0) {
-                               ERROR("python plugin: Unable to append \"%s\" to "
+                       if (PyList_Insert(sys_path, 0, dir_object) != 0) {
+                               ERROR("python plugin: Unable to prepend \"%s\" to "
                                      "python module path.", dir);
                                cpy_log_exception("python initialization");
                        }
index 85a8354629240553f7e60a65ae0c5cb72446ae29..7864ead07c01c1edf079cecfb9c79474470cb277 100644 (file)
@@ -26,7 +26,8 @@
 #include "configfile.h"
 
 #include <pthread.h>
-#include <credis.h>
+#include <sys/time.h>
+#include <hiredis/hiredis.h>
 
 #ifndef HOST_NAME_MAX
 # define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
@@ -37,6 +38,9 @@
 #define REDIS_DEF_PORT    6379
 #define REDIS_DEF_TIMEOUT 2000
 #define MAX_REDIS_NODE_NAME 64
+#define MAX_REDIS_PASSWD_LENGTH 512
+#define MAX_REDIS_VAL_SIZE 256
+#define MAX_REDIS_QUERY 2048
 
 /* Redis plugin configuration example:
  *
  *   <Node "mynode">
  *     Host "localhost"
  *     Port "6379"
- *     Timeout 2000
+ *     Timeout 2
+ *     Password "foobar"
  *   </Node>
  * </Plugin>
  */
 
+struct redis_query_s;
+typedef struct redis_query_s redis_query_t;
+struct redis_query_s
+{
+    char query[MAX_REDIS_QUERY];
+    char type[DATA_MAX_NAME_LEN];
+    char instance[DATA_MAX_NAME_LEN];
+    redis_query_t *next;
+};
+
 struct redis_node_s;
 typedef struct redis_node_s redis_node_t;
 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;
+  struct timeval timeout;
+  redis_query_t *queries;
 
   redis_node_t *next;
 };
@@ -106,16 +122,61 @@ static int redis_node_add (const redis_node_t *rn) /* {{{ */
   return (0);
 } /* }}} */
 
+static redis_query_t *redis_config_query (oconfig_item_t *ci) /* {{{ */
+{
+    redis_query_t *rq;
+    int status;
+    int i;
+
+    rq = calloc(1, sizeof(*rq));
+    if (rq == NULL) {
+        ERROR("redis plugin: calloca failed adding redis_query.");
+        return NULL;
+    }
+    status = cf_util_get_string_buffer(ci, rq->query, sizeof(rq->query));
+    if (status != 0)
+        goto err;
+
+    /*
+     * Default to a gauge type.
+     */
+    (void)strncpy(rq->type, "gauge", sizeof(rq->type));
+    (void)strncpy(rq->instance, rq->query, sizeof(rq->instance));
+    replace_special(rq->instance, sizeof(rq->instance));
+
+    for (i = 0; i < ci->children_num; i++) {
+        oconfig_item_t *option = ci->children + i;
+
+        if (strcasecmp("Type", option->key) == 0) {
+            status = cf_util_get_string_buffer(option, rq->type, sizeof(rq->type));
+        } else if (strcasecmp("Instance", option->key) == 0) {
+            status = cf_util_get_string_buffer(option, rq->instance, sizeof(rq->instance));
+        } else {
+            WARNING("redis plugin: unknown configuration option: %s", option->key);
+            status = -1;
+        }
+        if (status != 0)
+            goto err;
+    }
+    return rq;
+ err:
+    free(rq);
+    return NULL;
+} /* }}} */
+
 static int redis_config_node (oconfig_item_t *ci) /* {{{ */
 {
   redis_node_t rn;
+  redis_query_t *rq;
   int i;
   int status;
+  int timeout;
 
   memset (&rn, 0, sizeof (rn));
   sstrncpy (rn.host, REDIS_DEF_HOST, sizeof (rn.host));
   rn.port = REDIS_DEF_PORT;
-  rn.timeout = REDIS_DEF_TIMEOUT;
+  rn.timeout.tv_usec = REDIS_DEF_TIMEOUT;
+  rn.queries = NULL;
 
   status = cf_util_get_string_buffer (ci, rn.name, sizeof (rn.name));
   if (status != 0)
@@ -136,8 +197,21 @@ static int redis_config_node (oconfig_item_t *ci) /* {{{ */
         status = 0;
       }
     }
+    else if (strcasecmp ("Query", option->key) == 0)
+    {
+      rq = redis_config_query(option);
+      if (rq == NULL) {
+          status =1;
+      } else {
+          rq->next = rn.queries;
+          rn.queries = rq;
+      }
+    }
     else if (strcasecmp ("Timeout", option->key) == 0)
-      status = cf_util_get_int (option, &rn.timeout);
+    {
+      status = cf_util_get_int (option, &timeout);
+      if (status == 0) rn.timeout.tv_usec = timeout;
+    }
     else if (strcasecmp ("Password", option->key) == 0)
       status = cf_util_get_string_buffer (option, rn.passwd, sizeof (rn.passwd));
     else
@@ -179,39 +253,14 @@ static int redis_config (oconfig_item_t *ci) /* {{{ */
 } /* }}} */
 
   __attribute__ ((nonnull(2)))
-static void redis_submit_g (char *plugin_instance,
-    const char *type, 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, "redis", 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);
-} /* }}} */
-
-  __attribute__ ((nonnull(2)))
-static void redis_submit_d (char *plugin_instance,
+static void redis_submit (char *plugin_instance,
     const char *type, const char *type_instance,
-    derive_t value) /* {{{ */
+    value_t value) /* {{{ */
 {
   value_t values[1];
   value_list_t vl = VALUE_LIST_INIT;
 
-  values[0].derive = value;
+  values[0] = value;
 
   vl.values = values;
   vl.values_len = 1;
@@ -230,8 +279,14 @@ static void redis_submit_d (char *plugin_instance,
 
 static int redis_init (void) /* {{{ */
 {
-  redis_node_t rn = { "default", REDIS_DEF_HOST, REDIS_DEF_PASSWD,
-    REDIS_DEF_PORT, REDIS_DEF_TIMEOUT, /* next = */ NULL };
+  redis_node_t rn = {
+    .name = "default",
+    .host = REDIS_DEF_HOST,
+    .port = REDIS_DEF_PORT,
+    .timeout.tv_sec = 0,
+    .timeout.tv_usec = REDIS_DEF_TIMEOUT,
+    .next = NULL
+};
 
   if (nodes_head == NULL)
     redis_node_add (&rn);
@@ -239,20 +294,103 @@ static int redis_init (void) /* {{{ */
   return (0);
 } /* }}} int redis_init */
 
+int redis_handle_info (char *node, char const *info_line, char const *type, char const *type_instance, char const *field_name, int ds_type) /* {{{ */
+{
+  char *str = strstr (info_line, field_name);
+  static char buf[MAX_REDIS_VAL_SIZE];
+  value_t val;
+  if (str)
+  {
+    int i;
+
+    str += strlen (field_name) + 1; /* also skip the ':' */
+    for(i=0;(*str && (isdigit(*str) || *str == '.'));i++,str++)
+      buf[i] = *str;
+    buf[i] ='\0';
+
+    if(parse_value (buf, &val, ds_type) == -1)
+    {
+      WARNING ("redis plugin: Unable to parse field `%s'.", field_name);
+      return (-1);
+    }
+
+    redis_submit (node, type, type_instance, val);
+    return (0);
+  }
+  return (-1);
+
+} /* }}} int redis_handle_info */
+
+int redis_handle_query (redisContext *rh, redis_node_t *rn, redis_query_t *rq) /* {{{ */
+{
+    redisReply *rr;
+    const data_set_t *ds;
+    value_t val;
+
+    ds = plugin_get_ds (rq->type);
+    if (!ds) {
+        ERROR ("redis plugin: DataSet `%s' not defined.", rq->type);
+        return (-1);
+    }
+
+    if (ds->ds_num != 1) {
+        ERROR ("redis plugin: DS `%s' has too many types.", rq->type);
+        return (-1);
+    }
+
+    if ((rr = redisCommand(rh, rq->query)) == NULL) {
+        WARNING("redis plugin: unable to carry out query `%s'.", rq->query);
+        return (-1);
+    }
+
+    switch (rr->type) {
+    case REDIS_REPLY_INTEGER:
+        switch (ds->ds[0].type) {
+        case DS_TYPE_COUNTER:
+            val.counter = (counter_t)rr->integer;
+            break;
+        case DS_TYPE_GAUGE:
+            val.gauge = (gauge_t)rr->integer;
+            break;
+        case DS_TYPE_DERIVE:
+            val.gauge = (derive_t)rr->integer;
+            break;
+        case DS_TYPE_ABSOLUTE:
+            val.gauge = (absolute_t)rr->integer;
+            break;
+        }
+        break;
+    case REDIS_REPLY_STRING:
+        if (parse_value (rr->str, &val, ds->ds[0].type) == -1) {
+            WARNING("redis plugin: Unable to parse field `%s'.", rq->type);
+            freeReplyObject (rr);
+            return (-1);
+        }
+        break;
+    default:
+        WARNING("redis plugin: Cannot coerce redis type.");
+        freeReplyObject(rr);
+        return (-1);
+    }
+
+    redis_submit(rn->name, rq->type, (strlen(rq->instance) >0)?rq->instance:NULL, val);
+    freeReplyObject (rr);
+    return 0;
+} /* }}} int redis_handle_info */
+
 static int redis_read (void) /* {{{ */
 {
   redis_node_t *rn;
+  redis_query_t *rq;
 
   for (rn = nodes_head; rn != NULL; rn = rn->next)
   {
-    REDIS rh;
-    REDIS_INFO info;
-
-    int status;
+    redisContext *rh;
+    redisReply   *rr;
 
     DEBUG ("redis plugin: querying info from node `%s' (%s:%d).", rn->name, rn->host, rn->port);
 
-    rh = credis_connect (rn->host, rn->port, rn->timeout);
+    rh = redisConnectWithTimeout ((char *)rn->host, rn->port, rn->timeout);
     if (rh == NULL)
     {
       ERROR ("redis plugin: unable to connect to node `%s' (%s:%d).", rn->name, rn->host, rn->port);
@@ -262,56 +400,46 @@ static int redis_read (void) /* {{{ */
     if (strlen (rn->passwd) > 0)
     {
       DEBUG ("redis plugin: authenticanting node `%s' passwd(%s).", rn->name, rn->passwd);
-      status = credis_auth(rh, rn->passwd);
-      if (status != 0)
+      rr = redisCommand (rh, "AUTH %s", rn->passwd);
+
+      if (rr == NULL || rr->type != REDIS_REPLY_STATUS)
       {
         WARNING ("redis plugin: unable to authenticate on node `%s'.", rn->name);
-        credis_close (rh);
+        if (rr != NULL)
+          freeReplyObject (rr);
+
+        redisFree (rh);
         continue;
       }
     }
 
-    memset (&info, 0, sizeof (info));
-    status = credis_info (rh, &info);
-    if (status != 0)
+    if ((rr = redisCommand(rh, "INFO")) == NULL)
     {
-      WARNING ("redis plugin: unable to get info from node `%s'.", rn->name);
-      credis_close (rh);
+      WARNING ("redis plugin: unable to connect to node `%s'.", rn->name);
+      redisFree (rh);
       continue;
     }
 
-    /* typedef struct _cr_info {
-     *   char redis_version[CREDIS_VERSION_STRING_SIZE];
-     *   int bgsave_in_progress;
-     *   int connected_clients;
-     *   int connected_slaves;
-     *   unsigned int used_memory;
-     *   long long changes_since_last_save;
-     *   int last_save_time;
-     *   long long total_connections_received;
-     *   long long total_commands_processed;
-     *   int uptime_in_seconds;
-     *   int uptime_in_days;
-     *   int role;
-     * } REDIS_INFO; */
-
-    DEBUG ("redis plugin: received info from node `%s': connected_clients = %d; "
-        "connected_slaves = %d; used_memory = %lu; changes_since_last_save = %lld; "
-        "bgsave_in_progress = %d; total_connections_received = %lld; "
-        "total_commands_processed = %lld; uptime_in_seconds = %ld", rn->name,
-        info.connected_clients, info.connected_slaves, info.used_memory,
-        info.changes_since_last_save, info.bgsave_in_progress,
-        info.total_connections_received, info.total_commands_processed,
-        info.uptime_in_seconds);
-
-    redis_submit_g (rn->name, "current_connections", "clients", info.connected_clients);
-    redis_submit_g (rn->name, "current_connections", "slaves", info.connected_slaves);
-    redis_submit_g (rn->name, "memory", "used", info.used_memory);
-    redis_submit_g (rn->name, "volatile_changes", NULL, info.changes_since_last_save);
-    redis_submit_d (rn->name, "total_connections", NULL, info.total_connections_received);
-    redis_submit_d (rn->name, "total_operations", NULL, info.total_commands_processed);
-
-    credis_close (rh);
+    redis_handle_info (rn->name, rr->str, "uptime", NULL, "uptime_in_seconds", DS_TYPE_GAUGE);
+    redis_handle_info (rn->name, rr->str, "current_connections", "clients", "connected_clients", DS_TYPE_GAUGE);
+    redis_handle_info (rn->name, rr->str, "blocked_clients", NULL, "blocked_clients", DS_TYPE_GAUGE);
+    redis_handle_info (rn->name, rr->str, "memory", NULL, "used_memory", DS_TYPE_GAUGE);
+    redis_handle_info (rn->name, rr->str, "memory_lua", NULL, "used_memory_lua", DS_TYPE_GAUGE);
+    /* changes_since_last_save: Deprecated in redis version 2.6 and above */
+    redis_handle_info (rn->name, rr->str, "volatile_changes", NULL, "changes_since_last_save", DS_TYPE_GAUGE);
+    redis_handle_info (rn->name, rr->str, "total_connections", NULL, "total_connections_received", DS_TYPE_DERIVE);
+    redis_handle_info (rn->name, rr->str, "total_operations", NULL, "total_commands_processed", DS_TYPE_DERIVE);
+    redis_handle_info (rn->name, rr->str, "expired_keys", NULL, "expired_keys", DS_TYPE_GAUGE);
+    redis_handle_info (rn->name, rr->str, "pubsub", "channels", "pubsub_channels", DS_TYPE_GAUGE);
+    redis_handle_info (rn->name, rr->str, "pubsub", "patterns", "pubsub_patterns", DS_TYPE_GAUGE);
+    redis_handle_info (rn->name, rr->str, "current_connections", "slaves", "connected_slaves", DS_TYPE_GAUGE);
+
+    freeReplyObject (rr);
+
+    for (rq = rn->queries; rq != NULL; rq = rq->next)
+        redis_handle_query(rh, rn, rq);
+
+    redisFree (rh);
   }
 
   return 0;
index 2ade3bb9c9d2cceb90a71f8950353dd214f2c80a..4ca9d5b2e77e6b3d059aee2e1d656b0d62cbf292 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 e77be2dd29eddd6af3b2674e35a2ffec967a3cb5..645032cbe189686a707c7e6d34db7343432b8882 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 209482e09f88e37a536641bda22d71e2d71810b4..f5b09bd29be1c501fd2a807b78eb753f14683a56 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
@@ -62,7 +62,9 @@ static char *sensor_type_name_map[] =
        "fanspeed",
 # define SENSOR_TYPE_TEMPERATURE 2
        "temperature",
-# define SENSOR_TYPE_UNKNOWN     3
+# define SENSOR_TYPE_POWER       3
+       "power",
+# define SENSOR_TYPE_UNKNOWN     4
        NULL
 };
 
@@ -127,7 +129,8 @@ static sensors_labeltypes_t known_features[] =
        { "3.3V", SENSOR_TYPE_VOLTAGE },
        { "2.5V", SENSOR_TYPE_VOLTAGE },
        { "2.0V", SENSOR_TYPE_VOLTAGE },
-       { "12V", SENSOR_TYPE_VOLTAGE }
+       { "12V", SENSOR_TYPE_VOLTAGE },
+       { "power1", SENSOR_TYPE_POWER }
 };
 static int known_features_num = STATIC_ARRAY_SIZE (known_features);
 /* end new naming */
@@ -411,7 +414,8 @@ static int sensors_load_conf (void)
                        /* Only handle voltage, fanspeeds and temperatures */
                        if ((feature->type != SENSORS_FEATURE_IN)
                                        && (feature->type != SENSORS_FEATURE_FAN)
-                                       && (feature->type != SENSORS_FEATURE_TEMP))
+                                       && (feature->type != SENSORS_FEATURE_TEMP)
+                                       && (feature->type != SENSORS_FEATURE_POWER))
                        {
                                DEBUG ("sensors plugin: sensors_load_conf: "
                                                "Ignoring feature `%s', "
@@ -427,7 +431,8 @@ static int sensors_load_conf (void)
 
                                if ((subfeature->type != SENSORS_SUBFEATURE_IN_INPUT)
                                                && (subfeature->type != SENSORS_SUBFEATURE_FAN_INPUT)
-                                               && (subfeature->type != SENSORS_SUBFEATURE_TEMP_INPUT))
+                                               && (subfeature->type != SENSORS_SUBFEATURE_TEMP_INPUT)
+                                               && (subfeature->type != SENSORS_SUBFEATURE_POWER_INPUT))
                                        continue;
 
                                fl = (featurelist_t *) malloc (sizeof (featurelist_t));
@@ -573,6 +578,9 @@ static int sensors_read (void)
                else if (fl->feature->type
                                == SENSORS_FEATURE_TEMP)
                        type = "temperature";
+               else if (fl->feature->type
+                               == SENSORS_FEATURE_POWER)
+                       type = "power";
                else
                        continue;
 
index 9bd885dbbf0bec28aeacbe8ae06624a06bf0a98e..430082220595c58f2b927089871a76e4e482a157 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 ba3e4062f0e9519544858ce982c0fc22c921a012..eecb54c8c5fd8c1ad8a607358925d1510cdbe233 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"
diff --git a/src/smart.c b/src/smart.c
new file mode 100644 (file)
index 0000000..2207bd6
--- /dev/null
@@ -0,0 +1,270 @@
+/**
+ * collectd - src/smart.c
+ * Copyright (C) 2014       Vincent Bernat
+ *
+ * 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:
+ *   Vincent Bernat <vbe at exoscale.ch>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+#include "utils_ignorelist.h"
+
+#include <atasmart.h>
+#include <libudev.h>
+
+static const char *config_keys[] =
+{
+  "Disk",
+  "IgnoreSelected"
+};
+
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+
+static ignorelist_t *ignorelist = NULL;
+
+static int smart_config (const char *key, const char *value)
+{
+  if (ignorelist == NULL)
+    ignorelist = ignorelist_create (/* invert = */ 1);
+  if (ignorelist == NULL)
+    return (1);
+
+  if (strcasecmp ("Disk", key) == 0)
+  {
+    ignorelist_add (ignorelist, value);
+  }
+  else if (strcasecmp ("IgnoreSelected", key) == 0)
+  {
+    int invert = 1;
+    if (IS_TRUE (value))
+      invert = 0;
+    ignorelist_set_invert (ignorelist, invert);
+  }
+  else
+  {
+    return (-1);
+  }
+
+  return (0);
+} /* int smart_config */
+
+static void smart_submit (const char *dev, char *type, char *type_inst, double 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, "smart", sizeof (vl.plugin));
+       sstrncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance));
+       sstrncpy (vl.type, type, sizeof (vl.type));
+       sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
+
+       plugin_dispatch_values (&vl);
+}
+
+static void smart_handle_disk_attribute(SkDisk *d, const SkSmartAttributeParsedData *a,
+                                        void* userdata)
+{
+  const char *dev = userdata;
+  value_t values[4];
+  value_list_t vl = VALUE_LIST_INIT;
+
+  if (!a->current_value_valid || !a->worst_value_valid) return;
+  values[0].gauge = a->current_value;
+  values[1].gauge = a->worst_value;
+  values[2].gauge = a->threshold_valid?a->threshold:0;
+  values[3].gauge = a->pretty_value;
+
+  vl.values = values;
+  vl.values_len = 4;
+  sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+  sstrncpy (vl.plugin, "smart", sizeof (vl.plugin));
+  sstrncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance));
+  sstrncpy (vl.type, "smart_attribute", sizeof (vl.type));
+  sstrncpy (vl.type_instance, a->name, sizeof (vl.type_instance));
+
+  plugin_dispatch_values (&vl);
+
+  if (a->threshold_valid && a->current_value <= a->threshold)
+  {
+    notification_t notif = { NOTIF_WARNING,
+                             cdtime (),
+                             "",
+                             "",
+                             "smart", "",
+                             "smart_attribute",
+                             "",
+                             NULL };
+    sstrncpy (notif.host, hostname_g, sizeof (notif.host));
+    sstrncpy (notif.plugin_instance, dev, sizeof (notif.plugin_instance));
+    sstrncpy (notif.type_instance, a->name, sizeof (notif.type_instance));
+    ssnprintf (notif.message, sizeof (notif.message),
+               "attribute %s is below allowed threshold (%d < %d)",
+               a->name, a->current_value, a->threshold);
+    plugin_dispatch_notification (&notif);
+  }
+}
+
+static void smart_handle_disk (const char *dev)
+{
+  SkDisk *d = NULL;
+  SkBool awake = FALSE;
+  SkBool available = FALSE;
+  const char *shortname;
+  const SkSmartParsedData *spd;
+  uint64_t poweron, powercycles, badsectors, temperature;
+
+  shortname = strrchr(dev, '/');
+  if (!shortname) return;
+  shortname++;
+  if (ignorelist_match (ignorelist, shortname) != 0) {
+    DEBUG ("smart plugin: ignoring %s.", dev);
+    return;
+  }
+
+  DEBUG ("smart plugin: checking SMART status of %s.",
+         dev);
+
+  if (sk_disk_open (dev, &d) < 0)
+  {
+    ERROR ("smart plugin: unable to open %s.", dev);
+    return;
+  }
+  if (sk_disk_identify_is_available (d, &available) < 0 || !available)
+  {
+    DEBUG ("smart plugin: disk %s cannot be identified.", dev);
+    goto end;
+  }
+  if (sk_disk_smart_is_available (d, &available) < 0 || !available)
+  {
+    DEBUG ("smart plugin: disk %s has no SMART support.", dev);
+    goto end;
+  }
+  if (sk_disk_check_sleep_mode (d, &awake) < 0 || !awake)
+  {
+    DEBUG ("smart plugin: disk %s is sleeping.", dev);
+    goto end;
+  }
+  if (sk_disk_smart_read_data (d) < 0)
+  {
+    ERROR ("smart plugin: unable to get SMART data for disk %s.", dev);
+    goto end;
+  }
+  if (sk_disk_smart_parse (d, &spd) < 0)
+  {
+    ERROR ("smart plugin: unable to parse SMART data for disk %s.", dev);
+    goto end;
+  }
+
+  /* Get some specific values */
+  if (sk_disk_smart_get_power_on (d, &poweron) < 0)
+  {
+    WARNING ("smart plugin: unable to get milliseconds since power on for %s.",
+             dev);
+  }
+  else
+    smart_submit (shortname, "smart_poweron", "", poweron / 1000.);
+
+  if (sk_disk_smart_get_power_cycle (d, &powercycles) < 0)
+  {
+    WARNING ("smart plugin: unable to get number of power cycles for %s.",
+             dev);
+  }
+  else
+    smart_submit (shortname, "smart_powercycles", "", powercycles);
+
+  if (sk_disk_smart_get_bad (d, &badsectors) < 0)
+  {
+    WARNING ("smart plugin: unable to get number of bad sectors for %s.",
+             dev);
+  }
+  else
+    smart_submit (shortname, "smart_badsectors", "", badsectors);
+
+  if (sk_disk_smart_get_temperature (d, &temperature) < 0)
+  {
+    WARNING ("smart plugin: unable to get temperature for %s.",
+             dev);
+  }
+  else
+    smart_submit (shortname, "smart_temperature", "", temperature / 1000. - 273.15);
+
+  /* Grab all attributes */
+  if (sk_disk_smart_parse_attributes(d, smart_handle_disk_attribute,
+                                     (char *)shortname) < 0)
+  {
+    ERROR ("smart plugin: unable to handle SMART attributes for %s.",
+           dev);
+  }
+
+end:
+  sk_disk_free(d);
+}
+
+static int smart_read (void)
+{
+  struct udev *handle_udev;
+  struct udev_enumerate *enumerate;
+  struct udev_list_entry *devices, *dev_list_entry;
+  struct udev_device *dev;
+
+  /* Use udev to get a list of disks */
+  handle_udev = udev_new();
+  if (!handle_udev)
+  {
+    ERROR ("smart plugin: unable to initialize udev.");
+    return (-1);
+  }
+  enumerate = udev_enumerate_new (handle_udev);
+  udev_enumerate_add_match_subsystem (enumerate, "block");
+  udev_enumerate_add_match_property (enumerate, "DEVTYPE", "disk");
+  udev_enumerate_scan_devices (enumerate);
+  devices = udev_enumerate_get_list_entry (enumerate);
+  udev_list_entry_foreach (dev_list_entry, devices)
+  {
+    const char *path, *devpath;
+    path = udev_list_entry_get_name (dev_list_entry);
+    dev = udev_device_new_from_syspath (handle_udev, path);
+    devpath = udev_device_get_devnode (dev);
+
+    /* Query status with libatasmart */
+    smart_handle_disk (devpath);
+    udev_device_unref (dev);
+  }
+
+  udev_enumerate_unref (enumerate);
+  udev_unref (handle_udev);
+
+  return (0);
+} /* int smart_read */
+
+void module_register (void)
+{
+  plugin_register_config ("smart", smart_config,
+                          config_keys, config_keys_num);
+  plugin_register_read ("smart", smart_read);
+} /* void module_register */
index 858d44c563f9cc64e9de09ded4423d1b04e5eef4..8564c681705669a9d71901a2051e329a1a792b06 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;
 
@@ -404,9 +404,9 @@ static int csnmp_config_add_data (oconfig_item_t *ci)
     oconfig_item_t *option = ci->children + i;
 
     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)
@@ -414,9 +414,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);
@@ -450,6 +454,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);
   }
@@ -471,50 +476,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;
@@ -527,9 +488,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);
   }
 
@@ -589,6 +550,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;
@@ -600,12 +647,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);
@@ -613,12 +654,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;
@@ -629,15 +667,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);
@@ -656,12 +708,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) */
@@ -723,15 +820,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);
@@ -835,7 +992,8 @@ static value_t csnmp_value_list_to_value (struct variable_list *vl, int type,
       status = parse_value (string, &ret, type);
       if (status != 0)
       {
-        ERROR ("snmp plugin: csnmp_value_list_to_value: Parsing string as %s failed: %s",
+        ERROR ("snmp plugin: host %s: csnmp_value_list_to_value: Parsing string as %s failed: %s",
+            (host_name != NULL) ? host_name : "UNKNOWN",
             DS_TYPE_TO_STRING (type), string);
       }
     }
@@ -970,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;
@@ -1003,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))
@@ -1366,7 +1548,8 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data)
         if (csnmp_instance_list_add (&instance_list_head, &instance_list_tail,
               res, host, data) != 0)
         {
-          ERROR ("snmp plugin: csnmp_instance_list_add failed.");
+          ERROR ("snmp plugin: host %s: csnmp_instance_list_add failed.",
+              host->name);
           status = -1;
           break;
         }
@@ -1662,6 +1845,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 1512b866a870a12da60a3fce6f969c48b3e9bda9..5b0bdd693de71088f8ec47f3560b29c4c87f79f5 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 fb50cf38bae32639361d3e4d1ae1aaa4a0348452..cfde4ea6d2bd9d194abbab16d4d2269e7347e114 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);
@@ -190,44 +187,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, DS_TYPE_GAUGE,
+                               "used", used, "free", free,
+                               other_name, other_value, NULL);
+       if (values_percentage)
+               plugin_dispatch_multivalue (&vl, 1, DS_TYPE_GAUGE,
+                               "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
 
@@ -253,9 +256,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)
@@ -266,7 +268,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;
 
@@ -276,13 +278,11 @@ 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 * 1024.0, (total - used) * 1024.0,
+                               NULL, NAN);
        }
 
        fclose (fh);
@@ -295,11 +295,10 @@ static int swap_read_combined (void) /* {{{ */
        FILE *fh;
        char buffer[1024];
 
-       uint8_t have_data = 0;
-       gauge_t swap_used   = 0.0;
-       gauge_t swap_cached = 0.0;
-       gauge_t swap_free   = 0.0;
-       gauge_t swap_total  = 0.0;
+       gauge_t swap_used   = NAN;
+       gauge_t swap_cached = NAN;
+       gauge_t swap_free   = NAN;
+       gauge_t swap_total  = NAN;
 
        fh = fopen ("/proc/meminfo", "r");
        if (fh == NULL)
@@ -320,39 +319,31 @@ static int swap_read_combined (void) /* {{{ */
                        continue;
 
                if (strcasecmp (fields[0], "SwapTotal:") == 0)
-               {
-                       swap_total = strtod (fields[1], /* endptr = */ NULL);
-                       have_data |= 0x01;
-               }
+                       strtogauge (fields[1], &swap_total);
                else if (strcasecmp (fields[0], "SwapFree:") == 0)
-               {
-                       swap_free = strtod (fields[1], /* endptr = */ NULL);
-                       have_data |= 0x02;
-               }
+                       strtogauge (fields[1], &swap_free);
                else if (strcasecmp (fields[0], "SwapCached:") == 0)
-               {
-                       swap_cached = strtod (fields[1], /* endptr = */ NULL);
-                       have_data |= 0x04;
-               }
+                       strtogauge (fields[1], &swap_cached);
        }
 
        fclose (fh);
 
-       if ((have_data & 0x03) != 0x03)
+       if (isnan (swap_total) || isnan (swap_free))
                return (ENOENT);
 
-       if (isnan (swap_total)
-                       || (swap_total <= 0.0)
-                       || ((swap_free + swap_cached) > swap_total))
-               return (EINVAL);
-
-       swap_used = swap_total - (swap_free + swap_cached);
+       /* Some systems, OpenVZ for example, don't provide SwapCached. */
+       if (isnan (swap_cached))
+               swap_used = swap_total - swap_free;
+       else
+               swap_used = swap_total - (swap_free + swap_cached);
+       assert (!isnan (swap_used));
 
-       swap_submit_gauge (NULL, "used",   1024.0 * swap_used);
-       swap_submit_gauge (NULL, "free",   1024.0 * swap_free);
-       if (have_data & 0x04)
-               swap_submit_gauge (NULL, "cached", 1024.0 * swap_cached);
+       if (swap_used < 0.0)
+               return (EINVAL);
 
+       swap_submit_usage (NULL, swap_used * 1024.0, swap_free * 1024.0,
+                       isnan (swap_cached) ? NULL : "cached",
+                       isnan (swap_cached) ? NAN : swap_cached * 1024.0);
        return (0);
 } /* }}} int swap_read_combined */
 
@@ -430,8 +421,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 +453,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 +488,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 +507,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 +571,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 +591,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 +623,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 +653,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 +701,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 +715,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 +726,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 *= (derive_t) kvm_pagesize;
-       used  *= (derive_t) kvm_pagesize;
+       total = (gauge_t) data_s.ksw_total;
+       used  = (gauge_t) data_s.ksw_used;
 
-       free = total - used;
+       total *= (gauge_t) kvm_pagesize;
+       used  *= (gauge_t) kvm_pagesize;
 
-       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 +744,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 +757,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 +788,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 834ba79ce8395446f365d8079b0217e97fa3e4b5..3f73178fa5e09283dec5efee71f57a3d941b0735 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"
index a3bacc7ae6e73b2e7f7b587f25833a9cd9374e7a..beded1ae9eeafef7e7bbfe0232ee80e954622fbe 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 5b9dc53988c46440c839878253385dd097f8d3ad..3904f1be201acb31c089057bfe189d78e7e8c5ed 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 i;
@@ -230,21 +243,22 @@ static int ctail_config_add_file (oconfig_item_t *ci)
   for (i = 0; i < ci->children_num; i++)
   {
     oconfig_item_t *option = ci->children + i;
-    int status;
+    int status = 0;
 
-    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;
     }
 
@@ -274,6 +288,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++;
   }
 
@@ -299,41 +314,45 @@ 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++;
-    }
+  memset(&ud, '\0', sizeof(ud));
+
+  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)
 {
@@ -354,7 +373,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 7908a29b9bfdc0e3af00d852a8e93c48c156e7c7..ceb454ecba7bb6e8579e27044468c876310437e0 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 1d7af5c35d0b01a98ab1f9170b6e361fa8f41913..a85eced33532a75b7e81732ec7755ded9d2c1f66 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 bef03e58769cd147ee6fcf0efe8f15cf87f46c43..b29a02bfa64801d9e967294ba4d1af7e6ce0cb48 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 2fb9cee5665cbb463bcdb87dd1245116543b5587..daeaf8be62f7c2d9779b66f2643dd0e447ac6bd5 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"
@@ -33,57 +38,25 @@ struct ts_data_s
 };
 typedef struct ts_data_s ts_data_t;
 
-static char *ts_strdup (const char *orig) /* {{{ */
-{
-  size_t sz;
-  char *dest;
-
-  if (orig == NULL)
-    return (NULL);
-
-  sz = strlen (orig) + 1;
-  dest = (char *) malloc (sz);
-  if (dest == NULL)
-    return (NULL);
-
-  memcpy (dest, orig, sz);
-
-  return (dest);
-} /* }}} char *ts_strdup */
-
 static int ts_config_add_string (char **dest, /* {{{ */
     const oconfig_item_t *ci, int may_be_empty)
 {
-  char *temp;
-
-  if (dest == NULL)
-    return (-EINVAL);
+  char *tmp = NULL;
+  int status;
 
-  if ((ci->values_num != 1)
-      || (ci->values[0].type != OCONFIG_TYPE_STRING))
-  {
-    ERROR ("Target `set': The `%s' option requires exactly one string "
-        "argument.", ci->key);
-    return (-1);
-  }
+  status = cf_util_get_string (ci, &tmp);
+  if (status != 0)
+    return (status);
 
-  if ((!may_be_empty) && (ci->values[0].value.string[0] == 0))
+  if (!may_be_empty && (strlen (tmp) == 0))
   {
     ERROR ("Target `set': The `%s' option does not accept empty strings.",
         ci->key);
+    sfree (tmp);
     return (-1);
   }
 
-  temp = ts_strdup (ci->values[0].value.string);
-  if (temp == NULL)
-  {
-    ERROR ("ts_config_add_string: ts_strdup failed.");
-    return (-1);
-  }
-
-  free (*dest);
-  *dest = temp;
-
+  *dest = tmp;
   return (0);
 } /* }}} int ts_config_add_string */
 
index 25f4637d15b8afd75363b3256f8a78ca45aa4788..d85a181fb933d9fbdda91c8c366539834fbf8586 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 bf07a2a28b99f69c6c135bec7a1fb55872b7161a..5d4bb6966f98b024e57ffc7fd0956082777212ab 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"
 };
 
@@ -272,12 +272,15 @@ static const char *config_keys[] =
 {
   "ListeningPorts",
   "LocalPort",
-  "RemotePort"
+  "RemotePort",
+  "AllPortsSummary"
 };
 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
 
 static int port_collect_listening = 0;
+static int port_collect_total = 0;
 static port_entry_t *port_list_head = NULL;
+static uint32_t count_total[TCP_STATE_MAX + 1];
 
 #if KERNEL_LINUX
 #if HAVE_STRUCT_LINUX_INET_DIAG_REQ
@@ -295,17 +298,22 @@ enum
 } linux_source = SRC_DUNNO;
 #endif
 
+static void conn_prepare_vl (value_list_t *vl, value_t *values)
+{
+  vl->values = values;
+  vl->values_len = 1;
+  sstrncpy (vl->host, hostname_g, sizeof (vl->host));
+  sstrncpy (vl->plugin, "tcpconns", sizeof (vl->plugin));
+  sstrncpy (vl->type, "tcp_connections", sizeof (vl->type));
+}
+
 static void conn_submit_port_entry (port_entry_t *pe)
 {
   value_t values[1];
   value_list_t vl = VALUE_LIST_INIT;
   int i;
 
-  vl.values = values;
-  vl.values_len = 1;
-  sstrncpy (vl.host, hostname_g, sizeof (vl.host));
-  sstrncpy (vl.plugin, "tcpconns", sizeof (vl.plugin));
-  sstrncpy (vl.type, "tcp_connections", sizeof (vl.type));
+  conn_prepare_vl (&vl, values);
 
   if (((port_collect_listening != 0) && (pe->flags & PORT_IS_LISTENING))
       || (pe->flags & PORT_COLLECT_LOCAL))
@@ -339,10 +347,33 @@ static void conn_submit_port_entry (port_entry_t *pe)
   }
 } /* void conn_submit */
 
+static void conn_submit_port_total (void)
+{
+  value_t values[1];
+  value_list_t vl = VALUE_LIST_INIT;
+  int i;
+
+  conn_prepare_vl (&vl, values);
+
+  sstrncpy (vl.plugin_instance, "all", sizeof (vl.plugin_instance));
+
+  for (i = 1; i <= TCP_STATE_MAX; i++)
+  {
+    vl.values[0].gauge = count_total[i];
+
+    sstrncpy (vl.type_instance, tcp_state[i], sizeof (vl.type_instance));
+
+    plugin_dispatch_values (&vl);
+  }
+}
+
 static void conn_submit_all (void)
 {
   port_entry_t *pe;
 
+  if (port_collect_total)
+    conn_submit_port_total ();
+
   for (pe = port_list_head; pe != NULL; pe = pe->next)
     conn_submit_port_entry (pe);
 } /* void conn_submit_all */
@@ -381,6 +412,8 @@ static void conn_reset_port_entry (void)
   port_entry_t *prev = NULL;
   port_entry_t *pe = port_list_head;
 
+  memset (&count_total, '\0', sizeof(count_total));
+
   while (pe != NULL)
   {
     /* If this entry was created while reading the files (ant not when handling
@@ -429,6 +462,8 @@ static int conn_handle_ports (uint16_t port_local, uint16_t port_remote, uint8_t
     return (-1);
   }
 
+  count_total[state]++;
+
   /* Listening sockets */
   if ((state == TCP_STATE_LISTEN) && (port_collect_listening != 0))
   {
@@ -705,6 +740,13 @@ static int conn_config (const char *key, const char *value)
       else
        pe->flags |= PORT_COLLECT_REMOTE;
   }
+  else if (strcasecmp (key, "AllPortsSummary") == 0)
+  {
+    if (IS_TRUE (value))
+      port_collect_total = 1;
+    else
+      port_collect_total = 0;
+  }
   else
   {
     return (-1);
@@ -716,7 +758,7 @@ static int conn_config (const char *key, const char *value)
 #if KERNEL_LINUX
 static int conn_init (void)
 {
-  if (port_list_head == NULL)
+  if (port_collect_total == 0 && port_list_head == NULL)
     port_collect_listening = 1;
 
   return (0);
@@ -910,7 +952,9 @@ static int conn_init (void)
 static int conn_read (void)
 {
   struct inpcbtable table;
+#if !defined(__OpenBSD__) && (defined(__NetBSD_Version__) && __NetBSD_Version__ <= 699002700)
   struct inpcb *head;
+#endif
   struct inpcb *next;
   struct inpcb inpcb;
   struct tcpcb tcpcb;
@@ -923,12 +967,19 @@ static int conn_read (void)
   if (status != 0)
     return (-1);
 
+#if defined(__OpenBSD__) || (defined(__NetBSD_Version__) && __NetBSD_Version__ > 699002700)
+  /* inpt_queue is a TAILQ on OpenBSD */
+  /* Get the first pcb */
+  next = (struct inpcb *)TAILQ_FIRST (&table.inpt_queue);
+  while (next)
+#else
   /* Get the `head' pcb */
   head = (struct inpcb *) &(inpcbtable_ptr->inpt_queue);
   /* Get the first pcb */
   next = (struct inpcb *)CIRCLEQ_FIRST (&table.inpt_queue);
 
   while (next != head)
+#endif
   {
     /* Read the pcb pointed to by `next' into `inpcb' */
     status = kread ((u_long) next, &inpcb, sizeof (inpcb));
@@ -936,7 +987,12 @@ static int conn_read (void)
       return (-1);
 
     /* Advance `next' */
+#if defined(__OpenBSD__) || (defined(__NetBSD_Version__) && __NetBSD_Version__ > 699002700)
+    /* inpt_queue is a TAILQ on OpenBSD */
+    next = (struct inpcb *)TAILQ_NEXT (&inpcb, inp_queue);
+#else
     next = (struct inpcb *)CIRCLEQ_NEXT (&inpcb, inp_queue);
+#endif
 
     /* Ignore sockets, that are not connected. */
 #ifdef __NetBSD__
index 2552ad305ffcaa51decb9ab490764a1cc907e4fb..201e1828a2b2037093fde4b02c45709a53d6d062 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/testing.h b/src/testing.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)
index 391ee932aed1acf208bbd75c5fb56b243605ae0d..8dcb711d5e6004bb82d266b8d9e950242681c50d 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
  * =============
@@ -624,7 +514,10 @@ static int ut_report_state (const data_set_t *ds,
     if (state_old == STATE_MISSING)
       ssnprintf (buf, bufsize, ": Value is no longer missing.");
     else
-      ssnprintf (buf, bufsize, ": All data sources are within range again.");
+      ssnprintf (buf, bufsize,
+          ": All data sources are within range again. "
+          "Current value of \"%s\" is %f.",
+          ds->ds[ds_index].name, values[ds_index]);
   }
   else
   {
@@ -738,23 +631,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]))
@@ -764,7 +674,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);
@@ -853,7 +763,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.
  */
@@ -984,7 +894,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 678a341c1ceeaf15f24a708d12567c1b8ed92f15..7fa621bfa4e9d9d0ea4cd196e80c7bcd9b42c957 100644 (file)
@@ -23,7 +23,6 @@
 #include "plugin.h"
 #include "common.h"
 #include "utils_cache.h"
-#include "utils_parse_option.h"
 
 #include <tcrdb.h>
 
diff --git a/src/turbostat.c b/src/turbostat.c
new file mode 100644 (file)
index 0000000..42fed52
--- /dev/null
@@ -0,0 +1,1624 @@
+/*
+ * turbostat -- Log CPU frequency and C-state residency
+ * on modern Intel turbo-capable processors for collectd.
+ *
+ * Based on the 'turbostat' tool of the Linux kernel, found at
+ * linux/tools/power/x86/turbostat/turbostat.c:
+ * ----
+ * Copyright (c) 2013 Intel Corporation.
+ * Len Brown <len.brown@intel.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ * ----
+ * Ported to collectd by Vincent Brillault <git@lerya.net>
+ */
+
+/*
+ * _GNU_SOURCE is required because of the following functions:
+ * - CPU_ISSET_S
+ * - CPU_ZERO_S
+ * - CPU_SET_S
+ * - CPU_FREE
+ * - CPU_ALLOC
+ * - CPU_ALLOC_SIZE
+ */
+#define _GNU_SOURCE
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+#include "utils_time.h"
+
+#include <asm/msr-index.h>
+#include <cpuid.h>
+#ifdef HAVE_SYS_CAPABILITY_H
+#include <sys/capability.h>
+#endif /* HAVE_SYS_CAPABILITY_H */
+
+#define PLUGIN_NAME "turbostat"
+
+/*
+ * This tool uses the Model-Specific Registers (MSRs) present on Intel processors.
+ * The general description each of these registers, depending on the architecture,
+ * can be found in the Intel® 64 and IA-32 Architectures Software Developer Manual,
+ * Volume 3 Chapter 35.
+ */
+
+/*
+ * If set, aperf_mperf_unstable disables a/mperf based stats.
+ * This includes: C0 & C1 states, frequency
+ *
+ * This value is automatically set if mperf or aperf go backward
+ */
+static _Bool aperf_mperf_unstable;
+
+/*
+ * Bitmask of the list of core C states supported by the processor.
+ * Currently supported C-states (by this plugin): 3, 6, 7
+ */
+static unsigned int do_core_cstate;
+static unsigned int config_core_cstate;
+static _Bool apply_config_core_cstate;
+
+/*
+ * Bitmask of the list of pacages C states supported by the processor.
+ * Currently supported C-states (by this plugin): 2, 3, 6, 7, 8, 9, 10
+ */
+static unsigned int do_pkg_cstate;
+static unsigned int config_pkg_cstate;
+static _Bool apply_config_pkg_cstate;
+
+/*
+ * Boolean indicating if the processor supports 'I/O System-Management Interrupt counter'
+ */
+static _Bool do_smi;
+static _Bool config_smi;
+static _Bool apply_config_smi;
+
+/*
+ * Boolean indicating if the processor supports 'Digital temperature sensor'
+ * This feature enables the monitoring of the temperature of each core
+ *
+ * This feature has two limitations:
+ *  - if MSR_IA32_TEMPERATURE_TARGET is not supported, the absolute temperature might be wrong
+ *  - Temperatures above the tcc_activation_temp are not recorded
+ */
+static _Bool do_dts;
+static _Bool config_dts;
+static _Bool apply_config_dts;
+
+/*
+ * Boolean indicating if the processor supports 'Package thermal management'
+ * This feature allows the monitoring of the temperature of each package
+ *
+ * This feature has two limitations:
+ *  - if MSR_IA32_TEMPERATURE_TARGET is not supported, the absolute temperature might be wrong
+ *  - Temperatures above the tcc_activation_temp are not recorded
+ */
+static _Bool do_ptm;
+static _Bool config_ptm;
+static _Bool apply_config_ptm;
+
+/*
+ * Thermal Control Circuit Activation Temperature as configured by the user.
+ * This override the automated detection via MSR_IA32_TEMPERATURE_TARGET
+ * and should only be used if the automated detection fails.
+ */
+static unsigned int tcc_activation_temp;
+
+static unsigned int do_rapl;
+static unsigned int config_rapl;
+static _Bool apply_config_rapl;
+static double rapl_energy_units;
+
+#define RAPL_PKG               (1 << 0)
+                                       /* 0x610 MSR_PKG_POWER_LIMIT */
+                                       /* 0x611 MSR_PKG_ENERGY_STATUS */
+#define RAPL_DRAM              (1 << 1)
+                                       /* 0x618 MSR_DRAM_POWER_LIMIT */
+                                       /* 0x619 MSR_DRAM_ENERGY_STATUS */
+                                       /* 0x61c MSR_DRAM_POWER_INFO */
+#define RAPL_CORES             (1 << 2)
+                                       /* 0x638 MSR_PP0_POWER_LIMIT */
+                                       /* 0x639 MSR_PP0_ENERGY_STATUS */
+
+#define RAPL_GFX               (1 << 3)
+                                       /* 0x640 MSR_PP1_POWER_LIMIT */
+                                       /* 0x641 MSR_PP1_ENERGY_STATUS */
+                                       /* 0x642 MSR_PP1_POLICY */
+#define        TJMAX_DEFAULT   100
+
+static cpu_set_t *cpu_present_set, *cpu_affinity_set, *cpu_saved_affinity_set;
+static size_t cpu_present_setsize, cpu_affinity_setsize, cpu_saved_affinity_setsize;
+
+static struct thread_data {
+       unsigned long long tsc;
+       unsigned long long aperf;
+       unsigned long long mperf;
+       unsigned long long c1;
+       unsigned int smi_count;
+       unsigned int cpu_id;
+       unsigned int flags;
+#define CPU_IS_FIRST_THREAD_IN_CORE    0x2
+#define CPU_IS_FIRST_CORE_IN_PACKAGE   0x4
+} *thread_delta, *thread_even, *thread_odd;
+
+static struct core_data {
+       unsigned long long c3;
+       unsigned long long c6;
+       unsigned long long c7;
+       unsigned int core_temp_c;
+       unsigned int core_id;
+} *core_delta, *core_even, *core_odd;
+
+static struct pkg_data {
+       unsigned long long pc2;
+       unsigned long long pc3;
+       unsigned long long pc6;
+       unsigned long long pc7;
+       unsigned long long pc8;
+       unsigned long long pc9;
+       unsigned long long pc10;
+       unsigned int package_id;
+       uint32_t energy_pkg;    /* MSR_PKG_ENERGY_STATUS */
+       uint32_t energy_dram;   /* MSR_DRAM_ENERGY_STATUS */
+       uint32_t energy_cores;  /* MSR_PP0_ENERGY_STATUS */
+       uint32_t energy_gfx;    /* MSR_PP1_ENERGY_STATUS */
+       unsigned int tcc_activation_temp;
+       unsigned int pkg_temp_c;
+} *package_delta, *package_even, *package_odd;
+
+#define DELTA_COUNTERS thread_delta, core_delta, package_delta
+#define ODD_COUNTERS thread_odd, core_odd, package_odd
+#define EVEN_COUNTERS thread_even, core_even, package_even
+static _Bool is_even = 1;
+
+static _Bool allocated = 0;
+static _Bool initialized = 0;
+
+#define GET_THREAD(thread_base, thread_no, core_no, pkg_no) \
+       (thread_base + \
+               (pkg_no) * topology.num_cores * topology.num_threads + \
+               (core_no) * topology.num_threads + \
+               (thread_no))
+#define GET_CORE(core_base, core_no, pkg_no) \
+       (core_base + \
+               (pkg_no) * topology.num_cores + \
+               (core_no))
+#define GET_PKG(pkg_base, pkg_no) (pkg_base + pkg_no)
+
+struct cpu_topology {
+       unsigned int package_id;
+       unsigned int core_id;
+       _Bool first_core_in_package;
+       _Bool first_thread_in_core;
+};
+
+static struct topology {
+       unsigned int max_cpu_id;
+       unsigned int num_packages;
+       unsigned int num_cores;
+       unsigned int num_threads;
+       struct cpu_topology *cpus;
+} topology;
+
+static cdtime_t time_even, time_odd, time_delta;
+
+static const char *config_keys[] =
+{
+       "CoreCstates",
+       "PackageCstates",
+       "SystemManagementInterrupt",
+       "DigitalTemperatureSensor",
+       "PackageThermalManagement",
+       "TCCActivationTemp",
+       "RunningAveragePowerLimit",
+};
+static const int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+
+/*****************************
+ *  MSR Manipulation helpers *
+ *****************************/
+
+/*
+ * Open a MSR device for reading
+ * Can change the scheduling affinity of the current process if multiple_read is 1
+ */
+static int __attribute__((warn_unused_result))
+open_msr(unsigned int cpu, _Bool multiple_read)
+{
+       char pathname[32];
+       int fd;
+
+       /*
+        * If we need to do multiple read, let's migrate to the CPU
+        * Otherwise, we would lose time calling functions on another CPU
+        *
+        * If we are not yet initialized (cpu_affinity_setsize = 0),
+        * we need to skip this optimisation.
+        */
+       if (multiple_read && cpu_affinity_setsize) {
+               CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set);
+               CPU_SET_S(cpu, cpu_affinity_setsize, cpu_affinity_set);
+               if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1) {
+                       ERROR("turbostat plugin: Could not migrate to CPU %d", cpu);
+                       return -1;
+               }
+       }
+
+       ssnprintf(pathname, sizeof(pathname), "/dev/cpu/%d/msr", cpu);
+       fd = open(pathname, O_RDONLY);
+       if (fd < 0) {
+               ERROR("turbostat plugin: failed to open %s", pathname);
+               return -1;
+       }
+       return fd;
+}
+
+/*
+ * Read a single MSR from an open file descriptor
+ */
+static int __attribute__((warn_unused_result))
+read_msr(int fd, off_t offset, unsigned long long *msr)
+{
+       ssize_t retval;
+
+       retval = pread(fd, msr, sizeof *msr, offset);
+
+       if (retval != sizeof *msr) {
+               ERROR("turbostat plugin: MSR offset 0x%llx read failed",
+                     (unsigned long long)offset);
+               return -1;
+       }
+       return 0;
+}
+
+/*
+ * Open a MSR device for reading, read the value asked for and close it.
+ * This call will not affect the scheduling affinity of this thread.
+ */
+static ssize_t __attribute__((warn_unused_result))
+get_msr(unsigned int cpu, off_t offset, unsigned long long *msr)
+{
+       ssize_t retval;
+       int fd;
+
+       fd = open_msr(cpu, 0);
+       if (fd < 0)
+               return fd;
+       retval = read_msr(fd, offset, msr);
+       close(fd);
+       return retval;
+}
+
+
+/********************************
+ * Raw data acquisition (1 CPU) *
+ ********************************/
+
+/*
+ * Read every data avalaible for a single CPU
+ *
+ * Core data is shared for all threads in one core: extracted only for the first thread
+ * Package data is shared for all core in one package: extracted only for the first thread of the first core
+ *
+ * Side effect: migrates to the targeted CPU
+ */
+static int __attribute__((warn_unused_result))
+get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
+{
+       unsigned int cpu = t->cpu_id;
+       unsigned long long msr;
+       int msr_fd;
+       int retval = 0;
+
+       msr_fd = open_msr(cpu, 1);
+       if (msr_fd < 0)
+               return msr_fd;
+
+#define READ_MSR(msr, dst)                                             \
+do {                                                                   \
+       if (read_msr(msr_fd, msr, dst)) {                               \
+               ERROR("turbostat plugin: Unable to read " #msr);        \
+               retval = -1;                                            \
+               goto out;                                               \
+       }                                                               \
+} while (0)
+
+       READ_MSR(MSR_IA32_TSC, &t->tsc);
+
+       READ_MSR(MSR_IA32_APERF, &t->aperf);
+       READ_MSR(MSR_IA32_MPERF, &t->mperf);
+
+       if (do_smi) {
+               READ_MSR(MSR_SMI_COUNT, &msr);
+               t->smi_count = msr & 0xFFFFFFFF;
+       }
+
+       /* collect core counters only for 1st thread in core */
+       if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) {
+               retval = 0;
+               goto out;
+       }
+
+       if (do_core_cstate & (1 << 3))
+               READ_MSR(MSR_CORE_C3_RESIDENCY, &c->c3);
+       if (do_core_cstate & (1 << 6))
+               READ_MSR(MSR_CORE_C6_RESIDENCY, &c->c6);
+       if (do_core_cstate & (1 << 7))
+               READ_MSR(MSR_CORE_C7_RESIDENCY, &c->c7);
+
+       if (do_dts) {
+               READ_MSR(MSR_IA32_THERM_STATUS, &msr);
+               c->core_temp_c = p->tcc_activation_temp - ((msr >> 16) & 0x7F);
+       }
+
+       /* collect package counters only for 1st core in package */
+       if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) {
+               retval = 0;
+               goto out;
+       }
+
+       if (do_pkg_cstate & (1 << 2))
+               READ_MSR(MSR_PKG_C2_RESIDENCY, &p->pc2);
+       if (do_pkg_cstate & (1 << 3))
+               READ_MSR(MSR_PKG_C3_RESIDENCY, &p->pc3);
+       if (do_pkg_cstate & (1 << 6))
+               READ_MSR(MSR_PKG_C6_RESIDENCY, &p->pc6);
+       if (do_pkg_cstate & (1 << 7))
+               READ_MSR(MSR_PKG_C7_RESIDENCY, &p->pc7);
+       if (do_pkg_cstate & (1 << 8))
+               READ_MSR(MSR_PKG_C8_RESIDENCY, &p->pc8);
+       if (do_pkg_cstate & (1 << 9))
+               READ_MSR(MSR_PKG_C9_RESIDENCY, &p->pc9);
+       if (do_pkg_cstate & (1 << 10))
+               READ_MSR(MSR_PKG_C10_RESIDENCY, &p->pc10);
+
+       if (do_rapl & RAPL_PKG) {
+               READ_MSR(MSR_PKG_ENERGY_STATUS, &msr);
+               p->energy_pkg = msr & 0xFFFFFFFF;
+       }
+       if (do_rapl & RAPL_CORES) {
+               READ_MSR(MSR_PP0_ENERGY_STATUS, &msr);
+               p->energy_cores = msr & 0xFFFFFFFF;
+       }
+       if (do_rapl & RAPL_DRAM) {
+               READ_MSR(MSR_DRAM_ENERGY_STATUS, &msr);
+               p->energy_dram = msr & 0xFFFFFFFF;
+       }
+       if (do_rapl & RAPL_GFX) {
+               READ_MSR(MSR_PP1_ENERGY_STATUS, &msr);
+               p->energy_gfx = msr & 0xFFFFFFFF;
+       }
+       if (do_ptm) {
+               READ_MSR(MSR_IA32_PACKAGE_THERM_STATUS, &msr);
+               p->pkg_temp_c = p->tcc_activation_temp - ((msr >> 16) & 0x7F);
+       }
+
+out:
+       close(msr_fd);
+       return retval;
+}
+
+
+/**********************************
+ * Evaluating the changes (1 CPU) *
+ **********************************/
+
+/*
+ * Extract the evolution old->new in delta at a package level
+ * (some are not new-delta, e.g. temperature)
+ */
+static inline void
+delta_package(struct pkg_data *delta, const struct pkg_data *new, const struct pkg_data *old)
+{
+       delta->pc2 = new->pc2 - old->pc2;
+       delta->pc3 = new->pc3 - old->pc3;
+       delta->pc6 = new->pc6 - old->pc6;
+       delta->pc7 = new->pc7 - old->pc7;
+       delta->pc8 = new->pc8 - old->pc8;
+       delta->pc9 = new->pc9 - old->pc9;
+       delta->pc10 = new->pc10 - old->pc10;
+       delta->pkg_temp_c = new->pkg_temp_c;
+
+       delta->energy_pkg = new->energy_pkg - old->energy_pkg;
+       delta->energy_cores = new->energy_cores - old->energy_cores;
+       delta->energy_gfx = new->energy_gfx - old->energy_gfx;
+       delta->energy_dram = new->energy_dram - old->energy_dram;
+}
+
+/*
+ * Extract the evolution old->new in delta at a core level
+ * (some are not new-delta, e.g. temperature)
+ */
+static inline void
+delta_core(struct core_data *delta, const struct core_data *new, const struct core_data *old)
+{
+       delta->c3 = new->c3 - old->c3;
+       delta->c6 = new->c6 - old->c6;
+       delta->c7 = new->c7 - old->c7;
+       delta->core_temp_c = new->core_temp_c;
+}
+
+/*
+ * Extract the evolution old->new in delta at a package level
+ * core_delta is required for c1 estimation (tsc - c0 - all core cstates)
+ */
+static inline int __attribute__((warn_unused_result))
+delta_thread(struct thread_data *delta, const struct thread_data *new, const struct thread_data *old,
+       const struct core_data *core_delta)
+{
+       delta->tsc = new->tsc - old->tsc;
+
+       /* check for TSC < 1 Mcycles over interval */
+       if (delta->tsc < (1000 * 1000)) {
+               WARNING("turbostat plugin: Insanely slow TSC rate, TSC stops "
+                       "in idle? You can disable all c-states by booting with"
+                       " 'idle=poll' or just the deep ones with"
+                       " 'processor.max_cstate=1'");
+               return -1;
+       }
+
+       delta->c1 = new->c1 - old->c1;
+
+       if ((new->aperf > old->aperf) && (new->mperf > old->mperf)) {
+               delta->aperf = new->aperf - old->aperf;
+               delta->mperf = new->mperf - old->mperf;
+       } else {
+               if (!aperf_mperf_unstable) {
+                       WARNING("turbostat plugin: APERF or MPERF went "
+                               "backwards. Frequency results do not cover "
+                               "the entire interval. Fix this by running "
+                               "Linux-2.6.30 or later.");
+
+                       aperf_mperf_unstable = 1;
+               }
+       }
+
+       /*
+        * As counter collection is not atomic,
+        * it is possible for mperf's non-halted cycles + idle states
+        * to exceed TSC's all cycles: show c1 = 0% in that case.
+        */
+       if ((delta->mperf + core_delta->c3 + core_delta->c6 + core_delta->c7) > delta->tsc)
+               delta->c1 = 0;
+       else {
+               /* normal case, derive c1 */
+               delta->c1 = delta->tsc - delta->mperf - core_delta->c3
+                       - core_delta->c6 - core_delta->c7;
+       }
+
+       if (delta->mperf == 0) {
+               WARNING("turbostat plugin: cpu%d MPERF 0!", old->cpu_id);
+               delta->mperf = 1;       /* divide by 0 protection */
+       }
+
+       if (do_smi)
+               delta->smi_count = new->smi_count - old->smi_count;
+
+       return 0;
+}
+
+/**********************************
+ * Submitting the results (1 CPU) *
+ **********************************/
+
+/*
+ * Submit one gauge value
+ */
+static void
+turbostat_submit (const char *plugin_instance,
+       const char *type, const char *type_instance,
+       gauge_t value)
+{
+       value_list_t vl = VALUE_LIST_INIT;
+       value_t v;
+
+       v.gauge = value;
+       vl.values = &v;
+       vl.values_len = 1;
+       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       sstrncpy (vl.plugin, PLUGIN_NAME, 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);
+}
+
+/*
+ * Submit every data for a single CPU
+ *
+ * Core data is shared for all threads in one core: submitted only for the first thread
+ * Package data is shared for all core in one package: submitted only for the first thread of the first core
+ */
+static int
+submit_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
+{
+       char name[DATA_MAX_NAME_LEN];
+       double interval_float;
+
+       interval_float = CDTIME_T_TO_DOUBLE(time_delta);
+
+       ssnprintf(name, sizeof(name), "cpu%02d", t->cpu_id);
+
+       if (!aperf_mperf_unstable)
+               turbostat_submit(name, "percent", "c0", 100.0 * t->mperf/t->tsc);
+       if (!aperf_mperf_unstable)
+               turbostat_submit(name, "percent", "c1", 100.0 * t->c1/t->tsc);
+
+       turbostat_submit(name, "frequency", "average", 1.0 / 1000000 * t->aperf / interval_float);
+
+       if ((!aperf_mperf_unstable) || (!(t->aperf > t->tsc || t->mperf > t->tsc)))
+               turbostat_submit(name, "frequency", "busy", 1.0 * t->tsc / 1000000 * t->aperf / t->mperf / interval_float);
+
+       /* Sanity check (should stay stable) */
+       turbostat_submit(name, "gauge", "TSC", 1.0 * t->tsc / 1000000 / interval_float);
+
+       /* SMI */
+       if (do_smi)
+               turbostat_submit(name, "count", NULL, t->smi_count);
+
+       /* submit per-core data only for 1st thread in core */
+       if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE))
+               goto done;
+
+       ssnprintf(name, sizeof(name), "core%02d", c->core_id);
+
+       if (do_core_cstate & (1 << 3))
+               turbostat_submit(name, "percent", "c3", 100.0 * c->c3/t->tsc);
+       if (do_core_cstate & (1 << 6))
+               turbostat_submit(name, "percent", "c6", 100.0 * c->c6/t->tsc);
+       if (do_core_cstate & (1 << 7))
+               turbostat_submit(name, "percent", "c7", 100.0 * c->c7/t->tsc);
+
+       if (do_dts)
+               turbostat_submit(name, "temperature", NULL, c->core_temp_c);
+
+       /* submit per-package data only for 1st core in package */
+       if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE))
+               goto done;
+
+       ssnprintf(name, sizeof(name), "pkg%02d", p->package_id);
+
+       if (do_ptm)
+               turbostat_submit(name, "temperature", NULL, p->pkg_temp_c);
+
+       if (do_pkg_cstate & (1 << 2))
+               turbostat_submit(name, "percent", "pc2", 100.0 * p->pc2/t->tsc);
+       if (do_pkg_cstate & (1 << 3))
+               turbostat_submit(name, "percent", "pc3", 100.0 * p->pc3/t->tsc);
+       if (do_pkg_cstate & (1 << 6))
+               turbostat_submit(name, "percent", "pc6", 100.0 * p->pc6/t->tsc);
+       if (do_pkg_cstate & (1 << 7))
+               turbostat_submit(name, "percent", "pc7", 100.0 * p->pc7/t->tsc);
+       if (do_pkg_cstate & (1 << 8))
+               turbostat_submit(name, "percent", "pc8", 100.0 * p->pc8/t->tsc);
+       if (do_pkg_cstate & (1 << 9))
+               turbostat_submit(name, "percent", "pc9", 100.0 * p->pc9/t->tsc);
+       if (do_pkg_cstate & (1 << 10))
+               turbostat_submit(name, "percent", "pc10", 100.0 * p->pc10/t->tsc);
+
+       if (do_rapl) {
+               if (do_rapl & RAPL_PKG)
+                       turbostat_submit(name, "power", "pkg", p->energy_pkg * rapl_energy_units / interval_float);
+               if (do_rapl & RAPL_CORES)
+                       turbostat_submit(name, "power", "cores", p->energy_cores * rapl_energy_units / interval_float);
+               if (do_rapl & RAPL_GFX)
+                       turbostat_submit(name, "power", "GFX", p->energy_gfx * rapl_energy_units / interval_float);
+               if (do_rapl & RAPL_DRAM)
+                       turbostat_submit(name, "power", "DRAM", p->energy_dram * rapl_energy_units / interval_float);
+       }
+done:
+       return 0;
+}
+
+
+/**********************************
+ * Looping function over all CPUs *
+ **********************************/
+
+/*
+ * Check if a given cpu id is in our compiled list of existing CPUs
+ */
+static int
+cpu_is_not_present(unsigned int cpu)
+{
+       return !CPU_ISSET_S(cpu, cpu_present_setsize, cpu_present_set);
+}
+
+/*
+ * Loop on all CPUs in topological order
+ *
+ * Skip non-present cpus
+ * Return the error code at the first error or 0
+ */
+static int __attribute__((warn_unused_result))
+for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg_data *),
+       struct thread_data *thread_base, struct core_data *core_base, struct pkg_data *pkg_base)
+{
+       int retval;
+       unsigned int pkg_no, core_no, thread_no;
+
+       for (pkg_no = 0; pkg_no < topology.num_packages; ++pkg_no) {
+               for (core_no = 0; core_no < topology.num_cores; ++core_no) {
+                       for (thread_no = 0; thread_no < topology.num_threads; ++thread_no) {
+                               struct thread_data *t;
+                               struct core_data *c;
+                               struct pkg_data *p;
+
+                               t = GET_THREAD(thread_base, thread_no, core_no, pkg_no);
+
+                               if (cpu_is_not_present(t->cpu_id))
+                                       continue;
+
+                               c = GET_CORE(core_base, core_no, pkg_no);
+                               p = GET_PKG(pkg_base, pkg_no);
+
+                               retval = func(t, c, p);
+                               if (retval)
+                                       return retval;
+                       }
+               }
+       }
+       return 0;
+}
+
+/*
+ * Dedicated loop: Extract every data evolution for all CPU
+ *
+ * Skip non-present cpus
+ * Return the error code at the first error or 0
+ *
+ * Core data is shared for all threads in one core: extracted only for the first thread
+ * Package data is shared for all core in one package: extracted only for the first thread of the first core
+ */
+static int __attribute__((warn_unused_result))
+for_all_cpus_delta(const struct thread_data *thread_new_base, const struct core_data *core_new_base, const struct pkg_data *pkg_new_base,
+                  const struct thread_data *thread_old_base, const struct core_data *core_old_base, const struct pkg_data *pkg_old_base)
+{
+       int retval;
+       unsigned int pkg_no, core_no, thread_no;
+
+       for (pkg_no = 0; pkg_no < topology.num_packages; ++pkg_no) {
+               for (core_no = 0; core_no < topology.num_cores; ++core_no) {
+                       for (thread_no = 0; thread_no < topology.num_threads; ++thread_no) {
+                               struct thread_data *t_delta;
+                               const struct thread_data *t_old, *t_new;
+                               struct core_data *c_delta;
+
+                               /* Get correct pointers for threads */
+                               t_delta = GET_THREAD(thread_delta, thread_no, core_no, pkg_no);
+                               t_new = GET_THREAD(thread_new_base, thread_no, core_no, pkg_no);
+                               t_old = GET_THREAD(thread_old_base, thread_no, core_no, pkg_no);
+
+                               /* Skip threads that disappeared */
+                               if (cpu_is_not_present(t_delta->cpu_id))
+                                       continue;
+
+                               /* c_delta is always required for delta_thread */
+                               c_delta = GET_CORE(core_delta, core_no, pkg_no);
+
+                               /* calculate core delta only for 1st thread in core */
+                               if (t_new->flags & CPU_IS_FIRST_THREAD_IN_CORE) {
+                                       const struct core_data *c_old, *c_new;
+
+                                       c_new = GET_CORE(core_new_base, core_no, pkg_no);
+                                       c_old = GET_CORE(core_old_base, core_no, pkg_no);
+
+                                       delta_core(c_delta, c_new, c_old);
+                               }
+
+                               /* Always calculate thread delta */
+                               retval = delta_thread(t_delta, t_new, t_old, c_delta);
+                               if (retval)
+                                       return retval;
+
+                               /* calculate package delta only for 1st core in package */
+                               if (t_new->flags & CPU_IS_FIRST_CORE_IN_PACKAGE) {
+                                       struct pkg_data *p_delta;
+                                       const struct pkg_data *p_old, *p_new;
+
+                                       p_delta = GET_PKG(package_delta, pkg_no);
+                                       p_new = GET_PKG(pkg_new_base, pkg_no);
+                                       p_old = GET_PKG(pkg_old_base, pkg_no);
+
+                                       delta_package(p_delta, p_new, p_old);
+                               }
+                       }
+               }
+       }
+       return 0;
+}
+
+
+/***************
+ * CPU Probing *
+ ***************/
+
+/*
+ * MSR_IA32_TEMPERATURE_TARGET indicates the temperature where
+ * the Thermal Control Circuit (TCC) activates.
+ * This is usually equal to tjMax.
+ *
+ * Older processors do not have this MSR, so there we guess,
+ * but also allow conficuration over-ride with "TCCActivationTemp".
+ *
+ * Several MSR temperature values are in units of degrees-C
+ * below this value, including the Digital Thermal Sensor (DTS),
+ * Package Thermal Management Sensor (PTM), and thermal event thresholds.
+ */
+static int __attribute__((warn_unused_result))
+set_temperature_target(struct thread_data *t, struct core_data *c, struct pkg_data *p)
+{
+       unsigned long long msr;
+       unsigned int target_c_local;
+
+       /* tcc_activation_temp is used only for dts or ptm */
+       if (!(do_dts || do_ptm))
+               return 0;
+
+       /* this is a per-package concept */
+       if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE))
+               return 0;
+
+       if (tcc_activation_temp != 0) {
+               p->tcc_activation_temp = tcc_activation_temp;
+               return 0;
+       }
+
+       if (get_msr(t->cpu_id, MSR_IA32_TEMPERATURE_TARGET, &msr))
+               goto guess;
+
+       target_c_local = (msr >> 16) & 0xFF;
+
+       if (!target_c_local)
+               goto guess;
+
+       p->tcc_activation_temp = target_c_local;
+
+       return 0;
+
+guess:
+       p->tcc_activation_temp = TJMAX_DEFAULT;
+       WARNING("turbostat plugin: cpu%d: Guessing tjMax %d C,"
+               " Please use TCCActivationTemp to specify it.",
+               t->cpu_id, p->tcc_activation_temp);
+
+       return 0;
+}
+
+/*
+ * Identify the functionality of the CPU
+ */
+static int __attribute__((warn_unused_result))
+probe_cpu()
+{
+       unsigned int eax, ebx, ecx, edx, max_level;
+       unsigned int fms, family, model;
+
+       /* CPUID(0):
+        * - EAX: Maximum Input Value for Basic CPUID Information
+        * - EBX: "Genu" (0x756e6547)
+        * - EDX: "ineI" (0x49656e69)
+        * - ECX: "ntel" (0x6c65746e)
+        */
+       max_level = ebx = ecx = edx = 0;
+       __get_cpuid(0, &max_level, &ebx, &ecx, &edx);
+       if (ebx != 0x756e6547 && edx != 0x49656e69 && ecx != 0x6c65746e) {
+               ERROR("turbostat plugin: Unsupported CPU (not Intel)");
+               return -1;
+       }
+
+       /* CPUID(1):
+        * - EAX: Version Information: Type, Family, Model, and Stepping ID
+        *  + 4-7:   Model ID
+        *  + 8-11:  Family ID
+        *  + 12-13: Processor type
+        *  + 16-19: Extended Model ID
+        *  + 20-27: Extended Family ID
+        * - EDX: Feature Information:
+        *  + 5: Support for MSR read/write operations
+        */
+       fms = ebx = ecx = edx = 0;
+       __get_cpuid(1, &fms, &ebx, &ecx, &edx);
+       family = (fms >> 8) & 0xf;
+       model = (fms >> 4) & 0xf;
+       if (family == 0xf)
+               family += (fms >> 20) & 0xf;
+       if (family == 6 || family == 0xf)
+               model += ((fms >> 16) & 0xf) << 4;
+       if (!(edx & (1 << 5))) {
+               ERROR("turbostat plugin: Unsupported CPU (no MSR support)");
+               return -1;
+       }
+
+       /*
+        * CPUID(6):
+        * - EAX:
+        *  + 0: Digital temperature sensor is supported if set
+        *  + 6: Package thermal management is supported if set
+        * - ECX:
+        *  + 0: Hardware Coordination Feedback Capability (Presence of IA32_MPERF and IA32_APERF).
+        *  + 3: The processor supports performance-energy bias preference if set.
+        *       It also implies the presence of a new architectural MSR called IA32_ENERGY_PERF_BIAS
+        *
+        * This check is valid for both Intel and AMD
+        */
+       eax = ebx = ecx = edx = 0;
+       __get_cpuid(0x6, &eax, &ebx, &ecx, &edx);
+       do_dts = eax & (1 << 0);
+       do_ptm = eax & (1 << 6);
+       if (!(ecx & (1 << 0))) {
+               ERROR("turbostat plugin: Unsupported CPU (No APERF)");
+               return -1;
+       }
+
+       /*
+        * Enable or disable C states depending on the model and family
+        */
+       if (family == 6) {
+               switch (model) {
+               /* Atom (partial) */
+               case 0x27:
+                       do_smi = 0;
+                       do_core_cstate = 0;
+                       do_pkg_cstate = (1 << 2) | (1 << 4) | (1 << 6);
+                       break;
+               /* Silvermont */
+               case 0x37: /* BYT */
+               case 0x4D: /* AVN */
+                       do_smi = 1;
+                       do_core_cstate = (1 << 1) | (1 << 6);
+                       do_pkg_cstate = (1 << 6);
+                       break;
+               /* Nehalem */
+               case 0x1A: /* Core i7, Xeon 5500 series - Bloomfield, Gainstown NHM-EP */
+               case 0x1E: /* Core i7 and i5 Processor - Clarksfield, Lynnfield, Jasper Forest */
+               case 0x1F: /* Core i7 and i5 Processor - Nehalem */
+               case 0x2E: /* Nehalem-EX Xeon - Beckton */
+                       do_smi = 1;
+                       do_core_cstate = (1 << 3) | (1 << 6);
+                       do_pkg_cstate = (1 << 3) | (1 << 6) | (1 << 7);
+                       break;
+               /* Westmere */
+               case 0x25: /* Westmere Client - Clarkdale, Arrandale */
+               case 0x2C: /* Westmere EP - Gulftown */
+               case 0x2F: /* Westmere-EX Xeon - Eagleton */
+                       do_smi = 1;
+                       do_core_cstate = (1 << 3) | (1 << 6);
+                       do_pkg_cstate = (1 << 3) | (1 << 6) | (1 << 7);
+                       break;
+               /* Sandy Bridge */
+               case 0x2A: /* SNB */
+               case 0x2D: /* SNB Xeon */
+                       do_smi = 1;
+                       do_core_cstate = (1 << 3) | (1 << 6) | (1 << 7);
+                       do_pkg_cstate = (1 << 2) | (1 << 3) | (1 << 6) | (1 << 7);
+                       break;
+               /* Ivy Bridge */
+               case 0x3A: /* IVB */
+               case 0x3E: /* IVB Xeon */
+                       do_smi = 1;
+                       do_core_cstate = (1 << 3) | (1 << 6) | (1 << 7);
+                       do_pkg_cstate = (1 << 2) | (1 << 3) | (1 << 6) | (1 << 7);
+                       break;
+               /* Haswell Bridge */
+               case 0x3C: /* HSW */
+               case 0x3F: /* HSW */
+               case 0x46: /* HSW */
+                       do_smi = 1;
+                       do_core_cstate = (1 << 3) | (1 << 6) | (1 << 7);
+                       do_pkg_cstate = (1 << 2) | (1 << 3) | (1 << 6) | (1 << 7);
+                       break;
+               case 0x45: /* HSW */
+                       do_smi = 1;
+                       do_core_cstate = (1 << 3) | (1 << 6) | (1 << 7);
+                       do_pkg_cstate = (1 << 2) | (1 << 3) | (1 << 6) | (1 << 7) | (1 << 8) | (1 << 9) | (1 << 10);
+                       break;
+               /* Broadwel */
+               case 0x4F: /* BDW */
+               case 0x56: /* BDX-DE */
+                       do_smi = 1;
+                       do_core_cstate = (1 << 3) | (1 << 6) | (1 << 7);
+                       do_pkg_cstate = (1 << 2) | (1 << 3) | (1 << 6) | (1 << 7);
+                       break;
+               case 0x3D: /* BDW */
+                       do_smi = 1;
+                       do_core_cstate = (1 << 3) | (1 << 6) | (1 << 7);
+                       do_pkg_cstate = (1 << 2) | (1 << 3) | (1 << 6) | (1 << 7) | (1 << 8) | (1 << 9) | (1 << 10);
+                       break;
+               default:
+                       do_smi = 0;
+                       do_core_cstate = 0;
+                       do_pkg_cstate = 0;
+                       break;
+               }
+               switch (model) {
+               case 0x2A: /* SNB */
+               case 0x3A: /* IVB */
+               case 0x3C: /* HSW */
+               case 0x45: /* HSW */
+               case 0x46: /* HSW */
+               case 0x3D: /* BDW */
+                       do_rapl = RAPL_PKG | RAPL_CORES | RAPL_GFX;
+                       break;
+               case 0x3F: /* HSX */
+               case 0x4F: /* BDX */
+               case 0x56: /* BDX-DE */
+                       do_rapl = RAPL_PKG | RAPL_DRAM ;
+                       break;
+               case 0x2D: /* SNB Xeon */
+               case 0x3E: /* IVB Xeon */
+                       do_rapl = RAPL_PKG | RAPL_CORES | RAPL_DRAM;
+                       break;
+               case 0x37: /* BYT */
+               case 0x4D: /* AVN */
+                       do_rapl = RAPL_PKG | RAPL_CORES;
+                       break;
+               default:
+                       do_rapl = 0;
+               }
+       } else {
+               ERROR("turbostat plugin: Unsupported CPU (family: %#x, "
+                     "model: %#x)", family, model);
+               return -1;
+       }
+
+       /* Override detected values with configuration */
+       if (apply_config_core_cstate)
+               do_core_cstate = config_core_cstate;
+       if (apply_config_pkg_cstate)
+               do_pkg_cstate = config_pkg_cstate;
+       if (apply_config_smi)
+               do_smi = config_smi;
+       if (apply_config_dts)
+               do_dts = config_dts;
+       if (apply_config_ptm)
+               do_ptm = config_ptm;
+       if (apply_config_rapl)
+               do_rapl = config_rapl;
+
+       if (do_rapl) {
+               unsigned long long msr;
+               if (get_msr(0, MSR_RAPL_POWER_UNIT, &msr))
+                       return 0;
+
+               if (model == 0x37)
+                       rapl_energy_units = 1.0 * (1 << (msr >> 8 & 0x1F)) / 1000000;
+               else
+                       rapl_energy_units = 1.0 / (1 << (msr >> 8 & 0x1F));
+       }
+
+       return 0;
+}
+
+
+/********************
+ * Topology Probing *
+ ********************/
+
+/*
+ * Read a single int from a file.
+ */
+static int __attribute__ ((format(printf,1,2)))
+parse_int_file(const char *fmt, ...)
+{
+       va_list args;
+       char path[PATH_MAX];
+       FILE *filep;
+       int len, value;
+
+       va_start(args, fmt);
+       len = vsnprintf(path, sizeof(path), fmt, args);
+       va_end(args);
+       if (len < 0 || len >= PATH_MAX) {
+               ERROR("turbostat plugin: path truncated: '%s'", path);
+               return -1;
+       }
+
+       filep = fopen(path, "r");
+       if (!filep) {
+               ERROR("turbostat plugin: Failed to open '%s'", path);
+               return -1;
+       }
+       if (fscanf(filep, "%d", &value) != 1) {
+               ERROR("turbostat plugin: Failed to parse number from '%s'", path);
+               return -1;
+       }
+       fclose(filep);
+       return value;
+}
+
+static int
+get_threads_on_core(unsigned int cpu)
+{
+       char path[80];
+       FILE *filep;
+       int sib1, sib2;
+       int matches;
+       char character;
+
+       ssnprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu);
+       filep = fopen(path, "r");
+       if (!filep) {
+               ERROR("turbostat plugin: Failed to open '%s'", path);
+               return -1;
+       }
+       /*
+        * file format:
+        * if a pair of number with a character between: 2 siblings (eg. 1-2, or 1,4)
+        * otherwinse 1 sibling (self).
+        */
+       matches = fscanf(filep, "%d%c%d\n", &sib1, &character, &sib2);
+
+       fclose(filep);
+
+       if (matches == 3)
+               return 2;
+       else
+               return 1;
+}
+
+/*
+ * run func(cpu) on every cpu in /proc/stat
+ * return max_cpu number
+ */
+static int __attribute__((warn_unused_result))
+for_all_proc_cpus(int (func)(unsigned int))
+{
+       FILE *fp;
+       unsigned int cpu_num;
+       int retval;
+
+       fp = fopen("/proc/stat", "r");
+       if (!fp) {
+               ERROR("turbostat plugin: Failed to open /proc/stat");
+               return -1;
+       }
+
+       retval = fscanf(fp, "cpu %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n");
+       if (retval != 0) {
+               ERROR("turbostat plugin: Failed to parse /proc/stat");
+               fclose(fp);
+               return -1;
+       }
+
+       while (1) {
+               retval = fscanf(fp, "cpu%u %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n", &cpu_num);
+               if (retval != 1)
+                       break;
+
+               retval = func(cpu_num);
+               if (retval) {
+                       fclose(fp);
+                       return(retval);
+               }
+       }
+       fclose(fp);
+       return 0;
+}
+
+/*
+ * Update the stored topology.max_cpu_id
+ */
+static int
+update_max_cpu_id(unsigned int cpu)
+{
+       if (topology.max_cpu_id < cpu)
+               topology.max_cpu_id = cpu;
+       return 0;
+}
+
+static int
+mark_cpu_present(unsigned int cpu)
+{
+       CPU_SET_S(cpu, cpu_present_setsize, cpu_present_set);
+       return 0;
+}
+
+static int __attribute__((warn_unused_result))
+allocate_cpu_set(cpu_set_t ** set, size_t * size) {
+       *set = CPU_ALLOC(topology.max_cpu_id  + 1);
+       if (*set == NULL) {
+               ERROR("turbostat plugin: Unable to allocate CPU state");
+               return -1;
+       }
+       *size = CPU_ALLOC_SIZE(topology.max_cpu_id  + 1);
+       CPU_ZERO_S(*size, *set);
+       return 0;
+}
+
+/*
+ * Build a local representation of the cpu distribution
+ */
+static int __attribute__((warn_unused_result))
+topology_probe()
+{
+       unsigned int i;
+       int ret;
+       unsigned int max_package_id, max_core_id, max_threads;
+       max_package_id = max_core_id = max_threads = 0;
+
+       /* Clean topology */
+       free(topology.cpus);
+       memset(&topology, 0, sizeof(topology));
+
+       ret = for_all_proc_cpus(update_max_cpu_id);
+       if (ret != 0)
+               goto err;
+
+       topology.cpus = calloc(1, (topology.max_cpu_id  + 1) * sizeof(struct cpu_topology));
+       if (topology.cpus == NULL) {
+               ERROR("turbostat plugin: Unable to allocate memory for CPU topology");
+               return -1;
+       }
+
+       ret = allocate_cpu_set(&cpu_present_set, &cpu_present_setsize);
+       if (ret != 0)
+               goto err;
+       ret = allocate_cpu_set(&cpu_affinity_set, &cpu_affinity_setsize);
+       if (ret != 0)
+               goto err;
+       ret = allocate_cpu_set(&cpu_saved_affinity_set, &cpu_saved_affinity_setsize);
+       if (ret != 0)
+               goto err;
+
+       ret = for_all_proc_cpus(mark_cpu_present);
+       if (ret != 0)
+               goto err;
+
+       /*
+        * For online cpus
+        * find max_core_id, max_package_id
+        */
+       for (i = 0; i <= topology.max_cpu_id; ++i) {
+               unsigned int num_threads;
+               struct cpu_topology *cpu = &topology.cpus[i];
+
+               if (cpu_is_not_present(i)) {
+                       WARNING("turbostat plugin: cpu%d NOT PRESENT", i);
+                       continue;
+               }
+
+               ret = parse_int_file("/sys/devices/system/cpu/cpu%d/topology/physical_package_id", i);
+               if (ret < 0)
+                       goto err;
+               else
+                       cpu->package_id = (unsigned int) ret;
+               if (cpu->package_id > max_package_id)
+                       max_package_id = cpu->package_id;
+
+               ret = parse_int_file("/sys/devices/system/cpu/cpu%d/topology/core_id", i);
+               if (ret < 0)
+                       goto err;
+               else
+                       cpu->core_id = (unsigned int) ret;
+               if (cpu->core_id > max_core_id)
+                       max_core_id = cpu->core_id;
+               ret = parse_int_file("/sys/devices/system/cpu/cpu%d/topology/core_siblings_list", i);
+               if (ret < 0)
+                       goto err;
+               else if ((unsigned int) ret == i)
+                       cpu->first_core_in_package = 1;
+
+               ret = get_threads_on_core(i);
+               if (ret < 0)
+                       goto err;
+               else
+                       num_threads = (unsigned int) ret;
+               if (num_threads > max_threads)
+                       max_threads = num_threads;
+               ret = parse_int_file("/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", i);
+               if (ret < 0)
+                       goto err;
+               else if ((unsigned int) ret == i)
+                       cpu->first_thread_in_core = 1;
+
+               DEBUG("turbostat plugin: cpu %d pkg %d core %d\n",
+                       i, cpu->package_id, cpu->core_id);
+       }
+       /* Num is max + 1 (need to count 0) */
+       topology.num_packages = max_package_id + 1;
+       topology.num_cores = max_core_id + 1;
+       topology.num_threads = max_threads;
+
+       return 0;
+err:
+       free(topology.cpus);
+       return ret;
+}
+
+
+/************************
+ * Main alloc/init/free *
+ ************************/
+
+static int
+allocate_counters(struct thread_data **threads, struct core_data **cores, struct pkg_data **packages)
+{
+       unsigned int i;
+       unsigned int total_threads, total_cores;
+
+       if ((topology.num_threads == 0)
+           || (topology.num_cores == 0)
+           || (topology.num_packages == 0))
+       {
+               ERROR ("turbostat plugin: Invalid topology: %u threads, %u cores, %u packages",
+                      topology.num_threads, topology.num_cores, topology.num_packages);
+               return -1;
+       }
+
+       total_threads = topology.num_threads * topology.num_cores * topology.num_packages;
+       *threads = calloc(total_threads, sizeof(struct thread_data));
+       if (*threads == NULL)
+       {
+               ERROR ("turbostat plugin: calloc failed");
+               return -1;
+       }
+
+       for (i = 0; i < total_threads; ++i)
+               (*threads)[i].cpu_id = topology.max_cpu_id + 1;
+
+       total_cores = topology.num_cores * topology.num_packages;
+       *cores = calloc(total_cores, sizeof(struct core_data));
+       if (*cores == NULL)
+       {
+               ERROR ("turbostat plugin: calloc failed");
+               sfree (threads);
+               return -1;
+       }
+
+       *packages = calloc(topology.num_packages, sizeof(struct pkg_data));
+       if (*packages == NULL)
+       {
+               ERROR ("turbostat plugin: calloc failed");
+               sfree (cores);
+               sfree (threads);
+               return -1;
+       }
+
+       return 0;
+}
+
+static void
+init_counter(struct thread_data *thread_base, struct core_data *core_base,
+       struct pkg_data *pkg_base, unsigned int cpu_id)
+{
+       struct thread_data *t;
+       struct core_data *c;
+       struct pkg_data *p;
+       struct cpu_topology *cpu = &topology.cpus[cpu_id];
+
+       t = GET_THREAD(thread_base, !(cpu->first_thread_in_core), cpu->core_id, cpu->package_id);
+       c = GET_CORE(core_base, cpu->core_id, cpu->package_id);
+       p = GET_PKG(pkg_base, cpu->package_id);
+
+       t->cpu_id = cpu_id;
+       if (cpu->first_thread_in_core)
+               t->flags |= CPU_IS_FIRST_THREAD_IN_CORE;
+       if (cpu->first_core_in_package)
+               t->flags |= CPU_IS_FIRST_CORE_IN_PACKAGE;
+
+       c->core_id = cpu->core_id;
+       p->package_id = cpu->package_id;
+}
+
+static void
+initialize_counters(void)
+{
+       unsigned int cpu_id;
+
+       for (cpu_id = 0; cpu_id <= topology.max_cpu_id; ++cpu_id) {
+               if (cpu_is_not_present(cpu_id))
+                       continue;
+               init_counter(EVEN_COUNTERS, cpu_id);
+               init_counter(ODD_COUNTERS, cpu_id);
+               init_counter(DELTA_COUNTERS, cpu_id);
+       }
+}
+
+
+
+static void
+free_all_buffers(void)
+{
+       allocated = 0;
+       initialized = 0;
+
+       CPU_FREE(cpu_present_set);
+       cpu_present_set = NULL;
+       cpu_present_set = 0;
+
+       CPU_FREE(cpu_affinity_set);
+       cpu_affinity_set = NULL;
+       cpu_affinity_setsize = 0;
+
+       CPU_FREE(cpu_saved_affinity_set);
+       cpu_saved_affinity_set = NULL;
+       cpu_saved_affinity_setsize = 0;
+
+       free(thread_even);
+       free(core_even);
+       free(package_even);
+
+       thread_even = NULL;
+       core_even = NULL;
+       package_even = NULL;
+
+       free(thread_odd);
+       free(core_odd);
+       free(package_odd);
+
+       thread_odd = NULL;
+       core_odd = NULL;
+       package_odd = NULL;
+
+       free(thread_delta);
+       free(core_delta);
+       free(package_delta);
+
+       thread_delta = NULL;
+       core_delta = NULL;
+       package_delta = NULL;
+}
+
+
+/**********************
+ * Collectd functions *
+ **********************/
+
+#define DO_OR_GOTO_ERR(something) \
+do {                             \
+       ret = (something);        \
+       if (ret < 0)              \
+               goto err;         \
+} while (0)
+
+static int setup_all_buffers(void)
+{
+       int ret;
+
+       DO_OR_GOTO_ERR(topology_probe());
+       DO_OR_GOTO_ERR(allocate_counters(&thread_even, &core_even, &package_even));
+       DO_OR_GOTO_ERR(allocate_counters(&thread_odd, &core_odd, &package_odd));
+       DO_OR_GOTO_ERR(allocate_counters(&thread_delta, &core_delta, &package_delta));
+       initialize_counters();
+       DO_OR_GOTO_ERR(for_all_cpus(set_temperature_target, EVEN_COUNTERS));
+       DO_OR_GOTO_ERR(for_all_cpus(set_temperature_target, ODD_COUNTERS));
+
+       allocated = 1;
+       return 0;
+err:
+       free_all_buffers();
+       return ret;
+}
+
+static int
+turbostat_read(void)
+{
+       int ret;
+
+       if (!allocated) {
+               if ((ret = setup_all_buffers()) < 0)
+                       return ret;
+       }
+
+       if (for_all_proc_cpus(cpu_is_not_present)) {
+               free_all_buffers();
+               if ((ret = setup_all_buffers()) < 0)
+                       return ret;
+               if (for_all_proc_cpus(cpu_is_not_present)) {
+                       ERROR("turbostat plugin: CPU appeared just after "
+                             "initialization");
+                       return -1;
+               }
+       }
+
+       /* Saving the scheduling affinity, as it will be modified by get_counters */
+       if (sched_getaffinity(0, cpu_saved_affinity_setsize, cpu_saved_affinity_set) != 0) {
+               ERROR("turbostat plugin: Unable to save the CPU affinity");
+               return -1;
+       }
+
+       if (!initialized) {
+               if ((ret = for_all_cpus(get_counters, EVEN_COUNTERS)) < 0)
+                       goto out;
+               time_even = cdtime();
+               is_even = 1;
+               initialized = 1;
+               ret = 0;
+               goto out;
+       }
+
+       if (is_even) {
+               if ((ret = for_all_cpus(get_counters, ODD_COUNTERS)) < 0)
+                       goto out;
+               time_odd = cdtime();
+               is_even = 0;
+               time_delta = time_odd - time_even;
+               if ((ret = for_all_cpus_delta(ODD_COUNTERS, EVEN_COUNTERS)) < 0)
+                       goto out;
+               if ((ret = for_all_cpus(submit_counters, DELTA_COUNTERS)) < 0)
+                       goto out;
+       } else {
+               if ((ret = for_all_cpus(get_counters, EVEN_COUNTERS)) < 0)
+                       goto out;
+               time_even = cdtime();
+               is_even = 1;
+               time_delta = time_even - time_odd;
+               if ((ret = for_all_cpus_delta(EVEN_COUNTERS, ODD_COUNTERS)) < 0)
+                       goto out;
+               if ((ret = for_all_cpus(submit_counters, DELTA_COUNTERS)) < 0)
+                       goto out;
+       }
+       ret = 0;
+out:
+       /*
+        * Let's restore the affinity
+        * This might fail if the number of CPU changed, but we can't do anything in that case..
+        */
+       (void)sched_setaffinity(0, cpu_saved_affinity_setsize, cpu_saved_affinity_set);
+       return ret;
+}
+
+static int
+check_permissions(void)
+{
+#ifdef HAVE_SYS_CAPABILITY_H
+       struct __user_cap_header_struct cap_header_data;
+       cap_user_header_t cap_header = &cap_header_data;
+       struct __user_cap_data_struct cap_data_data;
+       cap_user_data_t cap_data = &cap_data_data;
+       int ret = 0;
+#endif /* HAVE_SYS_CAPABILITY_H */
+
+       if (getuid() == 0) {
+               /* We have everything we need */
+               return 0;
+#ifndef HAVE_SYS_CAPABILITY_H
+       } else {
+               ERROR("turbostat plugin: Initialization failed: this plugin "
+                     "requires collectd to run as root");
+               return -1;
+       }
+#else /* HAVE_SYS_CAPABILITY_H */
+       }
+
+       /* check for CAP_SYS_RAWIO */
+       cap_header->pid = getpid();
+       cap_header->version = _LINUX_CAPABILITY_VERSION;
+       if (capget(cap_header, cap_data) < 0) {
+               ERROR("turbostat plugin: capget failed");
+               return -1;
+       }
+
+       if ((cap_data->effective & (1 << CAP_SYS_RAWIO)) == 0) {
+               WARNING("turbostat plugin: Collectd doesn't have the "
+                       "CAP_SYS_RAWIO capability. If you don't want to run "
+                       "collectd as root, try running \"setcap "
+                       "cap_sys_rawio=ep\" on collectd binary");
+               ret = -1;
+       }
+
+       if (euidaccess("/dev/cpu/0/msr", R_OK)) {
+               WARNING("turbostat plugin: Collectd cannot open"
+                       "/dev/cpu/0/msr. If you don't want to run collectd as "
+                       "root, you need to change the ownership (chown) and "
+                       "permissions on /dev/cpu/*/msr to allow such access");
+               ret = -1;
+       }
+
+       if (ret != 0)
+               ERROR("turbostat plugin: Initialization failed: this plugin "
+                     "requires collectd to either to run as root or give "
+                     "collectd a special capability (CAP_SYS_RAWIO) and read "
+                      "access to /dev/cpu/*/msr (see previous warnings)");
+       return ret;
+#endif /* HAVE_SYS_CAPABILITY_H */
+}
+
+static int
+turbostat_init(void)
+{
+       struct stat sb;
+       int ret;
+
+       if (stat("/dev/cpu/0/msr", &sb)) {
+               ERROR("turbostat plugin: Initialization failed: /dev/cpu/0/msr"
+                     " does not exist while the CPU supports MSR. You may be "
+                     "missing the corresponding kernel module, please try '# "
+                     "modprobe msr'");
+               return -1;
+       }
+
+       DO_OR_GOTO_ERR(check_permissions());
+
+       DO_OR_GOTO_ERR(probe_cpu());
+
+       DO_OR_GOTO_ERR(setup_all_buffers());
+
+       plugin_register_read(PLUGIN_NAME, turbostat_read);
+
+       return 0;
+err:
+       free_all_buffers();
+       return ret;
+}
+
+static int
+turbostat_config(const char *key, const char *value)
+{
+       long unsigned int tmp_val;
+       char *end;
+
+       if (strcasecmp("CoreCstates", key) == 0) {
+               tmp_val = strtoul(value, &end, 0);
+               if (*end != '\0' || tmp_val > UINT_MAX) {
+                       ERROR("turbostat plugin: Invalid CoreCstates '%s'",
+                             value);
+                       return -1;
+               }
+               config_core_cstate = (unsigned int) tmp_val;
+               apply_config_core_cstate = 1;
+       } else if (strcasecmp("PackageCstates", key) == 0) {
+               tmp_val = strtoul(value, &end, 0);
+               if (*end != '\0' || tmp_val > UINT_MAX) {
+                       ERROR("turbostat plugin: Invalid PackageCstates '%s'",
+                             value);
+                       return -1;
+               }
+               config_pkg_cstate = (unsigned int) tmp_val;
+               apply_config_pkg_cstate = 1;
+       } else if (strcasecmp("SystemManagementInterrupt", key) == 0) {
+               config_smi = IS_TRUE(value);
+               apply_config_smi = 1;
+       } else if (strcasecmp("DigitalTemperatureSensor", key) == 0) {
+               config_dts = IS_TRUE(value);
+               apply_config_dts = 1;
+       } else if (strcasecmp("PackageThermalManagement", key) == 0) {
+               config_ptm = IS_TRUE(value);
+               apply_config_ptm = 1;
+       } else if (strcasecmp("RunningAveragePowerLimit", key) == 0) {
+               tmp_val = strtoul(value, &end, 0);
+               if (*end != '\0' || tmp_val > UINT_MAX) {
+                       ERROR("turbostat plugin: Invalid RunningAveragePowerLimit '%s'",
+                             value);
+                       return -1;
+               }
+               config_rapl = (unsigned int) tmp_val;
+               apply_config_rapl = 1;
+       } else if (strcasecmp("TCCActivationTemp", key) == 0) {
+               tmp_val = strtoul(value, &end, 0);
+               if (*end != '\0' || tmp_val > UINT_MAX) {
+                       ERROR("turbostat plugin: Invalid TCCActivationTemp '%s'",
+                             value);
+                       return -1;
+               }
+               tcc_activation_temp = (unsigned int) tmp_val;
+       } else {
+               ERROR("turbostat plugin: Invalid configuration option '%s'",
+                     key);
+               return -1;
+       }
+       return 0;
+}
+
+void module_register(void)
+{
+       plugin_register_init(PLUGIN_NAME, turbostat_init);
+       plugin_register_config(PLUGIN_NAME, turbostat_config, config_keys, config_keys_num);
+}
index 97cc4cc08ad81a640be9b6550d0435deb447e9ba..38fb546c867170f43eada049718786e46e6a1060 100644 (file)
@@ -8,18 +8,24 @@ ath_nodes             value:GAUGE:0:65535
 ath_stat               value:DERIVE:0:U
 backends               value:GAUGE:0:65535
 bitrate                        value:GAUGE:0:4294967295
+blocked_clients value:GAUGE:0:U
 bytes                  value:GAUGE:0:U
 cache_eviction         value:DERIVE:0:U
 cache_operation                value:DERIVE:0:U
 cache_ratio            value:GAUGE:0:100
 cache_result           value:DERIVE:0:U
 cache_size             value:GAUGE:0:U
+ceph_bytes             value:GAUGE:U:U
+ceph_latency   value:GAUGE:U:U
+ceph_rate                      value:DERIVE:0:U
+changes_since_last_save   value:GAUGE:0:U
 charge                 value:GAUGE:0:U
 compression_ratio      value:GAUGE:0:2
 compression            uncompressed:DERIVE:0:U, compressed:DERIVE:0:U
 connections            value:DERIVE:0:U
 conntrack              value:GAUGE:0:4294967295
 contextswitch          value:DERIVE:0:U
+count                  value:GAUGE:0:U
 counter                        value:COUNTER:U:U
 cpufreq                        value:GAUGE:0:U
 cpu                    value:DERIVE:0:U
@@ -37,6 +43,7 @@ disk_octets           read:DERIVE:0:U, write:DERIVE:0:U
 disk_ops_complex       value:DERIVE:0:U
 disk_ops               read:DERIVE:0:U, write:DERIVE:0:U
 disk_time              read:DERIVE:0:U, write:DERIVE:0:U
+disk_io_time           io_time:DERIVE:0:U, weighted_io_time:DERIVE:0:U
 dns_answer             value:DERIVE:0:U
 dns_notify             value:DERIVE:0:U
 dns_octets             queries:DERIVE:0:U, responses:DERIVE:0:U
@@ -53,12 +60,15 @@ 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
 email_size             value:GAUGE:0:U
 entropy                        value:GAUGE:0:4294967295
+expired_keys    value:GAUGE:0:U
 fanspeed               value:GAUGE:0:U
+file_handles           value:GAUGE:0:U
 file_size              value:GAUGE:0:U
 files                  value:GAUGE:0:U
 flow                   value:GAUGE:0:U
@@ -98,6 +108,7 @@ memcached_items              value:GAUGE:0:U
 memcached_octets       rx:DERIVE:0:U, tx:DERIVE:0:U
 memcached_ops          value:DERIVE:0:U
 memory                 value:GAUGE:0:281474976710656
+memory_lua             value:GAUGE:0:281474976710656
 multimeter             value:GAUGE:U:U
 mutex_operations       value:DERIVE:0:U
 mysql_commands         value:DERIVE:0:U
@@ -105,6 +116,17 @@ 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_bytes      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_log       value:DERIVE:0:U
+mysql_innodb_pages     value:DERIVE:0:U
+mysql_innodb_row_lock  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
@@ -114,6 +136,8 @@ node_stat           value:DERIVE:0:U
 node_tx_rate           value:GAUGE:0:127
 objects                        value:GAUGE:0:U
 operations             value:DERIVE:0:U
+packets                        value:DERIVE:0:U
+pending_operations     value:GAUGE:0:U
 percent                        value:GAUGE:0:100.1
 percent_bytes          value:GAUGE:0:100.1
 percent_inodes         value:GAUGE:0:100.1
@@ -134,6 +158,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
@@ -146,6 +171,7 @@ ps_rss                      value:GAUGE:0:9223372036854775807
 ps_stacksize           value:GAUGE:0:9223372036854775807
 ps_state               value:GAUGE:0:65535
 ps_vm                  value:GAUGE:0:9223372036854775807
+pubsub        value:GAUGE:0:U
 queue_length           value:GAUGE:0:U
 records                        value:GAUGE:0:U
 requests               value:GAUGE:0:U
@@ -154,10 +180,16 @@ response_code             value:GAUGE:0:U
 route_etx              value:GAUGE:0:U
 route_metric           value:GAUGE:0:U
 routes                 value:GAUGE:0:U
+segments               value:GAUGE:0:65535
 serial_octets          rx:DERIVE:0:U, tx:DERIVE:0:U
 signal_noise           value:GAUGE:U:0
 signal_power           value:GAUGE:U:0
 signal_quality         value:GAUGE:0:U
+smart_poweron          value:GAUGE:0:U
+smart_powercycles      value:GAUGE:0:U
+smart_badsectors       value:GAUGE:0:U
+smart_temperature      value:GAUGE:-300:300
+smart_attribute         current:GAUGE:0:255, worst:GAUGE:0:255, threshold:GAUGE:0:255, pretty:GAUGE:0:U
 snr                    value:GAUGE:0:U
 spam_check             value:GAUGE:0:U
 spam_score             value:GAUGE:U:U
index 111742ba0dc5c5ae9c3a866dc9920fd4cb566bd1..f0af60e0fc7f25d08a47315cd97ec006e64b6f21 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>.
diff --git a/src/types_list.c b/src/types_list.c
deleted file mode 100644 (file)
index 887b43d..0000000
+++ /dev/null
@@ -1,202 +0,0 @@
-/**
- * collectd - src/types_list.c
- * 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.
- *
- * 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
- *
- * Authors:
- *   Florian octo Forster <octo at verplant.org>
- **/
-
-#include "collectd.h"
-#include "common.h"
-
-#include "plugin.h"
-#include "configfile.h"
-
-static int parse_ds (data_source_t *dsrc, char *buf, size_t buf_len)
-{
-  char *dummy;
-  char *saveptr;
-  char *fields[8];
-  int   fields_num;
-
-  if (buf_len < 11)
-  {
-    ERROR ("parse_ds: (buf_len = %zu) < 11", buf_len);
-    return (-1);
-  }
-
-  if (buf[buf_len - 1] == ',')
-  {
-    buf_len--;
-    buf[buf_len] = '\0';
-  }
-
-  dummy = buf;
-  saveptr = NULL;
-
-  fields_num = 0;
-  while (fields_num < 8)
-  {
-    if ((fields[fields_num] = strtok_r (dummy, ":", &saveptr)) == NULL)
-      break;
-    dummy = NULL;
-    fields_num++;
-  }
-
-  if (fields_num != 4)
-  {
-    ERROR ("parse_ds: (fields_num = %i) != 4", fields_num);
-    return (-1);
-  }
-
-  sstrncpy (dsrc->name, fields[0], sizeof (dsrc->name));
-
-  if (strcasecmp (fields[1], "GAUGE") == 0)
-    dsrc->type = DS_TYPE_GAUGE;
-  else if (strcasecmp (fields[1], "COUNTER") == 0)
-    dsrc->type = DS_TYPE_COUNTER;
-  else if (strcasecmp (fields[1], "DERIVE") == 0)
-    dsrc->type = DS_TYPE_DERIVE;
-  else if (strcasecmp (fields[1], "ABSOLUTE") == 0)
-    dsrc->type = DS_TYPE_ABSOLUTE;
-  else
-  {
-    ERROR ("(fields[1] = %s) != (GAUGE || COUNTER || DERIVE || ABSOLUTE)", fields[1]);
-    return (-1);
-  }
-
-  if (strcasecmp (fields[2], "U") == 0)
-    dsrc->min = NAN;
-  else
-    dsrc->min = atof (fields[2]);
-
-  if (strcasecmp (fields[3], "U") == 0)
-    dsrc->max = NAN;
-  else
-    dsrc->max = atof (fields[3]);
-
-  return (0);
-} /* int parse_ds */
-
-static void parse_line (char *buf)
-{
-  char  *fields[64];
-  size_t fields_num;
-  data_set_t *ds;
-  int i;
-
-  fields_num = strsplit (buf, fields, 64);
-  if (fields_num < 2)
-    return;
-
-  /* Ignore lines which begin with a hash sign. */
-  if (fields[0][0] == '#')
-    return;
-
-  ds = (data_set_t *) malloc (sizeof (data_set_t));
-  if (ds == NULL)
-    return;
-
-  memset (ds, '\0', sizeof (data_set_t));
-
-  sstrncpy (ds->type, fields[0], sizeof (ds->type));
-
-  ds->ds_num = fields_num - 1;
-  ds->ds = (data_source_t *) calloc (ds->ds_num, sizeof (data_source_t));
-  if (ds->ds == NULL)
-    return;
-
-  for (i = 0; i < ds->ds_num; i++)
-    if (parse_ds (ds->ds + i, fields[i + 1], strlen (fields[i + 1])) != 0)
-    {
-      sfree (ds->ds);
-      ERROR ("types_list: parse_line: Cannot parse data source #%i "
-         "of data set %s", i, ds->type);
-      return;
-    }
-
-  plugin_register_data_set (ds);
-
-  sfree (ds->ds);
-  sfree (ds);
-} /* void parse_line */
-
-static void parse_file (FILE *fh)
-{
-  char buf[4096];
-  size_t buf_len;
-
-  while (fgets (buf, sizeof (buf), fh) != NULL)
-  {
-    buf_len = strlen (buf);
-
-    if (buf_len >= 4095)
-    {
-      NOTICE ("Skipping line with more than 4095 characters.");
-      do
-      {
-       if (fgets (buf, sizeof (buf), fh) == NULL)
-         break;
-       buf_len = strlen (buf);
-      } while (buf_len >= 4095);
-      continue;
-    } /* if (buf_len >= 4095) */
-
-    if ((buf_len == 0) || (buf[0] == '#'))
-      continue;
-
-    while ((buf_len > 0) && ((buf[buf_len - 1] == '\n')
-         || (buf[buf_len - 1] == '\r')))
-      buf[--buf_len] = '\0';
-
-    if (buf_len == 0)
-      continue;
-
-    parse_line (buf);
-  } /* while (fgets) */
-} /* void parse_file */
-
-int read_types_list (const char *file)
-{
-  FILE *fh;
-
-  if (file == NULL)
-    return (-1);
-
-  fh = fopen (file, "r");
-  if (fh == NULL)
-  {
-    char errbuf[1024];
-    fprintf (stderr, "Failed to open types database `%s': %s.\n",
-       file, sstrerror (errno, errbuf, sizeof (errbuf)));
-    ERROR ("Failed to open types database `%s': %s",
-       file, sstrerror (errno, errbuf, sizeof (errbuf)));
-    return (-1);
-  }
-
-  parse_file (fh);
-
-  fclose (fh);
-  fh = NULL;
-
-  DEBUG ("Done parsing `%s'", file);
-
-  return (0);
-} /* int read_types_list */
-
-/*
- * vim: shiftwidth=2:softtabstop=2:tabstop=8
- */
diff --git a/src/types_list.h b/src/types_list.h
deleted file mode 100644 (file)
index 8fe6ce8..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef TYPES_LIST_H
-#define TYPES_LIST_H 1
-
-/**
- * collectd - src/types_list.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.
- *
- * 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
- *
- * Authors:
- *   Florian octo Forster <octo at verplant.org>
- **/
-
-int read_types_list (const char *file);
-
-#endif /* TYPES_LIST_H */
index 2c1665fc9fcbbdffc3c91935838a720e4fbf6d6f..664c0184a5d21a793e1fc529dcbe6fbdddfbcde8 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 064c3ceed4752a359c7ec2e5b9d84afa27068543..345128da62f6750d30655d74a3f35a841ec6a110 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 1e337540e5b4f5b258d00234472385c8a1187454..139c97659a974701c2f69051c4d8fb93e78fc833 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>
  **/
 
@@ -40,9 +40,6 @@
 #elif HAVE_UTMP_H
 # include <utmp.h>
 /* #endif HAVE_UTMP_H */
-
-#else
-# error "No applicable input method."
 #endif
 
 static void users_submit (gauge_t value)
@@ -102,11 +99,21 @@ static int users_read (void)
 #elif HAVE_LIBSTATGRAB
        sg_user_stats *us;
 
+# if HAVE_LIBSTATGRAB_0_90
+       size_t num_entries;
+       us = sg_get_user_stats (&num_entries);
+# else
        us = sg_get_user_stats ();
+# endif
        if (us == NULL)
                return (-1);   
 
-       users_submit ((gauge_t) us->num_entries);
+       users_submit ((gauge_t)
+# if HAVE_LIBSTATGRAB_0_90
+                     num_entries);
+# else
+                     us->num_entries);
+# endif
 /* #endif HAVE_LIBSTATGRAB */
 
 #else
diff --git a/src/utils_avltree.c b/src/utils_avltree.c
deleted file mode 100644 (file)
index ecaf3c9..0000000
+++ /dev/null
@@ -1,740 +0,0 @@
-/**
- * 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.
- *
- * 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
- *
- * Authors:
- *   Florian octo Forster <octo at verplant.org>
- **/
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-
-#include "utils_avltree.h"
-
-#define BALANCE(n) ((((n)->left == NULL) ? 0 : (n)->left->height) \
-               - (((n)->right == NULL) ? 0 : (n)->right->height))
-
-/*
- * private data types
- */
-struct c_avl_node_s
-{
-       void *key;
-       void *value;
-
-       int height;
-       struct c_avl_node_s *left;
-       struct c_avl_node_s *right;
-       struct c_avl_node_s *parent;
-};
-typedef struct c_avl_node_s c_avl_node_t;
-
-struct c_avl_tree_s
-{
-       c_avl_node_t *root;
-       int (*compare) (const void *, const void *);
-       int size;
-};
-
-struct c_avl_iterator_s
-{
-       c_avl_tree_t *tree;
-       c_avl_node_t *node;
-};
-
-/*
- * private functions
- */
-#if 0
-static void verify_tree (c_avl_node_t *n)
-{
-       if (n == NULL)
-               return;
-
-       verify_tree (n->left);
-       verify_tree (n->right);
-
-       assert ((BALANCE (n) >= -1) && (BALANCE (n) <= 1));
-       assert ((n->parent == NULL) || (n->parent->right == n) || (n->parent->left == n));
-} /* void verify_tree */
-#else
-# define verify_tree(n) /**/
-#endif
-
-static void free_node (c_avl_node_t *n)
-{
-       if (n == NULL)
-               return;
-
-       if (n->left != NULL)
-               free_node (n->left);
-       if (n->right != NULL)
-               free_node (n->right);
-
-       free (n);
-}
-
-static int calc_height (c_avl_node_t *n)
-{
-       int height_left;
-       int height_right;
-
-       if (n == NULL)
-               return (0);
-
-       height_left  = (n->left == NULL)  ? 0 : n->left->height;
-       height_right = (n->right == NULL) ? 0 : n->right->height;
-
-       return (((height_left > height_right)
-                               ? height_left
-                               : height_right) + 1);
-} /* int calc_height */
-
-static c_avl_node_t *search (c_avl_tree_t *t, const void *key)
-{
-       c_avl_node_t *n;
-       int cmp;
-
-       n = t->root;
-       while (n != NULL)
-       {
-               cmp = t->compare (key, n->key);
-               if (cmp == 0)
-                       return (n);
-               else if (cmp < 0)
-                       n = n->left;
-               else
-                       n = n->right;
-       }
-
-       return (NULL);
-}
-
-/*         (x)             (y)
- *        /   \           /   \
- *     (y)    /\         /\    (x)
- *    /   \  /_c\  ==>  / a\  /   \
- *   /\   /\           /____\/\   /\
- *  / a\ /_b\               /_b\ /_c\
- * /____\
- */
-static c_avl_node_t *rotate_right (c_avl_tree_t *t, c_avl_node_t *x)
-{
-       c_avl_node_t *p;
-       c_avl_node_t *y;
-       c_avl_node_t *b;
-
-       assert (x != NULL);
-       assert (x->left != NULL);
-
-       p = x->parent;
-       y = x->left;
-       b = y->right;
-
-       x->left = b;
-       if (b != NULL)
-               b->parent = x;
-
-       x->parent = y;
-       y->right = x;
-
-       y->parent = p;
-       assert ((p == NULL) || (p->left == x) || (p->right == x));
-       if (p == NULL)
-               t->root = y;
-       else if (p->left == x)
-               p->left = y;
-       else
-               p->right = y;
-
-       x->height = calc_height (x);
-       y->height = calc_height (y);
-
-       return (y);
-} /* void rotate_right */
-
-/*
- *    (x)                   (y)
- *   /   \                 /   \
- *  /\    (y)           (x)    /\
- * /_a\  /   \   ==>   /   \  / c\
- *      /\   /\       /\   /\/____\
- *     /_b\ / c\     /_a\ /_b\
- *         /____\
- */
-static c_avl_node_t *rotate_left (c_avl_tree_t *t, c_avl_node_t *x)
-{
-       c_avl_node_t *p;
-       c_avl_node_t *y;
-       c_avl_node_t *b;
-
-       assert (x != NULL);
-       assert (x->right != NULL);
-
-       p = x->parent;
-       y = x->right;
-       b = y->left;
-
-       x->right = b;
-       if (b != NULL)
-               b->parent = x;
-
-       x->parent = y;
-       y->left = x;
-
-       y->parent = p;
-       assert ((p == NULL) || (p->left == x) || (p->right == x));
-       if (p == NULL)
-               t->root = y;
-       else if (p->left == x)
-               p->left = y;
-       else
-               p->right = y;
-
-       x->height = calc_height (x);
-       y->height = calc_height (y);
-
-       return (y);
-} /* void rotate_left */
-
-static c_avl_node_t *rotate_left_right (c_avl_tree_t *t, c_avl_node_t *x)
-{
-       rotate_left (t, x->left);
-       return (rotate_right (t, x));
-} /* void rotate_left_right */
-
-static c_avl_node_t *rotate_right_left (c_avl_tree_t *t, c_avl_node_t *x)
-{
-       rotate_right (t, x->right);
-       return (rotate_left (t, x));
-} /* void rotate_right_left */
-
-static void rebalance (c_avl_tree_t *t, c_avl_node_t *n)
-{
-       int b_top;
-       int b_bottom;
-
-       while (n != NULL)
-       {
-               b_top = BALANCE (n);
-               assert ((b_top >= -2) && (b_top <= 2));
-
-               if (b_top == -2)
-               {
-                       assert (n->right != NULL);
-                       b_bottom = BALANCE (n->right);
-                       assert ((b_bottom >= -1) || (b_bottom <= 1));
-                       if (b_bottom == 1)
-                               n = rotate_right_left (t, n);
-                       else
-                               n = rotate_left (t, n);
-               }
-               else if (b_top == 2)
-               {
-                       assert (n->left != NULL);
-                       b_bottom = BALANCE (n->left);
-                       assert ((b_bottom >= -1) || (b_bottom <= 1));
-                       if (b_bottom == -1)
-                               n = rotate_left_right (t, n);
-                       else
-                               n = rotate_right (t, n);
-               }
-               else
-               {
-                       int height = calc_height (n);
-                       if (height == n->height)
-                               break;
-                       n->height = height;
-               }
-
-               assert (n->height == calc_height (n));
-
-               n = n->parent;
-       } /* while (n != NULL) */
-} /* void rebalance */
-
-static c_avl_node_t *c_avl_node_next (c_avl_node_t *n)
-{
-       c_avl_node_t *r; /* return node */
-
-       if (n == NULL)
-       {
-               return (NULL);
-       }
-
-       /* If we can't descent any further, we have to backtrack to the first
-        * parent that's bigger than we, i. e. who's _left_ child we are. */
-       if (n->right == NULL)
-       {
-               r = n->parent;
-               while ((r != NULL) && (r->parent != NULL))
-               {
-                       if (r->left == n)
-                               break;
-                       n = r;
-                       r = n->parent;
-               }
-
-               /* n->right == NULL && r == NULL => t is root and has no next
-                * r->left != n => r->right = n => r->parent == NULL */
-               if ((r == NULL) || (r->left != n))
-               {
-                       assert ((r == NULL) || (r->parent == NULL));
-                       return (NULL);
-               }
-               else
-               {
-                       assert (r->left == n);
-                       return (r);
-               }
-       }
-       else
-       {
-               r = n->right;
-               while (r->left != NULL)
-                       r = r->left;
-       }
-
-       return (r);
-} /* c_avl_node_t *c_avl_node_next */
-
-static c_avl_node_t *c_avl_node_prev (c_avl_node_t *n)
-{
-       c_avl_node_t *r; /* return node */
-
-       if (n == NULL)
-       {
-               return (NULL);
-       }
-
-       /* If we can't descent any further, we have to backtrack to the first
-        * parent that's smaller than we, i. e. who's _right_ child we are. */
-       if (n->left == NULL)
-       {
-               r = n->parent;
-               while ((r != NULL) && (r->parent != NULL))
-               {
-                       if (r->right == n)
-                               break;
-                       n = r;
-                       r = n->parent;
-               }
-
-               /* n->left == NULL && r == NULL => t is root and has no next
-                * r->right != n => r->left = n => r->parent == NULL */
-               if ((r == NULL) || (r->right != n))
-               {
-                       assert ((r == NULL) || (r->parent == NULL));
-                       return (NULL);
-               }
-               else
-               {
-                       assert (r->right == n);
-                       return (r);
-               }
-       }
-       else
-       {
-               r = n->left;
-               while (r->right != NULL)
-                       r = r->right;
-       }
-
-       return (r);
-} /* c_avl_node_t *c_avl_node_prev */
-
-static int _remove (c_avl_tree_t *t, c_avl_node_t *n)
-{
-       assert ((t != NULL) && (n != NULL));
-
-       if ((n->left != NULL) && (n->right != NULL))
-       {
-               c_avl_node_t *r; /* replacement node */
-               if (BALANCE (n) > 0) /* left subtree is higher */
-               {
-                       assert (n->left != NULL);
-                       r = c_avl_node_prev (n);
-                       
-               }
-               else /* right subtree is higher */
-               {
-                       assert (n->right != NULL);
-                       r = c_avl_node_next (n);
-               }
-
-               assert ((r->left == NULL) || (r->right == NULL));
-
-               /* copy content */
-               n->key   = r->key;
-               n->value = r->value;
-
-               n = r;
-       }
-
-       assert ((n->left == NULL) || (n->right == NULL));
-
-       if ((n->left == NULL) && (n->right == NULL))
-       {
-               /* Deleting a leave is easy */
-               if (n->parent == NULL)
-               {
-                       assert (t->root == n);
-                       t->root = NULL;
-               }
-               else
-               {
-                       assert ((n->parent->left == n)
-                                       || (n->parent->right == n));
-                       if (n->parent->left == n)
-                               n->parent->left = NULL;
-                       else
-                               n->parent->right = NULL;
-
-                       rebalance (t, n->parent);
-               }
-
-               free_node (n);
-       }
-       else if (n->left == NULL)
-       {
-               assert (BALANCE (n) == -1);
-               assert ((n->parent == NULL) || (n->parent->left == n) || (n->parent->right == n));
-               if (n->parent == NULL)
-               {
-                       assert (t->root == n);
-                       t->root = n->right;
-               }
-               else if (n->parent->left == n)
-               {
-                       n->parent->left = n->right;
-               }
-               else
-               {
-                       n->parent->right = n->right;
-               }
-               n->right->parent = n->parent;
-
-               if (n->parent != NULL)
-                       rebalance (t, n->parent);
-
-               n->right = NULL;
-               free_node (n);
-       }
-       else if (n->right == NULL)
-       {
-               assert (BALANCE (n) == 1);
-               assert ((n->parent == NULL) || (n->parent->left == n) || (n->parent->right == n));
-               if (n->parent == NULL)
-               {
-                       assert (t->root == n);
-                       t->root = n->left;
-               }
-               else if (n->parent->left == n)
-               {
-                       n->parent->left = n->left;
-               }
-               else
-               {
-                       n->parent->right = n->left;
-               }
-               n->left->parent = n->parent;
-
-               if (n->parent != NULL)
-                       rebalance (t, n->parent);
-
-               n->left = NULL;
-               free_node (n);
-       }
-       else
-       {
-               assert (0);
-       }
-
-       return (0);
-} /* void *_remove */
-
-/*
- * public functions
- */
-c_avl_tree_t *c_avl_create (int (*compare) (const void *, const void *))
-{
-       c_avl_tree_t *t;
-
-       if (compare == NULL)
-               return (NULL);
-
-       if ((t = (c_avl_tree_t *) malloc (sizeof (c_avl_tree_t))) == NULL)
-               return (NULL);
-
-       t->root = NULL;
-       t->compare = compare;
-       t->size = 0;
-
-       return (t);
-}
-
-void c_avl_destroy (c_avl_tree_t *t)
-{
-       if (t == NULL)
-               return;
-       free_node (t->root);
-       free (t);
-}
-
-int c_avl_insert (c_avl_tree_t *t, void *key, void *value)
-{
-       c_avl_node_t *new;
-       c_avl_node_t *nptr;
-       int cmp;
-
-       if ((new = (c_avl_node_t *) malloc (sizeof (c_avl_node_t))) == NULL)
-               return (-1);
-
-       new->key = key;
-       new->value = value;
-       new->height = 1;
-       new->left = NULL;
-       new->right = NULL;
-
-       if (t->root == NULL)
-       {
-               new->parent = NULL;
-               t->root = new;
-               t->size = 1;
-               return (0);
-       }
-
-       nptr = t->root;
-       while (42)
-       {
-               cmp = t->compare (nptr->key, new->key);
-               if (cmp == 0)
-               {
-                       free_node (new);
-                       return (1);
-               }
-               else if (cmp < 0)
-               {
-                       /* nptr < new */
-                       if (nptr->right == NULL)
-                       {
-                               nptr->right = new;
-                               new->parent = nptr;
-                               rebalance (t, nptr);
-                               break;
-                       }
-                       else
-                       {
-                               nptr = nptr->right;
-                       }
-               }
-               else /* if (cmp > 0) */
-               {
-                       /* nptr > new */
-                       if (nptr->left == NULL)
-                       {
-                               nptr->left = new;
-                               new->parent = nptr;
-                               rebalance (t, nptr);
-                               break;
-                       }
-                       else
-                       {
-                               nptr = nptr->left;
-                       }
-               }
-       } /* while (42) */
-
-       verify_tree (t->root);
-       ++t->size;
-       return (0);
-} /* int c_avl_insert */
-
-int c_avl_remove (c_avl_tree_t *t, const void *key, void **rkey, void **rvalue)
-{
-       c_avl_node_t *n;
-       int status;
-
-       assert (t != NULL);
-
-       n = search (t, key);
-       if (n == NULL)
-               return (-1);
-
-       if (rkey != NULL)
-               *rkey = n->key;
-       if (rvalue != NULL)
-               *rvalue = n->value;
-
-       status = _remove (t, n);
-       verify_tree (t->root);
-       --t->size;
-       return (status);
-} /* void *c_avl_remove */
-
-int c_avl_get (c_avl_tree_t *t, const void *key, void **value)
-{
-       c_avl_node_t *n;
-
-       assert (t != NULL);
-
-       n = search (t, key);
-       if (n == NULL)
-               return (-1);
-
-       if (value != NULL)
-               *value = n->value;
-
-       return (0);
-}
-
-int c_avl_pick (c_avl_tree_t *t, void **key, void **value)
-{
-       c_avl_node_t *n;
-       c_avl_node_t *p;
-
-       if ((key == NULL) || (value == NULL))
-               return (-1);
-       if (t->root == NULL)
-               return (-1);
-
-       n = t->root;
-       while ((n->left != NULL) || (n->right != NULL))
-       {
-               if (n->left == NULL)
-               {
-                       n = n->right;
-                       continue;
-               }
-               else if (n->right == NULL)
-               {
-                       n = n->left;
-                       continue;
-               }
-
-               if (n->left->height > n->right->height)
-                       n = n->left;
-               else
-                       n = n->right;
-       }
-
-       p = n->parent;
-       if (p == NULL)
-               t->root = NULL;
-       else if (p->left == n)
-               p->left = NULL;
-       else
-               p->right = NULL;
-
-       *key   = n->key;
-       *value = n->value;
-
-       free_node (n);
-       rebalance (t, p);
-
-       return (0);
-} /* int c_avl_pick */
-
-c_avl_iterator_t *c_avl_get_iterator (c_avl_tree_t *t)
-{
-       c_avl_iterator_t *iter;
-
-       if (t == NULL)
-               return (NULL);
-
-       iter = (c_avl_iterator_t *) malloc (sizeof (c_avl_iterator_t));
-       if (iter == NULL)
-               return (NULL);
-       memset (iter, '\0', sizeof (c_avl_iterator_t));
-       iter->tree = t;
-
-       return (iter);
-} /* c_avl_iterator_t *c_avl_get_iterator */
-
-int c_avl_iterator_next (c_avl_iterator_t *iter, void **key, void **value)
-{
-       c_avl_node_t *n;
-
-       if ((iter == NULL) || (key == NULL) || (value == NULL))
-               return (-1);
-
-       if (iter->node == NULL)
-       {
-               for (n = iter->tree->root; n != NULL; n = n->left)
-                       if (n->left == NULL)
-                               break;
-               iter->node = n;
-       }
-       else
-       {
-               n = c_avl_node_next (iter->node);
-       }
-
-       if (n == NULL)
-               return (-1);
-
-       iter->node = n;
-       *key = n->key;
-       *value = n->value;
-
-       return (0);
-} /* int c_avl_iterator_next */
-
-int c_avl_iterator_prev (c_avl_iterator_t *iter, void **key, void **value)
-{
-       c_avl_node_t *n;
-
-       if ((iter == NULL) || (key == NULL) || (value == NULL))
-               return (-1);
-
-       if (iter->node == NULL)
-       {
-               for (n = iter->tree->root; n != NULL; n = n->left)
-                       if (n->right == NULL)
-                               break;
-               iter->node = n;
-       }
-       else
-       {
-               n = c_avl_node_prev (iter->node);
-       }
-
-       if (n == NULL)
-               return (-1);
-
-       iter->node = n;
-       *key = n->key;
-       *value = n->value;
-
-       return (0);
-} /* int c_avl_iterator_prev */
-
-void c_avl_iterator_destroy (c_avl_iterator_t *iter)
-{
-       free (iter);
-}
-
-int c_avl_size (c_avl_tree_t *t)
-{
-       if (t == NULL)
-               return (0);
-       return (t->size);
-}
diff --git a/src/utils_avltree.h b/src/utils_avltree.h
deleted file mode 100644 (file)
index 10fb5cb..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/**
- * 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
- *
- * Authors:
- *   Florian octo Forster <octo at verplant.org>
- **/
-
-#ifndef UTILS_AVLTREE_H
-#define UTILS_AVLTREE_H 1
-
-struct c_avl_tree_s;
-typedef struct c_avl_tree_s c_avl_tree_t;
-
-struct c_avl_iterator_s;
-typedef struct c_avl_iterator_s c_avl_iterator_t;
-
-/*
- * NAME
- *   c_avl_create
- *
- * DESCRIPTION
- *   Allocates a new AVL-tree.
- *
- * PARAMETERS
- *   `compare'  The function-pointer `compare' is used to compare two keys. It
- *              has to return less than zero if it's first argument is smaller
- *              then the second argument, more than zero if the first argument
- *              is bigger than the second argument and zero if they are equal.
- *              If your keys are char-pointers, you can use the `strcmp'
- *              function from the libc here.
- *
- * RETURN VALUE
- *   A c_avl_tree_t-pointer upon success or NULL upon failure.
- */
-c_avl_tree_t *c_avl_create (int (*compare) (const void *, const void *));
-
-
-/*
- * NAME
- *   c_avl_destroy
- *
- * DESCRIPTION
- *   Deallocates an AVL-tree. Stored value- and key-pointer are lost, but of
- *   course not freed.
- */
-void c_avl_destroy (c_avl_tree_t *t);
-
-/*
- * NAME
- *   c_avl_insert
- *
- * DESCRIPTION
- *   Stores the key-value-pair in the AVL-tree pointed to by `t'.
- *
- * PARAMETERS
- *   `t'        AVL-tree to store the data in.
- *   `key'      Key used to store the value under. This is used to get back to
- *              the value again. The pointer is stored in an internal structure
- *              and _not_ copied. So the memory pointed to may _not_ be freed
- *              before this entry is removed. You can use the `rkey' argument
- *              to `avl_remove' to get the original pointer back and free it.
- *   `value'    Value to be stored.
- *
- * RETURN VALUE
- *   Zero upon success, non-zero otherwise. It's less than zero if an error
- *   occurred or greater than zero if the key is already stored in the tree.
- */
-int c_avl_insert (c_avl_tree_t *t, void *key, void *value);
-
-/*
- * NAME
- *   c_avl_remove
- *
- * DESCRIPTION
- *   Removes a key-value-pair from the tree t. The stored key and value may be
- *   returned in `rkey' and `rvalue'.
- *
- * PARAMETERS
- *   `t'       AVL-tree to remove key-value-pair from.
- *   `key'      Key to identify the entry.
- *   `rkey'     Pointer to a pointer in which to store the key. May be NULL.
- *              Since the `key' pointer is not copied when creating an entry,
- *              the pointer may not be available anymore from outside the tree.
- *              You can use this argument to get the actual pointer back and
- *              free the memory pointed to by it.
- *   `rvalue'   Pointer to a pointer in which to store the value. May be NULL.
- *
- * RETURN VALUE
- *   Zero upon success or non-zero if the key isn't found in the tree.
- */
-int c_avl_remove (c_avl_tree_t *t, const void *key, void **rkey, void **rvalue);
-
-/*
- * NAME
- *   c_avl_get
- *
- * DESCRIPTION
- *   Retrieve the `value' belonging to `key'.
- *
- * PARAMETERS
- *   `t'       AVL-tree to get the value from.
- *   `key'      Key to identify the entry.
- *   `value'    Pointer to a pointer in which to store the value. May be NULL.
- *
- * RETURN VALUE
- *   Zero upon success or non-zero if the key isn't found in the tree.
- */
-int c_avl_get (c_avl_tree_t *t, const void *key, void **value);
-
-/*
- * NAME
- *   c_avl_pick
- *
- * DESCRIPTION
- *   Remove a (pseudo-)random element from the tree and return it's `key' and
- *   `value'. Entries are not returned in any particular order. This function
- *   is intended for cache-flushes that don't care about the order but simply
- *   want to remove all elements, one at a time.
- *
- * PARAMETERS
- *   `t'       AVL-tree to get the value from.
- *   `key'      Pointer to a pointer in which to store the key.
- *   `value'    Pointer to a pointer in which to store the value.
- *
- * RETURN VALUE
- *   Zero upon success or non-zero if the tree is empty or key or value is
- *   NULL.
- */
-int c_avl_pick (c_avl_tree_t *t, void **key, void **value);
-
-c_avl_iterator_t *c_avl_get_iterator (c_avl_tree_t *t);
-int c_avl_iterator_next (c_avl_iterator_t *iter, void **key, void **value);
-int c_avl_iterator_prev (c_avl_iterator_t *iter, void **key, void **value);
-void c_avl_iterator_destroy (c_avl_iterator_t *iter);
-
-/*
- * NAME
- *   c_avl_size
- *
- * DESCRIPTION
- *   Return the size (number of nodes) of the specified tree.
- *
- * PARAMETERS
- *   `t'        AVL-tree to get the size of.
- *
- * RETURN VALUE
- *   Number of nodes in the tree, 0 if the tree is empty or NULL.
- */
-int c_avl_size (c_avl_tree_t *t);
-
-#endif /* UTILS_AVLTREE_H */
diff --git a/src/utils_cache.c b/src/utils_cache.c
deleted file mode 100644 (file)
index 910e30b..0000000
+++ /dev/null
@@ -1,980 +0,0 @@
-/**
- * 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.
- *
- * 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:
- *   Florian octo Forster <octo at collectd.org>
- **/
-
-#include "collectd.h"
-#include "common.h"
-#include "plugin.h"
-#include "utils_avltree.h"
-#include "utils_cache.h"
-#include "meta_data.h"
-
-#include <assert.h>
-#include <pthread.h>
-
-typedef struct cache_entry_s
-{
-       char name[6 * DATA_MAX_NAME_LEN];
-       int        values_num;
-       gauge_t   *values_gauge;
-       value_t   *values_raw;
-       /* Time contained in the package
-        * (for calculating rates) */
-       cdtime_t last_time;
-       /* Time according to the local clock
-        * (for purging old entries) */
-       cdtime_t last_update;
-       /* Interval in which the data is collected
-        * (for purding old entries) */
-       cdtime_t interval;
-       int state;
-       int hits;
-
-       /*
-        * +-----+-----+-----+-----+-----+-----+-----+-----+-----+----
-        * !  0  !  1  !  2  !  3  !  4  !  5  !  6  !  7  !  8  ! ...
-        * +-----+-----+-----+-----+-----+-----+-----+-----+-----+----
-        * ! ds0 ! ds1 ! ds2 ! ds0 ! ds1 ! ds2 ! ds0 ! ds1 ! ds2 ! ...
-        * +-----+-----+-----+-----+-----+-----+-----+-----+-----+----
-        * !      t = 0      !      t = 1      !      t = 2      ! ...
-        * +-----------------+-----------------+-----------------+----
-        */
-       gauge_t *history;
-       size_t   history_index; /* points to the next position to write to. */
-       size_t   history_length;
-
-       meta_data_t *meta;
-} cache_entry_t;
-
-static c_avl_tree_t   *cache_tree = NULL;
-static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
-
-static int cache_compare (const cache_entry_t *a, const cache_entry_t *b)
-{
-  assert ((a != NULL) && (b != NULL));
-  return (strcmp (a->name, b->name));
-} /* int cache_compare */
-
-static cache_entry_t *cache_alloc (int values_num)
-{
-  cache_entry_t *ce;
-
-  ce = (cache_entry_t *) malloc (sizeof (cache_entry_t));
-  if (ce == NULL)
-  {
-    ERROR ("utils_cache: cache_alloc: malloc failed.");
-    return (NULL);
-  }
-  memset (ce, '\0', sizeof (cache_entry_t));
-  ce->values_num = values_num;
-
-  ce->values_gauge = calloc (values_num, sizeof (*ce->values_gauge));
-  ce->values_raw   = calloc (values_num, sizeof (*ce->values_raw));
-  if ((ce->values_gauge == NULL) || (ce->values_raw == NULL))
-  {
-    sfree (ce->values_gauge);
-    sfree (ce->values_raw);
-    sfree (ce);
-    ERROR ("utils_cache: cache_alloc: calloc failed.");
-    return (NULL);
-  }
-
-  ce->history = NULL;
-  ce->history_length = 0;
-  ce->meta = NULL;
-
-  return (ce);
-} /* cache_entry_t *cache_alloc */
-
-static void cache_free (cache_entry_t *ce)
-{
-  if (ce == NULL)
-    return;
-
-  sfree (ce->values_gauge);
-  sfree (ce->values_raw);
-  sfree (ce->history);
-  if (ce->meta != NULL)
-  {
-    meta_data_destroy (ce->meta);
-    ce->meta = NULL;
-  }
-  sfree (ce);
-} /* void cache_free */
-
-static void uc_check_range (const data_set_t *ds, cache_entry_t *ce)
-{
-  int i;
-
-  for (i = 0; i < ds->ds_num; i++)
-  {
-    if (isnan (ce->values_gauge[i]))
-      continue;
-    else if (ce->values_gauge[i] < ds->ds[i].min)
-      ce->values_gauge[i] = NAN;
-    else if (ce->values_gauge[i] > ds->ds[i].max)
-      ce->values_gauge[i] = NAN;
-  }
-} /* void uc_check_range */
-
-static int uc_insert (const data_set_t *ds, const value_list_t *vl,
-    const char *key)
-{
-  int i;
-  char *key_copy;
-  cache_entry_t *ce;
-
-  /* `cache_lock' has been locked by `uc_update' */
-
-  key_copy = strdup (key);
-  if (key_copy == NULL)
-  {
-    ERROR ("uc_insert: strdup failed.");
-    return (-1);
-  }
-
-  ce = cache_alloc (ds->ds_num);
-  if (ce == NULL)
-  {
-    sfree (key_copy);
-    ERROR ("uc_insert: cache_alloc (%i) failed.", ds->ds_num);
-    return (-1);
-  }
-
-  sstrncpy (ce->name, key, sizeof (ce->name));
-
-  for (i = 0; i < ds->ds_num; i++)
-  {
-    switch (ds->ds[i].type)
-    {
-      case DS_TYPE_COUNTER:
-       ce->values_gauge[i] = NAN;
-       ce->values_raw[i].counter = vl->values[i].counter;
-       break;
-
-      case DS_TYPE_GAUGE:
-       ce->values_gauge[i] = vl->values[i].gauge;
-       ce->values_raw[i].gauge = vl->values[i].gauge;
-       break;
-
-      case DS_TYPE_DERIVE:
-       ce->values_gauge[i] = NAN;
-       ce->values_raw[i].derive = vl->values[i].derive;
-       break;
-
-      case DS_TYPE_ABSOLUTE:
-       ce->values_gauge[i] = NAN;
-       if (vl->interval > 0)
-         ce->values_gauge[i] = ((double) vl->values[i].absolute)
-           / CDTIME_T_TO_DOUBLE (vl->interval);
-       ce->values_raw[i].absolute = vl->values[i].absolute;
-       break;
-       
-      default:
-       /* This shouldn't happen. */
-       ERROR ("uc_insert: Don't know how to handle data source type %i.",
-           ds->ds[i].type);
-       sfree (key_copy);
-       return (-1);
-    } /* switch (ds->ds[i].type) */
-  } /* for (i) */
-
-  /* Prune invalid gauge data */
-  uc_check_range (ds, ce);
-
-  ce->last_time = vl->time;
-  ce->last_update = cdtime ();
-  ce->interval = vl->interval;
-  ce->state = STATE_OKAY;
-
-  if (c_avl_insert (cache_tree, key_copy, ce) != 0)
-  {
-    sfree (key_copy);
-    ERROR ("uc_insert: c_avl_insert failed.");
-    return (-1);
-  }
-
-  DEBUG ("uc_insert: Added %s to the cache.", key);
-  return (0);
-} /* int uc_insert */
-
-int uc_init (void)
-{
-  if (cache_tree == NULL)
-    cache_tree = c_avl_create ((int (*) (const void *, const void *))
-       cache_compare);
-
-  return (0);
-} /* int uc_init */
-
-int uc_check_timeout (void)
-{
-  cdtime_t now;
-  cache_entry_t *ce;
-
-  char **keys = NULL;
-  cdtime_t *keys_time = NULL;
-  cdtime_t *keys_interval = NULL;
-  int keys_len = 0;
-
-  char *key;
-  c_avl_iterator_t *iter;
-
-  int status;
-  int i;
-  
-  pthread_mutex_lock (&cache_lock);
-
-  now = cdtime ();
-
-  /* Build a list of entries to be flushed */
-  iter = c_avl_get_iterator (cache_tree);
-  while (c_avl_iterator_next (iter, (void *) &key, (void *) &ce) == 0)
-  {
-    char **tmp;
-    cdtime_t *tmp_time;
-
-    /* If the entry is fresh enough, continue. */
-    if ((now - ce->last_update) < (ce->interval * timeout_g))
-      continue;
-
-    /* If entry has not been updated, add to `keys' array */
-    tmp = (char **) realloc ((void *) keys,
-       (keys_len + 1) * sizeof (char *));
-    if (tmp == NULL)
-    {
-      ERROR ("uc_check_timeout: realloc failed.");
-      continue;
-    }
-    keys = tmp;
-
-    tmp_time = realloc (keys_time, (keys_len + 1) * sizeof (*keys_time));
-    if (tmp_time == NULL)
-    {
-      ERROR ("uc_check_timeout: realloc failed.");
-      continue;
-    }
-    keys_time = tmp_time;
-
-    tmp_time = realloc (keys_interval, (keys_len + 1) * sizeof (*keys_interval));
-    if (tmp_time == NULL)
-    {
-      ERROR ("uc_check_timeout: realloc failed.");
-      continue;
-    }
-    keys_interval = tmp_time;
-
-    keys[keys_len] = strdup (key);
-    if (keys[keys_len] == NULL)
-    {
-      ERROR ("uc_check_timeout: strdup failed.");
-      continue;
-    }
-    keys_time[keys_len] = ce->last_time;
-    keys_interval[keys_len] = ce->interval;
-
-    keys_len++;
-  } /* while (c_avl_iterator_next) */
-
-  c_avl_iterator_destroy (iter);
-  pthread_mutex_unlock (&cache_lock);
-
-  if (keys_len == 0)
-  {
-    /* realloc() may have been called for these. */
-    sfree (keys);
-    sfree (keys_time);
-    sfree (keys_interval);
-    return (0);
-  }
-
-  /* Call the "missing" callback for each value. Do this before removing the
-   * value from the cache, so that callbacks can still access the data stored,
-   * including plugin specific meta data, rates, history, …. This must be done
-   * without holding the lock, otherwise we will run into a deadlock if a
-   * plugin calls the cache interface. */
-  for (i = 0; i < keys_len; i++)
-  {
-    value_list_t vl = VALUE_LIST_INIT;
-
-    vl.values = NULL;
-    vl.values_len = 0;
-    vl.meta = NULL;
-
-    status = parse_identifier_vl (keys[i], &vl);
-    if (status != 0)
-    {
-      ERROR ("uc_check_timeout: parse_identifier_vl (\"%s\") failed.", keys[i]);
-      continue;
-    }
-
-    vl.time = keys_time[i];
-    vl.interval = keys_interval[i];
-
-    plugin_dispatch_missing (&vl);
-  } /* for (i = 0; i < keys_len; i++) */
-
-  /* Now actually remove all the values from the cache. We don't re-evaluate
-   * the timestamp again, so in theory it is possible we remove a value after
-   * it is updated here. */
-  pthread_mutex_lock (&cache_lock);
-  for (i = 0; i < keys_len; i++)
-  {
-    key = NULL;
-    ce = NULL;
-
-    status = c_avl_remove (cache_tree, keys[i],
-       (void *) &key, (void *) &ce);
-    if (status != 0)
-    {
-      ERROR ("uc_check_timeout: c_avl_remove (\"%s\") failed.", keys[i]);
-      sfree (keys[i]);
-      continue;
-    }
-
-    sfree (keys[i]);
-    sfree (key);
-    cache_free (ce);
-  } /* for (i = 0; i < keys_len; i++) */
-  pthread_mutex_unlock (&cache_lock);
-
-  sfree (keys);
-  sfree (keys_time);
-  sfree (keys_interval);
-
-  return (0);
-} /* int uc_check_timeout */
-
-int uc_update (const data_set_t *ds, const value_list_t *vl)
-{
-  char name[6 * DATA_MAX_NAME_LEN];
-  cache_entry_t *ce = NULL;
-  int status;
-  int i;
-
-  if (FORMAT_VL (name, sizeof (name), vl) != 0)
-  {
-    ERROR ("uc_update: FORMAT_VL failed.");
-    return (-1);
-  }
-
-  pthread_mutex_lock (&cache_lock);
-
-  status = c_avl_get (cache_tree, name, (void *) &ce);
-  if (status != 0) /* entry does not yet exist */
-  {
-    status = uc_insert (ds, vl, name);
-    pthread_mutex_unlock (&cache_lock);
-    return (status);
-  }
-
-  assert (ce != NULL);
-  assert (ce->values_num == ds->ds_num);
-
-  if (ce->last_time >= vl->time)
-  {
-    pthread_mutex_unlock (&cache_lock);
-    NOTICE ("uc_update: Value too old: name = %s; value time = %.3f; "
-       "last cache update = %.3f;",
-       name,
-       CDTIME_T_TO_DOUBLE (vl->time),
-       CDTIME_T_TO_DOUBLE (ce->last_time));
-    return (-1);
-  }
-
-  for (i = 0; i < ds->ds_num; i++)
-  {
-    switch (ds->ds[i].type)
-    {
-      case DS_TYPE_COUNTER:
-       {
-         counter_t diff;
-
-         /* check if the counter has wrapped around */
-         if (vl->values[i].counter < ce->values_raw[i].counter)
-         {
-           if (ce->values_raw[i].counter <= 4294967295U)
-             diff = (4294967295U - ce->values_raw[i].counter)
-               + vl->values[i].counter;
-           else
-             diff = (18446744073709551615ULL - ce->values_raw[i].counter)
-               + vl->values[i].counter;
-         }
-         else /* counter has NOT wrapped around */
-         {
-           diff = vl->values[i].counter - ce->values_raw[i].counter;
-         }
-
-         ce->values_gauge[i] = ((double) diff)
-           / (CDTIME_T_TO_DOUBLE (vl->time - ce->last_time));
-         ce->values_raw[i].counter = vl->values[i].counter;
-       }
-       break;
-
-      case DS_TYPE_GAUGE:
-       ce->values_raw[i].gauge = vl->values[i].gauge;
-       ce->values_gauge[i] = vl->values[i].gauge;
-       break;
-
-      case DS_TYPE_DERIVE:
-       {
-         derive_t diff;
-
-         diff = vl->values[i].derive - ce->values_raw[i].derive;
-
-         ce->values_gauge[i] = ((double) diff)
-           / (CDTIME_T_TO_DOUBLE (vl->time - ce->last_time));
-         ce->values_raw[i].derive = vl->values[i].derive;
-       }
-       break;
-
-      case DS_TYPE_ABSOLUTE:
-       ce->values_gauge[i] = ((double) vl->values[i].absolute)
-         / (CDTIME_T_TO_DOUBLE (vl->time - ce->last_time));
-       ce->values_raw[i].absolute = vl->values[i].absolute;
-       break;
-
-      default:
-       /* This shouldn't happen. */
-       pthread_mutex_unlock (&cache_lock);
-       ERROR ("uc_update: Don't know how to handle data source type %i.",
-           ds->ds[i].type);
-       return (-1);
-    } /* switch (ds->ds[i].type) */
-
-    DEBUG ("uc_update: %s: ds[%i] = %lf", name, i, ce->values_gauge[i]);
-  } /* for (i) */
-
-  /* Update the history if it exists. */
-  if (ce->history != NULL)
-  {
-    assert (ce->history_index < ce->history_length);
-    for (i = 0; i < ce->values_num; i++)
-    {
-      size_t hist_idx = (ce->values_num * ce->history_index) + i;
-      ce->history[hist_idx] = ce->values_gauge[i];
-    }
-
-    assert (ce->history_length > 0);
-    ce->history_index = (ce->history_index + 1) % ce->history_length;
-  }
-
-  /* Prune invalid gauge data */
-  uc_check_range (ds, ce);
-
-  ce->last_time = vl->time;
-  ce->last_update = cdtime ();
-  ce->interval = vl->interval;
-
-  pthread_mutex_unlock (&cache_lock);
-
-  return (0);
-} /* int uc_update */
-
-int uc_get_rate_by_name (const char *name, gauge_t **ret_values, size_t *ret_values_num)
-{
-  gauge_t *ret = NULL;
-  size_t ret_num = 0;
-  cache_entry_t *ce = NULL;
-  int status = 0;
-
-  pthread_mutex_lock (&cache_lock);
-
-  if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
-  {
-    assert (ce != NULL);
-
-    /* remove missing values from getval */
-    if (ce->state == STATE_MISSING)
-    {
-      status = -1;
-    }
-    else
-    {
-      ret_num = ce->values_num;
-      ret = (gauge_t *) malloc (ret_num * sizeof (gauge_t));
-      if (ret == NULL)
-      {
-        ERROR ("utils_cache: uc_get_rate_by_name: malloc failed.");
-        status = -1;
-      }
-      else
-      {
-        memcpy (ret, ce->values_gauge, ret_num * sizeof (gauge_t));
-      }
-    }
-  }
-  else
-  {
-    DEBUG ("utils_cache: uc_get_rate_by_name: No such value: %s", name);
-    status = -1;
-  }
-
-  pthread_mutex_unlock (&cache_lock);
-
-  if (status == 0)
-  {
-    *ret_values = ret;
-    *ret_values_num = ret_num;
-  }
-
-  return (status);
-} /* gauge_t *uc_get_rate_by_name */
-
-gauge_t *uc_get_rate (const data_set_t *ds, const value_list_t *vl)
-{
-  char name[6 * DATA_MAX_NAME_LEN];
-  gauge_t *ret = NULL;
-  size_t ret_num = 0;
-  int status;
-
-  if (FORMAT_VL (name, sizeof (name), vl) != 0)
-  {
-    ERROR ("utils_cache: uc_get_rate: FORMAT_VL failed.");
-    return (NULL);
-  }
-
-  status = uc_get_rate_by_name (name, &ret, &ret_num);
-  if (status != 0)
-    return (NULL);
-
-  /* This is important - the caller has no other way of knowing how many
-   * values are returned. */
-  if (ret_num != (size_t) ds->ds_num)
-  {
-    ERROR ("utils_cache: uc_get_rate: ds[%s] has %i values, "
-       "but uc_get_rate_by_name returned %zu.",
-       ds->type, ds->ds_num, ret_num);
-    sfree (ret);
-    return (NULL);
-  }
-
-  return (ret);
-} /* gauge_t *uc_get_rate */
-
-int uc_get_names (char ***ret_names, cdtime_t **ret_times, size_t *ret_number)
-{
-  c_avl_iterator_t *iter;
-  char *key;
-  cache_entry_t *value;
-
-  char **names = NULL;
-  cdtime_t *times = NULL;
-  size_t number = 0;
-  size_t size_arrays = 0;
-
-  int status = 0;
-
-  if ((ret_names == NULL) || (ret_number == NULL))
-    return (-1);
-
-  pthread_mutex_lock (&cache_lock);
-
-  size_arrays = (size_t) c_avl_size (cache_tree);
-  if (size_arrays < 1)
-  {
-    /* Handle the "no values" case here, to avoid the error message when
-     * calloc() returns NULL. */
-    pthread_mutex_unlock (&cache_lock);
-    return (0);
-  }
-
-  names = calloc (size_arrays, sizeof (*names));
-  times = calloc (size_arrays, sizeof (*times));
-  if ((names == NULL) || (times == NULL))
-  {
-    ERROR ("uc_get_names: calloc failed.");
-    sfree (names);
-    sfree (times);
-    pthread_mutex_unlock (&cache_lock);
-    return (ENOMEM);
-  }
-
-  iter = c_avl_get_iterator (cache_tree);
-  while (c_avl_iterator_next (iter, (void *) &key, (void *) &value) == 0)
-  {
-    /* remove missing values when list values */
-    if (value->state == STATE_MISSING)
-      continue;
-
-    /* c_avl_size does not return a number smaller than the number of elements
-     * returned by c_avl_iterator_next. */
-    assert (number < size_arrays);
-
-    if (ret_times != NULL)
-      times[number] = value->last_time;
-
-    names[number] = strdup (key);
-    if (names[number] == NULL)
-    {
-      status = -1;
-      break;
-    }
-
-    number++;
-  } /* while (c_avl_iterator_next) */
-
-  c_avl_iterator_destroy (iter);
-  pthread_mutex_unlock (&cache_lock);
-
-  if (status != 0)
-  {
-    size_t i;
-
-    for (i = 0; i < number; i++)
-    {
-      sfree (names[i]);
-    }
-    sfree (names);
-    sfree (times);
-
-    return (-1);
-  }
-
-  *ret_names = names;
-  if (ret_times != NULL)
-    *ret_times = times;
-  else
-    sfree (times);
-  *ret_number = number;
-
-  return (0);
-} /* int uc_get_names */
-
-int uc_get_state (const data_set_t *ds, const value_list_t *vl)
-{
-  char name[6 * DATA_MAX_NAME_LEN];
-  cache_entry_t *ce = NULL;
-  int ret = STATE_ERROR;
-
-  if (FORMAT_VL (name, sizeof (name), vl) != 0)
-  {
-    ERROR ("uc_get_state: FORMAT_VL failed.");
-    return (STATE_ERROR);
-  }
-
-  pthread_mutex_lock (&cache_lock);
-
-  if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
-  {
-    assert (ce != NULL);
-    ret = ce->state;
-  }
-
-  pthread_mutex_unlock (&cache_lock);
-
-  return (ret);
-} /* int uc_get_state */
-
-int uc_set_state (const data_set_t *ds, const value_list_t *vl, int state)
-{
-  char name[6 * DATA_MAX_NAME_LEN];
-  cache_entry_t *ce = NULL;
-  int ret = -1;
-
-  if (FORMAT_VL (name, sizeof (name), vl) != 0)
-  {
-    ERROR ("uc_get_state: FORMAT_VL failed.");
-    return (STATE_ERROR);
-  }
-
-  pthread_mutex_lock (&cache_lock);
-
-  if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
-  {
-    assert (ce != NULL);
-    ret = ce->state;
-    ce->state = state;
-  }
-
-  pthread_mutex_unlock (&cache_lock);
-
-  return (ret);
-} /* int uc_set_state */
-
-int uc_get_history_by_name (const char *name,
-    gauge_t *ret_history, size_t num_steps, size_t num_ds)
-{
-  cache_entry_t *ce = NULL;
-  size_t i;
-  int status = 0;
-
-  pthread_mutex_lock (&cache_lock);
-
-  status = c_avl_get (cache_tree, name, (void *) &ce);
-  if (status != 0)
-  {
-    pthread_mutex_unlock (&cache_lock);
-    return (-ENOENT);
-  }
-
-  if (((size_t) ce->values_num) != num_ds)
-  {
-    pthread_mutex_unlock (&cache_lock);
-    return (-EINVAL);
-  }
-
-  /* Check if there are enough values available. If not, increase the buffer
-   * size. */
-  if (ce->history_length < num_steps)
-  {
-    gauge_t *tmp;
-    size_t i;
-
-    tmp = realloc (ce->history, sizeof (*ce->history)
-       * num_steps * ce->values_num);
-    if (tmp == NULL)
-    {
-      pthread_mutex_unlock (&cache_lock);
-      return (-ENOMEM);
-    }
-
-    for (i = ce->history_length * ce->values_num;
-       i < (num_steps * ce->values_num);
-       i++)
-      tmp[i] = NAN;
-
-    ce->history = tmp;
-    ce->history_length = num_steps;
-  } /* if (ce->history_length < num_steps) */
-
-  /* Copy the values to the output buffer. */
-  for (i = 0; i < num_steps; i++)
-  {
-    size_t src_index;
-    size_t dst_index;
-
-    if (i < ce->history_index)
-      src_index = ce->history_index - (i + 1);
-    else
-      src_index = ce->history_length + ce->history_index - (i + 1);
-    src_index = src_index * num_ds;
-
-    dst_index = i * num_ds;
-
-    memcpy (ret_history + dst_index, ce->history + src_index,
-       sizeof (*ret_history) * num_ds);
-  }
-
-  pthread_mutex_unlock (&cache_lock);
-
-  return (0);
-} /* int uc_get_history_by_name */
-
-int uc_get_history (const data_set_t *ds, const value_list_t *vl,
-    gauge_t *ret_history, size_t num_steps, size_t num_ds)
-{
-  char name[6 * DATA_MAX_NAME_LEN];
-
-  if (FORMAT_VL (name, sizeof (name), vl) != 0)
-  {
-    ERROR ("utils_cache: uc_get_history: FORMAT_VL failed.");
-    return (-1);
-  }
-
-  return (uc_get_history_by_name (name, ret_history, num_steps, num_ds));
-} /* int uc_get_history */
-
-int uc_get_hits (const data_set_t *ds, const value_list_t *vl)
-{
-  char name[6 * DATA_MAX_NAME_LEN];
-  cache_entry_t *ce = NULL;
-  int ret = STATE_ERROR;
-
-  if (FORMAT_VL (name, sizeof (name), vl) != 0)
-  {
-    ERROR ("uc_get_state: FORMAT_VL failed.");
-    return (STATE_ERROR);
-  }
-
-  pthread_mutex_lock (&cache_lock);
-
-  if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
-  {
-    assert (ce != NULL);
-    ret = ce->hits;
-  }
-
-  pthread_mutex_unlock (&cache_lock);
-
-  return (ret);
-} /* int uc_get_hits */
-
-int uc_set_hits (const data_set_t *ds, const value_list_t *vl, int hits)
-{
-  char name[6 * DATA_MAX_NAME_LEN];
-  cache_entry_t *ce = NULL;
-  int ret = -1;
-
-  if (FORMAT_VL (name, sizeof (name), vl) != 0)
-  {
-    ERROR ("uc_get_state: FORMAT_VL failed.");
-    return (STATE_ERROR);
-  }
-
-  pthread_mutex_lock (&cache_lock);
-
-  if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
-  {
-    assert (ce != NULL);
-    ret = ce->hits;
-    ce->hits = hits;
-  }
-
-  pthread_mutex_unlock (&cache_lock);
-
-  return (ret);
-} /* int uc_set_hits */
-
-int uc_inc_hits (const data_set_t *ds, const value_list_t *vl, int step)
-{
-  char name[6 * DATA_MAX_NAME_LEN];
-  cache_entry_t *ce = NULL;
-  int ret = -1;
-
-  if (FORMAT_VL (name, sizeof (name), vl) != 0)
-  {
-    ERROR ("uc_get_state: FORMAT_VL failed.");
-    return (STATE_ERROR);
-  }
-
-  pthread_mutex_lock (&cache_lock);
-
-  if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
-  {
-    assert (ce != NULL);
-    ret = ce->hits;
-    ce->hits = ret + step;
-  }
-
-  pthread_mutex_unlock (&cache_lock);
-
-  return (ret);
-} /* int uc_inc_hits */
-
-/*
- * Meta data interface
- */
-/* XXX: This function will acquire `cache_lock' but will not free it! */
-static meta_data_t *uc_get_meta (const value_list_t *vl) /* {{{ */
-{
-  char name[6 * DATA_MAX_NAME_LEN];
-  cache_entry_t *ce = NULL;
-  int status;
-
-  status = FORMAT_VL (name, sizeof (name), vl);
-  if (status != 0)
-  {
-    ERROR ("utils_cache: uc_get_meta: FORMAT_VL failed.");
-    return (NULL);
-  }
-
-  pthread_mutex_lock (&cache_lock);
-
-  status = c_avl_get (cache_tree, name, (void *) &ce);
-  if (status != 0)
-  {
-    pthread_mutex_unlock (&cache_lock);
-    return (NULL);
-  }
-  assert (ce != NULL);
-
-  if (ce->meta == NULL)
-    ce->meta = meta_data_create ();
-
-  if (ce->meta == NULL)
-    pthread_mutex_unlock (&cache_lock);
-
-  return (ce->meta);
-} /* }}} meta_data_t *uc_get_meta */
-
-/* Sorry about this preprocessor magic, but it really makes this file much
- * shorter.. */
-#define UC_WRAP(wrap_function) { \
-  meta_data_t *meta; \
-  int status; \
-  meta = uc_get_meta (vl); \
-  if (meta == NULL) return (-1); \
-  status = wrap_function (meta, key); \
-  pthread_mutex_unlock (&cache_lock); \
-  return (status); \
-}
-int uc_meta_data_exists (const value_list_t *vl, const char *key)
-  UC_WRAP (meta_data_exists)
-
-int uc_meta_data_delete (const value_list_t *vl, const char *key)
-  UC_WRAP (meta_data_delete)
-#undef UC_WRAP
-
-/* We need a new version of this macro because the following functions take
- * two argumetns. */
-#define UC_WRAP(wrap_function) { \
-  meta_data_t *meta; \
-  int status; \
-  meta = uc_get_meta (vl); \
-  if (meta == NULL) return (-1); \
-  status = wrap_function (meta, key, value); \
-  pthread_mutex_unlock (&cache_lock); \
-  return (status); \
-}
-int uc_meta_data_add_string (const value_list_t *vl,
-    const char *key,
-    const char *value)
-  UC_WRAP(meta_data_add_string)
-int uc_meta_data_add_signed_int (const value_list_t *vl,
-    const char *key,
-    int64_t value)
-  UC_WRAP(meta_data_add_signed_int)
-int uc_meta_data_add_unsigned_int (const value_list_t *vl,
-    const char *key,
-    uint64_t value)
-  UC_WRAP(meta_data_add_unsigned_int)
-int uc_meta_data_add_double (const value_list_t *vl,
-    const char *key,
-    double value)
-  UC_WRAP(meta_data_add_double)
-int uc_meta_data_add_boolean (const value_list_t *vl,
-    const char *key,
-    _Bool value)
-  UC_WRAP(meta_data_add_boolean)
-
-int uc_meta_data_get_string (const value_list_t *vl,
-    const char *key,
-    char **value)
-  UC_WRAP(meta_data_get_string)
-int uc_meta_data_get_signed_int (const value_list_t *vl,
-    const char *key,
-    int64_t *value)
-  UC_WRAP(meta_data_get_signed_int)
-int uc_meta_data_get_unsigned_int (const value_list_t *vl,
-    const char *key,
-    uint64_t *value)
-  UC_WRAP(meta_data_get_unsigned_int)
-int uc_meta_data_get_double (const value_list_t *vl,
-    const char *key,
-    double *value)
-  UC_WRAP(meta_data_get_double)
-int uc_meta_data_get_boolean (const value_list_t *vl,
-    const char *key,
-    _Bool *value)
-  UC_WRAP(meta_data_get_boolean)
-#undef UC_WRAP
-
-/* vim: set sw=2 ts=8 sts=2 tw=78 : */
diff --git a/src/utils_cache.h b/src/utils_cache.h
deleted file mode 100644 (file)
index 87f93c0..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * collectd - src/utils_cache.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.
- *
- * 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:
- *   Florian octo Forster <octo at verplant.org>
- **/
-
-#ifndef UTILS_CACHE_H
-#define UTILS_CACHE_H 1
-
-#include "plugin.h"
-
-#define STATE_OKAY     0
-#define STATE_WARNING  1
-#define STATE_ERROR    2
-#define STATE_MISSING 15
-
-int uc_init (void);
-int uc_check_timeout (void);
-int uc_update (const data_set_t *ds, const value_list_t *vl);
-int uc_get_rate_by_name (const char *name, gauge_t **ret_values, size_t *ret_values_num);
-gauge_t *uc_get_rate (const data_set_t *ds, const value_list_t *vl);
-
-int uc_get_names (char ***ret_names, cdtime_t **ret_times, size_t *ret_number);
-
-int uc_get_state (const data_set_t *ds, const value_list_t *vl);
-int uc_set_state (const data_set_t *ds, const value_list_t *vl, int state);
-int uc_get_hits (const data_set_t *ds, const value_list_t *vl);
-int uc_set_hits (const data_set_t *ds, const value_list_t *vl, int hits);
-int uc_inc_hits (const data_set_t *ds, const value_list_t *vl, int step);
-
-int uc_get_history (const data_set_t *ds, const value_list_t *vl,
-    gauge_t *ret_history, size_t num_steps, size_t num_ds);
-int uc_get_history_by_name (const char *name,
-    gauge_t *ret_history, size_t num_steps, size_t num_ds);
-
-/*
- * Meta data interface
- */
-int uc_meta_data_exists (const value_list_t *vl, const char *key);
-int uc_meta_data_delete (const value_list_t *vl, const char *key);
-
-int uc_meta_data_add_string (const value_list_t *vl,
-    const char *key,
-    const char *value);
-int uc_meta_data_add_signed_int (const value_list_t *vl,
-    const char *key,
-    int64_t value);
-int uc_meta_data_add_unsigned_int (const value_list_t *vl,
-    const char *key,
-    uint64_t value);
-int uc_meta_data_add_double (const value_list_t *vl,
-    const char *key,
-    double value);
-int uc_meta_data_add_boolean (const value_list_t *vl,
-    const char *key,
-    _Bool value);
-
-int uc_meta_data_get_string (const value_list_t *vl,
-    const char *key,
-    char **value);
-int uc_meta_data_get_signed_int (const value_list_t *vl,
-    const char *key,
-    int64_t *value);
-int uc_meta_data_get_unsigned_int (const value_list_t *vl,
-    const char *key,
-    uint64_t *value);
-int uc_meta_data_get_double (const value_list_t *vl,
-    const char *key,
-    double *value);
-int uc_meta_data_get_boolean (const value_list_t *vl,
-    const char *key,
-    _Bool *value);
-
-/* vim: set shiftwidth=2 softtabstop=2 tabstop=8 : */
-#endif /* !UTILS_CACHE_H */
index 9a59310a0f405323e60d405a5588a3fb86f17b11..f19835ef3e4e066e9488ecfc52de95f7392fab5b 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"
index 6b54acecaa30f26307e1e51504a388e4b09f831e..f43b25726749b20348f9c4ae641bb223dc603c5a 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 e8c29fa324923d4060132d1f8e6ef00955f3bb47..80babe3ebdc4dc36d63656c5c346ea67e297cc97 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 5481cfd94fbb2dcb6bd996d610222afce01e7fcb..8d581c8013049b952e984ca52063a759aa3cdf64 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 657483b6cf35c6f00bf62afc3e3c71a7c55c0f2f..196b45e3267eca52bc7950ebac6b181aaa837d65 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 ed9ca9a345d2592421548a85908ecde141100212..5e12f692b2416d99c2ab6b30ed689dc41756c4a8 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 fb45200a519801da29a823adba57a25ded5c263d..b698388d3304e9686ae70f5c0202a1422a0fd36e 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 0c72d678a46f6d69a9c3b652a800fd36a1e25da8..fc125bc1ce0ec45f6eb0db694037bba25857bb6d 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 bed8462817ea1b2c15a29d663a70cd37fb318b2b..530d153ea91437b0375b20eed65e85f426d5a5e8 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"
@@ -76,6 +81,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 7e900b509f7010cf4bc90d093140a287d044dd60..9d699ecab8cfd58e4940a5dadae30f0e5c55d1e0 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 c9bf48bbeb01184d5192e263bd7f5334c108cebf..7b0258c6796a295d0aa1da715d07bf654eea7f40 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 9c92fd31c0caf6a0524ef595c60d3158051b73aa..795409eb92e3e5e277a7a2aa6e147918d41ba874 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
diff --git a/src/utils_complain.c b/src/utils_complain.c
deleted file mode 100644 (file)
index c3752bc..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
- * collectd - src/utils_complain.c
- * Copyright (C) 2006-2013  Florian octo Forster
- * 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.
- *
- * 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
- *
- * Authors:
- *   Florian octo Forster <octo at verplant.org>
- *   Sebastian tokkee Harl <sh at tokkee.org>
- **/
-
-#include "collectd.h"
-#include "utils_complain.h"
-#include "plugin.h"
-
-/* vcomplain returns 0 if it did not report, 1 else */
-static int vcomplain (int level, c_complain_t *c,
-               const char *format, va_list ap)
-{
-       cdtime_t now;
-       char   message[512];
-
-       now = cdtime ();
-
-       if (c->last + c->interval > now)
-               return 0;
-
-       c->last = now;
-
-       if (c->interval < plugin_get_interval ())
-               c->interval = plugin_get_interval ();
-       else
-               c->interval *= 2;
-
-       if (c->interval > TIME_T_TO_CDTIME_T (86400))
-               c->interval = TIME_T_TO_CDTIME_T (86400);
-
-       vsnprintf (message, sizeof (message), format, ap);
-       message[sizeof (message) - 1] = '\0';
-
-       plugin_log (level, "%s", message);
-       return 1;
-} /* vcomplain */
-
-void c_complain (int level, c_complain_t *c, const char *format, ...)
-{
-       va_list ap;
-
-       va_start (ap, format);
-       if (vcomplain (level, c, format, ap))
-               c->complained_once = 1;
-       va_end (ap);
-} /* c_complain */
-
-void c_complain_once (int level, c_complain_t *c, const char *format, ...)
-{
-       va_list ap;
-
-       if (c->complained_once)
-               return;
-
-       va_start (ap, format);
-       if (vcomplain (level, c, format, ap))
-               c->complained_once = 1;
-       va_end (ap);
-} /* c_complain_once */
-
-void c_do_release (int level, c_complain_t *c, const char *format, ...)
-{
-       char message[512];
-       va_list ap;
-
-       if (c->interval == 0)
-               return;
-
-       c->interval = 0;
-       c->complained_once = 0;
-
-       va_start (ap, format);
-       vsnprintf (message, sizeof (message), format, ap);
-       message[sizeof (message) - 1] = '\0';
-       va_end (ap);
-
-       plugin_log (level, "%s", message);
-} /* c_release */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
-
diff --git a/src/utils_complain.h b/src/utils_complain.h
deleted file mode 100644 (file)
index 028dda6..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-/**
- * collectd - src/utils_complain.h
- * Copyright (C) 2006-2013  Florian octo Forster
- * 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.
- *
- * 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
- *
- * Authors:
- *   Florian octo Forster <octo at verplant.org>
- *   Sebastian tokkee Harl <sh at tokkee.org>
- **/
-
-#ifndef UTILS_COMPLAIN_H
-#define UTILS_COMPLAIN_H 1
-
-#include "utils_time.h"
-
-typedef struct
-{
-       /* time of the last report */
-       cdtime_t last;
-
-       /* How long to wait until reporting again.
-        * 0 indicates that the complaint is no longer valid. */
-       cdtime_t interval;
-
-       _Bool complained_once;
-} c_complain_t;
-
-#define C_COMPLAIN_INIT_STATIC { 0, 0, 0 }
-#define C_COMPLAIN_INIT(c) do { \
-       (c)->last = 0; \
-       (c)->interval = 0; \
-       (c)->complained_once = 0; \
-} while (0)
-
-/*
- * NAME
- *   c_complain
- *
- * DESCRIPTION
- *   Complain about something. This function will report a message (usually
- *   indicating some error condition) using the collectd logging mechanism.
- *   When this function is called again, reporting the message again will be
- *   deferred by an increasing interval (up to one day) to prevent flooding
- *   the logs. A call to `c_release' resets the counter.
- *
- * PARAMETERS
- *   `level'  The log level passed to `plugin_log'.
- *   `c'      Identifier for the complaint.
- *   `format' Message format - see the documentation of printf(3).
- */
-void c_complain (int level, c_complain_t *c, const char *format, ...);
-
-/*
- * NAME
- *   c_complain_once
- *
- * DESCRIPTION
- *   Complain about something once. This function will not report anything
- *   again, unless `c_release' has been called in between. If used after some
- *   calls to `c_complain', it will report again on the next interval and stop
- *   after that.
- *
- *   See `c_complain' for further details and a description of the parameters.
- */
-void c_complain_once (int level, c_complain_t *c, const char *format, ...);
-
-/*
- * NAME
- *   c_would_release
- *
- * DESCRIPTION
- *   Returns true if the specified complaint would be released, false else.
- */
-#define c_would_release(c) ((c)->interval != 0)
-
-/*
- * NAME
- *   c_release
- *
- * DESCRIPTION
- *   Release a complaint. This will report a message once, marking the
- *   complaint as released.
- *
- *   See `c_complain' for a description of the parameters.
- */
-void c_do_release (int level, c_complain_t *c, const char *format, ...);
-#define c_release(level, c, ...) \
-       do { \
-               if (c_would_release (c)) \
-                       c_do_release(level, c, __VA_ARGS__); \
-       } while (0)
-
-#endif /* UTILS_COMPLAIN_H */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
-
diff --git a/src/utils_crc32.c b/src/utils_crc32.c
new file mode 100644 (file)
index 0000000..f9eaf88
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ *  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 <stdint.h>
+#include <stddef.h>
+
+uint32_t               crc32_buffer(const unsigned 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. */
+
+uint32_t
+crc32_buffer(const unsigned char *s, size_t len)
+{
+    size_t      i;
+    uint32_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..cf60d24
--- /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
+
+uint32_t               crc32_buffer(const unsigned char *, size_t);
+
+#endif
index e8d7b3aa88509a5fdf38708470b9615c33aa73bf..9c84937f38845c34e2f7067fab6317f7d052c3fe 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);
@@ -254,8 +264,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 */
@@ -269,8 +309,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, /* {{{ */
@@ -288,6 +330,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 */
 
@@ -304,14 +349,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);
@@ -334,8 +382,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
@@ -370,6 +418,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 {{{ */
@@ -418,6 +483,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 */
@@ -439,6 +527,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);
@@ -469,6 +561,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.. */
@@ -485,6 +578,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 b6f4cea00d6351c8c0edcf97ab44d0a45cfc7e86..08b10bda2c2831424f2150580e53cbac48bda2ad 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 fcc65a56771021e184ce23addd4a508cef3f9622..6abfde16fba0f5cd2da6e1da4f98832717f48519 100644 (file)
@@ -1,12 +1,12 @@
 /*
  * 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
  * modification, are permitted provided that the following conditions are met:
- * 
+ *
  * 1. Redistributions of source code must retain the above copyright notice,
  *    this list of conditions and the following disclaimer.
  * 2. Redistributions in binary form must reproduce the above copyright notice,
  *
  * 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 _DEFAULT_SOURCE
 #define _BSD_SOURCE
 
 #include "collectd.h"
index 56213afa18bc800035fafa88b149120edf266b4f..83f0ea403e9809ab68c9261299119aa1537278d1 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 97f21a1f78317ebc4cc5d8ccce7f61dcd322b0ae..70b89089dce13e73e2deb9f25b8db5942ccdaa70 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 0a0305eda5488c54303d811a66e543527cf638e0..d9206a02b67658d042b8970f22ecd1152e0db0a2 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 e23d5d92c65599fecc29ac575ca48c68af2b3369..023f7a46a5240f7a7f52e3c9d6f237c91f932223 100644 (file)
@@ -27,7 +27,6 @@
 
 #include "utils_format_graphite.h"
 #include "utils_cache.h"
-#include "utils_parse_option.h"
 
 #define GRAPHITE_FORBIDDEN " \t\"\\:!/()\n\r"
 
index 48aa4fc61c1eea967c15c3a51c934c374b48c23b..10a5343f2c11bb0a1eba7454eb663a41eacd4a7a 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"
@@ -26,7 +31,7 @@
 #include "utils_cache.h"
 #include "utils_format_json.h"
 
-static int escape_string (char *buffer, size_t buffer_size, /* {{{ */
+static int json_escape_string (char *buffer, size_t buffer_size, /* {{{ */
     const char *string)
 {
   size_t src_pos;
@@ -70,7 +75,7 @@ static int escape_string (char *buffer, size_t buffer_size, /* {{{ */
 #undef BUFFER_ADD
 
   return (0);
-} /* }}} int escape_string */
+} /* }}} int json_escape_string */
 
 static int values_to_json (char *buffer, size_t buffer_size, /* {{{ */
                 const data_set_t *ds, const value_list_t *vl, int store_rates)
@@ -269,7 +274,7 @@ static int meta_data_to_json (char *buffer, size_t buffer_size, /* {{{ */
       if (meta_data_get_string (meta, key, &value) == 0)
       {
         char temp[512] = "";
-        escape_string (temp, sizeof (temp), value);
+        json_escape_string (temp, sizeof (temp), value);
         sfree (value);
         BUFFER_ADD (",\"%s\":%s", key, temp);
       }
@@ -357,7 +362,7 @@ static int value_list_to_json (char *buffer, size_t buffer_size, /* {{{ */
   BUFFER_ADD (",\"interval\":%.3f", CDTIME_T_TO_DOUBLE (vl->interval));
 
 #define BUFFER_ADD_KEYVAL(key, value) do { \
-  status = escape_string (temp, sizeof (temp), (value)); \
+  status = json_escape_string (temp, sizeof (temp), (value)); \
   if (status != 0) \
     return (status); \
   BUFFER_ADD (",\"%s\":%s", (key), temp); \
index 7a4aa542e9b5e077ae91a8ae9b9de91881d61328..f1fbb6e72766d7895446f322644ecedb4c70e617 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
diff --git a/src/utils_heap.c b/src/utils_heap.c
deleted file mode 100644 (file)
index f8f7405..0000000
+++ /dev/null
@@ -1,226 +0,0 @@
-/**
- * collectd - src/utils_heap.c
- * 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.
- *
- * 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
- *
- * Authors:
- *   Florian octo Forster <octo at verplant.org>
- **/
-
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <pthread.h>
-
-#include "utils_heap.h"
-
-struct c_heap_s
-{
-  pthread_mutex_t lock;
-  int (*compare) (const void *, const void *);
-
-  void **list;
-  size_t list_len; /* # entries used */
-  size_t list_size; /* # entries allocated */
-};
-
-enum reheap_direction
-{
-  DIR_UP,
-  DIR_DOWN
-};
-
-static void reheap (c_heap_t *h, size_t root, enum reheap_direction dir)
-{
-  size_t left;
-  size_t right;
-  size_t min;
-  int status;
-
-  /* Calculate the positions of the children */
-  left = (2 * root) + 1;
-  if (left >= h->list_len)
-    left = 0;
-
-  right = (2 * root) + 2;
-  if (right >= h->list_len)
-    right = 0;
-
-  /* Check which one of the children is smaller. */
-  if ((left == 0) && (right == 0))
-    return;
-  else if (left == 0)
-    min = right;
-  else if (right == 0)
-    min = left;
-  else
-  {
-    status = h->compare (h->list[left], h->list[right]);
-    if (status > 0)
-      min = right;
-    else
-      min = left;
-  }
-
-  status = h->compare (h->list[root], h->list[min]);
-  if (status <= 0)
-  {
-    /* We didn't need to change anything, so the rest of the tree should be
-     * okay now. */
-    return;
-  }
-  else /* if (status > 0) */
-  {
-    void *tmp;
-
-    tmp = h->list[root];
-    h->list[root] = h->list[min];
-    h->list[min] = tmp;
-  }
-
-  if ((dir == DIR_UP) && (root == 0))
-    return;
-
-  if (dir == DIR_UP)
-    reheap (h, (root - 1) / 2, dir);
-  else if (dir == DIR_DOWN)
-    reheap (h, min, dir);
-} /* void reheap */
-
-c_heap_t *c_heap_create (int (*compare) (const void *, const void *))
-{
-  c_heap_t *h;
-
-  if (compare == NULL)
-    return (NULL);
-
-  h = malloc (sizeof (*h));
-  if (h == NULL)
-    return (NULL);
-
-  memset (h, 0, sizeof (*h));
-  pthread_mutex_init (&h->lock, /* attr = */ NULL);
-  h->compare = compare;
-  
-  h->list = NULL;
-  h->list_len = 0;
-  h->list_size = 0;
-
-  return (h);
-} /* c_heap_t *c_heap_create */
-
-void c_heap_destroy (c_heap_t *h)
-{
-  if (h == NULL)
-    return;
-
-  h->list_len = 0;
-  h->list_size = 0;
-  free (h->list);
-  h->list = NULL;
-
-  pthread_mutex_destroy (&h->lock);
-
-  free (h);
-} /* void c_heap_destroy */
-
-int c_heap_insert (c_heap_t *h, void *ptr)
-{
-  size_t index;
-
-  if ((h == NULL) || (ptr == NULL))
-    return (-EINVAL);
-
-  pthread_mutex_lock (&h->lock);
-
-  assert (h->list_len <= h->list_size);
-  if (h->list_len == h->list_size)
-  {
-    void **tmp;
-
-    tmp = realloc (h->list, (h->list_size + 16) * sizeof (*h->list));
-    if (tmp == NULL)
-    {
-      pthread_mutex_unlock (&h->lock);
-      return (-ENOMEM);
-    }
-
-    h->list = tmp;
-    h->list_size += 16;
-  }
-
-  /* Insert the new node as a leaf. */
-  index = h->list_len;
-  h->list[index] = ptr;
-  h->list_len++;
-
-  /* Reorganize the heap from bottom up. */
-  reheap (h, /* parent of this node = */ (index - 1) / 2, DIR_UP);
-  
-  pthread_mutex_unlock (&h->lock);
-  return (0);
-} /* int c_heap_insert */
-
-void *c_heap_get_root (c_heap_t *h)
-{
-  void *ret = NULL;
-
-  if (h == NULL)
-    return (NULL);
-
-  pthread_mutex_lock (&h->lock);
-
-  if (h->list_len == 0)
-  {
-    pthread_mutex_unlock (&h->lock);
-    return (NULL);
-  }
-  else if (h->list_len == 1)
-  {
-    ret = h->list[0];
-    h->list[0] = NULL;
-    h->list_len = 0;
-  }
-  else /* if (h->list_len > 1) */
-  {
-    ret = h->list[0];
-    h->list[0] = h->list[h->list_len - 1];
-    h->list[h->list_len - 1] = NULL;
-    h->list_len--;
-
-    reheap (h, /* root = */ 0, DIR_DOWN);
-  }
-
-  /* free some memory */
-  if ((h->list_len + 32) < h->list_size)
-  {
-    void **tmp;
-
-    tmp = realloc (h->list, (h->list_len + 16) * sizeof (*h->list));
-    if (tmp != NULL)
-    {
-      h->list = tmp;
-      h->list_size = h->list_len + 16;
-    }
-  }
-
-  pthread_mutex_unlock (&h->lock);
-
-  return (ret);
-} /* void *c_heap_get_root */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/src/utils_heap.h b/src/utils_heap.h
deleted file mode 100644 (file)
index 6428006..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- * collectd - src/utils_heap.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; 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
- *
- * Authors:
- *   Florian octo Forster <octo at verplant.org>
- **/
-
-#ifndef UTILS_HEAP_H
-#define UTILS_HEAP_H 1
-
-struct c_heap_s;
-typedef struct c_heap_s c_heap_t;
-
-/*
- * NAME
- *   c_heap_create
- *
- * DESCRIPTION
- *   Allocates a new heap.
- *
- * PARAMETERS
- *   `compare'  The function-pointer `compare' is used to compare two keys. It
- *              has to return less than zero if it's first argument is smaller
- *              then the second argument, more than zero if the first argument
- *              is bigger than the second argument and zero if they are equal.
- *              If your keys are char-pointers, you can use the `strcmp'
- *              function from the libc here.
- *
- * RETURN VALUE
- *   A c_heap_t-pointer upon success or NULL upon failure.
- */
-c_heap_t *c_heap_create (int (*compare) (const void *, const void *));
-
-/*
- * NAME
- *   c_heap_destroy
- *
- * DESCRIPTION
- *   Deallocates a heap. Stored value- and key-pointer are lost, but of course
- *   not freed.
- */
-void c_heap_destroy (c_heap_t *h);
-
-/*
- * NAME
- *   c_heap_insert
- *
- * DESCRIPTION
- *   Stores the key-value-pair in the heap pointed to by `h'.
- *
- * PARAMETERS
- *   `h'        Heap to store the data in.
- *   `ptr'      Value to be stored. This is typically a pointer to a data
- *              structure. The data structure is of course *not* copied and may
- *              not be free'd before the pointer has been removed from the heap
- *              again.
- *
- * RETURN VALUE
- *   Zero upon success, non-zero otherwise. It's less than zero if an error
- *   occurred or greater than zero if the key is already stored in the tree.
- */
-int c_heap_insert (c_heap_t *h, void *ptr);
-
-/*
- * NAME
- *   c_heap_get_root
- *
- * DESCRIPTION
- *   Removes the value at the root of the heap and returns both, key and value.
- *
- * PARAMETERS
- *   `h'           Heap to remove key-value-pair from.
- *
- * RETURN VALUE
- *   The pointer passed to `c_heap_insert' or NULL if there are no more
- *   elements in the heap (or an error occurred).
- */
-void *c_heap_get_root (c_heap_t *h);
-
-#endif /* UTILS_HEAP_H */
-/* vim: set sw=2 sts=2 et : */
index b8169ff656483a3d2e7c55c45a4cea2853d7dad2..7b1c7d2547e915db1931eecdbeb9e34590e9e117 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 893bded3b9b387187adbab01eb55e6134001488e..12fc9b82dfa6e1e3817184d6027ef7f4b724fbee 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"),
 #include "common.h"
 
 #include <math.h>
+#include <limits.h>
+
+#ifndef LLONG_MAX
+# define LLONG_MAX 9223372036854775807LL
+#endif
 
 #ifndef HISTOGRAM_NUM_BINS
 # define HISTOGRAM_NUM_BINS 1000
 #endif
 
-static const int HISTOGRAM_DEFAULT_BIN_WIDTH = 1;
+#ifndef HISTOGRAM_DEFAULT_BIN_WIDTH
+/* 1048576 = 2^20 ^= 1/1024 s */
+# define HISTOGRAM_DEFAULT_BIN_WIDTH 1048576
+#endif
 
 struct latency_counter_s
 {
@@ -47,7 +55,7 @@ struct latency_counter_s
   cdtime_t min;
   cdtime_t max;
 
-  int bin_width;
+  cdtime_t bin_width;
   int histogram[HISTOGRAM_NUM_BINS];
 };
 
@@ -67,47 +75,46 @@ struct latency_counter_s
 *
 * So, if the required bin width is 300, then new bin width will be 512 as it is
 * the next nearest power of 2.
-*
 */
-void change_bin_width (latency_counter_t *lc, size_t val) /* {{{ */
+void change_bin_width (latency_counter_t *lc, cdtime_t latency) /* {{{ */
 {
-  int i=0;
   /* This function is called because the new value is above histogram's range.
    * First find the required bin width:
    *           requiredBinWidth = (value + 1) / numBins
    * then get the next nearest power of 2
    *           newBinWidth = 2^(ceil(log2(requiredBinWidth)))
    */
-  double required_bin_width = (double)(val + 1) / HISTOGRAM_NUM_BINS;
-  double required_bin_width_logbase2 = log(required_bin_width) / log(2.0);
-  int new_bin_width = (int)(pow(2.0, ceil( required_bin_width_logbase2)));
-  int old_bin_width = lc->bin_width;
+  double required_bin_width = ((double) (latency + 1)) / ((double) HISTOGRAM_NUM_BINS);
+  double required_bin_width_logbase2 = log (required_bin_width) / log (2.0);
+  cdtime_t new_bin_width = (cdtime_t) (pow (2.0, ceil (required_bin_width_logbase2)) + .5);
+  cdtime_t old_bin_width = lc->bin_width;
+
   lc->bin_width = new_bin_width;
 
-  /*
-   * bin width has been increased, now iterate through all bins and move the
-   * old bin's count to new bin.
-   */
+  /* bin_width has been increased, now iterate through all bins and move the
+   * old bin's count to new bin. */
   if (lc->num > 0) // if the histogram has data then iterate else skip
   {
-      double width_change_ratio = old_bin_width / new_bin_width;
-      for (i=0; i<HISTOGRAM_NUM_BINS; i++)
+      double width_change_ratio = ((double) old_bin_width) / ((double) new_bin_width);
+      size_t i;
+
+      for (i = 0; i < HISTOGRAM_NUM_BINS; i++)
       {
-         int new_bin = (int)(i * width_change_ratio);
+         size_t new_bin = (size_t) (((double) i) * width_change_ratio);
          if (i == new_bin)
              continue;
+         assert (new_bin < i);
+
          lc->histogram[new_bin] += lc->histogram[i];
          lc->histogram[i] = 0;
       }
-      DEBUG("utils_latency: change_bin_width: fixed all bins");
   }
 
-  DEBUG("utils_latency: change_bin_width: val-[%zu], oldBinWidth-[%d], "
-          "newBinWidth-[%d], required_bin_width-[%f], "
-          "required_bin_width_logbase2-[%f]",
-          val, old_bin_width, new_bin_width, required_bin_width,
-          required_bin_width_logbase2);
-
+  DEBUG("utils_latency: change_bin_width: latency = %.3f; "
+      "old_bin_width = %.3f; new_bin_width = %.3f;",
+      CDTIME_T_TO_DOUBLE (latency),
+      CDTIME_T_TO_DOUBLE (old_bin_width),
+      CDTIME_T_TO_DOUBLE (new_bin_width));
 } /* }}} void change_bin_width */
 
 latency_counter_t *latency_counter_create () /* {{{ */
@@ -131,9 +138,9 @@ void latency_counter_destroy (latency_counter_t *lc) /* {{{ */
 
 void latency_counter_add (latency_counter_t *lc, cdtime_t latency) /* {{{ */
 {
-  size_t latency_ms;
+  cdtime_t bin;
 
-  if ((lc == NULL) || (latency == 0))
+  if ((lc == NULL) || (latency == 0) || (latency > ((cdtime_t) LLONG_MAX)))
     return;
 
   lc->sum += latency;
@@ -149,16 +156,14 @@ void latency_counter_add (latency_counter_t *lc, cdtime_t latency) /* {{{ */
   /* A latency of _exactly_ 1.0 ms should be stored in the buffer 0, so
    * subtract one from the cdtime_t value so that exactly 1.0 ms get sorted
    * accordingly. */
-  latency_ms = (size_t) CDTIME_T_TO_MS (latency - 1);
-
-  int bin = (int)(latency_ms / lc->bin_width);
+  bin = (latency - 1) / lc->bin_width;
   if (bin >= HISTOGRAM_NUM_BINS)
   {
-      change_bin_width(lc, latency_ms);
-      bin = (int)(latency_ms / lc->bin_width);
+      change_bin_width (lc, latency);
+      bin = (latency - 1) / lc->bin_width;
       if (bin >= HISTOGRAM_NUM_BINS)
       {
-          ERROR("utils_latency: latency_counter_add: Invalid bin %d", bin);
+          ERROR ("utils_latency: latency_counter_add: Invalid bin: %"PRIu64, bin);
           return;
       }
   }
@@ -170,7 +175,7 @@ void latency_counter_reset (latency_counter_t *lc) /* {{{ */
   if (lc == NULL)
     return;
 
-  int bin_width = lc->bin_width;
+  cdtime_t bin_width = lc->bin_width;
   memset (lc, 0, sizeof (*lc));
 
   /* preserve bin width */
@@ -217,14 +222,14 @@ cdtime_t latency_counter_get_average (latency_counter_t *lc) /* {{{ */
   return (DOUBLE_TO_CDTIME_T (average));
 } /* }}} cdtime_t latency_counter_get_average */
 
-cdtime_t latency_counter_get_percentile (latency_counter_t *lc,
+cdtime_t latency_counter_get_percentile (latency_counter_t *lc, /* {{{ */
     double percent)
 {
   double percent_upper;
   double percent_lower;
-  double ms_upper;
-  double ms_lower;
-  double ms_interpolated;
+  double p;
+  cdtime_t latency_lower;
+  cdtime_t latency_interpolated;
   int sum;
   size_t i;
 
@@ -254,16 +259,18 @@ cdtime_t latency_counter_get_percentile (latency_counter_t *lc,
   assert (percent_upper >= percent);
   assert (percent_lower < percent);
 
-  ms_upper = (double) ( (i + 1) * lc->bin_width );
-  ms_lower = (double) ( i * lc->bin_width );
   if (i == 0)
-    return (MS_TO_CDTIME_T (ms_upper));
+    return (lc->bin_width);
+
+  latency_lower = ((cdtime_t) i) * lc->bin_width;
+  p = (percent - percent_lower) / (percent_upper - percent_lower);
 
-  ms_interpolated = (((percent_upper - percent) * ms_lower)
-      + ((percent - percent_lower) * ms_upper))
-    / (percent_upper - percent_lower);
+  latency_interpolated = latency_lower
+    + DOUBLE_TO_CDTIME_T (p * CDTIME_T_TO_DOUBLE (lc->bin_width));
 
-  return (MS_TO_CDTIME_T (ms_interpolated));
+  DEBUG ("latency_counter_get_percentile: latency_interpolated = %.3f",
+      CDTIME_T_TO_DOUBLE (latency_interpolated));
+  return (latency_interpolated);
 } /* }}} cdtime_t latency_counter_get_percentile */
 
 /* vim: set sw=2 sts=2 et fdm=marker : */
index 3787c779434c191957fe60a8fefae1063567e9a2..9930b7235368ddd368bd06c7c8c99a20ea267bcc 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"),
diff --git a/src/utils_llist.c b/src/utils_llist.c
deleted file mode 100644 (file)
index 11f838d..0000000
+++ /dev/null
@@ -1,190 +0,0 @@
-/**
- * collectd - src/utils_llist.c
- * Copyright (C) 2006 Florian Forster <octo at verplant.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.
- *
- * 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.
- *
- * 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.
- *
- * Authors:
- *   Florian Forster <octo at verplant.org>
- */
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "utils_llist.h"
-
-/*
- * Private data types
- */
-struct llist_s
-{
-       llentry_t *head;
-       llentry_t *tail;
-       int size;
-};
-
-/*
- * Public functions
- */
-llist_t *llist_create (void)
-{
-       llist_t *ret;
-
-       ret = (llist_t *) malloc (sizeof (llist_t));
-       if (ret == NULL)
-               return (NULL);
-
-       memset (ret, '\0', sizeof (llist_t));
-
-       return (ret);
-}
-
-void llist_destroy (llist_t *l)
-{
-       llentry_t *e_this;
-       llentry_t *e_next;
-
-       if (l == NULL)
-               return;
-
-       for (e_this = l->head; e_this != NULL; e_this = e_next)
-       {
-               e_next = e_this->next;
-               llentry_destroy (e_this);
-       }
-
-       free (l);
-}
-
-llentry_t *llentry_create (char *key, void *value)
-{
-       llentry_t *e;
-
-       e = (llentry_t *) malloc (sizeof (llentry_t));
-       if (e)
-       {
-               e->key   = key;
-               e->value = value;
-               e->next  = NULL;
-       }
-
-       return (e);
-}
-
-void llentry_destroy (llentry_t *e)
-{
-       free (e);
-}
-
-void llist_append (llist_t *l, llentry_t *e)
-{
-       e->next = NULL;
-
-       if (l->tail == NULL)
-               l->head = e;
-       else
-               l->tail->next = e;
-
-       l->tail = e;
-
-       ++(l->size);
-}
-
-void llist_prepend (llist_t *l, llentry_t *e)
-{
-       e->next = l->head;
-       l->head = e;
-
-       if (l->tail == NULL)
-               l->tail = e;
-
-       ++(l->size);
-}
-
-void llist_remove (llist_t *l, llentry_t *e)
-{
-       llentry_t *prev;
-
-       if ((l == NULL) || (e == NULL))
-               return;
-
-       prev = l->head;
-       while ((prev != NULL) && (prev->next != e))
-               prev = prev->next;
-
-       if (prev != NULL)
-               prev->next = e->next;
-       if (l->head == e)
-               l->head = e->next;
-       if (l->tail == e)
-               l->tail = prev;
-
-       --(l->size);
-}
-
-int llist_size (llist_t *l)
-{
-       return (l ? l->size : 0);
-}
-
-static int llist_strcmp (llentry_t *e, void *ud)
-{
-       if ((e == NULL) || (ud == NULL))
-               return (-1);
-       return (strcmp (e->key, (const char *)ud));
-}
-
-llentry_t *llist_search (llist_t *l, const char *key)
-{
-       return (llist_search_custom (l, llist_strcmp, (void *)key));
-}
-
-llentry_t *llist_search_custom (llist_t *l,
-               int (*compare) (llentry_t *, void *), void *user_data)
-{
-       llentry_t *e;
-
-       if (l == NULL)
-               return (NULL);
-
-       e = l->head;
-       while (e != NULL) {
-               llentry_t *next = e->next;
-
-               if (compare (e, user_data) == 0)
-                       break;
-
-               e = next;
-       }
-
-       return (e);
-}
-
-llentry_t *llist_head (llist_t *l)
-{
-       if (l == NULL)
-               return (NULL);
-       return (l->head);
-}
-
-llentry_t *llist_tail (llist_t *l)
-{
-       if (l == NULL)
-               return (NULL);
-       return (l->tail);
-}
diff --git a/src/utils_llist.h b/src/utils_llist.h
deleted file mode 100644 (file)
index 19d8d94..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * collectd - src/utils_llist.h
- * Copyright (C) 2006 Florian Forster <octo at verplant.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.
- *
- * 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.
- *
- * 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.
- *
- * Authors:
- *   Florian Forster <octo at verplant.org>
- */
-
-#ifndef UTILS_LLIST_H
-#define UTILS_LLIST_H 1
-
-/*
- * Data types
- */
-struct llentry_s
-{
-       char *key;
-       void *value;
-       struct llentry_s *next;
-};
-typedef struct llentry_s llentry_t;
-
-struct llist_s;
-typedef struct llist_s llist_t;
-
-/*
- * Functions
- */
-llist_t *llist_create (void);
-void llist_destroy (llist_t *l);
-
-llentry_t *llentry_create (char *key, void *value);
-void llentry_destroy (llentry_t *e);
-
-void llist_append (llist_t *l, llentry_t *e);
-void llist_prepend (llist_t *l, llentry_t *e);
-void llist_remove (llist_t *l, llentry_t *e);
-
-int llist_size (llist_t *l);
-
-llentry_t *llist_search (llist_t *l, const char *key);
-llentry_t *llist_search_custom (llist_t *l,
-               int (*compare) (llentry_t *, void *), void *user_data);
-
-llentry_t *llist_head (llist_t *l);
-llentry_t *llist_tail (llist_t *l);
-
-#endif /* UTILS_LLIST_H */
diff --git a/src/utils_match.c b/src/utils_match.c
deleted file mode 100644 (file)
index bb53a9a..0000000
+++ /dev/null
@@ -1,381 +0,0 @@
-/**
- * collectd - src/utils_match.c
- * Copyright (C) 2008-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; 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
- *
- * Authors:
- *   Florian octo Forster <octo at verplant.org>
- **/
-
-#include "collectd.h"
-#include "common.h"
-#include "plugin.h"
-
-#include "utils_match.h"
-
-#include <regex.h>
-
-#define UTILS_MATCH_FLAGS_FREE_USER_DATA 0x01
-#define UTILS_MATCH_FLAGS_EXCLUDE_REGEX 0x02
-
-struct cu_match_s
-{
-  regex_t regex;
-  regex_t excluderegex;
-  int flags;
-
-  int (*callback) (const char *str, char * const *matches, size_t matches_num,
-      void *user_data);
-  void *user_data;
-};
-
-/*
- * Private functions
- */
-static char *match_substr (const char *str, int begin, int end)
-{
-  char *ret;
-  size_t ret_len;
-
-  if ((begin < 0) || (end < 0) || (begin >= end))
-    return (NULL);
-  if ((size_t) end > (strlen (str) + 1))
-  {
-    ERROR ("utils_match: match_substr: `end' points after end of string.");
-    return (NULL);
-  }
-
-  ret_len = end - begin;
-  ret = (char *) malloc (sizeof (char) * (ret_len + 1));
-  if (ret == NULL)
-  {
-    ERROR ("utils_match: match_substr: malloc failed.");
-    return (NULL);
-  }
-
-  sstrncpy (ret, str + begin, ret_len + 1);
-  return (ret);
-} /* char *match_substr */
-
-static int default_callback (const char __attribute__((unused)) *str,
-    char * const *matches, size_t matches_num, void *user_data)
-{
-  cu_match_value_t *data = (cu_match_value_t *) user_data;
-
-  if (data->ds_type & UTILS_MATCH_DS_TYPE_GAUGE)
-  {
-    gauge_t value;
-    char *endptr = NULL;
-
-    if (matches_num < 2)
-      return (-1);
-
-    value = (gauge_t) strtod (matches[1], &endptr);
-    if (matches[1] == endptr)
-      return (-1);
-
-    if ((data->values_num == 0)
-       || (data->ds_type & UTILS_MATCH_CF_GAUGE_LAST))
-    {
-      data->value.gauge = value;
-    }
-    else if (data->ds_type & UTILS_MATCH_CF_GAUGE_AVERAGE)
-    {
-      double f = ((double) data->values_num)
-       / ((double) (data->values_num + 1));
-      data->value.gauge = (data->value.gauge * f) + (value * (1.0 - f));
-    }
-    else if (data->ds_type & UTILS_MATCH_CF_GAUGE_MIN)
-    {
-      if (data->value.gauge > value)
-       data->value.gauge = value;
-    }
-    else if (data->ds_type & UTILS_MATCH_CF_GAUGE_MAX)
-    {
-      if (data->value.gauge < value)
-       data->value.gauge = value;
-    }
-    else
-    {
-      ERROR ("utils_match: default_callback: obj->ds_type is invalid!");
-      return (-1);
-    }
-
-    data->values_num++;
-  }
-  else if (data->ds_type & UTILS_MATCH_DS_TYPE_COUNTER)
-  {
-    counter_t value;
-    char *endptr = NULL;
-
-    if (data->ds_type & UTILS_MATCH_CF_COUNTER_INC)
-    {
-      data->value.counter++;
-      data->values_num++;
-      return (0);
-    }
-
-    if (matches_num < 2)
-      return (-1);
-
-    value = (counter_t) strtoull (matches[1], &endptr, 0);
-    if (matches[1] == endptr)
-      return (-1);
-
-    if (data->ds_type & UTILS_MATCH_CF_COUNTER_SET)
-      data->value.counter = value;
-    else if (data->ds_type & UTILS_MATCH_CF_COUNTER_ADD)
-      data->value.counter += value;
-    else
-    {
-      ERROR ("utils_match: default_callback: obj->ds_type is invalid!");
-      return (-1);
-    }
-
-    data->values_num++;
-  }
-  else if (data->ds_type & UTILS_MATCH_DS_TYPE_DERIVE)
-  {
-    derive_t value;
-    char *endptr = NULL;
-
-    if (data->ds_type & UTILS_MATCH_CF_DERIVE_INC)
-    {
-      data->value.counter++;
-      data->values_num++;
-      return (0);
-    }
-
-    if (matches_num < 2)
-      return (-1);
-
-    value = (derive_t) strtoll (matches[1], &endptr, 0);
-    if (matches[1] == endptr)
-      return (-1);
-
-    if (data->ds_type & UTILS_MATCH_CF_DERIVE_SET)
-      data->value.derive = value;
-    else if (data->ds_type & UTILS_MATCH_CF_DERIVE_ADD)
-      data->value.derive += value;
-    else
-    {
-      ERROR ("utils_match: default_callback: obj->ds_type is invalid!");
-      return (-1);
-    }
-
-    data->values_num++;
-  }
-  else if (data->ds_type & UTILS_MATCH_DS_TYPE_ABSOLUTE)
-  {
-    absolute_t value;
-    char *endptr = NULL;
-
-    if (matches_num < 2)
-      return (-1);
-
-    value = (absolute_t) strtoull (matches[1], &endptr, 0);
-    if (matches[1] == endptr)
-      return (-1);
-
-    if (data->ds_type & UTILS_MATCH_CF_ABSOLUTE_SET)
-      data->value.absolute = value;
-    else
-    {
-      ERROR ("utils_match: default_callback: obj->ds_type is invalid!");
-      return (-1);
-    }
-
-    data->values_num++;
-  }
-  else
-  {
-    ERROR ("utils_match: default_callback: obj->ds_type is invalid!");
-    return (-1);
-  }
-
-  return (0);
-} /* int default_callback */
-
-/*
- * Public functions
- */
-cu_match_t *match_create_callback (const char *regex, const char *excluderegex,
-               int (*callback) (const char *str,
-                 char * const *matches, size_t matches_num, void *user_data),
-               void *user_data)
-{
-  cu_match_t *obj;
-  int status;
-
-  DEBUG ("utils_match: match_create_callback: regex = %s, excluderegex = %s",
-        regex, excluderegex);
-
-  obj = (cu_match_t *) malloc (sizeof (cu_match_t));
-  if (obj == NULL)
-    return (NULL);
-  memset (obj, '\0', sizeof (cu_match_t));
-
-  status = regcomp (&obj->regex, regex, REG_EXTENDED | REG_NEWLINE);
-  if (status != 0)
-  {
-    ERROR ("Compiling the regular expression \"%s\" failed.", regex);
-    sfree (obj);
-    return (NULL);
-  }
-
-  if (excluderegex && strcmp(excluderegex, "") != 0) {
-    status = regcomp (&obj->excluderegex, excluderegex, REG_EXTENDED);
-    if (status != 0)
-    {
-       ERROR ("Compiling the excluding regular expression \"%s\" failed.",
-              excluderegex);
-       sfree (obj);
-       return (NULL);
-    }
-    obj->flags |= UTILS_MATCH_FLAGS_EXCLUDE_REGEX;
-  }
-
-  obj->callback = callback;
-  obj->user_data = user_data;
-
-  return (obj);
-} /* cu_match_t *match_create_callback */
-
-cu_match_t *match_create_simple (const char *regex,
-                                const char *excluderegex, int match_ds_type)
-{
-  cu_match_value_t *user_data;
-  cu_match_t *obj;
-
-  user_data = (cu_match_value_t *) malloc (sizeof (cu_match_value_t));
-  if (user_data == NULL)
-    return (NULL);
-  memset (user_data, '\0', sizeof (cu_match_value_t));
-  user_data->ds_type = match_ds_type;
-
-  obj = match_create_callback (regex, excluderegex,
-                              default_callback, user_data);
-  if (obj == NULL)
-  {
-    sfree (user_data);
-    return (NULL);
-  }
-
-  obj->flags |= UTILS_MATCH_FLAGS_FREE_USER_DATA;
-
-  return (obj);
-} /* cu_match_t *match_create_simple */
-
-void match_value_reset (cu_match_value_t *mv)
-{
-  if (mv == NULL)
-    return;
-
-  if (mv->ds_type & UTILS_MATCH_DS_TYPE_GAUGE)
-  {
-    mv->value.gauge = NAN;
-    mv->values_num = 0;
-  }
-} /* }}} void match_value_reset */
-
-void match_destroy (cu_match_t *obj)
-{
-  if (obj == NULL)
-    return;
-
-  if (obj->flags & UTILS_MATCH_FLAGS_FREE_USER_DATA)
-  {
-    sfree (obj->user_data);
-  }
-
-  sfree (obj);
-} /* void match_destroy */
-
-int match_apply (cu_match_t *obj, const char *str)
-{
-  int status;
-  regmatch_t re_match[32];
-  char *matches[32];
-  size_t matches_num;
-  size_t i;
-
-  if ((obj == NULL) || (str == NULL))
-    return (-1);
-
-  if (obj->flags & UTILS_MATCH_FLAGS_EXCLUDE_REGEX) {
-    status = regexec (&obj->excluderegex, str,
-                     STATIC_ARRAY_SIZE (re_match), re_match,
-                     /* eflags = */ 0);
-    /* Regex did match, so exclude this line */
-    if (status == 0) {
-      DEBUG("ExludeRegex matched, don't count that line\n");
-      return (0);
-    }
-  }
-
-  status = regexec (&obj->regex, str,
-      STATIC_ARRAY_SIZE (re_match), re_match,
-      /* eflags = */ 0);
-
-  /* Regex did not match */
-  if (status != 0)
-    return (0);
-
-  memset (matches, '\0', sizeof (matches));
-  for (matches_num = 0; matches_num < STATIC_ARRAY_SIZE (matches); matches_num++)
-  {
-    if ((re_match[matches_num].rm_so < 0)
-       || (re_match[matches_num].rm_eo < 0))
-      break;
-
-    matches[matches_num] = match_substr (str,
-       re_match[matches_num].rm_so, re_match[matches_num].rm_eo);
-    if (matches[matches_num] == NULL)
-    {
-      status = -1;
-      break;
-    }
-  }
-
-  if (status != 0)
-  {
-    ERROR ("utils_match: match_apply: match_substr failed.");
-  }
-  else
-  {
-    status = obj->callback (str, matches, matches_num, obj->user_data);
-    if (status != 0)
-    {
-      ERROR ("utils_match: match_apply: callback failed.");
-    }
-  }
-
-  for (i = 0; i < matches_num; i++)
-  {
-    sfree (matches[i]);
-  }
-
-  return (status);
-} /* int match_apply */
-
-void *match_get_user_data (cu_match_t *obj)
-{
-  if (obj == NULL)
-    return (NULL);
-  return (obj->user_data);
-} /* void *match_get_user_data */
-
-/* vim: set sw=2 sts=2 ts=8 : */
diff --git a/src/utils_match.h b/src/utils_match.h
deleted file mode 100644 (file)
index 24517b3..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/**
- * collectd - src/utils_match.h
- * Copyright (C) 2008-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; 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
- *
- * Authors:
- *   Florian octo Forster <octo at verplant.org>
- **/
-
-#ifndef UTILS_MATCH_H
-#define UTILS_MATCH_H 1
-
-#include "plugin.h"
-
-/*
- * Defines
- */
-#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_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_COUNTER_SET   0x01
-#define UTILS_MATCH_CF_COUNTER_ADD   0x02
-#define UTILS_MATCH_CF_COUNTER_INC   0x04
-
-#define UTILS_MATCH_CF_DERIVE_SET   0x01
-#define UTILS_MATCH_CF_DERIVE_ADD   0x02
-#define UTILS_MATCH_CF_DERIVE_INC   0x04
-
-#define UTILS_MATCH_CF_ABSOLUTE_SET   0x01
-#define UTILS_MATCH_CF_ABSOLUTE_ADD   0x02
-#define UTILS_MATCH_CF_ABSOLUTE_INC   0x04
-
-/*
- * Data types
- */
-struct cu_match_s;
-typedef struct cu_match_s cu_match_t;
-
-struct cu_match_value_s
-{
-  int ds_type;
-  value_t value;
-  unsigned int values_num;
-};
-typedef struct cu_match_value_s cu_match_value_t;
-
-/*
- * Prototypes
- */
-/*
- * NAME
- *  match_create_callback
- *
- * DESCRIPTION
- *  Creates a new `cu_match_t' object which will use the regular expression
- *  `regex' to match lines, see the `match_apply' method below. If the line
- *  matches, the callback passed in `callback' will be called along with the
- *  pointer `user_pointer'.
- *  The string that's passed to the callback depends on the regular expression:
- *  If the regular expression includes a sub-match, i. e. something like
- *    "value=([0-9][0-9]*)"
- *  then only the submatch (the part in the parenthesis) will be passed to the
- *  callback. If there is no submatch, then the entire string is passed to the
- *  callback.
- *  The optional `excluderegex' allows to exclude the line from the match, if
- *  the excluderegex matches.
- */
-cu_match_t *match_create_callback (const char *regex, const char *excluderegex,
-               int (*callback) (const char *str,
-                 char * const *matches, size_t matches_num, void *user_data),
-               void *user_data);
-
-/*
- * NAME
- *  match_create_simple
- *
- * DESCRIPTION
- *  Creates a new `cu_match_t' with a default callback. The user data for that
- *  default callback will be a `cu_match_value_t' structure, with
- *  `ds_type' copied to the structure. The default callback will handle the
- *  string as containing a number (see strtoll(3) and strtod(3)) and store that
- *  number in the `value' member. How that is done depends on `ds_type':
- *
- *  UTILS_MATCH_DS_TYPE_GAUGE
- *    The function will search for a floating point number in the string and
- *    store it in value.gauge.
- *  UTILS_MATCH_DS_TYPE_COUNTER_SET
- *    The function will search for an integer in the string and store it in
- *    value.counter.
- *  UTILS_MATCH_DS_TYPE_COUNTER_ADD
- *    The function will search for an integer in the string and add it to the
- *    value in value.counter.
- *  UTILS_MATCH_DS_TYPE_COUNTER_INC
- *    The function will not search for anything in the string and increase
- *    value.counter by one.
- */
-cu_match_t *match_create_simple (const char *regex,
-                                const char *excluderegex, int ds_type);
-
-/*
- * NAME
- *  match_value_reset
- *
- * DESCRIPTION
- *   Resets the internal state, if applicable. This function must be called
- *   after each iteration for "simple" matches, usually after dispatching the
- *   metrics.
- */
-void match_value_reset (cu_match_value_t *mv);
-
-/*
- * NAME
- *  match_destroy
- *
- * DESCRIPTION
- *  Destroys the object and frees all internal resources.
- */
-void match_destroy (cu_match_t *obj);
-
-/*
- * NAME
- *  match_apply
- *
- * DESCRIPTION
- *  Tries to match the string `str' with the regular expression of `obj'. If
- *  the string matches, calls the callback in `obj' with the (sub-)match.
- *
- *  The user_data pointer passed to `match_create_callback' is NOT freed
- *  automatically. The `cu_match_value_t' structure allocated by
- *  `match_create_callback' is freed automatically.
- */
-int match_apply (cu_match_t *obj, const char *str);
-
-/*
- * NAME
- *  match_get_user_data
- *
- * DESCRIPTION
- *  Returns the pointer passed to `match_create_callback' or a pointer to the
- *  `cu_match_value_t' structure allocated by `match_create_simple'.
- */
-void *match_get_user_data (cu_match_t *obj);
-
-#endif /* UTILS_MATCH_H */
-
-/* vim: set sw=2 sts=2 ts=8 : */
index 3cede018e243067d5f1bcfb71d5f9e76949b074e..b63a81ad29b44fe13c113ca8843a7abb701bcfbf 100644 (file)
  *   Niki W. Waibel <niki.waibel@gmx.net>
 **/
 
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "collectd.h"
+#include "utils_mount.h"
+
+#include "common.h" /* sstrncpy() et alii */
+#include "plugin.h" /* ERROR() macro */
 
-#include "common.h"
 #if HAVE_XFS_XQM_H
 # include <xfs/xqm.h>
 #define XFS_SUPER_MAGIC_STR "XFSB"
 #define XFS_SUPER_MAGIC2_STR "BSFX"
 #endif
 
-#include "plugin.h"
-#include "utils_mount.h"
-
 #if HAVE_GETVFSSTAT
 #  if HAVE_SYS_TYPES_H
 #    include <sys/types.h>
index 83f789be9cd3acdf7f5535cb2e41ed035e3cbc2b..bc0077f95db3cac3fbf44cc637cc81bb9ddb87b2 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 ','.
diff --git a/src/utils_mount_test.c b/src/utils_mount_test.c
new file mode 100644 (file)
index 0000000..c5ffbfb
--- /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 "testing.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 : */
index 820f14f58ef1da32cdfbe73c016c7fefdba4a0b0..7f06f2959133fe46724344184d890a5d52befd9a 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);
@@ -150,55 +155,4 @@ int parse_option (char **ret_buffer, char **ret_key, char **ret_value)
   return (0);
 } /* int parse_option */
 
-int escape_string (char *buffer, size_t buffer_size)
-{
-  char *temp;
-  size_t i;
-  size_t j;
-
-  /* Check if we need to escape at all first */
-  temp = strpbrk (buffer, " \t\"\\");
-  if (temp == NULL)
-    return (0);
-
-  temp = (char *) malloc (buffer_size);
-  if (temp == NULL)
-    return (-1);
-  memset (temp, 0, buffer_size);
-
-  temp[0] = '"';
-  j = 1;
-
-  for (i = 0; i < buffer_size; i++)
-  {
-    if (buffer[i] == 0)
-    {
-      break;
-    }
-    else if ((buffer[i] == '"') || (buffer[i] == '\\'))
-    {
-      if (j > (buffer_size - 4))
-        break;
-      temp[j] = '\\';
-      temp[j + 1] = buffer[i];
-      j += 2;
-    }
-    else
-    {
-      if (j > (buffer_size - 3))
-        break;
-      temp[j] = buffer[i];
-      j++;
-    }
-  }
-
-  assert ((j + 1) < buffer_size);
-  temp[j] = '"';
-  temp[j + 1] = 0;
-
-  sstrncpy (buffer, temp, buffer_size);
-  sfree (temp);
-  return (0);
-} /* int escape_string */
-
 /* vim: set sw=2 ts=8 tw=78 et : */
index 1dfb3ae949e82573b951ae43e1ac914d1fa453ac..885a6a33d263dfe1dd3429e209dc4484bf7a307d 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
@@ -25,8 +30,6 @@
 int parse_string (char **ret_buffer, char **ret_string);
 int parse_option (char **ret_buffer, char **ret_key, char **ret_value);
 
-int escape_string (char *buffer, size_t buffer_size);
-
 #endif /* UTILS_PARSE_OPTION */
 
 /* vim: set sw=2 ts=8 tw=78 et : */
diff --git a/src/utils_random.c b/src/utils_random.c
deleted file mode 100644 (file)
index b873845..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- * collectd - src/utils_random.c
- * 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"),
- * 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_time.h"
-
-#include <pthread.h>
-
-static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
-static _Bool have_seed = 0;
-static unsigned short seed[3];
-
-static void cdrand_seed (void)
-{
-  cdtime_t t;
-
-  if (have_seed)
-    return;
-
-  t = cdtime();
-
-  seed[0] = (unsigned short) t;
-  seed[1] = (unsigned short) (t >> 16);
-  seed[2] = (unsigned short) (t >> 32);
-
-  have_seed = 1;
-}
-
-double cdrand_d (void)
-{
-  double r;
-
-  pthread_mutex_lock (&lock);
-  cdrand_seed ();
-  r = erand48 (seed);
-  pthread_mutex_unlock (&lock);
-
-  return (r);
-}
-
-long cdrand_range (long min, long max)
-{
-  long range;
-  long r;
-
-  range = 1 + max - min;
-
-  r = (long) (0.5 + (cdrand_d () * range));
-  r += min;
-
-  return (r);
-}
diff --git a/src/utils_random.h b/src/utils_random.h
deleted file mode 100644 (file)
index b05f4c8..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * collectd - src/utils_random.h
- * 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"),
- * 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>
- **/
-
-/**
- * Returns a random double value in the range [0..1), i.e. excluding 1.
- *
- * This function is thread- and reentrant-safe.
- */
-double cdrand_d (void);
-
-/**
- * Returns a random long between min and max, inclusively.
- *
- * If min is larger than max, the result may be rounded incorrectly and may be
- * outside the intended range. This function is thread- and reentrant-safe.
- */
-long cdrand_range (long min, long max);
index 1bd1ad473a8a265b06b9c4bf6633039c1a9e553e..5add32373cd3d91f861265df88dc459d4bb57c99 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 fdfd6ecb9727f51a6589e551bda125db72018836..14daadfa64614e577734dd5765fd8e543ed8a684 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>
diff --git a/src/utils_subst.c b/src/utils_subst.c
deleted file mode 100644 (file)
index a49f6db..0000000
+++ /dev/null
@@ -1,144 +0,0 @@
-/**
- * collectd - src/utils_subst.c
- * 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
- *
- * Authors:
- *   Sebastian "tokkee" Harl <sh at tokkee.org>
- **/
-
-/*
- * This module provides functions for string substitution.
- */
-
-#include "collectd.h"
-#include "common.h"
-
-char *subst (char *buf, size_t buflen, const char *string, int off1, int off2,
-               const char *replacement)
-{
-       char  *buf_ptr = buf;
-       size_t len     = buflen;
-
-       if ((NULL == buf) || (0 >= buflen) || (NULL == string)
-                       || (0 > off1) || (0 > off2) || (off1 > off2)
-                       || (NULL == replacement))
-               return NULL;
-
-       sstrncpy (buf_ptr, string,
-                       ((size_t)off1 + 1 > buflen) ? buflen : (size_t)off1 + 1);
-       buf_ptr += off1;
-       len     -= off1;
-
-       if (0 >= len)
-               return buf;
-
-       sstrncpy (buf_ptr, replacement, len);
-       buf_ptr += strlen (replacement);
-       len     -= strlen (replacement);
-
-       if (0 >= len)
-               return buf;
-
-       sstrncpy (buf_ptr, string + off2, len);
-       return buf;
-} /* subst */
-
-char *asubst (const char *string, int off1, int off2, const char *replacement)
-{
-       char *buf;
-       int   len;
-
-       char *ret;
-
-       if ((NULL == string) || (0 > off1) || (0 > off2) || (off1 > off2)
-                       || (NULL ==replacement))
-               return NULL;
-
-       len = off1 + strlen (replacement) + strlen (string) - off2 + 1;
-
-       buf = (char *)malloc (len);
-       if (NULL == buf)
-               return NULL;
-
-       ret = subst (buf, len, string, off1, off2, replacement);
-       if (NULL == ret)
-               free (buf);
-       return ret;
-} /* asubst */
-
-char *subst_string (char *buf, size_t buflen, const char *string,
-               const char *needle, const char *replacement)
-{
-       char *temp;
-       size_t needle_len;
-       size_t i;
-
-       if ((buf == NULL) || (string == NULL)
-                       || (needle == NULL) || (replacement == NULL))
-               return (NULL);
-
-       temp = (char *) malloc (buflen);
-       if (temp == NULL)
-       {
-               ERROR ("subst_string: malloc failed.");
-               return (NULL);
-       }
-
-       needle_len = strlen (needle);
-       strncpy (buf, string, buflen);
-
-       /* Limit the loop to prevent endless loops. */
-       for (i = 0; i < buflen; i++)
-       {
-               char *begin_ptr;
-               size_t begin;
-
-               /* Find `needle' in `buf'. */
-               begin_ptr = strstr (buf, needle);
-               if (begin_ptr == NULL)
-                       break;
-
-               /* Calculate the start offset. */
-               begin = begin_ptr - buf;
-
-               /* Substitute the region using `subst'. The result is stored in
-                * `temp'. */
-               begin_ptr = subst (temp, buflen, buf,
-                               begin, begin + needle_len,
-                               replacement);
-               if (begin_ptr == NULL)
-               {
-                       WARNING ("subst_string: subst failed.");
-                       break;
-               }
-
-               /* Copy the new string in `temp' to `buf' for the next round. */
-               strncpy (buf, temp, buflen);
-       }
-
-       if (i >= buflen)
-       {
-               WARNING ("subst_string: Loop exited after %zu iterations: "
-                               "string = %s; needle = %s; replacement = %s;",
-                               i, string, needle, replacement);
-       }
-
-       sfree (temp);
-       return (buf);
-} /* char *subst_string */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
-
diff --git a/src/utils_subst.h b/src/utils_subst.h
deleted file mode 100644 (file)
index 4387b85..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
- * 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
- *
- * Authors:
- *   Sebastian "tokkee" Harl <sh at tokkee.org>
- **/
-
-/*
- * This module provides functions for string substitution.
- */
-
-#ifndef UTILS_SUBST_H
-#define UTILS_SUBST_H 1
-
-#include <stddef.h>
-
-/*
- * subst:
- *
- * Replace a substring of a string with the specified replacement text. The
- * resulting string is stored in the buffer pointed to by 'buf' of length
- * 'buflen'. Upon success, the buffer will always be null-terminated. The
- * result may be truncated if the buffer is too small.
- *
- * The substring to be replaces is identified by the two offsets 'off1' and
- * 'off2' where 'off1' specifies the offset to the beginning of the substring
- * and 'off2' specifies the offset to the first byte after the substring.
- *
- * The minimum buffer size to store the complete return value (including the
- * terminating '\0' character) thus has to be:
- * off1 + strlen(replacement) + strlen(string) - off2 + 1
- *
- * Example:
- *
- *             01234567890
- *   string = "foo_____bar"
- *                ^    ^
- *                |    |
- *              off1  off2
- *
- *   off1 = 3
- *   off2 = 8
- *
- *   replacement = " - "
- *
- *   -> "foo - bar"
- *
- * The function returns 'buf' on success, NULL else.
- */
-char *subst (char *buf, size_t buflen, const char *string, int off1, int off2,
-               const char *replacement);
-
-/*
- * asubst:
- *
- * This function is very similar to subst(). It differs in that it
- * automatically allocates the memory required for the return value which the
- * user then has to free himself.
- *
- * Returns the newly allocated result string on success, NULL else.
- */
-char *asubst (const char *string, int off1, int off2, const char *replacement);
-
-/*
- * subst_string:
- *
- * Works like `subst', but instead of specifying start and end offsets you
- * specify `needle', the string that is to be replaced. If `needle' is found
- * in `string' (using strstr(3)), the offset is calculated and `subst' is
- * called with the determined parameters.
- *
- * If the substring is not found, no error will be indicated and
- * `subst_string' works mostly like `strncpy'.
- *
- * If the substring appears multiple times, all appearances will be replaced.
- * If the substring has been found `buflen' times, an endless loop is assumed
- * and the loop is broken. A warning is printed and the function returns
- * success.
- */
-char *subst_string (char *buf, size_t buflen, const char *string,
-               const char *needle, const char *replacement);
-
-#endif /* UTILS_SUBST_H */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
-
diff --git a/src/utils_tail.c b/src/utils_tail.c
deleted file mode 100644 (file)
index 0b31262..0000000
+++ /dev/null
@@ -1,255 +0,0 @@
-/**
- * collectd - src/utils_tail.c
- * 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
- *
- * Author:
- *   Luke Heberling <lukeh at c-ware.com>
- *   Florian Forster <octo at verplant.org>
- *
- * Description:
- *   Encapsulates useful code for plugins which must watch for appends to
- *   the end of a file.
- **/
-
-#include "collectd.h"
-#include "common.h"
-#include "utils_tail.h"
-
-struct cu_tail_s
-{
-       char  *file;
-       FILE  *fh;
-       struct stat stat;
-};
-
-static int cu_tail_reopen (cu_tail_t *obj)
-{
-  int seek_end = 0;
-  FILE *fh;
-  struct stat stat_buf;
-  int status;
-
-  memset (&stat_buf, 0, sizeof (stat_buf));
-  status = stat (obj->file, &stat_buf);
-  if (status != 0)
-  {
-    char errbuf[1024];
-    ERROR ("utils_tail: stat (%s) failed: %s", obj->file,
-       sstrerror (errno, errbuf, sizeof (errbuf)));
-    return (-1);
-  }
-
-  /* The file is already open.. */
-  if ((obj->fh != NULL) && (stat_buf.st_ino == obj->stat.st_ino))
-  {
-    /* Seek to the beginning if file was truncated */
-    if (stat_buf.st_size < obj->stat.st_size)
-    {
-      INFO ("utils_tail: File `%s' was truncated.", obj->file);
-      status = fseek (obj->fh, 0, SEEK_SET);
-      if (status != 0)
-      {
-       char errbuf[1024];
-       ERROR ("utils_tail: fseek (%s) failed: %s", obj->file,
-           sstrerror (errno, errbuf, sizeof (errbuf)));
-       fclose (obj->fh);
-       obj->fh = NULL;
-       return (-1);
-      }
-    }
-    memcpy (&obj->stat, &stat_buf, sizeof (struct stat));
-    return (1);
-  }
-
-  /* Seek to the end if we re-open the same file again or the file opened
-   * is the first at all or the first after an error */
-  if ((obj->stat.st_ino == 0) || (obj->stat.st_ino == stat_buf.st_ino))
-    seek_end = 1;
-
-  fh = fopen (obj->file, "r");
-  if (fh == NULL)
-  {
-    char errbuf[1024];
-    ERROR ("utils_tail: fopen (%s) failed: %s", obj->file,
-       sstrerror (errno, errbuf, sizeof (errbuf)));
-    return (-1);
-  }
-
-  if (seek_end != 0)
-  {
-    status = fseek (fh, 0, SEEK_END);
-    if (status != 0)
-    {
-      char errbuf[1024];
-      ERROR ("utils_tail: fseek (%s) failed: %s", obj->file,
-         sstrerror (errno, errbuf, sizeof (errbuf)));
-      fclose (fh);
-      return (-1);
-    }
-  }
-
-  if (obj->fh != NULL)
-    fclose (obj->fh);
-  obj->fh = fh;
-  memcpy (&obj->stat, &stat_buf, sizeof (struct stat));
-
-  return (0);
-} /* int cu_tail_reopen */
-
-cu_tail_t *cu_tail_create (const char *file)
-{
-       cu_tail_t *obj;
-
-       obj = (cu_tail_t *) malloc (sizeof (cu_tail_t));
-       if (obj == NULL)
-               return (NULL);
-       memset (obj, '\0', sizeof (cu_tail_t));
-
-       obj->file = strdup (file);
-       if (obj->file == NULL)
-       {
-               free (obj);
-               return (NULL);
-       }
-
-       obj->fh = NULL;
-
-       return (obj);
-} /* cu_tail_t *cu_tail_create */
-
-int cu_tail_destroy (cu_tail_t *obj)
-{
-       if (obj->fh != NULL)
-               fclose (obj->fh);
-       free (obj->file);
-       free (obj);
-
-       return (0);
-} /* int cu_tail_destroy */
-
-int cu_tail_readline (cu_tail_t *obj, char *buf, int buflen)
-{
-  int status;
-
-  if (buflen < 1)
-  {
-    ERROR ("utils_tail: cu_tail_readline: buflen too small: %i bytes.",
-       buflen);
-    return (-1);
-  }
-
-  if (obj->fh == NULL)
-  {
-    status = cu_tail_reopen (obj);
-    if (status < 0)
-      return (status);
-  }
-  assert (obj->fh != NULL);
-
-  /* Try to read from the filehandle. If that succeeds, everything appears to
-   * be fine and we can return. */
-  clearerr (obj->fh);
-  if (fgets (buf, buflen, obj->fh) != NULL)
-  {
-    buf[buflen - 1] = 0;
-    return (0);
-  }
-
-  /* Check if we encountered an error */
-  if (ferror (obj->fh) != 0)
-  {
-    /* Jupp, error. Force `cu_tail_reopen' to reopen the file.. */
-    fclose (obj->fh);
-    obj->fh = NULL;
-  }
-  /* else: eof -> check if the file was moved away and reopen the new file if
-   * so.. */
-
-  status = cu_tail_reopen (obj);
-  /* error -> return with error */
-  if (status < 0)
-    return (status);
-  /* file end reached and file not reopened -> nothing more to read */
-  else if (status > 0)
-  {
-    buf[0] = 0;
-    return (0);
-  }
-
-  /* If we get here: file was re-opened and there may be more to read.. Let's
-   * try again. */
-  if (fgets (buf, buflen, obj->fh) != NULL)
-  {
-    buf[buflen - 1] = 0;
-    return (0);
-  }
-
-  if (ferror (obj->fh) != 0)
-  {
-    char errbuf[1024];
-    WARNING ("utils_tail: fgets (%s) returned an error: %s", obj->file,
-       sstrerror (errno, errbuf, sizeof (errbuf)));
-    fclose (obj->fh);
-    obj->fh = NULL;
-    return (-1);
-  }
-
-  /* EOf, well, apparently the new file is empty.. */
-  buf[0] = 0;
-  return (0);
-} /* int cu_tail_readline */
-
-int cu_tail_read (cu_tail_t *obj, char *buf, int buflen, tailfunc_t *callback,
-               void *data)
-{
-       int status;
-
-       while (42)
-       {
-               size_t len;
-
-               status = cu_tail_readline (obj, buf, buflen);
-               if (status != 0)
-               {
-                       ERROR ("utils_tail: cu_tail_read: cu_tail_readline "
-                                       "failed.");
-                       break;
-               }
-
-               /* check for EOF */
-               if (buf[0] == 0)
-                       break;
-
-               len = strlen (buf);
-               while (len > 0) {
-                       if (buf[len - 1] != '\n')
-                               break;
-                       buf[len - 1] = '\0';
-                       len--;
-               }
-
-               status = callback (data, buf, buflen);
-               if (status != 0)
-               {
-                       ERROR ("utils_tail: cu_tail_read: callback returned "
-                                       "status %i.", status);
-                       break;
-               }
-       }
-
-       return status;
-} /* int cu_tail_read */
diff --git a/src/utils_tail.h b/src/utils_tail.h
deleted file mode 100644 (file)
index c479319..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/**
- * 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.
- *
- * 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:
- *   Luke Heberling <lukeh at c-ware.com>
- *
- * DESCRIPTION
- *   Facilitates reading information that is appended to a file, taking into
- *   account that the file may be rotated and a new file created under the
- *   same name.
- **/
-
-#ifndef UTILS_TAIL_H
-#define UTILS_TAIL_H 1
-
-struct cu_tail_s;
-typedef struct cu_tail_s cu_tail_t;
-
-typedef int tailfunc_t(void *data, char *buf, int buflen);
-
-/*
- * NAME
- *   cu_tail_create
- *
- * DESCRIPTION
- *   Allocates a new tail object..
- *
- * PARAMETERS
- *   `file'       The name of the file to be tailed.
- */
-cu_tail_t *cu_tail_create (const char *file);
-
-/*
- * cu_tail_destroy
- *
- * Takes a tail object returned by `cu_tail_create' and destroys it, freeing
- * all internal memory.
- *
- * Returns 0 when successful and non-zero otherwise.
- */
-int cu_tail_destroy (cu_tail_t *obj);
-
-/*
- * cu_tail_readline
- *
- * Reads from the file until `buflen' characters are read, a newline
- * character is read, or an eof condition is encountered. `buf' is
- * always null-terminated on successful return and isn't touched when non-zero
- * is returned.
- *
- * You can check if the EOF condition is reached by looking at the buffer: If
- * the length of the string stored in the buffer is zero, EOF occurred.
- * Otherwise at least the newline character will be in the buffer.
- *
- * Returns 0 when successful and non-zero otherwise.
- */
-int cu_tail_readline (cu_tail_t *obj, char *buf, int buflen);
-
-/*
- * cu_tail_readline
- *
- * Reads from the file until eof condition or an error is encountered.
- *
- * Returns 0 when successful and non-zero otherwise.
- */
-int cu_tail_read (cu_tail_t *obj, char *buf, int buflen, tailfunc_t *callback,
-               void *data);
-
-#endif /* UTILS_TAIL_H */
diff --git a/src/utils_tail_match.c b/src/utils_tail_match.c
deleted file mode 100644 (file)
index 8ae2208..0000000
+++ /dev/null
@@ -1,263 +0,0 @@
-/*
- * collectd - src/utils_tail_match.c
- * 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
- *
- * Author:
- *   Luke Heberling <lukeh at c-ware.com>
- *   Florian Forster <octo at verplant.org>
- *
- * Description:
- *   Encapsulates useful code to plugins which must parse a log file.
- */
-
-#include "collectd.h"
-#include "common.h"
-#include "plugin.h"
-#include "utils_match.h"
-#include "utils_tail.h"
-#include "utils_tail_match.h"
-
-struct cu_tail_match_simple_s
-{
-  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];
-};
-typedef struct cu_tail_match_simple_s cu_tail_match_simple_t;
-
-struct cu_tail_match_match_s
-{
-  cu_match_t *match;
-  void *user_data;
-  int (*submit) (cu_match_t *match, void *user_data);
-  void (*free) (void *user_data);
-};
-typedef struct cu_tail_match_match_s cu_tail_match_match_t;
-
-struct cu_tail_match_s
-{
-  int flags;
-  cu_tail_t *tail;
-
-  cu_tail_match_match_t *matches;
-  size_t matches_num;
-};
-
-/*
- * Private functions
- */
-static int simple_submit_match (cu_match_t *match, void *user_data)
-{
-  cu_tail_match_simple_t *data = (cu_tail_match_simple_t *) user_data;
-  cu_match_value_t *match_value;
-  value_list_t vl = VALUE_LIST_INIT;
-  value_t values[1];
-
-  match_value = (cu_match_value_t *) match_get_user_data (match);
-  if (match_value == NULL)
-    return (-1);
-
-  if ((match_value->ds_type & UTILS_MATCH_DS_TYPE_GAUGE)
-      && (match_value->values_num == 0))
-    values[0].gauge = NAN;
-  else
-    values[0] = match_value->value;
-
-  vl.values = values;
-  vl.values_len = 1;
-  sstrncpy (vl.host, hostname_g, sizeof (vl.host));
-  sstrncpy (vl.plugin, data->plugin, sizeof (vl.plugin));
-  sstrncpy (vl.plugin_instance, data->plugin_instance,
-      sizeof (vl.plugin_instance));
-  sstrncpy (vl.type, data->type, sizeof (vl.type));
-  sstrncpy (vl.type_instance, data->type_instance,
-      sizeof (vl.type_instance));
-
-  plugin_dispatch_values (&vl);
-
-  if (match_value->ds_type & UTILS_MATCH_DS_TYPE_GAUGE)
-  {
-    match_value->value.gauge = NAN;
-    match_value->values_num = 0;
-  }
-
-  return (0);
-} /* int simple_submit_match */
-
-static int tail_callback (void *data, char *buf,
-    int __attribute__((unused)) buflen)
-{
-  cu_tail_match_t *obj = (cu_tail_match_t *) data;
-  size_t i;
-
-  for (i = 0; i < obj->matches_num; i++)
-    match_apply (obj->matches[i].match, buf);
-
-  return (0);
-} /* int tail_callback */
-
-/*
- * Public functions
- */
-cu_tail_match_t *tail_match_create (const char *filename)
-{
-  cu_tail_match_t *obj;
-
-  obj = (cu_tail_match_t *) malloc (sizeof (cu_tail_match_t));
-  if (obj == NULL)
-    return (NULL);
-  memset (obj, '\0', sizeof (cu_tail_match_t));
-
-  obj->tail = cu_tail_create (filename);
-  if (obj->tail == NULL)
-  {
-    sfree (obj);
-    return (NULL);
-  }
-
-  return (obj);
-} /* cu_tail_match_t *tail_match_create */
-
-void tail_match_destroy (cu_tail_match_t *obj)
-{
-  size_t i;
-
-  if (obj == NULL)
-    return;
-
-  if (obj->tail != NULL)
-  {
-    cu_tail_destroy (obj->tail);
-    obj->tail = NULL;
-  }
-
-  for (i = 0; i < obj->matches_num; i++)
-  {
-    cu_tail_match_match_t *match = obj->matches + i;
-    if (match->match != NULL)
-    {
-      match_destroy (match->match);
-      match->match = NULL;
-    }
-
-    if ((match->user_data != NULL)
-       && (match->free != NULL))
-      (*match->free) (match->user_data);
-    match->user_data = NULL;
-  }
-
-  sfree (obj->matches);
-  sfree (obj);
-} /* void tail_match_destroy */
-
-int tail_match_add_match (cu_tail_match_t *obj, cu_match_t *match,
-    int (*submit_match) (cu_match_t *match, void *user_data),
-    void *user_data,
-    void (*free_user_data) (void *user_data))
-{
-  cu_tail_match_match_t *temp;
-
-  temp = (cu_tail_match_match_t *) realloc (obj->matches,
-      sizeof (cu_tail_match_match_t) * (obj->matches_num + 1));
-  if (temp == NULL)
-    return (-1);
-
-  obj->matches = temp;
-  obj->matches_num++;
-
-  temp = obj->matches + (obj->matches_num - 1);
-
-  temp->match = match;
-  temp->user_data = user_data;
-  temp->submit = submit_match;
-  temp->free = free_user_data;
-
-  return (0);
-} /* int tail_match_add_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)
-{
-  cu_match_t *match;
-  cu_tail_match_simple_t *user_data;
-  int status;
-
-  match = match_create_simple (regex, excluderegex, ds_type);
-  if (match == NULL)
-    return (-1);
-
-  user_data = (cu_tail_match_simple_t *) malloc (sizeof (cu_tail_match_simple_t));
-  if (user_data == NULL)
-  {
-    match_destroy (match);
-    return (-1);
-  }
-  memset (user_data, '\0', sizeof (cu_tail_match_simple_t));
-
-  sstrncpy (user_data->plugin, plugin, sizeof (user_data->plugin));
-  if (plugin_instance != NULL)
-    sstrncpy (user_data->plugin_instance, plugin_instance,
-       sizeof (user_data->plugin_instance));
-
-  sstrncpy (user_data->type, type, sizeof (user_data->type));
-  if (type_instance != NULL)
-    sstrncpy (user_data->type_instance, type_instance,
-       sizeof (user_data->type_instance));
-
-  status = tail_match_add_match (obj, match, simple_submit_match,
-      user_data, free);
-
-  if (status != 0)
-  {
-    match_destroy (match);
-    sfree (user_data);
-  }
-
-  return (status);
-} /* int tail_match_add_match_simple */
-
-int tail_match_read (cu_tail_match_t *obj)
-{
-  char buffer[4096];
-  int status;
-  size_t i;
-
-  status = cu_tail_read (obj->tail, buffer, sizeof (buffer), tail_callback,
-      (void *) obj);
-  if (status != 0)
-  {
-    ERROR ("tail_match: cu_tail_read failed.");
-    return (status);
-  }
-
-  for (i = 0; i < obj->matches_num; i++)
-  {
-    cu_tail_match_match_t *lt_match = obj->matches + i;
-
-    if (lt_match->submit == NULL)
-      continue;
-
-    (*lt_match->submit) (lt_match->match, lt_match->user_data);
-  }
-
-  return (0);
-} /* int tail_match_read */
-
-/* vim: set sw=2 sts=2 ts=8 : */
diff --git a/src/utils_tail_match.h b/src/utils_tail_match.h
deleted file mode 100644 (file)
index 7659745..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * collectd - src/utils_tail_match.h
- * 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
- *
- * Authors:
- *   Luke Heberling <lukeh at c-ware.com>
- *   Florian Forster <octo at verplant.org>
- *
- * Description:
- *   `tail_match' uses `utils_tail' and `utils_match' to tail a file and try to
- *   match it using several regular expressions. Matches are then passed to
- *   user-provided callback functions or default handlers. This should keep all
- *   of the parsing logic out of the actual plugin, which only operate with
- *   regular expressions.
- */
-
-#include "utils_match.h"
-
-struct cu_tail_match_s;
-typedef struct cu_tail_match_s cu_tail_match_t;
-
-/*
- * NAME
- *   tail_match_create
- *
- * DESCRIPTION
- *   Allocates, initializes and returns a new `cu_tail_match_t' object.
- *
- * PARAMETERS
- *   `filename'  The name to read data from.
- *
- * RETURN VALUE
- *   Returns NULL upon failure, non-NULL otherwise.
- */
-cu_tail_match_t *tail_match_create (const char *filename);
-
-/*
- * NAME
- *   tail_match_destroy
- *
- * DESCRIPTION
- *   Releases resources used by the `cu_tail_match_t' object.
- *
- * PARAMETERS
- *   The object to destroy.
- */
-void tail_match_destroy (cu_tail_match_t *obj);
-
-/*
- * NAME
- *   tail_match_add_match
- *
- * DESCRIPTION
- *   Adds a match, in form of a `cu_match_t' object, to the object.
- *   After data has been read from the logfile (using utils_tail) the callback
- *   function `submit_match' is called with the match object and the user
- *   supplied data.
- *   Please note that his function is called regardless whether this match
- *   matched any lines recently or not.
- *   When `tail_match_destroy' is called the `user_data' pointer is freed using
- *   the `free_user_data' callback - if it is not NULL.
- *   When using this interface the `tail_match' module doesn't dispatch any values
- *   itself - all that has to happen in either the match-callbacks or the
- *   submit_match callback.
- *
- * RETURN VALUE
- *   Zero upon success, non-zero otherwise.
- */
-int tail_match_add_match (cu_tail_match_t *obj, cu_match_t *match,
-    int (*submit_match) (cu_match_t *match, void *user_data),
-    void *user_data,
-    void (*free_user_data) (void *user_data));
-
-/*
- * NAME
- *  tail_match_add_match_simple
- *
- * DESCRIPTION
- *  A simplified version of `tail_match_add_match'. The regular expressen `regex'
- *  must match a number, which is then dispatched according to `ds_type'. See
- *  the `match_create_simple' function in utils_match.h for a description how
- *  this flag effects calculation of a new value.
- *  The values gathered are dispatched by the tail_match module in this case. The
- *  passed `plugin', `plugin_instance', `type', and `type_instance' are
- *  directly used when submitting these values.
- *  With excluderegex it is possible to exlude lines from the match.
- *
- * RETURN VALUE
- *   Zero upon success, non-zero otherwise.
- */
-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);
-
-/*
- * NAME
- *   tail_match_read
- *
- * DESCRIPTION
- *   This function should be called periodically by plugins. It reads new lines
- *   from the logfile using `utils_tail' and tries to match them using all
- *   added `utils_match' objects.
- *   After all lines have been read and processed, the submit_match callback is
- *   called or, in case of tail_match_add_match_simple, the data is dispatched to
- *   the daemon directly.
- *
- * RETURN VALUE
- *   Zero on success, nonzero on failure.
-*/
-int tail_match_read (cu_tail_match_t *obj);
-
-/* vim: set sw=2 sts=2 ts=8 : */
diff --git a/src/utils_time.c b/src/utils_time.c
deleted file mode 100644 (file)
index 6789758..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * collectd - src/utils_time.h
- * 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.
- *
- * 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
- *
- * Authors:
- *   Florian octo Forster <ff at octo.it>
- **/
-
-#include "collectd.h"
-#include "utils_time.h"
-#include "plugin.h"
-#include "common.h"
-
-#if HAVE_CLOCK_GETTIME
-cdtime_t cdtime (void) /* {{{ */
-{
-  int status;
-  struct timespec ts = { 0, 0 };
-
-  status = clock_gettime (CLOCK_REALTIME, &ts);
-  if (status != 0)
-  {
-    char errbuf[1024];
-    ERROR ("cdtime: clock_gettime failed: %s",
-        sstrerror (errno, errbuf, sizeof (errbuf)));
-    return (0);
-  }
-
-  return (TIMESPEC_TO_CDTIME_T (&ts));
-} /* }}} cdtime_t cdtime */
-#else
-/* Work around for Mac OS X which doesn't have clock_gettime(2). *sigh* */
-cdtime_t cdtime (void) /* {{{ */
-{
-  int status;
-  struct timeval tv = { 0, 0 };
-
-  status = gettimeofday (&tv, /* struct timezone = */ NULL);
-  if (status != 0)
-  {
-    char errbuf[1024];
-    ERROR ("cdtime: gettimeofday failed: %s",
-        sstrerror (errno, errbuf, sizeof (errbuf)));
-    return (0);
-  }
-
-  return (TIMEVAL_TO_CDTIME_T (&tv));
-} /* }}} cdtime_t cdtime */
-#endif
-
-size_t cdtime_to_iso8601 (char *s, size_t max, cdtime_t t) /* {{{ */
-{
-  struct timespec t_spec;
-  struct tm t_tm;
-
-  size_t len;
-
-  CDTIME_T_TO_TIMESPEC (t, &t_spec);
-  NORMALIZE_TIMESPEC (t_spec);
-
-  if (localtime_r ((time_t *)&t_spec.tv_sec, &t_tm) == NULL) {
-    char errbuf[1024];
-    ERROR ("cdtime_to_iso8601: localtime_r failed: %s",
-        sstrerror (errno, errbuf, sizeof (errbuf)));
-    return (0);
-  }
-
-  len = strftime (s, max, "%Y-%m-%dT%H:%M:%S", &t_tm);
-  if (len == 0)
-    return 0;
-
-  if (max - len > 2) {
-    int n = snprintf (s + len, max - len, ".%09i", (int)t_spec.tv_nsec);
-    len += (n < max - len) ? n : max - len;
-  }
-
-  if (max - len > 3) {
-    int n = strftime (s + len, max - len, "%z", &t_tm);
-    len += (n < max - len) ? n : max - len;
-  }
-
-  s[max - 1] = '\0';
-  return len;
-} /* }}} size_t cdtime_to_iso8601 */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/src/utils_time.h b/src/utils_time.h
deleted file mode 100644 (file)
index 0081957..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- * collectd - src/utils_time.h
- * 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.
- *
- * 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
- *
- * Authors:
- *   Florian octo Forster <ff at octo.it>
- **/
-
-#ifndef UTILS_TIME_H
-#define UTILS_TIME_H 1
-
-#include "collectd.h"
-
-/*
- * "cdtime_t" is a 64bit unsigned integer. The time is stored at a 2^-30 second
- * resolution, i.e. the most significant 34 bit are used to store the time in
- * seconds, the least significant bits store the sub-second part in something
- * very close to nanoseconds. *The* big advantage of storing time in this
- * manner is that comparing times and calculating differences is as simple as
- * it is with "time_t", i.e. a simple integer comparison / subtraction works.
- */
-/* 
- * cdtime_t is defined in "collectd.h" */
-/* typedef uint64_t cdtime_t; */
-
-/* 2^30 = 1073741824 */
-#define TIME_T_TO_CDTIME_T(t) (((cdtime_t) (t)) * 1073741824)
-#define CDTIME_T_TO_TIME_T(t) ((time_t) ((t) / 1073741824))
-
-#define CDTIME_T_TO_DOUBLE(t) (((double) (t)) / 1073741824.0)
-#define DOUBLE_TO_CDTIME_T(d) ((cdtime_t) ((d) * 1073741824.0))
-
-#define MS_TO_CDTIME_T(ms) ((cdtime_t)    (((double) (ms)) * 1073741.824))
-#define CDTIME_T_TO_MS(t)  ((long)        (((double) (t))  / 1073741.824))
-#define US_TO_CDTIME_T(us) ((cdtime_t)    (((double) (us)) * 1073.741824))
-#define CDTIME_T_TO_US(t)  ((suseconds_t) (((double) (t))  / 1073.741824))
-#define NS_TO_CDTIME_T(ns) ((cdtime_t)    (((double) (ns)) * 1.073741824))
-#define CDTIME_T_TO_NS(t)  ((long)        (((double) (t))  / 1.073741824))
-
-#define CDTIME_T_TO_TIMEVAL(cdt,tvp) do {                                    \
-        (tvp)->tv_sec = CDTIME_T_TO_TIME_T (cdt);                            \
-        (tvp)->tv_usec = CDTIME_T_TO_US ((cdt) % 1073741824);                \
-} while (0)
-#define TIMEVAL_TO_CDTIME_T(tv) (TIME_T_TO_CDTIME_T ((tv)->tv_sec)           \
-    + US_TO_CDTIME_T ((tv)->tv_usec))
-
-#define CDTIME_T_TO_TIMESPEC(cdt,tsp) do {                                   \
-  (tsp)->tv_sec = CDTIME_T_TO_TIME_T (cdt);                                  \
-  (tsp)->tv_nsec = CDTIME_T_TO_NS ((cdt) % 1073741824);                      \
-} while (0)
-#define TIMESPEC_TO_CDTIME_T(ts) (TIME_T_TO_CDTIME_T ((ts)->tv_sec)           \
-    + NS_TO_CDTIME_T ((ts)->tv_nsec))
-
-cdtime_t cdtime (void);
-
-/* format a cdtime_t value in ISO 8601 format:
- * returns the number of characters written to the string (not including the
- * terminating null byte or 0 on error; the function ensures that the string
- * is null terminated */
-size_t cdtime_to_iso8601 (char *s, size_t max, cdtime_t t);
-
-#endif /* UTILS_TIME_H */
-/* vim: set sw=2 sts=2 et : */
index 8180d0d9ea60380b3c4705eab4654615ea2c9bf3..75c0206169666da7b693f59880a5603c52ff5a03 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 31787f53250b2ca893827170a8ab868f2a6ea024..1d01ebdf2978a32b924e21fe844c6cc87793c37e 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"),
index bbb3a67fbe24d640029bef0f02cd7823f7bc2eac..6a2676a89e1d8ccee1cddc6735d2f5e7d9335ff7 100644 (file)
@@ -1,6 +1,6 @@
 /**
- * collectd - src/utils_vl_lookup_test.c
- * Copyright (C) 2012  Florian Forster
+ * 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"),
@@ -24,6 +24,7 @@
  *   Florian Forster <octo at collectd.org>
  **/
 
+#include "testing.h"
 #include "collectd.h"
 #include "utils_vl_lookup.h"
 
@@ -46,7 +47,8 @@ static int lookup_obj_callback (data_set_t const *ds,
   identifier_t *class = user_class;
   identifier_t *obj = user_obj;
 
-  assert (expect_new_obj == have_new_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));
@@ -63,7 +65,7 @@ static void *lookup_class_callback (data_set_t const *ds,
   identifier_t *class = user_class;
   identifier_t *obj;
 
-  assert (expect_new_obj);
+  OK(expect_new_obj);
 
   memcpy (&last_class_ident, class, sizeof (last_class_ident));
   
@@ -87,7 +89,6 @@ static void checked_lookup_add (lookup_t *obj, /* {{{ */
 {
   identifier_t ident;
   void *user_class;
-  int status;
 
   memset (&ident, 0, sizeof (ident));
   strncpy (ident.host, host, sizeof (ident.host));
@@ -99,8 +100,7 @@ static void checked_lookup_add (lookup_t *obj, /* {{{ */
   user_class = malloc (sizeof (ident));
   memmove (user_class, &ident, sizeof (ident));
 
-  status = lookup_add (obj, &ident, group_by, user_class);
-  assert (status == 0);
+  OK(lookup_add (obj, &ident, group_by, user_class) == 0);
 } /* }}} void test_add */
 
 static int checked_lookup_search (lookup_t *obj,
@@ -136,11 +136,11 @@ static lookup_t *checked_lookup_create (void)
       lookup_obj_callback,
       (void *) free,
       (void *) free);
-  assert (obj != NULL);
+  OK(obj != NULL);
   return (obj);
 }
 
-static void testcase0 (void)
+DEF_TEST(group_by_specific_host)
 {
   lookup_t *obj = checked_lookup_create ();
 
@@ -155,9 +155,10 @@ static void testcase0 (void)
       /* expect new = */ 0);
 
   lookup_destroy (obj);
+  return (0);
 }
 
-static void testcase1 (void)
+DEF_TEST(group_by_any_host)
 {
   lookup_t *obj = checked_lookup_create ();
 
@@ -180,9 +181,10 @@ static void testcase1 (void)
       /* expect new = */ 0);
 
   lookup_destroy (obj);
+  return (0);
 }
 
-static void testcase2 (void)
+DEF_TEST(multiple_lookups)
 {
   lookup_t *obj = checked_lookup_create ();
   int status;
@@ -204,9 +206,10 @@ static void testcase2 (void)
   assert (status == 2);
 
   lookup_destroy (obj);
+  return (0);
 }
 
-static void testcase3 (void)
+DEF_TEST(regex)
 {
   lookup_t *obj = checked_lookup_create ();
 
@@ -232,13 +235,15 @@ static void testcase3 (void)
       /* expect new = */ 1);
 
   lookup_destroy (obj);
+  return (0);
 }
 
 int main (int argc, char **argv) /* {{{ */
 {
-  testcase0 ();
-  testcase1 ();
-  testcase2 ();
-  testcase3 ();
-  return (EXIT_SUCCESS);
+  RUN_TEST(group_by_specific_host);
+  RUN_TEST(group_by_any_host);
+  RUN_TEST(multiple_lookups);
+  RUN_TEST(regex);
+
+  END_TEST;
 } /* }}} int main */
index 3a8dddd78ac05bbf2633c362dda2f90a350e0d8a..a27f9cf6d3476f3e7ba38ff515d43a4c7a231639 100644 (file)
 #include "plugin.h"
 #include "configfile.h"
 
-#include <varnish/varnishapi.h>
+#if HAVE_VARNISH_V4
+#include <varnish/vapi/vsm.h>
+#include <varnish/vapi/vsc.h>
+typedef struct VSC_C_main c_varnish_stats_t;
+#endif
 
 #if HAVE_VARNISH_V3
-# include <varnish/vsc.h>
+#include <varnish/varnishapi.h>
+#include <varnish/vsc.h>
 typedef struct VSC_C_main c_varnish_stats_t;
 #endif
 
 #if HAVE_VARNISH_V2
+#include <varnish/varnishapi.h>
 typedef struct varnish_stats c_varnish_stats_t;
 #endif
 
@@ -67,11 +73,14 @@ struct user_config_s {
 #endif
        _Bool collect_struct;
        _Bool collect_totals;
-#ifdef HAVE_VARNISH_V3
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
        _Bool collect_uptime;
 #endif
        _Bool collect_vcl;
        _Bool collect_workers;
+#if HAVE_VARNISH_V4
+       _Bool collect_vsm;
+#endif
 };
 typedef struct user_config_s user_config_t; /* }}} */
 
@@ -141,10 +150,12 @@ static void varnish_monitor (const user_config_t *conf, /* {{{ */
 
        if (conf->collect_connections)
        {
+#ifndef HAVE_VARNISH_V4
                /* Client connections accepted */
                varnish_submit_derive (conf->instance, "connections", "connections", "accepted", stats->client_conn);
                /* Connection dropped, no sess */
                varnish_submit_derive (conf->instance, "connections", "connections", "dropped" , stats->client_drop);
+#endif
                /* Client requests received    */
                varnish_submit_derive (conf->instance, "connections", "connections", "received", stats->client_req);
        }
@@ -225,7 +236,7 @@ static void varnish_monitor (const user_config_t *conf, /* {{{ */
                varnish_submit_derive (conf->instance, "fetch", "http_requests", "zero"       , stats->fetch_zero);
                /* Fetch failed              */
                varnish_submit_derive (conf->instance, "fetch", "http_requests", "failed"     , stats->fetch_failed);
-#if HAVE_VARNISH_V3
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
                /* Fetch no body (1xx)       */
                varnish_submit_derive (conf->instance, "fetch", "http_requests", "no_body_1xx", stats->fetch_1xx);
                /* Fetch no body (204)       */
@@ -263,12 +274,17 @@ static void varnish_monitor (const user_config_t *conf, /* {{{ */
 #endif
                /* HTTP header overflows         */
                varnish_submit_derive (conf->instance, "objects", "total_objects", "header_overflow",    stats->losthdr);
+#if HAVE_VARNISH_V4
+               /* N purged objects              */
+               varnish_submit_derive (conf->instance, "objects", "total_objects", "purged",             stats->n_obj_purged);
+#else
                /* Objects sent with sendfile    */
                varnish_submit_derive (conf->instance, "objects", "total_objects", "sent_sendfile",      stats->n_objsendfile);
                /* Objects sent with write       */
                varnish_submit_derive (conf->instance, "objects", "total_objects", "sent_write",         stats->n_objwrite);
                /* Objects overflowing workspace */
                varnish_submit_derive (conf->instance, "objects", "total_objects", "workspace_overflow", stats->n_objoverflow);
+#endif
        }
 
 #if HAVE_VARNISH_V2
@@ -287,7 +303,8 @@ static void varnish_monitor (const user_config_t *conf, /* {{{ */
                /* N duplicate purges removed */
                varnish_submit_derive (conf->instance, "purge", "total_operations", "duplicate",        stats->n_purge_dups);
        }
-#else
+#endif
+#if HAVE_VARNISH_V3
        if (conf->collect_ban)
        {
                /* N total active bans      */
@@ -304,6 +321,27 @@ static void varnish_monitor (const user_config_t *conf, /* {{{ */
                varnish_submit_derive (conf->instance, "ban", "total_operations", "duplicate",      stats->n_ban_dups);
        }
 #endif
+#if HAVE_VARNISH_V4
+       if (conf->collect_ban)
+       {
+               /* N total active bans      */
+               varnish_submit_derive (conf->instance, "ban", "total_operations", "total",          stats->bans);
+               /* N new bans added         */
+               varnish_submit_derive (conf->instance, "ban", "total_operations", "added",          stats->bans_added);
+               /* N bans using obj */
+               varnish_submit_derive (conf->instance, "ban", "total_operations", "obj",            stats->bans_obj);
+               /* N bans using req */
+               varnish_submit_derive (conf->instance, "ban", "total_operations", "req",            stats->bans_req);
+               /* N new bans completed     */
+               varnish_submit_derive (conf->instance, "ban", "total_operations", "completed",      stats->bans_completed);
+               /* N old bans deleted       */
+               varnish_submit_derive (conf->instance, "ban", "total_operations", "deleted",        stats->bans_deleted);
+               /* N objects tested         */
+               varnish_submit_derive (conf->instance, "ban", "total_operations", "tested",         stats->bans_tested);
+               /* N duplicate bans removed */
+               varnish_submit_derive (conf->instance, "ban", "total_operations", "duplicate",      stats->bans_dups);
+       }
+#endif
 
        if (conf->collect_session)
        {
@@ -313,8 +351,21 @@ static void varnish_monitor (const user_config_t *conf, /* {{{ */
                varnish_submit_derive (conf->instance, "session", "total_operations", "pipeline",  stats->sess_pipeline);
                /* Session Read Ahead */
                varnish_submit_derive (conf->instance, "session", "total_operations", "readahead", stats->sess_readahead);
+#if HAVE_VARNISH_V4
+               /* Sessions accepted */
+               varnish_submit_derive (conf->instance, "session", "total_operations", "accepted",  stats->sess_conn);
+               /* Sessions dropped for thread */
+               varnish_submit_derive (conf->instance, "session", "total_operations", "dropped",   stats->sess_drop);
+               /* Sessions accept failure */
+               varnish_submit_derive (conf->instance, "session", "total_operations", "failed",    stats->sess_fail);
+               /* Sessions pipe overflow */
+               varnish_submit_derive (conf->instance, "session", "total_operations", "overflow",  stats->sess_pipe_overflow);
+               /* Sessions queued for thread */
+               varnish_submit_derive (conf->instance, "session", "total_operations", "queued",    stats->sess_queued);
+#else
                /* Session Linger     */
                varnish_submit_derive (conf->instance, "session", "total_operations", "linger",    stats->sess_linger);
+#endif
                /* Session herd       */
                varnish_submit_derive (conf->instance, "session", "total_operations", "herd",      stats->sess_herd);
        }
@@ -377,17 +428,21 @@ static void varnish_monitor (const user_config_t *conf, /* {{{ */
 
        if (conf->collect_struct)
        {
+#if !HAVE_VARNISH_V4
                /* N struct sess_mem       */
                varnish_submit_gauge (conf->instance, "struct", "current_sessions", "sess_mem",  stats->n_sess_mem);
                /* N struct sess           */
                varnish_submit_gauge (conf->instance, "struct", "current_sessions", "sess",      stats->n_sess);
+#endif
                /* N struct object         */
                varnish_submit_gauge (conf->instance, "struct", "objects", "object",             stats->n_object);
-#ifdef HAVE_VARNISH_V3
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
                /* N unresurrected objects */
                varnish_submit_gauge (conf->instance, "struct", "objects", "vampireobject",      stats->n_vampireobject);
                /* N struct objectcore     */
                varnish_submit_gauge (conf->instance, "struct", "objects", "objectcore",         stats->n_objectcore);
+               /* N struct waitinglist    */
+               varnish_submit_gauge (conf->instance, "struct", "objects", "waitinglist",        stats->n_waitinglist);
 #endif
                /* N struct objecthead     */
                varnish_submit_gauge (conf->instance, "struct", "objects", "objecthead",         stats->n_objecthead);
@@ -415,13 +470,40 @@ static void varnish_monitor (const user_config_t *conf, /* {{{ */
                varnish_submit_derive (conf->instance, "totals", "total_operations", "pass",    stats->s_pass);
                /* Total fetch */
                varnish_submit_derive (conf->instance, "totals", "total_operations", "fetches", stats->s_fetch);
+#if HAVE_VARNISH_V4
+               /* Total synth */
+               varnish_submit_derive (conf->instance, "totals", "total_bytes", "synth",       stats->s_synth);
+               /* Request header bytes */
+               varnish_submit_derive (conf->instance, "totals", "total_bytes", "req_header",  stats->s_req_hdrbytes);
+               /* Request body byte */
+               varnish_submit_derive (conf->instance, "totals", "total_bytes", "req_body",    stats->s_req_bodybytes);
+               /* Response header bytes */
+               varnish_submit_derive (conf->instance, "totals", "total_bytes", "resp_header", stats->s_resp_hdrbytes);
+               /* Response body byte */
+               varnish_submit_derive (conf->instance, "totals", "total_bytes", "resp_body",   stats->s_resp_bodybytes);
+               /* Pipe request header bytes */
+               varnish_submit_derive (conf->instance, "totals", "total_bytes", "pipe_header", stats->s_pipe_hdrbytes);
+               /* Piped bytes from client */
+               varnish_submit_derive (conf->instance, "totals", "total_bytes", "pipe_in",     stats->s_pipe_in);
+               /* Piped bytes to client */
+               varnish_submit_derive (conf->instance, "totals", "total_bytes", "pipe_out",    stats->s_pipe_out);
+               /* Number of purge operations */
+               varnish_submit_derive (conf->instance, "totals", "total_operations", "purges", stats->n_purges);
+#else
                /* Total header bytes */
                varnish_submit_derive (conf->instance, "totals", "total_bytes", "header-bytes", stats->s_hdrbytes);
                /* Total body byte */
                varnish_submit_derive (conf->instance, "totals", "total_bytes", "body-bytes",   stats->s_bodybytes);
+#endif
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
+               /* Gzip operations */
+               varnish_submit_derive (conf->instance, "totals", "total_operations", "gzip",    stats->n_gzip);
+               /* Gunzip operations */
+               varnish_submit_derive (conf->instance, "totals", "total_operations", "gunzip",  stats->n_gunzip);
+#endif
        }
 
-#ifdef HAVE_VARNISH_V3
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
        if (conf->collect_uptime)
        {
                /* Client uptime */
@@ -437,10 +519,28 @@ static void varnish_monitor (const user_config_t *conf, /* {{{ */
                varnish_submit_gauge (conf->instance, "vcl", "vcl", "avail_vcl",     stats->n_vcl_avail);
                /* N vcl discarded */
                varnish_submit_gauge (conf->instance, "vcl", "vcl", "discarded_vcl", stats->n_vcl_discard);
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
+               /* Loaded VMODs */
+               varnish_submit_gauge (conf->instance, "vcl", "objects", "vmod",      stats->vmods);
+#endif
        }
 
        if (conf->collect_workers)
        {
+#ifdef HAVE_VARNISH_V4
+               /* total number of threads */
+               varnish_submit_gauge (conf->instance, "workers", "threads", "worker",             stats->threads);
+               /* threads created */
+               varnish_submit_derive (conf->instance, "workers", "total_threads", "created",     stats->threads_created);
+               /* thread creation failed */
+               varnish_submit_derive (conf->instance, "workers", "total_threads", "failed",      stats->threads_failed);
+               /* threads hit max */
+               varnish_submit_derive (conf->instance, "workers", "total_threads", "limited",     stats->threads_limited);
+               /* threads destroyed */
+               varnish_submit_derive (conf->instance, "workers", "total_threads", "dropped",     stats->threads_destroyed);
+               /* length of session queue */
+               varnish_submit_derive (conf->instance, "workers", "queue_length",  "threads",     stats->thread_queue_len);
+#else
                /* worker threads */
                varnish_submit_gauge (conf->instance, "workers", "threads", "worker",             stats->n_wrk);
                /* worker threads created */
@@ -450,22 +550,40 @@ static void varnish_monitor (const user_config_t *conf, /* {{{ */
                /* worker threads limited */
                varnish_submit_derive (conf->instance, "workers", "total_threads", "limited",     stats->n_wrk_max);
                /* dropped work requests */
-               varnish_submit_derive (conf->instance, "workers", "total_requests", "dropped",    stats->n_wrk_drop);
+               varnish_submit_derive (conf->instance, "workers", "total_threads", "dropped",     stats->n_wrk_drop);
 #ifdef HAVE_VARNISH_V2
                /* queued work requests */
                varnish_submit_derive (conf->instance, "workers", "total_requests", "queued",     stats->n_wrk_queue);
                /* overflowed work requests */
                varnish_submit_derive (conf->instance, "workers", "total_requests", "overflowed", stats->n_wrk_overflow);
-#else
+#else /* HAVE_VARNISH_V3 */
                /* queued work requests */
                varnish_submit_derive (conf->instance, "workers", "total_requests", "queued",       stats->n_wrk_queued);
                /* work request queue length */
                varnish_submit_derive (conf->instance, "workers", "total_requests", "queue_length", stats->n_wrk_lqueue);
+#endif
 #endif
        }
+
+#if HAVE_VARNISH_V4
+       if (conf->collect_vsm)
+       {
+               /* Free VSM space */
+               varnish_submit_gauge (conf->instance, "vsm", "bytes", "free",              stats->vsm_free);
+               /* Used VSM space */
+               varnish_submit_gauge (conf->instance, "vsm", "bytes", "used",              stats->vsm_used);
+               /* Cooling VSM space */
+               varnish_submit_gauge (conf->instance, "vsm", "bytes", "cooling",           stats->vsm_cooling);
+               /* Overflow VSM space */
+               varnish_submit_gauge (conf->instance, "vsm", "bytes", "overflow",          stats->vsm_overflow);
+               /* Total overflowed VSM space */
+               varnish_submit_derive (conf->instance, "vsm", "total_bytes", "overflowed", stats->vsm_overflowed);
+       }
+#endif
+
 } /* }}} void varnish_monitor */
 
-#if HAVE_VARNISH_V3
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
 static int varnish_read (user_data_t *ud) /* {{{ */
 {
        struct VSM_data *vd;
@@ -479,7 +597,9 @@ static int varnish_read (user_data_t *ud) /* {{{ */
        conf = ud->data;
 
        vd = VSM_New();
+#if HAVE_VARNISH_V3
        VSC_Setup(vd);
+#endif
 
        if (conf->instance != NULL)
        {
@@ -488,6 +608,7 @@ static int varnish_read (user_data_t *ud) /* {{{ */
                status = VSM_n_Arg (vd, conf->instance);
                if (status < 0)
                {
+                       VSM_Delete (vd);
                        ERROR ("varnish plugin: VSM_n_Arg (\"%s\") failed "
                                        "with status %i.",
                                        conf->instance, status);
@@ -495,17 +616,34 @@ static int varnish_read (user_data_t *ud) /* {{{ */
                }
        }
 
+#if HAVE_VARNISH_V3
        if (VSC_Open (vd, /* diag = */ 1))
+#else /* if HAVE_VARNISH_V4 */
+       if (VSM_Open (vd))
+#endif
        {
-               ERROR ("varnish plugin: Unable to load statistics.");
+               VSM_Delete (vd);
+               ERROR ("varnish plugin: Unable to open connection.");
 
                return (-1);
        }
 
+#if HAVE_VARNISH_V3
        stats = VSC_Main(vd);
+#else /* if HAVE_VARNISH_V4 */
+       stats = VSC_Main(vd, NULL);
+#endif
+       if (!stats)
+       {
+               VSM_Delete (vd);
+               ERROR ("varnish plugin: Unable to get statistics.");
+
+               return (-1);
+       }
+
 
        varnish_monitor (conf, stats);
-       VSM_Close (vd);
+       VSM_Delete (vd);
 
        return (0);
 } /* }}} */
@@ -575,11 +713,14 @@ static int varnish_config_apply_default (user_config_t *conf) /* {{{ */
        conf->collect_sms         = 0;
        conf->collect_struct      = 0;
        conf->collect_totals      = 0;
-#ifdef HAVE_VARNISH_V3
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
        conf->collect_uptime      = 0;
 #endif
        conf->collect_vcl         = 0;
        conf->collect_workers     = 0;
+#if HAVE_VARNISH_V4
+       conf->collect_vsm         = 0;
+#endif
 
        return (0);
 } /* }}} int varnish_config_apply_default */
@@ -699,7 +840,7 @@ static int varnish_config_instance (const oconfig_item_t *ci) /* {{{ */
                        cf_util_get_boolean (child, &conf->collect_struct);
                else if (strcasecmp ("CollectTotals", child->key) == 0)
                        cf_util_get_boolean (child, &conf->collect_totals);
-#ifdef HAVE_VARNISH_V3
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
                else if (strcasecmp ("CollectUptime", child->key) == 0)
                        cf_util_get_boolean (child, &conf->collect_uptime);
 #endif
@@ -707,6 +848,10 @@ static int varnish_config_instance (const oconfig_item_t *ci) /* {{{ */
                        cf_util_get_boolean (child, &conf->collect_vcl);
                else if (strcasecmp ("CollectWorkers", child->key) == 0)
                        cf_util_get_boolean (child, &conf->collect_workers);
+#if HAVE_VARNISH_V4
+               else if (strcasecmp ("CollectVSM", child->key) == 0)
+                       cf_util_get_boolean (child, &conf->collect_vsm);
+#endif
                else
                {
                        WARNING ("Varnish plugin: Ignoring unknown "
@@ -741,11 +886,15 @@ static int varnish_config_instance (const oconfig_item_t *ci) /* {{{ */
 #endif
                        && !conf->collect_struct
                        && !conf->collect_totals
-#ifdef HAVE_VARNISH_V3
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
                        && !conf->collect_uptime
 #endif
                        && !conf->collect_vcl
-                       && !conf->collect_workers)
+                       && !conf->collect_workers
+#if HAVE_VARNISH_V4
+                       && !conf->collect_vsm
+#endif
+       )
        {
                WARNING ("Varnish plugin: No metric has been configured for "
                                "instance \"%s\". Disabling this instance.",
diff --git a/src/virt.c b/src/virt.c
new file mode 100644 (file)
index 0000000..dff8f71
--- /dev/null
@@ -0,0 +1,1016 @@
+/**
+ * collectd - src/virt.c
+ * Copyright (C) 2006-2008  Red Hat 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
+ *
+ * Authors:
+ *   Richard W.M. Jones <rjones@redhat.com>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+#include "configfile.h"
+#include "utils_ignorelist.h"
+#include "utils_complain.h"
+
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xpath.h>
+
+/* Plugin name */
+#define PLUGIN_NAME "virt"
+
+static const char *config_keys[] = {
+    "Connection",
+
+    "RefreshInterval",
+
+    "Domain",
+    "BlockDevice",
+    "InterfaceDevice",
+    "IgnoreSelected",
+
+    "HostnameFormat",
+    "InterfaceFormat",
+
+    "PluginInstanceFormat",
+
+    NULL
+};
+#define NR_CONFIG_KEYS ((sizeof config_keys / sizeof config_keys[0]) - 1)
+
+/* Connection. */
+static virConnectPtr conn = 0;
+static char *conn_string = NULL;
+static c_complain_t conn_complain = C_COMPLAIN_INIT_STATIC;
+
+/* Seconds between list refreshes, 0 disables completely. */
+static int interval = 60;
+
+/* List of domains, if specified. */
+static ignorelist_t *il_domains = NULL;
+/* List of block devices, if specified. */
+static ignorelist_t *il_block_devices = NULL;
+/* List of network interface devices, if specified. */
+static ignorelist_t *il_interface_devices = NULL;
+
+static int ignore_device_match (ignorelist_t *,
+                                const char *domname, const char *devpath);
+
+/* Actual list of domains found on last refresh. */
+static virDomainPtr *domains = NULL;
+static int nr_domains = 0;
+
+static void free_domains (void);
+static int add_domain (virDomainPtr dom);
+
+/* Actual list of block devices found on last refresh. */
+struct block_device {
+    virDomainPtr dom;           /* domain */
+    char *path;                 /* name of block device */
+};
+
+static struct block_device *block_devices = NULL;
+static int nr_block_devices = 0;
+
+static void free_block_devices (void);
+static int add_block_device (virDomainPtr dom, const char *path);
+
+/* Actual list of network interfaces found on last refresh. */
+struct interface_device {
+    virDomainPtr dom;           /* domain */
+    char *path;                 /* name of interface device */
+    char *address;              /* mac address of interface device */
+    char *number;               /* interface device number */
+};
+
+static struct interface_device *interface_devices = NULL;
+static int nr_interface_devices = 0;
+
+static void free_interface_devices (void);
+static int add_interface_device (virDomainPtr dom, const char *path, const char *address, unsigned int number);
+
+/* HostnameFormat. */
+#define HF_MAX_FIELDS 3
+
+enum hf_field {
+    hf_none = 0,
+    hf_hostname,
+    hf_name,
+    hf_uuid
+};
+
+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,
+    if_name,
+    if_number
+};
+
+static enum if_field interface_format = if_name;
+
+/* Time that we last refreshed. */
+static time_t last_refresh = (time_t) 0;
+
+static int refresh_lists (void);
+
+/* ERROR(...) macro for virterrors. */
+#define VIRT_ERROR(conn,s) do {                 \
+        virErrorPtr err;                        \
+        err = (conn) ? virConnGetLastError ((conn)) : virGetLastError (); \
+        if (err) ERROR ("%s: %s", (s), err->message);                   \
+    } while(0)
+
+static void
+init_value_list (value_list_t *vl, virDomainPtr dom)
+{
+    int i, n;
+    const char *name;
+    char uuid[VIR_UUID_STRING_BUFLEN];
+
+    sstrncpy (vl->plugin, PLUGIN_NAME, sizeof (vl->plugin));
+
+    vl->host[0] = '\0';
+
+    /* Construct the hostname field according to HostnameFormat. */
+    for (i = 0; i < HF_MAX_FIELDS; ++i) {
+        if (hostname_format[i] == hf_none)
+            continue;
+
+        n = DATA_MAX_NAME_LEN - strlen (vl->host) - 2;
+
+        if (i > 0 && n >= 1) {
+            strncat (vl->host, ":", 1);
+            n--;
+        }
+
+        switch (hostname_format[i]) {
+        case hf_none: break;
+        case hf_hostname:
+            strncat (vl->host, hostname_g, n);
+            break;
+        case hf_name:
+            name = virDomainGetName (dom);
+            if (name)
+                strncat (vl->host, name, n);
+            break;
+        case hf_uuid:
+            if (virDomainGetUUIDString (dom, uuid) == 0)
+                strncat (vl->host, uuid, n);
+            break;
+        }
+    }
+
+    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
+memory_submit (gauge_t memory, virDomainPtr dom)
+{
+    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, "total", sizeof (vl.type_instance));
+
+    plugin_dispatch_values (&vl);
+}
+
+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)
+{
+    value_t values[1];
+    value_list_t vl = VALUE_LIST_INIT;
+
+    init_value_list (&vl, dom);
+
+    values[0].derive = cpu_time;
+
+    vl.values = values;
+    vl.values_len = 1;
+
+    sstrncpy (vl.type, type, sizeof (vl.type));
+
+    plugin_dispatch_values (&vl);
+}
+
+static void
+vcpu_submit (derive_t cpu_time,
+             virDomainPtr dom, int vcpu_nr, const char *type)
+{
+    value_t values[1];
+    value_list_t vl = VALUE_LIST_INIT;
+
+    init_value_list (&vl, dom);
+
+    values[0].derive = cpu_time;
+    vl.values = values;
+    vl.values_len = 1;
+
+    sstrncpy (vl.type, type, sizeof (vl.type));
+    ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%d", vcpu_nr);
+
+    plugin_dispatch_values (&vl);
+}
+
+static void
+submit_derive2 (const char *type, derive_t v0, derive_t v1,
+             virDomainPtr dom, const char *devname)
+{
+    value_t values[2];
+    value_list_t vl = VALUE_LIST_INIT;
+
+    init_value_list (&vl, dom);
+
+    values[0].derive = v0;
+    values[1].derive = v1;
+    vl.values = values;
+    vl.values_len = 2;
+
+    sstrncpy (vl.type, type, sizeof (vl.type));
+    sstrncpy (vl.type_instance, devname, sizeof (vl.type_instance));
+
+    plugin_dispatch_values (&vl);
+} /* void submit_derive2 */
+
+static int
+lv_init (void)
+{
+    if (virInitialize () != 0)
+        return -1;
+
+       return 0;
+}
+
+static int
+lv_config (const char *key, const char *value)
+{
+    if (virInitialize () != 0)
+        return 1;
+
+    if (il_domains == NULL)
+        il_domains = ignorelist_create (1);
+    if (il_block_devices == NULL)
+        il_block_devices = ignorelist_create (1);
+    if (il_interface_devices == NULL)
+        il_interface_devices = ignorelist_create (1);
+
+    if (strcasecmp (key, "Connection") == 0) {
+        char *tmp = strdup (value);
+        if (tmp == NULL) {
+            ERROR (PLUGIN_NAME " plugin: Connection strdup failed.");
+            return 1;
+        }
+        sfree (conn_string);
+        conn_string = tmp;
+        return 0;
+    }
+
+    if (strcasecmp (key, "RefreshInterval") == 0) {
+        char *eptr = NULL;
+        interval = strtol (value, &eptr, 10);
+        if (eptr == NULL || *eptr != '\0') return 1;
+        return 0;
+    }
+
+    if (strcasecmp (key, "Domain") == 0) {
+        if (ignorelist_add (il_domains, value)) return 1;
+        return 0;
+    }
+    if (strcasecmp (key, "BlockDevice") == 0) {
+        if (ignorelist_add (il_block_devices, value)) return 1;
+        return 0;
+    }
+    if (strcasecmp (key, "InterfaceDevice") == 0) {
+        if (ignorelist_add (il_interface_devices, value)) return 1;
+        return 0;
+    }
+
+    if (strcasecmp (key, "IgnoreSelected") == 0) {
+        if (IS_TRUE (value))
+        {
+            ignorelist_set_invert (il_domains, 0);
+            ignorelist_set_invert (il_block_devices, 0);
+            ignorelist_set_invert (il_interface_devices, 0);
+        }
+        else
+        {
+            ignorelist_set_invert (il_domains, 1);
+            ignorelist_set_invert (il_block_devices, 1);
+            ignorelist_set_invert (il_interface_devices, 1);
+        }
+        return 0;
+    }
+
+    if (strcasecmp (key, "HostnameFormat") == 0) {
+        char *value_copy;
+        char *fields[HF_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, HF_MAX_FIELDS);
+        if (n < 1) {
+            sfree (value_copy);
+            ERROR (PLUGIN_NAME " plugin: HostnameFormat: no fields");
+            return -1;
+        }
+
+        for (i = 0; i < n; ++i) {
+            if (strcasecmp (fields[i], "hostname") == 0)
+                hostname_format[i] = hf_hostname;
+            else if (strcasecmp (fields[i], "name") == 0)
+                hostname_format[i] = hf_name;
+            else if (strcasecmp (fields[i], "uuid") == 0)
+                hostname_format[i] = hf_uuid;
+            else {
+                sfree (value_copy);
+                ERROR (PLUGIN_NAME " plugin: unknown HostnameFormat field: %s", fields[i]);
+                return -1;
+            }
+        }
+        sfree (value_copy);
+
+        for (i = n; i < HF_MAX_FIELDS; ++i)
+            hostname_format[i] = hf_none;
+
+        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;
+        else if (strcasecmp (value, "address") == 0)
+            interface_format = if_address;
+        else if (strcasecmp (value, "number") == 0)
+            interface_format = if_number;
+        else {
+            ERROR (PLUGIN_NAME " plugin: unknown InterfaceFormat: %s", value);
+            return -1;
+        }
+        return 0;
+    }
+
+    /* Unrecognised option. */
+    return -1;
+}
+
+static int
+lv_read (void)
+{
+    time_t t;
+    int i;
+
+    if (conn == NULL) {
+        /* `conn_string == NULL' is acceptable. */
+        conn = virConnectOpenReadOnly (conn_string);
+        if (conn == NULL) {
+            c_complain (LOG_ERR, &conn_complain,
+                    PLUGIN_NAME " plugin: Unable to connect: "
+                    "virConnectOpenReadOnly failed.");
+            return -1;
+        }
+    }
+    c_release (LOG_NOTICE, &conn_complain,
+            PLUGIN_NAME " plugin: Connection established.");
+
+    time (&t);
+
+    /* Need to refresh domain or device lists? */
+    if ((last_refresh == (time_t) 0) ||
+            ((interval > 0) && ((last_refresh + interval) <= t))) {
+        if (refresh_lists () != 0) {
+            if (conn != NULL)
+                virConnectClose (conn);
+            conn = NULL;
+            return -1;
+        }
+        last_refresh = t;
+    }
+
+#if 0
+    for (i = 0; i < nr_domains; ++i)
+        fprintf (stderr, "domain %s\n", virDomainGetName (domains[i]));
+    for (i = 0; i < nr_block_devices; ++i)
+        fprintf  (stderr, "block device %d %s:%s\n",
+                  i, virDomainGetName (block_devices[i].dom),
+                  block_devices[i].path);
+    for (i = 0; i < nr_interface_devices; ++i)
+        fprintf (stderr, "interface device %d %s:%s\n",
+                 i, virDomainGetName (interface_devices[i].dom),
+                 interface_devices[i].path);
+#endif
+
+    /* Get CPU usage, memory, VCPU usage for each domain. */
+    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 (PLUGIN_NAME " plugin: virDomainGetInfo failed with status %i.",
+                    status);
+            continue;
+        }
+
+        if (info.state != VIR_DOMAIN_RUNNING)
+        {
+            /* only gather stats for running domains */
+            continue;
+        }
+
+        cpu_submit (info.cpuTime, domains[i], "virt_cpu_total");
+        memory_submit ((gauge_t) info.memory * 1024, domains[i]);
+
+        vinfo = malloc (info.nrVirtCpu * sizeof (vinfo[0]));
+        if (vinfo == NULL) {
+            ERROR (PLUGIN_NAME " plugin: malloc failed.");
+            continue;
+        }
+
+        status = virDomainGetVcpus (domains[i], vinfo, info.nrVirtCpu,
+                /* cpu map = */ NULL, /* cpu map length = */ 0);
+        if (status < 0)
+        {
+            ERROR (PLUGIN_NAME " plugin: virDomainGetVcpus failed with status %i.",
+                    status);
+            sfree (vinfo);
+            continue;
+        }
+
+        for (j = 0; j < info.nrVirtCpu; ++j)
+            vcpu_submit (vinfo[j].cpuTime,
+                    domains[i], vinfo[j].number, "virt_vcpu");
+
+        sfree (vinfo);
+
+        minfo = malloc (VIR_DOMAIN_MEMORY_STAT_NR * sizeof (virDomainMemoryStatStruct));
+        if (minfo == NULL) {
+            ERROR ("virt plugin: malloc failed.");
+            continue;
+        }
+
+        status =  virDomainMemoryStats (domains[i], minfo, VIR_DOMAIN_MEMORY_STAT_NR, 0);
+
+        if (status < 0) {
+            ERROR ("virt plugin: virDomainMemoryStats failed with status %i.",
+                    status);
+            sfree (minfo);
+            continue;
+        }
+
+        for (j = 0; j < status; j++) {
+            memory_stats_submit ((gauge_t) minfo[j].val * 1024, 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;
+
+        if (virDomainBlockStats (block_devices[i].dom, block_devices[i].path,
+                    &stats, sizeof stats) != 0)
+            continue;
+
+        if ((stats.rd_req != -1) && (stats.wr_req != -1))
+            submit_derive2 ("disk_ops",
+                    (derive_t) stats.rd_req, (derive_t) stats.wr_req,
+                    block_devices[i].dom, block_devices[i].path);
+
+        if ((stats.rd_bytes != -1) && (stats.wr_bytes != -1))
+            submit_derive2 ("disk_octets",
+                    (derive_t) stats.rd_bytes, (derive_t) stats.wr_bytes,
+                    block_devices[i].dom, block_devices[i].path);
+    } /* for (nr_block_devices) */
+
+    /* Get interface stats for each domain. */
+    for (i = 0; i < nr_interface_devices; ++i) {
+        struct _virDomainInterfaceStats stats;
+        char *display_name = NULL;
+
+
+        switch (interface_format) {
+            case if_address:
+                display_name = interface_devices[i].address;
+                break;
+            case if_number:
+                display_name = interface_devices[i].number;
+                break;
+            case if_name:
+            default:
+                display_name = interface_devices[i].path;
+        }
+
+        if (virDomainInterfaceStats (interface_devices[i].dom,
+                    interface_devices[i].path,
+                    &stats, sizeof stats) != 0)
+            continue;
+
+       if ((stats.rx_bytes != -1) && (stats.tx_bytes != -1))
+           submit_derive2 ("if_octets",
+                   (derive_t) stats.rx_bytes, (derive_t) stats.tx_bytes,
+                   interface_devices[i].dom, display_name);
+
+       if ((stats.rx_packets != -1) && (stats.tx_packets != -1))
+           submit_derive2 ("if_packets",
+                   (derive_t) stats.rx_packets, (derive_t) stats.tx_packets,
+                   interface_devices[i].dom, display_name);
+
+       if ((stats.rx_errs != -1) && (stats.tx_errs != -1))
+           submit_derive2 ("if_errors",
+                   (derive_t) stats.rx_errs, (derive_t) stats.tx_errs,
+                   interface_devices[i].dom, display_name);
+
+       if ((stats.rx_drop != -1) && (stats.tx_drop != -1))
+           submit_derive2 ("if_dropped",
+                   (derive_t) stats.rx_drop, (derive_t) stats.tx_drop,
+                   interface_devices[i].dom, display_name);
+    } /* for (nr_interface_devices) */
+
+    return 0;
+}
+
+static int
+refresh_lists (void)
+{
+    int n;
+
+    n = virConnectNumOfDomains (conn);
+    if (n < 0) {
+        VIRT_ERROR (conn, "reading number of domains");
+        return -1;
+    }
+
+    if (n > 0) {
+        int i;
+        int *domids;
+
+        /* Get list of domains. */
+        domids = malloc (sizeof (int) * n);
+        if (domids == 0) {
+            ERROR (PLUGIN_NAME " plugin: malloc failed.");
+            return -1;
+        }
+
+        n = virConnectListDomains (conn, domids, n);
+        if (n < 0) {
+            VIRT_ERROR (conn, "reading list of domains");
+            sfree (domids);
+            return -1;
+        }
+
+        free_block_devices ();
+        free_interface_devices ();
+        free_domains ();
+
+        /* Fetch each domain and add it to the list, unless ignore. */
+        for (i = 0; i < n; ++i) {
+            virDomainPtr dom = NULL;
+            const char *name;
+            char *xml = NULL;
+            xmlDocPtr xml_doc = NULL;
+            xmlXPathContextPtr xpath_ctx = NULL;
+            xmlXPathObjectPtr xpath_obj = NULL;
+            int j;
+
+            dom = virDomainLookupByID (conn, domids[i]);
+            if (dom == NULL) {
+                VIRT_ERROR (conn, "virDomainLookupByID");
+                /* Could be that the domain went away -- ignore it anyway. */
+                continue;
+            }
+
+            name = virDomainGetName (dom);
+            if (name == NULL) {
+                VIRT_ERROR (conn, "virDomainGetName");
+                goto cont;
+            }
+
+            if (il_domains && ignorelist_match (il_domains, name) != 0)
+                goto cont;
+
+            if (add_domain (dom) < 0) {
+                ERROR (PLUGIN_NAME " plugin: malloc failed.");
+                goto cont;
+            }
+
+            /* Get a list of devices for this domain. */
+            xml = virDomainGetXMLDesc (dom, 0);
+            if (!xml) {
+                VIRT_ERROR (conn, "virDomainGetXMLDesc");
+                goto cont;
+            }
+
+            /* Yuck, XML.  Parse out the devices. */
+            xml_doc = xmlReadDoc ((xmlChar *) xml, NULL, NULL, XML_PARSE_NONET);
+            if (xml_doc == NULL) {
+                VIRT_ERROR (conn, "xmlReadDoc");
+                goto cont;
+            }
+
+            xpath_ctx = xmlXPathNewContext (xml_doc);
+
+            /* Block devices. */
+            xpath_obj = xmlXPathEval
+                ((xmlChar *) "/domain/devices/disk/target[@dev]",
+                 xpath_ctx);
+            if (xpath_obj == NULL || xpath_obj->type != XPATH_NODESET ||
+                xpath_obj->nodesetval == NULL)
+                goto cont;
+
+            for (j = 0; j < xpath_obj->nodesetval->nodeNr; ++j) {
+                xmlNodePtr node;
+                char *path = NULL;
+
+                node = xpath_obj->nodesetval->nodeTab[j];
+                if (!node) continue;
+                path = (char *) xmlGetProp (node, (xmlChar *) "dev");
+                if (!path) continue;
+
+                if (il_block_devices &&
+                    ignore_device_match (il_block_devices, name, path) != 0)
+                    goto cont2;
+
+                add_block_device (dom, path);
+            cont2:
+                if (path) xmlFree (path);
+            }
+            xmlXPathFreeObject (xpath_obj);
+
+            /* Network interfaces. */
+            xpath_obj = xmlXPathEval
+                ((xmlChar *) "/domain/devices/interface[target[@dev]]",
+                 xpath_ctx);
+            if (xpath_obj == NULL || xpath_obj->type != XPATH_NODESET ||
+                xpath_obj->nodesetval == NULL)
+                goto cont;
+
+            xmlNodeSetPtr xml_interfaces = xpath_obj->nodesetval;
+
+            for (j = 0; j < xml_interfaces->nodeNr; ++j) {
+                char *path = NULL;
+                char *address = NULL;
+                xmlNodePtr xml_interface;
+
+                xml_interface = xml_interfaces->nodeTab[j];
+                if (!xml_interface) continue;
+                xmlNodePtr child = NULL;
+
+                for (child = xml_interface->children; child; child = child->next) {
+                    if (child->type != XML_ELEMENT_NODE) continue;
+
+                    if (xmlStrEqual(child->name, (const xmlChar *) "target")) {
+                        path = (char *) xmlGetProp (child, (const xmlChar *) "dev");
+                        if (!path) continue;
+                    } else if (xmlStrEqual(child->name, (const xmlChar *) "mac")) {
+                        address = (char *) xmlGetProp (child, (const xmlChar *) "address");
+                        if (!address) continue;
+                    }
+                }
+
+                if (il_interface_devices &&
+                    (ignore_device_match (il_interface_devices, name, path) != 0 ||
+                     ignore_device_match (il_interface_devices, name, address) != 0))
+                    goto cont3;
+
+                add_interface_device (dom, path, address, j+1);
+                cont3:
+                    if (path) xmlFree (path);
+                    if (address) xmlFree (address);
+            }
+
+        cont:
+            if (xpath_obj) xmlXPathFreeObject (xpath_obj);
+            if (xpath_ctx) xmlXPathFreeContext (xpath_ctx);
+            if (xml_doc) xmlFreeDoc (xml_doc);
+            sfree (xml);
+        }
+
+        sfree (domids);
+    }
+
+    return 0;
+}
+
+static void
+free_domains ()
+{
+    int i;
+
+    if (domains) {
+        for (i = 0; i < nr_domains; ++i)
+            virDomainFree (domains[i]);
+        sfree (domains);
+    }
+    domains = NULL;
+    nr_domains = 0;
+}
+
+static int
+add_domain (virDomainPtr dom)
+{
+    virDomainPtr *new_ptr;
+    int new_size = sizeof (domains[0]) * (nr_domains+1);
+
+    if (domains)
+        new_ptr = realloc (domains, new_size);
+    else
+        new_ptr = malloc (new_size);
+
+    if (new_ptr == NULL)
+        return -1;
+
+    domains = new_ptr;
+    domains[nr_domains] = dom;
+    return nr_domains++;
+}
+
+static void
+free_block_devices ()
+{
+    int i;
+
+    if (block_devices) {
+        for (i = 0; i < nr_block_devices; ++i)
+            sfree (block_devices[i].path);
+        sfree (block_devices);
+    }
+    block_devices = NULL;
+    nr_block_devices = 0;
+}
+
+static int
+add_block_device (virDomainPtr dom, const char *path)
+{
+    struct block_device *new_ptr;
+    int new_size = sizeof (block_devices[0]) * (nr_block_devices+1);
+    char *path_copy;
+
+    path_copy = strdup (path);
+    if (!path_copy)
+        return -1;
+
+    if (block_devices)
+        new_ptr = realloc (block_devices, new_size);
+    else
+        new_ptr = malloc (new_size);
+
+    if (new_ptr == NULL) {
+        sfree (path_copy);
+        return -1;
+    }
+    block_devices = new_ptr;
+    block_devices[nr_block_devices].dom = dom;
+    block_devices[nr_block_devices].path = path_copy;
+    return nr_block_devices++;
+}
+
+static void
+free_interface_devices ()
+{
+    int i;
+
+    if (interface_devices) {
+        for (i = 0; i < nr_interface_devices; ++i) {
+            sfree (interface_devices[i].path);
+            sfree (interface_devices[i].address);
+            sfree (interface_devices[i].number);
+        }
+        sfree (interface_devices);
+    }
+    interface_devices = NULL;
+    nr_interface_devices = 0;
+}
+
+static int
+add_interface_device (virDomainPtr dom, const char *path, const char *address, unsigned int number)
+{
+    struct interface_device *new_ptr;
+    int new_size = sizeof (interface_devices[0]) * (nr_interface_devices+1);
+    char *path_copy, *address_copy, number_string[15];
+
+    if ((path == NULL) || (address == NULL))
+        return EINVAL;
+
+    path_copy = strdup (path);
+    if (!path_copy) return -1;
+
+    address_copy = strdup (address);
+    if (!address_copy) {
+        sfree(path_copy);
+        return -1;
+    }
+
+    snprintf(number_string, sizeof (number_string), "interface-%u", number);
+
+    if (interface_devices)
+        new_ptr = realloc (interface_devices, new_size);
+    else
+        new_ptr = malloc (new_size);
+
+    if (new_ptr == NULL) {
+        sfree (path_copy);
+        sfree (address_copy);
+        return -1;
+    }
+    interface_devices = new_ptr;
+    interface_devices[nr_interface_devices].dom = dom;
+    interface_devices[nr_interface_devices].path = path_copy;
+    interface_devices[nr_interface_devices].address = address_copy;
+    interface_devices[nr_interface_devices].number = strdup(number_string);
+    return nr_interface_devices++;
+}
+
+static int
+ignore_device_match (ignorelist_t *il, const char *domname, const char *devpath)
+{
+    char *name;
+    int n, r;
+
+    if ((domname == NULL) || (devpath == NULL))
+        return 0;
+
+    n = sizeof (char) * (strlen (domname) + strlen (devpath) + 2);
+    name = malloc (n);
+    if (name == NULL) {
+        ERROR (PLUGIN_NAME " plugin: malloc failed.");
+        return 0;
+    }
+    ssnprintf (name, n, "%s:%s", domname, devpath);
+    r = ignorelist_match (il, name);
+    sfree (name);
+    return r;
+}
+
+static int
+lv_shutdown (void)
+{
+    free_block_devices ();
+    free_interface_devices ();
+    free_domains ();
+
+    if (conn != NULL)
+        virConnectClose (conn);
+    conn = NULL;
+
+    ignorelist_free (il_domains);
+    il_domains = NULL;
+    ignorelist_free (il_block_devices);
+    il_block_devices = NULL;
+    ignorelist_free (il_interface_devices);
+    il_interface_devices = NULL;
+
+    return 0;
+}
+
+void
+module_register (void)
+{
+    plugin_register_config (PLUGIN_NAME,
+    lv_config,
+    config_keys, NR_CONFIG_KEYS);
+    plugin_register_init (PLUGIN_NAME, lv_init);
+    plugin_register_read (PLUGIN_NAME, lv_read);
+    plugin_register_shutdown (PLUGIN_NAME, lv_shutdown);
+}
+
+/*
+ * vim: shiftwidth=4 tabstop=8 softtabstop=4 expandtab fdm=marker
+ */
index b8febcecf748de0ec86030639a990f2eb0edb521..5e609e67e26fc3b108b32c7151cae023bc175289 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 d80717cd3349e6a684e977375604209e7d05b775..bd2e867384870ef7212af60d88d678b21bdd3db5 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 f7ba735d37687356d16d3d7bd5b3ff230736563d..f2a3cf5832de46792371fbc2ff499ac42efaa114 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 504ea9d45fa2e55534e1fdc62fec4a0aab01db73..41451a8cee8f8d0bab4dda5d81361b3efd30a229 100644 (file)
@@ -49,7 +49,6 @@
 
 #include "utils_cache.h"
 #include "utils_complain.h"
-#include "utils_parse_option.h"
 #include "utils_format_graphite.h"
 
 /* Folks without pthread will need to disable this plugin. */
 # define WG_SEND_BUF_SIZE 1428
 #endif
 
+#ifndef WG_MIN_RECONNECT_INTERVAL
+# define WG_MIN_RECONNECT_INTERVAL TIME_T_TO_CDTIME_T (1)
+#endif
+
 /*
  * Private variables
  */
@@ -109,6 +112,7 @@ struct wg_callback
 
     pthread_mutex_t send_lock;
     c_complain_t init_complaint;
+    cdtime_t last_connect_time;
 };
 
 
@@ -186,6 +190,7 @@ static int wg_callback_init (struct wg_callback *cb)
     struct addrinfo ai_hints;
     struct addrinfo *ai_list;
     struct addrinfo *ai_ptr;
+    cdtime_t now;
     int status;
 
     const char *node = cb->node ? cb->node : WG_DEFAULT_NODE;
@@ -197,6 +202,13 @@ static int wg_callback_init (struct wg_callback *cb)
     if (cb->sock_fd > 0)
         return (0);
 
+    /* Don't try to reconnect too often. By default, one reconnection attempt
+     * is made per second. */
+    now = cdtime ();
+    if ((now - cb->last_connect_time) < WG_MIN_RECONNECT_INTERVAL)
+        return (EAGAIN);
+    cb->last_connect_time = now;
+
     memset (&ai_hints, 0, sizeof (ai_hints));
 #ifdef AI_ADDRCONFIG
     ai_hints.ai_flags |= AI_ADDRCONFIG;
index bfb5524c936c699f3545640f7f6d0d17ce9b615b..ed596bbf56b9e9ee88becd425126951a4591fb91 100644 (file)
@@ -2,7 +2,7 @@
  * collectd - src/write_http.c
  * Copyright (C) 2009       Paul Sadauskas
  * Copyright (C) 2009       Doug MacEachern
- * Copyright (C) 2007-2009  Florian octo Forster
+ * Copyright (C) 2007-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
@@ -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>
  **/
@@ -27,7 +27,6 @@
 #include "plugin.h"
 #include "common.h"
 #include "utils_cache.h"
-#include "utils_parse_option.h"
 #include "utils_format_json.h"
 
 #if HAVE_PTHREAD_H
 
 #include <curl/curl.h>
 
+#ifndef WRITE_HTTP_DEFAULT_BUFFER_SIZE
+# define WRITE_HTTP_DEFAULT_BUFFER_SIZE 4096
+#endif
+
 /*
  * Private variables
  */
 struct wh_callback_s
 {
-        char *location;
+        char *name;
 
+        char *location;
         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;
+        int   low_speed_limit;
+        time_t low_speed_time;
+        int timeout;
 
 #define WH_FORMAT_COMMAND 0
 #define WH_FORMAT_JSON    1
@@ -58,7 +70,8 @@ struct wh_callback_s
         CURL *curl;
         char curl_errbuf[CURL_ERROR_SIZE];
 
-        char   send_buffer[4096];
+        char  *send_buffer;
+        size_t send_buffer_size;
         size_t send_buffer_free;
         size_t send_buffer_fill;
         cdtime_t send_buffer_init_time;
@@ -69,8 +82,8 @@ typedef struct wh_callback_s wh_callback_t;
 
 static void wh_reset_buffer (wh_callback_t *cb)  /* {{{ */
 {
-        memset (cb->send_buffer, 0, sizeof (cb->send_buffer));
-        cb->send_buffer_free = sizeof (cb->send_buffer);
+        memset (cb->send_buffer, 0, cb->send_buffer_size);
+        cb->send_buffer_free = cb->send_buffer_size;
         cb->send_buffer_fill = 0;
         cb->send_buffer_init_time = cdtime ();
 
@@ -111,8 +124,21 @@ static int wh_callback_init (wh_callback_t *cb) /* {{{ */
                 return (-1);
         }
 
+        if (cb->low_speed_limit > 0 && cb->low_speed_time > 0)
+        {
+                curl_easy_setopt (cb->curl, CURLOPT_LOW_SPEED_LIMIT,
+                                  (long) (cb->low_speed_limit * cb->low_speed_time));
+                curl_easy_setopt (cb->curl, CURLOPT_LOW_SPEED_TIME,
+                                  (long) cb->low_speed_time);
+        }
+
+#ifdef HAVE_CURLOPT_TIMEOUT_MS
+        if (cb->timeout > 0)
+                curl_easy_setopt (cb->curl, CURLOPT_TIMEOUT_MS, (long) cb->timeout);
+#endif
+
         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:  */*");
@@ -125,9 +151,16 @@ static int wh_callback_init (wh_callback_t *cb) /* {{{ */
 
         curl_easy_setopt (cb->curl, CURLOPT_ERRORBUFFER, cb->curl_errbuf);
         curl_easy_setopt (cb->curl, CURLOPT_URL, cb->location);
+        curl_easy_setopt (cb->curl, CURLOPT_FOLLOWLOCATION, 1L);
+        curl_easy_setopt (cb->curl, CURLOPT_MAXREDIRS, 50L);
 
         if (cb->user != NULL)
         {
+#ifdef HAVE_CURLOPT_USERNAME
+                curl_easy_setopt (cb->curl, CURLOPT_USERNAME, cb->user);
+                curl_easy_setopt (cb->curl, CURLOPT_PASSWORD,
+                        (cb->pass == NULL) ? "" : cb->pass);
+#else
                 size_t credentials_size;
 
                 credentials_size = strlen (cb->user) + 2;
@@ -144,14 +177,27 @@ static int wh_callback_init (wh_callback_t *cb) /* {{{ */
                 ssnprintf (cb->credentials, credentials_size, "%s:%s",
                                 cb->user, (cb->pass == NULL) ? "" : cb->pass);
                 curl_easy_setopt (cb->curl, CURLOPT_USERPWD, cb->credentials);
+#endif
                 curl_easy_setopt (cb->curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
         }
 
         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);
 
@@ -263,12 +309,22 @@ static void wh_callback_free (void *data) /* {{{ */
 
         wh_flush_nolock (/* timeout = */ 0, cb);
 
-        curl_easy_cleanup (cb->curl);
+        if (cb->curl != NULL)
+        {
+                curl_easy_cleanup (cb->curl);
+                cb->curl = NULL;
+        }
+        sfree (cb->name);
         sfree (cb->location);
         sfree (cb->user);
         sfree (cb->pass);
         sfree (cb->credentials);
         sfree (cb->cacert);
+        sfree (cb->capath);
+        sfree (cb->clientkey);
+        sfree (cb->clientcert);
+        sfree (cb->clientkeypass);
+        sfree (cb->send_buffer);
 
         sfree (cb);
 } /* }}} void wh_callback_free */
@@ -350,8 +406,8 @@ static int wh_write_command (const data_set_t *ds, const value_list_t *vl, /* {{
 
         DEBUG ("write_http plugin: <%s> buffer %zu/%zu (%g%%) \"%s\"",
                         cb->location,
-                        cb->send_buffer_fill, sizeof (cb->send_buffer),
-                        100.0 * ((double) cb->send_buffer_fill) / ((double) sizeof (cb->send_buffer)),
+                        cb->send_buffer_fill, cb->send_buffer_size,
+                        100.0 * ((double) cb->send_buffer_fill) / ((double) cb->send_buffer_size),
                         command);
 
         /* Check if we have enough space for this command. */
@@ -405,8 +461,8 @@ static int wh_write_json (const data_set_t *ds, const value_list_t *vl, /* {{{ *
 
         DEBUG ("write_http plugin: <%s> buffer %zu/%zu (%g%%)",
                         cb->location,
-                        cb->send_buffer_fill, sizeof (cb->send_buffer),
-                        100.0 * ((double) cb->send_buffer_fill) / ((double) sizeof (cb->send_buffer)));
+                        cb->send_buffer_fill, cb->send_buffer_size,
+                        100.0 * ((double) cb->send_buffer_fill) / ((double) cb->send_buffer_size));
 
         /* Check if we have enough space for this command. */
         pthread_mutex_unlock (&cb->send_lock);
@@ -433,47 +489,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,11 +515,12 @@ 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) /* {{{ */
+static int wh_config_node (oconfig_item_t *ci) /* {{{ */
 {
         wh_callback_t *cb;
+        int buffer_size = 0;
         user_data_t user_data;
         char callback_name[DATA_MAX_NAME_LEN];
         int i;
@@ -516,40 +532,83 @@ 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;
+        cb->low_speed_limit = 0;
+        cb->timeout = 0;
 
         pthread_mutex_init (&cb->send_lock, /* attr = */ NULL);
 
-        config_set_string (&cb->location, ci);
-        if (cb->location == NULL)
-                return (-1);
+        cf_util_get_string (ci, &cb->name);
+
+        /* FIXME: Remove this legacy mode in version 6. */
+        if (strcasecmp ("URL", ci->key) == 0)
+                cf_util_get_string (ci, &cb->location);
 
         for (i = 0; i < ci->children_num; i++)
         {
                 oconfig_item_t *child = ci->children + i;
 
-                if (strcasecmp ("User", child->key) == 0)
-                        config_set_string (&cb->user, child);
+                if (strcasecmp ("URL", child->key) == 0)
+                        cf_util_get_string (child, &cb->location);
+                else if (strcasecmp ("User", child->key) == 0)
+                        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 if (strcasecmp ("BufferSize", child->key) == 0)
+                        cf_util_get_int (child, &buffer_size);
+                else if (strcasecmp ("LowSpeedLimit", child->key) == 0)
+                        cf_util_get_int (child, &cb->low_speed_limit);
+                else if (strcasecmp ("Timeout", child->key) == 0)
+                        cf_util_get_int (child, &cb->timeout);
                 else
                 {
                         ERROR ("write_http plugin: Invalid configuration "
@@ -557,8 +616,38 @@ static int wh_config_url (oconfig_item_t *ci) /* {{{ */
                 }
         }
 
+        if (cb->location == NULL)
+        {
+                ERROR ("write_http plugin: no URL defined for instance '%s'",
+                        cb->name);
+                wh_callback_free (cb);
+                return (-1);
+        }
+
+        if (cb->low_speed_limit > 0)
+                cb->low_speed_time = CDTIME_T_TO_TIME_T(plugin_get_interval());
+
+        /* Determine send_buffer_size. */
+        cb->send_buffer_size = WRITE_HTTP_DEFAULT_BUFFER_SIZE;
+        if (buffer_size >= 1024)
+                cb->send_buffer_size = (size_t) buffer_size;
+        else if (buffer_size != 0)
+                ERROR ("write_http plugin: Ignoring invalid BufferSize setting (%d).",
+                                buffer_size);
+
+        /* Allocate the buffer. */
+        cb->send_buffer = malloc (cb->send_buffer_size);
+        if (cb->send_buffer == NULL)
+        {
+                ERROR ("write_http plugin: malloc(%zu) failed.", cb->send_buffer_size);
+                wh_callback_free (cb);
+                return (-1);
+        }
+        /* Nulls the buffer and sets ..._free and ..._fill. */
+        wh_reset_buffer (cb);
+
         ssnprintf (callback_name, sizeof (callback_name), "write_http/%s",
-                        cb->location);
+                        cb->name);
         DEBUG ("write_http: Registering write callback '%s' with URL '%s'",
                         callback_name, cb->location);
 
@@ -571,7 +660,7 @@ static int wh_config_url (oconfig_item_t *ci) /* {{{ */
         plugin_register_write (callback_name, wh_write, &user_data);
 
         return (0);
-} /* }}} int wh_config_url */
+} /* }}} int wh_config_node */
 
 static int wh_config (oconfig_item_t *ci) /* {{{ */
 {
@@ -581,8 +670,14 @@ static int wh_config (oconfig_item_t *ci) /* {{{ */
         {
                 oconfig_item_t *child = ci->children + i;
 
-                if (strcasecmp ("URL", child->key) == 0)
-                        wh_config_url (child);
+                if (strcasecmp ("Node", child->key) == 0)
+                        wh_config_node (child);
+                /* FIXME: Remove this legacy mode in version 6. */
+                else if (strcasecmp ("URL", child->key) == 0) {
+                        WARNING ("write_http plugin: Legacy <URL> block found. "
+                                "Please use <Node> instead.");
+                        wh_config_node (child);
+                }
                 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..775e2e0
--- /dev/null
@@ -0,0 +1,487 @@
+/**
+ * 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 <stdint.h>
+#include <librdkafka/rdkafka.h>
+#include <pthread.h>
+#include <zlib.h>
+#include <errno.h>
+
+struct kafka_topic_context {
+#define KAFKA_FORMAT_JSON        0
+#define KAFKA_FORMAT_COMMAND     1
+#define KAFKA_FORMAT_GRAPHITE    2
+    uint8_t                     format;
+    unsigned int                 graphite_flags;
+    _Bool                        store_rates;
+    rd_kafka_topic_conf_t       *conf;
+    rd_kafka_topic_t            *topic;
+    rd_kafka_conf_t             *kafka_conf;
+    rd_kafka_t                  *kafka;
+    int                          has_key;
+    uint32_t                    key;
+    char                        *prefix;
+    char                        *postfix;
+    char                         escape_char;
+    char                        *topic_name;
+    pthread_mutex_t            lock;
+};
+
+static int kafka_handle(struct kafka_topic_context *);
+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 *);
+
+#if defined HAVE_LIBRDKAFKA_LOGGER || defined HAVE_LIBRDKAFKA_LOG_CB
+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)
+{
+    uint32_t key = *((uint32_t *)keydata );
+    uint32_t target = key % partition_cnt;
+    int32_t   i = partition_cnt;
+
+    while (--i > 0 && !rd_kafka_topic_partition_available(rkt, target)) {
+        target = (target + 1) % partition_cnt;
+    }
+    return target;
+}
+
+static int kafka_handle(struct kafka_topic_context *ctx) /* {{{ */
+{
+    char                         errbuf[1024];
+    rd_kafka_conf_t             *conf;
+    rd_kafka_topic_conf_t       *topic_conf;
+
+    if (ctx->kafka != NULL && ctx->topic != NULL)
+        return(0);
+
+    if (ctx->kafka == NULL) {
+        if ((conf = rd_kafka_conf_dup(ctx->kafka_conf)) == NULL) {
+            ERROR("write_kafka plugin: cannot duplicate kafka config");
+            return(1);
+        }
+
+        if ((ctx->kafka = rd_kafka_new(RD_KAFKA_PRODUCER, conf,
+                                    errbuf, sizeof(errbuf))) == NULL) {
+               ERROR("write_kafka plugin: cannot create kafka handle.");
+               return 1;
+        }
+
+       rd_kafka_conf_destroy(ctx->kafka_conf);
+       ctx->kafka_conf = NULL;
+
+       INFO ("write_kafka plugin: created KAFKA handle : %s", rd_kafka_name(ctx->kafka));
+
+#ifdef HAVE_LIBRDKAFKA_LOGGER
+       rd_kafka_set_logger(ctx->kafka, kafka_log);
+#endif
+    }
+
+    if (ctx->topic == NULL ) {
+       if ((topic_conf = rd_kafka_topic_conf_dup(ctx->conf)) == NULL) {
+            ERROR("write_kafka plugin: cannot duplicate kafka topic config");
+            return 1;
+       }
+
+       if ((ctx->topic = rd_kafka_topic_new(ctx->kafka, ctx->topic_name,
+                                                       topic_conf)) == NULL) {
+               ERROR("write_kafka plugin: cannot create topic : %s\n", 
+                       rd_kafka_err2str(rd_kafka_errno2err(errno)));
+               return errno;
+       }
+
+       rd_kafka_topic_conf_destroy(ctx->conf);
+       ctx->conf = NULL;
+
+       INFO ("write_kafka plugin: handle created for topic : %s", rd_kafka_topic_name(ctx->topic));
+    }
+
+    return(0);
+
+} /* }}} int kafka_handle */
+
+static int kafka_write(const data_set_t *ds, /* {{{ */
+             const value_list_t *vl,
+             user_data_t *ud)
+{
+       int                      status = 0;
+    uint32_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;
+
+    pthread_mutex_lock (&ctx->lock);
+    status = kafka_handle(ctx);
+    pthread_mutex_unlock (&ctx->lock);
+    if( status != 0 )
+        return status;
+
+    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);
+    if (ctx->kafka_conf != NULL)
+        rd_kafka_conf_destroy(ctx->kafka_conf);
+    if (ctx->kafka != NULL)
+        rd_kafka_destroy(ctx->kafka);
+
+    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;
+
+    if ((tctx->kafka_conf = rd_kafka_conf_dup(conf)) == NULL) {
+        sfree(tctx);
+        ERROR("write_kafka plugin: cannot allocate memory for kafka config");
+        return;
+    }
+
+#ifdef HAVE_LIBRDKAFKA_LOG_CB
+    rd_kafka_conf_set_log_cb(tctx->kafka_conf, kafka_log);
+#endif
+
+    if ((tctx->conf = rd_kafka_topic_conf_new()) == NULL) {
+        rd_kafka_conf_destroy(tctx->kafka_conf);
+        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[1].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);
+
+    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;
+    }
+
+    pthread_mutex_init (&tctx->lock, /* attr = */ NULL);
+
+    return;
+ errout:
+    if (tctx->topic_name != NULL)
+        free(tctx->topic_name);
+    if (tctx->conf != NULL)
+        rd_kafka_topic_conf_destroy(tctx->conf);
+    if (tctx->kafka_conf != NULL)
+               rd_kafka_conf_destroy(tctx->kafka_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_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) {
+                       kafka_config_topic (conf, 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 : */
diff --git a/src/write_log.c b/src/write_log.c
new file mode 100644 (file)
index 0000000..e37aae9
--- /dev/null
@@ -0,0 +1,81 @@
+/**
+ * collectd - src/write_log.c
+ * Copyright (C) 2015       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 "plugin.h"
+#include "configfile.h"
+
+#include "utils_format_graphite.h"
+
+/* Folks without pthread will need to disable this plugin. */
+#include <pthread.h>
+
+#include <sys/socket.h>
+#include <netdb.h>
+
+#define WL_BUF_SIZE 8192
+
+static int wl_write_messages (const data_set_t *ds, const value_list_t *vl)
+{
+    char buffer[WL_BUF_SIZE];
+    int status;
+
+    if (0 != strcmp (ds->type, vl->type))
+    {
+        ERROR ("write_log plugin: DS type does not match "
+                "value list type");
+        return -1;
+    }
+
+    memset (buffer, 0, sizeof (buffer));
+    status = format_graphite (buffer, sizeof (buffer), ds, vl,
+                              NULL, NULL, '_', 0);
+    if (status != 0) /* error message has been printed already. */
+        return (status);
+
+    INFO ("write_log values:\n%s", buffer);
+
+    return (0);
+} /* int wl_write_messages */
+
+static int wl_write (const data_set_t *ds, const value_list_t *vl,
+        user_data_t *user_data)
+{
+    int status;
+
+    status = wl_write_messages (ds, vl);
+
+    return (status);
+}
+
+void module_register (void)
+{
+    plugin_register_write ("write_log", wl_write, NULL);
+}
+
+/* vim: set sw=4 ts=4 sts=4 tw=78 et : */
index 3b8addd2c02e63f9ea8725d2ba431d7253ffb36f..2a6f9124aee0f9a66e3c6a004d8456442d7a067b 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"),
@@ -30,7 +30,8 @@
 #include "configfile.h"
 
 #include <pthread.h>
-#include <credis.h>
+#include <sys/time.h>
+#include <hiredis/hiredis.h>
 
 struct wr_node_s
 {
@@ -38,9 +39,9 @@ struct wr_node_s
 
   char *host;
   int port;
-  int timeout;
+  struct timeval timeout;
 
-  REDIS conn;
+  redisContext *conn;
   pthread_mutex_t lock;
 };
 typedef struct wr_node_s wr_node_t;
@@ -56,20 +57,55 @@ static int wr_write (const data_set_t *ds, /* {{{ */
   char ident[512];
   char key[512];
   char value[512];
+  char time[24];
   size_t value_size;
   char *value_ptr;
   int status;
+  redisReply   *rr;
   int i;
 
   status = FORMAT_VL (ident, sizeof (ident), vl);
   if (status != 0)
     return (status);
   ssnprintf (key, sizeof (key), "collectd/%s", ident);
+  ssnprintf (time, sizeof (time), "%.9f", CDTIME_T_TO_DOUBLE(vl->time));
 
   memset (value, 0, sizeof (value));
   value_size = sizeof (value);
   value_ptr = &value[0];
 
+#define APPEND(...) do {                                             \
+  status = snprintf (value_ptr, value_size, __VA_ARGS__);            \
+  if (((size_t) status) > value_size)                                \
+  {                                                                  \
+    value_ptr += value_size;                                         \
+    value_size = 0;                                                  \
+  }                                                                  \
+  else                                                               \
+  {                                                                  \
+    value_ptr += status;                                             \
+    value_size -= status;                                            \
+  }                                                                  \
+} while (0)
+
+  APPEND ("%s:", time);
+
+  for (i = 0; i < ds->ds_num; i++)
+  {
+    if (ds->ds[i].type == DS_TYPE_COUNTER)
+      APPEND ("%llu", vl->values[i].counter);
+    else if (ds->ds[i].type == DS_TYPE_GAUGE)
+      APPEND (GAUGE_FORMAT, vl->values[i].gauge);
+    else if (ds->ds[i].type == DS_TYPE_DERIVE)
+      APPEND ("%"PRIi64, vl->values[i].derive);
+    else if (ds->ds[i].type == DS_TYPE_ABSOLUTE)
+      APPEND ("%"PRIu64, vl->values[i].absolute);
+    else
+      assert (23 == 42);
+  }
+
+#undef APPEND
+
   status = format_values (value_ptr, value_size, ds, vl, /* store rates = */ 0);
   pthread_mutex_lock (&node->lock);
   if (status != 0)
@@ -77,23 +113,40 @@ static int wr_write (const data_set_t *ds, /* {{{ */
 
   if (node->conn == NULL)
   {
-    node->conn = credis_connect (node->host, node->port, node->timeout);
+    node->conn = redisConnectWithTimeout ((char *)node->host, node->port, node->timeout);
     if (node->conn == NULL)
     {
-      ERROR ("write_redis plugin: Connecting to host \"%s\" (port %i) failed.",
+      ERROR ("write_redis plugin: Connecting to host \"%s\" (port %i) failed: Unkown reason",
           (node->host != NULL) ? node->host : "localhost",
           (node->port != 0) ? node->port : 6379);
       pthread_mutex_unlock (&node->lock);
       return (-1);
     }
+    else if (node->conn->err)
+    {
+      ERROR ("write_redis plugin: Connecting to host \"%s\" (port %i) failed: %s",
+          (node->host != NULL) ? node->host : "localhost",
+          (node->port != 0) ? node->port : 6379,
+          node->conn->errstr);
+      pthread_mutex_unlock (&node->lock);
+      return (-1);
+    }
   }
 
-  /* "credis_zadd" doesn't handle a NULL pointer gracefully, so I'd rather
-   * have a meaningful assertion message than a normal segmentation fault. */
-  assert (node->conn != NULL);
-  status = credis_zadd (node->conn, key, (double) vl->time, value);
-
-  credis_sadd (node->conn, "collectd/values", ident);
+  rr = redisCommand (node->conn, "ZADD %s %s %s", key, time, value);
+  if (rr == NULL)
+    WARNING("ZADD command error. key:%s message:%s", key, node->conn->errstr);
+  else
+    freeReplyObject (rr);
+
+  /* TODO(octo): This is more overhead than necessary. Use the cache and
+   * metadata to determine if it is a new metric and call SADD only once for
+   * each metric. */
+  rr = redisCommand (node->conn, "SADD collectd/values %s", ident);
+  if (rr==NULL)
+    WARNING("SADD command error. ident:%s message:%s", ident, node->conn->errstr);
+  else
+    freeReplyObject (rr);
 
   pthread_mutex_unlock (&node->lock);
 
@@ -109,7 +162,7 @@ static void wr_config_free (void *ptr) /* {{{ */
 
   if (node->conn != NULL)
   {
-    credis_close (node->conn);
+    redisFree (node->conn);
     node->conn = NULL;
   }
 
@@ -120,6 +173,7 @@ static void wr_config_free (void *ptr) /* {{{ */
 static int wr_config_node (oconfig_item_t *ci) /* {{{ */
 {
   wr_node_t *node;
+  int timeout;
   int status;
   int i;
 
@@ -129,7 +183,8 @@ static int wr_config_node (oconfig_item_t *ci) /* {{{ */
   memset (node, 0, sizeof (*node));
   node->host = NULL;
   node->port = 0;
-  node->timeout = 1000;
+  node->timeout.tv_sec = 0;
+  node->timeout.tv_usec = 1000;
   node->conn = NULL;
   pthread_mutex_init (&node->lock, /* attr = */ NULL);
 
@@ -155,8 +210,10 @@ static int wr_config_node (oconfig_item_t *ci) /* {{{ */
         status = 0;
       }
     }
-    else if (strcasecmp ("Timeout", child->key) == 0)
-      status = cf_util_get_int (child, &node->timeout);
+    else if (strcasecmp ("Timeout", child->key) == 0) {
+      status = cf_util_get_int (child, &timeout);
+      if (status == 0) node->timeout.tv_usec = timeout;
+    }
     else
       WARNING ("write_redis plugin: Ignoring unknown config option \"%s\".",
           child->key);
index a404ff6e19470f10f52f8926d89b7f5225c037e4..a09c72361f910ac8615a219fd9187da36e77a819 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_HOST           "localhost"
 #define RIEMANN_PORT           "5555"
 #define RIEMANN_TTL_FACTOR      2.0
+#define RIEMANN_BATCH_MAX      8192
+
+int write_riemann_threshold_check(const data_set_t *, const value_list_t *, int *);
 
 struct riemann_host {
        char                    *name;
-#define F_CONNECT               0x01
+       char                    *event_service_prefix;
+#define F_CONNECT       0x01
        uint8_t                  flags;
-       pthread_mutex_t          lock;
+       pthread_mutex_t  lock;
+    _Bool            batch_mode;
+       _Bool            notifications;
+       _Bool            check_thresholds;
        _Bool                    store_rates;
        _Bool                    always_append_ds;
        char                    *node;
        char                    *service;
        _Bool                    use_tcp;
-       int                      s;
+       int                          s;
        double                   ttl_factor;
-
-       int                      reference_count;
+    Msg             *batch_msg;
+    cdtime_t         batch_init;
+    int              batch_max;
+       int                          reference_count;
 };
 
 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 +164,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 +426,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 +439,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 +467,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 +489,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 +541,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]);
 
@@ -522,11 +574,22 @@ static Event *riemann_value_to_protobuf(struct riemann_host const *host, /* {{{
                        /* host = */ "", vl->plugin, vl->plugin_instance,
                        vl->type, vl->type_instance);
        if (host->always_append_ds || (ds->ds_num > 1))
-               ssnprintf (service_buffer, sizeof (service_buffer),
-                               "%s/%s", &name_buffer[1], ds->ds[index].name);
+       {
+               if (host->event_service_prefix == NULL)
+                       ssnprintf (service_buffer, sizeof (service_buffer), "%s/%s",
+                                       &name_buffer[1], ds->ds[index].name);
+               else
+                       ssnprintf (service_buffer, sizeof (service_buffer), "%s%s/%s",
+                                       host->event_service_prefix, &name_buffer[1], ds->ds[index].name);
+       }
        else
-               sstrncpy (service_buffer, &name_buffer[1],
-                               sizeof (service_buffer));
+       {
+               if (host->event_service_prefix == NULL)
+                       sstrncpy (service_buffer, &name_buffer[1], sizeof (service_buffer));
+               else
+                       ssnprintf (service_buffer, sizeof (service_buffer), "%s%s",
+                                       host->event_service_prefix, &name_buffer[1]);
+       }
 
        event->service = strdup (service_buffer);
 
@@ -536,9 +599,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 +642,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);
@@ -591,12 +655,115 @@ static Msg *riemann_value_list_to_protobuf(struct riemann_host const *host, /* {
        return (msg);
 } /* }}} Msg *riemann_value_list_to_protobuf */
 
+
+/*
+ * Always call while holding host->lock !
+ */
+static int riemann_batch_flush_nolock (cdtime_t timeout,
+                                       struct riemann_host *host)
+{
+    cdtime_t    now;
+    int         status = 0;
+
+    if (timeout > 0) {
+        now = cdtime ();
+        if ((host->batch_init + timeout) > now)
+            return status;
+    }
+    riemann_send_msg(host, host->batch_msg);
+    riemann_msg_protobuf_free(host->batch_msg);
+
+       if (host->use_tcp && ((status = riemann_recv_ack(host)) != 0))
+        riemann_disconnect (host);
+
+    host->batch_init = cdtime();
+    host->batch_msg = NULL;
+    return status;
+}
+
+static int riemann_batch_flush (cdtime_t timeout,
+        const char *identifier __attribute__((unused)),
+        user_data_t *user_data)
+{
+    struct riemann_host *host;
+    int status;
+
+    if (user_data == NULL)
+        return (-EINVAL);
+
+    host = user_data->data;
+    pthread_mutex_lock (&host->lock);
+    status = riemann_batch_flush_nolock (timeout, host);
+    if (status != 0)
+        ERROR ("write_riemann plugin: riemann_send failed with status %i",
+               status);
+
+    pthread_mutex_unlock(&host->lock);
+    return status;
+}
+
+static int riemann_batch_add_value_list (struct riemann_host *host, /* {{{ */
+                                         data_set_t const *ds,
+                                         value_list_t const *vl,
+                                         int *statuses)
+{
+       size_t i;
+    Event **events;
+    Msg *msg;
+    size_t len;
+    int ret;
+
+    msg = riemann_value_list_to_protobuf (host, ds, vl, statuses);
+    if (msg == NULL)
+        return -1;
+
+    pthread_mutex_lock(&host->lock);
+
+    if (host->batch_msg == NULL) {
+        host->batch_msg = msg;
+    } else {
+        len = msg->n_events + host->batch_msg->n_events;
+        events = realloc(host->batch_msg->events,
+                         (len * sizeof(*host->batch_msg->events)));
+        if (events == NULL) {
+            pthread_mutex_unlock(&host->lock);
+            ERROR ("write_riemann plugin: out of memory");
+            riemann_msg_protobuf_free (msg);
+            return -1;
+        }
+        host->batch_msg->events = events;
+
+        for (i = host->batch_msg->n_events; i < len; i++)
+            host->batch_msg->events[i] = msg->events[i - host->batch_msg->n_events];
+
+        host->batch_msg->n_events = len;
+        sfree (msg->events);
+        msg->n_events = 0;
+        sfree (msg);
+    }
+
+       len = msg__get_packed_size(host->batch_msg);
+    ret = 0;
+    if (len >= host->batch_max) {
+        ret = riemann_batch_flush_nolock(0, host);
+    }
+
+    pthread_mutex_unlock(&host->lock);
+    return ret;
+} /* }}} Msg *riemann_batch_add_value_list */
+
 static int riemann_notification(const notification_t *n, user_data_t *ud) /* {{{ */
 {
        int                      status;
        struct riemann_host     *host = ud->data;
        Msg                     *msg;
 
+       if (!host->notifications)
+               return 0;
+
+    /*
+     * Never batch for notifications, send them ASAP
+     */
        msg = riemann_notification_to_protobuf (host, n);
        if (msg == NULL)
                return (-1);
@@ -614,20 +781,32 @@ static int riemann_write(const data_set_t *ds, /* {{{ */
              const value_list_t *vl,
              user_data_t *ud)
 {
-       int                      status;
+       int                      status = 0;
+       int                      statuses[vl->values_len];
        struct riemann_host     *host = ud->data;
        Msg                     *msg;
 
-       msg = riemann_value_list_to_protobuf (host, ds, vl);
-       if (msg == NULL)
-               return (-1);
+       if (host->check_thresholds)
+               write_riemann_threshold_check(ds, vl, statuses);
 
-       status = riemann_send (host, msg);
-       if (status != 0)
-               ERROR ("write_riemann plugin: riemann_send failed with status %i",
-                               status);
+    if (host->use_tcp == 1 && host->batch_mode) {
 
-       riemann_msg_protobuf_free (msg);
+        riemann_batch_add_value_list (host, ds, vl, statuses);
+
+
+    } else {
+
+        msg = riemann_value_list_to_protobuf (host, ds, vl, statuses);
+        if (msg == NULL)
+            return (-1);
+
+        status = riemann_send (host, msg);
+        if (status != 0)
+            ERROR ("write_riemann plugin: riemann_send failed with status %i",
+                   status);
+
+        riemann_msg_protobuf_free (msg);
+    }
        return status;
 } /* }}} int riemann_write */
 
@@ -671,9 +850,14 @@ 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;
+       host->use_tcp = 1;
+       host->batch_mode = 1;
+       host->batch_max = RIEMANN_BATCH_MAX; /* typical MSS */
+       host->batch_init = cdtime();
        host->ttl_factor = RIEMANN_TTL_FACTOR;
 
        status = cf_util_get_string (ci, &host->name);
@@ -695,6 +879,26 @@ 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 ("EventServicePrefix", child->key) == 0) {
+                       status = cf_util_get_string (child, &host->event_service_prefix);
+                       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 ("Batch", child->key) == 0) {
+            status = cf_util_get_boolean(child, &host->batch_mode);
+            if (status != 0)
+                break;
+        } else if (strcasecmp("BatchMaxSize", child->key) == 0) {
+            status = cf_util_get_int(child, &host->batch_max);
+            if (status != 0)
+                break;
                } else if (strcasecmp ("Port", child->key) == 0) {
                        status = cf_util_get_service (child, &host->service);
                        if (status != 0) {
@@ -779,6 +983,11 @@ static int riemann_config_node(oconfig_item_t *ci) /* {{{ */
        pthread_mutex_lock (&host->lock);
 
        status = plugin_register_write (callback_name, riemann_write, &ud);
+
+    if (host->use_tcp == 1 && host->batch_mode) {
+        ud.free_func = NULL;
+        plugin_register_flush(callback_name, riemann_batch_flush, &ud);
+    }
        if (status != 0)
                WARNING ("write_riemann plugin: plugin_register_write (\"%s\") "
                                "failed with status %i.",
@@ -823,6 +1032,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_sensu.c b/src/write_sensu.c
new file mode 100644 (file)
index 0000000..f7803e8
--- /dev/null
@@ -0,0 +1,1220 @@
+/**
+ * collectd - src/write_sensu.c
+ * Copyright (C) 2015 Fabrice A. Marie
+ *
+ * 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:
+ *   Fabrice A. Marie <fabrice at kibinlabs.com>
+ */
+
+#include "collectd.h"
+#include "plugin.h"
+#include "common.h"
+#include "configfile.h"
+#include "utils_cache.h"
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <errno.h>
+#include <netdb.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <stddef.h>
+
+#include <stdlib.h>
+#ifndef HAVE_ASPRINTF
+/*
+ * Uses asprintf() portable implementation from
+ * https://github.com/littlstar/asprintf.c/blob/master/
+ * copyright (c) 2014 joseph werle <joseph.werle@gmail.com> under MIT license.
+ */
+#include <stdio.h>
+#include <stdarg.h>
+
+int vasprintf(char **str, const char *fmt, va_list args) {
+       int size = 0;
+       va_list tmpa;
+       // copy
+       va_copy(tmpa, args);
+       // apply variadic arguments to
+       // sprintf with format to get size
+       size = vsnprintf(NULL, size, fmt, tmpa);
+       // toss args
+       va_end(tmpa);
+       // return -1 to be compliant if
+       // size is less than 0
+       if (size < 0) { return -1; }
+       // alloc with size plus 1 for `\0'
+       *str = (char *) malloc(size + 1);
+       // return -1 to be compliant
+       // if pointer is `NULL'
+       if (NULL == *str) { return -1; }
+       // format string with original
+       // variadic arguments and set new size
+       size = vsprintf(*str, fmt, args);
+       return size;
+}
+
+int asprintf(char **str, const char *fmt, ...) {
+       int size = 0;
+       va_list args;
+       // init variadic argumens
+       va_start(args, fmt);
+       // format and get size
+       size = vasprintf(str, fmt, args);
+       // toss args
+       va_end(args);
+       return size;
+}
+
+#endif
+
+#define SENSU_HOST             "localhost"
+#define SENSU_PORT             "3030"
+
+struct str_list {
+       int nb_strs;
+       char **strs;
+};
+
+struct sensu_host {
+       char                    *name;
+       char                    *event_service_prefix;
+       struct str_list metric_handlers;
+       struct str_list notification_handlers;
+#define F_READY      0x01
+       uint8_t                  flags;
+       pthread_mutex_t  lock;
+       _Bool            notifications;
+       _Bool            metrics;
+       _Bool                    store_rates;
+       _Bool                    always_append_ds;
+       char                    *separator;
+       char                    *node;
+       char                    *service;
+       int              s;
+       struct addrinfo *res;
+       int                          reference_count;
+};
+
+static char    *sensu_tags = NULL;
+static char    **sensu_attrs = NULL;
+static size_t sensu_attrs_num;
+
+static int add_str_to_list(struct str_list *strs,
+               const char *str_to_add) /* {{{ */
+{
+       char **old_strs_ptr = strs->strs;
+       char *newstr = strdup(str_to_add);
+       if (newstr == NULL) {
+               ERROR("write_sensu plugin: Unable to alloc memory");
+               return -1;
+       }
+       strs->strs = realloc(strs->strs, sizeof(char *) *(strs->nb_strs + 1));
+       if (strs->strs == NULL) {
+               strs->strs = old_strs_ptr;
+               free(newstr);
+               ERROR("write_sensu plugin: Unable to alloc memory");
+               return -1;
+       }
+       strs->strs[strs->nb_strs] = newstr;
+       strs->nb_strs++;
+       return 0;
+}
+/* }}} int add_str_to_list */
+
+static void free_str_list(struct str_list *strs) /* {{{ */
+{
+       int i;
+       for (i=0; i<strs->nb_strs; i++)
+               free(strs->strs[i]);
+       free(strs->strs);
+}
+/* }}} void free_str_list */
+
+static int sensu_connect(struct sensu_host *host) /* {{{ */
+{
+       int                      e;
+       struct addrinfo         *ai, hints;
+       char const              *node;
+       char const              *service;
+
+       // Resolve the target if we haven't done already
+       if (!(host->flags & F_READY)) {
+               memset(&hints, 0, sizeof(hints));
+               memset(&service, 0, sizeof(service));
+               host->res = NULL;
+               hints.ai_family = AF_INET;
+               hints.ai_socktype = SOCK_STREAM;
+#ifdef AI_ADDRCONFIG
+               hints.ai_flags |= AI_ADDRCONFIG;
+#endif
+
+               node = (host->node != NULL) ? host->node : SENSU_HOST;
+               service = (host->service != NULL) ? host->service : SENSU_PORT;
+
+               if ((e = getaddrinfo(node, service, &hints, &(host->res))) != 0) {
+                       ERROR("write_sensu plugin: Unable to resolve host \"%s\": %s",
+                                       node, gai_strerror(e));
+                       return -1;
+               }
+               DEBUG("write_sensu plugin: successfully resolved host/port: %s/%s",
+                               node, service);
+               host->flags |= F_READY;
+       }
+
+       struct linger so_linger;
+       host->s = -1;
+       for (ai = host->res; ai != NULL; ai = ai->ai_next) {
+               // create the socket
+               if ((host->s = socket(ai->ai_family,
+                                     ai->ai_socktype,
+                                     ai->ai_protocol)) == -1) {
+                       continue;
+               }
+
+               // Set very low close() lingering
+               so_linger.l_onoff = 1;
+               so_linger.l_linger = 3;
+               if (setsockopt(host->s, SOL_SOCKET, SO_LINGER, &so_linger, sizeof so_linger) != 0)
+                       WARNING("write_sensu plugin: failed to set socket close() lingering");
+
+               // connect the socket
+               if (connect(host->s, ai->ai_addr, ai->ai_addrlen) != 0) {
+                       close(host->s);
+                       host->s = -1;
+                       continue;
+               }
+               DEBUG("write_sensu plugin: connected");
+               break;
+       }
+
+       if (host->s < 0) {
+               WARNING("write_sensu plugin: Unable to connect to sensu client");
+               return -1;
+       }
+       return 0;
+} /* }}} int sensu_connect */
+
+static void sensu_close_socket(struct sensu_host *host) /* {{{ */
+{
+       if (host->s != -1)
+               close(host->s);
+       host->s = -1;
+
+} /* }}} void sensu_close_socket */
+
+static char *build_json_str_list(const char *tag, struct str_list const *list) /* {{{ */
+{
+       int res;
+       char *ret_str;
+       char *temp_str;
+       int i;
+       if (list->nb_strs == 0) {
+               ret_str = malloc(sizeof(char));
+               if (ret_str == NULL) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+               ret_str[0] = '\0';
+       }
+
+       res = asprintf(&temp_str, "\"%s\": [\"%s\"", tag, list->strs[0]);
+       if (res == -1) {
+               ERROR("write_sensu plugin: Unable to alloc memory");
+               return NULL;
+       }
+       for (i=1; i<list->nb_strs; i++) {
+               res = asprintf(&ret_str, "%s, \"%s\"", temp_str, list->strs[i]);
+               free(temp_str);
+               if (res == -1) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+               temp_str = ret_str;
+       }
+       res = asprintf(&ret_str, "%s]", temp_str);
+       free(temp_str);
+       if (res == -1) {
+               ERROR("write_sensu plugin: Unable to alloc memory");
+               return NULL;
+       }
+
+       return ret_str;
+} /* }}} char *build_json_str_list*/
+
+int sensu_format_name2(char *ret, int ret_len,
+               const char *hostname,
+               const char *plugin, const char *plugin_instance,
+               const char *type, const char *type_instance,
+               const char *separator)
+{
+       char *buffer;
+       size_t buffer_size;
+
+       buffer = ret;
+       buffer_size = (size_t) ret_len;
+
+#define APPEND(str) do {          \
+       size_t l = strlen (str);        \
+       if (l >= buffer_size)           \
+               return (ENOBUFS);             \
+       memcpy (buffer, (str), l);      \
+       buffer += l; buffer_size -= l;  \
+} while (0)
+
+       assert (plugin != NULL);
+       assert (type != NULL);
+
+       APPEND (hostname);
+       APPEND (separator);
+       APPEND (plugin);
+       if ((plugin_instance != NULL) && (plugin_instance[0] != 0))
+       {
+               APPEND ("-");
+               APPEND (plugin_instance);
+       }
+       APPEND (separator);
+       APPEND (type);
+       if ((type_instance != NULL) && (type_instance[0] != 0))
+       {
+               APPEND ("-");
+               APPEND (type_instance);
+       }
+       assert (buffer_size > 0);
+       buffer[0] = 0;
+
+#undef APPEND
+       return (0);
+} /* int sensu_format_name2 */
+
+static void in_place_replace_sensu_name_reserved(char *orig_name) /* {{{ */
+{
+       int i;
+       int len=strlen(orig_name);
+       for (i=0; i<len; i++) {
+               // some plugins like ipmi generate special characters in metric name
+               switch(orig_name[i]) {
+                       case '(': orig_name[i] = '_'; break;
+                       case ')': orig_name[i] = '_'; break;
+                       case ' ': orig_name[i] = '_'; break;
+                       case '"': orig_name[i] = '_'; break;
+                       case '\'': orig_name[i] = '_'; break;
+                       case '+': orig_name[i] = '_'; break;
+               }
+       }
+} /* }}} char *replace_sensu_name_reserved */
+
+static char *sensu_value_to_json(struct sensu_host const *host, /* {{{ */
+               data_set_t const *ds,
+               value_list_t const *vl, size_t index,
+               gauge_t const *rates,
+               int status)
+{
+       char name_buffer[5 * DATA_MAX_NAME_LEN];
+       char service_buffer[6 * DATA_MAX_NAME_LEN];
+       int i;
+       char *ret_str;
+       char *temp_str;
+       char *value_str;
+       int res;
+       // First part of the JSON string
+       const char *part1 = "{\"name\": \"collectd\", \"type\": \"metric\"";
+
+       char *handlers_str = build_json_str_list("handlers", &(host->metric_handlers));
+       if (handlers_str == NULL) {
+               ERROR("write_sensu plugin: Unable to alloc memory");
+               return NULL;
+       }
+
+       // incorporate the handlers
+       if (strlen(handlers_str) == 0) {
+               free(handlers_str);
+               ret_str = strdup(part1);
+               if (ret_str == NULL) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+       }
+       else {
+               res = asprintf(&ret_str, "%s, %s", part1, handlers_str);
+               free(handlers_str);
+               if (res == -1) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+       }
+
+       // incorporate the plugin name information
+       res = asprintf(&temp_str, "%s, \"collectd_plugin\": \"%s\"", ret_str, vl->plugin);
+       free(ret_str);
+       if (res == -1) {
+               ERROR("write_sensu plugin: Unable to alloc memory");
+               return NULL;
+       }
+       ret_str = temp_str;
+
+       // incorporate the plugin type
+       res = asprintf(&temp_str, "%s, \"collectd_plugin_type\": \"%s\"", ret_str, vl->type);
+       free(ret_str);
+       if (res == -1) {
+               ERROR("write_sensu plugin: Unable to alloc memory");
+               return NULL;
+       }
+       ret_str = temp_str;
+
+       // incorporate the plugin instance if any
+       if (vl->plugin_instance[0] != 0) {
+               res = asprintf(&temp_str, "%s, \"collectd_plugin_instance\": \"%s\"", ret_str, vl->plugin_instance);
+               free(ret_str);
+               if (res == -1) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+               ret_str = temp_str;
+       }
+
+       // incorporate the plugin type instance if any
+       if (vl->type_instance[0] != 0) {
+               res = asprintf(&temp_str, "%s, \"collectd_plugin_type_instance\": \"%s\"", ret_str, vl->type_instance);
+               free(ret_str);
+               if (res == -1) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+               ret_str = temp_str;
+       }
+
+       // incorporate the data source type
+       if ((ds->ds[index].type != DS_TYPE_GAUGE) && (rates != NULL)) {
+               char ds_type[DATA_MAX_NAME_LEN];
+               ssnprintf (ds_type, sizeof (ds_type), "%s:rate", DS_TYPE_TO_STRING(ds->ds[index].type));
+               res = asprintf(&temp_str, "%s, \"collectd_data_source_type\": \"%s\"", ret_str, ds_type);
+               free(ret_str);
+               if (res == -1) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+               ret_str = temp_str;
+       } else {
+               res = asprintf(&temp_str, "%s, \"collectd_data_source_type\": \"%s\"", ret_str, DS_TYPE_TO_STRING(ds->ds[index].type));
+               free(ret_str);
+               if (res == -1) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+               ret_str = temp_str;
+       }
+
+       // incorporate the data source name
+       res = asprintf(&temp_str, "%s, \"collectd_data_source_name\": \"%s\"", ret_str, ds->ds[index].name);
+       free(ret_str);
+       if (res == -1) {
+               ERROR("write_sensu plugin: Unable to alloc memory");
+               return NULL;
+       }
+       ret_str = temp_str;
+
+       // incorporate the data source index
+       {
+               char ds_index[DATA_MAX_NAME_LEN];
+               ssnprintf (ds_index, sizeof (ds_index), "%zu", index);
+               res = asprintf(&temp_str, "%s, \"collectd_data_source_index\": %s", ret_str, ds_index);
+               free(ret_str);
+               if (res == -1) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+               ret_str = temp_str;
+       }
+
+       // add key value attributes from config if any
+       for (i = 0; i < sensu_attrs_num; i += 2) {
+               res = asprintf(&temp_str, "%s, \"%s\": \"%s\"", ret_str, sensu_attrs[i], sensu_attrs[i+1]);
+               free(ret_str);
+               if (res == -1) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+               ret_str = temp_str;
+       }
+
+       // incorporate sensu tags from config if any
+       if (strlen(sensu_tags) != 0) {
+               res = asprintf(&temp_str, "%s, %s", ret_str, sensu_tags);
+               free(ret_str);
+               if (res == -1) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+               ret_str = temp_str;
+       }
+
+       // calculate the value and set to a string
+       if (ds->ds[index].type == DS_TYPE_GAUGE) {
+               res = asprintf(&value_str, GAUGE_FORMAT, vl->values[index].gauge);
+               if (res == -1) {
+                       free(ret_str);
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+       } else if (rates != NULL) {
+               res = asprintf(&value_str, GAUGE_FORMAT, rates[index]);
+               if (res == -1) {
+                       free(ret_str);
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+       } else {
+               if (ds->ds[index].type == DS_TYPE_DERIVE) {
+                       res = asprintf(&value_str, "%"PRIi64, vl->values[index].derive);
+                       if (res == -1) {
+                               free(ret_str);
+                               ERROR("write_sensu plugin: Unable to alloc memory");
+                               return NULL;
+                       }
+               }
+               else if (ds->ds[index].type == DS_TYPE_ABSOLUTE) {
+                       res = asprintf(&value_str, "%"PRIu64, vl->values[index].absolute);
+                       if (res == -1) {
+                               free(ret_str);
+                               ERROR("write_sensu plugin: Unable to alloc memory");
+                               return NULL;
+                       }
+               }
+               else {
+                       res = asprintf(&value_str, "%llu", vl->values[index].counter);
+                       if (res == -1) {
+                               free(ret_str);
+                               ERROR("write_sensu plugin: Unable to alloc memory");
+                               return NULL;
+                       }
+               }
+       }
+
+       // Generate the full service name
+       sensu_format_name2(name_buffer, sizeof(name_buffer),
+               vl->host, vl->plugin, vl->plugin_instance,
+               vl->type, vl->type_instance, host->separator);
+       if (host->always_append_ds || (ds->ds_num > 1)) {
+               if (host->event_service_prefix == NULL)
+                       ssnprintf(service_buffer, sizeof(service_buffer), "%s.%s",
+                                       name_buffer, ds->ds[index].name);
+               else
+                       ssnprintf(service_buffer, sizeof(service_buffer), "%s%s.%s",
+                                       host->event_service_prefix, name_buffer, ds->ds[index].name);
+       } else {
+               if (host->event_service_prefix == NULL)
+                       sstrncpy(service_buffer, name_buffer, sizeof(service_buffer));
+               else
+                       ssnprintf(service_buffer, sizeof(service_buffer), "%s%s",
+                                       host->event_service_prefix, name_buffer);
+       }
+
+       // Replace collectd sensor name reserved characters so that time series DB is happy
+       in_place_replace_sensu_name_reserved(service_buffer);
+
+       // finalize the buffer by setting the output and closing curly bracket
+       res = asprintf(&temp_str, "%s, \"output\": \"%s %s %ld\"}\n", ret_str, service_buffer, value_str, CDTIME_T_TO_TIME_T(vl->time));
+       free(ret_str);
+       free(value_str);
+       if (res == -1) {
+               ERROR("write_sensu plugin: Unable to alloc memory");
+               return NULL;
+       }
+       ret_str = temp_str;
+
+       DEBUG("write_sensu plugin: Successfully created json for metric: "
+                       "host = \"%s\", service = \"%s\"",
+                       vl->host, service_buffer);
+       return ret_str;
+} /* }}} char *sensu_value_to_json */
+
+/*
+ * Uses replace_str2() implementation from
+ * http://creativeandcritical.net/str-replace-c/
+ * copyright (c) Laird Shaw, under public domain.
+ */
+char *replace_str(const char *str, const char *old, /* {{{ */
+               const char *new)
+{
+       char *ret, *r;
+       const char *p, *q;
+       size_t oldlen = strlen(old);
+       size_t count = strlen(new);
+       size_t retlen;
+       size_t newlen = count;
+       int samesize = (oldlen == newlen);
+
+       if (!samesize) {
+               for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen)
+                       count++;
+               /* This is undefined if p - str > PTRDIFF_MAX */
+               retlen = p - str + strlen(p) + count * (newlen - oldlen);
+       } else
+               retlen = strlen(str);
+
+       ret = malloc(retlen + 1);
+       if (ret == NULL)
+               return NULL;
+       // added to original: not optimized, but keeps valgrind happy.
+       memset(ret, 0, retlen + 1);
+
+       r = ret;
+       p = str;
+       while (1) {
+               /* If the old and new strings are different lengths - in other
+                * words we have already iterated through with strstr above,
+                * and thus we know how many times we need to call it - then we
+                * can avoid the final (potentially lengthy) call to strstr,
+                * which we already know is going to return NULL, by
+                * decrementing and checking count.
+                */
+               if (!samesize && !count--)
+                       break;
+               /* Otherwise i.e. when the old and new strings are the same
+                * length, and we don't know how many times to call strstr,
+                * we must check for a NULL return here (we check it in any
+                * event, to avoid further conditions, and because there's
+                * no harm done with the check even when the old and new
+                * strings are different lengths).
+                */
+               if ((q = strstr(p, old)) == NULL)
+                       break;
+               /* This is undefined if q - p > PTRDIFF_MAX */
+               ptrdiff_t l = q - p;
+               memcpy(r, p, l);
+               r += l;
+               memcpy(r, new, newlen);
+               r += newlen;
+               p = q + oldlen;
+       }
+       strncpy(r, p, strlen(p));
+
+       return ret;
+} /* }}} char *replace_str */
+
+static char *replace_json_reserved(const char *message) /* {{{ */
+{
+       char *msg = replace_str(message, "\\", "\\\\");
+       if (msg == NULL) {
+               ERROR("write_sensu plugin: Unable to alloc memory");
+               return NULL;
+       }
+       char *tmp = replace_str(msg, "\"", "\\\"");
+       free(msg);
+       if (tmp == NULL) {
+               ERROR("write_sensu plugin: Unable to alloc memory");
+               return NULL;
+       }
+       msg = replace_str(tmp, "\n", "\\\n");
+       free(tmp);
+       if (msg == NULL) {
+               ERROR("write_sensu plugin: Unable to alloc memory");
+               return NULL;
+       }
+       return msg;
+} /* }}} char *replace_json_reserved */
+
+static char *sensu_notification_to_json(struct sensu_host *host, /* {{{ */
+               notification_t const *n)
+{
+       char service_buffer[6 * DATA_MAX_NAME_LEN];
+       char const *severity;
+       notification_meta_t *meta;
+       char *ret_str;
+       char *temp_str;
+       int status;
+       int i;
+       int res;
+       // add the severity/status
+       switch (n->severity) {
+               case NOTIF_OKAY:
+                       severity = "OK";
+                       status = 0;
+                       break;
+               case NOTIF_WARNING:
+                       severity = "WARNING";
+                       status = 1;
+                       break;
+               case NOTIF_FAILURE:
+                       severity = "CRITICAL";
+                       status = 2;
+                       break;
+               default:
+                       severity = "UNKNOWN";
+                       status = 3;
+       }
+       res = asprintf(&temp_str, "{\"status\": %d", status);
+       if (res == -1) {
+               ERROR("write_sensu plugin: Unable to alloc memory");
+               return NULL;
+       }
+       ret_str = temp_str;
+
+       // incorporate the timestamp
+       res = asprintf(&temp_str, "%s, \"timestamp\": %ld", ret_str, CDTIME_T_TO_TIME_T(n->time));
+       free(ret_str);
+       if (res == -1) {
+               ERROR("write_sensu plugin: Unable to alloc memory");
+               return NULL;
+       }
+       ret_str = temp_str;
+
+       char *handlers_str = build_json_str_list("handlers", &(host->notification_handlers));
+       if (handlers_str == NULL) {
+               ERROR("write_sensu plugin: Unable to alloc memory");
+               return NULL;
+       }
+       // incorporate the handlers
+       if (strlen(handlers_str) != 0) {
+               res = asprintf(&temp_str, "%s, %s", ret_str, handlers_str);
+               free(ret_str);
+               free(handlers_str);
+               if (res == -1) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+               ret_str = temp_str;
+       } else {
+               free(handlers_str);
+       }
+
+       // incorporate the plugin name information if any
+       if (n->plugin[0] != 0) {
+               res = asprintf(&temp_str, "%s, \"collectd_plugin\": \"%s\"", ret_str, n->plugin);
+               free(ret_str);
+               if (res == -1) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+               ret_str = temp_str;
+       }
+
+       // incorporate the plugin type if any
+       if (n->type[0] != 0) {
+               res = asprintf(&temp_str, "%s, \"collectd_plugin_type\": \"%s\"", ret_str, n->type);
+               free(ret_str);
+               if (res == -1) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+               ret_str = temp_str;
+       }
+
+       // incorporate the plugin instance if any
+       if (n->plugin_instance[0] != 0) {
+               res = asprintf(&temp_str, "%s, \"collectd_plugin_instance\": \"%s\"", ret_str, n->plugin_instance);
+               free(ret_str);
+               if (res == -1) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+               ret_str = temp_str;
+       }
+
+       // incorporate the plugin type instance if any
+       if (n->type_instance[0] != 0) {
+               res = asprintf(&temp_str, "%s, \"collectd_plugin_type_instance\": \"%s\"", ret_str, n->type_instance);
+               free(ret_str);
+               if (res == -1) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+               ret_str = temp_str;
+       }
+
+       // add key value attributes from config if any
+       for (i = 0; i < sensu_attrs_num; i += 2) {
+               res = asprintf(&temp_str, "%s, \"%s\": \"%s\"", ret_str, sensu_attrs[i], sensu_attrs[i+1]);
+               free(ret_str);
+               if (res == -1) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+               ret_str = temp_str;
+       }
+
+       // incorporate sensu tags from config if any
+       if (strlen(sensu_tags) != 0) {
+               res = asprintf(&temp_str, "%s, %s", ret_str, sensu_tags);
+               free(ret_str);
+               if (res == -1) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+               ret_str = temp_str;
+       }
+
+       // incorporate the service name
+       sensu_format_name2(service_buffer, sizeof(service_buffer),
+                               /* host */ "", n->plugin, n->plugin_instance,
+                               n->type, n->type_instance, host->separator);
+       // replace sensu event name chars that are considered illegal
+       in_place_replace_sensu_name_reserved(service_buffer);
+       res = asprintf(&temp_str, "%s, \"name\": \"%s\"", ret_str, &service_buffer[1]);
+       free(ret_str);
+       if (res == -1) {
+               ERROR("write_sensu plugin: Unable to alloc memory");
+               return NULL;
+       }
+       ret_str = temp_str;
+
+       // incorporate the check output
+       if (n->message[0] != 0) {
+               char *msg = replace_json_reserved(n->message);
+               if (msg == NULL) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+               res = asprintf(&temp_str, "%s, \"output\": \"%s - %s\"", ret_str, severity, msg);
+               free(ret_str);
+               free(msg);
+               if (res == -1) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return NULL;
+               }
+               ret_str = temp_str;
+       }
+
+       // Pull in values from threshold and add extra attributes
+       for (meta = n->meta; meta != NULL; meta = meta->next) {
+               if (strcasecmp("CurrentValue", meta->name) == 0 && meta->type == NM_TYPE_DOUBLE) {
+                       res = asprintf(&temp_str, "%s, \"current_value\": \"%.8f\"", ret_str, meta->nm_value.nm_double);
+                       free(ret_str);
+                       if (res == -1) {
+                               ERROR("write_sensu plugin: Unable to alloc memory");
+                               return NULL;
+                       }
+                       ret_str = temp_str;
+               }
+               if (meta->type == NM_TYPE_STRING) {
+                       res = asprintf(&temp_str, "%s, \"%s\": \"%s\"", ret_str, meta->name, meta->nm_value.nm_string);
+                       free(ret_str);
+                       if (res == -1) {
+                               ERROR("write_sensu plugin: Unable to alloc memory");
+                               return NULL;
+                       }
+                       ret_str = temp_str;
+               }
+       }
+
+       // close the curly bracket
+       res = asprintf(&temp_str, "%s}\n", ret_str);
+       free(ret_str);
+       if (res == -1) {
+               ERROR("write_sensu plugin: Unable to alloc memory");
+               return NULL;
+       }
+       ret_str = temp_str;
+
+       DEBUG("write_sensu plugin: Successfully created JSON for notification: "
+                               "host = \"%s\", service = \"%s\", state = \"%s\"",
+                               n->host, service_buffer, severity);
+       return ret_str;
+} /* }}} char *sensu_notification_to_json */
+
+static int sensu_send_msg(struct sensu_host *host, const char *msg) /* {{{ */
+{
+       int status = 0;
+       size_t  buffer_len;
+
+       status = sensu_connect(host);
+       if (status != 0)
+               return status;
+
+       buffer_len = strlen(msg);
+
+       status = (int) swrite(host->s, msg, buffer_len);
+       sensu_close_socket(host);
+
+       if (status != 0) {
+               char errbuf[1024];
+               ERROR("write_sensu plugin: Sending to Sensu at %s:%s failed: %s",
+                               (host->node != NULL) ? host->node : SENSU_HOST,
+                               (host->service != NULL) ? host->service : SENSU_PORT,
+                               sstrerror(errno, errbuf, sizeof(errbuf)));
+               return -1;
+       }
+
+       return 0;
+} /* }}} int sensu_send_msg */
+
+
+static int sensu_send(struct sensu_host *host, char const *msg) /* {{{ */
+{
+       int status = 0;
+
+       status = sensu_send_msg(host, msg);
+       if (status != 0) {
+               host->flags &= ~F_READY;
+               if (host->res != NULL) {
+                       freeaddrinfo(host->res);
+                       host->res = NULL;
+               }
+               return status;
+       }
+
+       return 0;
+} /* }}} int sensu_send */
+
+
+static int sensu_write(const data_set_t *ds, /* {{{ */
+             const value_list_t *vl,
+             user_data_t *ud)
+{
+       int status = 0;
+       int statuses[vl->values_len];
+       struct sensu_host       *host = ud->data;
+       gauge_t *rates = NULL;
+       int i;
+       char *msg;
+
+       pthread_mutex_lock(&host->lock);
+       memset(statuses, 0, vl->values_len * sizeof(*statuses));
+
+       if (host->store_rates) {
+               rates = uc_get_rate(ds, vl);
+               if (rates == NULL) {
+                       ERROR("write_sensu plugin: uc_get_rate failed.");
+                       pthread_mutex_unlock(&host->lock);
+                       return -1;
+               }
+       }
+       for (i = 0; i < (size_t) vl->values_len; i++) {
+               msg = sensu_value_to_json(host, ds, vl, (int) i, rates, statuses[i]);
+               if (msg == NULL) {
+                       sfree(rates);
+                       pthread_mutex_unlock(&host->lock);
+                       return -1;
+               }
+               status = sensu_send(host, msg);
+               free(msg);
+               if (status != 0) {
+                       ERROR("write_sensu plugin: sensu_send failed with status %i", status);
+                       pthread_mutex_unlock(&host->lock);
+                       sfree(rates);
+                       return status;
+               }
+       }
+       sfree(rates);
+       pthread_mutex_unlock(&host->lock);
+       return status;
+} /* }}} int sensu_write */
+
+static int sensu_notification(const notification_t *n, user_data_t *ud) /* {{{ */
+{
+       int     status;
+       struct sensu_host *host = ud->data;
+       char *msg;
+
+       pthread_mutex_lock(&host->lock);
+
+       msg = sensu_notification_to_json(host, n);
+       if (msg == NULL) {
+               pthread_mutex_unlock(&host->lock);
+               return -1;
+       }
+
+       status = sensu_send(host, msg);
+       free(msg);
+       if (status != 0)
+               ERROR("write_sensu plugin: sensu_send failed with status %i", status);
+       pthread_mutex_unlock(&host->lock);
+
+       return status;
+} /* }}} int sensu_notification */
+
+static void sensu_free(void *p) /* {{{ */
+{
+       struct sensu_host *host = p;
+
+       if (host == NULL)
+               return;
+
+       pthread_mutex_lock(&host->lock);
+
+       host->reference_count--;
+       if (host->reference_count > 0) {
+               pthread_mutex_unlock(&host->lock);
+               return;
+       }
+
+       sensu_close_socket(host);
+       if (host->res != NULL) {
+               freeaddrinfo(host->res);
+               host->res = NULL;
+       }
+       sfree(host->service);
+       sfree(host->event_service_prefix);
+       sfree(host->name);
+       sfree(host->node);
+       sfree(host->separator);
+       free_str_list(&(host->metric_handlers));
+       free_str_list(&(host->notification_handlers));
+       pthread_mutex_destroy(&host->lock);
+       sfree(host);
+} /* }}} void sensu_free */
+
+
+static int sensu_config_node(oconfig_item_t *ci) /* {{{ */
+{
+       struct sensu_host       *host = NULL;
+       int                                     status = 0;
+       int                                     i;
+       oconfig_item_t          *child;
+       char                            callback_name[DATA_MAX_NAME_LEN];
+       user_data_t                     ud;
+
+       if ((host = calloc(1, sizeof(*host))) == NULL) {
+               ERROR("write_sensu plugin: calloc failed.");
+               return ENOMEM;
+       }
+       pthread_mutex_init(&host->lock, NULL);
+       host->reference_count = 1;
+       host->node = NULL;
+       host->service = NULL;
+       host->notifications = 0;
+       host->metrics = 0;
+       host->store_rates = 1;
+       host->always_append_ds = 0;
+       host->metric_handlers.nb_strs = 0;
+       host->metric_handlers.strs = NULL;
+       host->notification_handlers.nb_strs = 0;
+       host->notification_handlers.strs = NULL;
+       host->separator = strdup("/");
+       if (host->separator == NULL) {
+               ERROR("write_sensu plugin: Unable to alloc memory");
+               sensu_free(host);
+               return -1;
+       }
+
+       status = cf_util_get_string(ci, &host->name);
+       if (status != 0) {
+               WARNING("write_sensu plugin: Required host name is missing.");
+               sensu_free(host);
+               return -1;
+       }
+
+       for (i = 0; i < ci->children_num; i++) {
+               child = &ci->children[i];
+               status = 0;
+
+               if (strcasecmp("Host", child->key) == 0) {
+                       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("Metrics", child->key) == 0) {
+                                       status = cf_util_get_boolean(child, &host->metrics);
+                                       if (status != 0)
+                                               break;
+               } else if (strcasecmp("EventServicePrefix", child->key) == 0) {
+                       status = cf_util_get_string(child, &host->event_service_prefix);
+                       if (status != 0)
+                               break;
+               } else if (strcasecmp("Separator", child->key) == 0) {
+                               status = cf_util_get_string(child, &host->separator);
+                               if (status != 0)
+                                       break;
+               } else if (strcasecmp("MetricHandler", child->key) == 0) {
+                       char *temp_str = NULL;
+                       status = cf_util_get_string(child, &temp_str);
+                       if (status != 0)
+                               break;
+                       status = add_str_to_list(&(host->metric_handlers), temp_str);
+                       free(temp_str);
+                       if (status != 0)
+                               break;
+               } else if (strcasecmp("NotificationHandler", child->key) == 0) {
+                       char *temp_str = NULL;
+                       status = cf_util_get_string(child, &temp_str);
+                       if (status != 0)
+                               break;
+                       status = add_str_to_list(&(host->notification_handlers), temp_str);
+                       free(temp_str);
+                       if (status != 0)
+                               break;
+               } else if (strcasecmp("Port", child->key) == 0) {
+                       status = cf_util_get_service(child, &host->service);
+                       if (status != 0) {
+                               ERROR("write_sensu plugin: Invalid argument "
+                                               "configured for the \"Port\" "
+                                               "option.");
+                               break;
+                       }
+               } else if (strcasecmp("StoreRates", child->key) == 0) {
+                       status = cf_util_get_boolean(child, &host->store_rates);
+                       if (status != 0)
+                               break;
+               } else if (strcasecmp("AlwaysAppendDS", child->key) == 0) {
+                       status = cf_util_get_boolean(child,
+                                       &host->always_append_ds);
+                       if (status != 0)
+                               break;
+               } else {
+                       WARNING("write_sensu plugin: ignoring unknown config "
+                               "option: \"%s\"", child->key);
+               }
+       }
+       if (status != 0) {
+               sensu_free(host);
+               return status;
+       }
+
+       if (host->metrics && (host->metric_handlers.nb_strs == 0)) {
+                       sensu_free(host);
+                       WARNING("write_sensu plugin: metrics enabled but no MetricHandler defined. Giving up.");
+                       return -1;
+               }
+
+       if (host->notifications && (host->notification_handlers.nb_strs == 0)) {
+               sensu_free(host);
+               WARNING("write_sensu plugin: notifications enabled but no NotificationHandler defined. Giving up.");
+               return -1;
+       }
+
+       if ((host->notification_handlers.nb_strs > 0) && (host->notifications == 0)) {
+               WARNING("write_sensu plugin: NotificationHandler given so forcing notifications to be enabled");
+               host->notifications = 1;
+       }
+
+       if ((host->metric_handlers.nb_strs > 0) && (host->metrics == 0)) {
+               WARNING("write_sensu plugin: MetricHandler given so forcing metrics to be enabled");
+               host->metrics = 1;
+       }
+
+       if (!(host->notifications || host->metrics)) {
+               WARNING("write_sensu plugin: neither metrics nor notifications enabled. Giving up.");
+               sensu_free(host);
+               return -1;
+       }
+
+       ssnprintf(callback_name, sizeof(callback_name), "write_sensu/%s", host->name);
+       ud.data = host;
+       ud.free_func = sensu_free;
+
+       pthread_mutex_lock(&host->lock);
+
+       if (host->metrics) {
+               status = plugin_register_write(callback_name, sensu_write, &ud);
+               if (status != 0)
+                       WARNING("write_sensu plugin: plugin_register_write (\"%s\") "
+                                       "failed with status %i.",
+                                       callback_name, status);
+               else /* success */
+                       host->reference_count++;
+       }
+
+       if (host->notifications) {
+               status = plugin_register_notification(callback_name, sensu_notification, &ud);
+               if (status != 0)
+                       WARNING("write_sensu plugin: plugin_register_notification (\"%s\") "
+                                       "failed with status %i.",
+                                       callback_name, status);
+               else
+                       host->reference_count++;
+       }
+
+       if (host->reference_count <= 1) {
+               /* Both callbacks failed => free memory.
+                * We need to unlock here, because sensu_free() will lock.
+                * This is not a race condition, because we're the only one
+                * holding a reference. */
+               pthread_mutex_unlock(&host->lock);
+               sensu_free(host);
+               return -1;
+       }
+
+       host->reference_count--;
+       pthread_mutex_unlock(&host->lock);
+
+       return status;
+} /* }}} int sensu_config_node */
+
+static int sensu_config(oconfig_item_t *ci) /* {{{ */
+{
+       int              i;
+       oconfig_item_t  *child;
+       int              status;
+       struct str_list sensu_tags_arr;
+
+       sensu_tags_arr.nb_strs = 0;
+       sensu_tags_arr.strs = NULL;
+
+       for (i = 0; i < ci->children_num; i++)  {
+               child = &ci->children[i];
+
+               if (strcasecmp("Node", child->key) == 0) {
+                       sensu_config_node(child);
+               } else if (strcasecmp(child->key, "attribute") == 0) {
+                       if (child->values_num != 2) {
+                               WARNING("sensu attributes need both a key and a value.");
+                               continue;
+                       }
+                       if (child->values[0].type != OCONFIG_TYPE_STRING ||
+                                       child->values[1].type != OCONFIG_TYPE_STRING) {
+                               WARNING("sensu attribute needs string arguments.");
+                               continue;
+                       }
+
+                       strarray_add(&sensu_attrs, &sensu_attrs_num, child->values[0].value.string);
+                       strarray_add(&sensu_attrs, &sensu_attrs_num, child->values[1].value.string);
+
+                       DEBUG("write_sensu plugin: New attribute: %s => %s",
+                                       child->values[0].value.string,
+                                       child->values[1].value.string);
+               } else if (strcasecmp(child->key, "tag") == 0) {
+                       char *tmp = NULL;
+                       status = cf_util_get_string(child, &tmp);
+                       if (status != 0)
+                               continue;
+
+                       status = add_str_to_list(&sensu_tags_arr, tmp);
+                       sfree(tmp);
+                       if (status != 0)
+                               continue;
+                       DEBUG("write_sensu plugin: Got tag: %s", tmp);
+               } else {
+                       WARNING("write_sensu plugin: Ignoring unknown "
+                                "configuration option \"%s\" at top level.",
+                                child->key);
+               }
+       }
+       if (sensu_tags_arr.nb_strs > 0) {
+               sfree (sensu_tags);
+               sensu_tags = build_json_str_list("tags", &sensu_tags_arr);
+               free_str_list(&sensu_tags_arr);
+               if (sensu_tags == NULL) {
+                       ERROR("write_sensu plugin: Unable to alloc memory");
+                       return -1;
+               }
+       }
+       return 0;
+} /* }}} int sensu_config */
+
+void module_register(void)
+{
+       plugin_register_complex_config("write_sensu", sensu_config);
+}
+
+/* vim: set sw=8 sts=8 ts=8 noet : */
diff --git a/src/write_tsdb.c b/src/write_tsdb.c
new file mode 100644 (file)
index 0000000..27ea473
--- /dev/null
@@ -0,0 +1,657 @@
+/**
+ * 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 <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(GAUGE_FORMAT, 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(GAUGE_FORMAT, 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') {
+            if (vl->type_instance[0] == '\0') {
+                ssnprintf(ret, ret_len, "%s%s.%s.%s", prefix, vl->plugin,
+                        vl->type, ds_name);
+            } else {
+                ssnprintf(ret, ret_len, "%s%s.%s.%s.%s", prefix, vl->plugin,
+                        vl->type, vl->type_instance, ds_name);
+            }
+        } else { /* vl->plugin_instance != "" */
+            if (vl->type_instance[0] == '\0') {
+                ssnprintf(ret, ret_len, "%s%s.%s.%s.%s", prefix, vl->plugin,
+                        vl->plugin_instance, vl->type, ds_name);
+            } else {
+                ssnprintf(ret, ret_len, "%s%s.%s.%s.%s.%s", prefix,
+                        vl->plugin, vl->plugin_instance, vl->type,
+                        vl->type_instance, ds_name);
+            }
+        }
+    } else { /* ds_name == NULL */
+        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.%s", prefix, vl->plugin,
+                        vl->type_instance, vl->type);
+            }
+        } else { /* vl->plugin_instance != "" */
+            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.%s", prefix, vl->plugin,
+                        vl->plugin_instance, vl->type, 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 52beb65f8a5d21d32880f81a58be887363390873..a423bb6ad701342283be0e1339a52f76d0fd13b7 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 3a54ad8d57d92c97a6ef9b2050c8b68e02fef682..f0d23239a82ab158c03c669f9a96cf2fc7f8dd24 100644 (file)
@@ -3,6 +3,8 @@
  * Copyright (C) 2009  Anthony Dewhurst
  * Copyright (C) 2012  Aurelien Rougemont
  * Copyright (C) 2013  Xin Li
+ * Copyright (C) 2014  Marc Fournier
+ * Copyright (C) 2014  Wilfried Goesgens
  *
  * 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
@@ -21,6 +23,8 @@
  *   Anthony Dewhurst <dewhurst at gmail>
  *   Aurelien Rougemont <beorn at gandi.net>
  *   Xin Li <delphij at FreeBSD.org>
+ *   Marc Fournier <marc.fournier at camptocamp.com>
+ *   Wilfried Goesgens <dothebart at citadel.org>
  **/
 
 #include "collectd.h"
  * Global variables
  */
 
-#if !defined(__FreeBSD__)
+#if defined(KERNEL_LINUX)
+#include "utils_llist.h"
+#define ZOL_ARCSTATS_FILE "/proc/spl/kstat/zfs/arcstats"
+
+typedef        llist_t kstat_t;
+
+static long long get_zfs_value(kstat_t *zfs_stats  __attribute__((unused)),
+               char *name)
+{
+       llentry_t *e;
+
+       e = llist_search (zfs_stats, name);
+       if (e == NULL)
+       {
+               ERROR ("zfs_arc plugin: `llist_search` failed for key: '%s'.", name);
+               return (-1);
+       }
+
+       return (*(long long int*)e->value);
+}
+
+#elif !defined(__FreeBSD__) // Solaris
 extern kstat_ctl_t *kc;
 
 static long long get_zfs_value(kstat_t *ksp, char *name)
@@ -39,7 +64,7 @@ static long long get_zfs_value(kstat_t *ksp, char *name)
 
        return (get_kstat_value(ksp, name));
 }
-#else
+#else // FreeBSD
 #include <sys/types.h>
 #include <sys/sysctl.h>
 
@@ -147,7 +172,75 @@ static int za_read (void)
        value_t  l2_io[2];
        kstat_t  *ksp   = NULL;
 
-#if !defined(__FreeBSD__)
+#if KERNEL_LINUX
+       long long int *llvalues = NULL;
+       char file_contents[1024 * 10];
+       char *fields[3];
+       int numfields;
+       ssize_t len;
+
+       ksp = llist_create ();
+       if (ksp == NULL)
+       {
+               ERROR ("zfs_arc plugin: `llist_create' failed.");
+               return (-1);
+       }
+
+       len = read_file_contents (ZOL_ARCSTATS_FILE, file_contents, sizeof(file_contents));
+       if (len > 1)
+       {
+
+               int i=0;
+               char *pnl = file_contents;
+               char *pnnl;
+
+               file_contents[len] = '\0';
+
+               while (pnl != NULL)
+               {
+                       pnl = strchr(pnl, '\n');
+                       i++;
+                       if (pnl && (*pnl != '\0'))
+                               pnl++;
+               }
+
+               if (i > 0)
+               {
+                       llentry_t *e;
+                       llvalues = malloc(sizeof(long long int) * i);
+                       int j = 0;
+
+                       pnl = file_contents;
+                       while (pnl != NULL)
+                       {
+                               pnnl = strchr(pnl, '\n');
+                               if (pnnl != NULL)
+                                       *pnnl = '\0';
+
+                               numfields = strsplit (pnl, fields, 4);
+                               if (numfields == 3)
+                               {
+                                       llvalues[j] = atoll (fields[2]);
+
+                                       e = llentry_create (fields[0], &llvalues[j]);
+                                       if (e == NULL)
+                                       {
+                                               ERROR ("zfs_arc plugin: `llentry_create' failed.");
+                                       }
+                                       else
+                                       {
+                                               llist_append (ksp, e);
+                                       }
+                                       j++;
+                               }
+                               pnl = pnnl;
+                               if (pnl != NULL)
+                                       pnl ++;
+                       }
+               }
+       }
+
+#elif !defined(__FreeBSD__) // Solaris
        get_kstat (&ksp, "zfs", 0, "arcstats");
        if (ksp == NULL)
        {
@@ -177,7 +270,7 @@ static int za_read (void)
        /* Issue indicators */
        za_read_derive (ksp, "mutex_miss", "mutex_operations", "miss");
        za_read_derive (ksp, "hash_collisions", "hash_collisions", "");
-       
+
        /* Evictions */
        za_read_derive (ksp, "evict_l2_cached",     "cache_eviction", "cached");
        za_read_derive (ksp, "evict_l2_eligible",   "cache_eviction", "eligible");
@@ -208,12 +301,23 @@ static int za_read (void)
 
        za_submit ("io_octets", "L2", l2_io, /* num values = */ 2);
 
+#if defined(KERNEL_LINUX)
+       if (llvalues != NULL)
+       {
+               free(llvalues);
+       }
+       if (ksp != NULL)
+       {
+               llist_destroy (ksp);
+       }
+#endif
+
        return (0);
 } /* int za_read */
 
 static int za_init (void) /* {{{ */
 {
-#if !defined(__FreeBSD__)
+#if !defined(__FreeBSD__) && !defined(KERNEL_LINUX) // Solaris
        /* kstats chain already opened by update_kstat (using *kc), verify everything went fine. */
        if (kc == NULL)
        {
diff --git a/src/zookeeper.c b/src/zookeeper.c
new file mode 100644 (file)
index 0000000..63ee6c9
--- /dev/null
@@ -0,0 +1,322 @@
+/**
+ * collectd - src/zookeeper.c
+ * Copyright (C) 2014       Google, Inc.
+ *
+ * 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:
+ *   Jeremy Katz <jeremy at katzbox.net>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+#include <netdb.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+
+#define ZOOKEEPER_DEF_HOST "127.0.0.1"
+#define ZOOKEEPER_DEF_PORT "2181"
+
+static char *zk_host = NULL;
+static char *zk_port = NULL;
+
+static const char *config_keys[] =
+{
+       "Host",
+       "Port"
+};
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+
+static int zookeeper_config(const char *key, const char *value)
+{
+       if (strncmp(key, "Host", strlen("Host")) == 0)
+       {
+               sfree (zk_host);
+               zk_host = strdup (value);
+       }
+       else if (strncmp(key, "Port", strlen("Port")) == 0)
+       {
+               sfree (zk_port);
+               zk_port = strdup (value);
+       }
+       else
+       {
+               return -1;
+       }
+       return 0;
+}
+
+static void zookeeper_submit_gauge (const char * type, const char * type_inst, gauge_t val)
+{
+       value_t values[1];
+       value_list_t vl = VALUE_LIST_INIT;
+
+       values[0].gauge = val;
+
+       vl.values = values;
+       vl.values_len = 1;
+       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       sstrncpy (vl.plugin, "zookeeper", sizeof (vl.plugin));
+       sstrncpy (vl.type, type, sizeof (vl.type));
+       if (type_inst != NULL)
+               sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
+
+       plugin_dispatch_values (&vl);
+} /* zookeeper_submit_gauge */
+
+static void zookeeper_submit_derive (const char * type, const char * type_inst, derive_t val)
+{
+       value_t values[1];
+       value_list_t vl = VALUE_LIST_INIT;
+
+       values[0].derive = val;
+
+       vl.values = values;
+       vl.values_len = 1;
+       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       sstrncpy (vl.plugin, "zookeeper", sizeof (vl.plugin));
+       sstrncpy (vl.type, type, sizeof (vl.type));
+       if (type_inst != NULL)
+               sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
+
+       plugin_dispatch_values (&vl);
+} /* zookeeper_submit_derive */
+
+static int zookeeper_connect (void)
+{
+       int sk = -1;
+       int status;
+       struct addrinfo ai_hints;
+       struct addrinfo *ai;
+       struct addrinfo *ai_list;
+       char *host;
+       char *port;
+
+       memset ((void *) &ai_hints, '\0', sizeof (ai_hints));
+       ai_hints.ai_family   = AF_UNSPEC;
+       ai_hints.ai_socktype = SOCK_STREAM;
+
+       host = (zk_host != NULL) ? zk_host : ZOOKEEPER_DEF_HOST;
+       port = (zk_port != NULL) ? zk_port : ZOOKEEPER_DEF_PORT;
+       status = getaddrinfo (host, port, &ai_hints, &ai_list);
+       if (status != 0)
+       {
+               char errbuf[1024];
+               INFO ("getaddrinfo failed: %s",
+                         (status == EAI_SYSTEM)
+                         ? sstrerror (errno, errbuf, sizeof (errbuf))
+                         : gai_strerror (status));
+               return (-1);
+       }
+
+       for (ai = ai_list; ai != NULL; ai = ai->ai_next)
+       {
+               sk = socket (ai->ai_family, SOCK_STREAM, 0);
+               if (sk < 0)
+               {
+                       char errbuf[1024];
+                       WARNING ("zookeeper: socket(2) failed: %s",
+                                        sstrerror (errno, errbuf, sizeof(errbuf)));
+                       continue;
+               }
+               status = (int) connect (sk, ai->ai_addr, ai->ai_addrlen);
+               if (status != 0)
+               {
+                       char errbuf[1024];
+                       close (sk);
+                       sk = -1;
+                       WARNING ("zookeeper: connect(2) failed: %s",
+                                        sstrerror (errno, errbuf, sizeof(errbuf)));
+                       continue;
+               }
+
+               /* connected */
+               break;
+       }
+
+       freeaddrinfo(ai_list);
+       return (sk);
+} /* int zookeeper_connect */
+
+static int zookeeper_query (char *buffer, size_t buffer_size)
+{
+       int sk = -1;
+       int status;
+       size_t buffer_fill;
+
+       sk = zookeeper_connect();
+       if (sk < 0)
+       {
+               ERROR ("zookeeper: Could not connect to daemon");
+               return (-1);
+       }
+
+       status = (int) swrite (sk, "mntr\r\n", strlen("mntr\r\n"));
+       if (status != 0)
+       {
+               char errbuf[1024];
+               ERROR ("zookeeper: write(2) failed: %s",
+                          sstrerror (errno, errbuf, sizeof (errbuf)));
+               close (sk);
+               return (-1);
+       }
+
+       memset (buffer, 0, buffer_size);
+       buffer_fill = 0;
+
+       while ((status = (int) recv (sk, buffer + buffer_fill,
+          buffer_size - buffer_fill, /* flags = */ 0)) != 0)
+       {
+               if (status < 0)
+               {
+                       char errbuf[1024];
+                       if ((errno == EAGAIN) || (errno == EINTR))
+                               continue;
+                       ERROR ("zookeeper: Error reading from socket: %s",
+                                  sstrerror (errno, errbuf, sizeof (errbuf)));
+                       close (sk);
+                       return (-1);
+               }
+
+               buffer_fill += (size_t) status;
+               if (status == 0)
+               {
+                       /* done reading from the socket */
+                       break;
+               }
+       } /* while (recv) */
+
+       status = 0;
+       if (buffer_fill == 0)
+       {
+               WARNING ("zookeeper: No data returned by MNTR command.");
+               status = -1;
+       }
+
+       close(sk);
+       return (status);
+} /* int zookeeper_query */
+
+
+static int zookeeper_read (void) {
+       char buf[4096];
+       char *ptr;
+       char *save_ptr;
+       char *line;
+       char *fields[2];
+
+       if (zookeeper_query (buf, sizeof (buf)) < 0)
+       {
+               return (-1);
+       }
+
+       ptr = buf;
+       save_ptr = NULL;
+       while ((line = strtok_r (ptr, "\n\r", &save_ptr)) != NULL)
+       {
+               ptr = NULL;
+               if (strsplit(line, fields, 2) != 2)
+               {
+                       continue;
+               }
+#define FIELD_CHECK(check, expected) \
+       (strncmp (check, expected, strlen(expected)) == 0)
+
+               if (FIELD_CHECK (fields[0], "zk_avg_latency"))
+               {
+                       zookeeper_submit_gauge ("latency", "avg", atol(fields[1]));
+               }
+               else if (FIELD_CHECK(fields[0], "zk_min_latency"))
+               {
+                       zookeeper_submit_gauge ("latency", "min", atol(fields[1]));
+               }
+               else if (FIELD_CHECK (fields[0], "zk_max_latency"))
+               {
+                       zookeeper_submit_gauge ("latency", "max", atol(fields[1]));
+               }
+               else if (FIELD_CHECK (fields[0], "zk_packets_received"))
+               {
+                       zookeeper_submit_derive ("packets", "received", atol(fields[1]));
+               }
+               else if (FIELD_CHECK (fields[0], "zk_packets_sent"))
+               {
+                       zookeeper_submit_derive ("packets", "sent", atol(fields[1]));
+               }
+               else if (FIELD_CHECK (fields[0], "zk_num_alive_connections"))
+               {
+                       zookeeper_submit_gauge ("current_connections", NULL, atol(fields[1]));
+               }
+               else if (FIELD_CHECK (fields[0], "zk_outstanding_requests"))
+               {
+                       zookeeper_submit_gauge ("requests", "outstanding", atol(fields[1]));
+               }
+               else if (FIELD_CHECK (fields[0], "zk_znode_count"))
+               {
+                       zookeeper_submit_gauge ("gauge", "znode", atol(fields[1]));
+               }
+               else if (FIELD_CHECK (fields[0], "zk_watch_count"))
+               {
+                       zookeeper_submit_gauge ("gauge", "watch", atol(fields[1]));
+               }
+               else if (FIELD_CHECK (fields[0], "zk_ephemerals_count"))
+               {
+                       zookeeper_submit_gauge ("gauge", "ephemerals", atol(fields[1]));
+               }
+               else if (FIELD_CHECK (fields[0], "zk_ephemerals_count"))
+               {
+                       zookeeper_submit_gauge ("gauge", "ephemerals", atol(fields[1]));
+               }
+               else if (FIELD_CHECK (fields[0], "zk_ephemerals_count"))
+               {
+                       zookeeper_submit_gauge ("gauge", "ephemerals", atol(fields[1]));
+               }
+               else if (FIELD_CHECK (fields[0], "zk_approximate_data_size"))
+               {
+                       zookeeper_submit_gauge ("bytes", "approximate_data_size", atol(fields[1]));
+               }
+               else if (FIELD_CHECK (fields[0], "zk_followers"))
+               {
+                       zookeeper_submit_gauge ("count", "followers", atol(fields[1]));
+               }
+               else if (FIELD_CHECK (fields[0], "zk_synced_followers"))
+               {
+                       zookeeper_submit_gauge ("count", "synced_followers", atol(fields[1]));
+               }
+               else if (FIELD_CHECK (fields[0], "zk_pending_syncs"))
+               {
+                       zookeeper_submit_gauge ("count", "pending_syncs", atol(fields[1]));
+               }
+               else
+               {
+                       DEBUG("Uncollected zookeeper MNTR field %s", fields[0]);
+               }
+       }
+
+       return (0);
+} /* zookeeper_read */
+
+void module_register (void)
+{
+       plugin_register_config ("zookeeper", zookeeper_config, config_keys, config_keys_num);
+       plugin_register_read ("zookeeper", zookeeper_read);
+} /* void module_register */
index 3a7fac860ad49c378b151f1d7f55f6b95cc845c5..b09be8e78227f350edbe8fc6bf96634f67a0a057 100755 (executable)
@@ -1,8 +1,8 @@
 #!/bin/sh
 
-DEFAULT_VERSION="5.4.2.git"
+DEFAULT_VERSION="5.5.0.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"