author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Tue, 10 Nov 2009 19:18:05 +0000 (20:18 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Tue, 10 Nov 2009 19:18:05 +0000 (20:18 +0100) |
46 files changed:
index 8d0a022d22f0698eef840d89f777bd04f29f203e..885d021a17c380ea246152697e4f96454364bb74 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
Ondrej Zajicek <santiago at crfreenet.org>
- madwifi plugin.
+Patrik Weiskircher <weiskircher at inqnet.at>
+ - Contextswitch plugin.
+ - Forkrate counter in the processes plugin.
+ - INode count in the DF plugin.
+
Paul Sadauskas <psadauskas at gmail.com>
- tokyotyrant plugin.
- `ReportByDevice' option of the df plugin.
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.
index 37ddf8eb7bf95245cd8270efa2468d4ae0b18b15..d40fd2f0ab596a42b4aaa5f735d7fc1c0ff4e43c 100644 (file)
--- a/README
+++ b/README
- conntrack
Number of nf_conntrack entries.
+ - contextswitch
+ Number of context switches done by the operating system.
+
- cpu
CPU utilization: Time spent in the system, user, nice, idle, and related
states.
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
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>
diff --git a/configure.in b/configure.in
index 589ff75bb159b8051a715c5d9e5f1d68e885c045..b3d9516e30e349db1b6f843ce44a8080bdc1e265 100644 (file)
--- a/configure.in
+++ b/configure.in
#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)
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 -lcrypto -lz"
+ 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=""
plugin_battery="no"
plugin_bind="no"
plugin_conntrack="no"
+plugin_contextswitch="no"
plugin_cpu="no"
plugin_cpufreq="no"
plugin_curl_json="no"
then
plugin_battery="yes"
plugin_conntrack="yes"
+ plugin_contextswitch="yes"
plugin_cpu="yes"
plugin_cpufreq="yes"
plugin_disk="yes"
AC_PLUGIN([battery], [$plugin_battery], [Battery statistics])
AC_PLUGIN([bind], [$plugin_bind], [ISC Bind nameserver statistics])
AC_PLUGIN([conntrack], [$plugin_conntrack], [nf_conntrack statistics])
+AC_PLUGIN([contextswitch], [$plugin_contextswitch], [context switch statistics])
AC_PLUGIN([cpufreq], [$plugin_cpufreq], [CPU frequency statistics])
AC_PLUGIN([cpu], [$plugin_cpu], [CPU usage statistics])
AC_PLUGIN([csv], [yes], [CSV output plugin])
AC_PLUGIN([logfile], [yes], [File logging plugin])
AC_PLUGIN([madwifi], [$have_linux_wireless_h], [Madwifi wireless statistics])
AC_PLUGIN([match_empty_counter], [yes], [The empty counter match])
+AC_PLUGIN([match_hashed], [yes], [The hashed match])
AC_PLUGIN([match_regex], [yes], [The regex match])
AC_PLUGIN([match_timediff], [yes], [The timediff match])
AC_PLUGIN([match_value], [yes], [The value match])
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])
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])
libkvm . . . . . . . $with_libkvm
libmemcached . . . . $with_libmemcached
libmysql . . . . . . $with_libmysql
+ libnetapp . . . . . . $with_libnetapp
libnetlink . . . . . $with_libnetlink
libnetsnmp . . . . . $with_libnetsnmp
libnotify . . . . . . $with_libnotify
battery . . . . . . . $enable_battery
bind . . . . . . . . $enable_bind
conntrack . . . . . . $enable_conntrack
+ contextswitch . . . . $enable_contextswitch
cpu . . . . . . . . . $enable_cpu
cpufreq . . . . . . . $enable_cpufreq
csv . . . . . . . . . $enable_csv
logfile . . . . . . . $enable_logfile
madwifi . . . . . . . $enable_madwifi
match_empty_counter . $enable_match_empty_counter
+ match_hashed . . . . $enable_match_hashed
match_regex . . . . . $enable_match_regex
match_timediff . . . $enable_match_timediff
match_value . . . . . $enable_match_value
memory . . . . . . . $enable_memory
multimeter . . . . . $enable_multimeter
mysql . . . . . . . . $enable_mysql
+ netapp . . . . . . . $enable_netapp
netlink . . . . . . . $enable_netlink
network . . . . . . . $enable_network
nfs . . . . . . . . . $enable_nfs
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 1322d0d9f6bdf24f35c283dc023ac08fbc542537..e56017e11bcda6e0ce7662536e012bb9c5bbfb07 100644 (file)
<Type df_complex>
Module GenericStacked
DataSources value
- RRDTitle "disk usage on {plugin_instance}"
+ RRDTitle "Disk/Volume usage on {plugin_instance}"
RRDVerticalLabel "Byte"
- RRDFormat "%6.2lf%s"
- DSName "snap_used used for snapshots"
- DSName "snap_reserved snapshot reserve "
- DSName "used in use "
- DSName "free free "
- DSName "sis_saved sis_saved "
- Order free snap_used snap_reserved sis_saved used
+ RRDFormat "%5.1lf%s"
+ DSName "sis_saved SIS saved "
+ DSName "free Free "
+ DSName "used Used "
+ DSName "snap_normal_used Snap used (normal)"
+ DSName "snap_reserved Snap reserved "
+ DSName "snap_reserve_used Snap used (resv) "
+ Order sis_saved free used snap_normal_used snap_reserved snap_reserve_used
+ Color sis_saved 00e0e0
+ Color free 00ff00
Color snap_reverse ff8000
Color used ff0000
- Color snap_used 000080
- Color snap_reserved ff8000
- Color free 00ff00
- Color sis_saved 00e0e0
+ Color snap_normal_used c10640
+ Color snap_reserved f15aef
+ Color snap_reserve_used 820c81
</Type>
<Type disk_latency>
Module GenericIO
diff --git a/src/Makefile.am b/src/Makefile.am
index 0ed299b5fa48d830eb92cad8e6ddd77c1eed5bed..15609e47cd10df369cacebf6c4b1d96e2b8b7b3b 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
collectd_DEPENDENCIES += conntrack.la
endif
+if BUILD_PLUGIN_CONTEXTSWITCH
+pkglib_LTLIBRARIES += contextswitch.la
+contextswitch_la_SOURCES = contextswitch.c
+contextswitch_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" contextswitch.la
+collectd_DEPENDENCIES += contextswitch.la
+endif
+
if BUILD_PLUGIN_CPU
pkglib_LTLIBRARIES += cpu.la
cpu_la_SOURCES = cpu.c
collectd_DEPENDENCIES += match_empty_counter.la
endif
+if BUILD_PLUGIN_MATCH_HASHED
+pkglib_LTLIBRARIES += match_hashed.la
+match_hashed_la_SOURCES = match_hashed.c
+match_hashed_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" match_hashed.la
+collectd_DEPENDENCIES += match_hashed.la
+endif
+
if BUILD_PLUGIN_MATCH_REGEX
pkglib_LTLIBRARIES += match_regex.la
match_regex_la_SOURCES = match_regex.c
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
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
diff --git a/src/apache.c b/src/apache.c
index a333bf2b50a7db6a6ab39d1e2eaa962ca1902f17..df1b560f092e89bbc8dd9cb65309fb55b20216f5 100644 (file)
--- a/src/apache.c
+++ b/src/apache.c
else /* if (ci->values[0].type != OCONFIG_TYPE_STRING) */
{
char *string = ci->values[0].value.string;
- if ((strcasecmp ("true", string) == 0)
- || (strcasecmp ("yes", string) == 0)
- || (strcasecmp ("on", string) == 0))
+ if (IS_TRUE (string))
*ret_boolean = 1;
- else if ((strcasecmp ("false", string) == 0)
- || (strcasecmp ("no", string) == 0)
- || (strcasecmp ("off", string) == 0))
+ else if (IS_FALSE (string))
*ret_boolean = 0;
else
{
diff --git a/src/ascent.c b/src/ascent.c
index 1e7eca1480fee669b888cd279a3f903f7e1ddeb9..6782fce199db3f5c9ffbbe984d81080e7e1a7cb3 100644 (file)
--- a/src/ascent.c
+++ b/src/ascent.c
curl_easy_setopt (curl, CURLOPT_URL, url);
curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1);
- if ((verify_peer == NULL) || (strcmp (verify_peer, "true") == 0))
+ if ((verify_peer == NULL) || IS_TRUE (verify_peer))
curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 1);
else
curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0);
- if ((verify_host == NULL) || (strcmp (verify_host, "true") == 0))
+ if ((verify_host == NULL) || IS_TRUE (verify_host))
curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 2);
else
curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 0);
diff --git a/src/collectd-exec.pod b/src/collectd-exec.pod
index b95779dd5fc4414cb6e65bebcac880d6c048070a..81b3a2ecc07ecb11302b7ede4d2e26f87e72f0d8 100644 (file)
--- a/src/collectd-exec.pod
+++ b/src/collectd-exec.pod
=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.
diff --git a/src/collectd.c b/src/collectd.c
index 576abef48c7110575d3a7452008c4a28970db3c4..bc69a3b7fc47d2279f63b0d148b210f525bcf825 100644 (file)
--- a/src/collectd.c
+++ b/src/collectd.c
}
str = global_option_get ("FQDNLookup");
- if ((strcasecmp ("false", str) == 0)
- || (strcasecmp ("no", str) == 0)
- || (strcasecmp ("off", str) == 0))
+ if (IS_FALSE (str))
return (0);
memset (&ai_hints, '\0', sizeof (ai_hints));
diff --git a/src/collectd.conf.in b/src/collectd.conf.in
index f76d9d63f49fdf7145cdb830a0848bc29bacd8a7..ad13353f59242ddadceed98393f03fed8cdfa1a7 100644 (file)
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
#@BUILD_PLUGIN_BATTERY_TRUE@LoadPlugin battery
#@BUILD_PLUGIN_BIND_TRUE@LoadPlugin bind
#@BUILD_PLUGIN_CONNTRACK_TRUE@LoadPlugin conntrack
+#@BUILD_PLUGIN_CONTEXTSWITCH_TRUE@LoadPlugin contextswitch
@BUILD_PLUGIN_CPU_TRUE@@BUILD_PLUGIN_CPU_TRUE@LoadPlugin cpu
#@BUILD_PLUGIN_CPUFREQ_TRUE@LoadPlugin cpufreq
@LOAD_PLUGIN_CSV@LoadPlugin csv
# TimeToLive "128"
# Forward false
# CacheFlush 1800
+# ReportStats false
@LOAD_PLUGIN_NETWORK@</Plugin>
#<Plugin nginx>
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 43a322bf879d96f6ffda6ff4407aa3e33d9df638..6bae33936e3eac1b0cbe6980e019bf1e55db1d45 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
@@ -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
Select partitions based on the filesystem type.
-=item B<IgnoreSelected> I<true>|I<false>
+=item B<IgnoreSelected> B<true>|B<false>
Invert the selection: If set to true, all partitions B<except> the ones that
match any one of the criteria are collected. By default only selected
partitions are collected if a selection is made. If no selection is configured
at all, B<all> partitions are selected.
-=item B<ReportByDevice> I<true>|I<false>
+=item B<ReportByDevice> B<true>|B<false>
Report using the device name rather than the mountpoint. i.e. with this I<false>,
(the default), it will report a disk as "root", but with it I<true>, it will be
"sda1" (or whichever).
+=item B<ReportReserved> B<true>|B<false>
+
+When enabled, the blocks reserved for root are reported separately. When
+disabled (the default for backwards compatibility reasons) the reserved space
+will be included in the "free" space.
+
+When disabled, the "df" type will be used to store "free" and "used" space. The
+mount point or disk name (see option B<ReportByDevice>) is used as type
+instance in this case (again: backwards compatibility).
+
+When enabled, the type "df_complex" is used and three files are created. The
+mount point or disk name is used as plugin instance and the type instance is
+set to "free", "reserved" and "used" as appropriate.
+
+Enabling this option is recommended.
+
+=item B<ReportInodes> B<true>|B<false>
+
+Enables or disables reporting of free, reserved and used inodes. Defaults to
+inode collection being disabled.
+
+Enable this option if inodes are a scarce resource for you, usually because
+many small files are stored on the disk. This is a usual scenario for mail
+transfer agents and web caches.
+
=back
=head2 Plugin C<disk>
=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
1800 seconds, but setting this to 86400 seconds (one day) will not do much harm
either.
+=item B<ReportStats> B<true>|B<false>
+
+The network plugin cannot only receive and send statistics, it can also create
+statistics about itself. Collected data included the number of received and
+sent octets and packets, the length of the receive queue and the number of
+values handled. When set to B<true>, the I<Network plugin> will make these
+statistics available. Defaults to B<false>.
+
=back
=head2 Plugin C<nginx>
Select more detailed statistics of processes matching this name. The statistics
collected for these selected processes are size of the resident segment size
(RSS), user- and system-time used, number of processes and number of threads,
-and minor and major pagefaults.
+io data (where available) and minor and major pagefaults.
=item B<ProcessMatch> I<name> I<regex>
usually), the graph will be empty (NAN) for a long time. People may not
understand why.
+=item B<hashed>
+
+Calculates a hash value of the host name and matches values according to that
+hash value. This makes it possible to divide all hosts into groups and match
+only values that are in a specific group. The intended use is in load
+balancing, where you want to handle only part of all data and leave the rest
+for other servers.
+
+The hashing function used tries to distribute the hosts evenly. First, it
+calculates a 32E<nbsp>bit hash value using the characters of the hostname:
+
+ hash_value = 0;
+ for (i = 0; host[i] != 0; i++)
+ hash_value = (hash_value * 251) + host[i];
+
+The constant 251 is a prime number which is supposed to make this hash value
+more random. The code then checks the group for this host according to the
+I<Total> and I<Match> arguments:
+
+ if ((hash_value % Total) == Match)
+ matches;
+ else
+ does not match;
+
+Please note that when you set I<Total> to two (i.E<nbsp>e. you have only two
+groups), then the least significant bit of the hash value will be the XOR of
+all least significant bits in the host name. One consequence is that when you
+have two hosts, "server0.example.com" and "server1.example.com", where the host
+name differs in one digit only and the digits differ by one, those hosts will
+never end up in the same group.
+
+Available options:
+
+=over 4
+
+=item B<Match> I<Match> I<Total>
+
+Divide the data into I<Total> groups and match all hosts in group I<Match> as
+described above. The groups are numbered from zero, i.E<nbsp>e. I<Match> must
+be smaller than I<Total>. I<Total> must be at least one, although only values
+greater than one really do make any sense.
+
+You can repeat this option to match multiple groups, for example:
+
+ Match 3 7
+ Match 5 7
+
+The above config will divide the data into seven groups and match groups three
+and five. One use would be to keep every value on two hosts so that if one
+fails the missing data can later be reconstructed from the second host.
+
+=back
+
+Example:
+
+ # Operate on the pre-cache chain, so that ignored values are not even in the
+ # global cache.
+ <Chain "PreCache">
+ <Rule>
+ <Match "hashed">
+ # Divide all received hosts in seven groups and accept all hosts in
+ # group three.
+ Match 3 7
+ </Match>
+ # If matched: Return and continue.
+ Target "return"
+ </Rule>
+ # If not matched: Return and stop.
+ Target "stop"
+ </Chain>
+
=back
=head2 Available targets
diff --git a/src/common.c b/src/common.c
index 7c2c30eccf38b1bcc498264727679b6be3270031..c6a651dc56248050ccc0b7a50c7aca68e4f2c3f9 100644 (file)
--- a/src/common.c
+++ b/src/common.c
/**
* 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
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 */
diff --git a/src/common.h b/src/common.h
index 6682e1c852ffd3328253f347a54fa23de78f630b..019e8b69f9817e673df2b7f3f673401d91e7579f 100644 (file)
--- a/src/common.h
+++ b/src/common.h
/**
* 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
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 */
diff --git a/src/configfile.c b/src/configfile.c
index d401a2e1e0e2998a1a965fa9b31acb2532106682..1a957f67463f138c673cc5dd5f23ebcbabffa8c3 100644 (file)
--- a/src/configfile.c
+++ b/src/configfile.c
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 */
diff --git a/src/configfile.h b/src/configfile.h
index 3952c180d9949f08bc42a94899d23a9c19a5db70..74d074ed2fb746d7b4fe9596e7589532da966799 100644 (file)
--- a/src/configfile.h
+++ b/src/configfile.h
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) */
diff --git a/src/contextswitch.c b/src/contextswitch.c
--- /dev/null
+++ b/src/contextswitch.c
@@ -0,0 +1,98 @@
+/**
+ * collectd - src/contextswitch.c
+ * Copyright (C) 2009 Patrik Weiskircher
+ *
+ * This program 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:
+ * Patrik Weiskircher <weiskircher at inqnet.at>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+#if !KERNEL_LINUX
+# error "No applicable input method."
+#endif
+
+static void cs_submit (unsigned long context_switches)
+{
+ value_t values[1];
+ value_list_t vl = VALUE_LIST_INIT;
+
+ values[0].derive = (derive_t) context_switches;
+
+ vl.values = values;
+ vl.values_len = 1;
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+ sstrncpy (vl.plugin, "contextswitch", sizeof (vl.plugin));
+ sstrncpy (vl.type, "contextswitch", sizeof (vl.type));
+
+ plugin_dispatch_values (&vl);
+}
+
+static int cs_read (void)
+{
+ FILE *fh;
+ char buffer[64];
+ int numfields;
+ char *fields[3];
+ unsigned long result = 0;
+ int status = -2;
+
+ fh = fopen ("/proc/stat", "r");
+ if (fh == NULL) {
+ ERROR ("contextswitch plugin: unable to open /proc/stat: %s",
+ sstrerror (errno, buffer, sizeof (buffer)));
+ return (-1);
+ }
+
+ while (fgets(buffer, sizeof(buffer), fh) != NULL)
+ {
+ char *endptr;
+
+ numfields = strsplit(buffer, fields, STATIC_ARRAY_SIZE (fields));
+ if (numfields != 2)
+ continue;
+
+ if (strcmp("ctxt", fields[0]) != 0)
+ continue;
+
+ errno = 0;
+ endptr = NULL;
+ result = strtoul(fields[1], &endptr, 10);
+ if ((endptr == fields[1]) || (errno != 0)) {
+ ERROR ("contextswitch plugin: Cannot parse ctxt value: %s",
+ fields[1]);
+ status = -1;
+ break;
+ }
+
+ cs_submit(result);
+ status = 0;
+ break;
+ }
+ fclose(fh);
+
+ if (status == -2)
+ ERROR ("contextswitch plugin: Unable to find context switch value.");
+
+ return status;
+}
+
+void module_register (void)
+{
+ plugin_register_read ("contextswitch", cs_read);
+} /* void module_register */
diff --git a/src/cpu.c b/src/cpu.c
index dc44a50ff5f71b732ae69a4be9ba64401b09d7e7..b92b0e2f0b7e74d4f89800e97d29e0434b5abe83 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
#elif defined(HAVE_SYSCTLBYNAME)
static int numcpu;
+# ifdef HAVE_SYSCTL_KERN_CP_TIMES
+static int maxcpu;
+# endif /* HAVE_SYSCTL_KERN_CP_TIMES */
/* #endif HAVE_SYSCTLBYNAME */
#elif defined(HAVE_LIBSTATGRAB)
if (sysctlbyname ("hw.ncpu", &numcpu, &numcpu_size, NULL, 0) < 0)
{
char errbuf[1024];
- WARNING ("cpu plugin: sysctlbyname: %s",
+ WARNING ("cpu plugin: sysctlbyname(hw.ncpu): %s",
sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
+#ifdef HAVE_SYSCTL_KERN_CP_TIMES
+ numcpu_size = sizeof (maxcpu);
+
+ if (sysctlbyname("kern.smp.maxcpus", &maxcpu, &numcpu_size, NULL, 0) < 0)
+ {
+ char errbuf[1024];
+ WARNING ("cpu plugin: sysctlbyname(kern.smp.maxcpus): %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ return (-1);
+ }
+#else
if (numcpu != 1)
NOTICE ("cpu: Only one processor supported when using `sysctlbyname' (found %i)", numcpu);
+#endif
/* #endif HAVE_SYSCTLBYNAME */
#elif defined(HAVE_LIBSTATGRAB)
submit (i, "interrupt", cpuinfo[i][CP_INTR]);
}
/* #endif CAN_USE_SYSCTL */
+#elif defined(HAVE_SYSCTLBYNAME) && defined(HAVE_SYSCTL_KERN_CP_TIMES)
+ long cpuinfo[maxcpu][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;
diff --git a/src/csv.c b/src/csv.c
index 78037a940ca3981a150a3fa84055c490b83c955b..0b34687dac172b863379a89803d1a86936c9c71d 100644 (file)
--- a/src/csv.c
+++ b/src/csv.c
}
else if (strcasecmp ("StoreRates", key) == 0)
{
- if ((strcasecmp ("True", value) == 0)
- || (strcasecmp ("Yes", value) == 0)
- || (strcasecmp ("On", value) == 0))
- {
+ if (IS_TRUE (value))
store_rates = 1;
- }
else
- {
store_rates = 0;
- }
}
else
{
diff --git a/src/curl.c b/src/curl.c
index a43e7ed9000781b16390dfb024ce270858b64b86..abf45c23d2c7990077295a0c130c3ecd358bf498 100644 (file)
--- a/src/curl.c
+++ b/src/curl.c
int verify_peer;
int verify_host;
char *cacert;
+ int response_time;
CURL *curl;
char curl_errbuf[CURL_ERROR_SIZE];
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)
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)
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;
}
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);
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;
diff --git a/src/df.c b/src/df.c
index 462e1c6778fe3aa2f1066de9e3172b548fada012..62775fd286df0485c1fd0e23e25142a921e6a4c1 100644 (file)
--- a/src/df.c
+++ b/src/df.c
"MountPoint",
"FSType",
"IgnoreSelected",
- "ReportByDevice"
+ "ReportByDevice",
+ "ReportReserved",
+ "ReportInodes"
};
static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
static ignorelist_t *il_fstype = NULL;
static _Bool by_device = false;
+static _Bool report_reserved = false;
+static _Bool report_inodes = false;
static int df_init (void)
{
return (0);
}
+ else if (strcasecmp (key, "ReportReserved") == 0)
+ {
+ if (IS_TRUE (value))
+ report_reserved = true;
+ else
+ report_reserved = false;
+
+ return (0);
+ }
+ else if (strcasecmp (key, "ReportInodes") == 0)
+ {
+ if (IS_TRUE (value))
+ report_inodes = true;
+ else
+ report_inodes = false;
+
+ return (0);
+ }
+
return (-1);
}
-static void df_submit (char *df_name,
+static void df_submit_two (char *df_name,
+ const char *type,
gauge_t df_used,
gauge_t df_free)
{
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "df", sizeof (vl.plugin));
sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance));
- sstrncpy (vl.type, "df", sizeof (vl.type));
+ sstrncpy (vl.type, type, sizeof (vl.type));
sstrncpy (vl.type_instance, df_name, sizeof (vl.type_instance));
plugin_dispatch_values (&vl);
-} /* void df_submit */
+} /* void df_submit_two */
+
+__attribute__ ((nonnull(2)))
+static void df_submit_one (char *plugin_instance,
+ const char *type, const char *type_instance,
+ gauge_t value)
+{
+ value_t values[1];
+ value_list_t vl = VALUE_LIST_INIT;
+
+ values[0].gauge = value;
+
+ vl.values = values;
+ vl.values_len = 1;
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+ sstrncpy (vl.plugin, "df", sizeof (vl.plugin));
+ if (plugin_instance != NULL)
+ sstrncpy (vl.plugin_instance, plugin_instance,
+ sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
+ if (type_instance != NULL)
+ sstrncpy (vl.type_instance, type_instance,
+ sizeof (vl.type_instance));
+
+ plugin_dispatch_values (&vl);
+} /* void df_submit_one */
static int df_read (void)
{
cu_mount_t *mnt_list;
cu_mount_t *mnt_ptr;
- unsigned long long blocksize;
- gauge_t df_free;
- gauge_t df_used;
- char disk_name[256];
-
mnt_list = NULL;
if (cu_mount_getlist (&mnt_list) == NULL)
return (-1);
for (mnt_ptr = mnt_list; mnt_ptr != NULL; mnt_ptr = mnt_ptr->next)
{
+ unsigned long long blocksize;
+ char disk_name[256];
+
if (ignorelist_match (il_device,
(mnt_ptr->spec_device != NULL)
? mnt_ptr->spec_device
if (!statbuf.f_blocks)
continue;
- blocksize = BLOCKSIZE(statbuf);
- df_free = statbuf.f_bfree * blocksize;
- df_used = (statbuf.f_blocks - statbuf.f_bfree) * blocksize;
-
if (by_device)
{
/* eg, /dev/hda1 -- strip off the "/dev/" */
}
}
- df_submit (disk_name, df_used, df_free);
+ blocksize = BLOCKSIZE(statbuf);
+
+ if (report_reserved)
+ {
+ uint64_t blk_free;
+ uint64_t blk_reserved;
+ uint64_t blk_used;
+
+ /* Sanity-check for the values in the struct */
+ if (statbuf.f_bfree < statbuf.f_bavail)
+ statbuf.f_bfree = statbuf.f_bavail;
+ if (statbuf.f_blocks < statbuf.f_bfree)
+ statbuf.f_blocks = statbuf.f_bfree;
+
+ blk_free = (uint64_t) statbuf.f_bavail;
+ blk_reserved = (uint64_t) (statbuf.f_bfree - statbuf.f_bavail);
+ blk_used = (uint64_t) (statbuf.f_blocks - statbuf.f_bfree);
+
+ df_submit_one (disk_name, "df_complex", "free",
+ (gauge_t) (blk_free * blocksize));
+ df_submit_one (disk_name, "df_complex", "reserved",
+ (gauge_t) (blk_reserved * blocksize));
+ df_submit_one (disk_name, "df_complex", "used",
+ (gauge_t) (blk_used * blocksize));
+ }
+ else /* compatibility code */
+ {
+ gauge_t df_free;
+ gauge_t df_used;
+
+ df_free = statbuf.f_bfree * blocksize;
+ df_used = (statbuf.f_blocks - statbuf.f_bfree) * blocksize;
+
+ df_submit_two (disk_name, "df", df_used, df_free);
+ }
+
+ /* inode handling */
+ if (report_inodes)
+ {
+ uint64_t inode_free;
+ uint64_t inode_reserved;
+ uint64_t inode_used;
+
+ /* Sanity-check for the values in the struct */
+ if (statbuf.f_ffree < statbuf.f_favail)
+ statbuf.f_ffree = statbuf.f_favail;
+ if (statbuf.f_files < statbuf.f_ffree)
+ statbuf.f_files = statbuf.f_ffree;
+
+ inode_free = (uint64_t) statbuf.f_favail;
+ inode_reserved = (uint64_t) (statbuf.f_ffree - statbuf.f_favail);
+ inode_used = (uint64_t) (statbuf.f_files - statbuf.f_ffree);
+
+ df_submit_one (disk_name, "df_inodes", "free",
+ (gauge_t) inode_free);
+ df_submit_one (disk_name, "df_inodes", "reserved",
+ (gauge_t) inode_reserved);
+ df_submit_one (disk_name, "df_inodes", "used",
+ (gauge_t) inode_used);
+ }
}
cu_mount_freelist (mnt_list);
diff --git a/src/disk.c b/src/disk.c
index 489770c7f9da86b9f8c0cb50d918871933c05603..5df1c9827b465d136e185fa9b15925d142912c10 100644 (file)
--- a/src/disk.c
+++ b/src/disk.c
else if (strcasecmp ("IgnoreSelected", key) == 0)
{
int invert = 1;
- if ((strcasecmp ("True", value) == 0)
- || (strcasecmp ("Yes", value) == 0)
- || (strcasecmp ("On", value) == 0))
+ if (IS_TRUE (value))
invert = 0;
ignorelist_set_invert (ignorelist, invert);
}
diff --git a/src/exec.c b/src/exec.c
index 8719201ea956fe3129561889191fddab3f047a35..acc6cf6f12aa93ea7fc743e78cc378acaf78c29a 100644 (file)
--- a/src/exec.c
+++ b/src/exec.c
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/hddtemp.c b/src/hddtemp.c
index 2405d8c3e9d540152aaab25cab0c703c8bb22c5c..4e083753202718c588f72b0b1a2c58dc3ef1f37c 100644 (file)
--- a/src/hddtemp.c
+++ b/src/hddtemp.c
}
else if (strcasecmp (key, "TranslateDevicename") == 0)
{
- if ((strcasecmp ("true", value) == 0)
- || (strcasecmp ("yes", value) == 0)
- || (strcasecmp ("on", value) == 0))
+ if (IS_TRUE (value))
translate_devicename = 1;
else
translate_devicename = 0;
diff --git a/src/interface.c b/src/interface.c
index fad37dbefdaf6208133e2454da22ac3ef2e263db..fead88859c08fd5e429a973a1bd79d9ed7898c12 100644 (file)
--- a/src/interface.c
+++ b/src/interface.c
else if (strcasecmp (key, "IgnoreSelected") == 0)
{
int invert = 1;
- if ((strcasecmp (value, "True") == 0)
- || (strcasecmp (value, "Yes") == 0)
- || (strcasecmp (value, "On") == 0))
+ if (IS_TRUE (value))
invert = 0;
ignorelist_set_invert (ignorelist, invert);
}
diff --git a/src/ipmi.c b/src/ipmi.c
index 441ad8fbc543ee4651ad0f458a9cb45b4d499c8e..95b3dbf5625fcd4c09aef04d2a880c5ca85d2ae8 100644 (file)
--- a/src/ipmi.c
+++ b/src/ipmi.c
else if (strcasecmp ("IgnoreSelected", key) == 0)
{
int invert = 1;
- if ((strcasecmp ("True", value) == 0)
- || (strcasecmp ("Yes", value) == 0)
- || (strcasecmp ("On", value) == 0))
+ if (IS_TRUE (value))
invert = 0;
ignorelist_set_invert (ignorelist, invert);
}
else if (strcasecmp ("NotifySensorAdd", key) == 0)
{
- if ((strcasecmp ("True", value) == 0)
- || (strcasecmp ("Yes", value) == 0)
- || (strcasecmp ("On", value) == 0))
+ if (IS_TRUE (value))
c_ipmi_nofiy_add = 1;
}
else if (strcasecmp ("NotifySensorRemove", key) == 0)
{
- if ((strcasecmp ("True", value) == 0)
- || (strcasecmp ("Yes", value) == 0)
- || (strcasecmp ("On", value) == 0))
+ if (IS_TRUE (value))
c_ipmi_nofiy_remove = 1;
}
else if (strcasecmp ("NotifySensorNotPresent", key) == 0)
{
- if ((strcasecmp ("True", value) == 0)
- || (strcasecmp ("Yes", value) == 0)
- || (strcasecmp ("On", value) == 0))
+ if (IS_TRUE (value))
c_ipmi_nofiy_notpresent = 1;
}
else
diff --git a/src/irq.c b/src/irq.c
index 1aef344f596219aa3287ffabedb118c1685a9e59..401cc6f9cb3f13e84e1a5e2fd961238565c6632c 100644 (file)
--- a/src/irq.c
+++ b/src/irq.c
}
else if (strcasecmp (key, "IgnoreSelected") == 0)
{
- if ((strcasecmp (value, "True") == 0)
- || (strcasecmp (value, "Yes") == 0)
- || (strcasecmp (value, "On") == 0))
+ if (IS_TRUE (value))
irq_list_action = 1;
else
irq_list_action = 0;
diff --git a/src/libvirt.c b/src/libvirt.c
index 6f9e5f126d497b44ef2c42e2cd437cae3f5a1b49..bcbf0e6ad51a5527df6b9a74a6a7322bd916881c 100644 (file)
--- a/src/libvirt.c
+++ b/src/libvirt.c
}
if (strcasecmp (key, "IgnoreSelected") == 0) {
- if (strcasecmp (value, "True") == 0 ||
- strcasecmp (value, "Yes") == 0 ||
- strcasecmp (value, "On") == 0)
+ if (IS_TRUE (value))
{
ignorelist_set_invert (il_domains, 0);
ignorelist_set_invert (il_block_devices, 0);
diff --git a/src/logfile.c b/src/logfile.c
index 03af7a3fe4369f2b614517613ac3c7108f52b7e1..7b96ac57fcb21130a42a74e5342303503c2a88aa 100644 (file)
--- a/src/logfile.c
+++ b/src/logfile.c
log_file = strdup (value);
}
else if (0 == strcasecmp (key, "Timestamp")) {
- if ((strcasecmp (value, "false") == 0)
- || (strcasecmp (value, "no") == 0)
- || (strcasecmp (value, "off") == 0))
+ if (IS_FALSE (value))
print_timestamp = 0;
else
print_timestamp = 1;
diff --git a/src/match_hashed.c b/src/match_hashed.c
--- /dev/null
+++ b/src/match_hashed.c
@@ -0,0 +1,184 @@
+/**
+ * collectd - src/match_hashed.c
+ * Copyright (C) 2009 Florian Forster
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; only version 2 of the License is applicable.
+ *
+ * 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 "utils_cache.h"
+#include "filter_chain.h"
+
+/*
+ * private data types
+ */
+struct mh_hash_match_s
+{
+ uint32_t match;
+ uint32_t total;
+};
+typedef struct mh_hash_match_s mh_hash_match_t;
+
+struct mh_match_s;
+typedef struct mh_match_s mh_match_t;
+struct mh_match_s
+{
+ mh_hash_match_t *matches;
+ size_t matches_num;
+};
+
+/*
+ * internal helper functions
+ */
+static int mh_config_match (const oconfig_item_t *ci, /* {{{ */
+ mh_match_t *m)
+{
+ mh_hash_match_t *tmp;
+
+ if ((ci->values_num != 2)
+ || (ci->values[0].type != OCONFIG_TYPE_NUMBER)
+ || (ci->values[1].type != OCONFIG_TYPE_NUMBER))
+ {
+ ERROR ("hashed match: The `Match' option requires "
+ "exactly two numeric arguments.");
+ return (-1);
+ }
+
+ if ((ci->values[0].value.number < 0)
+ || (ci->values[1].value.number < 0))
+ {
+ ERROR ("hashed match: The arguments of the `Match' "
+ "option must be positive.");
+ return (-1);
+ }
+
+ tmp = realloc (m->matches, sizeof (*tmp) * (m->matches_num + 1));
+ if (tmp == NULL)
+ {
+ ERROR ("hashed match: realloc failed.");
+ return (-1);
+ }
+ m->matches = tmp;
+ tmp = m->matches + m->matches_num;
+
+ tmp->match = (uint32_t) (ci->values[0].value.number + .5);
+ tmp->total = (uint32_t) (ci->values[1].value.number + .5);
+
+ if (tmp->match >= tmp->total)
+ {
+ ERROR ("hashed match: The first argument of the `Match' option "
+ "must be smaller than the second argument.");
+ return (-1);
+ }
+ assert (tmp->total != 0);
+
+ m->matches_num++;
+ return (0);
+} /* }}} int mh_config_match */
+
+static int mh_create (const oconfig_item_t *ci, void **user_data) /* {{{ */
+{
+ mh_match_t *m;
+ int i;
+
+ m = (mh_match_t *) malloc (sizeof (*m));
+ if (m == NULL)
+ {
+ ERROR ("mh_create: malloc failed.");
+ return (-ENOMEM);
+ }
+ memset (m, 0, sizeof (*m));
+
+ for (i = 0; i < ci->children_num; i++)
+ {
+ oconfig_item_t *child = ci->children + i;
+
+ if (strcasecmp ("Match", child->key) == 0)
+ mh_config_match (child, m);
+ else
+ ERROR ("hashed match: No such config option: %s", child->key);
+ }
+
+ if (m->matches_num == 0)
+ {
+ sfree (m->matches);
+ sfree (m);
+ ERROR ("hashed match: No matches were configured. Not creating match.");
+ return (-1);
+ }
+
+ *user_data = m;
+ return (0);
+} /* }}} int mh_create */
+
+static int mh_destroy (void **user_data) /* {{{ */
+{
+ mh_match_t *mh;
+
+ if ((user_data == NULL) || (*user_data == NULL))
+ return (0);
+
+ mh = *user_data;
+ sfree (mh->matches);
+ sfree (mh);
+
+ return (0);
+} /* }}} int mh_destroy */
+
+static int mh_match (const data_set_t __attribute__((unused)) *ds, /* {{{ */
+ const value_list_t *vl,
+ notification_meta_t __attribute__((unused)) **meta, void **user_data)
+{
+ mh_match_t *m;
+ uint32_t hash_val;
+ const char *host_ptr;
+ size_t i;
+
+ if ((user_data == NULL) || (*user_data == NULL))
+ return (-1);
+
+ m = *user_data;
+
+ hash_val = 0;
+
+ for (host_ptr = vl->host; *host_ptr != 0; host_ptr++)
+ {
+ /* 251 is the largest prime smaller than 256. */
+ hash_val = (hash_val * 251) + ((uint32_t) *host_ptr);
+ }
+ DEBUG ("hashed match: host = %s; hash_val = %"PRIu32";", vl->host, hash_val);
+
+ for (i = 0; i < m->matches_num; i++)
+ if ((hash_val % m->matches[i].total) == m->matches[i].match)
+ return (FC_MATCH_MATCHES);
+
+ return (FC_MATCH_NO_MATCH);
+} /* }}} int mh_match */
+
+void module_register (void)
+{
+ match_proc_t mproc;
+
+ memset (&mproc, 0, sizeof (mproc));
+ mproc.create = mh_create;
+ mproc.destroy = mh_destroy;
+ mproc.match = mh_match;
+ fc_register_match ("hashed", mproc);
+} /* module_register */
+
+/* vim: set sw=2 sts=2 tw=78 et fdm=marker : */
diff --git a/src/netapp.c b/src/netapp.c
--- /dev/null
+++ b/src/netapp.c
@@ -0,0 +1,2581 @@
+/**
+ * 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;
+};
+
+/*
+ * 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, "counter", "name_cache_hit");
+ na_child_add_string(e, "counter", "name_cache_miss");
+ na_child_add_string(e, "counter", "find_dir_hit");
+ na_child_add_string(e, "counter", "find_dir_miss");
+ na_child_add_string(e, "counter", "buf_hash_hit");
+ na_child_add_string(e, "counter", "buf_hash_miss");
+ na_child_add_string(e, "counter", "inode_cache_hit");
+ na_child_add_string(e, "counter", "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, "counter", "disk_busy");
+ na_child_add_string(e, "counter", "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);
+ }
+ na_child_add_string(e, "counter", "read_ops");
+ na_child_add_string(e, "counter", "write_ops");
+ na_child_add_string(e, "counter", "read_data");
+ na_child_add_string(e, "counter", "write_data");
+ na_child_add_string(e, "counter", "read_latency");
+ na_child_add_string(e, "counter", "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) /* {{{ */
+{
+ 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));
+ memset (host, 0, sizeof (*host));
+ host->name = NULL;
+ host->protocol = NA_SERVER_TRANSPORT_HTTPS;
+ host->host = NULL;
+ host->username = NULL;
+ host->password = NULL;
+ host->srv = NULL;
+ host->cfg_wafl = NULL;
+ host->cfg_disk = NULL;
+ host->cfg_volume_perf = NULL;
+ host->cfg_volume_usage = NULL;
+ host->cfg_system = NULL;
+
+ 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_host (host_config_t *host) /* {{{ */
+{
+ if (host == NULL)
+ return (EINVAL);
+
+ if (host->srv != NULL)
+ return (0);
+
+ /* 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);
+ return (-1);
+ }
+
+ 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_host */
+
+static int cna_init (void) /* {{{ */
+{
+ char err[256];
+
+ 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;
+ }
+
+ return (0);
+} /* }}} cna_init */
+
+static int cna_read (user_data_t *ud) { /* {{{ */
+ host_config_t *host;
+ int status;
+
+ if ((ud == NULL) || (ud->data == NULL))
+ return (-1);
+
+ host = ud->data;
+
+ status = cna_init_host (host);
+ if (status != 0)
+ return (status);
+
+ 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_config (oconfig_item_t *ci) { /* {{{ */
+ int i;
+ oconfig_item_t *item;
+
+ for (i = 0; i < ci->children_num; ++i) {
+ item = ci->children + i;
+
+ if (strcasecmp(item->key, "Host") == 0)
+ {
+ host_config_t *host;
+ char cb_name[256];
+ struct timespec interval;
+ user_data_t ud;
+
+ host = cna_config_host (item);
+ if (host == NULL)
+ continue;
+
+ ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name);
+
+ memset (&interval, 0, sizeof (interval));
+ interval.tv_sec = host->interval;
+
+ memset (&ud, 0, sizeof (ud));
+ ud.data = host;
+ ud.free_func = (void (*) (void *)) free_host_config;
+
+ plugin_register_complex_read (cb_name,
+ /* callback = */ cna_read,
+ /* interval = */ (host->interval > 0) ? &interval : NULL,
+ /* user data = */ &ud);
+ continue;
+ }
+ else /* if (item->key != "Host") */
+ {
+ WARNING("netapp plugin: Ignoring unknown config option \"%s\".", item->key);
+ }
+ }
+ return 0;
+} /* }}} int cna_config */
+
+static int cna_shutdown (void) /* {{{ */
+{
+ /* Clean up system resources and stuff. */
+ na_shutdown ();
+
+ return (0);
+} /* }}} int cna_shutdown */
+
+void module_register(void) {
+ plugin_register_complex_config("netapp", cna_config);
+ plugin_register_init("netapp", cna_init);
+ plugin_register_shutdown("netapp", cna_shutdown);
+}
+
+/* vim: set sw=2 ts=2 noet fdm=marker : */
diff --git a/src/netlink.c b/src/netlink.c
index b15768e719d5c7ea847848ea63db4142e703c45c..49c4e990fb47d8ea5c15e5c8ae2b8f132c959d1f 100644 (file)
--- a/src/netlink.c
+++ b/src/netlink.c
}
else
{
- if ((strcasecmp (fields[0], "yes") == 0)
- || (strcasecmp (fields[0], "true") == 0)
- || (strcasecmp (fields[0], "on") == 0))
+ if (IS_TRUE (fields[0]))
ir_ignorelist_invert = 0;
else
ir_ignorelist_invert = 1;
diff --git a/src/network.c b/src/network.c
index 109289e3a76d62924be53dce9902cd2e21c2273f..1b453753a4d0204f930afce574624a039d3e313e 100644 (file)
--- a/src/network.c
+++ b/src/network.c
static int network_config_ttl = 0;
static size_t network_config_packet_size = 1024;
static int network_config_forward = 0;
+static int network_config_stats = 0;
static sockent_t *sending_sockets = NULL;
static receive_list_entry_t *receive_list_tail = NULL;
static pthread_mutex_t receive_list_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t receive_list_cond = PTHREAD_COND_INITIALIZER;
+static uint64_t receive_list_length = 0;
static sockent_t *listen_sockets = NULL;
static struct pollfd *listen_sockets_pollfd = NULL;
static value_list_t send_buffer_vl = VALUE_LIST_STATIC;
static pthread_mutex_t send_buffer_lock = PTHREAD_MUTEX_INITIALIZER;
+/* XXX: These counters are incremented from one place only. The spot in which
+ * the values are incremented is either only reachable by one thread (the
+ * dispatch thread, for example) or locked by some lock (send_buffer_lock for
+ * example). Only if neither is true, the stats_lock is acquired. The counters
+ * are always read without holding a lock in the hope that writing 8 bytes to
+ * memory is an atomic operation. */
+static uint64_t stats_octets_rx = 0;
+static uint64_t stats_octets_tx = 0;
+static uint64_t stats_packets_rx = 0;
+static uint64_t stats_packets_tx = 0;
+static uint64_t stats_values_dispatched = 0;
+static uint64_t stats_values_not_dispatched = 0;
+static uint64_t stats_values_sent = 0;
+static uint64_t stats_values_not_sent = 0;
+static pthread_mutex_t stats_lock = PTHREAD_MUTEX_INITIALIZER;
+
/*
* Private functions
*/
if (!check_receive_okay (vl))
{
#if COLLECT_DEBUG
- char name[6*DATA_MAX_NAME_LEN];
- FORMAT_VL (name, sizeof (name), vl);
- name[sizeof (name) - 1] = 0;
- DEBUG ("network plugin: network_dispatch_values: "
- "NOT dispatching %s.", name);
+ char name[6*DATA_MAX_NAME_LEN];
+ FORMAT_VL (name, sizeof (name), vl);
+ name[sizeof (name) - 1] = 0;
+ DEBUG ("network plugin: network_dispatch_values: "
+ "NOT dispatching %s.", name);
#endif
+ stats_values_not_dispatched++;
return (0);
}
}
plugin_dispatch_values (vl);
+ stats_values_dispatched++;
meta_data_destroy (vl->meta);
vl->meta = NULL;
ent = receive_list_head;
if (ent != NULL)
receive_list_head = ent->next;
+ receive_list_length--;
pthread_mutex_unlock (&receive_list_lock);
/* Check whether we are supposed to exit. We do NOT check `listen_loop'
receive_list_entry_t *private_list_head;
receive_list_entry_t *private_list_tail;
+ uint64_t private_list_length;
assert (listen_sockets_num > 0);
private_list_head = NULL;
private_list_tail = NULL;
+ private_list_length = 0;
while (listen_loop == 0)
{
return (-1);
}
+ stats_octets_rx += ((uint64_t) buffer_len);
+ stats_packets_rx++;
+
/* TODO: Possible performance enhancement: Do not free
* these entries in the dispatch thread but put them in
* another list, so we don't have to allocate more and
ent->data = malloc (network_config_packet_size);
if (ent->data == NULL)
{
+ sfree (ent);
ERROR ("network plugin: malloc failed.");
return (-1);
}
else
private_list_tail->next = ent;
private_list_tail = ent;
+ private_list_length++;
/* Do not block here. Blocking here has led to
* insufficient performance in the past. */
if (pthread_mutex_trylock (&receive_list_lock) == 0)
{
+ assert (((receive_list_head == NULL) && (receive_list_length == 0))
+ || ((receive_list_head != NULL) && (receive_list_length != 0)));
+
if (receive_list_head == NULL)
receive_list_head = private_list_head;
else
receive_list_tail->next = private_list_head;
receive_list_tail = private_list_tail;
-
- private_list_head = NULL;
- private_list_tail = NULL;
+ receive_list_length += private_list_length;
pthread_cond_signal (&receive_list_cond);
pthread_mutex_unlock (&receive_list_lock);
+
+ private_list_head = NULL;
+ private_list_tail = NULL;
+ private_list_length = 0;
}
} /* for (listen_sockets_pollfd) */
} /* while (listen_loop == 0) */
else
receive_list_tail->next = private_list_head;
receive_list_tail = private_list_tail;
+ receive_list_length += private_list_length;
private_list_head = NULL;
private_list_tail = NULL;
+ private_list_length = 0;
pthread_cond_signal (&receive_list_cond);
pthread_mutex_unlock (&receive_list_lock);
send_buffer_fill);
network_send_buffer (send_buffer, (size_t) send_buffer_fill);
+
+ stats_octets_tx += ((uint64_t) send_buffer_fill);
+ stats_packets_tx++;
+
network_init_buffer ();
}
DEBUG ("network plugin: network_write: "
"NOT sending %s.", name);
#endif
+ /* Counter is not protected by another lock and may be reached by
+ * multiple threads */
+ pthread_mutex_lock (&stats_lock);
+ stats_values_not_sent++;
+ pthread_mutex_unlock (&stats_lock);
return (0);
}
/* status == bytes added to the buffer */
send_buffer_fill += status;
send_buffer_ptr += status;
+
+ stats_values_sent++;
}
else
{
{
send_buffer_fill += status;
send_buffer_ptr += status;
+
+ stats_values_sent++;
}
}
{
char *str = ci->values[0].value.string;
- if ((strcasecmp ("true", str) == 0)
- || (strcasecmp ("yes", str) == 0)
- || (strcasecmp ("on", str) == 0))
+ if (IS_TRUE (str))
*retval = 1;
- else if ((strcasecmp ("false", str) == 0)
- || (strcasecmp ("no", str) == 0)
- || (strcasecmp ("off", str) == 0))
+ else if (IS_FALSE (str))
*retval = 0;
else
{
network_config_set_buffer_size (child);
else if (strcasecmp ("Forward", child->key) == 0)
network_config_set_boolean (child, &network_config_forward);
+ else if (strcasecmp ("ReportStats", child->key) == 0)
+ network_config_set_boolean (child, &network_config_stats);
else if (strcasecmp ("CacheFlush", child->key) == 0)
/* no op for backwards compatibility only */;
else
return (0);
} /* int network_shutdown */
+static int network_stats_read (void) /* {{{ */
+{
+ uint64_t copy_octets_rx;
+ uint64_t copy_octets_tx;
+ uint64_t copy_packets_rx;
+ uint64_t copy_packets_tx;
+ uint64_t copy_values_dispatched;
+ uint64_t copy_values_not_dispatched;
+ uint64_t copy_values_sent;
+ uint64_t copy_values_not_sent;
+ uint64_t copy_receive_list_length;
+ value_list_t vl = VALUE_LIST_INIT;
+ value_t values[2];
+
+ copy_octets_rx = stats_octets_rx;
+ copy_octets_tx = stats_octets_tx;
+ copy_packets_rx = stats_packets_rx;
+ copy_packets_tx = stats_packets_tx;
+ copy_values_dispatched = stats_values_dispatched;
+ copy_values_not_dispatched = stats_values_not_dispatched;
+ copy_values_sent = stats_values_sent;
+ copy_values_not_sent = stats_values_not_sent;
+ copy_receive_list_length = receive_list_length;
+
+ /* Initialize `vl' */
+ vl.values = values;
+ vl.values_len = 2;
+ vl.time = 0;
+ vl.interval = interval_g;
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+ sstrncpy (vl.plugin, "network", sizeof (vl.plugin));
+
+ /* Octets received / sent */
+ vl.values[0].counter = (counter_t) copy_octets_rx;
+ vl.values[1].counter = (counter_t) copy_octets_tx;
+ sstrncpy (vl.type, "if_octets", sizeof (vl.type));
+ plugin_dispatch_values (&vl);
+
+ /* Packets received / send */
+ vl.values[0].counter = (counter_t) copy_packets_rx;
+ vl.values[1].counter = (counter_t) copy_packets_tx;
+ sstrncpy (vl.type, "if_packets", sizeof (vl.type));
+ plugin_dispatch_values (&vl);
+
+ /* Values (not) dispatched and (not) send */
+ sstrncpy (vl.type, "total_values", sizeof (vl.type));
+ vl.values_len = 1;
+
+ vl.values[0].derive = (derive_t) copy_values_dispatched;
+ sstrncpy (vl.type_instance, "dispatch-accepted",
+ sizeof (vl.type_instance));
+ plugin_dispatch_values (&vl);
+
+ vl.values[0].derive = (derive_t) copy_values_not_dispatched;
+ sstrncpy (vl.type_instance, "dispatch-rejected",
+ sizeof (vl.type_instance));
+ plugin_dispatch_values (&vl);
+
+ vl.values[0].derive = (derive_t) copy_values_sent;
+ sstrncpy (vl.type_instance, "send-accepted",
+ sizeof (vl.type_instance));
+ plugin_dispatch_values (&vl);
+
+ vl.values[0].derive = (derive_t) copy_values_not_sent;
+ sstrncpy (vl.type_instance, "send-rejected",
+ sizeof (vl.type_instance));
+ plugin_dispatch_values (&vl);
+
+ /* Receive queue length */
+ vl.values[0].gauge = (gauge_t) copy_receive_list_length;
+ sstrncpy (vl.type, "queue_length", sizeof (vl.type));
+ vl.type_instance[0] = 0;
+ plugin_dispatch_values (&vl);
+
+ return (0);
+} /* }}} int network_stats_read */
+
static int network_init (void)
{
static _Bool have_init = false;
gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
#endif
+ if (network_config_stats != 0)
+ plugin_register_read ("network", network_stats_read);
+
plugin_register_shutdown ("network", network_shutdown);
send_buffer = malloc (network_config_packet_size);
diff --git a/src/nginx.c b/src/nginx.c
index 53137a71d206dd5ec9218d9697a963a6085c8db3..697684277a153911fdc43474cdc74bdab5b62d1e 100644 (file)
--- a/src/nginx.c
+++ b/src/nginx.c
curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1);
- if ((verify_peer == NULL) || (strcmp (verify_peer, "true") == 0))
+ if ((verify_peer == NULL) || IS_TRUE (verify_peer))
{
curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 1);
}
curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0);
}
- if ((verify_host == NULL) || (strcmp (verify_host, "true") == 0))
+ if ((verify_host == NULL) || IS_TRUE (verify_host))
{
curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 2);
}
diff --git a/src/ntpd.c b/src/ntpd.c
index 9d716adc0e0e181f3c965107c32e06670dfa97f4..ecc87c78977dbbdde88e920aa5f6156a1060fc0d 100644 (file)
--- a/src/ntpd.c
+++ b/src/ntpd.c
}
else if (strcasecmp (key, "ReverseLookups") == 0)
{
- if ((strcasecmp (value, "True") == 0)
- || (strcasecmp (value, "Yes") == 0)
- || (strcasecmp (value, "On") == 0))
+ if (IS_TRUE (value))
do_reverse_lookups = 1;
else
do_reverse_lookups = 0;
diff --git a/src/onewire.c b/src/onewire.c
index 261457a1bb90cad631a236c8fc7014818b4f9c01..cae0d63d4c22f529aab642a3e3f6dd37e8195fb4 100644 (file)
--- a/src/onewire.c
+++ b/src/onewire.c
else if (strcasecmp (key, "IgnoreSelected") == 0)
{
ignorelist_set_invert (sensor_list, 1);
- if ((strcasecmp (value, "True") == 0)
- || (strcasecmp (value, "Yes") == 0)
- || (strcasecmp (value, "On") == 0))
+ if (IS_TRUE (value))
ignorelist_set_invert (sensor_list, 0);
}
else if (strcasecmp (key, "Device") == 0)
diff --git a/src/plugin.c b/src/plugin.c
index 5d882e64de7e69f47b47c53eeb7e63e4adea1045..11a0ef6eadbada45aad092f7116c879aeef9dfdd 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
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/processes.c b/src/processes.c
index 4f515184ed85a66f38f17400f9f08dbca112fdb5..5ef4acc039907743d1f22180f23871ec5f9ce326 100644 (file)
--- a/src/processes.c
+++ b/src/processes.c
unsigned long cpu_user_counter;
unsigned long cpu_system_counter;
+ /* io data */
+ long io_rchar;
+ long io_wchar;
+ long io_syscr;
+ long io_syscw;
+
struct procstat_entry_s *next;
} procstat_entry_t;
unsigned long cpu_user_counter;
unsigned long cpu_system_counter;
+ /* io data */
+ long io_rchar;
+ long io_wchar;
+ long io_syscr;
+ long io_syscw;
+
struct procstat *next;
struct procstat_entry_s *instances;
} procstat_t;
@@ -328,6 +340,10 @@ static void ps_list_add (const char *name, const char *cmdline, procstat_entry_t
pse->vmem_size = entry->vmem_size;
pse->vmem_rss = entry->vmem_rss;
pse->stack_size = entry->stack_size;
+ pse->io_rchar = entry->io_rchar;
+ pse->io_wchar = entry->io_wchar;
+ pse->io_syscr = entry->io_syscr;
+ pse->io_syscw = entry->io_syscw;
ps->num_proc += pse->num_proc;
ps->num_lwp += pse->num_lwp;
@@ -335,6 +351,11 @@ static void ps_list_add (const char *name, const char *cmdline, procstat_entry_t
ps->vmem_rss += pse->vmem_rss;
ps->stack_size += pse->stack_size;
+ ps->io_rchar += ((pse->io_rchar == -1)?0:pse->io_rchar);
+ ps->io_wchar += ((pse->io_wchar == -1)?0:pse->io_wchar);
+ ps->io_syscr += ((pse->io_syscr == -1)?0:pse->io_syscr);
+ ps->io_syscw += ((pse->io_syscw == -1)?0:pse->io_syscw);
+
if ((entry->vmem_minflt_counter == 0)
&& (entry->vmem_majflt_counter == 0))
{
ps->vmem_size = 0;
ps->vmem_rss = 0;
ps->stack_size = 0;
+ ps->io_rchar = -1;
+ ps->io_wchar = -1;
+ ps->io_syscr = -1;
+ ps->io_syscw = -1;
pse_prev = NULL;
pse = ps->instances;
vl.values_len = 2;
plugin_dispatch_values (&vl);
+ if ( (ps->io_rchar != -1) && (ps->io_wchar != -1) )
+ {
+ sstrncpy (vl.type, "ps_disk_octets", sizeof (vl.type));
+ vl.values[0].counter = ps->io_rchar;
+ vl.values[1].counter = ps->io_wchar;
+ vl.values_len = 2;
+ plugin_dispatch_values (&vl);
+ }
+
+ if ( (ps->io_syscr != -1) && (ps->io_syscw != -1) )
+ {
+ sstrncpy (vl.type, "ps_disk_ops", sizeof (vl.type));
+ vl.values[0].counter = ps->io_syscr;
+ vl.values[1].counter = ps->io_syscw;
+ vl.values_len = 2;
+ plugin_dispatch_values (&vl);
+ }
+
DEBUG ("name = %s; num_proc = %lu; num_lwp = %lu; vmem_rss = %lu; "
"vmem_minflt_counter = %lu; vmem_majflt_counter = %lu; "
- "cpu_user_counter = %lu; cpu_system_counter = %lu;",
+ "cpu_user_counter = %lu; cpu_system_counter = %lu; "
+ "io_rchar = %ld; io_wchar = %ld; "
+ "io_syscr = %ld; io_syscw = %ld;",
ps->name, ps->num_proc, ps->num_lwp, ps->vmem_rss,
ps->vmem_minflt_counter, ps->vmem_majflt_counter,
- ps->cpu_user_counter, ps->cpu_system_counter);
+ ps->cpu_user_counter, ps->cpu_system_counter,
+ ps->io_rchar, ps->io_wchar, ps->io_syscr, ps->io_syscw);
} /* void ps_submit_proc_list */
/* ------- additional functions for KERNEL_LINUX/HAVE_THREAD_INFO ------- */
return ((count >= 1) ? count : 1);
} /* int *ps_read_tasks */
+static procstat_t *ps_read_io (int pid, procstat_t *ps)
+{
+ FILE *fh;
+ char buffer[1024];
+ char filename[64];
+
+ char *fields[8];
+ int numfields;
+
+ ssnprintf (filename, sizeof (filename), "/proc/%i/io", pid);
+ if ((fh = fopen (filename, "r")) == NULL)
+ return (NULL);
+
+ while (fgets (buffer, 1024, fh) != NULL)
+ {
+ long *val = NULL;
+
+ if (strncasecmp (buffer, "rchar:", 6) == 0)
+ val = &(ps->io_rchar);
+ else if (strncasecmp (buffer, "wchar:", 6) == 0)
+ val = &(ps->io_wchar);
+ else if (strncasecmp (buffer, "syscr:", 6) == 0)
+ val = &(ps->io_syscr);
+ else if (strncasecmp (buffer, "syscw:", 6) == 0)
+ val = &(ps->io_syscw);
+ else
+ continue;
+
+ numfields = strsplit (buffer, fields, 8);
+
+ if (numfields < 2)
+ continue;
+
+ *val = atol (fields[1]);
+ }
+
+ if (fclose (fh))
+ {
+ char errbuf[1024];
+ WARNING ("processes: fclose: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ }
+
+ return (ps);
+} /* procstat_t *ps_read_io */
+
int ps_read_process (int pid, procstat_t *ps, char *state)
{
char filename[64];
ps->vmem_rss = (unsigned long) vmem_rss;
ps->stack_size = (unsigned long) stack_size;
+ if ( (ps_read_io (pid, ps)) == NULL)
+ {
+ /* no io data */
+ ps->io_rchar = -1;
+ ps->io_wchar = -1;
+ ps->io_syscr = -1;
+ ps->io_syscw = -1;
+
+ DEBUG("ps_read_process: not get io data for pid %i",pid);
+ }
+
/* success */
return (0);
} /* int ps_read_process (...) */
}
return buf;
} /* char *ps_get_cmdline (...) */
+
+static unsigned long read_fork_rate ()
+{
+ FILE *proc_stat;
+ char buf[1024];
+ unsigned long result = 0;
+ int numfields;
+ char *fields[3];
+
+ proc_stat = fopen("/proc/stat", "r");
+ if (proc_stat == NULL) {
+ char errbuf[1024];
+ ERROR ("processes plugin: fopen (/proc/stat) failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ return ULONG_MAX;
+ }
+
+ while (fgets (buf, sizeof(buf), proc_stat) != NULL)
+ {
+ char *endptr;
+
+ numfields = strsplit(buf, fields, STATIC_ARRAY_SIZE (fields));
+ if (numfields != 2)
+ continue;
+
+ if (strcmp ("processes", fields[0]) != 0)
+ continue;
+
+ errno = 0;
+ endptr = NULL;
+ result = strtoul(fields[1], &endptr, 10);
+ if ((endptr == fields[1]) || (errno != 0)) {
+ ERROR ("processes plugin: Cannot parse fork rate: %s",
+ fields[1]);
+ result = ULONG_MAX;
+ break;
+ }
+
+ break;
+ }
+
+ fclose(proc_stat);
+
+ return result;
+}
+
+static void ps_submit_fork_rate (unsigned long value)
+{
+ value_t values[1];
+ value_list_t vl = VALUE_LIST_INIT;
+
+ values[0].derive = (derive_t) value;
+
+ vl.values = values;
+ vl.values_len = 1;
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+ sstrncpy (vl.plugin, "processes", sizeof (vl.plugin));
+ sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, "fork_rate", sizeof (vl.type));
+ sstrncpy (vl.type_instance, "", sizeof (vl.type_instance));
+
+ plugin_dispatch_values (&vl);
+}
+
#endif /* KERNEL_LINUX */
#if HAVE_THREAD_INFO
procstat_entry_t pse;
char state;
+ unsigned long fork_rate;
+
procstat_t *ps_ptr;
running = sleeping = zombies = stopped = paging = blocked = 0;
pse.cpu_system = 0;
pse.cpu_system_counter = ps.cpu_system_counter;
+ pse.io_rchar = ps.io_rchar;
+ pse.io_wchar = ps.io_wchar;
+ pse.io_syscr = ps.io_syscr;
+ pse.io_syscw = ps.io_syscw;
+
switch (state)
{
case 'R': running++; break;
for (ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next)
ps_submit_proc_list (ps_ptr);
+
+ fork_rate = read_fork_rate();
+ if (fork_rate != ULONG_MAX)
+ ps_submit_fork_rate(fork_rate);
/* #endif KERNEL_LINUX */
#elif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD
* 1000
+ procs[i].ki_rusage.ru_stime.tv_usec;
+ /* no io data */
+ pse.io_rchar = -1;
+ pse.io_wchar = -1;
+ pse.io_syscr = -1;
+ pse.io_syscw = -1;
+
switch (procs[i].ki_stat)
{
case SSTOP: stopped++; break;
diff --git a/src/protocols.c b/src/protocols.c
index 75e9a1c4782035bbeffcbfc232a9fcb5d3936512..73fe15431a96e8d39f52b429aac7998f2b291f85 100644 (file)
--- a/src/protocols.c
+++ b/src/protocols.c
else if (strcasecmp (key, "IgnoreSelected") == 0)
{
int invert = 1;
- if ((strcasecmp (value, "True") == 0)
- || (strcasecmp (value, "Yes") == 0)
- || (strcasecmp (value, "On") == 0))
+ if (IS_TRUE (value))
invert = 0;
ignorelist_set_invert (values_list, invert);
}
diff --git a/src/rrdcached.c b/src/rrdcached.c
index 191df58e93599094b16cb9752fc517d1f44ffb7c..aab8c11ebdb77dcf0c5939a32599ce7cad5bb5b6 100644 (file)
--- a/src/rrdcached.c
+++ b/src/rrdcached.c
}
else if (strcasecmp ("CreateFiles", key) == 0)
{
- if ((strcasecmp ("false", value) == 0)
- || (strcasecmp ("no", value) == 0)
- || (strcasecmp ("off", value) == 0))
+ if (IS_FALSE (value))
config_create_files = 0;
else
config_create_files = 1;
}
else if (strcasecmp ("CollectStatistics", key) == 0)
{
- if ((strcasecmp ("false", value) == 0)
- || (strcasecmp ("no", value) == 0)
- || (strcasecmp ("off", value) == 0))
+ if (IS_FALSE (value))
config_collect_stats = 0;
else
config_collect_stats = 1;
diff --git a/src/sensors.c b/src/sensors.c
index fa461a2f6bffd7db8b3dca5dcca02a23e542dc53..8391346b4dc611b060633e8e6b1c828d20d7b67a 100644 (file)
--- a/src/sensors.c
+++ b/src/sensors.c
else if (strcasecmp (key, "IgnoreSelected") == 0)
{
ignorelist_set_invert (sensor_list, 1);
- if ((strcasecmp (value, "True") == 0)
- || (strcasecmp (value, "Yes") == 0)
- || (strcasecmp (value, "On") == 0))
+ if (IS_TRUE (value))
ignorelist_set_invert (sensor_list, 0);
}
else
diff --git a/src/target_scale.c b/src/target_scale.c
--- /dev/null
+++ b/src/target_scale.c
@@ -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 : */
+
diff --git a/src/tcpconns.c b/src/tcpconns.c
index f164b53b4858406a27e8cd49040a88cc02f61e20..d68cd0968ca70a126dfd37d839f41ebe0be2fe77 100644 (file)
--- a/src/tcpconns.c
+++ b/src/tcpconns.c
{
if (strcasecmp (key, "ListeningPorts") == 0)
{
- if ((strcasecmp (value, "Yes") == 0)
- || (strcasecmp (value, "True") == 0)
- || (strcasecmp (value, "On") == 0))
+ if (IS_TRUE (value))
port_collect_listening = 1;
else
port_collect_listening = 0;
diff --git a/src/thermal.c b/src/thermal.c
index fe54aee443790617b30c22915414bcd4c5123b5c..2b708052d707461afa3f9976f3bd9132affa79a6 100644 (file)
--- a/src/thermal.c
+++ b/src/thermal.c
else if (strcasecmp (key, "IgnoreSelected") == 0)
{
ignorelist_set_invert (device_list, 1);
- if ((strcasecmp (value, "True") == 0)
- || (strcasecmp (value, "Yes") == 0)
- || (strcasecmp (value, "On") == 0))
+ if (IS_TRUE (value))
ignorelist_set_invert (device_list, 0);
}
else if (strcasecmp (key, "ForceUseProcfs") == 0)
{
force_procfs = 0;
- if ((strcasecmp (value, "True") == 0)
- || (strcasecmp (value, "Yes") == 0)
- || (strcasecmp (value, "On") == 0))
+ if (IS_TRUE (value))
force_procfs = 1;
}
else
diff --git a/src/tokyotyrant.c b/src/tokyotyrant.c
index 26366c928373aee0c4c12e91d3013d30b34d3c4f..678a341c1ceeaf15f24a708d12567c1b8ed92f15 100644 (file)
--- a/src/tokyotyrant.c
+++ b/src/tokyotyrant.c
#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"
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)
if (config_port != NULL)
{
- port = parse_service_name (config_port);
+ port = service_name_to_port_number (config_port);
if (port <= 0)
return;
}
diff --git a/src/types.db b/src/types.db
index 8ac9dd4f7b8f06ddf0c7a472a23e0988b7cdb999..c8c6b98aa7a73337a68252e73c0c33feb4727498 100644 (file)
--- a/src/types.db
+++ b/src/types.db
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
compression_ratio value:GAUGE:0:2
connections value:COUNTER:0:U
conntrack entropy:GAUGE:0:4294967295
+contextswitch contextswitches:DERIVE:0:U
counter value:COUNTER:U:U
cpufreq value:GAUGE:0:U
cpu value:COUNTER:0:4294967295
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
+df_inodes 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
frequency frequency:GAUGE:0:U
frequency_offset ppm:GAUGE:-1000000:1000000
fscache_stat value:COUNTER:0:4294967295
+fork_rate value:DERIVE:0:U
gauge value:GAUGE:U:U
http_request_methods count:COUNTER:0:134217728
http_requests count:COUNTER:0:134217728
ps_count processes:GAUGE:0:1000000, threads:GAUGE:0:1000000
ps_cputime user:COUNTER:0:16000000, syst:COUNTER:0:16000000
ps_pagefaults minflt:COUNTER:0:9223372036854775807, majflt:COUNTER:0:9223372036854775807
+ps_disk_octets read:DERIVE:0:U, write:DERIVE:0:U
+ps_disk_ops read:DERIVE:0:U, write:DERIVE:0:U
ps_rss value:GAUGE:0:9223372036854775807
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
time_offset seconds:GAUGE:-1000000:1000000
total_requests value:DERIVE:0:U
total_time_in_ms value:DERIVE:0:U
+total_values value:DERIVE:0:U
uptime value:GAUGE:0:4294967295
users users:GAUGE:0:65535
virt_cpu_total ns:COUNTER:0:256000000000
diff --git a/src/vmem.c b/src/vmem.c
index 6775d20ddf0b3b4788fb4132d8359334af1d045b..d32f1db8cf42e9b2e155db93f0bf32df89f51e39 100644 (file)
--- a/src/vmem.c
+++ b/src/vmem.c
{
if (strcasecmp ("Verbose", key) == 0)
{
- if ((strcasecmp ("true", value) == 0)
- || (strcasecmp ("yes", value) == 0)
- || (strcasecmp ("on", value) == 0))
+ if (IS_TRUE (value))
verbose_output = 1;
else
verbose_output = 0;