Merge branch 'collectd-4.8'
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Thu, 1 Oct 2009 19:34:21 +0000 (21:34 +0200)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Thu, 1 Oct 2009 19:34:21 +0000 (21:34 +0200)
Conflicts:
src/types.db

18 files changed:
AUTHORS
README
configure.in
src/Makefile.am
src/collectd-exec.pod
src/collectd.conf.pod
src/common.c
src/common.h
src/configfile.c
src/configfile.h
src/cpu.c
src/curl.c
src/exec.c
src/netapp.c [new file with mode: 0644]
src/plugin.c
src/target_scale.c [new file with mode: 0644]
src/tokyotyrant.c
src/types.db

diff --git a/AUTHORS b/AUTHORS
index 8d0a022..5d443d9 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -147,6 +147,9 @@ Sjoerd van der Berg <harekiet at gmail.com>
 Stefan Hacker <stefan.hacker at web.de>
  - teamspeak2 plugin.
 
+Sven Trenkel <collectd at semidefinite.de>
+ - netapp plugin.
+
 Tomasz Pala <gotar at pld-linux.org>
  - conntrack plugin.
 
diff --git a/README b/README
index ea53dba..a737f86 100644 (file)
--- a/README
+++ b/README
@@ -148,6 +148,10 @@ Features
       MySQL server statistics: Commands issued, handlers triggered, thread
       usage, query cache utilization and traffic/octets sent and received.
 
+    - netapp
+      Plugin to query performance values from a NetApp storage system using the
+      “Manage ONTAP” SDK provided by NetApp.
+
     - netlink
       Very detailed Linux network interface and routing statistics. You can get
       (detailed) information on interfaces, qdiscs, classes, and, if you can
@@ -503,6 +507,10 @@ Prerequisites
     Unsurprisingly used by the `mysql' plugin.
     <http://dev.mysql.com/>
 
+  * libnatapp (optional)
+    Required for the “netapp” plugin.
+    This library is part of the “Manage ONTAP SDK” published by NetApp.
+
   * libnetlink (optional)
     Used, obviously, for the `netlink' plugin.
     <http://www.linuxfoundation.org/en/Net:Iproute2>
index a898d74..08de43b 100644 (file)
@@ -262,6 +262,22 @@ AC_CHECK_HEADERS(sys/sysctl.h, [], [],
 #endif
 ])
 
+AC_MSG_CHECKING([for sysctl kern.cp_times])
+if test -x /sbin/sysctl
+then
+       /sbin/sysctl kern.cp_times 2>/dev/null
+       if test $? -eq 0
+       then
+               AC_MSG_RESULT([yes])
+               AC_DEFINE(HAVE_SYSCTL_KERN_CP_TIMES, 1,
+               [Define if sysctl supports kern.cp_times])
+       else
+               AC_MSG_RESULT([no])
+       fi
+else
+       AC_MSG_RESULT([no])
+fi
+
 # For hddtemp module
 AC_CHECK_HEADERS(linux/major.h libgen.h)
 
@@ -1928,6 +1944,78 @@ fi
 AM_CONDITIONAL(BUILD_WITH_LIBNETLINK, test "x$with_libnetlink" = "xyes")
 # }}}
 
+# --with-libnetapp {{{
+AC_ARG_VAR([LIBNETAPP_CPPFLAGS], [C preprocessor flags required to build with libnetapp])
+AC_ARG_VAR([LIBNETAPP_LDFLAGS],  [Linker flags required to build with libnetapp])
+AC_ARG_VAR([LIBNETAPP_LIBS],     [Other libraries required to link against libnetapp])
+LIBNETAPP_CPPFLAGS="$LIBNETAPP_CPPFLAGS"
+LIBNETAPP_LDFLAGS="$LIBNETAPP_LDFLAGS"
+LIBNETAPP_LIBS="$LIBNETAPP_LIBS"
+AC_ARG_WITH(libnetapp, [AS_HELP_STRING([--with-libnetapp@<:@=PREFIX@:>@], [Path to libnetapp.])],
+[
+ if test -d "$withval"
+ then
+        LIBNETAPP_CPPFLAGS="$LIBNETAPP_CPPFLAGS -I$withval/include"
+        LIBNETAPP_LDFLAGS="$LIBNETAPP_LDFLAGS -L$withval/lib"
+        with_libnetapp="yes"
+ else
+        with_libnetapp="$withval"
+ fi
+],
+[
+ with_libnetapp="yes"
+])
+
+SAVE_CPPFLAGS="$CPPFLAGS"
+SAVE_LDFLAGS="$LDFLAGS"
+CPPFLAGS="$CPPFLAGS $LIBNETAPP_CPPFLAGS"
+LDFLAGS="$LDFLAGS $LIBNETAPP_LDFLAGS"
+
+if test "x$with_libnetapp" = "xyes"
+then
+       if test "x$LIBNETAPP_CPPFLAGS" != "x"
+       then
+               AC_MSG_NOTICE([netapp CPPFLAGS: $LIBNETAPP_CPPFLAGS])
+       fi
+       AC_CHECK_HEADERS(netapp_api.h,
+               [with_libnetapp="yes"],
+               [with_libnetapp="no (netapp_api.h not found)"])
+fi
+
+if test "x$with_libnetapp" = "xyes"
+then
+       if test "x$LIBNETAPP_LDFLAGS" != "x"
+       then
+               AC_MSG_NOTICE([netapp LDFLAGS: $LIBNETAPP_LDFLAGS])
+       fi
+
+       if test "x$LIBNETAPP_LIBS" = "x"
+       then
+               LIBNETAPP_LIBS="-lpthread -lxml -ladt -lssl -lm"
+       fi
+       AC_MSG_NOTICE([netapp LIBS: $LIBNETAPP_LIBS])
+
+       AC_CHECK_LIB(netapp, na_server_invoke_elem,
+               [with_libnetapp="yes"],
+               [with_libnetapp="no (symbol na_server_invoke_elem not found)"],
+               [$LIBNETAPP_LIBS])
+       LIBNETAPP_LIBS="-lnetapp $LIBNETAPP_LIBS"
+fi
+
+CPPFLAGS="$SAVE_CPPFLAGS"
+LDFLAGS="$SAVE_LDFLAGS"
+
+if test "x$with_libnetapp" = "xyes"
+then
+       AC_DEFINE(HAVE_LIBNETAPP, 1, [Define to 1 if you have the netapp library (-lnetapp).])
+fi
+
+AC_SUBST(LIBNETAPP_CPPFLAGS)
+AC_SUBST(LIBNETAPP_LDFLAGS)
+AC_SUBST(LIBNETAPP_LIBS)
+AM_CONDITIONAL(BUILD_WITH_LIBNETAPP, test "x$with_libnetapp" = "xyes")
+# }}}
+
 # --with-libnetsnmp {{{
 with_snmp_config="net-snmp-config"
 with_snmp_cflags=""
@@ -3787,6 +3875,7 @@ AC_PLUGIN([memcached],   [yes],                [memcached statistics])
 AC_PLUGIN([memory],      [$plugin_memory],     [Memory usage])
 AC_PLUGIN([multimeter],  [$plugin_multimeter], [Read multimeter values])
 AC_PLUGIN([mysql],       [$with_libmysql],     [MySQL statistics])
+AC_PLUGIN([netapp],      [$with_libnetapp],    [NetApp plugin])
 AC_PLUGIN([netlink],     [$with_libnetlink],   [Enhanced Linux network statistics])
 AC_PLUGIN([network],     [yes],                [Network communication plugin])
 AC_PLUGIN([nfs],         [$plugin_nfs],        [NFS statistics])
@@ -3817,6 +3906,7 @@ AC_PLUGIN([tail],        [yes],                [Parsing of logfiles])
 AC_PLUGIN([tape],        [$plugin_tape],       [Tape drive statistics])
 AC_PLUGIN([target_notification], [yes],        [The notification target])
 AC_PLUGIN([target_replace], [yes],             [The replace target])
+AC_PLUGIN([target_scale],[yes],                [The scale target])
 AC_PLUGIN([target_set],  [yes],                [The set target])
 AC_PLUGIN([tcpconns],    [$plugin_tcpconns],   [TCP connection statistics])
 AC_PLUGIN([teamspeak2],  [yes],                [TeamSpeak2 server statistics])
@@ -4015,6 +4105,7 @@ Configuration:
     libkvm  . . . . . . . $with_libkvm
     libmemcached  . . . . $with_libmemcached
     libmysql  . . . . . . $with_libmysql
+    libnetapp . . . . . . $with_libnetapp
     libnetlink  . . . . . $with_libnetlink
     libnetsnmp  . . . . . $with_libnetsnmp
     libnotify . . . . . . $with_libnotify
@@ -4087,6 +4178,7 @@ Configuration:
     memory  . . . . . . . $enable_memory
     multimeter  . . . . . $enable_multimeter
     mysql . . . . . . . . $enable_mysql
+    netapp  . . . . . . . $enable_netapp
     netlink . . . . . . . $enable_netlink
     network . . . . . . . $enable_network
     nfs . . . . . . . . . $enable_nfs
@@ -4117,6 +4209,7 @@ Configuration:
     tape  . . . . . . . . $enable_tape
     target_notification . $enable_target_notification
     target_replace  . . . $enable_target_replace
+    target_scale  . . . . $enable_target_scale
     target_set  . . . . . $enable_target_set
     tcpconns  . . . . . . $enable_tcpconns
     teamspeak2  . . . . . $enable_teamspeak2
index 2a83659..2e9f265 100644 (file)
@@ -570,6 +570,16 @@ endif
 collectd_DEPENDENCIES += mysql.la
 endif
 
+if BUILD_PLUGIN_NETAPP
+pkglib_LTLIBRARIES += netapp.la
+netapp_la_SOURCES = netapp.c
+netapp_la_CPPFLAGS = $(AM_CPPFLAGS) $(LIBNETAPP_CPPFLAGS)
+netapp_la_LDFLAGS = -module -avoid-version $(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
@@ -911,6 +921,14 @@ collectd_LDADD += "-dlopen" target_replace.la
 collectd_DEPENDENCIES += target_replace.la
 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
+endif
+
 if BUILD_PLUGIN_TARGET_SET
 pkglib_LTLIBRARIES += target_set.la
 target_set_la_SOURCES = target_set.c
index b95779d..81b3a2e 100644 (file)
@@ -230,6 +230,23 @@ associated with a certain value.
 
 =back
 
+=head1 ENVIRONMENT
+
+The following environment variables are set by the plugin before calling
+I<exec>:
+
+=over 4
+
+=item COLLECTD_INTERVAL
+
+Value of the global interval setting.
+
+=item COLLECTD_HOSTNAME
+
+Hostname used by I<collectd> to dispatch local values.
+
+=back
+
 =head1 USING NAGIOS PLUGINS
 
 Though the interface is far from perfect, there are tons of plugins for Nagios.
index 43a322b..f7531cd 100644 (file)
@@ -501,6 +501,10 @@ 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<MeasureResponseTime> B<true>|B<false>
+
+Measure response time for the request. Disabled by default.
+
 =item B<E<lt>MatchE<gt>>
 
 One or more B<Match> blocks that define how to match information in the data
@@ -1640,6 +1644,454 @@ or SQL threads are not running.
 
 =back
 
+=head2 Plugin C<netapp>
+
+The netapp plugin can collect various performance and capacity informations
+from a NetApp filer using the NetApp API.
+
+To collect these data collectd will log in to the NetApp via HTTP(S) and HTTP
+basic authentication.
+
+B<Do not use a regular user for this!> Create a special collectd user with just
+the minimum of capabilities needed. The user only needs the "login-http-admin"
+capability as well as a few more depending on which data will be collected.
+Required capabilities are documented below.
+
+=head3 Synopsis
+
+ <Plugin "netapp">
+   <Host "netapp1.example.com">
+    Protocol      "https"
+    Address       "10.0.0.1"
+    Port          443
+    User          "username"
+    Password      "aef4Aebe"
+    Interval      30
+    
+    <WAFL>
+      Interval 30
+      GetNameCache   true
+      GetDirCache    true
+      GetBufferCache true
+      GetInodeCache  true
+    </WAFL>
+    
+    <Disks>
+      Interval 30
+      GetBusy true
+    </Disks>
+    
+    <VolumePerf>
+      Interval 30
+      GetIO      "volume0"
+      IgnoreSelectedIO      false
+      GetOps     "volume0"
+      IgnoreSelectedOps     false
+      GetLatency "volume0"
+      IgnoreSelectedLatency false
+    </VolumePerf>
+    
+    <VolumeUsage>
+      Interval 30
+      GetCapacity "vol0"
+      GetCapacity "vol1"
+      IgnoreSelectedCapacity false
+      GetSnapshot "vol1"
+      GetSnapshot "vol3"
+      IgnoreSelectedSnapshot false
+    </VolumeUsage>
+    
+    <System>
+      Interval 30
+      GetCPULoad     true
+      GetInterfaces  true
+      GetDiskOps     true
+      GetDiskIO      true
+    </System>
+   </Host>
+ </Plugin>
+
+The netapp plugin accepts the following configuration options:
+
+=over 4
+
+=item B<Host> I<Name>
+
+A host block defines one NetApp filer. It will appear in collectd with the name
+you specify here which does not have to be its real name nor its hostname.
+
+=item B<Protocol> B<httpd>|B<http>
+
+The protocol collectd will use to query this host.
+
+Optional
+
+Type: string
+
+Default: https
+
+Valid options: http, https
+
+=item B<Address> I<Address>
+
+The hostname or IP address of the host.
+
+Optional
+
+Type: string
+
+Default: The "host" block's name.
+
+=item B<Port> I<Port>
+
+The TCP port to connect to on the host.
+
+Optional
+
+Type: integer
+
+Default: 80 for protocol "http", 443 for protocol "https"
+
+=item B<User> I<User>
+
+=item B<Password> I<Password>
+
+The username and password to use to login to the NetApp.
+
+Mandatory
+
+Type: string
+
+=item B<Interval> I<Interval>
+
+B<TODO>
+
+=back
+
+The following options decide what kind of data will be collected. You can
+either use them as a block and fine tune various parameters inside this block,
+use them as a single statement to just accept all default values, or omit it to
+not collect any data.
+
+The following options are valid inside all blocks:
+
+=over 4
+
+=item B<Interval> I<Seconds>
+
+Collect the respective statistics every I<Seconds> seconds. Defaults to the
+host specific setting.
+
+=back
+
+=head3 The System block
+
+This will collect various performance data about the whole system.
+
+B<Note:> To get this data the collectd user needs the
+"api-perf-object-get-instances" capability.
+
+=over 4
+
+=item B<Interval> I<Seconds>
+
+Collect disk statistics every I<Seconds> seconds.
+
+=item B<GetCPULoad> B<true>|B<false>
+
+If you set this option to true the current CPU usage will be read. This will be
+the average usage between all CPUs in your NetApp without any information about
+individual CPUs.
+
+B<Note:> These are the same values that the NetApp CLI command "sysstat"
+returns in the "CPU" field.
+
+Optional
+
+Type: boolean
+
+Default: true
+
+Result: Two value lists of type "cpu", and type instances "idle" and "system".
+
+=item B<GetInterfaces> B<true>|B<false>
+
+If you set this option to true the current traffic of the network interfaces
+will be read. This will be the total traffic over all interfaces of your NetApp
+without any information about individual interfaces.
+
+B<Note:> This is the same values that the NetApp CLI command "sysstat" returns
+in the "Net kB/s" field.
+
+B<Or is it?>
+
+Optional
+
+Type: boolean
+
+Default: true
+
+Result: One value list of type "if_octects".
+
+=item B<GetDiskIO> B<true>|B<false>
+
+If you set this option to true the current IO throughput will be read. This
+will be the total IO of your NetApp without any information about individual
+disks, volumes or aggregates.
+
+B<Note:> This is the same values that the NetApp CLI command "sysstat" returns
+in the "DiskE<nbsp>kB/s" field.
+
+Optional
+
+Type: boolean
+
+Default: true
+
+Result: One value list of type "disk_octets".
+
+=item B<GetDiskOps> B<true>|B<false>
+
+If you set this option to true the current number of HTTP, NFS, CIFS, FCP,
+iSCSI, etc. operations will be read. This will be the total number of
+operations on your NetApp without any information about individual volumes or
+aggregates.
+
+B<Note:> These are the same values that the NetApp CLI command "sysstat"
+returns in the "NFS", "CIFS", "HTTP", "FCP" and "iSCSI" fields.
+
+Optional
+
+Type: boolean
+
+Default: true
+
+Result: A variable number of value lists of type "disk_ops_complex". Each type
+of operation will result in one value list with the name of the operation as
+type instance.
+
+=back
+
+=head3 The WAFL block
+
+This will collect various performance data about the WAFL file system. At the
+moment this just means cache performance.
+
+B<Note:> To get this data the collectd user needs the
+"api-perf-object-get-instances" capability.
+
+B<Note:> The interface to get these values is classified as "Diagnostics" by
+NetApp. This means that it is not guaranteed to be stable even between minor
+releases.
+
+=over 4
+
+=item B<Interval> I<Seconds>
+
+Collect disk statistics every I<Seconds> seconds.
+
+=item B<GetNameCache> B<true>|B<false>
+
+Optional
+
+Type: boolean
+
+Default: true
+
+Result: One value list of type "cache_ratio" and type instance
+"name_cache_hit".
+
+=item B<GetDirCache> B<true>|B<false>
+
+Optional
+
+Type: boolean
+
+Default: true
+
+Result: One value list of type "cache_ratio" and type instance "find_dir_hit".
+
+=item B<GetInodeCache> B<true>|B<false>
+
+Optional
+
+Type: boolean
+
+Default: true
+
+Result: One value list of type "cache_ratio" and type instance
+"inode_cache_hit".
+
+=item B<GetBufferCache> B<true>|B<false>
+
+B<Note:> This is the same value that the NetApp CLI command "sysstat" returns
+in the "Cache hit" field.
+
+Optional
+
+Type: boolean
+
+Default: true
+
+Result: One value list of type "cache_ratio" and type instance "buf_hash_hit".
+
+=back
+
+=head3 The Disks block
+
+This will collect performance data about the individual disks in the NetApp.
+
+B<Note:> To get this data the collectd user needs the
+"api-perf-object-get-instances" capability.
+
+=over 4
+
+=item B<Interval> I<Seconds>
+
+Collect disk statistics every I<Seconds> seconds.
+
+=item B<GetBusy> B<true>|B<false>
+
+If you set this option to true the busy time of all disks will be calculated
+and the value of the busiest disk in the system will be written.
+
+B<Note:> This is the same values that the NetApp CLI command "sysstat" returns
+in the "Disk util" field. Probably.
+
+Optional
+
+Type: boolean
+
+Default: true
+
+Result: One value list of type "percent" and type instance "disk_busy".
+
+=back
+
+=head3 The VolumePerf block
+
+This will collect various performance data about the individual volumes.
+
+You can select which data to collect about which volume using the following
+options. They follow the standard ignorelist semantic.
+
+B<Note:> To get this data the collectd user needs the
+I<api-perf-object-get-instances> capability.
+
+=over 4
+
+=item B<Interval> I<Seconds>
+
+Collect volume performance data every I<Seconds> seconds.
+
+=item B<GetIO> I<Volume>
+
+=item B<GetOps> I<Volume>
+
+=item B<GetLatency> I<Volume>
+
+Select the given volume for IO, operations or latency statistics collection.
+The argument is the name of the volume without the C</vol/> prefix.
+
+Since the standard ignorelist functionality is used here, you can use a string
+starting and ending with a slash to specify regular expression matching: To
+match the volumes "vol0", "vol2" and "vol7", you can use this regular
+expression:
+
+  GetIO "/^vol[027]$/"
+
+If no regular expression is specified, an exact match is required. Both,
+regular and exact matching are case sensitive.
+
+If no volume was specified at all for either of the three options, that data
+will be collected for all available volumes.
+
+=item B<IgnoreSelectedIO> B<true>|B<false>
+
+=item B<IgnoreSelectedOps> B<true>|B<false>
+
+=item B<IgnoreSelectedLatency> B<true>|B<false>
+
+When set to B<true>, the volumes selected for IO, operations or latency
+statistics collection will be ignored and the data will be collected for all
+other volumes.
+
+When set to B<false>, data will only be collected for the specified volumes and
+all other volumes will be ignored.
+
+If no volumes have been specified with the above B<Get*> options, all volumes
+will be collected regardless of the B<IgnoreSelected*> option.
+
+Defaults to B<false>
+
+=back
+
+=head3 The VolumeUsage block
+
+This will collect capacity data about the individual volumes.
+
+B<Note:> To get this data the collectd user needs the I<api-volume-list-info>
+capability.
+
+=over 4
+
+=item B<Interval> I<Seconds>
+
+Collect volume usage statistics every I<Seconds> seconds.
+
+=item B<GetCapacity> I<VolumeName>
+
+The current capacity of the volume will be collected. This will result in two
+to four value lists, depending on the configuration of the volume. All data
+sources are of type "df_complex" with the name of the volume as
+plugin_instance.
+
+There will be type_instances "used" and "free" for the number of used and
+available bytes on the volume.  If the volume has some space reserved for
+snapshots, a type_instance "snap_reserved" will be available.  If the volume
+has SIS enabled, a type_instance "sis_saved" will be available. This is the
+number of bytes saved by the SIS feature.
+
+B<Note:> The current NetApp API has a bug that results in this value being
+reported as a 32E<nbsp>bit number. This plugin tries to guess the correct
+number which works most of the time.  If you see strange values here, bug
+NetApp support to fix this.
+
+Repeat this option to specify multiple volumes.
+
+=item B<IgnoreSelectedCapacity> B<true>|B<false>
+
+Specify whether to collect only the volumes selected by the B<GetCapacity>
+option or to ignore those volumes. B<IgnoreSelectedCapacity> defaults to
+B<false>. However, if no B<GetCapacity> option is specified at all, all
+capacities will be selected anyway.
+
+=item B<GetSnapshot> I<VolumeName>
+
+Select volumes from which to collect snapshot information.
+
+Usually, the space used for snapshots is included in the space reported as
+"used". If snapshot information is collected as well, the space used for
+snapshots is subtracted from the used space.
+
+To make things even more interesting, it is possible to reserve space to be
+used for snapshots. If the space required for snapshots is less than that
+reserved space, there is "reserved free" and "reserved used" space in addition
+to "free" and "used". If the space required for snapshots exceeds the reserved
+space, that part allocated in the normal space is subtracted from the "used"
+space again.
+
+Repeat this option to specify multiple volumes.
+
+=item B<IgnoreSelectedSnapshot>
+
+Specify whether to collect only the volumes selected by the B<GetSnapshot>
+option or to ignore those volumes. B<IgnoreSelectedSnapshot> defaults to
+B<false>. However, if no B<GetSnapshot> option is specified at all, all
+capacities will be selected anyway.
+
+=back
+
 =head2 Plugin C<netlink>
 
 The C<netlink> plugin uses a netlink socket to query the Linux kernel about
index 7c2c30e..c6a651d 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * collectd - src/common.c
- * Copyright (C) 2005-2008  Florian octo Forster
+ * Copyright (C) 2005-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
 # include <arpa/inet.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
+
 #ifdef HAVE_LIBKSTAT
 extern kstat_ctl_t *kc;
 #endif
@@ -1071,3 +1080,56 @@ counter_t counter_diff (counter_t old_value, counter_t new_value)
 
        return (diff);
 } /* counter_t counter_to_gauge */
+
+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 */
index 6682e1c..019e8b6 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * collectd - src/common.h
- * Copyright (C) 2005-2008  Florian octo Forster
+ * Copyright (C) 2005-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
@@ -285,4 +285,8 @@ int read_file_contents (const char *filename, char *buf, int bufsize);
 
 counter_t counter_diff (counter_t old_value, counter_t new_value);
 
+/* 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);
+
 #endif /* COMMON_H */
index d401a2e..1a957f6 100644 (file)
@@ -917,3 +917,43 @@ int cf_read (char *filename)
 
        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 plugin 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 that the config option is a string. The string is then converted to
+ * a port number using `service_name_to_port_number' and returned. Returns the
+ * port number in the range [1-65535] or less than zero upon failure. */
+int cf_util_get_port_number (const oconfig_item_t *ci) /* {{{ */
+{
+       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
+       {
+               ERROR ("cf_util_get_port_number: The %s plugin requires "
+                               "exactly one string argument.", ci->key);
+               return (-1);
+       }
+
+       return (service_name_to_port_number (ci->values[0].value.string));
+} /* }}} int cf_util_get_port_number */
index 3952c18..74d074e 100644 (file)
@@ -86,4 +86,14 @@ int cf_read (char *filename);
 int global_option_set (const char *option, const char *value);
 const char *global_option_get (const char *option);
 
+/* 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 that the config option is a string. The string is then converted to
+ * a port number using `service_name_to_port_number' and returned. Returns the
+ * port number in the range [1-65535] or less than zero upon failure. */
+int cf_util_get_port_number (const oconfig_item_t *ci);
+
 #endif /* defined(CONFIGFILE_H) */
index dc44a50..c4bd1a6 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -198,8 +198,10 @@ static int init (void)
                return (-1);
        }
 
+#ifndef HAVE_SYSCTL_KERN_CP_TIMES
        if (numcpu != 1)
                NOTICE ("cpu: Only one processor supported when using `sysctlbyname' (found %i)", numcpu);
+#endif
 /* #endif HAVE_SYSCTLBYNAME */
 
 #elif defined(HAVE_LIBSTATGRAB)
@@ -464,7 +466,30 @@ static int cpu_read (void)
                submit (i, "interrupt", cpuinfo[i][CP_INTR]);
        }
 /* #endif CAN_USE_SYSCTL */
+#elif defined(HAVE_SYSCTLBYNAME) && defined(HAVE_SYSCTL_KERN_CP_TIMES)
+       long cpuinfo[numcpu][CPUSTATES];
+       size_t cpuinfo_size;
+       int i;
+
+       memset (cpuinfo, 0, sizeof (cpuinfo));
+
+       cpuinfo_size = sizeof (cpuinfo);
+       if (sysctlbyname("kern.cp_times", &cpuinfo, &cpuinfo_size, NULL, 0) < 0)
+       {
+               char errbuf[1024];
+               ERROR ("cpu plugin: sysctlbyname failed: %s.",
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
+               return (-1);
+       }
 
+       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]);
+       }
+/* #endif HAVE_SYSCTL_KERN_CP_TIMES */
 #elif defined(HAVE_SYSCTLBYNAME)
        long cpuinfo[CPUSTATES];
        size_t cpuinfo_size;
index a43e7ed..abf45c2 100644 (file)
@@ -57,6 +57,7 @@ struct web_page_s /* {{{ */
   int   verify_peer;
   int   verify_host;
   char *cacert;
+  int   response_time;
 
   CURL *curl;
   char curl_errbuf[CURL_ERROR_SIZE];
@@ -424,6 +425,7 @@ static int cc_config_add_page (oconfig_item_t *ci) /* {{{ */
   page->pass = NULL;
   page->verify_peer = 1;
   page->verify_host = 1;
+  page->response_time = 0;
 
   page->instance = strdup (ci->values[0].value.string);
   if (page->instance == NULL)
@@ -449,6 +451,8 @@ static int cc_config_add_page (oconfig_item_t *ci) /* {{{ */
       status = cc_config_set_boolean ("VerifyPeer", &page->verify_peer, child);
     else if (strcasecmp ("VerifyHost", child->key) == 0)
       status = cc_config_set_boolean ("VerifyHost", &page->verify_host, child);
+    else if (strcasecmp ("MeasureResponseTime", child->key) == 0)
+      status = cc_config_set_boolean (child->key, &page->response_time, child);
     else if (strcasecmp ("CACert", child->key) == 0)
       status = cc_config_add_string ("CACert", &page->cacert, child);
     else if (strcasecmp ("Match", child->key) == 0)
@@ -473,11 +477,11 @@ static int cc_config_add_page (oconfig_item_t *ci) /* {{{ */
       status = -1;
     }
 
-    if (page->matches == NULL)
+    if (page->matches == NULL && !page->response_time)
     {
       assert (page->instance != NULL);
       WARNING ("curl plugin: No (valid) `Match' block "
-          "within `Page' block `%s'.", page->instance);
+          "or MeasureResponseTime within `Page' block `%s'.", page->instance);
       status = -1;
     }
 
@@ -577,10 +581,32 @@ static void cc_submit (const web_page_t *wp, const web_match_t *wm, /* {{{ */
   plugin_dispatch_values (&vl);
 } /* }}} void cc_submit */
 
+static void cc_submit_response_time (const web_page_t *wp, double seconds) /* {{{ */
+{
+  value_t values[1];
+  value_list_t vl = VALUE_LIST_INIT;
+
+  values[0].gauge = seconds;
+
+  vl.values = values;
+  vl.values_len = 1;
+  vl.time = time (NULL);
+  sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+  sstrncpy (vl.plugin, "curl", sizeof (vl.plugin));
+  sstrncpy (vl.plugin_instance, wp->instance, sizeof (vl.plugin_instance));
+  sstrncpy (vl.type, "response_time", sizeof (vl.type));
+
+  plugin_dispatch_values (&vl);
+} /* }}} void cc_submit_response_time */
+
 static int cc_read_page (web_page_t *wp) /* {{{ */
 {
   web_match_t *wm;
   int status;
+  struct timeval start, end;
+
+  if (wp->response_time)
+    gettimeofday (&start, NULL);
 
   wp->buffer_fill = 0;
   status = curl_easy_perform (wp->curl);
@@ -591,6 +617,15 @@ static int cc_read_page (web_page_t *wp) /* {{{ */
     return (-1);
   }
 
+  if (wp->response_time)
+  {
+    double secs = 0;
+    gettimeofday (&end, NULL);
+    secs += end.tv_sec - start.tv_sec;
+    secs += (end.tv_usec - start.tv_usec) / 1000000.0;
+    cc_submit_response_time (wp, secs);
+  }
+
   for (wm = wp->matches; wm != NULL; wm = wm->next)
   {
     cu_match_value_t *mv;
index 8719201..acc6cf6 100644 (file)
@@ -265,6 +265,17 @@ static int exec_config (oconfig_item_t *ci) /* {{{ */
   return (0);
 } /* int exec_config }}} */
 
+static void set_environment (void) /* {{{ */
+{
+  char buffer[1024];
+
+  ssnprintf (buffer, sizeof (buffer), "%i", interval_g);
+  setenv ("COLLECTD_INTERVAL", buffer, /* overwrite = */ 1);
+
+  ssnprintf (buffer, sizeof (buffer), "%s", hostname_g);
+  setenv ("COLLECTD_HOSTNAME", buffer, /* overwrite = */ 1);
+} /* }}} void set_environment */
+
 static void exec_child (program_list_t *pl) /* {{{ */
 {
   int status;
@@ -477,6 +488,8 @@ static int fork_child (program_list_t *pl, int *fd_in, int *fd_out, int *fd_err)
       close (fd_pipe_err[1]);
     }
 
+    set_environment ();
+
     /* Unblock all signals */
     reset_signal_mask ();
 
diff --git a/src/netapp.c b/src/netapp.c
new file mode 100644 (file)
index 0000000..b11e9fa
--- /dev/null
@@ -0,0 +1,2565 @@
+/**
+ * collectd - src/netapp.c
+ * Copyright (C) 2009  Sven Trenkel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/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:
+ *   Sven Trenkel <collectd at semidefinite.de>  
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "utils_ignorelist.h"
+
+#include <netapp_api.h>
+#include <netapp_errno.h>
+
+#define HAS_ALL_FLAGS(has,needs) (((has) & (needs)) == (needs))
+
+typedef struct host_config_s host_config_t;
+typedef void service_handler_t(host_config_t *host, na_elem_t *result, void *data);
+
+struct cna_interval_s
+{
+       time_t interval;
+       time_t last_read;
+};
+typedef struct cna_interval_s cna_interval_t;
+
+/*! Data types for WAFL statistics {{{
+ *
+ * \brief Persistent data for WAFL performance counters. (a.k.a. cache performance)
+ *
+ * The cache counters use old counter values to calculate a hit ratio for each
+ * counter. The "cfg_wafl_t" struct therefore contains old counter values along
+ * with flags, which are set if the counter is valid.
+ *
+ * The function "cna_handle_wafl_data" will fill a new structure of this kind
+ * with new values, then pass both, new and old data, to "submit_wafl_data".
+ * That function calculates the hit ratios, submits the calculated values and
+ * updates the old counter values for the next iteration.
+ */
+#define CFG_WAFL_NAME_CACHE        0x0001
+#define CFG_WAFL_DIR_CACHE         0x0002
+#define CFG_WAFL_BUF_CACHE         0x0004
+#define CFG_WAFL_INODE_CACHE       0x0008
+#define CFG_WAFL_ALL               0x000F
+#define HAVE_WAFL_NAME_CACHE_HIT   0x0100
+#define HAVE_WAFL_NAME_CACHE_MISS  0x0200
+#define HAVE_WAFL_NAME_CACHE       (HAVE_WAFL_NAME_CACHE_HIT | HAVE_WAFL_NAME_CACHE_MISS)
+#define HAVE_WAFL_FIND_DIR_HIT     0x0400
+#define HAVE_WAFL_FIND_DIR_MISS    0x0800
+#define HAVE_WAFL_FIND_DIR         (HAVE_WAFL_FIND_DIR_HIT | HAVE_WAFL_FIND_DIR_MISS)
+#define HAVE_WAFL_BUF_HASH_HIT     0x1000
+#define HAVE_WAFL_BUF_HASH_MISS    0x2000
+#define HAVE_WAFL_BUF_HASH         (HAVE_WAFL_BUF_HASH_HIT | HAVE_WAFL_BUF_HASH_MISS)
+#define HAVE_WAFL_INODE_CACHE_HIT  0x4000
+#define HAVE_WAFL_INODE_CACHE_MISS 0x8000
+#define HAVE_WAFL_INODE_CACHE      (HAVE_WAFL_INODE_CACHE_HIT | HAVE_WAFL_INODE_CACHE_MISS)
+#define HAVE_WAFL_ALL              0xff00
+typedef struct {
+       uint32_t flags;
+       cna_interval_t interval;
+       na_elem_t *query;
+
+       time_t timestamp;
+       uint64_t name_cache_hit;
+       uint64_t name_cache_miss;
+       uint64_t find_dir_hit;
+       uint64_t find_dir_miss;
+       uint64_t buf_hash_hit;
+       uint64_t buf_hash_miss;
+       uint64_t inode_cache_hit;
+       uint64_t inode_cache_miss;
+} cfg_wafl_t;
+/* }}} cfg_wafl_t */
+
+/*! Data types for disk statistics {{{
+ *
+ * \brief A disk in the NetApp.
+ *
+ * A disk doesn't have any more information than its name at the moment.
+ * The name includes the "disk_" prefix.
+ */
+#define HAVE_DISK_BUSY   0x10
+#define HAVE_DISK_BASE   0x20
+#define HAVE_DISK_ALL    0x30
+typedef struct disk_s {
+       char *name;
+       uint32_t flags;
+       time_t timestamp;
+       uint64_t disk_busy;
+       uint64_t base_for_disk_busy;
+       double disk_busy_percent;
+       struct disk_s *next;
+} disk_t;
+
+#define CFG_DISK_BUSIEST 0x01
+#define CFG_DISK_ALL     0x01
+typedef struct {
+       uint32_t flags;
+       cna_interval_t interval;
+       na_elem_t *query;
+       disk_t *disks;
+} cfg_disk_t;
+/* }}} cfg_disk_t */
+
+/*! Data types for volume performance statistics {{{
+ *
+ * \brief Persistent data for volume performance data.
+ *
+ * The code below uses the difference of the operations and latency counters to
+ * calculate an average per-operation latency. For this, old counters need to
+ * be stored in the "data_volume_perf_t" structure. The byte-counters are just
+ * kept for completeness sake. The "flags" member indicates if each counter is
+ * valid or not.
+ *
+ * The "cna_handle_volume_perf_data" function will fill a new struct of this
+ * type and pass both, old and new data, to "submit_volume_perf_data". In that
+ * function, the per-operation latency is calculated and dispatched, then the
+ * old counters are updated.
+ */
+#define CFG_VOLUME_PERF_INIT           0x0001
+#define CFG_VOLUME_PERF_IO             0x0002
+#define CFG_VOLUME_PERF_OPS            0x0003
+#define CFG_VOLUME_PERF_LATENCY        0x0008
+#define CFG_VOLUME_PERF_ALL            0x000F
+#define HAVE_VOLUME_PERF_BYTES_READ    0x0010
+#define HAVE_VOLUME_PERF_BYTES_WRITE   0x0020
+#define HAVE_VOLUME_PERF_OPS_READ      0x0040
+#define HAVE_VOLUME_PERF_OPS_WRITE     0x0080
+#define HAVE_VOLUME_PERF_LATENCY_READ  0x0100
+#define HAVE_VOLUME_PERF_LATENCY_WRITE 0x0200
+#define HAVE_VOLUME_PERF_ALL           0x03F0
+struct data_volume_perf_s;
+typedef struct data_volume_perf_s data_volume_perf_t;
+struct data_volume_perf_s {
+       char *name;
+       uint32_t flags;
+       time_t timestamp;
+
+       uint64_t read_bytes;
+       uint64_t write_bytes;
+       uint64_t read_ops;
+       uint64_t write_ops;
+       uint64_t read_latency;
+       uint64_t write_latency;
+
+       data_volume_perf_t *next;
+};
+
+typedef struct {
+       cna_interval_t interval;
+       na_elem_t *query;
+
+       ignorelist_t *il_octets;
+       ignorelist_t *il_operations;
+       ignorelist_t *il_latency;
+
+       data_volume_perf_t *volumes;
+} cfg_volume_perf_t;
+/* }}} data_volume_perf_t */
+
+/*! Data types for volume usage statistics {{{
+ *
+ * \brief Configuration struct for volume usage data (free / used).
+ */
+#define CFG_VOLUME_USAGE_DF             0x0002
+#define CFG_VOLUME_USAGE_SNAP           0x0004
+#define CFG_VOLUME_USAGE_ALL            0x0006
+#define HAVE_VOLUME_USAGE_NORM_FREE     0x0010
+#define HAVE_VOLUME_USAGE_NORM_USED     0x0020
+#define HAVE_VOLUME_USAGE_SNAP_RSVD     0x0040
+#define HAVE_VOLUME_USAGE_SNAP_USED     0x0080
+#define HAVE_VOLUME_USAGE_SIS_SAVED     0x0100
+#define HAVE_VOLUME_USAGE_ALL           0x01f0
+#define IS_VOLUME_USAGE_OFFLINE         0x0200
+struct data_volume_usage_s;
+typedef struct data_volume_usage_s data_volume_usage_t;
+struct data_volume_usage_s {
+       char *name;
+       uint32_t flags;
+
+       na_elem_t *snap_query;
+
+       uint64_t norm_free;
+       uint64_t norm_used;
+       uint64_t snap_reserved;
+       uint64_t snap_used;
+       uint64_t sis_saved;
+
+       data_volume_usage_t *next;
+};
+
+typedef struct {
+       cna_interval_t interval;
+       na_elem_t *query;
+
+       ignorelist_t *il_capacity;
+       ignorelist_t *il_snapshot;
+
+       data_volume_usage_t *volumes;
+} cfg_volume_usage_t;
+/* }}} cfg_volume_usage_t */
+
+/*! Data types for system statistics {{{
+ *
+ * \brief Persistent data for system performance counters
+ */
+#define CFG_SYSTEM_CPU  0x01
+#define CFG_SYSTEM_NET  0x02
+#define CFG_SYSTEM_OPS  0x04
+#define CFG_SYSTEM_DISK 0x08
+#define CFG_SYSTEM_ALL  0x0F
+typedef struct {
+       uint32_t flags;
+       cna_interval_t interval;
+       na_elem_t *query;
+} cfg_system_t;
+/* }}} cfg_system_t */
+
+struct host_config_s {
+       char *name;
+       na_server_transport_t protocol;
+       char *host;
+       int port;
+       char *username;
+       char *password;
+       int interval;
+
+       na_server_t *srv;
+       cfg_wafl_t *cfg_wafl;
+       cfg_disk_t *cfg_disk;
+       cfg_volume_perf_t *cfg_volume_perf;
+       cfg_volume_usage_t *cfg_volume_usage;
+       cfg_system_t *cfg_system;
+
+       struct host_config_s *next;
+};
+#define HOST_INIT { NULL, NA_SERVER_TRANSPORT_HTTPS, NULL, 0, NULL, NULL, 0, \
+       NULL, NULL, NULL, NULL, NULL, NULL, \
+       NULL}
+
+static host_config_t *global_host_config;
+
+/*
+ * Free functions
+ *
+ * Used to free the various structures above.
+ */
+static void free_disk (disk_t *disk) /* {{{ */
+{
+       disk_t *next;
+
+       if (disk == NULL)
+               return;
+
+       next = disk->next;
+
+       sfree (disk->name);
+       sfree (disk);
+
+       free_disk (next);
+} /* }}} void free_disk */
+
+static void free_cfg_wafl (cfg_wafl_t *cw) /* {{{ */
+{
+       if (cw == NULL)
+               return;
+
+       if (cw->query != NULL)
+               na_elem_free (cw->query);
+
+       sfree (cw);
+} /* }}} void free_cfg_wafl */
+
+static void free_cfg_disk (cfg_disk_t *cfg_disk) /* {{{ */
+{
+       if (cfg_disk == NULL)
+               return;
+
+       if (cfg_disk->query != NULL)
+               na_elem_free (cfg_disk->query);
+
+       free_disk (cfg_disk->disks);
+       sfree (cfg_disk);
+} /* }}} void free_cfg_disk */
+
+static void free_cfg_volume_perf (cfg_volume_perf_t *cvp) /* {{{ */
+{
+       data_volume_perf_t *data;
+
+       if (cvp == NULL)
+               return;
+
+       /* Free the ignorelists */
+       ignorelist_free (cvp->il_octets);
+       ignorelist_free (cvp->il_operations);
+       ignorelist_free (cvp->il_latency);
+
+       /* Free the linked list of volumes */
+       data = cvp->volumes;
+       while (data != NULL)
+       {
+               data_volume_perf_t *next = data->next;
+               sfree (data->name);
+               sfree (data);
+               data = next;
+       }
+
+       if (cvp->query != NULL)
+               na_elem_free (cvp->query);
+
+       sfree (cvp);
+} /* }}} void free_cfg_volume_perf */
+
+static void free_cfg_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
+{
+       data_volume_usage_t *data;
+
+       if (cvu == NULL)
+               return;
+
+       /* Free the ignorelists */
+       ignorelist_free (cvu->il_capacity);
+       ignorelist_free (cvu->il_snapshot);
+
+       /* Free the linked list of volumes */
+       data = cvu->volumes;
+       while (data != NULL)
+       {
+               data_volume_usage_t *next = data->next;
+               sfree (data->name);
+               if (data->snap_query != NULL)
+                       na_elem_free(data->snap_query);
+               sfree (data);
+               data = next;
+       }
+
+       if (cvu->query != NULL)
+               na_elem_free (cvu->query);
+
+       sfree (cvu);
+} /* }}} void free_cfg_volume_usage */
+
+static void free_cfg_system (cfg_system_t *cs) /* {{{ */
+{
+       if (cs == NULL)
+               return;
+
+       if (cs->query != NULL)
+               na_elem_free (cs->query);
+
+       sfree (cs);
+} /* }}} void free_cfg_system */
+
+static void free_host_config (host_config_t *hc) /* {{{ */
+{
+       host_config_t *next;
+
+       if (hc == NULL)
+               return;
+
+       next = hc->next;
+
+       sfree (hc->name);
+       sfree (hc->host);
+       sfree (hc->username);
+       sfree (hc->password);
+
+       free_cfg_disk (hc->cfg_disk);
+       free_cfg_wafl (hc->cfg_wafl);
+       free_cfg_volume_perf (hc->cfg_volume_perf);
+       free_cfg_volume_usage (hc->cfg_volume_usage);
+       free_cfg_system (hc->cfg_system);
+
+       if (hc->srv != NULL)
+               na_server_close (hc->srv);
+
+       sfree (hc);
+
+       free_host_config (next);
+} /* }}} void free_host_config */
+
+/*
+ * Auxiliary functions
+ *
+ * Used to look up volumes and disks or to handle flags.
+ */
+static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */
+{
+       disk_t *d;
+
+       if ((cd == NULL) || (name == NULL))
+               return (NULL);
+
+       for (d = cd->disks; d != NULL; d = d->next) {
+               if (strcmp(d->name, name) == 0)
+                       return d;
+       }
+
+       d = malloc(sizeof(*d));
+       if (d == NULL)
+               return (NULL);
+       memset (d, 0, sizeof (*d));
+       d->next = NULL;
+
+       d->name = strdup(name);
+       if (d->name == NULL) {
+               sfree (d);
+               return (NULL);
+       }
+
+       d->next = cd->disks;
+       cd->disks = d;
+
+       return d;
+} /* }}} disk_t *get_disk */
+
+static data_volume_usage_t *get_volume_usage (cfg_volume_usage_t *cvu, /* {{{ */
+               const char *name)
+{
+       data_volume_usage_t *last;
+       data_volume_usage_t *new;
+
+       int ignore_capacity = 0;
+       int ignore_snapshot = 0;
+
+       if ((cvu == NULL) || (name == NULL))
+               return (NULL);
+
+       last = cvu->volumes;
+       while (last != NULL)
+       {
+               if (strcmp (last->name, name) == 0)
+                       return (last);
+
+               if (last->next == NULL)
+                       break;
+
+               last = last->next;
+       }
+
+       /* Check the ignorelists. If *both* tell us to ignore a volume, return NULL. */
+       ignore_capacity = ignorelist_match (cvu->il_capacity, name);
+       ignore_snapshot = ignorelist_match (cvu->il_snapshot, name);
+       if ((ignore_capacity != 0) && (ignore_snapshot != 0))
+               return (NULL);
+
+       /* Not found: allocate. */
+       new = malloc (sizeof (*new));
+       if (new == NULL)
+               return (NULL);
+       memset (new, 0, sizeof (*new));
+       new->next = NULL;
+
+       new->name = strdup (name);
+       if (new->name == NULL)
+       {
+               sfree (new);
+               return (NULL);
+       }
+
+       if (ignore_capacity == 0)
+               new->flags |= CFG_VOLUME_USAGE_DF;
+       if (ignore_snapshot == 0) {
+               new->flags |= CFG_VOLUME_USAGE_SNAP;
+               new->snap_query = na_elem_new ("snapshot-list-info");
+               na_child_add_string(new->snap_query, "target-type", "volume");
+               na_child_add_string(new->snap_query, "target-name", name);
+       } else {
+               new->snap_query = NULL;
+       }
+
+       /* Add to end of list. */
+       if (last == NULL)
+               cvu->volumes = new;
+       else
+               last->next = new;
+
+       return (new);
+} /* }}} data_volume_usage_t *get_volume_usage */
+
+static data_volume_perf_t *get_volume_perf (cfg_volume_perf_t *cvp, /* {{{ */
+               const char *name)
+{
+       data_volume_perf_t *last;
+       data_volume_perf_t *new;
+
+       int ignore_octets = 0;
+       int ignore_operations = 0;
+       int ignore_latency = 0;
+
+       if ((cvp == NULL) || (name == NULL))
+               return (NULL);
+
+       last = cvp->volumes;
+       while (last != NULL)
+       {
+               if (strcmp (last->name, name) == 0)
+                       return (last);
+
+               if (last->next == NULL)
+                       break;
+
+               last = last->next;
+       }
+
+       /* Check the ignorelists. If *all three* tell us to ignore a volume, return
+        * NULL. */
+       ignore_octets = ignorelist_match (cvp->il_octets, name);
+       ignore_operations = ignorelist_match (cvp->il_operations, name);
+       ignore_latency = ignorelist_match (cvp->il_latency, name);
+       if ((ignore_octets != 0) || (ignore_operations != 0)
+                       || (ignore_latency != 0))
+               return (NULL);
+
+       /* Not found: allocate. */
+       new = malloc (sizeof (*new));
+       if (new == NULL)
+               return (NULL);
+       memset (new, 0, sizeof (*new));
+       new->next = NULL;
+
+       new->name = strdup (name);
+       if (new->name == NULL)
+       {
+               sfree (new);
+               return (NULL);
+       }
+
+       if (ignore_octets == 0)
+               new->flags |= CFG_VOLUME_PERF_IO;
+       if (ignore_operations == 0)
+               new->flags |= CFG_VOLUME_PERF_OPS;
+       if (ignore_latency == 0)
+               new->flags |= CFG_VOLUME_PERF_LATENCY;
+
+       /* Add to end of list. */
+       if (last == NULL)
+               cvp->volumes = new;
+       else
+               last->next = new;
+
+       return (new);
+} /* }}} data_volume_perf_t *get_volume_perf */
+
+/*
+ * Various submit functions.
+ *
+ * They all eventually call "submit_values" which creates a value_list_t and
+ * dispatches it to the daemon.
+ */
+static int submit_values (const char *host, /* {{{ */
+               const char *plugin_inst,
+               const char *type, const char *type_inst,
+               value_t *values, int values_len,
+               time_t timestamp)
+{
+       value_list_t vl = VALUE_LIST_INIT;
+
+       vl.values = values;
+       vl.values_len = values_len;
+
+       if (timestamp > 0)
+               vl.time = timestamp;
+
+       if (host != NULL)
+               sstrncpy (vl.host, host, sizeof (vl.host));
+       else
+               sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       sstrncpy (vl.plugin, "netapp", sizeof (vl.plugin));
+       if (plugin_inst != NULL)
+               sstrncpy (vl.plugin_instance, plugin_inst, sizeof (vl.plugin_instance));
+       sstrncpy (vl.type, type, sizeof (vl.type));
+       if (type_inst != NULL)
+               sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
+
+       return (plugin_dispatch_values (&vl));
+} /* }}} int submit_uint64 */
+
+static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
+               const char *type, const char *type_inst, counter_t val0, counter_t val1,
+               time_t timestamp)
+{
+       value_t values[2];
+
+       values[0].counter = val0;
+       values[1].counter = val1;
+
+       return (submit_values (host, plugin_inst, type, type_inst,
+                               values, 2, timestamp));
+} /* }}} int submit_two_counters */
+
+static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
+               const char *type, const char *type_inst, counter_t counter, time_t timestamp)
+{
+       value_t v;
+
+       v.counter = counter;
+
+       return (submit_values (host, plugin_inst, type, type_inst,
+                               &v, 1, timestamp));
+} /* }}} int submit_counter */
+
+static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
+               const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
+               time_t timestamp)
+{
+       value_t values[2];
+
+       values[0].gauge = val0;
+       values[1].gauge = val1;
+
+       return (submit_values (host, plugin_inst, type, type_inst,
+                               values, 2, timestamp));
+} /* }}} int submit_two_gauge */
+
+static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
+               const char *type, const char *type_inst, double d, time_t timestamp)
+{
+       value_t v;
+
+       v.gauge = (gauge_t) d;
+
+       return (submit_values (host, plugin_inst, type, type_inst,
+                               &v, 1, timestamp));
+} /* }}} int submit_uint64 */
+
+/* Calculate hit ratio from old and new counters and submit the resulting
+ * percentage. Used by "submit_wafl_data". */
+static int submit_cache_ratio (const char *host, /* {{{ */
+               const char *plugin_inst,
+               const char *type_inst,
+               uint64_t new_hits,
+               uint64_t new_misses,
+               uint64_t old_hits,
+               uint64_t old_misses,
+               time_t timestamp)
+{
+       value_t v;
+
+       if ((new_hits >= old_hits) && (new_misses >= old_misses)) {
+               uint64_t hits;
+               uint64_t misses;
+
+               hits = new_hits - old_hits;
+               misses = new_misses - old_misses;
+
+               v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses));
+       } else {
+               v.gauge = NAN;
+       }
+
+       return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
+                               &v, 1, timestamp));
+} /* }}} int submit_cache_ratio */
+
+/* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
+static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
+               cfg_wafl_t *old_data, const cfg_wafl_t *new_data)
+{
+       /* Submit requested counters */
+       if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
+                       && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_NAME_CACHE))
+               submit_cache_ratio (hostname, instance, "name_cache_hit",
+                               new_data->name_cache_hit, new_data->name_cache_miss,
+                               old_data->name_cache_hit, old_data->name_cache_miss,
+                               new_data->timestamp);
+
+       if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
+                       && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
+               submit_cache_ratio (hostname, instance, "find_dir_hit",
+                               new_data->find_dir_hit, new_data->find_dir_miss,
+                               old_data->find_dir_hit, old_data->find_dir_miss,
+                               new_data->timestamp);
+
+       if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
+                       && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
+               submit_cache_ratio (hostname, instance, "buf_hash_hit",
+                               new_data->buf_hash_hit, new_data->buf_hash_miss,
+                               old_data->buf_hash_hit, old_data->buf_hash_miss,
+                               new_data->timestamp);
+
+       if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
+                       && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
+               submit_cache_ratio (hostname, instance, "inode_cache_hit",
+                               new_data->inode_cache_hit, new_data->inode_cache_miss,
+                               old_data->inode_cache_hit, old_data->inode_cache_miss,
+                               new_data->timestamp);
+
+       /* Clear old HAVE_* flags */
+       old_data->flags &= ~HAVE_WAFL_ALL;
+
+       /* Copy all counters */
+       old_data->timestamp        = new_data->timestamp;
+       old_data->name_cache_hit   = new_data->name_cache_hit;
+       old_data->name_cache_miss  = new_data->name_cache_miss;
+       old_data->find_dir_hit     = new_data->find_dir_hit;
+       old_data->find_dir_miss    = new_data->find_dir_miss;
+       old_data->buf_hash_hit     = new_data->buf_hash_hit;
+       old_data->buf_hash_miss    = new_data->buf_hash_miss;
+       old_data->inode_cache_hit  = new_data->inode_cache_hit;
+       old_data->inode_cache_miss = new_data->inode_cache_miss;
+
+       /* Copy HAVE_* flags */
+       old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
+
+       return (0);
+} /* }}} int submit_wafl_data */
+
+/* Submits volume performance data to the daemon, taking care to honor and
+ * update flags appropriately. */
+static int submit_volume_perf_data (const char *hostname, /* {{{ */
+               data_volume_perf_t *old_data,
+               const data_volume_perf_t *new_data)
+{
+       char plugin_instance[DATA_MAX_NAME_LEN];
+
+       if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL))
+               return (-1);
+
+       ssnprintf (plugin_instance, sizeof (plugin_instance),
+                       "volume-%s", old_data->name);
+
+       /* Check for and submit disk-octet values */
+       if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_IO)
+                       && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
+       {
+               submit_two_counters (hostname, plugin_instance, "disk_octets", /* type instance = */ NULL,
+                               (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp);
+       }
+
+       /* Check for and submit disk-operations values */
+       if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_OPS)
+                       && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
+       {
+               submit_two_counters (hostname, plugin_instance, "disk_ops", /* type instance = */ NULL,
+                               (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp);
+       }
+
+       /* Check for, calculate and submit disk-latency values */
+       if (HAS_ALL_FLAGS (old_data->flags, CFG_VOLUME_PERF_LATENCY
+                               | HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
+                               | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE)
+                       && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE
+                               | HAVE_VOLUME_PERF_LATENCY_READ | HAVE_VOLUME_PERF_LATENCY_WRITE))
+       {
+               gauge_t latency_per_op_read;
+               gauge_t latency_per_op_write;
+
+               latency_per_op_read = NAN;
+               latency_per_op_write = NAN;
+
+               /* Check if a counter wrapped around. */
+               if ((new_data->read_ops > old_data->read_ops)
+                               && (new_data->read_latency > old_data->read_latency))
+               {
+                       uint64_t diff_ops_read;
+                       uint64_t diff_latency_read;
+
+                       diff_ops_read = new_data->read_ops - old_data->read_ops;
+                       diff_latency_read = new_data->read_latency - old_data->read_latency;
+
+                       if (diff_ops_read > 0)
+                               latency_per_op_read = ((gauge_t) diff_latency_read) / ((gauge_t) diff_ops_read);
+               }
+
+               if ((new_data->write_ops > old_data->write_ops)
+                               && (new_data->write_latency > old_data->write_latency))
+               {
+                       uint64_t diff_ops_write;
+                       uint64_t diff_latency_write;
+
+                       diff_ops_write = new_data->write_ops - old_data->write_ops;
+                       diff_latency_write = new_data->write_latency - old_data->write_latency;
+
+                       if (diff_ops_write > 0)
+                               latency_per_op_write = ((gauge_t) diff_latency_write) / ((gauge_t) diff_ops_write);
+               }
+
+               submit_two_gauge (hostname, plugin_instance, "disk_latency", /* type instance = */ NULL,
+                               latency_per_op_read, latency_per_op_write, new_data->timestamp);
+       }
+
+       /* Clear all HAVE_* flags. */
+       old_data->flags &= ~HAVE_VOLUME_PERF_ALL;
+
+       /* Copy all counters */
+       old_data->timestamp = new_data->timestamp;
+       old_data->read_bytes = new_data->read_bytes;
+       old_data->write_bytes = new_data->write_bytes;
+       old_data->read_ops = new_data->read_ops;
+       old_data->write_ops = new_data->write_ops;
+       old_data->read_latency = new_data->read_latency;
+       old_data->write_latency = new_data->write_latency;
+
+       /* Copy the HAVE_* flags */
+       old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
+
+       return (0);
+} /* }}} int submit_volume_perf_data */
+
+/* 
+ * Query functions
+ *
+ * These functions are called with appropriate data returned by the libnetapp
+ * interface which is parsed and submitted with the above functions.
+ */
+/* Data corresponding to <WAFL /> */
+static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
+               na_elem_t *data)
+{
+       cfg_wafl_t perf_data;
+       const char *plugin_inst;
+
+       na_elem_t *instances;
+       na_elem_t *counter;
+       na_elem_iter_t counter_iter;
+
+       memset (&perf_data, 0, sizeof (perf_data));
+       
+       perf_data.timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
+
+       instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
+       if (instances == NULL)
+       {
+               ERROR ("netapp plugin: cna_handle_wafl_data: "
+                               "na_elem_child (\"instances\") failed.");
+               return (-1);
+       }
+
+       plugin_inst = na_child_get_string(instances, "name");
+       if (plugin_inst == NULL)
+       {
+               ERROR ("netapp plugin: cna_handle_wafl_data: "
+                               "na_child_get_string (\"name\") failed.");
+               return (-1);
+       }
+
+       /* Iterate over all counters */
+       counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
+       for (counter = na_iterator_next (&counter_iter);
+                       counter != NULL;
+                       counter = na_iterator_next (&counter_iter))
+       {
+               const char *name;
+               uint64_t value;
+
+               name = na_child_get_string(counter, "name");
+               if (name == NULL)
+                       continue;
+
+               value = na_child_get_uint64(counter, "value", UINT64_MAX);
+               if (value == UINT64_MAX)
+                       continue;
+
+               if (!strcmp(name, "name_cache_hit")) {
+                       perf_data.name_cache_hit = value;
+                       perf_data.flags |= HAVE_WAFL_NAME_CACHE_HIT;
+               } else if (!strcmp(name, "name_cache_miss")) {
+                       perf_data.name_cache_miss = value;
+                       perf_data.flags |= HAVE_WAFL_NAME_CACHE_MISS;
+               } else if (!strcmp(name, "find_dir_hit")) {
+                       perf_data.find_dir_hit = value;
+                       perf_data.flags |= HAVE_WAFL_FIND_DIR_HIT;
+               } else if (!strcmp(name, "find_dir_miss")) {
+                       perf_data.find_dir_miss = value;
+                       perf_data.flags |= HAVE_WAFL_FIND_DIR_MISS;
+               } else if (!strcmp(name, "buf_hash_hit")) {
+                       perf_data.buf_hash_hit = value;
+                       perf_data.flags |= HAVE_WAFL_BUF_HASH_HIT;
+               } else if (!strcmp(name, "buf_hash_miss")) {
+                       perf_data.buf_hash_miss = value;
+                       perf_data.flags |= HAVE_WAFL_BUF_HASH_MISS;
+               } else if (!strcmp(name, "inode_cache_hit")) {
+                       perf_data.inode_cache_hit = value;
+                       perf_data.flags |= HAVE_WAFL_INODE_CACHE_HIT;
+               } else if (!strcmp(name, "inode_cache_miss")) {
+                       perf_data.inode_cache_miss = value;
+                       perf_data.flags |= HAVE_WAFL_INODE_CACHE_MISS;
+               } else {
+                       DEBUG("netapp plugin: cna_handle_wafl_data: "
+                                       "Found unexpected child: %s", name);
+               }
+       }
+
+       return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data));
+} /* }}} void cna_handle_wafl_data */
+
+static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
+{
+       na_elem_t *e;
+
+       if (cw == NULL)
+               return (EINVAL);
+
+       if (cw->query != NULL)
+               return (0);
+
+       cw->query = na_elem_new("perf-object-get-instances");
+       if (cw->query == NULL)
+       {
+               ERROR ("netapp plugin: na_elem_new failed.");
+               return (-1);
+       }
+       na_child_add_string (cw->query, "objectname", "wafl");
+
+       e = na_elem_new("counters");
+       if (e == NULL)
+       {
+               na_elem_free (cw->query);
+               cw->query = NULL;
+               ERROR ("netapp plugin: na_elem_new failed.");
+               return (-1);
+       }
+       na_child_add_string(e, "foo", "name_cache_hit");
+       na_child_add_string(e, "foo", "name_cache_miss");
+       na_child_add_string(e, "foo", "find_dir_hit");
+       na_child_add_string(e, "foo", "find_dir_miss");
+       na_child_add_string(e, "foo", "buf_hash_hit");
+       na_child_add_string(e, "foo", "buf_hash_miss");
+       na_child_add_string(e, "foo", "inode_cache_hit");
+       na_child_add_string(e, "foo", "inode_cache_miss");
+
+       na_child_add(cw->query, e);
+
+       return (0);
+} /* }}} int cna_setup_wafl */
+
+static int cna_query_wafl (host_config_t *host) /* {{{ */
+{
+       na_elem_t *data;
+       int status;
+       time_t now;
+
+       if (host == NULL)
+               return (EINVAL);
+
+       /* If WAFL was not configured, return without doing anything. */
+       if (host->cfg_wafl == NULL)
+               return (0);
+
+       now = time (NULL);
+       if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) > now)
+               return (0);
+
+       status = cna_setup_wafl (host->cfg_wafl);
+       if (status != 0)
+               return (status);
+       assert (host->cfg_wafl->query != NULL);
+
+       data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
+       if (na_results_status (data) != NA_OK)
+       {
+               ERROR ("netapp plugin: cna_query_wafl: na_server_invoke_elem failed: %s",
+                               na_results_reason (data));
+               na_elem_free (data);
+               return (-1);
+       }
+
+       status = cna_handle_wafl_data (host->name, host->cfg_wafl, data);
+
+       if (status == 0)
+               host->cfg_wafl->interval.last_read = now;
+
+       na_elem_free (data);
+       return (status);
+} /* }}} int cna_query_wafl */
+
+/* Data corresponding to <Disks /> */
+static int cna_handle_disk_data (const char *hostname, /* {{{ */
+               cfg_disk_t *cfg_disk, na_elem_t *data)
+{
+       time_t timestamp;
+       na_elem_t *instances;
+       na_elem_t *instance;
+       na_elem_iter_t instance_iter;
+       disk_t *worst_disk = NULL;
+
+       if ((cfg_disk == NULL) || (data == NULL))
+               return (EINVAL);
+       
+       timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
+
+       instances = na_elem_child (data, "instances");
+       if (instances == NULL)
+       {
+               ERROR ("netapp plugin: cna_handle_disk_data: "
+                               "na_elem_child (\"instances\") failed.");
+               return (-1);
+       }
+
+       /* Iterate over all children */
+       instance_iter = na_child_iterator (instances);
+       for (instance = na_iterator_next (&instance_iter);
+                       instance != NULL;
+                       instance = na_iterator_next(&instance_iter))
+       {
+               disk_t *old_data;
+               disk_t  new_data;
+
+               na_elem_iter_t counter_iterator;
+               na_elem_t *counter;
+
+               memset (&new_data, 0, sizeof (new_data));
+               new_data.timestamp = timestamp;
+               new_data.disk_busy_percent = NAN;
+
+               old_data = get_disk(cfg_disk, na_child_get_string (instance, "name"));
+               if (old_data == NULL)
+                       continue;
+
+               /* Look for the "disk_busy" and "base_for_disk_busy" counters */
+               counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
+               for (counter = na_iterator_next(&counter_iterator);
+                               counter != NULL;
+                               counter = na_iterator_next(&counter_iterator))
+               {
+                       const char *name;
+                       uint64_t value;
+
+                       name = na_child_get_string(counter, "name");
+                       if (name == NULL)
+                               continue;
+
+                       value = na_child_get_uint64(counter, "value", UINT64_MAX);
+                       if (value == UINT64_MAX)
+                               continue;
+
+                       if (strcmp(name, "disk_busy") == 0)
+                       {
+                               new_data.disk_busy = value;
+                               new_data.flags |= HAVE_DISK_BUSY;
+                       }
+                       else if (strcmp(name, "base_for_disk_busy") == 0)
+                       {
+                               new_data.base_for_disk_busy = value;
+                               new_data.flags |= HAVE_DISK_BASE;
+                       }
+                       else
+                       {
+                               DEBUG ("netapp plugin: cna_handle_disk_data: "
+                                               "Counter not handled: %s = %"PRIu64,
+                                               name, value);
+                       }
+               }
+
+               /* If all required counters are available and did not just wrap around,
+                * calculate the busy percentage. Otherwise, the value is initialized to
+                * NAN at the top of the for-loop. */
+               if (HAS_ALL_FLAGS (old_data->flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
+                               && HAS_ALL_FLAGS (new_data.flags, HAVE_DISK_BUSY | HAVE_DISK_BASE)
+                               && (new_data.disk_busy >= old_data->disk_busy)
+                               && (new_data.base_for_disk_busy > old_data->base_for_disk_busy))
+               {
+                       uint64_t busy_diff;
+                       uint64_t base_diff;
+
+                       busy_diff = new_data.disk_busy - old_data->disk_busy;
+                       base_diff = new_data.base_for_disk_busy - old_data->base_for_disk_busy;
+
+                       new_data.disk_busy_percent = 100.0
+                               * ((gauge_t) busy_diff) / ((gauge_t) base_diff);
+               }
+
+               /* Clear HAVE_* flags */
+               old_data->flags &= ~HAVE_DISK_ALL;
+
+               /* Copy data */
+               old_data->timestamp = new_data.timestamp;
+               old_data->disk_busy = new_data.disk_busy;
+               old_data->base_for_disk_busy = new_data.base_for_disk_busy;
+               old_data->disk_busy_percent = new_data.disk_busy_percent;
+
+               /* Copy flags */
+               old_data->flags |= (new_data.flags & HAVE_DISK_ALL);
+
+               if ((worst_disk == NULL)
+                               || (worst_disk->disk_busy_percent < old_data->disk_busy_percent))
+                       worst_disk = old_data;
+       } /* for (all disks) */
+
+       if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
+               submit_double (hostname, "system", "percent", "disk_busy",
+                               worst_disk->disk_busy_percent, timestamp);
+
+       return (0);
+} /* }}} int cna_handle_disk_data */
+
+static int cna_setup_disk (cfg_disk_t *cd) /* {{{ */
+{
+       na_elem_t *e;
+
+       if (cd == NULL)
+               return (EINVAL);
+
+       if (cd->query != NULL)
+               return (0);
+
+       cd->query = na_elem_new ("perf-object-get-instances");
+       if (cd->query == NULL)
+       {
+               ERROR ("netapp plugin: na_elem_new failed.");
+               return (-1);
+       }
+       na_child_add_string (cd->query, "objectname", "disk");
+
+       e = na_elem_new("counters");
+       if (e == NULL)
+       {
+               na_elem_free (cd->query);
+               cd->query = NULL;
+               ERROR ("netapp plugin: na_elem_new failed.");
+               return (-1);
+       }
+       na_child_add_string(e, "foo", "disk_busy");
+       na_child_add_string(e, "foo", "base_for_disk_busy");
+       na_child_add(cd->query, e);
+
+       return (0);
+} /* }}} int cna_setup_disk */
+
+static int cna_query_disk (host_config_t *host) /* {{{ */
+{
+       na_elem_t *data;
+       int status;
+       time_t now;
+
+       if (host == NULL)
+               return (EINVAL);
+
+       /* If the user did not configure disk statistics, return without doing
+        * anything. */
+       if (host->cfg_disk == NULL)
+               return (0);
+
+       now = time (NULL);
+       if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) > now)
+               return (0);
+
+       status = cna_setup_disk (host->cfg_disk);
+       if (status != 0)
+               return (status);
+       assert (host->cfg_disk->query != NULL);
+
+       data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
+       if (na_results_status (data) != NA_OK)
+       {
+               ERROR ("netapp plugin: cna_query_disk: na_server_invoke_elem failed: %s",
+                               na_results_reason (data));
+               na_elem_free (data);
+               return (-1);
+       }
+
+       status = cna_handle_disk_data (host->name, host->cfg_disk, data);
+
+       if (status == 0)
+               host->cfg_disk->interval.last_read = now;
+
+       na_elem_free (data);
+       return (status);
+} /* }}} int cna_query_disk */
+
+/* Data corresponding to <VolumePerf /> */
+static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
+               cfg_volume_perf_t *cvp, na_elem_t *data)
+{
+       time_t timestamp;
+       na_elem_t *elem_instances;
+       na_elem_iter_t iter_instances;
+       na_elem_t *elem_instance;
+       
+       timestamp = (time_t) na_child_get_uint64(data, "timestamp", 0);
+
+       elem_instances = na_elem_child(data, "instances");
+       if (elem_instances == NULL)
+       {
+               ERROR ("netapp plugin: handle_volume_perf_data: "
+                               "na_elem_child (\"instances\") failed.");
+               return (-1);
+       }
+
+       iter_instances = na_child_iterator (elem_instances);
+       for (elem_instance = na_iterator_next(&iter_instances);
+                       elem_instance != NULL;
+                       elem_instance = na_iterator_next(&iter_instances))
+       {
+               const char *name;
+
+               data_volume_perf_t perf_data;
+               data_volume_perf_t *v;
+
+               na_elem_t *elem_counters;
+               na_elem_iter_t iter_counters;
+               na_elem_t *elem_counter;
+
+               memset (&perf_data, 0, sizeof (perf_data));
+               perf_data.timestamp = timestamp;
+
+               name = na_child_get_string (elem_instance, "name");
+               if (name == NULL)
+                       continue;
+
+               /* get_volume_perf may return NULL if this volume is to be ignored. */
+               v = get_volume_perf (cvp, name);
+               if (v == NULL)
+                       continue;
+
+               elem_counters = na_elem_child (elem_instance, "counters");
+               if (elem_counters == NULL)
+                       continue;
+
+               iter_counters = na_child_iterator (elem_counters);
+               for (elem_counter = na_iterator_next(&iter_counters);
+                               elem_counter != NULL;
+                               elem_counter = na_iterator_next(&iter_counters))
+               {
+                       const char *name;
+                       uint64_t value;
+
+                       name = na_child_get_string (elem_counter, "name");
+                       if (name == NULL)
+                               continue;
+
+                       value = na_child_get_uint64 (elem_counter, "value", UINT64_MAX);
+                       if (value == UINT64_MAX)
+                               continue;
+
+                       if (!strcmp(name, "read_data")) {
+                               perf_data.read_bytes = value;
+                               perf_data.flags |= HAVE_VOLUME_PERF_BYTES_READ;
+                       } else if (!strcmp(name, "write_data")) {
+                               perf_data.write_bytes = value;
+                               perf_data.flags |= HAVE_VOLUME_PERF_BYTES_WRITE;
+                       } else if (!strcmp(name, "read_ops")) {
+                               perf_data.read_ops = value;
+                               perf_data.flags |= HAVE_VOLUME_PERF_OPS_READ;
+                       } else if (!strcmp(name, "write_ops")) {
+                               perf_data.write_ops = value;
+                               perf_data.flags |= HAVE_VOLUME_PERF_OPS_WRITE;
+                       } else if (!strcmp(name, "read_latency")) {
+                               perf_data.read_latency = value;
+                               perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_READ;
+                       } else if (!strcmp(name, "write_latency")) {
+                               perf_data.write_latency = value;
+                               perf_data.flags |= HAVE_VOLUME_PERF_LATENCY_WRITE;
+                       }
+               } /* for (elem_counter) */
+
+               submit_volume_perf_data (hostname, v, &perf_data);
+       } /* for (volume) */
+
+       return (0);
+} /* }}} int cna_handle_volume_perf_data */
+
+static int cna_setup_volume_perf (cfg_volume_perf_t *cd) /* {{{ */
+{
+       na_elem_t *e;
+
+       if (cd == NULL)
+               return (EINVAL);
+
+       if (cd->query != NULL)
+               return (0);
+
+       cd->query = na_elem_new ("perf-object-get-instances");
+       if (cd->query == NULL)
+       {
+               ERROR ("netapp plugin: na_elem_new failed.");
+               return (-1);
+       }
+       na_child_add_string (cd->query, "objectname", "volume");
+
+       e = na_elem_new("counters");
+       if (e == NULL)
+       {
+               na_elem_free (cd->query);
+               cd->query = NULL;
+               ERROR ("netapp plugin: na_elem_new failed.");
+               return (-1);
+       }
+       /* "foo" means: This string has to be here but the content doesn't matter. */
+       na_child_add_string(e, "foo", "read_ops");
+       na_child_add_string(e, "foo", "write_ops");
+       na_child_add_string(e, "foo", "read_data");
+       na_child_add_string(e, "foo", "write_data");
+       na_child_add_string(e, "foo", "read_latency");
+       na_child_add_string(e, "foo", "write_latency");
+       na_child_add(cd->query, e);
+
+       return (0);
+} /* }}} int cna_setup_volume_perf */
+
+static int cna_query_volume_perf (host_config_t *host) /* {{{ */
+{
+       na_elem_t *data;
+       int status;
+       time_t now;
+
+       if (host == NULL)
+               return (EINVAL);
+
+       /* If the user did not configure volume performance statistics, return
+        * without doing anything. */
+       if (host->cfg_volume_perf == NULL)
+               return (0);
+
+       now = time (NULL);
+       if ((host->cfg_volume_perf->interval.interval + host->cfg_volume_perf->interval.last_read) > now)
+               return (0);
+
+       status = cna_setup_volume_perf (host->cfg_volume_perf);
+       if (status != 0)
+               return (status);
+       assert (host->cfg_volume_perf->query != NULL);
+
+       data = na_server_invoke_elem (host->srv, host->cfg_volume_perf->query);
+       if (na_results_status (data) != NA_OK)
+       {
+               ERROR ("netapp plugin: cna_query_volume_perf: na_server_invoke_elem failed: %s",
+                               na_results_reason (data));
+               na_elem_free (data);
+               return (-1);
+       }
+
+       status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data);
+
+       if (status == 0)
+               host->cfg_volume_perf->interval.last_read = now;
+
+       na_elem_free (data);
+       return (status);
+} /* }}} int cna_query_volume_perf */
+
+/* Data corresponding to <VolumeUsage /> */
+static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
+               cfg_volume_usage_t *cfg_volume)
+{
+       data_volume_usage_t *v;
+
+       for (v = cfg_volume->volumes; v != NULL; v = v->next)
+       {
+               char plugin_instance[DATA_MAX_NAME_LEN];
+
+               uint64_t norm_used = v->norm_used;
+               uint64_t norm_free = v->norm_free;
+               uint64_t sis_saved = v->sis_saved;
+               uint64_t snap_reserve_used = 0;
+               uint64_t snap_reserve_free = v->snap_reserved;
+               uint64_t snap_norm_used = v->snap_used;
+
+               ssnprintf (plugin_instance, sizeof (plugin_instance),
+                               "volume-%s", v->name);
+
+               if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD)) {
+                       if (v->snap_reserved > v->snap_used) {
+                               snap_reserve_free = v->snap_reserved - v->snap_used;
+                               snap_reserve_used = v->snap_used;
+                               snap_norm_used = 0;
+                       } else {
+                               snap_reserve_free = 0;
+                               snap_reserve_used = v->snap_reserved;
+                               snap_norm_used = v->snap_used - v->snap_reserved;
+                       }
+               }
+
+               /* The space used by snapshots but not reserved for them is included in
+                * both, norm_used and snap_norm_used. If possible, subtract this here. */
+               if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED))
+               {
+                       if (norm_used >= snap_norm_used)
+                               norm_used -= snap_norm_used;
+                       else
+                       {
+                               ERROR ("netapp plugin: (norm_used = %"PRIu64") < (snap_norm_used = "
+                                               "%"PRIu64"). Invalidating both.",
+                                               norm_used, snap_norm_used);
+                               v->flags &= ~(HAVE_VOLUME_USAGE_NORM_USED | HAVE_VOLUME_USAGE_SNAP_USED);
+                       }
+               }
+
+               if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
+                       submit_double (hostname, /* plugin instance = */ plugin_instance,
+                                       "df_complex", "free",
+                                       (double) norm_free, /* timestamp = */ 0);
+
+               if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
+                       submit_double (hostname, /* plugin instance = */ plugin_instance,
+                                       "df_complex", "sis_saved",
+                                       (double) sis_saved, /* timestamp = */ 0);
+
+               if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
+                       submit_double (hostname, /* plugin instance = */ plugin_instance,
+                                       "df_complex", "used",
+                                       (double) norm_used, /* timestamp = */ 0);
+
+               if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
+                       submit_double (hostname, /* plugin instance = */ plugin_instance,
+                                       "df_complex", "snap_reserved",
+                                       (double) snap_reserve_free, /* timestamp = */ 0);
+
+               if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD))
+                       submit_double (hostname, /* plugin instance = */ plugin_instance,
+                                       "df_complex", "snap_reserve_used",
+                                       (double) snap_reserve_used, /* timestamp = */ 0);
+
+               if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
+                       submit_double (hostname, /* plugin instance = */ plugin_instance,
+                                       "df_complex", "snap_normal_used",
+                                       (double) snap_norm_used, /* timestamp = */ 0);
+
+               /* Clear all the HAVE_* flags */
+               v->flags &= ~HAVE_VOLUME_USAGE_ALL;
+       } /* for (v = cfg_volume->volumes) */
+
+       return (0);
+} /* }}} int cna_submit_volume_usage_data */
+
+/* Switch the state of a volume between online and offline and send out a
+ * notification. */
+static int cna_change_volume_status (const char *hostname, /* {{{ */
+               data_volume_usage_t *v)
+{
+       notification_t n;
+
+       memset (&n, 0, sizeof (&n));
+       n.time = time (NULL);
+       sstrncpy (n.host, hostname, sizeof (n.host));
+       sstrncpy (n.plugin, "netapp", sizeof (n.plugin));
+       sstrncpy (n.plugin_instance, v->name, sizeof (n.plugin_instance));
+
+       if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0) {
+               n.severity = NOTIF_OKAY;
+               ssnprintf (n.message, sizeof (n.message),
+                               "Volume %s is now online.", v->name);
+               v->flags &= ~IS_VOLUME_USAGE_OFFLINE;
+       } else {
+               n.severity = NOTIF_WARNING;
+               ssnprintf (n.message, sizeof (n.message),
+                               "Volume %s is now offline.", v->name);
+               v->flags |= IS_VOLUME_USAGE_OFFLINE;
+       }
+
+       return (plugin_dispatch_notification (&n));
+} /* }}} int cna_change_volume_status */
+
+static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
+               data_volume_usage_t *v)
+{
+       uint64_t snap_used = 0, value;
+       na_elem_t *data, *elem_snap, *elem_snapshots;
+       na_elem_iter_t iter_snap;
+
+       data = na_server_invoke_elem(host->srv, v->snap_query);
+       if (na_results_status(data) != NA_OK)
+       {
+               if (na_results_errno(data) == EVOLUMEOFFLINE) {
+                       if ((v->flags & IS_VOLUME_USAGE_OFFLINE) == 0)
+                               cna_change_volume_status (host->name, v);
+               } else {
+                       ERROR ("netapp plugin: cna_handle_volume_snap_usage: na_server_invoke_elem for "
+                                       "volume \"%s\" failed with error %d: %s", v->name,
+                                       na_results_errno(data), na_results_reason(data));
+               }
+               na_elem_free(data);
+               return;
+       }
+
+       if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0)
+               cna_change_volume_status (host->name, v);
+
+       elem_snapshots = na_elem_child (data, "snapshots");
+       if (elem_snapshots == NULL)
+       {
+               ERROR ("netapp plugin: cna_handle_volume_snap_usage: "
+                               "na_elem_child (\"snapshots\") failed.");
+               na_elem_free(data);
+               return;
+       }
+
+       iter_snap = na_child_iterator (elem_snapshots);
+       for (elem_snap = na_iterator_next (&iter_snap);
+                       elem_snap != NULL;
+                       elem_snap = na_iterator_next (&iter_snap))
+       {
+               value = na_child_get_uint64(elem_snap, "cumulative-total", 0);
+               /* "cumulative-total" is the total size of the oldest snapshot plus all
+                * newer ones in blocks (1KB). We therefore are looking for the highest
+                * number of all snapshots - that's the size required for the snapshots. */
+               if (value > snap_used)
+                       snap_used = value;
+       }
+       na_elem_free (data);
+       /* snap_used is in 1024 byte blocks */
+       v->snap_used = snap_used * 1024;
+       v->flags |= HAVE_VOLUME_USAGE_SNAP_USED;
+} /* }}} void cna_handle_volume_snap_usage */
+
+static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */
+               cfg_volume_usage_t *cfg_volume, na_elem_t *data)
+{
+       na_elem_t *elem_volume;
+       na_elem_t *elem_volumes;
+       na_elem_iter_t iter_volume;
+
+       elem_volumes = na_elem_child (data, "volumes");
+       if (elem_volumes == NULL)
+       {
+               ERROR ("netapp plugin: cna_handle_volume_usage_data: "
+                               "na_elem_child (\"volumes\") failed.");
+               return (-1);
+       }
+
+       iter_volume = na_child_iterator (elem_volumes);
+       for (elem_volume = na_iterator_next (&iter_volume);
+                       elem_volume != NULL;
+                       elem_volume = na_iterator_next (&iter_volume))
+       {
+               const char *volume_name, *state;
+
+               data_volume_usage_t *v;
+               uint64_t value;
+
+               na_elem_t *sis;
+               const char *sis_state;
+               uint64_t sis_saved_reported;
+
+               volume_name = na_child_get_string (elem_volume, "name");
+               if (volume_name == NULL)
+                       continue;
+
+               state = na_child_get_string (elem_volume, "state");
+               if ((state == NULL) || (strcmp(state, "online") != 0))
+                       continue;
+
+               /* get_volume_usage may return NULL if the volume is to be ignored. */
+               v = get_volume_usage (cfg_volume, volume_name);
+               if (v == NULL)
+                       continue;
+
+               if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
+                       cna_handle_volume_snap_usage(host, v);
+               
+               if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
+                       continue;
+
+               /* 2^4 exa-bytes? This will take a while ;) */
+               value = na_child_get_uint64(elem_volume, "size-available", UINT64_MAX);
+               if (value != UINT64_MAX) {
+                       v->norm_free = value;
+                       v->flags |= HAVE_VOLUME_USAGE_NORM_FREE;
+               }
+
+               value = na_child_get_uint64(elem_volume, "size-used", UINT64_MAX);
+               if (value != UINT64_MAX) {
+                       v->norm_used = value;
+                       v->flags |= HAVE_VOLUME_USAGE_NORM_USED;
+               }
+
+               value = na_child_get_uint64(elem_volume, "snapshot-blocks-reserved", UINT64_MAX);
+               if (value != UINT64_MAX) {
+                       /* 1 block == 1024 bytes  as per API docs */
+                       v->snap_reserved = 1024 * value;
+                       v->flags |= HAVE_VOLUME_USAGE_SNAP_RSVD;
+               }
+
+               sis = na_elem_child(elem_volume, "sis");
+               if (sis == NULL)
+                       continue;
+
+               sis_state = na_child_get_string(sis, "state");
+               if (sis_state == NULL)
+                       continue;
+
+               /* If SIS is not enabled, there's nothing left to do for this volume. */
+               if (strcmp ("enabled", sis_state) != 0)
+                       continue;
+
+               sis_saved_reported = na_child_get_uint64(sis, "size-saved", UINT64_MAX);
+               if (sis_saved_reported == UINT64_MAX)
+                       continue;
+
+               /* size-saved is actually a 32 bit number, so ... time for some guesswork. */
+               if ((sis_saved_reported >> 32) != 0) {
+                       /* In case they ever fix this bug. */
+                       v->sis_saved = sis_saved_reported;
+                       v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
+               } else { /* really hacky work-around code. {{{ */
+                       uint64_t sis_saved_percent;
+                       uint64_t sis_saved_guess;
+                       uint64_t overflow_guess;
+                       uint64_t guess1, guess2, guess3;
+
+                       /* Check if we have v->norm_used. Without it, we cannot calculate
+                        * sis_saved_guess. */
+                       if ((v->flags & HAVE_VOLUME_USAGE_NORM_USED) == 0)
+                               continue;
+
+                       sis_saved_percent = na_child_get_uint64(sis, "percentage-saved", UINT64_MAX);
+                       if (sis_saved_percent > 100)
+                               continue;
+
+                       /* The "size-saved" value is a 32bit unsigned integer. This is a bug and
+                        * will hopefully be fixed in later versions. To work around the bug, try
+                        * to figure out how often the 32bit integer wrapped around by using the
+                        * "percentage-saved" value. Because the percentage is in the range
+                        * [0-100], this should work as long as the saved space does not exceed
+                        * 400 GBytes. */
+                       /* percentage-saved = size-saved / (size-saved + size-used) */
+                       if (sis_saved_percent < 100)
+                               sis_saved_guess = v->norm_used * sis_saved_percent / (100 - sis_saved_percent);
+                       else
+                               sis_saved_guess = v->norm_used;
+
+                       overflow_guess = sis_saved_guess >> 32;
+                       guess1 = overflow_guess ? ((overflow_guess - 1) << 32) + sis_saved_reported : sis_saved_reported;
+                       guess2 = (overflow_guess << 32) + sis_saved_reported;
+                       guess3 = ((overflow_guess + 1) << 32) + sis_saved_reported;
+
+                       if (sis_saved_guess < guess2) {
+                               if ((sis_saved_guess - guess1) < (guess2 - sis_saved_guess))
+                                       v->sis_saved = guess1;
+                               else
+                                       v->sis_saved = guess2;
+                       } else {
+                               if ((sis_saved_guess - guess2) < (guess3 - sis_saved_guess))
+                                       v->sis_saved = guess2;
+                               else
+                                       v->sis_saved = guess3;
+                       }
+                       v->flags |= HAVE_VOLUME_USAGE_SIS_SAVED;
+               } /* }}} end of 32-bit workaround */
+       } /* for (elem_volume) */
+
+       return (cna_submit_volume_usage_data (host->name, cfg_volume));
+} /* }}} int cna_handle_volume_usage_data */
+
+static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
+{
+       if (cvu == NULL)
+               return (EINVAL);
+
+       if (cvu->query != NULL)
+               return (0);
+
+       cvu->query = na_elem_new ("volume-list-info");
+       if (cvu->query == NULL)
+       {
+               ERROR ("netapp plugin: na_elem_new failed.");
+               return (-1);
+       }
+
+       return (0);
+} /* }}} int cna_setup_volume_usage */
+
+static int cna_query_volume_usage (host_config_t *host) /* {{{ */
+{
+       na_elem_t *data;
+       int status;
+       time_t now;
+
+       if (host == NULL)
+               return (EINVAL);
+
+       /* If the user did not configure volume_usage statistics, return without
+        * doing anything. */
+       if (host->cfg_volume_usage == NULL)
+               return (0);
+
+       now = time (NULL);
+       if ((host->cfg_volume_usage->interval.interval + host->cfg_volume_usage->interval.last_read) > now)
+               return (0);
+
+       status = cna_setup_volume_usage (host->cfg_volume_usage);
+       if (status != 0)
+               return (status);
+       assert (host->cfg_volume_usage->query != NULL);
+
+       data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
+       if (na_results_status (data) != NA_OK)
+       {
+               ERROR ("netapp plugin: cna_query_volume_usage: na_server_invoke_elem failed: %s",
+                               na_results_reason (data));
+               na_elem_free (data);
+               return (-1);
+       }
+
+       status = cna_handle_volume_usage_data (host, host->cfg_volume_usage, data);
+
+       if (status == 0)
+               host->cfg_volume_usage->interval.last_read = now;
+
+       na_elem_free (data);
+       return (status);
+} /* }}} int cna_query_volume_usage */
+
+/* Data corresponding to <System /> */
+static int cna_handle_system_data (const char *hostname, /* {{{ */
+               cfg_system_t *cfg_system, na_elem_t *data)
+{
+       na_elem_t *instances;
+       na_elem_t *counter;
+       na_elem_iter_t counter_iter;
+
+       counter_t disk_read = 0, disk_written = 0;
+       counter_t net_recv = 0, net_sent = 0;
+       counter_t cpu_busy = 0, cpu_total = 0;
+       uint32_t counter_flags = 0;
+
+       const char *instance;
+       time_t timestamp;
+       
+       timestamp = (time_t) na_child_get_uint64 (data, "timestamp", 0);
+
+       instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
+       if (instances == NULL)
+       {
+               ERROR ("netapp plugin: cna_handle_system_data: "
+                               "na_elem_child (\"instances\") failed.");
+               return (-1);
+       }
+
+       instance = na_child_get_string (instances, "name");
+       if (instance == NULL)
+       {
+               ERROR ("netapp plugin: cna_handle_system_data: "
+                               "na_child_get_string (\"name\") failed.");
+               return (-1);
+       }
+
+       counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
+       for (counter = na_iterator_next (&counter_iter);
+                       counter != NULL;
+                       counter = na_iterator_next (&counter_iter))
+       {
+               const char *name;
+               uint64_t value;
+
+               name = na_child_get_string(counter, "name");
+               if (name == NULL)
+                       continue;
+
+               value = na_child_get_uint64(counter, "value", UINT64_MAX);
+               if (value == UINT64_MAX)
+                       continue;
+
+               if (!strcmp(name, "disk_data_read")) {
+                       disk_read = (counter_t) (value * 1024);
+                       counter_flags |= 0x01;
+               } else if (!strcmp(name, "disk_data_written")) {
+                       disk_written = (counter_t) (value * 1024);
+                       counter_flags |= 0x02;
+               } else if (!strcmp(name, "net_data_recv")) {
+                       net_recv = (counter_t) (value * 1024);
+                       counter_flags |= 0x04;
+               } else if (!strcmp(name, "net_data_sent")) {
+                       net_sent = (counter_t) (value * 1024);
+                       counter_flags |= 0x08;
+               } else if (!strcmp(name, "cpu_busy")) {
+                       cpu_busy = (counter_t) value;
+                       counter_flags |= 0x10;
+               } else if (!strcmp(name, "cpu_elapsed_time")) {
+                       cpu_total = (counter_t) value;
+                       counter_flags |= 0x20;
+               } else if ((cfg_system->flags & CFG_SYSTEM_OPS)
+                               && (value > 0) && (strlen(name) > 4)
+                               && (!strcmp(name + strlen(name) - 4, "_ops"))) {
+                       submit_counter (hostname, instance, "disk_ops_complex", name,
+                                       (counter_t) value, timestamp);
+               }
+       } /* for (counter) */
+
+       if ((cfg_system->flags & CFG_SYSTEM_DISK)
+                       && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
+               submit_two_counters (hostname, instance, "disk_octets", NULL,
+                               disk_read, disk_written, timestamp);
+                               
+       if ((cfg_system->flags & CFG_SYSTEM_NET)
+                       && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
+               submit_two_counters (hostname, instance, "if_octets", NULL,
+                               net_recv, net_sent, timestamp);
+
+       if ((cfg_system->flags & CFG_SYSTEM_CPU)
+                       && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
+       {
+               submit_counter (hostname, instance, "cpu", "system",
+                               cpu_busy, timestamp);
+               submit_counter (hostname, instance, "cpu", "idle",
+                               cpu_total - cpu_busy, timestamp);
+       }
+
+       return (0);
+} /* }}} int cna_handle_system_data */
+
+static int cna_setup_system (cfg_system_t *cs) /* {{{ */
+{
+       if (cs == NULL)
+               return (EINVAL);
+
+       if (cs->query != NULL)
+               return (0);
+
+       cs->query = na_elem_new ("perf-object-get-instances");
+       if (cs->query == NULL)
+       {
+               ERROR ("netapp plugin: na_elem_new failed.");
+               return (-1);
+       }
+       na_child_add_string (cs->query, "objectname", "system");
+
+       return (0);
+} /* }}} int cna_setup_system */
+
+static int cna_query_system (host_config_t *host) /* {{{ */
+{
+       na_elem_t *data;
+       int status;
+       time_t now;
+
+       if (host == NULL)
+               return (EINVAL);
+
+       /* If system statistics were not configured, return without doing anything. */
+       if (host->cfg_system == NULL)
+               return (0);
+
+       now = time (NULL);
+       if ((host->cfg_system->interval.interval + host->cfg_system->interval.last_read) > now)
+               return (0);
+
+       status = cna_setup_system (host->cfg_system);
+       if (status != 0)
+               return (status);
+       assert (host->cfg_system->query != NULL);
+
+       data = na_server_invoke_elem(host->srv, host->cfg_system->query);
+       if (na_results_status (data) != NA_OK)
+       {
+               ERROR ("netapp plugin: cna_query_system: na_server_invoke_elem failed: %s",
+                               na_results_reason (data));
+               na_elem_free (data);
+               return (-1);
+       }
+
+       status = cna_handle_system_data (host->name, host->cfg_system, data);
+
+       if (status == 0)
+               host->cfg_system->interval.last_read = now;
+
+       na_elem_free (data);
+       return (status);
+} /* }}} int cna_query_system */
+
+/*
+ * Configuration handling
+ */
+/* Sets a given flag if the boolean argument is true and unsets the flag if it
+ * is false. On error, the flag-field is not changed. */
+static int cna_config_bool_to_flag (const oconfig_item_t *ci, /* {{{ */
+               uint32_t *flags, uint32_t flag)
+{
+       if ((ci == NULL) || (flags == NULL))
+               return (EINVAL);
+
+       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
+       {
+               WARNING ("netapp plugin: The %s option needs exactly one boolean argument.",
+                               ci->key);
+               return (-1);
+       }
+
+       if (ci->values[0].value.boolean)
+               *flags |= flag;
+       else
+               *flags &= ~flag;
+
+       return (0);
+} /* }}} int cna_config_bool_to_flag */
+
+/* Handling of the "Interval" option which is allowed in every block. */
+static int cna_config_get_interval (const oconfig_item_t *ci, /* {{{ */
+               cna_interval_t *out_interval)
+{
+       time_t tmp;
+
+       if ((ci == NULL) || (out_interval == NULL))
+               return (EINVAL);
+
+       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
+       {
+               WARNING ("netapp plugin: The `Interval' option needs exactly one numeric argument.");
+               return (-1);
+       }
+
+       tmp = (time_t) (ci->values[0].value.number + .5);
+       if (tmp < 1)
+       {
+               WARNING ("netapp plugin: The `Interval' option needs a positive integer argument.");
+               return (-1);
+       }
+
+       out_interval->interval = tmp;
+       out_interval->last_read = 0;
+
+       return (0);
+} /* }}} int cna_config_get_interval */
+
+/* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
+ * <VolumePerf /> block. */
+static void cna_config_volume_perf_option (cfg_volume_perf_t *cvp, /* {{{ */
+               const oconfig_item_t *ci)
+{
+       char *name;
+       ignorelist_t * il;
+
+       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
+       {
+               WARNING ("netapp plugin: The %s option requires exactly one string argument.",
+                               ci->key);
+               return;
+       }
+
+       name = ci->values[0].value.string;
+
+       if (strcasecmp ("GetIO", ci->key) == 0)
+               il = cvp->il_octets;
+       else if (strcasecmp ("GetOps", ci->key) == 0)
+               il = cvp->il_operations;
+       else if (strcasecmp ("GetLatency", ci->key) == 0)
+               il = cvp->il_latency;
+       else
+               return;
+
+       ignorelist_add (il, name);
+} /* }}} void cna_config_volume_perf_option */
+
+/* Handling of the "IgnoreSelectedIO", "IgnoreSelectedOps" and
+ * "IgnoreSelectedLatency" options within a <VolumePerf /> block. */
+static void cna_config_volume_perf_default (cfg_volume_perf_t *cvp, /* {{{ */
+               const oconfig_item_t *ci)
+{
+       ignorelist_t *il;
+
+       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
+       {
+               WARNING ("netapp plugin: The %s option requires exactly one string argument.",
+                               ci->key);
+               return;
+       }
+
+       if (strcasecmp ("IgnoreSelectedIO", ci->key) == 0)
+               il = cvp->il_octets;
+       else if (strcasecmp ("IgnoreSelectedOps", ci->key) == 0)
+               il = cvp->il_operations;
+       else if (strcasecmp ("IgnoreSelectedLatency", ci->key) == 0)
+               il = cvp->il_latency;
+       else
+               return;
+
+       if (ci->values[0].value.boolean)
+               ignorelist_set_invert (il, /* invert = */ 0);
+       else
+               ignorelist_set_invert (il, /* invert = */ 1);
+} /* }}} void cna_config_volume_perf_default */
+
+/* Corresponds to a <Disks /> block */
+/*
+ * <VolumePerf>
+ *   GetIO "vol0"
+ *   GetIO "vol1"
+ *   IgnoreSelectedIO false
+ *
+ *   GetOps "vol0"
+ *   GetOps "vol2"
+ *   IgnoreSelectedOps false
+ *
+ *   GetLatency "vol2"
+ *   GetLatency "vol3"
+ *   IgnoreSelectedLatency false
+ * </VolumePerf>
+ */
+/* Corresponds to a <VolumePerf /> block */
+static int cna_config_volume_performance (host_config_t *host, /* {{{ */
+               const oconfig_item_t *ci)
+{
+       cfg_volume_perf_t *cfg_volume_perf;
+       int i;
+
+       if ((host == NULL) || (ci == NULL))
+               return (EINVAL);
+
+       if (host->cfg_volume_perf == NULL)
+       {
+               cfg_volume_perf = malloc (sizeof (*cfg_volume_perf));
+               if (cfg_volume_perf == NULL)
+                       return (ENOMEM);
+               memset (cfg_volume_perf, 0, sizeof (*cfg_volume_perf));
+
+               /* Set default flags */
+               cfg_volume_perf->query = NULL;
+               cfg_volume_perf->volumes = NULL;
+
+               cfg_volume_perf->il_octets = ignorelist_create (/* invert = */ 1);
+               if (cfg_volume_perf->il_octets == NULL)
+               {
+                       sfree (cfg_volume_perf);
+                       return (ENOMEM);
+               }
+
+               cfg_volume_perf->il_operations = ignorelist_create (/* invert = */ 1);
+               if (cfg_volume_perf->il_operations == NULL)
+               {
+                       ignorelist_free (cfg_volume_perf->il_octets);
+                       sfree (cfg_volume_perf);
+                       return (ENOMEM);
+               }
+
+               cfg_volume_perf->il_latency = ignorelist_create (/* invert = */ 1);
+               if (cfg_volume_perf->il_latency == NULL)
+               {
+                       ignorelist_free (cfg_volume_perf->il_octets);
+                       ignorelist_free (cfg_volume_perf->il_operations);
+                       sfree (cfg_volume_perf);
+                       return (ENOMEM);
+               }
+
+               host->cfg_volume_perf = cfg_volume_perf;
+       }
+       cfg_volume_perf = host->cfg_volume_perf;
+       
+       for (i = 0; i < ci->children_num; ++i) {
+               oconfig_item_t *item = ci->children + i;
+               
+               /* if (!item || !item->key || !*item->key) continue; */
+               if (strcasecmp(item->key, "Interval") == 0)
+                       cna_config_get_interval (item, &cfg_volume_perf->interval);
+               else if (!strcasecmp(item->key, "GetIO"))
+                       cna_config_volume_perf_option (cfg_volume_perf, item);
+               else if (!strcasecmp(item->key, "GetOps"))
+                       cna_config_volume_perf_option (cfg_volume_perf, item);
+               else if (!strcasecmp(item->key, "GetLatency"))
+                       cna_config_volume_perf_option (cfg_volume_perf, item);
+               else if (!strcasecmp(item->key, "IgnoreSelectedIO"))
+                       cna_config_volume_perf_default (cfg_volume_perf, item);
+               else if (!strcasecmp(item->key, "IgnoreSelectedOps"))
+                       cna_config_volume_perf_default (cfg_volume_perf, item);
+               else if (!strcasecmp(item->key, "IgnoreSelectedLatency"))
+                       cna_config_volume_perf_default (cfg_volume_perf, item);
+               else
+                       WARNING ("netapp plugin: The option %s is not allowed within "
+                                       "`VolumePerf' blocks.", item->key);
+       }
+
+       return (0);
+} /* }}} int cna_config_volume_performance */
+
+/* Handling of the "GetCapacity" and "GetSnapshot" options within a
+ * <VolumeUsage /> block. */
+static void cna_config_volume_usage_option (cfg_volume_usage_t *cvu, /* {{{ */
+               const oconfig_item_t *ci)
+{
+       char *name;
+       ignorelist_t * il;
+
+       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
+       {
+               WARNING ("netapp plugin: The %s option requires exactly one string argument.",
+                               ci->key);
+               return;
+       }
+
+       name = ci->values[0].value.string;
+
+       if (strcasecmp ("GetCapacity", ci->key) == 0)
+               il = cvu->il_capacity;
+       else if (strcasecmp ("GetSnapshot", ci->key) == 0)
+               il = cvu->il_snapshot;
+       else
+               return;
+
+       ignorelist_add (il, name);
+} /* }}} void cna_config_volume_usage_option */
+
+/* Handling of the "IgnoreSelectedCapacity" and "IgnoreSelectedSnapshot"
+ * options within a <VolumeUsage /> block. */
+static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
+               const oconfig_item_t *ci)
+{
+       ignorelist_t *il;
+
+       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
+       {
+               WARNING ("netapp plugin: The %s option requires exactly one string argument.",
+                               ci->key);
+               return;
+       }
+
+       if (strcasecmp ("IgnoreSelectedCapacity", ci->key) == 0)
+               il = cvu->il_capacity;
+       else if (strcasecmp ("IgnoreSelectedSnapshot", ci->key) == 0)
+               il = cvu->il_snapshot;
+       else
+               return;
+
+       if (ci->values[0].value.boolean)
+               ignorelist_set_invert (il, /* invert = */ 0);
+       else
+               ignorelist_set_invert (il, /* invert = */ 1);
+} /* }}} void cna_config_volume_usage_default */
+
+/* Corresponds to a <Disks /> block */
+static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
+       cfg_disk_t *cfg_disk;
+       int i;
+
+       if ((host == NULL) || (ci == NULL))
+               return (EINVAL);
+
+       if (host->cfg_disk == NULL)
+       {
+               cfg_disk = malloc (sizeof (*cfg_disk));
+               if (cfg_disk == NULL)
+                       return (ENOMEM);
+               memset (cfg_disk, 0, sizeof (*cfg_disk));
+
+               /* Set default flags */
+               cfg_disk->flags = CFG_DISK_ALL;
+               cfg_disk->query = NULL;
+               cfg_disk->disks = NULL;
+
+               host->cfg_disk = cfg_disk;
+       }
+       cfg_disk = host->cfg_disk;
+       
+       for (i = 0; i < ci->children_num; ++i) {
+               oconfig_item_t *item = ci->children + i;
+               
+               /* if (!item || !item->key || !*item->key) continue; */
+               if (strcasecmp(item->key, "Interval") == 0)
+                       cna_config_get_interval (item, &cfg_disk->interval);
+               else if (strcasecmp(item->key, "GetBusy") == 0)
+                       cna_config_bool_to_flag (item, &cfg_disk->flags, CFG_DISK_BUSIEST);
+       }
+
+       if ((cfg_disk->flags & CFG_DISK_ALL) == 0)
+       {
+               NOTICE ("netapp plugin: All disk related values have been disabled. "
+                               "Collection of per-disk data will be disabled entirely.");
+               free_cfg_disk (host->cfg_disk);
+               host->cfg_disk = NULL;
+       }
+
+       return (0);
+} /* }}} int cna_config_disk */
+
+/* Corresponds to a <WAFL /> block */
+static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
+{
+       cfg_wafl_t *cfg_wafl;
+       int i;
+
+       if ((host == NULL) || (ci == NULL))
+               return (EINVAL);
+
+       if (host->cfg_wafl == NULL)
+       {
+               cfg_wafl = malloc (sizeof (*cfg_wafl));
+               if (cfg_wafl == NULL)
+                       return (ENOMEM);
+               memset (cfg_wafl, 0, sizeof (*cfg_wafl));
+
+               /* Set default flags */
+               cfg_wafl->flags = CFG_WAFL_ALL;
+
+               host->cfg_wafl = cfg_wafl;
+       }
+       cfg_wafl = host->cfg_wafl;
+
+       for (i = 0; i < ci->children_num; ++i) {
+               oconfig_item_t *item = ci->children + i;
+               
+               if (strcasecmp(item->key, "Interval") == 0)
+                       cna_config_get_interval (item, &cfg_wafl->interval);
+               else if (!strcasecmp(item->key, "GetNameCache"))
+                       cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_NAME_CACHE);
+               else if (!strcasecmp(item->key, "GetDirCache"))
+                       cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_DIR_CACHE);
+               else if (!strcasecmp(item->key, "GetBufferCache"))
+                       cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_BUF_CACHE);
+               else if (!strcasecmp(item->key, "GetInodeCache"))
+                       cna_config_bool_to_flag (item, &cfg_wafl->flags, CFG_WAFL_INODE_CACHE);
+               else
+                       WARNING ("netapp plugin: The %s config option is not allowed within "
+                                       "`WAFL' blocks.", item->key);
+       }
+
+       if ((cfg_wafl->flags & CFG_WAFL_ALL) == 0)
+       {
+               NOTICE ("netapp plugin: All WAFL related values have been disabled. "
+                               "Collection of WAFL data will be disabled entirely.");
+               free_cfg_wafl (host->cfg_wafl);
+               host->cfg_wafl = NULL;
+       }
+
+       return (0);
+} /* }}} int cna_config_wafl */
+
+/*
+ * <VolumeUsage>
+ *   GetCapacity "vol0"
+ *   GetCapacity "vol1"
+ *   GetCapacity "vol2"
+ *   GetCapacity "vol3"
+ *   GetCapacity "vol4"
+ *   IgnoreSelectedCapacity false
+ *
+ *   GetSnapshot "vol0"
+ *   GetSnapshot "vol3"
+ *   GetSnapshot "vol4"
+ *   GetSnapshot "vol7"
+ *   IgnoreSelectedSnapshot false
+ * </VolumeUsage>
+ */
+/* Corresponds to a <VolumeUsage /> block */
+static int cna_config_volume_usage(host_config_t *host, /* {{{ */
+               const oconfig_item_t *ci)
+{
+       cfg_volume_usage_t *cfg_volume_usage;
+       int i;
+
+       if ((host == NULL) || (ci == NULL))
+               return (EINVAL);
+
+       if (host->cfg_volume_usage == NULL)
+       {
+               cfg_volume_usage = malloc (sizeof (*cfg_volume_usage));
+               if (cfg_volume_usage == NULL)
+                       return (ENOMEM);
+               memset (cfg_volume_usage, 0, sizeof (*cfg_volume_usage));
+
+               /* Set default flags */
+               cfg_volume_usage->query = NULL;
+               cfg_volume_usage->volumes = NULL;
+
+               cfg_volume_usage->il_capacity = ignorelist_create (/* invert = */ 1);
+               if (cfg_volume_usage->il_capacity == NULL)
+               {
+                       sfree (cfg_volume_usage);
+                       return (ENOMEM);
+               }
+
+               cfg_volume_usage->il_snapshot = ignorelist_create (/* invert = */ 1);
+               if (cfg_volume_usage->il_snapshot == NULL)
+               {
+                       ignorelist_free (cfg_volume_usage->il_capacity);
+                       sfree (cfg_volume_usage);
+                       return (ENOMEM);
+               }
+
+               host->cfg_volume_usage = cfg_volume_usage;
+       }
+       cfg_volume_usage = host->cfg_volume_usage;
+       
+       for (i = 0; i < ci->children_num; ++i) {
+               oconfig_item_t *item = ci->children + i;
+               
+               /* if (!item || !item->key || !*item->key) continue; */
+               if (strcasecmp(item->key, "Interval") == 0)
+                       cna_config_get_interval (item, &cfg_volume_usage->interval);
+               else if (!strcasecmp(item->key, "GetCapacity"))
+                       cna_config_volume_usage_option (cfg_volume_usage, item);
+               else if (!strcasecmp(item->key, "GetSnapshot"))
+                       cna_config_volume_usage_option (cfg_volume_usage, item);
+               else if (!strcasecmp(item->key, "IgnoreSelectedCapacity"))
+                       cna_config_volume_usage_default (cfg_volume_usage, item);
+               else if (!strcasecmp(item->key, "IgnoreSelectedSnapshot"))
+                       cna_config_volume_usage_default (cfg_volume_usage, item);
+               else
+                       WARNING ("netapp plugin: The option %s is not allowed within "
+                                       "`VolumeUsage' blocks.", item->key);
+       }
+
+       return (0);
+} /* }}} int cna_config_volume_usage */
+
+/* Corresponds to a <System /> block */
+static int cna_config_system (host_config_t *host, /* {{{ */
+               oconfig_item_t *ci)
+{
+       cfg_system_t *cfg_system;
+       int i;
+       
+       if ((host == NULL) || (ci == NULL))
+               return (EINVAL);
+
+       if (host->cfg_system == NULL)
+       {
+               cfg_system = malloc (sizeof (*cfg_system));
+               if (cfg_system == NULL)
+                       return (ENOMEM);
+               memset (cfg_system, 0, sizeof (*cfg_system));
+
+               /* Set default flags */
+               cfg_system->flags = CFG_SYSTEM_ALL;
+               cfg_system->query = NULL;
+
+               host->cfg_system = cfg_system;
+       }
+       cfg_system = host->cfg_system;
+
+       for (i = 0; i < ci->children_num; ++i) {
+               oconfig_item_t *item = ci->children + i;
+
+               if (strcasecmp(item->key, "Interval") == 0) {
+                       cna_config_get_interval (item, &cfg_system->interval);
+               } else if (!strcasecmp(item->key, "GetCPULoad")) {
+                       cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_CPU);
+               } else if (!strcasecmp(item->key, "GetInterfaces")) {
+                       cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_NET);
+               } else if (!strcasecmp(item->key, "GetDiskOps")) {
+                       cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_OPS);
+               } else if (!strcasecmp(item->key, "GetDiskIO")) {
+                       cna_config_bool_to_flag (item, &cfg_system->flags, CFG_SYSTEM_DISK);
+               } else {
+                       WARNING ("netapp plugin: The %s config option is not allowed within "
+                                       "`System' blocks.", item->key);
+               }
+       }
+
+       if ((cfg_system->flags & CFG_SYSTEM_ALL) == 0)
+       {
+               NOTICE ("netapp plugin: All system related values have been disabled. "
+                               "Collection of system data will be disabled entirely.");
+               free_cfg_system (host->cfg_system);
+               host->cfg_system = NULL;
+       }
+
+       return (0);
+} /* }}} int cna_config_system */
+
+/* Corresponds to a <Host /> block. */
+static host_config_t *cna_config_host (const oconfig_item_t *ci, /* {{{ */
+               const host_config_t *default_host)
+{
+       oconfig_item_t *item;
+       host_config_t *host;
+       int status;
+       int i;
+       
+       if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
+               WARNING("netapp plugin: \"Host\" needs exactly one string argument. Ignoring host block.");
+               return 0;
+       }
+
+       host = malloc(sizeof(*host));
+       memcpy (host, default_host, sizeof (*host));
+
+       status = cf_util_get_string (ci, &host->name);
+       if (status != 0)
+       {
+               sfree (host);
+               return (NULL);
+       }
+
+       for (i = 0; i < ci->children_num; ++i) {
+               item = ci->children + i;
+
+               status = 0;
+
+               if (!strcasecmp(item->key, "Address")) {
+                       status = cf_util_get_string (item, &host->host);
+               } else if (!strcasecmp(item->key, "Port")) {
+                       int tmp;
+
+                       tmp = cf_util_get_port_number (item);
+                       if (tmp > 0)
+                               host->port = tmp;
+               } else if (!strcasecmp(item->key, "Protocol")) {
+                       if ((item->values_num != 1) || (item->values[0].type != OCONFIG_TYPE_STRING) || (strcasecmp(item->values[0].value.string, "http") && strcasecmp(item->values[0].value.string, "https"))) {
+                               WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or \"https\". Ignoring host block \"%s\".", ci->values[0].value.string);
+                               return 0;
+                       }
+                       if (!strcasecmp(item->values[0].value.string, "http")) host->protocol = NA_SERVER_TRANSPORT_HTTP;
+                       else host->protocol = NA_SERVER_TRANSPORT_HTTPS;
+               } else if (!strcasecmp(item->key, "User")) {
+                       status = cf_util_get_string (item, &host->username);
+               } else if (!strcasecmp(item->key, "Password")) {
+                       status = cf_util_get_string (item, &host->password);
+               } else if (!strcasecmp(item->key, "Interval")) {
+                       if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_NUMBER || item->values[0].value.number != (int) item->values[0].value.number || item->values[0].value.number < 2) {
+                               WARNING("netapp plugin: \"Interval\" of host %s needs exactly one integer argument.", ci->values[0].value.string);
+                               continue;
+                       }
+                       host->interval = item->values[0].value.number;
+               } else if (!strcasecmp(item->key, "WAFL")) {
+                       cna_config_wafl(host, item);
+               } else if (!strcasecmp(item->key, "Disks")) {
+                       cna_config_disk(host, item);
+               } else if (!strcasecmp(item->key, "VolumePerf")) {
+                       cna_config_volume_performance(host, item);
+               } else if (!strcasecmp(item->key, "VolumeUsage")) {
+                       cna_config_volume_usage(host, item);
+               } else if (!strcasecmp(item->key, "System")) {
+                       cna_config_system(host, item);
+               } else {
+                       WARNING("netapp plugin: Ignoring unknown config option \"%s\" in host block \"%s\".",
+                                       item->key, ci->values[0].value.string);
+               }
+
+               if (status != 0)
+                       break;
+       }
+
+       if (host->host == NULL)
+               host->host = strdup (host->name);
+
+       if (host->host == NULL)
+               status = -1;
+
+       if (host->port <= 0)
+               host->port = (host->protocol == NA_SERVER_TRANSPORT_HTTP) ? 80 : 443;
+
+       if ((host->username == NULL) || (host->password == NULL)) {
+               WARNING("netapp plugin: Please supply login information for host \"%s\". "
+                               "Ignoring host block.", host->name);
+               status = -1;
+       }
+
+       if (status != 0)
+       {
+               free_host_config (host);
+               return (NULL);
+       }
+
+       return host;
+} /* }}} host_config_t *cna_config_host */
+
+/*
+ * Callbacks registered with the daemon
+ *
+ * Pretty standard stuff here.
+ */
+static int cna_init(void) { /* {{{ */
+       char err[256];
+       host_config_t *host;
+       
+       if (!global_host_config) {
+               WARNING("netapp plugin: Plugin loaded but no hosts defined.");
+               return 1;
+       }
+
+       memset (err, 0, sizeof (err));
+       if (!na_startup(err, sizeof(err))) {
+               err[sizeof (err) - 1] = 0;
+               ERROR("netapp plugin: Error initializing netapp API: %s", err);
+               return 1;
+       }
+
+       for (host = global_host_config; host; host = host->next) {
+               /* Request version 1.1 of the ONTAP API */
+               host->srv = na_server_open(host->host,
+                               /* major version = */ 1, /* minor version = */ 1); 
+               if (host->srv == NULL) {
+                       ERROR ("netapp plugin: na_server_open (%s) failed.", host->host);
+                       continue;
+               }
+
+               if (host->interval < interval_g)
+                       host->interval = interval_g;
+
+               na_server_set_transport_type(host->srv, host->protocol,
+                               /* transportarg = */ NULL);
+               na_server_set_port(host->srv, host->port);
+               na_server_style(host->srv, NA_STYLE_LOGIN_PASSWORD);
+               na_server_adminuser(host->srv, host->username, host->password);
+               na_server_set_timeout(host->srv, 5 /* seconds */);
+       }
+       return 0;
+} /* }}} int cna_init */
+
+static int cna_config (oconfig_item_t *ci) { /* {{{ */
+       int i;
+       oconfig_item_t *item;
+       host_config_t default_host = HOST_INIT;
+       
+       for (i = 0; i < ci->children_num; ++i) {
+               item = ci->children + i;
+
+               if (!strcasecmp(item->key, "Host")) {
+                       host_config_t *host;
+                       host_config_t *tmp;
+
+                       host = cna_config_host(item, &default_host);
+                       if (host == NULL)
+                               continue;
+
+                       for (tmp = global_host_config; tmp != NULL; tmp = tmp->next)
+                       {
+                               if (strcasecmp (host->name, tmp->name) == 0)
+                                       WARNING ("netapp plugin: Duplicate definition of host `%s'. "
+                                                       "This is probably a bad idea.",
+                                                       host->name);
+
+                               if (tmp->next == NULL)
+                                       break;
+                       }
+
+                       host->next = NULL;
+                       if (tmp == NULL)
+                               global_host_config = host;
+                       else
+                               tmp->next = host;
+               } else {
+                       WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
+               }
+       }
+       return 0;
+} /* }}} int cna_config */
+
+static int cna_read (void) { /* {{{ */
+       host_config_t *host;
+       
+       for (host = global_host_config; host; host = host->next) {
+               cna_query_wafl (host);
+               cna_query_disk (host);
+               cna_query_volume_perf (host);
+               cna_query_volume_usage (host);
+               cna_query_system (host);
+       }
+       return 0;
+} /* }}} int cna_read */
+
+static int cna_shutdown (void) /* {{{ */
+{
+       free_host_config (global_host_config);
+       global_host_config = NULL;
+
+       return (0);
+} /* }}} int cna_shutdown */
+
+void module_register(void) {
+       plugin_register_complex_config("netapp", cna_config);
+       plugin_register_init("netapp", cna_init);
+       plugin_register_read("netapp", cna_read);
+       plugin_register_shutdown("netapp", cna_shutdown);
+}
+
+/* vim: set sw=2 ts=2 noet fdm=marker : */
index 5d882e6..11a0ef6 100644 (file)
@@ -1444,7 +1444,12 @@ void plugin_log (int level, const char *format, ...)
        llentry_t *le;
 
        if (list_log == NULL)
+       {
+               va_start (ap, format);
+               vfprintf (stderr, format, ap);
+               va_end (ap);
                return;
+       }
 
 #if !COLLECT_DEBUG
        if (level >= LOG_DEBUG)
diff --git a/src/target_scale.c b/src/target_scale.c
new file mode 100644 (file)
index 0000000..6b261c7
--- /dev/null
@@ -0,0 +1,420 @@
+/**
+ * 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.
+ *
+ * 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 Forster <octo at verplant.org>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "filter_chain.h"
+
+#include "utils_cache.h"
+
+struct ts_data_s
+{
+       double factor;
+       double offset;
+};
+typedef struct ts_data_s ts_data_t;
+
+static int ts_invoke_counter (const data_set_t *ds, value_list_t *vl, /* {{{ */
+               ts_data_t *data, int dsrc_index)
+{
+       uint64_t curr_counter;
+       int status;
+       int failure;
+
+       /* Required meta data */
+       uint64_t prev_counter;
+       char key_prev_counter[128];
+       uint64_t int_counter;
+       char key_int_counter[128];
+       double int_fraction;
+       char key_int_fraction[128];
+
+       curr_counter = (uint64_t) vl->values[dsrc_index].counter;
+
+       ssnprintf (key_prev_counter, sizeof (key_prev_counter),
+                       "target_scale[%p,%i]:prev_counter",
+                       (void *) data, dsrc_index);
+       ssnprintf (key_int_counter, sizeof (key_int_counter),
+                       "target_scale[%p,%i]:int_counter",
+                       (void *) data, dsrc_index);
+       ssnprintf (key_int_fraction, sizeof (key_int_fraction),
+                       "target_scale[%p,%i]:int_fraction",
+                       (void *) data, dsrc_index);
+
+       prev_counter = curr_counter;
+       int_counter = 0;
+       int_fraction = 0.0;
+
+       /* Query the meta data */
+       failure = 0;
+
+       status = uc_meta_data_get_unsigned_int (vl, key_prev_counter,
+                       &prev_counter);
+       if (status != 0)
+               failure++;
+
+       status = uc_meta_data_get_unsigned_int (vl, key_int_counter, &int_counter);
+       if (status != 0)
+               failure++;
+
+       status = uc_meta_data_get_double (vl, key_int_fraction, &int_fraction);
+       if (status != 0)
+               failure++;
+
+       if (failure == 0)
+       {
+               uint64_t difference;
+               double rate;
+
+               /* Calcualte the rate */
+               if (prev_counter > curr_counter) /* => counter overflow */
+               {
+                       if (prev_counter <= 4294967295UL) /* 32 bit overflow */
+                               difference = (4294967295UL - prev_counter) + curr_counter;
+                       else /* 64 bit overflow */
+                               difference = (18446744073709551615ULL - prev_counter) + curr_counter;
+               }
+               else /* no overflow */
+               {
+                       difference = curr_counter - prev_counter;
+               }
+               rate = ((double) difference) / ((double) vl->interval);
+
+               /* Modify the rate. */
+               if (!isnan (data->factor))
+                       rate *= data->factor;
+               if (!isnan (data->offset))
+                       rate += data->offset;
+
+               /* Calculate the internal counter. */
+               int_fraction += (rate * ((double) vl->interval));
+               difference = (uint64_t) int_fraction;
+               int_fraction -= ((double) difference);
+               int_counter  += difference;
+
+               assert (int_fraction >= 0.0);
+               assert (int_fraction <  1.0);
+
+               DEBUG ("Target `scale': ts_invoke_counter: %"PRIu64" -> %g -> %"PRIu64
+                               "(+%g)",
+                               curr_counter, rate, int_counter, int_fraction);
+       }
+       else /* (failure != 0) */
+       {
+               int_counter = 0;
+               int_fraction = 0.0;
+       }
+
+       vl->values[dsrc_index].counter = (counter_t) int_counter;
+
+       /* Update to the new counter value */
+       uc_meta_data_add_unsigned_int (vl, key_prev_counter, curr_counter);
+       uc_meta_data_add_unsigned_int (vl, key_int_counter, int_counter);
+       uc_meta_data_add_double (vl, key_int_fraction, int_fraction);
+
+
+       return (0);
+} /* }}} int ts_invoke_counter */
+
+static int ts_invoke_gauge (const data_set_t *ds, value_list_t *vl, /* {{{ */
+               ts_data_t *data, int dsrc_index)
+{
+       if (!isnan (data->factor))
+               vl->values[dsrc_index].gauge *= data->factor;
+       if (!isnan (data->offset))
+               vl->values[dsrc_index].gauge += data->offset;
+
+       return (0);
+} /* }}} int ts_invoke_gauge */
+
+static int ts_invoke_derive (const data_set_t *ds, value_list_t *vl, /* {{{ */
+               ts_data_t *data, int dsrc_index)
+{
+       int64_t curr_derive;
+       int status;
+       int failure;
+
+       /* Required meta data */
+       int64_t prev_derive;
+       char key_prev_derive[128];
+       int64_t int_derive;
+       char key_int_derive[128];
+       double int_fraction;
+       char key_int_fraction[128];
+
+       curr_derive = (int64_t) vl->values[dsrc_index].derive;
+
+       ssnprintf (key_prev_derive, sizeof (key_prev_derive),
+                       "target_scale[%p,%i]:prev_derive",
+                       (void *) data, dsrc_index);
+       ssnprintf (key_int_derive, sizeof (key_int_derive),
+                       "target_scale[%p,%i]:int_derive",
+                       (void *) data, dsrc_index);
+       ssnprintf (key_int_fraction, sizeof (key_int_fraction),
+                       "target_scale[%p,%i]:int_fraction",
+                       (void *) data, dsrc_index);
+
+       prev_derive = curr_derive;
+       int_derive = 0;
+       int_fraction = 0.0;
+
+       /* Query the meta data */
+       failure = 0;
+
+       status = uc_meta_data_get_signed_int (vl, key_prev_derive,
+                       &prev_derive);
+       if (status != 0)
+               failure++;
+
+       status = uc_meta_data_get_signed_int (vl, key_int_derive, &int_derive);
+       if (status != 0)
+               failure++;
+
+       status = uc_meta_data_get_double (vl, key_int_fraction, &int_fraction);
+       if (status != 0)
+               failure++;
+
+       if (failure == 0)
+       {
+               int64_t difference;
+               double rate;
+
+               /* Calcualte the rate */
+               difference = curr_derive - prev_derive;
+               rate = ((double) difference) / ((double) vl->interval);
+
+               /* Modify the rate. */
+               if (!isnan (data->factor))
+                       rate *= data->factor;
+               if (!isnan (data->offset))
+                       rate += data->offset;
+
+               /* Calculate the internal derive. */
+               int_fraction += (rate * ((double) vl->interval));
+               if (int_fraction < 0.0) /* handle negative integer rounding correctly */
+                       difference = ((int64_t) int_fraction) - 1;
+               else
+                       difference = (int64_t) int_fraction;
+               int_fraction -= ((double) difference);
+               int_derive  += difference;
+
+               assert (int_fraction >= 0.0);
+               assert (int_fraction <  1.0);
+
+               DEBUG ("Target `scale': ts_invoke_derive: %"PRIu64" -> %g -> %"PRIu64
+                               "(+%g)",
+                               curr_derive, rate, int_derive, int_fraction);
+       }
+       else /* (failure != 0) */
+       {
+               int_derive = 0;
+               int_fraction = 0.0;
+       }
+
+       vl->values[dsrc_index].derive = (derive_t) int_derive;
+
+       /* Update to the new derive value */
+       uc_meta_data_add_signed_int (vl, key_prev_derive, curr_derive);
+       uc_meta_data_add_signed_int (vl, key_int_derive, int_derive);
+       uc_meta_data_add_double (vl, key_int_fraction, int_fraction);
+
+       return (0);
+} /* }}} int ts_invoke_derive */
+
+static int ts_invoke_absolute (const data_set_t *ds, value_list_t *vl, /* {{{ */
+               ts_data_t *data, int dsrc_index)
+{
+       uint64_t curr_absolute;
+       double rate;
+       int status;
+
+       /* Required meta data */
+       double int_fraction;
+       char key_int_fraction[128];
+
+       curr_absolute = (uint64_t) vl->values[dsrc_index].absolute;
+
+       ssnprintf (key_int_fraction, sizeof (key_int_fraction),
+                       "target_scale[%p,%i]:int_fraction",
+                       (void *) data, dsrc_index);
+
+       int_fraction = 0.0;
+
+       /* Query the meta data */
+       status = uc_meta_data_get_double (vl, key_int_fraction, &int_fraction);
+       if (status != 0)
+               int_fraction = 0.0;
+
+       rate = ((double) curr_absolute) / ((double) vl->interval);
+
+       /* Modify the rate. */
+       if (!isnan (data->factor))
+               rate *= data->factor;
+       if (!isnan (data->offset))
+               rate += data->offset;
+
+       /* Calculate the new absolute. */
+       int_fraction += (rate * ((double) vl->interval));
+       curr_absolute = (uint64_t) int_fraction;
+       int_fraction -= ((double) curr_absolute);
+
+       vl->values[dsrc_index].absolute = (absolute_t) curr_absolute;
+
+       /* Update to the new absolute value */
+       uc_meta_data_add_double (vl, key_int_fraction, int_fraction);
+
+       return (0);
+} /* }}} int ts_invoke_absolute */
+
+static int ts_config_set_double (double *ret, oconfig_item_t *ci) /* {{{ */
+{
+       if ((ci->values_num != 1)
+                       || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
+       {
+               WARNING ("scale target: The `%s' config option needs "
+                               "exactly one numeric argument.", ci->key);
+               return (-1);
+       }
+
+       *ret = ci->values[0].value.number;
+       DEBUG ("ts_config_set_double: *ret = %g", *ret);
+
+       return (0);
+} /* }}} int ts_config_set_double */
+
+static int ts_destroy (void **user_data) /* {{{ */
+{
+       if (user_data == NULL)
+               return (-EINVAL);
+
+       free (*user_data);
+       *user_data = NULL;
+
+       return (0);
+} /* }}} int ts_destroy */
+
+static int ts_create (const oconfig_item_t *ci, void **user_data) /* {{{ */
+{
+       ts_data_t *data;
+       int status;
+       int i;
+
+       data = (ts_data_t *) malloc (sizeof (*data));
+       if (data == NULL)
+       {
+               ERROR ("ts_create: malloc failed.");
+               return (-ENOMEM);
+       }
+       memset (data, 0, sizeof (*data));
+
+       data->factor = NAN;
+       data->offset = NAN;
+
+       status = 0;
+       for (i = 0; i < ci->children_num; i++)
+       {
+               oconfig_item_t *child = ci->children + i;
+
+               if (strcasecmp ("Factor", child->key) == 0)
+                               status = ts_config_set_double (&data->factor, child);
+               else if (strcasecmp ("Offset", child->key) == 0)
+                               status = ts_config_set_double (&data->offset, child);
+               else
+               {
+                       ERROR ("Target `scale': The `%s' configuration option is not understood "
+                                       "and will be ignored.", child->key);
+                       status = 0;
+               }
+
+               if (status != 0)
+                       break;
+       }
+
+       /* Additional sanity-checking */
+       while (status == 0)
+       {
+               if (isnan (data->factor) && isnan (data->offset))
+               {
+                       ERROR ("Target `scale': You need to at least set either the `Factor' "
+                                       "or `Offset' option!");
+                       status = -1;
+               }
+
+               break;
+       }
+
+       if (status != 0)
+       {
+               ts_destroy ((void *) &data);
+               return (status);
+       }
+
+       *user_data = data;
+       return (0);
+} /* }}} int ts_create */
+
+static int ts_invoke (const data_set_t *ds, value_list_t *vl, /* {{{ */
+               notification_meta_t __attribute__((unused)) **meta, void **user_data)
+{
+       ts_data_t *data;
+       int i;
+
+       if ((ds == NULL) || (vl == NULL) || (user_data == NULL))
+               return (-EINVAL);
+
+       data = *user_data;
+       if (data == NULL)
+       {
+               ERROR ("Target `scale': Invoke: `data' is NULL.");
+               return (-EINVAL);
+       }
+
+       for (i = 0; i < ds->ds_num; i++)
+       {
+               if (ds->ds[i].type == DS_TYPE_COUNTER)
+                       ts_invoke_counter (ds, vl, data, i);
+               else if (ds->ds[i].type == DS_TYPE_GAUGE)
+                       ts_invoke_gauge (ds, vl, data, i);
+               else if (ds->ds[i].type == DS_TYPE_DERIVE)
+                       ts_invoke_derive (ds, vl, data, i);
+               else if (ds->ds[i].type == DS_TYPE_ABSOLUTE)
+                       ts_invoke_absolute (ds, vl, data, i);
+               else
+                       ERROR ("Target `scale': Ignoring unknown data source type %i",
+                                       ds->ds[i].type);
+       }
+
+       return (FC_TARGET_CONTINUE);
+} /* }}} int ts_invoke */
+
+void module_register (void)
+{
+       target_proc_t tproc;
+
+       memset (&tproc, 0, sizeof (tproc));
+       tproc.create  = ts_create;
+       tproc.destroy = ts_destroy;
+       tproc.invoke  = ts_invoke;
+       fc_register_target ("scale", tproc);
+} /* module_register */
+
+/* vim: set sw=2 ts=2 tw=78 fdm=marker : */
+
index 26366c9..678a341 100644 (file)
 #include "utils_cache.h"
 #include "utils_parse_option.h"
 
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-
 #include <tcrdb.h>
 
 #define DEFAULT_HOST "127.0.0.1"
@@ -46,56 +42,6 @@ static char *config_port = NULL;
 
 static TCRDB *rdb = NULL;
 
-static int parse_service_name (const char *service_name)
-{
-       struct addrinfo *ai_list;
-       struct addrinfo *ai_ptr;
-       struct addrinfo ai_hints;
-       int status;
-       int service_number;
-
-       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 ("tokyotyrant plugin: 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 parse_service_name */
-
 static int tt_config (const char *key, const char *value)
 {
        if (strcasecmp ("Host", key) == 0)
@@ -171,7 +117,7 @@ static void tt_open_db (void)
 
        if (config_port != NULL)
        {
-               port = parse_service_name (config_port);
+               port = service_name_to_port_number (config_port);
                if (port <= 0)
                        return;
        }
index 8ac9dd4..960674c 100644 (file)
@@ -12,6 +12,7 @@ ath_nodes             value:GAUGE:0:65535
 ath_stat               value:COUNTER:0:4294967295
 bitrate                        value:GAUGE:0:4294967295
 bytes                  value:GAUGE:0:U
+cache_ratio            value:GAUGE:0:100
 cache_result           value:COUNTER:0:4294967295
 cache_size             value:GAUGE:0:4294967295
 charge                 value:GAUGE:0:U
@@ -25,9 +26,12 @@ current                      value:GAUGE:U:U
 delay                  seconds:GAUGE:-1000000:1000000
 derive                 value:DERIVE:0:U
 df                     used:GAUGE:0:1125899906842623, free:GAUGE:0:1125899906842623
+df_complex             value:GAUGE:0:U
+disk_latency           read:GAUGE:0:U, write:GAUGE:0:U
 disk_merged            read:COUNTER:0:4294967295, write:COUNTER:0:4294967295
 disk_octets            read:COUNTER:0:17179869183, write:COUNTER:0:17179869183
 disk_ops               read:COUNTER:0:4294967295, write:COUNTER:0:4294967295
+disk_ops_complex       value:COUNTER:0:4294967296
 disk_time              read:COUNTER:0:1000000, write:COUNTER:0:1000000
 dns_answer             value:COUNTER:0:65535
 dns_notify             value:COUNTER:0:65535
@@ -121,6 +125,7 @@ ps_stacksize                value:GAUGE:0:9223372036854775807
 ps_state               value:GAUGE:0:65535
 ps_vm                  value:GAUGE:0:9223372036854775807
 queue_length           value:GAUGE:0:U
+response_time          value:GAUGE:0:U
 records                        count:GAUGE:0:U
 route_etx              value:GAUGE:0:U
 route_metric           value:GAUGE:0:U