Merge branch 'collectd-4.0'
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Thu, 5 Jul 2007 20:16:17 +0000 (22:16 +0200)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Thu, 5 Jul 2007 20:16:17 +0000 (22:16 +0200)
Conflicts:

configure.in

54 files changed:
configure.in
contrib/PerlLib/Collectd/Unixsock.pm
contrib/SpamAssassin/Collectd.pm
contrib/SpamAssassin/example.cf
contrib/cussh.pl [new file with mode: 0755]
src/Makefile.am
src/apache.c
src/apcups.c
src/apple_sensors.c
src/battery.c
src/collectd-nagios.c
src/collectd-snmp.pod [new file with mode: 0644]
src/collectd-unixsock.pod
src/collectd.conf.in
src/collectd.conf.pod
src/collectd.h
src/configfile.c
src/configfile.h
src/cpu.c
src/cpufreq.c
src/df.c
src/disk.c
src/dns.c
src/email.c
src/entropy.c
src/hddtemp.c
src/interface.c
src/iptables.c
src/irq.c
src/load.c
src/mbmon.c
src/memory.c
src/multimeter.c
src/mysql.c
src/network.c
src/network.h
src/nfs.c
src/ntpd.c
src/nut.c
src/plugin.c
src/plugin.h
src/processes.c
src/rrdtool.c
src/sensors.c
src/serial.c
src/snmp.c [new file with mode: 0644]
src/swap.c
src/tape.c
src/types.db
src/unixsock.c
src/users.c
src/vserver.c
src/wireless.c
src/xmms.c [new file with mode: 0644]

index 62ec8b2..9c4be50 100644 (file)
@@ -36,23 +36,8 @@ AC_CONFIG_SUBDIRS(libltdl)
 AC_HEADER_STDC
 AC_HEADER_SYS_WAIT
 AC_HEADER_DIRENT
-AC_CHECK_HEADERS(stdint.h)
-AC_CHECK_HEADERS(stdio.h)
-AC_CHECK_HEADERS(errno.h)
-AC_CHECK_HEADERS(math.h)
-AC_CHECK_HEADERS(syslog.h)
-AC_CHECK_HEADERS(fcntl.h)
-AC_CHECK_HEADERS(signal.h)
-AC_CHECK_HEADERS(assert.h)
-AC_CHECK_HEADERS(sys/types.h)
-AC_CHECK_HEADERS(sys/socket.h)
-AC_CHECK_HEADERS(sys/select.h)
-AC_CHECK_HEADERS(poll.h)
-AC_CHECK_HEADERS(netdb.h)
-AC_CHECK_HEADERS(arpa/inet.h)
-AC_CHECK_HEADERS(sys/resource.h)
-AC_CHECK_HEADERS(sys/param.h)
-AC_CHECK_HEADERS(kstat.h)
+
+AC_CHECK_HEADERS(stdint.h stdio.h errno.h math.h stdarg.h syslog.h fcntl.h signal.h assert.h sys/types.h sys/socket.h sys/select.h poll.h netdb.h arpa/inet.h sys/resource.h sys/param.h kstat.h regex.h)
 
 # For ping library
 AC_CHECK_HEADERS(netinet/in_systm.h, [], [],
@@ -189,6 +174,7 @@ AC_CHECK_HEADERS(netinet/udp.h, [], [],
 ])
 
 # For cpu modules
+AC_CHECK_HEADERS(sys/dkstat.h mach/mach_init.h mach/host_priv.h mach/mach_error.h mach/mach_host.h mach/mach_port.h mach/mach_types.h mach/message.h mach/processor_set.h mach/processor.h mach/processor_info.h mach/task.h mach/thread_act.h mach/vm_region.h mach/vm_map.h mach/vm_prot.h mach/vm_statistics.h mach/kern_return.h)
 AC_CHECK_HEADERS(sys/sysctl.h, [], [],
 [
 #if HAVE_SYS_TYPES_H
@@ -198,33 +184,12 @@ AC_CHECK_HEADERS(sys/sysctl.h, [], [],
 # include <sys/param.h>
 #endif
 ])
-AC_CHECK_HEADERS(sys/dkstat.h)
-AC_CHECK_HEADERS(mach/mach_init.h)
-AC_CHECK_HEADERS(mach/host_priv.h)
-AC_CHECK_HEADERS(mach/mach_error.h)
-AC_CHECK_HEADERS(mach/mach_host.h)
-AC_CHECK_HEADERS(mach/mach_port.h)
-AC_CHECK_HEADERS(mach/mach_types.h)
-AC_CHECK_HEADERS(mach/message.h)
-AC_CHECK_HEADERS(mach/processor_set.h)
-AC_CHECK_HEADERS(mach/processor.h)
-AC_CHECK_HEADERS(mach/processor_info.h)
-AC_CHECK_HEADERS(mach/task.h)
-AC_CHECK_HEADERS(mach/thread_act.h)
-AC_CHECK_HEADERS(mach/vm_region.h)
-AC_CHECK_HEADERS(mach/vm_map.h)
-AC_CHECK_HEADERS(mach/vm_prot.h)
-AC_CHECK_HEADERS(mach/vm_statistics.h)
-AC_CHECK_HEADERS(mach/kern_return.h)
 
 # For hddtemp module
-AC_CHECK_HEADERS(linux/major.h)
-AC_CHECK_HEADERS(libgen.h)
+AC_CHECK_HEADERS(linux/major.h libgen.h)
 
 # For the apple_sensors module
-AC_CHECK_HEADERS(CoreFoundation/CoreFoundation.h)
-AC_CHECK_HEADERS(IOKit/IOKitLib.h)
-AC_CHECK_HEADERS(IOKit/IOTypes.h)
+AC_CHECK_HEADERS(CoreFoundation/CoreFoundation.h IOKit/IOKitLib.h IOKit/IOTypes.h IOKit/ps/IOPSKeys.h IOKit/IOBSD.h IOKit/storage/IOBlockStorageDriver.h)
 
 # For the battery plugin
 AC_CHECK_HEADERS(IOKit/ps/IOPowerSources.h, [], [],
@@ -236,17 +201,6 @@ AC_CHECK_HEADERS(IOKit/ps/IOPowerSources.h, [], [],
 #  include <IOKit/IOTypes.h>
 #endif
 ])
-AC_CHECK_HEADERS(IOKit/ps/IOPSKeys.h)
-
-# For the `disk' plugin
-AC_CHECK_HEADERS(IOKit/IOBSD.h)
-AC_CHECK_HEADERS(IOKit/storage/IOBlockStorageDriver.h)
-
-# For load module
-AC_CHECK_HEADERS(sys/loadavg.h)
-
-# For the processes plugin
-AC_CHECK_HEADERS(linux/config.h)
 
 # For the swap module
 AC_CHECK_HEADERS(sys/swap.h, [], [],
@@ -259,9 +213,10 @@ AC_CHECK_HEADERS(sys/swap.h, [], [],
 #endif
 ])
 
+# For load module
+# For the processes plugin
 # For users module
-AC_CHECK_HEADERS(utmp.h)
-AC_CHECK_HEADERS(utmpx.h)
+AC_CHECK_HEADERS(sys/loadavg.h linux/config.h utmp.h utmpx.h)
 
 # For interface plugin
 AC_CHECK_HEADERS(ifaddrs.h)
@@ -296,11 +251,7 @@ AC_CHECK_HEADERS(linux/netdevice.h, [], [],
 #endif
 ])
 
-# For apache plugin
-AC_CHECK_HEADERS(curl/curl.h)
-
 # For quota module
-AC_CHECK_HEADERS(pwd.h)
 AC_CHECK_HEADERS(sys/ucred.h, [], [],
 [
 #if HAVE_SYS_TYPES_H
@@ -310,21 +261,8 @@ AC_CHECK_HEADERS(sys/ucred.h, [], [],
 # include <sys/param.h>
 #endif
 ])
-AC_CHECK_HEADERS(ctype.h)
-AC_CHECK_HEADERS(limits.h)
-AC_CHECK_HEADERS(sys/quota.h)
-AC_CHECK_HEADERS(xfs/xqm.h)
 
 # For mount interface
-AC_CHECK_HEADERS(fs_info.h)
-AC_CHECK_HEADERS(fshelp.h)
-AC_CHECK_HEADERS(paths.h)
-AC_CHECK_HEADERS(mntent.h)
-AC_CHECK_HEADERS(mnttab.h)
-AC_CHECK_HEADERS(sys/fstyp.h)
-AC_CHECK_HEADERS(sys/fs_types.h)
-AC_CHECK_HEADERS(sys/mntent.h)
-AC_CHECK_HEADERS(sys/mnttab.h)
 AC_CHECK_HEADERS(sys/mount.h, [], [],
 [
 #if HAVE_SYS_TYPES_H
@@ -334,13 +272,6 @@ AC_CHECK_HEADERS(sys/mount.h, [], [],
 # include <sys/param.h>
 #endif
 ])
-AC_CHECK_HEADERS(sys/statfs.h)
-AC_CHECK_HEADERS(sys/statvfs.h)
-AC_CHECK_HEADERS(sys/vfs.h)
-AC_CHECK_HEADERS(sys/vfstab.h)
-
-# For the swap plugin, FreeBSD
-AC_CHECK_HEADERS(kvm.h)
 
 # For the email plugin
 AC_CHECK_HEADERS(linux/un.h, [], [],
@@ -349,14 +280,8 @@ AC_CHECK_HEADERS(linux/un.h, [], [],
 #      include <sys/socket.h>
 #endif
 ])
-AC_CHECK_HEADERS(sys/un.h)
-AC_CHECK_HEADERS(grp.h)
 
-# For debugging interface (variable number of arguments)
-AC_CHECK_HEADERS(stdarg.h)
-
-# Regular expressions for the ignorelist.
-AC_CHECK_HEADERS(regex.h)
+AC_CHECK_HEADERS(curl/curl.h pwd.h grp.h sys/un.h ctype.h limits.h sys/quota.h xfs/xqm.h fs_info.h fshelp.h paths.h mntent.h mnttab.h sys/fstyp.h sys/fs_types.h sys/mntent.h sys/mnttab.h sys/statfs.h sys/statvfs.h sys/vfs.h sys/vfstab.h kvm.h)
 
 # For the dns plugin
 AC_CHECK_HEADERS(arpa/nameser.h)
@@ -397,8 +322,7 @@ AC_CHECK_HEADERS(netinet/if_ether.h, [], [],
 ])
 
 # For the multimeter plugin
-AC_CHECK_HEADERS(termios.h)
-AC_CHECK_HEADERS(sys/ioctl.h)
+AC_CHECK_HEADERS(termios.h sys/ioctl.h)
 
 #
 # Checking for libraries
@@ -418,11 +342,7 @@ AC_HEADER_TIME
 # Checks for library functions.
 #
 AC_PROG_GCC_TRADITIONAL
-AC_CHECK_FUNCS(gettimeofday select strdup strtol)
-AC_CHECK_FUNCS(getaddrinfo getnameinfo)
-AC_CHECK_FUNCS(strchr memcpy strstr strcmp strncmp strncpy strlen)
-AC_CHECK_FUNCS(strncasecmp strcasecmp)
-AC_CHECK_FUNCS(openlog syslog closelog)
+AC_CHECK_FUNCS(gettimeofday select strdup strtol getaddrinfo getnameinfo strchr memcpy strstr strcmp strncmp strncpy strlen strncasecmp strcasecmp openlog closelog)
 
 AC_CHECK_FUNCS(getpwnam_r)
 AC_CHECK_FUNCS(getgrnam_r)
@@ -435,27 +355,22 @@ nanosleep_needs_rt="no"
 AC_CHECK_FUNCS(nanosleep, [], AC_CHECK_LIB(rt, nanosleep, [nanosleep_needs_rt="yes"], AC_MSG_ERROR(cannot find nanosleep)))
 AM_CONDITIONAL(BUILD_WITH_LIBRT, test "x$nanosleep_needs_rt" = "xyes")
 
-# Regular expressions for the ignorelist.
 AC_CHECK_FUNCS(regcomp regerror regexec regfree)
 
-# For cpu module
 AC_CHECK_FUNCS(sysctlbyname, [have_sysctlbyname="yes"], [have_sysctlbyname="no"])
-
-# For df module
-AC_CHECK_FUNCS(statfs statvfs)
+AC_CHECK_FUNCS(host_statistics, [have_host_statistics="yes"], [have_host_statistics="no"])
+AC_CHECK_FUNCS(processor_info, [have_processor_info="yes"], [have_processor_info="no"])
+AC_CHECK_FUNCS(thread_info, [have_thread_info="yes"], [have_thread_info="no"])
+AC_CHECK_FUNCS(statfs, [have_statfs="yes"], [have_statfs="no"])
+AC_CHECK_FUNCS(statvfs, [have_statvfs="yes"], [have_statvfs="no"])
+AC_CHECK_FUNCS(getifaddrs, [have_getifaddrs="yes"], [have_getifaddrs="no"])
+AC_CHECK_FUNCS(syslog, [have_syslog="yes"], [have_syslog="no"])
+AC_CHECK_FUNCS(getutent, [have_getutent="yes"], [have_getutent="no"])
+AC_CHECK_FUNCS(getutxent, [have_getutxent="yes"], [have_getutxent="no"])
 
 # For load module
 AC_CHECK_FUNCS(getloadavg, [have_getloadavg="yes"], [have_getloadavg="no"])
 
-# For the `processes' plugin
-AC_CHECK_FUNCS(thread_info)
-
-# For users module
-AC_CHECK_FUNCS(getutent getutxent)
-
-# For interface module
-AC_CHECK_FUNCS(getifaddrs)
-
 # Check for NAN
 AC_ARG_WITH(nan-emulation, [AS_HELP_STRING([--with-nan-emulation], [use emulated NAN. For crosscompiling only.])],
 [
@@ -1140,10 +1055,6 @@ then
 fi
 AM_CONDITIONAL(BUILD_WITH_LIBOPING, test "x$with_liboping" = "xyes")
 AM_CONDITIONAL(BUILD_WITH_OWN_LIBOPING, test "x$with_own_liboping" = "xyes")
-if test "x$with_liboping" = "xyes" -a "x$with_own_liboping" = "xyes"
-then
-       with_liboping="yes (shipped version)"
-fi
 
 AC_ARG_WITH(libpcap, [AS_HELP_STRING([--with-libpcap@<:@=PREFIX@:>@], [Path to libpcap.])],
 [
@@ -1277,6 +1188,32 @@ else
 fi
 AM_CONDITIONAL(BUILD_WITH_LIBIPTC, test "x$with_libiptc" = "xyes")
 
+AC_ARG_WITH(libnetsnmp, [AS_HELP_STRING([--with-libnetsnmp@<:@=PREFIX@:>@], [Path to the Net-SNMPD library.])],
+[
+       if test "x$withval" != "xno" && test "x$withval" != "xyes"
+       then
+               LDFLAGS="$LDFLAGS -L$withval/lib"
+               CPPFLAGS="$CPPFLAGS -I$withval/include"
+               with_libnetsnmp="yes"
+       fi
+],
+[with_libnetsnmp="yes"])
+if test "x$with_libnetsnmp" = "xyes"
+then
+       AC_CHECK_LIB(netsnmp, init_snmp,
+       [
+               AC_DEFINE(HAVE_LIBSNMP, 1, [Define to 1 if you have the Net-SNMP library (-lnetsnmp).])
+       ], [with_libnetsnmp="no (libnetsnmp not found)"])
+fi
+if test "x$with_libnetsnmp" = "xyes"
+then
+       AC_CHECK_HEADERS(net-snmp/net-snmp-config.h,
+       [
+               AC_DEFINE(HAVE_NET_SNMP_NET_SNMP_CONFIG_H, 1, [Define to 1 if you have the <net-snmp/net-snmp-config.h> header file.])
+       ], [with_libnetsnmp="no (net-snmp/net-snmp-config.h not found)"])
+fi
+AM_CONDITIONAL(BUILD_WITH_LIBNETSNMP, test "x$with_libnetsnmp" = "xyes")
+
 AC_ARG_WITH(libupsclient, [AS_HELP_STRING([--with-libupsclient@<:@=PREFIX@:>@], [Path to libupsclient.])],
 [
        if test "x$withval" != "xno" && test "x$withval" != "xyes"
@@ -1305,6 +1242,74 @@ then
 fi
 AM_CONDITIONAL(BUILD_WITH_LIBUPSCLIENT, test "x$with_libupsclient" = "xyes")
 
+### BEGIN of check for libxmms ###
+with_xmms_config="xmms-config"
+with_xmms_prefix=0
+with_xmms_cflags=""
+with_xmms_libs=""
+AC_ARG_WITH(libxmms, [AS_HELP_STRING([--with-libxmms@<:@=PREFIX@:>@], [Path to libxmms.])],
+[
+       if test "x$withval" != "xno" -a "x$withval" != "xyes"
+       then
+               if test -x "$withval/bin/xmms-config"
+               then
+                       with_xmms_config="$withval/bin/xmms-config"
+                       with_xmms_prefix=1
+               fi
+       fi
+       if test "x$withval" = "xno"
+       then
+               with_libxmms="no"
+       else
+               with_libxmms="yes"
+       fi
+],
+[
+       with_libxmms="yes"
+])
+if test "x$with_libxmms" = "xyes"
+then
+       with_xmms_cflags=`$with_xmms_config --cflags 2>/dev/null`
+       xmms_config_status=$?
+
+       if test $xmms_config_status -ne 0
+       then
+               with_libxmms="no"
+       fi
+fi
+if test "x$with_libxmms" = "xyes"
+then
+       with_xmms_libs=`$with_xmms_config --libs 2>/dev/null`
+       xmms_config_status=$?
+
+       if test $xmms_config_status -ne 0
+       then
+               with_libxmms="no"
+       fi
+fi
+if test "x$with_libxmms" = "xyes"
+then
+       AC_CHECK_LIB(xmms, xmms_remote_get_info,
+       [
+               BUILD_WITH_LIBXMMS_CFLAGS="$with_xmms_cflags"
+               BUILD_WITH_LIBXMMS_LIBS="$with_xmms_libs"
+               AC_SUBST(BUILD_WITH_LIBXMMS_CFLAGS)
+               AC_SUBST(BUILD_WITH_LIBXMMS_LIBS)
+       ],
+       [
+               with_libxmms="no"
+       ],
+       [$with_xmms_libs])
+fi
+with_libxmms_numeric=0
+if test "x$with_libxmms" = "xyes"
+then
+       with_libxmms_numeric=1
+fi
+AC_DEFINE_UNQUOTED(HAVE_LIBXMMS, [$with_libxmms_numeric], [Define to 1 if you have the 'xmms' library (-lxmms).])
+AM_CONDITIONAL(BUILD_WITH_LIBXMMS, test "x$with_libxmms" = "xyes")
+### END of check for libxmms ###
+
 # Check for enabled/disabled features
 #
 
        ]dnl
 )# AC_COLLECTD(name, enable/disable, info-text, feature/module)
 
+# AC_PLUGIN(name, default, info)
+# ------------------------------------------------------------
+dnl
+AC_DEFUN(
+  [AC_PLUGIN],
+  [
+    enable_plugin="no"
+    AC_ARG_ENABLE([$1], AC_HELP_STRING([--enable-$1], [$3]),
+    [
+     if test "x$enableval" = "xyes"
+     then
+            enable_plugin="yes"
+     else
+            enable_plugin="no"
+     fi
+    ],
+    [
+     if test "x$2" = "xyes"
+     then
+            enable_plugin="yes"
+     else
+            enable_plugin="no"
+     fi
+    ])
+    if test "x$enable_plugin" = "xyes"
+    then
+           AC_DEFINE([HAVE_PLUGIN_]my_toupper([$1]), 1, [Define to 1 if the $1 plugin is enabled.])
+    fi
+    AM_CONDITIONAL([BUILD_PLUGIN_]my_toupper([$1]), test "x$enable_plugin" = "xyes")
+    enable_$1="$enable_plugin"
+  ]
+)# AC_PLUGIN(name, default, info)
+
 m4_divert_once([HELP_ENABLE], [
 collectd features:])
+# FIXME: Remove these calls to `AC_COLLECTD' and then remove that macro.
 AC_COLLECTD([debug],     [enable],  [feature], [debugging])
 AC_COLLECTD([daemon],    [disable], [feature], [daemon mode])
 AC_COLLECTD([getifaddrs],[enable],  [feature], [getifaddrs under Linux])
 
+plugin_battery="no"
+plugin_cpu="no"
+plugin_cpufreq="no"
+plugin_df="no"
+plugin_disk="no"
+plugin_entropy="no"
+plugin_interface="no"
+plugin_irq="no"
+plugin_load="no"
+plugin_memory="no"
+plugin_nfs="no"
+plugin_processes="no"
+plugin_serial="no"
+plugin_swap="no"
+plugin_tape="no"
+plugin_users="no"
+plugin_vserver="no"
+plugin_wireless="no"
+
+# Linux
+if test "x$ac_system" = "xLinux"
+then
+       plugin_battery="yes"
+       plugin_cpu="yes"
+       plugin_cpufreq="yes"
+       plugin_disk="yes"
+       plugin_entropy="yes"
+       plugin_interface="yes"
+       plugin_irq="yes"
+       plugin_load="yes"
+       plugin_memory="yes"
+       plugin_nfs="yes"
+       plugin_processes="yes"
+       plugin_serial="yes"
+       plugin_swap="yes"
+       plugin_vserver="yes"
+       plugin_wireless="yes"
+fi
+
+# Mac OS X devices
+if test "x$with_libiokit" = "xyes"
+then
+       plugin_battery="yes"
+       plugin_disk="yes"
+fi
+
+# Solaris
+if test "x$with_devinfo$with_kstat" = "xyesyes"
+then
+       plugin_cpu="yes"
+       plugin_disk="yes"
+       plugin_interface="yes"
+       plugin_memory="yes"
+       plugin_swap="yes"
+       plugin_tape="yes"
+fi
+
+# libstatgrab
+if test "x$with_libstatgrab" = "xyes"
+then
+       plugin_interface="yes"
+       plugin_load="yes"
+       plugin_memory="yes"
+       plugin_swap="yes"
+fi
+
+if test "x$have_processor_info" = "xyes"
+then
+       plugin_cpu="yes"
+fi
+if test "x$have_sysctlbyname" = "xyes"
+then
+       plugin_cpu="yes"
+       plugin_memory="yes"
+fi
+
+if test "x$have_statfs" = "xyes"
+then
+       plugin_df="yes"
+fi
+if test "x$have_statvfs" = "xyes"
+then
+       plugin_df="yes"
+fi
+
+if test "x$have_getifaddrs" = "xyes"
+then
+       plugin_interface="yes"
+fi
+
+if test "x$have_getloadavg" = "xyes"
+then
+       plugin_load="yes"
+fi
+
+# Mac OS X memory interface
+if test "x$have_host_statistics" = "xyes"
+then
+       plugin_memory="yes"
+fi
+
+if test "x$have_thread_info" = "xyes"
+then
+       plugin_processes="yes"
+fi
+
+if test "x$with_libkvm" = "xyes"
+then
+       plugin_swap="yes"
+fi
+
+if test "x$have_getutent" = "xyes"
+then
+       plugin_users="yes"
+fi
+if test "x$have_getutxent" = "xyes"
+then
+       plugin_users="yes"
+fi
+
+# FIXME: sysctl for swap plugin
+
 m4_divert_once([HELP_ENABLE], [
-collectd modules:])
-AC_COLLECTD([apache],    [disable], [module], [Apache httpd statistics])
-AC_COLLECTD([apcups],    [disable], [module], [Statistics of UPSes by APC])
-AC_COLLECTD([apple_sensors], [disable], [module], [Apple's hardware sensors])
-AC_COLLECTD([battery],   [disable], [module], [battery statistics])
-AC_COLLECTD([cpu],       [disable], [module], [cpu usage statistics])
-AC_COLLECTD([cpufreq],   [disable], [module], [system cpu frequency statistics])
-AC_COLLECTD([disk],      [disable], [module], [disk/partition statistics])
-AC_COLLECTD([csv],       [disable], [module], [csv output plugin])
-AC_COLLECTD([df],        [disable], [module], [df statistics])
-AC_COLLECTD([dns],       [disable], [module], [dns statistics])
-AC_COLLECTD([email],     [disable], [module], [email statistics])
-AC_COLLECTD([entropy],   [disable], [module], [entropy statistics])
-AC_COLLECTD([exec],      [disable], [module], [exec of external programs])
-AC_COLLECTD([hddtemp],   [disable], [module], [hdd temperature statistics])
-AC_COLLECTD([interface], [disable], [module], [interface statistics])
-AC_COLLECTD([iptables],  [disable], [module], [IPtables statistics])
-AC_COLLECTD([irq],       [disable], [module], [irq statistics])
-AC_COLLECTD([load],      [disable], [module], [system load statistics])
-AC_COLLECTD([mbmon],     [disable], [module], [motherboard monitor statistics])
-AC_COLLECTD([memory],    [disable], [module], [memory statistics])
-AC_COLLECTD([multimeter],[disable], [module], [multimeter statistics])
-AC_COLLECTD([mysql],     [disable], [module], [mysql statistics])
-AC_COLLECTD([network],   [disable], [module], [network functionality])
-AC_COLLECTD([nfs],       [disable], [module], [nfs statistics])
-AC_COLLECTD([ntpd],      [disable], [module], [ntpd statistics])
-AC_COLLECTD([nut],       [disable], [module], [network UPS tools statistics])
-AC_COLLECTD([perl],      [disable], [module], [embedded perl interpreter])
-AC_COLLECTD([ping],      [disable], [module], [ping statistics])
-AC_COLLECTD([processes], [disable], [module], [processes statistics])
-AC_COLLECTD([sensors],   [disable], [module], [lm_sensors statistics])
-AC_COLLECTD([serial],    [disable], [module], [serial statistics])
-AC_COLLECTD([logfile],   [disable], [module], [logfile log facility])
-AC_COLLECTD([swap],      [disable], [module], [swap statistics])
-AC_COLLECTD([syslog],    [disable], [module], [syslog log facility])
-AC_COLLECTD([tape],      [disable], [module], [tape statistics])
-AC_COLLECTD([unixsock],  [disable], [module], [UNIX socket plugin])
-AC_COLLECTD([users],     [disable], [module], [user count statistics])
-AC_COLLECTD([vserver],   [disable], [module], [vserver statistics])
-AC_COLLECTD([wireless],  [disable], [module], [wireless link statistics])
+collectd plugins:])
+
+AC_PLUGIN([apache],      [$with_libcurl],     [Apache httpd statistics])
+AC_PLUGIN([apcups],      [yes],               [Statistics of UPSes by APC])
+AC_PLUGIN([apple_sensors], [$with_libiokit],  [Apple's hardware sensors])
+AC_PLUGIN([battery],     [$plugin_battery],   [Battery statistics])
+AC_PLUGIN([cpu],         [$plugin_cpu],       [CPU usage statistics])
+AC_PLUGIN([cpufreq],     [$plugin_cpufreq],   [CPU frequency statistics])
+AC_PLUGIN([csv],         [yes],               [CSV output plugin])
+AC_PLUGIN([df],          [$plugin_df],        [Filesystem usage statistics])
+AC_PLUGIN([disk],        [$plugin_disk],      [Disk usage statistics])
+AC_PLUGIN([dns],         [$with_libpcap],     [DNS traffic analysis])
+AC_PLUGIN([email],       [yes],               [EMail statistics])
+AC_PLUGIN([entropy],     [$plugin_entropy],   [Entropy statistics])
+AC_PLUGIN([exec],        [yes],               [Execution of external programs])
+AC_PLUGIN([hddtemp],     [yes],               [Query hddtempd])
+AC_PLUGIN([interface],   [$plugin_interface], [Interface traffic statistics])
+AC_PLUGIN([iptables],    [$with_libiptc],     [IPTables rule counters])
+AC_PLUGIN([irq],         [$plugin_irq],       [IRQ statistics])
+AC_PLUGIN([load],        [$plugin_load],      [System load])
+AC_PLUGIN([logfile],     [yes],               [File logging plugin])
+AC_PLUGIN([mbmon],       [yes],               [Query mbmond])
+AC_PLUGIN([memory],      [$plugin_memory],    [Memory usage])
+AC_PLUGIN([multimeter],  [no],                [Read multimeter values])
+AC_PLUGIN([mysql],       [$with_libmysql],    [MySQL statistics])
+AC_PLUGIN([network],     [yes],               [Network communication plugin])
+AC_PLUGIN([nfs],         [$plugin_nfs],       [NFS statistics])
+AC_PLUGIN([ntpd],        [yes],               [NTPd statistics])
+AC_PLUGIN([nut],         [$with_libupsclient], [Network UPS tools statistics])
+AC_PLUGIN([perl],        [$with_libperl],     [Embed a Perl interpreter])
+AC_PLUGIN([ping],        [$with_liboping],    [Network latency statistics])
+AC_PLUGIN([processes],   [$plugin_processes], [Process statistics])
+AC_PLUGIN([rrdtool],     [$with_rrdtool],     [RRDTool output plugin])
+AC_PLUGIN([sensors],     [$with_lm_sensors],  [lm_sensors statistics])
+AC_PLUGIN([serial],      [$plugin_serial],    [serial port traffic])
+AC_PLUGIN([snmp],        [$with_libnetsnmp],  [SNMP querying plugin])
+AC_PLUGIN([swap],        [$plugin_swap],      [Swap usage statistics])
+AC_PLUGIN([syslog],      [$have_syslog],      [Syslog logging plugin])
+AC_PLUGIN([tape],        [$plugin_tape],      [Tape drive statistics])
+AC_PLUGIN([unixsock],    [yes],               [Unixsock communication plugin])
+AC_PLUGIN([users],       [$plugin_users],     [User statistics])
+AC_PLUGIN([vserver],     [$plugin_vserver],   [Linux VServer statistics])
+AC_PLUGIN([wireless],    [$plugin_wireless],  [Wireless statistics])
+AC_PLUGIN([xmms],        [$with_libxmms],     [XMMS statistics])
 
 AC_OUTPUT(Makefile src/Makefile src/collectd.conf src/liboconfig/Makefile src/liboping/Makefile)
 
+if test "x$with_liboping" = "xyes" -a "x$with_own_liboping" = "xyes"
+then
+       with_liboping="yes (shipped version)"
+fi
+
 if test "x$with_libperl" = "xyes"
 then
        with_libperl="yes (version `perl -MConfig -e 'print $Config{version};'`)"
@@ -1433,7 +1603,9 @@ Configuration:
     libiokit  . . . . . $with_libiokit
     libiptc . . . . . . $with_libiptc
     libkstat  . . . . . $with_kstat
+    libkvm  . . . . . . $with_libkvm
     libmysql  . . . . . $with_libmysql
+    libnetsnmp  . . . . $with_libnetsnmp
     liboconfig  . . . . $with_liboconfig
     liboping  . . . . . $with_liboping
     libpcap . . . . . . $with_libpcap
@@ -1443,6 +1615,7 @@ Configuration:
     libsensors  . . . . $with_lm_sensors
     libstatgrab . . . . $with_libstatgrab
     libupsclient  . . . $with_libupsclient
+    libxmms . . . . . . $with_libxmms
 
   Features:
     daemon mode . . . . $enable_daemon
@@ -1481,6 +1654,7 @@ Configuration:
     processes . . . . . $enable_processes
     sensors . . . . . . $enable_sensors
     serial  . . . . . . $enable_serial
+    snmp  . . . . . . . $enable_snmp
     swap  . . . . . . . $enable_swap
     syslog  . . . . . . $enable_syslog
     tape  . . . . . . . $enable_tape
@@ -1488,5 +1662,6 @@ Configuration:
     users . . . . . . . $enable_users
     vserver . . . . . . $enable_vserver
     wireless  . . . . . $enable_wireless
+    xmms  . . . . . . . $enable_xmms
 
 EOF
index 92e8772..3b8a91c 100644 (file)
@@ -83,6 +83,33 @@ sub _create_identifier
        return ("$host/$plugin/$type");
 } # _create_identifier
 
+sub _parse_identifier
+{
+       my $string = shift;
+       my $host;
+       my $plugin;
+       my $plugin_instance;
+       my $type;
+       my $type_instance;
+       my $ident;
+
+       ($host, $plugin, $type) = split ('/', $string);
+
+       ($plugin, $plugin_instance) = split ('-', $plugin, 2);
+       ($type, $type_instance) = split ('-', $type, 2);
+
+       $ident =
+       {
+               host => $host,
+               plugin => $plugin,
+               type => $type
+       };
+       $ident->{'plugin_instance'} = $plugin_instance if (defined ($plugin_instance));
+       $ident->{'type_instance'} = $type_instance if (defined ($type_instance));
+
+       return ($ident);
+} # _parse_identifier
+
 =head1 PUBLIC METHODS
 
 =over 4
@@ -217,6 +244,52 @@ sub putval
        return;
 } # putval
 
+=item I<$res> = I<$obj>-E<gt>B<listval> ()
+
+Queries a list of values from the daemon. The list is returned as an array of
+hash references, where each hash reference is a valid identifier. The C<time>
+member of each hash holds the epoch value of the last update of that value.
+
+=cut
+
+sub listval
+{
+       my $obj = shift;
+       my $msg;
+       my @ret = ();
+       my $status;
+       my $fh = $obj->{'sock'} or confess;
+
+       $msg = "LISTVAL\n";
+       send ($fh, $msg, 0) or confess ("send: $!");
+
+       $msg = <$fh>;
+       ($status, $msg) = split (' ', $msg, 2);
+       if ($status < 0)
+       {
+               $obj->{'error'} = $msg;
+               return;
+       }
+
+       for (my $i = 0; $i < $status; $i++)
+       {
+               my $time;
+               my $ident;
+
+               $msg = <$fh>;
+               chomp ($msg);
+
+               ($time, $ident) = split (' ', $msg, 2);
+
+               $ident = _parse_identifier ($ident);
+               $ident->{'time'} = int ($time);
+
+               push (@ret, $ident);
+       } # for (i = 0 .. $status)
+
+       return (@ret);
+} # listval
+
 =item I<$obj>-E<gt>destroy ();
 
 Closes the socket before the object is destroyed. This function is also
index c76c44d..1edcfc6 100644 (file)
@@ -18,7 +18,7 @@ add a loadplugin call into your init.pre file.
 
 =over 4
 
-=item collectd_socket [ socket path ]      (default: /tmp/.collectd-email)
+=item collectd_socket [ socket path ]      (default: /var/run/collectd-email)
 
 Where the collectd socket is
 
@@ -116,7 +116,7 @@ sub set_config {
 
     push (@cmds, {
            setting => 'collectd_socket', 
-           default => '/tmp/.collectd-email',
+           default => '/var/run/collectd-email',
            type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING,
     });
 
index 0abfb49..7ffd708 100644 (file)
@@ -1,5 +1,5 @@
 collectd_buffersize 256
-collectd_socket /tmp/.collectd-email
+collectd_socket /var/run/collectd-email
 collectd_timeout 2
 collectd_retries 3 
 
diff --git a/contrib/cussh.pl b/contrib/cussh.pl
new file mode 100755 (executable)
index 0000000..65c634e
--- /dev/null
@@ -0,0 +1,185 @@
+#!/usr/bin/perl
+#
+# collectd - contrib/cussh.pl
+# Copyright (C) 2007  Sebastian Harl
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; only version 2 of the License is applicable.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+#
+# Author:
+#   Sebastian Harl <sh at tokkee.org>
+#
+
+=head1 NAME
+
+cussh - collectd UNIX socket shell
+
+=head1 SYNOPSIS
+
+B<cussh> [I<E<lt>pathE<gt>>]
+
+=head1 DESCRIPTION
+
+B<collectd>'s unixsock plugin allows external programs to access the values it
+has collected or received and to submit own values. This is a little
+interactive frontend for this plugin.
+
+=head1 OPTIONS
+
+=over 4
+
+=item I<E<lt>pathE<gt>>
+
+The path to the UNIX socket provided by collectd's unixsock plugin. (Default:
+F</var/run/collectd-unixsock>)
+
+=back
+
+=cut
+
+use strict;
+use warnings;
+
+use Collectd::Unixsock();
+
+{ # main
+       my $path = $ARGV[0] || "/var/run/collectd-unixsock";
+       my $sock = Collectd::Unixsock->new($path);
+
+       if (! $sock) {
+               print STDERR "Unable to connect to $path!\n";
+               exit 1;
+       }
+
+       print "cussh version 0.1, Copyright (C) 2007 Sebastian Harl\n"
+               . "cussh comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
+               . "and you are welcome to redistribute it under certain conditions.\n"
+               . "See the GNU General Public License 2 for more details.\n\n";
+
+       while (1) {
+               print "cussh> ";
+               my $line = <STDIN>;
+
+               last if ((! $line) || ($line =~ m/^quit$/i));
+
+               my ($cmd) = $line =~ m/^(\w+)\s+/;
+               $line = $';
+
+               next if (! $cmd);
+               $cmd = uc $cmd;
+
+               my $f = undef;
+               if ($cmd eq "PUTVAL") {
+                       $f = \&putval;
+               }
+               elsif ($cmd eq "GETVAL") {
+                       $f = \&getval;
+               }
+               else {
+                       print STDERR "ERROR: Unknown command $cmd!\n";
+                       next;
+               }
+
+               if (! $f->($sock, $line)) {
+                       print STDERR "ERROR: Command failed!\n";
+                       next;
+               }
+       }
+
+       $sock->destroy();
+       exit 0;
+}
+
+sub getid {
+       my $string = shift || return;
+
+       print $$string . $/;
+       my ($h, $p, $pi, $t, $ti) =
+               $$string =~ m/^(\w+)\/(\w+)(?:-(\w+))?\/(\w+)(?:-(\w+))?\s+/;
+       $$string = $';
+
+       return if ((! $h) || (! $p) || (! $t));
+
+       my %id = ();
+
+       ($id{'host'}, $id{'plugin'}, $id{'type'}) = ($h, $p, $t);
+
+       $id{'plugin_instance'} = $pi if ($pi);
+       $id{'type_instance'} = $ti if ($ti);
+       return \%id;
+}
+
+=head1 COMMANDS
+
+=over 4
+
+=item B<GETVAL> I<Identifier>
+
+=item B<PUTVAL> I<Identifier> I<Valuelist>
+
+These commands follow the exact same syntax as described in
+L<collectd-unixsock(5)>.
+
+=cut
+
+sub putval {
+       my $sock = shift || return;
+       my $line = shift || return;
+
+       my $id = getid(\$line);
+
+       return if (! $id);
+
+       my ($time, @values) = split m/:/, $line;
+       return $sock->putval(%$id, $time, \@values);
+}
+
+sub getval {
+       my $sock = shift || return;
+       my $line = shift || return;
+
+       my $id = getid(\$line);
+
+       return if (! $id);
+
+       my $vals = $sock->getval(%$id);
+
+       return if (! $vals);
+
+       foreach my $key (keys %$vals) {
+               print "\t$key: $vals->{$key}\n";
+       }
+       return 1;
+}
+
+=head1 SEE ALSO
+
+L<collectd(1)>, L<collectd-unisock(5)>
+
+=head1 AUTHOR
+
+Written by Sebastian Harl E<lt>sh@tokkee.orgE<gt>.
+
+B<collectd> has been written by Florian Forster and others.
+
+=head1 COPYRIGHT
+
+Copyright (C) 2007 Sebastian Harl.
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation; only version 2 of the License is applicable.
+
+=cut
+
+# vim: set sw=4 ts=4 tw=78 noexpandtab :
index f3f259b..458c138 100644 (file)
@@ -25,6 +25,7 @@ collectd_SOURCES = collectd.c collectd.h \
 collectd_CPPFLAGS = $(LTDLINCL)
 collectd_CPPFLAGS += -DPREFIX='"${prefix}"'
 collectd_CPPFLAGS += -DCONFIGFILE='"${sysconfdir}/${PACKAGE_NAME}.conf"'
+collectd_CPPFLAGS += -DLOCALSTATEDIR='"${localstatedir}"'
 collectd_CPPFLAGS += -DPKGLOCALSTATEDIR='"${localstatedir}/lib/${PACKAGE_NAME}"'
 if BUILD_FEATURE_DAEMON
 collectd_CPPFLAGS += -DPIDFILE='"${localstatedir}/run/${PACKAGE_NAME}.pid"'
@@ -80,18 +81,15 @@ endif
 
 pkglib_LTLIBRARIES = 
 
-if BUILD_MODULE_APACHE
+if BUILD_PLUGIN_APACHE
 pkglib_LTLIBRARIES += apache.la
 apache_la_SOURCES = apache.c
-apache_la_LDFLAGS = -module -avoid-version
-if BUILD_WITH_LIBCURL
-apache_la_LDFLAGS += $(BUILD_WITH_LIBCURL_LIBS)
-endif
+apache_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_LIBCURL_LIBS)
 collectd_LDADD += "-dlopen" apache.la
 collectd_DEPENDENCIES += apache.la
 endif
 
-if BUILD_MODULE_APCUPS
+if BUILD_PLUGIN_APCUPS
 pkglib_LTLIBRARIES += apcups.la
 apcups_la_SOURCES = apcups.c
 apcups_la_LDFLAGS = -module -avoid-version
@@ -102,18 +100,15 @@ collectd_LDADD += "-dlopen" apcups.la
 collectd_DEPENDENCIES += apcups.la
 endif
 
-if BUILD_MODULE_APPLE_SENSORS
+if BUILD_PLUGIN_APPLE_SENSORS
 pkglib_LTLIBRARIES += apple_sensors.la
 apple_sensors_la_SOURCES = apple_sensors.c
-apple_sensors_la_LDFLAGS = -module -avoid-version
-if BUILD_WITH_LIBIOKIT
-apple_sensors_la_LDFLAGS += -lIOKit
-endif
+apple_sensors_la_LDFLAGS = -module -avoid-version -lIOKit
 collectd_LDADD += "-dlopen" apple_sensors.la
 collectd_DEPENDENCIES += apple_sensors.la
 endif
 
-if BUILD_MODULE_BATTERY
+if BUILD_PLUGIN_BATTERY
 pkglib_LTLIBRARIES += battery.la
 battery_la_SOURCES = battery.c
 battery_la_LDFLAGS = -module -avoid-version
@@ -124,7 +119,7 @@ collectd_LDADD += "-dlopen" battery.la
 collectd_DEPENDENCIES += battery.la
 endif
 
-if BUILD_MODULE_CPU
+if BUILD_PLUGIN_CPU
 pkglib_LTLIBRARIES += cpu.la
 cpu_la_SOURCES = cpu.c
 cpu_la_LDFLAGS = -module -avoid-version
@@ -138,7 +133,7 @@ collectd_LDADD += "-dlopen" cpu.la
 collectd_DEPENDENCIES += cpu.la
 endif
 
-if BUILD_MODULE_CPUFREQ
+if BUILD_PLUGIN_CPUFREQ
 pkglib_LTLIBRARIES += cpufreq.la
 cpufreq_la_SOURCES = cpufreq.c
 cpufreq_la_LDFLAGS = -module -avoid-version
@@ -146,7 +141,7 @@ collectd_LDADD += "-dlopen" cpufreq.la
 collectd_DEPENDENCIES += cpufreq.la
 endif
 
-if BUILD_MODULE_CSV
+if BUILD_PLUGIN_CSV
 pkglib_LTLIBRARIES += csv.la
 csv_la_SOURCES = csv.c
 csv_la_LDFLAGS = -module -avoid-version
@@ -154,7 +149,7 @@ collectd_LDADD += "-dlopen" csv.la
 collectd_DEPENDENCIES += csv.la
 endif
 
-if BUILD_MODULE_DF
+if BUILD_PLUGIN_DF
 pkglib_LTLIBRARIES += df.la
 df_la_SOURCES = df.c
 df_la_LDFLAGS = -module -avoid-version
@@ -162,7 +157,7 @@ collectd_LDADD += "-dlopen" df.la
 collectd_DEPENDENCIES += df.la
 endif
 
-if BUILD_MODULE_DISK
+if BUILD_PLUGIN_DISK
 pkglib_LTLIBRARIES += disk.la
 disk_la_SOURCES = disk.c
 disk_la_LDFLAGS = -module -avoid-version
@@ -179,26 +174,15 @@ collectd_LDADD += "-dlopen" disk.la
 collectd_DEPENDENCIES += disk.la
 endif
 
-if BUILD_MODULE_DNS
+if BUILD_PLUGIN_DNS
 pkglib_LTLIBRARIES += dns.la
-dns_la_SOURCES = dns.c
-if BUILD_WITH_LIBPCAP
-if BUILD_WITH_LIBPTHREAD
-dns_la_SOURCES += utils_dns.c utils_dns.h
-endif
-endif
-dns_la_LDFLAGS = -module -avoid-version
-if BUILD_WITH_LIBPCAP
-dns_la_LDFLAGS += -lpcap
-endif
-if BUILD_WITH_LIBPTHREAD
-dns_la_LDFLAGS += -lpthread
-endif
+dns_la_SOURCES = dns.c utils_dns.c utils_dns.h
+dns_la_LDFLAGS = -module -avoid-version -lpcap -lpthread
 collectd_LDADD += "-dlopen" dns.la
 collectd_DEPENDENCIES += dns.la
 endif
 
-if BUILD_MODULE_EMAIL
+if BUILD_PLUGIN_EMAIL
 pkglib_LTLIBRARIES += email.la
 email_la_SOURCES = email.c
 email_la_LDFLAGS = -module -avoid-version
@@ -209,7 +193,7 @@ collectd_LDADD += "-dlopen" email.la
 collectd_DEPENDENCIES += email.la
 endif
 
-if BUILD_MODULE_ENTROPY
+if BUILD_PLUGIN_ENTROPY
 pkglib_LTLIBRARIES += entropy.la
 entropy_la_SOURCES = entropy.c
 entropy_la_LDFLAGS = -module -avoid-version
@@ -217,7 +201,7 @@ collectd_LDADD += "-dlopen" entropy.la
 collectd_DEPENDENCIES += entropy.la
 endif
 
-if BUILD_MODULE_EXEC
+if BUILD_PLUGIN_EXEC
 pkglib_LTLIBRARIES += exec.la
 exec_la_SOURCES = exec.c
 exec_la_LDFLAGS = -module -avoid-version
@@ -228,7 +212,7 @@ collectd_LDADD += "-dlopen" exec.la
 collectd_DEPENDENCIES += exec.la
 endif
 
-if BUILD_MODULE_HDDTEMP
+if BUILD_PLUGIN_HDDTEMP
 pkglib_LTLIBRARIES += hddtemp.la
 hddtemp_la_SOURCES = hddtemp.c
 hddtemp_la_LDFLAGS = -module -avoid-version
@@ -239,7 +223,7 @@ collectd_LDADD += "-dlopen" hddtemp.la
 collectd_DEPENDENCIES += hddtemp.la
 endif
 
-if BUILD_MODULE_INTERFACE
+if BUILD_PLUGIN_INTERFACE
 pkglib_LTLIBRARIES += interface.la
 interface_la_SOURCES = interface.c
 interface_la_LDFLAGS = -module -avoid-version
@@ -262,18 +246,15 @@ interface_la_LDFLAGS += -lstatgrab
 endif
 endif
 
-if BUILD_MODULE_IPTABLES
+if BUILD_PLUGIN_IPTABLES
 pkglib_LTLIBRARIES += iptables.la
 iptables_la_SOURCES = iptables.c
-iptables_la_LDFLAGS = -module -avoid-version
-if BUILD_WITH_LIBIPTC
-iptables_la_LDFLAGS += -liptc
-endif
+iptables_la_LDFLAGS = -module -avoid-version -liptc
 collectd_LDADD += "-dlopen" iptables.la
 collectd_DEPENDENCIES += iptables.la
 endif
 
-if BUILD_MODULE_IRQ
+if BUILD_PLUGIN_IRQ
 pkglib_LTLIBRARIES += irq.la
 irq_la_SOURCES = irq.c
 irq_la_LDFLAGS = -module -avoid-version
@@ -281,7 +262,7 @@ collectd_LDADD += "-dlopen" irq.la
 collectd_DEPENDENCIES += irq.la
 endif
 
-if BUILD_MODULE_LOAD
+if BUILD_PLUGIN_LOAD
 pkglib_LTLIBRARIES += load.la
 load_la_SOURCES = load.c
 load_la_LDFLAGS = -module -avoid-version
@@ -298,7 +279,7 @@ load_la_LDFLAGS += -lstatgrab
 endif
 endif
 
-if BUILD_MODULE_LOGFILE
+if BUILD_PLUGIN_LOGFILE
 pkglib_LTLIBRARIES += logfile.la
 logfile_la_SOURCES = logfile.c
 logfile_la_LDFLAGS = -module -avoid-version
@@ -306,7 +287,7 @@ collectd_LDADD += "-dlopen" logfile.la
 collectd_DEPENDENCIES += logfile.la
 endif
 
-if BUILD_MODULE_MBMON
+if BUILD_PLUGIN_MBMON
 pkglib_LTLIBRARIES += mbmon.la
 mbmon_la_SOURCES = mbmon.c
 mbmon_la_LDFLAGS = -module -avoid-version
@@ -317,7 +298,7 @@ collectd_LDADD += "-dlopen" mbmon.la
 collectd_DEPENDENCIES += mbmon.la
 endif
 
-if BUILD_MODULE_MEMORY
+if BUILD_PLUGIN_MEMORY
 pkglib_LTLIBRARIES += memory.la
 memory_la_SOURCES = memory.c
 memory_la_LDFLAGS = -module -avoid-version
@@ -340,7 +321,7 @@ memory_la_LDFLAGS += -lstatgrab
 endif
 endif
 
-if BUILD_MODULE_MULTIMETER
+if BUILD_PLUGIN_MULTIMETER
 pkglib_LTLIBRARIES += multimeter.la
 multimeter_la_SOURCES = multimeter.c
 multimeter_la_LDFLAGS = -module -avoid-version
@@ -348,18 +329,15 @@ collectd_LDADD += "-dlopen" multimeter.la
 collectd_DEPENDENCIES += multimeter.la
 endif
 
-if BUILD_MODULE_MYSQL
+if BUILD_PLUGIN_MYSQL
 pkglib_LTLIBRARIES += mysql.la
 mysql_la_SOURCES = mysql.c
-mysql_la_LDFLAGS = -module -avoid-version
-if BUILD_WITH_LIBMYSQL
-mysql_la_LDFLAGS += -lmysqlclient
-endif
+mysql_la_LDFLAGS = -module -avoid-version -lmysqlclient
 collectd_LDADD += "-dlopen" mysql.la
 collectd_DEPENDENCIES += mysql.la
 endif
 
-if BUILD_MODULE_NETWORK
+if BUILD_PLUGIN_NETWORK
 pkglib_LTLIBRARIES += network.la
 network_la_SOURCES = network.c network.h
 network_la_LDFLAGS = -module -avoid-version
@@ -373,7 +351,7 @@ collectd_LDADD += "-dlopen" network.la
 collectd_DEPENDENCIES += network.la
 endif
 
-if BUILD_MODULE_NFS
+if BUILD_PLUGIN_NFS
 pkglib_LTLIBRARIES += nfs.la
 nfs_la_SOURCES = nfs.c
 nfs_la_LDFLAGS = -module -avoid-version
@@ -381,7 +359,7 @@ collectd_LDADD += "-dlopen" nfs.la
 collectd_DEPENDENCIES += nfs.la
 endif
 
-if BUILD_MODULE_NTPD
+if BUILD_PLUGIN_NTPD
 pkglib_LTLIBRARIES += ntpd.la
 ntpd_la_SOURCES = ntpd.c
 ntpd_la_LDFLAGS = -module -avoid-version
@@ -392,22 +370,15 @@ collectd_LDADD += "-dlopen" ntpd.la
 collectd_DEPENDENCIES += ntpd.la
 endif
 
-if BUILD_MODULE_NUT
+if BUILD_PLUGIN_NUT
 pkglib_LTLIBRARIES += nut.la
 nut_la_SOURCES = nut.c
-nut_la_LDFLAGS = -module -avoid-version
-if BUILD_WITH_LIBUPSCLIENT
-nut_la_LDFLAGS += -lupsclient
-if BUILD_WITH_LIBPTHREAD
-nut_la_LDFLAGS += -lpthread
-endif
-endif
+nut_la_LDFLAGS = -module -avoid-version -lupsclient -lpthread
 collectd_LDADD += "-dlopen" nut.la
 collectd_DEPENDENCIES += nut.la
 endif
 
-if BUILD_WITH_LIBPERL
-if BUILD_MODULE_PERL
+if BUILD_PLUGIN_PERL
 pkglib_LTLIBRARIES += perl.la
 perl_la_SOURCES = perl.c
 perl_la_CFLAGS  = $(AM_CFLAGS) \
@@ -418,25 +389,22 @@ perl_la_LDFLAGS = -module -avoid-version \
 collectd_LDADD += "-dlopen" perl.la
 collectd_DEPENDENCIES += perl.la
 endif
-endif
 
-if BUILD_MODULE_PING
+if BUILD_PLUGIN_PING
 pkglib_LTLIBRARIES += ping.la
 ping_la_SOURCES = ping.c
 ping_la_LDFLAGS = -module -avoid-version
-if BUILD_WITH_LIBOPING
 if BUILD_WITH_OWN_LIBOPING
 ping_la_LIBADD  = liboping/liboping.la
 ping_la_DEPENDENCIES = liboping/liboping.la
 else
 ping_la_LDFLAGS += -loping
 endif
-endif
 collectd_LDADD += "-dlopen" ping.la
 collectd_DEPENDENCIES += ping.la
 endif
 
-if BUILD_MODULE_PROCESSES
+if BUILD_PLUGIN_PROCESSES
 pkglib_LTLIBRARIES += processes.la
 processes_la_SOURCES = processes.c
 processes_la_LDFLAGS = -module -avoid-version
@@ -444,7 +412,7 @@ collectd_LDADD += "-dlopen" processes.la
 collectd_DEPENDENCIES += processes.la
 endif
 
-if BUILD_WITH_RRDTOOL
+if BUILD_PLUGIN_RRDTOOL
 pkglib_LTLIBRARIES += rrdtool.la
 rrdtool_la_SOURCES = rrdtool.c
 rrdtool_la_LDFLAGS = -module -avoid-version -lrrd
@@ -452,7 +420,7 @@ collectd_LDADD += "-dlopen" rrdtool.la
 collectd_DEPENDENCIES += rrdtool.la
 endif
 
-if BUILD_MODULE_SENSORS
+if BUILD_PLUGIN_SENSORS
 pkglib_LTLIBRARIES += sensors.la
 sensors_la_SOURCES = sensors.c
 sensors_la_LDFLAGS = -module -avoid-version
@@ -463,7 +431,7 @@ collectd_LDADD += "-dlopen" sensors.la
 collectd_DEPENDENCIES += sensors.la
 endif
 
-if BUILD_MODULE_SERIAL
+if BUILD_PLUGIN_SERIAL
 pkglib_LTLIBRARIES += serial.la
 serial_la_SOURCES = serial.c
 serial_la_LDFLAGS = -module -avoid-version
@@ -471,7 +439,21 @@ collectd_LDADD += "-dlopen" serial.la
 collectd_DEPENDENCIES += serial.la
 endif
 
-if BUILD_MODULE_SWAP
+if BUILD_PLUGIN_SNMP
+pkglib_LTLIBRARIES += snmp.la
+snmp_la_SOURCES = snmp.c
+snmp_la_LDFLAGS = -module -avoid-version
+if BUILD_WITH_LIBNETSNMP
+snmp_la_LDFLAGS += -lnetsnmp
+endif
+if BUILD_WITH_LIBPTHREAD
+snmp_la_LDFLAGS += -lpthread
+endif
+collectd_LDADD += "-dlopen" snmp.la
+collectd_DEPENDENCIES += snmp.la
+endif
+
+if BUILD_PLUGIN_SWAP
 pkglib_LTLIBRARIES += swap.la
 swap_la_SOURCES = swap.c
 swap_la_LDFLAGS = -module -avoid-version
@@ -494,7 +476,7 @@ swap_la_LDFLAGS += -lstatgrab
 endif
 endif
 
-if BUILD_MODULE_SYSLOG
+if BUILD_PLUGIN_SYSLOG
 pkglib_LTLIBRARIES += syslog.la
 syslog_la_SOURCES = syslog.c
 syslog_la_LDFLAGS = -module -avoid-version
@@ -502,30 +484,24 @@ collectd_LDADD += "-dlopen" syslog.la
 collectd_DEPENDENCIES += syslog.la
 endif
 
-if BUILD_MODULE_TAPE
+if BUILD_PLUGIN_TAPE
 pkglib_LTLIBRARIES += tape.la
 tape_la_SOURCES = tape.c
-tape_la_LDFLAGS = -module -avoid-version
-if BUILD_WITH_LIBKSTAT
-tape_la_LDFLAGS += -lkstat
-endif
-if BUILD_WITH_LIBDEVINFO
-tape_la_LDFLAGS += -ldevinfo
-endif
+tape_la_LDFLAGS = -module -avoid-version -lkstat -ldevinfo
 collectd_LDADD += "-dlopen" tape.la
 collectd_DEPENDENCIES += tape.la
 endif
 
-if BUILD_MODULE_UNIXSOCK
+if BUILD_PLUGIN_UNIXSOCK
 pkglib_LTLIBRARIES += unixsock.la
 unixsock_la_SOURCES = unixsock.c
-unixsock_la_CPPFLAGS = -DPREFIX='"${prefix}"'
+unixsock_la_CPPFLAGS = -DLOCALSTATEDIR='"${localstatedir}"'
 unixsock_la_LDFLAGS = -module -avoid-version -lpthread
 collectd_LDADD += "-dlopen" unixsock.la
 collectd_DEPENDENCIES += unixsock.la
 endif
 
-if BUILD_MODULE_USERS
+if BUILD_PLUGIN_USERS
 pkglib_LTLIBRARIES += users.la
 users_la_SOURCES = users.c
 users_la_LDFLAGS = -module -avoid-version
@@ -533,7 +509,7 @@ collectd_LDADD += "-dlopen" users.la
 collectd_DEPENDENCIES += users.la
 endif
 
-if BUILD_MODULE_VSERVER
+if BUILD_PLUGIN_VSERVER
 pkglib_LTLIBRARIES += vserver.la
 vserver_la_SOURCES = vserver.c
 vserver_la_LDFLAGS = -module -avoid-version
@@ -541,7 +517,7 @@ collectd_LDADD += "-dlopen" vserver.la
 collectd_DEPENDENCIES += vserver.la
 endif
 
-if BUILD_MODULE_WIRELESS
+if BUILD_PLUGIN_WIRELESS
 pkglib_LTLIBRARIES += wireless.la
 wireless_la_SOURCES = wireless.c
 wireless_la_LDFLAGS = -module -avoid-version
@@ -549,9 +525,19 @@ collectd_LDADD += "-dlopen" wireless.la
 collectd_DEPENDENCIES += wireless.la
 endif
 
+if BUILD_PLUGIN_XMMS
+pkglib_LTLIBRARIES += xmms.la
+xmms_la_SOURCES = xmms.c
+xmms_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBXMMS_CFLAGS)
+xmms_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_LIBXMMS_LIBS)
+collectd_LDADD += "-dlopen" xmms.la
+collectd_DEPENDENCIES += xmms.la
+endif
+
+
 dist_man_MANS = collectd.1 collectd-nagios.1 collectd.conf.5 \
                collectd-email.5 collectd-exec.5 collectd-perl.5 \
-               collectd-unixsock.5
+               collectd-snmp.5 collectd-unixsock.5
 
 #collectd_1_SOURCES = collectd.pod
 
index 573a116..2365d1f 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * collectd - src/apache.c
- * Copyright (C) 2006  Florian octo Forster
+ * Copyright (C) 2006,2007  Florian octo Forster
  * Copyright (C) 2007  Florent EppO Monbillard
  *
  * This program is free software; you can redistribute it and/or modify it
 #include "plugin.h"
 #include "configfile.h"
 
-#if HAVE_LIBCURL && HAVE_CURL_CURL_H
-#  define APACHE_HAVE_READ 1
-#  include <curl/curl.h>
-#else
-#  define APACHE_HAVE_READ 0
-#endif
+#include <curl/curl.h>
 
-#if APACHE_HAVE_READ
 static char *url    = NULL;
 static char *user   = NULL;
 static char *pass   = NULL;
@@ -309,14 +303,11 @@ static int apache_read (void)
 
        return (0);
 } /* int apache_read */
-#endif /* APACHE_HAVE_READ */
 
 void module_register (void)
 {
-#if APACHE_HAVE_READ
        plugin_register_config ("apache", config,
                        config_keys, config_keys_num);
        plugin_register_init ("apache", init);
        plugin_register_read ("apache", apache_read);
-#endif
 } /* void module_register */
index 75de03e..62c7a3c 100644 (file)
@@ -1,9 +1,11 @@
 /*
  * collectd - src/apcups.c
+ * Copyright (C) 2007 Florian octo Forster
  * Copyright (C) 2006 Anthony Gialluca <tonyabg at charter.net>
  * Copyright (C) 2000-2004 Kern Sibbald
  * Copyright (C) 1996-99 Andre M. Hedrick <andre at suse.com>
  *
+ *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General
  * Public License as published by the Free Software Foundation.
index e13bdc8..2726ad2 100644 (file)
 #  include <IOKit/IOTypes.h>
 #endif
 
-#if HAVE_IOKIT_IOKITLIB_H
-# define IOKIT_HAVE_READ 1
-#else
-# define IOKIT_HAVE_READ 0
-#endif
-
-#if HAVE_IOKIT_IOKITLIB_H
 static mach_port_t io_master_port = MACH_PORT_NULL;
-#endif
 
-#if IOKIT_HAVE_READ
 static int as_init (void)
 {
        kern_return_t status;
@@ -240,12 +231,9 @@ static int as_read (void)
 
        return (0);
 } /* int as_read */
-#endif /* IOKIT_HAVE_READ */
 
 void module_register (void)
 {
-#if IOKIT_HAVE_READ
        plugin_register_init ("apple_sensors", as_init);
        plugin_register_read ("apple_sensors", as_read);
-#endif /* IOKIT_HAVE_READ */
 } /* void module_register */
index 952c56c..2e27e60 100644 (file)
 #  include <IOKit/ps/IOPSKeys.h>
 #endif
 
-#if HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H || KERNEL_LINUX
-# define BATTERY_HAVE_READ 1
-#else
-# define BATTERY_HAVE_READ 0
+#if !HAVE_IOKIT_IOKITLIB_H && !HAVE_IOKIT_PS_IOPOWERSOURCES_H && !KERNEL_LINUX
+# error "No applicable input method."
 #endif
 
 #define INVALID_VALUE 47841.29
 
-#if BATTERY_HAVE_READ
 #if HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H
        /* No global variables */
 /* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */
@@ -523,12 +520,9 @@ static int battery_read (void)
 
        return (0);
 }
-#endif /* BATTERY_HAVE_READ */
 
 void module_register (void)
 {
-#if BATTERY_HAVE_READ
        plugin_register_init ("battery", battery_init);
        plugin_register_read ("battery", battery_read);
-#endif /* BATTERY_HAVE_READ */
 } /* void module_register */
index fca9f18..63effd5 100644 (file)
@@ -294,25 +294,22 @@ int do_check_con_none (int values_num, double *values, char **values_names)
                        num_okay++;
        }
 
-       if ((num_critical != 0) || (values_num == 0))
+       printf ("%i critical, %i warning, %i okay",
+                       num_critical, num_warning, num_okay);
+       if (values_num > 0)
        {
-               printf ("CRITICAL: %i critical, %i warning, %i okay\n",
-                               num_critical, num_warning, num_okay);
-               return (RET_CRITICAL);
+               printf (" |");
+               for (i = 0; i < values_num; i++)
+                       printf (" %s=%lf;;;;", values_names[i], values[i]);
        }
+       printf ("\n");
+
+       if ((num_critical != 0) || (values_num == 0))
+               return (RET_CRITICAL);
        else if (num_warning != 0)
-       {
-               printf ("WARNING: %i warning, %i okay\n",
-                               num_warning, num_okay);
                return (RET_WARNING);
-       }
-       else
-       {
-               printf ("OKAY: %i okay\n", num_okay);
-               return (RET_OKAY);
-       }
 
-       return (RET_UNKNOWN);
+       return (RET_OKAY);
 } /* int do_check_con_none */
 
 int do_check_con_average (int values_num, double *values, char **values_names)
@@ -320,6 +317,7 @@ int do_check_con_average (int values_num, double *values, char **values_names)
        int i;
        double total;
        int total_num;
+       double average;
 
        total = 0.0;
        total_num = 0;
@@ -333,31 +331,23 @@ int do_check_con_average (int values_num, double *values, char **values_names)
        }
 
        if (total_num == 0)
-       {
-               printf ("WARNING: No defined values found\n");
+               average = NAN;
+       else
+               average = total / total_num;
+       printf ("%lf average |", average);
+       for (i = 0; i < values_num; i++)
+               printf (" %s=%lf;;;;", values_names[i], values[i]);
+
+       if (total_num == 0)
                return (RET_WARNING);
-       }
 
-       if (match_range (&range_critical_g, total / total_num) != 0)
-       {
-               printf ("CRITICAL: Average = %lf\n",
-                               (double) (total / total_num));
+       if (isnan (average)
+                       || match_range (&range_critical_g, average))
                return (RET_CRITICAL);
-       }
-       else if (match_range (&range_warning_g, total / total_num) != 0)
-       {
-               printf ("WARNING: Average = %lf\n",
-                               (double) (total / total_num));
+       else if (match_range (&range_warning_g, average) != 0)
                return (RET_WARNING);
-       }
-       else
-       {
-               printf ("OKAY: Average = %lf\n",
-                               (double) (total / total_num));
-               return (RET_OKAY);
-       }
 
-       return (RET_UNKNOWN);
+       return (RET_OKAY);
 } /* int do_check_con_average */
 
 int do_check_con_sum (int values_num, double *values, char **values_names)
@@ -422,7 +412,7 @@ int do_check (void)
                return (do_check_con_sum (values_num, values, values_names));
 
        free (values);
-       free (values_names);
+       free (values_names); /* FIXME? */
 
        return (RET_UNKNOWN);
 }
diff --git a/src/collectd-snmp.pod b/src/collectd-snmp.pod
new file mode 100644 (file)
index 0000000..22d6e37
--- /dev/null
@@ -0,0 +1,191 @@
+=head1 NAME
+
+collectd-snmp - Documentation of collectd's C<snmp plugin>
+
+=head1 SYNOPSIS
+
+  LoadPlugin snmp
+  # ...
+  <Plugin snmp>
+    <Data "powerplus_voltge_input">
+      Type "voltage"
+      Table false
+      Instance "input_line1"
+      Values "SNMPv2-SMI::enterprises.6050.5.4.1.1.2.1"
+    </Data>
+    <Data "hr_users">
+      Type "users"
+      Table false
+      Instance ""
+      Values "HOST-RESOURCES-MIB::hrSystemNumUsers.0"
+    </Data>
+    <Data "std_traffic">
+      Type "if_octets"
+      Table true
+      Instance "IF-MIB::ifDescr"
+      Values "IF-MIB::ifInOctets" "IF-MIB::ifOutOctets"
+    </Data>
+
+    <Host "some.switch.mydomain.org">
+      Address "192.168.0.2"
+      Version 1
+      Community "community_string"
+      Collect "std_traffic"
+      Inverval 120
+    </Host>
+    <Host "some.server.mydomain.org">
+      Address "192.168.0.42"
+      Version 2
+      Community "another_string"
+      Collect "std_traffic" "hr_users"
+    </Host>
+    <Host "some.ups.mydomain.org">
+      Address "192.168.0.3"
+      Version 1
+      Community "more_communities"
+      Collect "powerplus_voltge_input"
+      Interval 300
+    </Host>
+  </Plugin>
+
+=head1 DESCRIPTION
+
+The C<snmp plugin> queries other hosts using SNMP, the simple network
+management protocol, and translates the value it receives to collectd's
+internal format and dispatches them. Depending on the write plugins you have
+loaded they may be written to disk or submitted to another instance or
+whatever you configured.
+
+=head1 CONFIGURATION
+
+Since the aim of the C<snmp plugin> is to provide a generic interface to SNMP,
+it's configuration is not trivial and may take some time.
+
+There are two types of blocks that can be contained in the
+C<E<lt>PluginE<nbsp>snmpE<gt>> block: B<Data> and B<Host>:
+
+=head2 The B<Data> block
+
+The B<Data> block defines a list of values or a table of values that are to be
+queried. The following options can be set:
+
+=over 4
+
+=item B<Type> I<type>
+
+collectd's type that is to be used, e.E<nbsp>g. "if_octets" for interface
+traffic or "users" for a user count. The types are read from the B<TypesDB>
+(see L<collectd.conf(5)>), so you may want to check for which types are
+defined.
+
+=item B<Table> I<true|false>
+
+Define if this is a single list of values or a table of values. The difference
+is that when querying a list of values from SNMP that data is going to be
+dispatched as one value-list to the daemon (i.E<nbsp>e.  one RRD file will be
+created). If the correcponding data-set needs more than one value (has more
+than one data-source) you will still need to configure more than one B<Values>
+(see below).
+
+If B<Table> is set to I<true> then the plugin will search the entire subtree
+and dispatch all values it can find. This is handy for the typical SNMP
+tables, such as the interface table (C<IF-MIB::ifTable>).
+
+Since the semantic of B<Instance> and B<Values> depends on this setting you
+need to set it before setting them. Doing vice verse will result in undefined
+behavior.
+
+=item B<Instance> I<Instance>
+
+Sets the type-instance of the values that are dispatched. The meaning of this
+setting depends on wether B<Table> is set to I<true> or I<false>:
+
+If B<Table> is set to I<true>, I<Instance> is interpreted as an SNMP-prefix
+that will return a list of strings. Those strings are then used as the actual
+type-instance. An example would be the C<IF-MIB::ifDescr> subtree.
+L<variables(5)> from the SNMP distribution describes the format of OIDs.
+
+If B<Table> is set to I<false> the actual string configured for I<Instance> is
+copied into the value-list. In this case I<Instance> may be empty, i.E<nbsp>e.
+"".
+
+=item B<Values> I<OID> [I<OID> ...]
+
+Configures the values to be queried from the SNMP host. The meaning slightly
+changes with the B<Table> setting. L<variables(5)> from the SNMP distribution
+describes the format of OIDs.
+
+If B<Table> is set to I<true>, each I<OID> must be the prefix of all the
+values to query, e.E<nbsp>g. C<IF-MIB::ifInOctets> for all the counters of
+incoming traffic. This subtree is walked (using C<GETNEXT>) until a value from
+outside the subtree is returned.
+
+If B<Table> is set to I<false>, each I<OID> must be the OID of exactly one
+value, e.E<nbsp>g. C<IF-MIB::ifInOctets.3> for the third counter of incoming
+traffic.
+
+=back
+
+=head2 The Host block
+
+The B<Host> block defines which hosts to query, which SNMP community and
+version to use and which of the defined B<Data> to query.
+
+The argument passed to the B<Host> block is used as the hostname in the data
+stored by collectd.
+
+=over 4
+
+=item B<Address> I<IP-Address>|I<Hostname>
+
+Set the address to connect to.
+
+=item B<Version> B<1>|B<2>
+
+Set the SNMP version to use. When giving B<2> version 2c is actually used.
+Version 3 is not supported by this plugin.
+
+=item B<Community> I<Community>
+
+Pass I<Community> to the host.
+
+=item B<Collect> I<Data> [I<Data> ...]
+
+Defines which values to collect. I<Data> refers to one of the B<Data> block
+above. Since the config file is read top-down you need to define the data
+before using it here.
+
+=item B<Interval> I<Seconds>
+
+Collect data from this host every I<Seconds> seconds. This value needs to be a
+multiple of the global B<Interval> setting and, if it is not, will be rounded
+B<down> to one and a warning is logged in this case. So if your global
+B<Interval> is set to I<10> and you configure I<25> here, it's rounded down to
+I<20>. By default the global B<Interval> setting will be used.
+
+This option is meant for devices with not much CPU power, e.E<nbsp>g. network
+equipment such as switches, embedded devices, rack monitoring systems and so
+on. Since the B<Step> of generated RRD files depends on this setting it's
+wise to select a reasonable value once and never change it.
+
+=back
+
+=head1 BUGS
+
+All configured hosts are queried sequencially, so timeouts may cause gaps in
+graphs.
+
+=head1 SEE ALSO
+
+L<collectd(1)>,
+L<collectd.conf(5)>,
+L<snmpget(1)>,
+L<snmpgetnext(1)>,
+L<variables(5)>,
+L<unix(7)>
+
+=head1 AUTHOR
+
+Florian Forster E<lt>octo@verplant.orgE<gt>
+
+=cut
index 7c0e316..da4f2b2 100644 (file)
@@ -50,6 +50,25 @@ Example:
   -> | GETVAL myhost/cpu-0/cpu-user
   <- | 1 value=1.260000e+00
 
+=item B<LISTVAL>
+
+Returnes a list of the values available in the value cache together with the
+time of the last update, so that querying applications can issue a B<GETVAL>
+command for the values that have changed.
+
+The first line's status number is the number of identifiers returned or less
+than zero if an error occured. Each of the following lines containes the
+update time as an epoch value and the identifier, seperated by a space.
+
+Example:
+  -> | LISTVAL
+  <- | 69 Values found
+  <- | 1182204284 leeloo/cpu-0/cpu-idle
+  <- | 1182204284 leeloo/cpu-0/cpu-nice
+  <- | 1182204284 leeloo/cpu-0/cpu-system
+  <- | 1182204284 leeloo/cpu-0/cpu-user
+  ...
+
 =item B<PUTVAL> I<Identifier> I<Valuelist>
 
 Submits a value (identified by I<Identifier>, see below) to the daemon which
index 94c60ee..780d04d 100644 (file)
 #Interval     10
 #ReadThreads  5
 
-@BUILD_MODULE_APACHE_TRUE@LoadPlugin apache
-@BUILD_MODULE_APCUPS_TRUE@LoadPlugin apcups
-@BUILD_MODULE_APPLE_SENSORS_TRUE@LoadPlugin apple_sensors
-@BUILD_MODULE_BATTERY_TRUE@LoadPlugin battery
-@BUILD_MODULE_CPU_TRUE@LoadPlugin cpu
-@BUILD_MODULE_CPUFREQ_TRUE@LoadPlugin cpufreq
-@BUILD_MODULE_CSV_TRUE@LoadPlugin csv
-@BUILD_MODULE_DF_TRUE@LoadPlugin df
-@BUILD_MODULE_DISK_TRUE@LoadPlugin disk
-@BUILD_MODULE_DNS_TRUE@LoadPlugin dns
-@BUILD_MODULE_EMAIL_TRUE@LoadPlugin email
-@BUILD_MODULE_ENTROPY_TRUE@LoadPlugin entropy
-@BUILD_MODULE_EXEC_TRUE@LoadPlugin exec
-@BUILD_MODULE_HDDTEMP_TRUE@LoadPlugin hddtemp
-@BUILD_MODULE_INTERFACE_TRUE@LoadPlugin interface
-@BUILD_MODULE_IPTABLES_TRUE@LoadPlugin iptables
-@BUILD_MODULE_IRQ_TRUE@LoadPlugin irq
-@BUILD_MODULE_LOAD_TRUE@LoadPlugin load
-@BUILD_MODULE_LOGFILE_TRUE@LoadPlugin logfile
-@BUILD_MODULE_MBMON_TRUE@LoadPlugin mbmon
-@BUILD_MODULE_MEMORY_TRUE@LoadPlugin memory
-@BUILD_MODULE_MULTIMETER_TRUE@LoadPlugin multimeter
-@BUILD_MODULE_MYSQL_TRUE@LoadPlugin mysql
-@BUILD_MODULE_NETWORK_TRUE@LoadPlugin network
-@BUILD_MODULE_NFS_TRUE@LoadPlugin nfs
-@BUILD_MODULE_NTPD_TRUE@LoadPlugin ntpd
-@BUILD_MODULE_NUT_TRUE@LoadPlugin nut
-@BUILD_MODULE_PERL_TRUE@LoadPlugin perl
-@BUILD_MODULE_PING_TRUE@LoadPlugin ping
-@BUILD_MODULE_PROCESSES_TRUE@LoadPlugin processes
-@BUILD_WITH_RRDTOOL_TRUE@LoadPlugin rrdtool
-@BUILD_MODULE_SENSORS_TRUE@LoadPlugin sensors
-@BUILD_MODULE_SERIAL_TRUE@LoadPlugin serial
-@BUILD_MODULE_SWAP_TRUE@LoadPlugin swap
-@BUILD_MODULE_SYSLOG_TRUE@LoadPlugin syslog
-@BUILD_MODULE_TAPE_TRUE@LoadPlugin tape
-@BUILD_MODULE_UNIXSOCK_TRUE@LoadPlugin unixsock
-@BUILD_MODULE_USERS_TRUE@LoadPlugin users
-@BUILD_MODULE_VSERVER_TRUE@LoadPlugin vserver
-@BUILD_MODULE_WIRELESS_TRUE@LoadPlugin wireless
+@BUILD_PLUGIN_APACHE_TRUE@LoadPlugin apache
+@BUILD_PLUGIN_APCUPS_TRUE@LoadPlugin apcups
+@BUILD_PLUGIN_APPLE_SENSORS_TRUE@LoadPlugin apple_sensors
+@BUILD_PLUGIN_BATTERY_TRUE@LoadPlugin battery
+@BUILD_PLUGIN_CPU_TRUE@LoadPlugin cpu
+@BUILD_PLUGIN_CPUFREQ_TRUE@LoadPlugin cpufreq
+@BUILD_PLUGIN_CSV_TRUE@LoadPlugin csv
+@BUILD_PLUGIN_DF_TRUE@LoadPlugin df
+@BUILD_PLUGIN_DISK_TRUE@LoadPlugin disk
+@BUILD_PLUGIN_DNS_TRUE@LoadPlugin dns
+@BUILD_PLUGIN_EMAIL_TRUE@LoadPlugin email
+@BUILD_PLUGIN_ENTROPY_TRUE@LoadPlugin entropy
+@BUILD_PLUGIN_EXEC_TRUE@LoadPlugin exec
+@BUILD_PLUGIN_HDDTEMP_TRUE@LoadPlugin hddtemp
+@BUILD_PLUGIN_INTERFACE_TRUE@LoadPlugin interface
+@BUILD_PLUGIN_IPTABLES_TRUE@LoadPlugin iptables
+@BUILD_PLUGIN_IRQ_TRUE@LoadPlugin irq
+@BUILD_PLUGIN_LOAD_TRUE@LoadPlugin load
+@BUILD_PLUGIN_LOGFILE_TRUE@LoadPlugin logfile
+@BUILD_PLUGIN_MBMON_TRUE@LoadPlugin mbmon
+@BUILD_PLUGIN_MEMORY_TRUE@LoadPlugin memory
+@BUILD_PLUGIN_MULTIMETER_TRUE@LoadPlugin multimeter
+@BUILD_PLUGIN_MYSQL_TRUE@LoadPlugin mysql
+@BUILD_PLUGIN_NETWORK_TRUE@LoadPlugin network
+@BUILD_PLUGIN_NFS_TRUE@LoadPlugin nfs
+@BUILD_PLUGIN_NTPD_TRUE@LoadPlugin ntpd
+@BUILD_PLUGIN_NUT_TRUE@LoadPlugin nut
+@BUILD_PLUGIN_PERL_TRUE@LoadPlugin perl
+@BUILD_PLUGIN_PING_TRUE@LoadPlugin ping
+@BUILD_PLUGIN_PROCESSES_TRUE@LoadPlugin processes
+@BUILD_PLUGIN_RRDTOOL_TRUE@LoadPlugin rrdtool
+@BUILD_PLUGIN_SENSORS_TRUE@LoadPlugin sensors
+@BUILD_PLUGIN_SERIAL_TRUE@LoadPlugin serial
+@BUILD_PLUGIN_SWAP_TRUE@LoadPlugin swap
+@BUILD_PLUGIN_SYSLOG_TRUE@LoadPlugin syslog
+@BUILD_PLUGIN_TAPE_TRUE@LoadPlugin tape
+@BUILD_PLUGIN_UNIXSOCK_TRUE@LoadPlugin unixsock
+@BUILD_PLUGIN_USERS_TRUE@LoadPlugin users
+@BUILD_PLUGIN_VSERVER_TRUE@LoadPlugin vserver
+@BUILD_PLUGIN_WIRELESS_TRUE@LoadPlugin wireless
 
 #<Plugin apache>
 #      URL "http://localhost/status?auto"
index f7c10ad..d6de96e 100644 (file)
@@ -214,6 +214,10 @@ Ignore packets that originate from this address.
 
 =over 4
 
+=item B<SocketFile> I<Path>
+
+Sets the socket-file which is to be created.
+
 =item B<SocketGroup> I<Group>
 
 If running as root change the group of the UNIX-socket after it has been 
index ac75516..282e632 100644 (file)
 #define CONFIGFILE SYSCONFDIR"/collectd.conf"
 #endif
 
+#ifndef LOCALSTATEDIR
+#define LOCALSTATEDIR PREFIX "/var"
+#endif
+
 #ifndef PKGLOCALSTATEDIR
 #define PKGLOCALSTATEDIR PREFIX "/var/lib/" PACKAGE_NAME
 #endif
index 4b6803e..f4e9c60 100644 (file)
@@ -42,6 +42,13 @@ typedef struct cf_callback
        struct cf_callback *next;
 } cf_callback_t;
 
+typedef struct cf_complex_callback_s
+{
+       char *type;
+       int (*callback) (oconfig_item_t *);
+       struct cf_complex_callback_s *next;
+} cf_complex_callback_t;
+
 typedef struct cf_value_map_s
 {
        char *key;
@@ -65,6 +72,7 @@ static int dispatch_value_loadplugin (const oconfig_item_t *ci);
  * Private variables
  */
 static cf_callback_t *first_callback = NULL;
+static cf_complex_callback_t *complex_callback_head = NULL;
 
 static cf_value_map_t cf_value_map[] =
 {
@@ -257,21 +265,29 @@ static int dispatch_block_plugin (oconfig_item_t *ci)
        int i;
        char *name;
 
+       cf_complex_callback_t *cb;
+
        if (strcasecmp (ci->key, "Plugin") != 0)
                return (-1);
-       if (ci->values_num != 1)
+       if (ci->values_num < 1)
                return (-1);
        if (ci->values[0].type != OCONFIG_TYPE_STRING)
                return (-1);
 
        name = ci->values[0].value.string;
 
+       /* Check for a complex callback first */
+       for (cb = complex_callback_head; cb != NULL; cb = cb->next)
+               if (strcasecmp (name, cb->type) == 0)
+                       return (cb->callback (ci));
+
+       /* Hm, no complex plugin found. Dispatch the values one by one */
        for (i = 0; i < ci->children_num; i++)
        {
                if (ci->children[i].children == NULL)
                        dispatch_value_plugin (name, ci->children + i);
                else
-                       {DEBUG ("No nested config blocks allow for plugins. Yet.");}
+                       {DEBUG ("No nested config blocks allow for this plugin.");}
        }
 
        return (0);
@@ -347,6 +363,26 @@ void cf_unregister (const char *type)
                }
 } /* void cf_unregister */
 
+void cf_unregister_complex (const char *type)
+{
+       cf_complex_callback_t *this, *prev;
+
+       for (prev = NULL, this = complex_callback_head;
+                       this != NULL;
+                       prev = this, this = this->next)
+               if (strcasecmp (this->type, type) == 0)
+               {
+                       if (prev == NULL)
+                               complex_callback_head = this->next;
+                       else
+                               prev->next = this->next;
+
+                       sfree (this->type);
+                       sfree (this);
+                       break;
+               }
+} /* void cf_unregister */
+
 void cf_register (const char *type,
                int (*callback) (const char *, const char *),
                const char **keys, int keys_num)
@@ -369,6 +405,39 @@ void cf_register (const char *type,
        first_callback = cf_cb;
 } /* void cf_register */
 
+int cf_register_complex (const char *type, int (*callback) (oconfig_item_t *))
+{
+       cf_complex_callback_t *new;
+
+       new = (cf_complex_callback_t *) malloc (sizeof (cf_complex_callback_t));
+       if (new == NULL)
+               return (-1);
+
+       new->type = strdup (type);
+       if (new->type == NULL)
+       {
+               sfree (new);
+               return (-1);
+       }
+
+       new->callback = callback;
+       new->next = NULL;
+
+       if (complex_callback_head == NULL)
+       {
+               complex_callback_head = new;
+       }
+       else
+       {
+               cf_complex_callback_t *last = complex_callback_head;
+               while (last->next != NULL)
+                       last = last->next;
+               last->next = new;
+       }
+
+       return (0);
+} /* int cf_register_complex */
+
 int cf_read (char *filename)
 {
        oconfig_item_t *conf;
index 0ee8f33..3952c18 100644 (file)
@@ -1,3 +1,5 @@
+#ifndef CONFIGFILE_H
+#define CONFIGFILE_H
 /**
  * collectd - src/configfile.h
  * Copyright (C) 2005,2006  Florian octo Forster
@@ -20,8 +22,8 @@
  *   Florian octo Forster <octo at verplant.org>
  **/
 
-#ifndef CONFIGFILE_H
-#define CONFIGFILE_H
+#include "collectd.h"
+#include "liboconfig/oconfig.h"
 
 /*
  * DESCRIPTION
@@ -32,6 +34,7 @@
  *              `plugin_register'
  */
 void cf_unregister (const char *type);
+void cf_unregister_complex (const char *type);
 
 /*
  * DESCRIPTION
@@ -61,6 +64,8 @@ void cf_register (const char *type,
                int (*callback) (const char *, const char *),
                const char **keys, int keys_num);
 
+int cf_register_complex (const char *type, int (*callback) (oconfig_item_t *));
+
 /*
  * DESCRIPTION
  *  `cf_read' reads the config file `filename' and dispatches the read
index cbdde1e..ba0c1b1 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
 # endif
 #endif /* HAVE_SYSCTLBYNAME */
 
-#if defined(PROCESSOR_CPU_LOAD_INFO) || defined(KERNEL_LINUX) || defined(HAVE_LIBKSTAT) || defined(HAVE_SYSCTLBYNAME)
-# define CPU_HAVE_READ 1
-#else
-# define CPU_HAVE_READ 0
+#if !PROCESSOR_CPU_LOAD_INFO && !KERNEL_LINUX && !HAVE_LIBKSTAT && !HAVE_SYSCTLBYNAME
+# error "No applicable input method."
 #endif
 
-#if CPU_HAVE_READ
 #ifdef PROCESSOR_CPU_LOAD_INFO
 static mach_port_t port_host;
 static processor_port_array_t cpu_list;
@@ -389,12 +386,9 @@ static int cpu_read (void)
 
        return (0);
 }
-#endif /* CPU_HAVE_READ */
 
 void module_register (void)
 {
-#if CPU_HAVE_READ
        plugin_register_init ("cpu", init);
        plugin_register_read ("cpu", cpu_read);
-#endif /* CPU_HAVE_READ */
 } /* void module_register */
index 7a5c8fd..b1037c3 100644 (file)
 
 #define MODULE_NAME "cpufreq"
 
-#if defined(KERNEL_LINUX)
-# define CPUFREQ_HAVE_READ 1
-#else
-# define CPUFREQ_HAVE_READ 0
-#endif
-
-#if CPUFREQ_HAVE_READ
-#ifdef KERNEL_LINUX
 static int num_cpu = 0;
-#endif
 
 static int cpufreq_init (void)
 {
-#ifdef KERNEL_LINUX
         int status;
        char filename[256];
 
@@ -64,7 +54,6 @@ static int cpufreq_init (void)
 
        if (num_cpu == 0)
                plugin_unregister_read ("cpufreq");
-#endif /* defined(KERNEL_LINUX) */
 
        return (0);
 } /* int cpufreq_init */
@@ -89,7 +78,6 @@ static void cpufreq_submit (int cpu_num, double value)
 
 static int cpufreq_read (void)
 {
-#ifdef KERNEL_LINUX
         int status;
        unsigned long long val;
        int i = 0;
@@ -138,17 +126,12 @@ static int cpufreq_read (void)
 
                cpufreq_submit (i, val);
        }
-#endif /* defined(KERNEL_LINUX) */
 
        return (0);
 } /* int cpufreq_read */
-#endif /* CPUFREQ_HAVE_READ */
-#undef BUFSIZE
 
 void module_register (void)
 {
-#if CPUFREQ_HAVE_READ
        plugin_register_init ("cpufreq", cpufreq_init);
        plugin_register_read ("cpufreq", cpufreq_read);
-#endif /* CPUFREQ_HAVE_READ */
 }
index 433f4e2..0f357d8 100644 (file)
--- a/src/df.c
+++ b/src/df.c
 #include "utils_mount.h"
 #include "utils_ignorelist.h"
 
-#if HAVE_STATFS || HAVE_STATVFS
-# define DF_HAVE_READ 1
-#else
-# define DF_HAVE_READ 0
-#endif
-
 #if HAVE_STATVFS
 # if HAVE_SYS_STATVFS_H
 #  include <sys/statvfs.h>
 # endif
 # define STATANYFS statfs
 # define BLOCKSIZE(s) (s).f_bsize
+#else
+# error "No applicable input method."
 #endif
 
-#if DF_HAVE_READ
 static const char *config_keys[] =
 {
        "Device",
@@ -209,14 +204,11 @@ static int df_read (void)
 
        return (0);
 } /* int df_read */
-#endif /* DF_HAVE_READ */
 
 void module_register (void)
 {
-#if DF_HAVE_READ
        plugin_register_config ("df", df_config,
                        config_keys, config_keys_num);
        plugin_register_init ("df", df_init);
        plugin_register_read ("df", df_read);
-#endif
 } /* void module_register */
index 38c161f..490da07 100644 (file)
 #  define UINT_MAX 4294967295U
 #endif
 
-#if HAVE_IOKIT_IOKITLIB_H || KERNEL_LINUX || HAVE_LIBKSTAT
-# define DISK_HAVE_READ 1
-#else
-# define DISK_HAVE_READ 0
-#endif
-
-#if DISK_HAVE_READ
 #if HAVE_IOKIT_IOKITLIB_H
 static mach_port_t io_master_port = MACH_PORT_NULL;
 /* #endif HAVE_IOKIT_IOKITLIB_H */
@@ -102,7 +95,11 @@ static diskstats_t *disklist;
 extern kstat_ctl_t *kc;
 static kstat_t *ksp[MAX_NUMDISK];
 static int numdisk = 0;
-#endif /* HAVE_LIBKSTAT */
+/* #endif HAVE_LIBKSTAT */
+
+#else
+# error "No applicable input method."
+#endif
 
 static int disk_init (void)
 {
@@ -639,12 +636,9 @@ static int disk_read (void)
 
        return (0);
 } /* int disk_read */
-#endif /* DISK_HAVE_READ */
 
 void module_register (void)
 {
-#if DISK_HAVE_READ
        plugin_register_init ("disk", disk_init);
        plugin_register_read ("disk", disk_read);
-#endif /* DISK_HAVE_READ */
 } /* void module_register */
index 7ce7aad..2cbd0c3 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
 #include "plugin.h"
 #include "configfile.h"
 
-#if HAVE_LIBPCAP && HAVE_LIBPTHREAD
-# include "utils_dns.h"
-# include <pthread.h>
-# include <pcap.h>
-# include <poll.h>
-# define DNS_HAVE_READ 1
-#else
-# define DNS_HAVE_READ 0
-#endif
+#include "utils_dns.h"
+#include <pthread.h>
+#include <pcap.h>
+#include <poll.h>
 
 /*
  * Private data types
  */
-#if DNS_HAVE_READ
 struct counter_list_s
 {
        unsigned int key;
@@ -45,12 +39,10 @@ struct counter_list_s
        struct counter_list_s *next;
 };
 typedef struct counter_list_s counter_list_t;
-#endif
 
 /*
  * Private variables
  */
-#if DNS_HAVE_READ
 static const char *config_keys[] =
 {
        "Interface",
@@ -75,12 +67,10 @@ static pthread_mutex_t traffic_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t qtype_mutex   = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t opcode_mutex  = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t rcode_mutex   = PTHREAD_MUTEX_INITIALIZER;
-#endif /* DNS_HAVE_READ */
 
 /*
  * Private functions
  */
-#if DNS_HAVE_READ
 static counter_list_t *counter_list_search (counter_list_t **list, unsigned int key)
 {
        counter_list_t *entry;
@@ -402,13 +392,10 @@ static int dns_read (void)
 
        return (0);
 } /* int dns_read */
-#endif
 
 void module_register (void)
 {
-#if DNS_HAVE_READ
        plugin_register_config ("dns", dns_config, config_keys, config_keys_num);
        plugin_register_init ("dns", dns_init);
        plugin_register_read ("dns", dns_read);
-#endif
 } /* void module_register */
index 594ef96..f5a544a 100644 (file)
 /* 256 bytes ought to be enough for anybody ;-) */
 #define BUFSIZE 256
 
-#ifndef COLLECTD_SOCKET_PREFIX
-# define COLLECTD_SOCKET_PREFIX "/tmp/.collectd-"
-#endif /* COLLECTD_SOCKET_PREFIX */
-
-#define SOCK_PATH COLLECTD_SOCKET_PREFIX"email"
+#define SOCK_PATH LOCALSTATEDIR"/run/"PACKAGE_NAME"-email"
 #define MAX_CONNS 5
 #define MAX_CONNS_LIMIT 16384
 
@@ -119,6 +115,7 @@ typedef struct {
 /* valid configuration file keys */
 static const char *config_keys[] =
 {
+       "SocketFile",
        "SocketGroup",
        "SocketPerms",
        "MaxConns"
@@ -126,6 +123,7 @@ static const char *config_keys[] =
 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
 
 /* socket configuration */
+static char *sock_file  = SOCK_PATH;
 static char *sock_group = COLLECTD_GRP_NAME;
 static int  sock_perms  = S_IRWXU | S_IRWXG;
 static int  max_conns   = MAX_CONNS;
@@ -171,7 +169,10 @@ static type_list_t check;
  */
 static int email_config (const char *key, const char *value)
 {
-       if (0 == strcasecmp (key, "SocketGroup")) {
+       if (0 == strcasecmp (key, "SocketFile")) {
+               sock_file = sstrdup (value);
+       }
+       else if (0 == strcasecmp (key, "SocketGroup")) {
                sock_group = sstrdup (value);
        }
        else if (0 == strcasecmp (key, "SocketPerms")) {
@@ -508,7 +509,7 @@ static void *open_connection (void *arg)
 
        addr.sun_family = AF_UNIX;
 
-       strncpy (addr.sun_path, SOCK_PATH, (size_t)(UNIX_PATH_MAX - 1));
+       strncpy (addr.sun_path, sock_file, (size_t)(UNIX_PATH_MAX - 1));
        addr.sun_path[UNIX_PATH_MAX - 1] = '\0';
        unlink (addr.sun_path);
 
@@ -555,12 +556,12 @@ static void *open_connection (void *arg)
                }
                else
                {
-                       status = chown (SOCK_PATH, (uid_t) -1, grp->gr_gid);
+                       status = chown (sock_file, (uid_t) -1, grp->gr_gid);
                        if (status != 0)
                        {
                                char errbuf[1024];
                                log_warn ("chown (%s, -1, %i) failed: %s",
-                                               SOCK_PATH, (int) grp->gr_gid,
+                                               sock_file, (int) grp->gr_gid,
                                                sstrerror (errno, errbuf, sizeof (errbuf)));
                        }
                }
@@ -571,7 +572,7 @@ static void *open_connection (void *arg)
        }
 
        errno = 0;
-       if (0 != chmod (SOCK_PATH, sock_perms)) {
+       if (0 != chmod (sock_file, sock_perms)) {
                char errbuf[1024];
                log_warn ("chmod() failed: %s",
                                sstrerror (errno, errbuf, sizeof (errbuf)));
@@ -714,7 +715,7 @@ static int email_shutdown (void)
 
        pthread_mutex_unlock (&conns_mutex);
 
-       unlink (SOCK_PATH);
+       unlink (sock_file);
        errno = 0;
 
        return (0);
index 7e90395..5f9eb53 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * collectd - src/entropy.c
- * Copyright (C) 2005,2006  Florian octo Forster
+ * Copyright (C) 2007  Florian octo Forster
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
 #include "common.h"
 #include "plugin.h"
 
-#if KERNEL_LINUX
-# define ENTROPY_HAVE_READ 1
-#else
-# define ENTROPY_HAVE_READ 0
+#if !KERNEL_LINUX
+# error "No applicable input method."
 #endif
 
 #define ENTROPY_FILE "/proc/sys/kernel/random/entropy_avail"
 
-#if ENTROPY_HAVE_READ
 static void entropy_submit (double entropy)
 {
        value_t values[1];
@@ -52,7 +49,6 @@ static void entropy_submit (double entropy)
 
 static int entropy_read (void)
 {
-#if KERNEL_LINUX
        double entropy;
        FILE *fh;
        char buffer[64];
@@ -72,15 +68,11 @@ static int entropy_read (void)
        
        if (entropy > 0.0)
                entropy_submit (entropy);
-#endif /* KERNEL_LINUX */
 
        return (0);
 }
-#endif /* ENTROPY_HAVE_READ */
 
 void module_register (void)
 {
-#if ENTROPY_HAVE_READ
        plugin_register_read ("entropy", entropy_read);
-#endif
 } /* void module_register */
index c777465..0432de7 100644 (file)
 #include "plugin.h"
 #include "configfile.h"
 
-#if HAVE_NETDB_H && HAVE_SYS_SOCKET_H && HAVE_NETINET_IN_H \
-       && HAVE_NETINET_TCP_H && HAVE_LIBGEN_H
 # include <netdb.h>
 # include <sys/socket.h>
 # include <netinet/in.h>
 # include <netinet/tcp.h>
 # include <libgen.h> /* for basename */
-# define HDDTEMP_HAVE_READ 1
-#else
-# define HDDTEMP_HAVE_READ 0
-#endif
 
 #if HAVE_LINUX_MAJOR_H
 # include <linux/major.h>
@@ -50,7 +44,6 @@
 #define HDDTEMP_DEF_HOST "127.0.0.1"
 #define HDDTEMP_DEF_PORT "7634"
 
-#if HDDTEMP_HAVE_READ
 static const char *config_keys[] =
 {
        "Host",
@@ -507,16 +500,13 @@ static int hddtemp_read (void)
        
        return (0);
 } /* int hddtemp_read */
-#endif /* HDDTEMP_HAVE_READ */
 
 /* module_register
    Register collectd plugin. */
 void module_register (void)
 {
-#if HDDTEMP_HAVE_READ
        plugin_register_config ("hddtemp", hddtemp_config,
                        config_keys, config_keys_num);
        plugin_register_init ("hddtemp", hddtemp_init);
        plugin_register_read ("hddtemp", hddtemp_read);
-#endif /* HDDTEMP_HAVE_READ */
 }
index 52b2ddf..741ff76 100644 (file)
 # endif /* !COLLECT_GETIFADDRS */
 #endif /* KERNEL_LINUX */
 
-#if HAVE_GETIFADDRS || KERNEL_LINUX || HAVE_LIBKSTAT || HAVE_LIBSTATGRAB
-# define INTERFACE_HAVE_READ 1
-#else
-# define INTERFACE_HAVE_READ 0
+#if !HAVE_GETIFADDRS && !KERNEL_LINUX && !HAVE_LIBKSTAT && !HAVE_LIBSTATGRAB
+# error "No applicable input method."
 #endif
 
 /*
@@ -132,7 +130,6 @@ static int interface_config (const char *key, const char *value)
 #if HAVE_LIBKSTAT
 static int interface_init (void)
 {
-#if HAVE_LIBKSTAT
        kstat_t *ksp_chain;
        unsigned long long val;
 
@@ -155,7 +152,6 @@ static int interface_init (void)
                        continue;
                ksp[numif++] = ksp_chain;
        }
-#endif /* HAVE_LIBKSTAT */
 
        return (0);
 } /* int interface_init */
@@ -181,7 +177,6 @@ static int check_ignore_if (const char *interface)
        return (1 - if_list_action);
 } /* int check_ignore_if */
 
-#if INTERFACE_HAVE_READ
 static void if_submit (const char *dev, const char *type,
                unsigned long long rx,
                unsigned long long tx)
@@ -353,7 +348,6 @@ static int interface_read (void)
 
        return (0);
 } /* int interface_read */
-#endif /* INTERFACE_HAVE_READ */
 
 void module_register (void)
 {
@@ -362,7 +356,5 @@ void module_register (void)
 #if HAVE_LIBKSTAT
        plugin_register_init ("interface", interface_init);
 #endif
-#if INTERFACE_HAVE_READ
        plugin_register_read ("interface", interface_read);
-#endif
 } /* void module_register */
index 8dc5710..5fa1f40 100644 (file)
 # include <libiptc/libiptc.h>
 #endif
 
-#if HAVE_LIBIPTC_LIBIPTC_H
-# define IPTABLES_HAVE_READ 1
-#else
-# define IPTABLES_HAVE_READ 0
-#endif
-
-#define MODULE_NAME "iptables"
-#define BUFSIZE 512
-
 /*
  * (Module-)Global variables
  */
 
 /*
- * Removed packet count for now, should have config option if you want to save
- * them Although other collectd models don't seem to care much for options
- * eitherway for what to log
- */
-#if IPTABLES_HAVE_READ
-/*
  * Config format should be `Chain table chainname',
  * e. g. `Chain mangle incoming'
  */
@@ -205,9 +190,7 @@ static int iptables_config (const char *key, const char *value)
 
        return (0);
 } /* int iptables_config */
-#endif /* IPTABLES_HAVE_READ */
 
-#if IPTABLES_HAVE_READ
 /* This needs to return `int' for IPT_MATCH_ITERATE to work. */
 static int submit_match (const struct ipt_entry_match *match,
                const struct ipt_entry *entry,
@@ -350,21 +333,15 @@ static int iptables_shutdown (void)
 
     return (0);
 } /* int iptables_shutdown */
-#endif /* IPTABLES_HAVE_READ */
 
 void module_register (void)
 {
-#if IPTABLES_HAVE_READ
     plugin_register_config ("iptables", iptables_config,
            config_keys, config_keys_num);
     plugin_register_read ("iptables", iptables_read);
     plugin_register_shutdown ("iptables", iptables_shutdown);
-#endif
 } /* void module_register */
 
-#undef BUFSIZE
-#undef MODULE_NAME
-
 /*
  * vim:shiftwidth=4:softtabstop=4:tabstop=8
  */
index 1c7b5ae..b6b8c4c 100644 (file)
--- a/src/irq.c
+++ b/src/irq.c
 #include "plugin.h"
 #include "configfile.h"
 
-#if KERNEL_LINUX
-# define IRQ_HAVE_READ 1
-#else
-# define IRQ_HAVE_READ 0
+#if !KERNEL_LINUX
+# error "No applicable input method."
 #endif
 
 #define BUFSIZE 128
@@ -36,7 +34,6 @@
 /*
  * (Module-)Global variables
  */
-#if IRQ_HAVE_READ
 static const char *config_keys[] =
 {
        "Irq",
@@ -148,8 +145,6 @@ static void irq_submit (unsigned int irq, counter_t value)
 
 static int irq_read (void)
 {
-#if KERNEL_LINUX
-
 #undef BUFSIZE
 #define BUFSIZE 256
 
@@ -198,19 +193,15 @@ static int irq_read (void)
                irq_submit (irq, irq_value);
        }
        fclose (fh);
-#endif /* KERNEL_LINUX */
 
        return (0);
 } /* int irq_read */
-#endif /* IRQ_HAVE_READ */
 
 void module_register (void)
 {
-#if IRQ_HAVE_READ
        plugin_register_config ("irq", irq_config,
                        config_keys, config_keys_num);
        plugin_register_read ("irq", irq_read);
-#endif /* IRQ_HAVE_READ */
 } /* void module_register */
 
 #undef BUFSIZE
index 22872f0..c9f130b 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * collectd - src/load.c
- * Copyright (C) 2005,2006  Florian octo Forster
+ * Copyright (C) 2005-2007  Florian octo Forster
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
 #include "common.h"
 #include "plugin.h"
 
-#if defined(HAVE_GETLOADAVG) || defined(KERNEL_LINUX) || defined(HAVE_LIBSTATGRAB)
-# define LOAD_HAVE_READ 1
-#else
-# define LOAD_HAVE_READ 0
-#endif
-
 #ifdef HAVE_SYS_LOADAVG_H
 #include <sys/loadavg.h>
 #endif
@@ -41,7 +35,6 @@
 #endif
 #endif /* defined(HAVE_GETLOADAVG) */
 
-#if LOAD_HAVE_READ
 static void load_submit (gauge_t snum, gauge_t mnum, gauge_t lnum)
 {
        value_t values[3];
@@ -131,15 +124,16 @@ static int load_read (void)
        lnum = ls->min15;
 
        load_submit (snum, mnum, lnum);
-#endif /* HAVE_LIBSTATGRAB */
+/* #endif HAVE_LIBSTATGRAB */
+
+#else
+# error "No applicable input method."
+#endif
 
        return (0);
 }
-#endif /* LOAD_HAVE_READ */
 
 void module_register (void)
 {
-#if LOAD_HAVE_READ
        plugin_register_read ("load", load_read);
-#endif
 } /* void module_register */
index 7694abc..384ecb5 100644 (file)
 #include "plugin.h"
 #include "configfile.h"
 
-#if HAVE_NETDB_H && HAVE_SYS_SOCKET_H && HAVE_NETINET_IN_H && HAVE_NETINET_TCP_H
-# include <netdb.h>
-# include <sys/socket.h>
-# include <netinet/in.h>
-# include <netinet/tcp.h>
-# define MBMON_HAVE_READ 1
-#else
-# define MBMON_HAVE_READ 0
-#endif
+#include <netdb.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
 
 #define MBMON_DEF_HOST "127.0.0.1"
 #define MBMON_DEF_PORT "411" /* the default for Debian */
@@ -47,7 +42,6 @@ static const char *config_keys[] =
 };
 static int config_keys_num = 2;
 
-#if MBMON_HAVE_READ
 static char *mbmon_host = NULL;
 static char *mbmon_port = NULL;
 
@@ -308,14 +302,11 @@ static int mbmon_read (void)
 
        return (0);
 } /* void mbmon_read */
-#endif /* MBMON_HAVE_READ */
 
 /* module_register
    Register collectd plugin. */
 void module_register (void)
 {
-#if MBMON_HAVE_READ
        plugin_register_config ("mbmon", mbmon_config, config_keys, config_keys_num);
        plugin_register_read ("mbmon", mbmon_read);
-#endif /* MBMON_HAVE_READ */
 } /* void module_register */
index cb7e688..3fbd33f 100644 (file)
 # include <mach/vm_statistics.h>
 #endif
 
-#if defined (HOST_VM_INFO) || HAVE_SYSCTLBYNAME || KERNEL_LINUX || HAVE_LIBKSTAT
-# define MEMORY_HAVE_READ 1
-#else
-# define MEMORY_HAVE_READ 0
-#endif
-
 /* vm_statistics_data_t */
-#if defined(HOST_VM_INFO)
+#if HAVE_HOST_STATISTICS
 static mach_port_t port_host;
 static vm_size_t pagesize;
-/* #endif HOST_VM_INFO */
+/* #endif HAVE_HOST_STATISTICS */
 
 #elif HAVE_SYSCTLBYNAME
 /* no global variables */
@@ -66,15 +60,18 @@ static vm_size_t pagesize;
 #elif HAVE_LIBKSTAT
 static int pagesize;
 static kstat_t *ksp;
-#endif /* HAVE_LIBKSTAT */
+/* #endif HAVE_LIBKSTAT */
+
+#else
+# error "No applicable input method."
+#endif
 
-#if MEMORY_HAVE_READ
 static int memory_init (void)
 {
-#if defined(HOST_VM_INFO)
+#if HAVE_HOST_STATISTICS
        port_host = mach_host_self ();
        host_page_size (port_host, &pagesize);
-/* #endif HOST_VM_INFO */
+/* #endif HAVE_HOST_STATISTICS */
 
 #elif HAVE_SYSCTLBYNAME
 /* no init stuff */
@@ -114,7 +111,7 @@ static void memory_submit (const char *type_instance, gauge_t value)
 
 static int memory_read (void)
 {
-#if defined(HOST_VM_INFO)
+#if HAVE_HOST_STATISTICS
        kern_return_t status;
        vm_statistics_data_t   vm_data;
        mach_msg_type_number_t vm_data_len;
@@ -165,7 +162,7 @@ static int memory_read (void)
        memory_submit ("active",   active);
        memory_submit ("inactive", inactive);
        memory_submit ("free",     free);
-/* #endif HOST_VM_INFO */
+/* #endif HAVE_HOST_STATISTICS */
 
 #elif HAVE_SYSCTLBYNAME
        /*
@@ -321,12 +318,9 @@ static int memory_read (void)
 
        return (0);
 }
-#endif /* MEMORY_HAVE_READ */
 
 void module_register (void)
 {
-#if MEMORY_HAVE_READ
        plugin_register_init ("memory", memory_init);
        plugin_register_read ("memory", memory_read);
-#endif /* MEMORY_HAVE_READ */
 } /* void module_register */
index 21a2144..11ca42c 100644 (file)
 # include <termios.h>
 # include <sys/ioctl.h>
 # include <math.h>
-# define MULTIMETER_HAVE_READ 1
 #else
-# define MULTIMETER_HAVE_READ 0
-# error "multimeter cannot read!"
+# error "No applicable input method."
 #endif
 
-#if MULTIMETER_HAVE_READ
 static int fd = -1;
 
 static int multimeter_timeval_sub (struct timeval *tv1, struct timeval *tv2,
@@ -58,6 +55,7 @@ static int multimeter_timeval_sub (struct timeval *tv1, struct timeval *tv2,
         }
        return (0);
 }
+
 #define LINE_LENGTH 14
 static int multimeter_read_value(double *value)
 {
@@ -248,13 +246,10 @@ static int multimeter_shutdown (void)
 
        return (0);
 }
-#endif /* MULTIMETER_HAVE_READ */
 
 void module_register (void)
 {
-#if MULTIMETER_HAVE_READ
        plugin_register_init ("multimeter", multimeter_init);
        plugin_register_read ("multimeter", multimeter_read);
        plugin_register_shutdown ("multimeter", multimeter_shutdown);
-#endif /* MULTIMETER_HAVE_READ */
 } /* void module_register */
index fccaedb..d472853 100644 (file)
 #include <mysql/mysql.h>
 #endif
 
-#if COLLECT_LIBMYSQL
-# define MYSQL_HAVE_READ 1
-#else
-# define MYSQL_HAVE_READ 0
-#endif
-
 /* TODO: Understand `Select_*' and possibly do that stuff as well.. */
 
-#if MYSQL_HAVE_READ
 static const char *config_keys[] =
 {
        "Host",
@@ -322,12 +315,9 @@ static int mysql_read (void)
 
        return (0);
 } /* int mysql_read */
-#endif /* MYSQL_HAVE_READ */
 
 void module_register (void)
 {
-#if MYSQL_HAVE_READ
        plugin_register_config ("mysql", config, config_keys, config_keys_num);
        plugin_register_read ("mysql", mysql_read);
-#endif /* MYSQL_HAVE_READ */
 } /* void module_register */
index 34385bf..ad8d530 100644 (file)
@@ -162,7 +162,7 @@ static int listen_loop = 0;
 static char         send_buffer[BUFF_SIZE];
 static char        *send_buffer_ptr;
 static int          send_buffer_fill;
-static value_list_t send_buffer_vl = VALUE_LIST_INIT;
+static value_list_t send_buffer_vl = VALUE_LIST_STATIC;
 static char         send_buffer_type[DATA_MAX_NAME_LEN];
 static pthread_mutex_t send_buffer_lock = PTHREAD_MUTEX_INITIALIZER;
 
@@ -557,6 +557,13 @@ static int parse_packet (void *buffer, int buffer_len)
                        if (status == 0)
                                vl.time = (time_t) tmp;
                }
+               else if (ntohs (header->type) == TYPE_INTERVAL)
+               {
+                       uint64_t tmp = 0;
+                       status = parse_part_number (&buffer, &buffer_len, &tmp);
+                       if (status == 0)
+                               vl.interval = (int) tmp;
+               }
                else if (ntohs (header->type) == TYPE_HOST)
                {
                        status = parse_part_string (&buffer, &buffer_len,
@@ -1097,6 +1104,16 @@ static int add_to_buffer (char *buffer, int buffer_size,
                                (unsigned int) vl->time);
        }
 
+       if (vl_def->interval != vl->interval)
+       {
+               if (write_part_number (&buffer, &buffer_size, TYPE_INTERVAL,
+                                       (uint64_t) vl->interval))
+                       return (-1);
+               vl_def->interval = vl->interval;
+               DEBUG ("network plugin: add_to_buffer: interval = %i",
+                               (int) vl->interval);
+       }
+
        if (strcmp (vl_def->plugin, vl->plugin) != 0)
        {
                if (write_part_string (&buffer, &buffer_size, TYPE_PLUGIN,
index b20fc75..6d8e966 100644 (file)
@@ -61,5 +61,6 @@
 #define TYPE_TYPE            0x0004
 #define TYPE_TYPE_INSTANCE   0x0005
 #define TYPE_VALUES          0x0006
+#define TYPE_INTERVAL        0x0007
 
 #endif /* NETWORK_H */
index 299d63b..77c7f48 100644 (file)
--- a/src/nfs.c
+++ b/src/nfs.c
 #include "common.h"
 #include "plugin.h"
 
-/* #if defined(KERNEL_LINUX) || defined(HAVE_LIBKSTAT) */
-#if KERNEL_LINUX
-# define NFS_HAVE_READ 1
-#else
-# define NFS_HAVE_READ 0
+#if !KERNEL_LINUX
+# error "No applicable input method."
 #endif
 
 /*
@@ -76,7 +73,6 @@ Number      Procedures  Procedures
 21                      commit
 */
 
-#if NFS_HAVE_READ
 static const char *nfs2_procedures_names[] =
 {
        "null",
@@ -209,7 +205,6 @@ static void nfs_procedures_submit (const char *plugin_instance,
        }
 } /* void nfs_procedures_submit */
 
-#if KERNEL_LINUX
 static void nfs_read_stats_file (FILE *fh, char *inst)
 {
        char buffer[BUFSIZE];
@@ -307,7 +302,6 @@ static void nfs_read_stats_file (FILE *fh, char *inst)
                }
        } /* while (fgets (buffer, BUFSIZE, fh) != NULL) */
 } /* void nfs_read_stats_file */
-#endif /* defined(KERNEL_LINUX) */
 #undef BUFSIZE
 
 #if HAVE_LIBKSTAT && 0
@@ -340,7 +334,6 @@ static void nfs2_read_kstat (kstat_t *ksp, char *inst)
 
 static int nfs_read (void)
 {
-#if KERNEL_LINUX
        FILE *fh;
 
        if ((fh = fopen ("/proc/net/rpc/nfs", "r")) != NULL)
@@ -355,9 +348,7 @@ static int nfs_read (void)
                fclose (fh);
        }
 
-/* #endif defined(KERNEL_LINUX) */
-
-#elif HAVE_LIBKSTAT && 0
+#if HAVE_LIBKSTAT && 0
        if (nfs2_ksp_client != NULL)
                nfs2_read_kstat (nfs2_ksp_client, "client");
        if (nfs2_ksp_server != NULL)
@@ -366,11 +357,8 @@ static int nfs_read (void)
 
        return (0);
 }
-#endif /* NFS_HAVE_READ */
 
 void module_register (void)
 {
-#if NFS_HAVE_READ
        plugin_register_read ("nfs", nfs_read);
-#endif
 } /* void module_register */
index 23daacd..fe3576c 100644 (file)
 #include "plugin.h"
 #include "configfile.h"
 
-#if HAVE_SYS_SOCKET_H
-# define NTPD_HAVE_READ 1
-#else
-# define NTPD_HAVE_READ 0
-#endif
-
 #if HAVE_STDINT_H
 # include <stdint.h>
 #endif
@@ -60,7 +54,6 @@ static const char *config_keys[] =
 };
 static int config_keys_num = 2;
 
-#if NTPD_HAVE_READ
 # define NTPD_DEFAULT_HOST "localhost"
 # define NTPD_DEFAULT_PORT "123"
 static int   sock_descr = -1;
@@ -959,13 +952,10 @@ static int ntpd_read (void)
 
        return (0);
 } /* int ntpd_read */
-#endif /* NTPD_HAVE_READ */
 
 void module_register (void)
 {
-#if NTPD_HAVE_READ
        plugin_register_config ("ntpd", ntpd_config,
                        config_keys, config_keys_num);
        plugin_register_read ("ntpd", ntpd_read);
-#endif /* NTPD_HAVE_READ */
 } /* void module_register */
index 6af12b8..bde5d82 100644 (file)
--- a/src/nut.c
+++ b/src/nut.c
 
 #if HAVE_UPSCLIENT_H
 # include <upsclient.h>
-# define NUT_HAVE_READ 1
-#else
-# define NUT_HAVE_READ 0
 #endif
 
-#if NUT_HAVE_READ
 struct nut_ups_s;
 typedef struct nut_ups_s nut_ups_t;
 struct nut_ups_s
@@ -286,15 +282,12 @@ static int nut_shutdown (void)
 
   return (0);
 } /* int nut_shutdown */
-#endif /* NUT_HAVE_READ */
 
 void module_register (void)
 {
-#if NUT_HAVE_READ
   plugin_register_config ("nut", nut_config, config_keys, config_keys_num);
   plugin_register_read ("nut", nut_read);
   plugin_register_shutdown ("nut", nut_shutdown);
-#endif
 } /* void module_register */
 
 /* vim: set sw=2 ts=8 sts=2 tw=78 : */
index da66204..6272581 100644 (file)
@@ -374,6 +374,12 @@ int plugin_register_config (const char *name,
        return (0);
 } /* int plugin_register_config */
 
+int plugin_register_complex_config (const char *type,
+               int (*callback) (oconfig_item_t *))
+{
+       return (cf_register_complex (type, callback));
+} /* int plugin_register_complex_config */
+
 int plugin_register_init (const char *name,
                int (*callback) (void))
 {
@@ -458,6 +464,12 @@ int plugin_unregister_config (const char *name)
        return (0);
 } /* int plugin_unregister_config */
 
+int plugin_unregister_complex_config (const char *name)
+{
+       cf_unregister_complex (name);
+       return (0);
+} /* int plugin_unregister_complex_config */
+
 int plugin_unregister_init (const char *name)
 {
        return (plugin_unregister (list_init, name));
index 83c2109..4ca6c77 100644 (file)
@@ -1,9 +1,8 @@
 #ifndef PLUGIN_H
 #define PLUGIN_H
-
 /**
  * collectd - src/plugin.h
- * Copyright (C) 2005,2006  Florian octo Forster
+ * Copyright (C) 2005-2007  Florian octo Forster
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -22,6 +21,9 @@
  *   Florian octo Forster <octo at verplant.org>
  **/
 
+#include "collectd.h"
+#include "configfile.h"
+
 #define DATA_MAX_NAME_LEN 64
 
 #define DS_TYPE_COUNTER 0
@@ -61,6 +63,7 @@ struct value_list_s
        value_t *values;
        int      values_len;
        time_t   time;
+       int      interval;
        char     host[DATA_MAX_NAME_LEN];
        char     plugin[DATA_MAX_NAME_LEN];
        char     plugin_instance[DATA_MAX_NAME_LEN];
@@ -68,7 +71,8 @@ struct value_list_s
 };
 typedef struct value_list_s value_list_t;
 
-#define VALUE_LIST_INIT { NULL, 0, 0, "localhost", "", "", "" }
+#define VALUE_LIST_INIT { NULL, 0, 0, interval_g, "localhost", "", "", "" }
+#define VALUE_LIST_STATIC { NULL, 0, 0, 0, "localhost", "", "", "" }
 
 struct data_source_s
 {
@@ -143,6 +147,8 @@ void plugin_shutdown_all (void);
 int plugin_register_config (const char *name,
                int (*callback) (const char *key, const char *val),
                const char **keys, int keys_num);
+int plugin_register_complex_config (const char *type,
+               int (*callback) (oconfig_item_t *));
 int plugin_register_init (const char *name,
                int (*callback) (void));
 int plugin_register_read (const char *name,
@@ -156,6 +162,7 @@ int plugin_register_log (char *name,
                void (*callback) (int, const char *));
 
 int plugin_unregister_config (const char *name);
+int plugin_unregister_complex_config (const char *name);
 int plugin_unregister_init (const char *name);
 int plugin_unregister_read (const char *name);
 int plugin_unregister_write (const char *name);
@@ -163,6 +170,7 @@ int plugin_unregister_shutdown (const char *name);
 int plugin_unregister_data_set (const char *name);
 int plugin_unregister_log (const char *name);
 
+
 /*
  * NAME
  *  plugin_dispatch_values
index ff40126..29492ac 100644 (file)
 #  ifndef CONFIG_HZ
 #    define CONFIG_HZ 100
 #  endif
-#endif /* KERNEL_LINUX */
-
-#define MODULE_NAME "processes"
+/* #endif KERNEL_LINUX */
 
-#if HAVE_THREAD_INFO || KERNEL_LINUX
-# define PROCESSES_HAVE_READ 1
 #else
-# define PROCESSES_HAVE_READ 0
+# error "No applicable input method."
 #endif
 
 #define BUFSIZE 256
 
-#if PROCESSES_HAVE_READ
-#if HAVE_THREAD_INFO | KERNEL_LINUX
 static const char *config_keys[] =
 {
        "Process",
        NULL
 };
 static int config_keys_num = 1;
-#endif
 
 typedef struct procstat_entry_s
 {
@@ -143,9 +136,7 @@ typedef struct procstat
        struct procstat_entry_s *instances;
 } procstat_t;
 
-#if HAVE_THREAD_INFO | KERNEL_LINUX
 static procstat_t *list_head_g = NULL;
-#endif
 
 #if HAVE_THREAD_INFO
 static mach_port_t port_host_self;
@@ -159,7 +150,6 @@ static mach_msg_type_number_t     pset_list_len;
 static long pagesize_g;
 #endif /* KERNEL_LINUX */
 
-#if HAVE_THREAD_INFO | KERNEL_LINUX
 static void ps_list_register (const char *name)
 {
        procstat_t *new;
@@ -370,7 +360,6 @@ static int ps_config (const char *key, const char *value)
 
        return (0);
 }
-#endif /* HAVE_THREAD_INFO | KERNEL_LINUX */
 
 static int ps_init (void)
 {
@@ -1018,16 +1007,11 @@ static int ps_read (void)
 
        return (0);
 } /* int ps_read */
-#endif /* PROCESSES_HAVE_READ */
 
 void module_register (void)
 {
-#if PROCESSES_HAVE_READ
-#if HAVE_THREAD_INFO | KERNEL_LINUX
        plugin_register_config ("processes", ps_config,
                        config_keys, config_keys_num);
-#endif
        plugin_register_init ("processes", ps_init);
        plugin_register_read ("processes", ps_read);
-#endif /* PROCESSES_HAVE_READ */
 } /* void module_register */
index d20a814..4d4b87c 100644 (file)
@@ -37,9 +37,21 @@ struct rrd_cache_s
        char **values;
        time_t first_value;
        time_t last_value;
+       enum
+       {
+               FLAG_NONE   = 0x00,
+               FLAG_QUEUED = 0x01
+       } flags;
 };
 typedef struct rrd_cache_s rrd_cache_t;
 
+struct rrd_queue_s
+{
+       char *filename;
+       struct rrd_queue_s *next;
+};
+typedef struct rrd_queue_s rrd_queue_t;
+
 /*
  * Private variables
  */
@@ -77,25 +89,50 @@ static const char *config_keys[] =
 };
 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
 
+/* If datadir is zero, the daemon's basedir is used. If stepsize or heartbeat
+ * is zero a default, depending on the `interval' member of the value list is
+ * being used. */
 static char   *datadir   = NULL;
 static int     stepsize  = 0;
 static int     heartbeat = 0;
 static int     rrarows   = 1200;
 static double  xff       = 0.1;
 
+/* XXX: If you need to lock both, cache_lock and queue_lock, at the same time,
+ * ALWAYS lock `cache_lock' first! */
 static int         cache_timeout = 0;
 static int         cache_flush_timeout = 0;
 static time_t      cache_flush_last;
 static avl_tree_t *cache = NULL;
 static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
 
+static rrd_queue_t    *queue_head = NULL;
+static rrd_queue_t    *queue_tail = NULL;
+static pthread_t       queue_thread = 0;
+static pthread_mutex_t queue_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t  queue_cond = PTHREAD_COND_INITIALIZER;
+
+static int do_shutdown = 0;
+
 /* * * * * * * * * *
  * WARNING:  Magic *
  * * * * * * * * * */
-static int rra_get (char ***ret)
+
+static void rra_free (int rra_num, char **rra_def)
+{
+       int i;
+
+       for (i = 0; i < rra_num; i++)
+       {
+               sfree (rra_def[i]);
+       }
+       sfree (rra_def);
+} /* void rra_free */
+
+static int rra_get (char ***ret, const value_list_t *vl)
 {
-       static char **rra_def = NULL;
-       static int rra_num = 0;
+       char **rra_def;
+       int rra_num;
 
        int *rts;
        int  rts_num;
@@ -110,10 +147,21 @@ static int rra_get (char ***ret)
 
        char buffer[64];
 
-       if ((rra_num != 0) && (rra_def != NULL))
+       /* The stepsize we use here: If it is user-set, use it. If not, use the
+        * interval of the value-list. */
+       int ss;
+
+       if (rrarows <= 0)
+       {
+               *ret = NULL;
+               return (-1);
+       }
+
+       ss = (stepsize > 0) ? stepsize : vl->interval;
+       if (ss <= 0)
        {
-               *ret = rra_def;
-               return (rra_num);
+               *ret = NULL;
+               return (-1);
        }
 
        /* Use the configured timespans or fall back to the built-in defaults */
@@ -133,29 +181,24 @@ static int rra_get (char ***ret)
        if ((rra_def = (char **) malloc ((rra_max + 1) * sizeof (char *))) == NULL)
                return (-1);
        memset (rra_def, '\0', (rra_max + 1) * sizeof (char *));
-
-       if ((stepsize <= 0) || (rrarows <= 0))
-       {
-               *ret = NULL;
-               return (-1);
-       }
+       rra_num = 0;
 
        cdp_len = 0;
        for (i = 0; i < rts_num; i++)
        {
                span = rts[i];
 
-               if ((span / stepsize) < rrarows)
+               if ((span / ss) < rrarows)
                        continue;
 
                if (cdp_len == 0)
                        cdp_len = 1;
                else
                        cdp_len = (int) floor (((double) span)
-                                       / ((double) (rrarows * stepsize)));
+                                       / ((double) (rrarows * ss)));
 
                cdp_num = (int) ceil (((double) span)
-                               / ((double) (cdp_len * stepsize)));
+                               / ((double) (cdp_len * ss)));
 
                for (j = 0; j < rra_types_num; j++)
                {
@@ -182,7 +225,7 @@ static int rra_get (char ***ret)
 
        *ret = rra_def;
        return (rra_num);
-}
+} /* int rra_get */
 
 static void ds_free (int ds_num, char **ds_def)
 {
@@ -194,7 +237,7 @@ static void ds_free (int ds_num, char **ds_def)
        free (ds_def);
 }
 
-static int ds_get (char ***ret, const data_set_t *ds)
+static int ds_get (char ***ret, const data_set_t *ds, const value_list_t *vl)
 {
        char **ds_def;
        int ds_num;
@@ -256,7 +299,8 @@ static int ds_get (char ***ret, const data_set_t *ds)
 
                status = snprintf (buffer, sizeof (buffer),
                                "DS:%s:%s:%i:%s:%s",
-                               d->name, type, heartbeat,
+                               d->name, type,
+                               (heartbeat > 0) ? heartbeat : (2 * vl->interval),
                                min, max);
                if ((status < 1) || (status >= sizeof (buffer)))
                        break;
@@ -283,7 +327,7 @@ static int ds_get (char ***ret, const data_set_t *ds)
        return (ds_num);
 }
 
-static int rrd_create_file (char *filename, const data_set_t *ds)
+static int rrd_create_file (char *filename, const data_set_t *ds, const value_list_t *vl)
 {
        char **argv;
        int argc;
@@ -298,13 +342,13 @@ static int rrd_create_file (char *filename, const data_set_t *ds)
        if (check_create_dir (filename))
                return (-1);
 
-       if ((rra_num = rra_get (&rra_def)) < 1)
+       if ((rra_num = rra_get (&rra_def, vl)) < 1)
        {
                ERROR ("rrd_create_file failed: Could not calculate RRAs");
                return (-1);
        }
 
-       if ((ds_num = ds_get (&ds_def, ds)) < 1)
+       if ((ds_num = ds_get (&ds_def, ds, vl)) < 1)
        {
                ERROR ("rrd_create_file failed: Could not calculate DSes");
                return (-1);
@@ -321,10 +365,13 @@ static int rrd_create_file (char *filename, const data_set_t *ds)
        }
 
        status = snprintf (stepsize_str, sizeof (stepsize_str),
-                       "%i", stepsize);
+                       "%i", (stepsize > 0) ? stepsize : vl->interval);
        if ((status < 1) || (status >= sizeof (stepsize_str)))
        {
                ERROR ("rrdtool plugin: snprintf failed.");
+               free (argv);
+               ds_free (ds_num, ds_def);
+               rra_free (rra_num, rra_def);
                return (-1);
        }
 
@@ -350,6 +397,7 @@ static int rrd_create_file (char *filename, const data_set_t *ds)
 
        free (argv);
        ds_free (ds_num, ds_def);
+       rra_free (rra_num, rra_def);
 
        return (status);
 }
@@ -434,138 +482,143 @@ static int value_list_to_filename (char *buffer, int buffer_len,
        return (0);
 } /* int value_list_to_filename */
 
-static rrd_cache_t *rrd_cache_insert (const char *filename,
-               const char *value, time_t value_time)
+static int rrd_write_to_file (char *filename, char **values, int values_num)
 {
-       rrd_cache_t *rc = NULL;
-       int new_rc = 0;
+       char **argv;
+       int argc;
+       int status;
 
-       if (cache != NULL)
-               avl_get (cache, filename, (void *) &rc);
+       if (values_num < 1)
+               return (0);
 
-       if (rc == NULL)
-       {
-               rc = (rrd_cache_t *) malloc (sizeof (rrd_cache_t));
-               if (rc == NULL)
-                       return (NULL);
-               rc->values_num = 0;
-               rc->values = NULL;
-               rc->first_value = 0;
-               rc->last_value = 0;
-               new_rc = 1;
-       }
+       argc = values_num + 2;
+       argv = (char **) malloc ((argc + 1) * sizeof (char *));
+       if (argv == NULL)
+               return (-1);
 
-       if (rc->last_value >= value_time)
+       argv[0] = "update";
+       argv[1] = filename;
+       memcpy (argv + 2, values, values_num * sizeof (char *));
+       argv[argc] = NULL;
+
+       DEBUG ("rrd_update (argc = %i, argv = %p)", argc, (void *) argv);
+
+       optind = 0; /* bug in librrd? */
+       rrd_clear_error ();
+       status = rrd_update (argc, argv);
+       if (status != 0)
        {
-               WARNING ("rrdtool plugin: (rc->last_value = %u) >= (value_time = %u)",
-                               (unsigned int) rc->last_value,
-                               (unsigned int) value_time);
-               return (NULL);
+               WARNING ("rrd_update failed: %s: %s",
+                               filename, rrd_get_error ());
+               status = -1;
        }
 
-       rc->values = (char **) realloc ((void *) rc->values,
-                       (rc->values_num + 1) * sizeof (char *));
-       if (rc->values == NULL)
+       sfree (argv);
+
+       return (status);
+} /* int rrd_write_cache_entry */
+
+static void *rrd_queue_thread (void *data)
+{
+       while (42)
        {
-               char errbuf[1024];
-               ERROR ("rrdtool plugin: realloc failed: %s",
-                               sstrerror (errno, errbuf, sizeof (errbuf)));
-               if (cache != NULL)
+               rrd_queue_t *queue_entry;
+               rrd_cache_t *cache_entry;
+               char **values;
+               int    values_num;
+               int    i;
+
+               /* XXX: If you need to lock both, cache_lock and queue_lock, at
+                * the same time, ALWAYS lock `cache_lock' first! */
+
+               /* wait until an entry is available */
+               pthread_mutex_lock (&queue_lock);
+               while ((queue_head == NULL) && (do_shutdown == 0))
+                       pthread_cond_wait (&queue_cond, &queue_lock);
+
+               /* We're in the shutdown phase */
+               if (queue_head == NULL)
                {
-                       void *cache_key = NULL;
-                       avl_remove (cache, filename, &cache_key, NULL);
-                       sfree (cache_key);
+                       pthread_mutex_unlock (&queue_lock);
+                       break;
                }
-               free (rc);
-               return (NULL);
-       }
 
-       rc->values[rc->values_num] = strdup (value);
-       if (rc->values[rc->values_num] != NULL)
-               rc->values_num++;
+               /* Dequeue the first entry */
+               queue_entry = queue_head;
+               if (queue_head == queue_tail)
+                       queue_head = queue_tail = NULL;
+               else
+                       queue_head = queue_head->next;
 
-       if (rc->values_num == 1)
-               rc->first_value = value_time;
-       rc->last_value = value_time;
+               /* Unlock the queue again */
+               pthread_mutex_unlock (&queue_lock);
 
-       /* Insert if this is the first value */
-       if ((cache != NULL) && (new_rc == 1))
-       {
-               void *cache_key = strdup (filename);
+               /* We now need the cache lock so the entry isn't updated while
+                * we make a copy of it's values */
+               pthread_mutex_lock (&cache_lock);
 
-               if (cache_key == NULL)
-               {
-                       char errbuf[1024];
-                       ERROR ("rrdtool plugin: strdup failed: %s",
-                                       sstrerror (errno, errbuf, sizeof (errbuf)));
-                       sfree (rc->values[0]);
-                       sfree (rc->values);
-                       sfree (rc);
-                       return (NULL);
-               }
+               avl_get (cache, queue_entry->filename, (void *) &cache_entry);
 
-               avl_insert (cache, cache_key, rc);
-       }
+               values = cache_entry->values;
+               values_num = cache_entry->values_num;
 
-       DEBUG ("rrd_cache_insert (%s, %s, %u) = %p", filename, value,
-                       (unsigned int) value_time, (void *) rc);
+               cache_entry->values = NULL;
+               cache_entry->values_num = 0;
+               cache_entry->flags = FLAG_NONE;
 
-       return (rc);
-} /* rrd_cache_t *rrd_cache_insert */
+               pthread_mutex_unlock (&cache_lock);
 
-static int rrd_write_cache_entry (const char *filename, rrd_cache_t *rc)
-{
-       char **argv;
-       int    argc;
+               /* Write the values to the RRD-file */
+               rrd_write_to_file (queue_entry->filename, values, values_num);
 
-       char *fn;
-       int status;
+               for (i = 0; i < values_num; i++)
+               {
+                       sfree (values[i]);
+               }
+               sfree (values);
+               sfree (queue_entry->filename);
+               sfree (queue_entry);
+       } /* while (42) */
 
-       int i;
+       pthread_mutex_lock (&cache_lock);
+       avl_destroy (cache);
+       cache = NULL;
+       pthread_mutex_unlock (&cache_lock);
 
-       if (rc->values_num < 1)
-               return (0);
+       pthread_exit ((void *) 0);
+       return ((void *) 0);
+} /* void *rrd_queue_thread */
 
-       argc = rc->values_num + 2;
-       argv = (char **) malloc ((argc + 1) * sizeof (char *));
-       if (argv == NULL)
+static int rrd_queue_cache_entry (const char *filename)
+{
+       rrd_queue_t *queue_entry;
+
+       queue_entry = (rrd_queue_t *) malloc (sizeof (rrd_queue_t));
+       if (queue_entry == NULL)
                return (-1);
 
-       fn = strdup (filename);
-       if (fn == NULL)
+       queue_entry->filename = strdup (filename);
+       if (queue_entry->filename == NULL)
        {
-               free (argv);
+               free (queue_entry);
                return (-1);
        }
 
-       argv[0] = "update";
-       argv[1] = fn;
-       memcpy (argv + 2, rc->values, rc->values_num * sizeof (char *));
-       argv[argc] = NULL;
-
-       DEBUG ("rrd_update (argc = %i, argv = %p)", argc, (void *) argv);
+       queue_entry->next = NULL;
 
-       optind = 0; /* bug in librrd? */
-       rrd_clear_error ();
-       status = rrd_update (argc, argv);
-       if (status != 0)
-       {
-               WARNING ("rrd_update failed: %s: %s",
-                               filename, rrd_get_error ());
-               status = -1;
-       }
+       pthread_mutex_lock (&queue_lock);
+       if (queue_tail == NULL)
+               queue_head = queue_entry;
+       else
+               queue_tail->next = queue_entry;
+       queue_tail = queue_entry;
+       pthread_cond_signal (&queue_cond);
+       pthread_mutex_unlock (&queue_lock);
 
-       free (argv);
-       free (fn);
-       /* Free the value list of `rc' */
-       for (i = 0; i < rc->values_num; i++)
-               free (rc->values[i]);
-       free (rc->values);
-       rc->values = NULL;
-       rc->values_num = 0;
+       DEBUG ("rrdtool plugin: Put `%s' into the update queue", filename);
 
-       return (status);
-} /* int rrd_write_cache_entry */
+       return (0);
+} /* int rrd_queue_cache_entry */
 
 static void rrd_cache_flush (int timeout)
 {
@@ -579,9 +632,6 @@ static void rrd_cache_flush (int timeout)
        avl_iterator_t *iter;
        int i;
 
-       if (cache == NULL)
-               return;
-
        DEBUG ("Flushing cache, timeout = %i", timeout);
 
        now = time (NULL);
@@ -591,7 +641,17 @@ static void rrd_cache_flush (int timeout)
        while (avl_iterator_next (iter, (void *) &key, (void *) &rc) == 0)
        {
                DEBUG ("key = %s; age = %i;", key, now - rc->first_value);
-               if ((now - rc->first_value) >= timeout)
+
+               if (rc->flags == FLAG_QUEUED)
+                       continue;
+               else if ((now - rc->first_value) < timeout)
+                       continue;
+               else if (rc->values_num > 0)
+               {
+                       if (rrd_queue_cache_entry (key) == 0)
+                               rc->flags = FLAG_QUEUED;
+               }
+               else /* ancient and no values -> waste of memory */
                {
                        keys = (char **) realloc ((void *) keys,
                                        (keys_num + 1) * sizeof (char *));
@@ -619,8 +679,9 @@ static void rrd_cache_flush (int timeout)
                        continue;
                }
 
-               rrd_write_cache_entry (keys[i], rc);
-               /* rc's value-list is free's by `rrd_write_cache_entry' */
+               assert (rc->values == NULL);
+               assert (rc->values_num == 0);
+
                sfree (rc);
                sfree (key);
                keys[i] = NULL;
@@ -632,13 +693,125 @@ static void rrd_cache_flush (int timeout)
        cache_flush_last = now;
 } /* void rrd_cache_flush */
 
+static int rrd_cache_insert (const char *filename,
+               const char *value, time_t value_time)
+{
+       rrd_cache_t *rc = NULL;
+       int new_rc = 0;
+       char **values_new;
+
+       pthread_mutex_lock (&cache_lock);
+
+       avl_get (cache, filename, (void *) &rc);
+
+       if (rc == NULL)
+       {
+               rc = (rrd_cache_t *) malloc (sizeof (rrd_cache_t));
+               if (rc == NULL)
+                       return (-1);
+               rc->values_num = 0;
+               rc->values = NULL;
+               rc->first_value = 0;
+               rc->last_value = 0;
+               rc->flags = FLAG_NONE;
+               new_rc = 1;
+       }
+
+       if (rc->last_value >= value_time)
+       {
+               pthread_mutex_unlock (&cache_lock);
+               WARNING ("rrdtool plugin: (rc->last_value = %u) >= (value_time = %u)",
+                               (unsigned int) rc->last_value,
+                               (unsigned int) value_time);
+               return (-1);
+       }
+
+       values_new = (char **) realloc ((void *) rc->values,
+                       (rc->values_num + 1) * sizeof (char *));
+       if (values_new == NULL)
+       {
+               char errbuf[1024];
+               void *cache_key = NULL;
+
+               sstrerror (errno, errbuf, sizeof (errbuf));
+
+               avl_remove (cache, filename, &cache_key, NULL);
+               pthread_mutex_unlock (&cache_lock);
+
+               ERROR ("rrdtool plugin: realloc failed: %s", errbuf);
+
+               sfree (cache_key);
+               sfree (rc->values);
+               sfree (rc);
+               return (-1);
+       }
+       rc->values = values_new;
+
+       rc->values[rc->values_num] = strdup (value);
+       if (rc->values[rc->values_num] != NULL)
+               rc->values_num++;
+
+       if (rc->values_num == 1)
+               rc->first_value = value_time;
+       rc->last_value = value_time;
+
+       /* Insert if this is the first value */
+       if (new_rc == 1)
+       {
+               void *cache_key = strdup (filename);
+
+               if (cache_key == NULL)
+               {
+                       char errbuf[1024];
+                       sstrerror (errno, errbuf, sizeof (errbuf));
+
+                       pthread_mutex_unlock (&cache_lock);
+
+                       ERROR ("rrdtool plugin: strdup failed: %s", errbuf);
+
+                       sfree (rc->values[0]);
+                       sfree (rc->values);
+                       sfree (rc);
+                       return (-1);
+               }
+
+               avl_insert (cache, cache_key, rc);
+       }
+
+       DEBUG ("rrd_cache_insert (%s, %s, %u) = %p", filename, value,
+                       (unsigned int) value_time, (void *) rc);
+
+       if ((rc->last_value - rc->first_value) >= cache_timeout)
+       {
+               /* XXX: If you need to lock both, cache_lock and queue_lock, at
+                * the same time, ALWAYS lock `cache_lock' first! */
+               if (rc->flags != FLAG_QUEUED)
+               {
+                       if (rrd_queue_cache_entry (filename) == 0)
+                               rc->flags = FLAG_QUEUED;
+               }
+               else
+               {
+                       DEBUG ("rrdtool plugin: `%s' is already queued.", filename);
+               }
+       }
+
+       if ((cache_timeout > 0) &&
+                       ((time (NULL) - cache_flush_last) > cache_flush_timeout))
+               rrd_cache_flush (cache_flush_timeout);
+
+
+       pthread_mutex_unlock (&cache_lock);
+
+       return (0);
+} /* int rrd_cache_insert */
+
 static int rrd_write (const data_set_t *ds, const value_list_t *vl)
 {
        struct stat  statbuf;
        char         filename[512];
        char         values[512];
-       rrd_cache_t *rc;
-       time_t       now;
+       int          status;
 
        if (value_list_to_filename (filename, sizeof (filename), ds, vl) != 0)
                return (-1);
@@ -650,7 +823,7 @@ static int rrd_write (const data_set_t *ds, const value_list_t *vl)
        {
                if (errno == ENOENT)
                {
-                       if (rrd_create_file (filename, ds))
+                       if (rrd_create_file (filename, ds, vl))
                                return (-1);
                }
                else
@@ -669,37 +842,9 @@ static int rrd_write (const data_set_t *ds, const value_list_t *vl)
                return (-1);
        }
 
-       pthread_mutex_lock (&cache_lock);
-       rc = rrd_cache_insert (filename, values, vl->time);
-       if (rc == NULL)
-       {
-               pthread_mutex_unlock (&cache_lock);
-               return (-1);
-       }
-
-       if (cache == NULL)
-       {
-               rrd_write_cache_entry (filename, rc);
-               /* rc's value-list is free's by `rrd_write_cache_entry' */
-               sfree (rc);
-               pthread_mutex_unlock (&cache_lock);
-               return (0);
-       }
-
-       now = time (NULL);
-
-       DEBUG ("age (%s) = %i", filename, now - rc->first_value);
+       status = rrd_cache_insert (filename, values, vl->time);
 
-       /* `rc' is not free'd here, because we'll likely reuse it. If not, then
-        * the next flush will remove this entry.  */
-       if ((now - rc->first_value) >= cache_timeout)
-               rrd_write_cache_entry (filename, rc);
-
-       if ((now - cache_flush_last) >= cache_flush_timeout)
-               rrd_cache_flush (cache_flush_timeout);
-
-       pthread_mutex_unlock (&cache_lock);
-       return (0);
+       return (status);
 } /* int rrd_write */
 
 static int rrd_config (const char *key, const char *value)
@@ -748,25 +893,15 @@ static int rrd_config (const char *key, const char *value)
        }
        else if (strcasecmp ("StepSize", key) == 0)
        {
-               int tmp = atoi (value);
-               if (tmp <= 0)
-               {
-                       fprintf (stderr, "rrdtool: `StepSize' must "
-                                       "be greater than 0.\n");
-                       return (1);
-               }
-               stepsize = tmp;
+               stepsize = atoi (value);
+               if (stepsize < 0)
+                       stepsize = 0;
        }
        else if (strcasecmp ("HeartBeat", key) == 0)
        {
-               int tmp = atoi (value);
-               if (tmp <= 0)
-               {
-                       fprintf (stderr, "rrdtool: `HeartBeat' must "
-                                       "be greater than 0.\n");
-                       return (1);
-               }
-               heartbeat = tmp;
+               heartbeat = atoi (value);
+               if (heartbeat < 0)
+                       heartbeat = 0;
        }
        else if (strcasecmp ("RRARows", key) == 0)
        {
@@ -833,47 +968,67 @@ static int rrd_shutdown (void)
 {
        pthread_mutex_lock (&cache_lock);
        rrd_cache_flush (-1);
-       if (cache != NULL)
-               avl_destroy (cache);
-       cache = NULL;
        pthread_mutex_unlock (&cache_lock);
 
+       pthread_mutex_lock (&queue_lock);
+       do_shutdown = 1;
+       pthread_cond_signal (&queue_cond);
+       pthread_mutex_unlock (&queue_lock);
+
        return (0);
 } /* int rrd_shutdown */
 
 static int rrd_init (void)
 {
-       if (stepsize <= 0)
-               stepsize = interval_g;
+       int status;
+
+       if (stepsize < 0)
+               stepsize = 0;
        if (heartbeat <= 0)
-               heartbeat = 2 * interval_g;
+       {
+               if (stepsize > 0)
+                       heartbeat = 2 * stepsize;
+               else
+                       heartbeat = 0;
+       }
 
-       if (heartbeat < interval_g)
+       if ((heartbeat > 0) && (heartbeat < interval_g))
                WARNING ("rrdtool plugin: Your `heartbeat' is "
                                "smaller than your `interval'. This will "
                                "likely cause problems.");
-       else if (stepsize < interval_g)
+       else if ((stepsize > 0) && (stepsize < interval_g))
                WARNING ("rrdtool plugin: Your `stepsize' is "
                                "smaller than your `interval'. This will "
                                "create needlessly big RRD-files.");
 
+       /* Set the cache up */
        pthread_mutex_lock (&cache_lock);
+
+       cache = avl_create ((int (*) (const void *, const void *)) strcmp);
+       if (cache == NULL)
+       {
+               ERROR ("rrdtool plugin: avl_create failed.");
+               return (-1);
+       }
+
+       cache_flush_last = time (NULL);
        if (cache_timeout < 2)
        {
                cache_timeout = 0;
                cache_flush_timeout = 0;
        }
-       else
-       {
-               if (cache_flush_timeout < cache_timeout)
-                       cache_flush_timeout = 10 * cache_timeout;
+       else if (cache_flush_timeout < cache_timeout)
+               cache_flush_timeout = 10 * cache_timeout;
 
-               cache = avl_create ((int (*) (const void *, const void *)) strcmp);
-               cache_flush_last = time (NULL);
-               plugin_register_shutdown ("rrdtool", rrd_shutdown);
-       }
        pthread_mutex_unlock (&cache_lock);
 
+       status = pthread_create (&queue_thread, NULL, rrd_queue_thread, NULL);
+       if (status != 0)
+       {
+               ERROR ("rrdtool plugin: Cannot create queue-thread.");
+               return (-1);
+       }
+
        DEBUG ("rrdtool plugin: rrd_init: datadir = %s; stepsize = %i;"
                        " heartbeat = %i; rrarows = %i; xff = %lf;",
                        (datadir == NULL) ? "(null)" : datadir,
@@ -888,4 +1043,5 @@ void module_register (void)
                        config_keys, config_keys_num);
        plugin_register_init ("rrdtool", rrd_init);
        plugin_register_write ("rrdtool", rrd_write);
+       plugin_register_shutdown ("rrdtool", rrd_shutdown);
 }
index e1bc7aa..3e1d4f9 100644 (file)
 
 #if defined(HAVE_SENSORS_SENSORS_H)
 # include <sensors/sensors.h>
-#else
-# undef HAVE_LIBSENSORS
 #endif
 
-#if defined(HAVE_LIBSENSORS)
-# define SENSORS_HAVE_READ 1
-#else
-# define SENSORS_HAVE_READ 0
-#endif
-
-#if SENSORS_HAVE_READ
 #define SENSOR_TYPE_VOLTAGE     0
 #define SENSOR_TYPE_FANSPEED    1
 #define SENSOR_TYPE_TEMPERATURE 2
@@ -421,14 +412,11 @@ static int sensors_read (void)
 
        return (0);
 } /* int sensors_read */
-#endif /* SENSORS_HAVE_READ */
 
 void module_register (void)
 {
-#if SENSORS_HAVE_READ
        plugin_register_config ("sensors", sensors_config,
                        config_keys, config_keys_num);
        plugin_register_read ("sensors", sensors_read);
        plugin_register_shutdown ("sensors", sensors_shutdown);
-#endif
 } /* void module_register */
index dd063bb..9cfe1dd 100644 (file)
 #include "common.h"
 #include "plugin.h"
 
-#if defined(KERNEL_LINUX)
-# define SERIAL_HAVE_READ 1
-#else
-# define SERIAL_HAVE_READ 0
+#if !KERNEL_LINUX
+# error "No applicable input method."
 #endif
 
-#if SERIAL_HAVE_READ
 static void serial_submit (const char *type_instance,
                counter_t rx, counter_t tx)
 {
@@ -54,7 +51,6 @@ static void serial_submit (const char *type_instance,
 
 static int serial_read (void)
 {
-#ifdef KERNEL_LINUX
        FILE *fh;
        char buffer[1024];
 
@@ -121,13 +117,9 @@ static int serial_read (void)
 
        fclose (fh);
        return (0);
-#endif /* KERNEL_LINUX */
 } /* int serial_read */
-#endif /* SERIAL_HAVE_READ */
 
 void module_register (void)
 {
-#if SERIAL_HAVE_READ
        plugin_register_read ("serial", serial_read);
-#endif /* SERIAL_HAVE_READ */
 } /* void module_register */
diff --git a/src/snmp.c b/src/snmp.c
new file mode 100644 (file)
index 0000000..2c4c930
--- /dev/null
@@ -0,0 +1,1314 @@
+/**
+ * collectd - src/snmp.c
+ * Copyright (C) 2007  Florian octo Forster
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; only version 2 of the License is applicable.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ *
+ * Authors:
+ *   Florian octo Forster <octo at verplant.org>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+#include <pthread.h>
+
+#include <net-snmp/net-snmp-config.h>
+#include <net-snmp/net-snmp-includes.h>
+
+/*
+ * Private data structes
+ */
+struct oid_s
+{
+  oid oid[MAX_OID_LEN];
+  size_t oid_len;
+};
+typedef struct oid_s oid_t;
+
+union instance_u
+{
+  char  string[DATA_MAX_NAME_LEN];
+  oid_t oid;
+};
+typedef union instance_u instance_t;
+
+struct data_definition_s
+{
+  char *name; /* used to reference this from the `Collect' option */
+  char *type; /* used to find the data_set */
+  int is_table;
+  instance_t instance;
+  oid_t *values;
+  int values_len;
+  struct data_definition_s *next;
+};
+typedef struct data_definition_s data_definition_t;
+
+struct host_definition_s
+{
+  char *name;
+  char *address;
+  char *community;
+  int version;
+  void *sess_handle;
+  int16_t skip_num;
+  int16_t skip_left;
+  data_definition_t **data_list;
+  int data_list_len;
+  enum          /****************************************************/
+  {             /* This host..                                      */
+    STATE_IDLE, /* - just sits there until `skip_left < interval_g' */
+    STATE_WAIT, /* - waits to be queried.                           */
+    STATE_BUSY  /* - is currently being queried.                    */
+  } state;      /****************************************************/
+  struct host_definition_s *next;
+};
+typedef struct host_definition_s host_definition_t;
+
+/* These two types are used to cache values in `csnmp_read_table' to handle
+ * gaps in tables. */
+struct csnmp_list_instances_s
+{
+  oid subid;
+  char instance[DATA_MAX_NAME_LEN];
+  struct csnmp_list_instances_s *next;
+};
+typedef struct csnmp_list_instances_s csnmp_list_instances_t;
+
+struct csnmp_table_values_s
+{
+  oid subid;
+  value_t value;
+  struct csnmp_table_values_s *next;
+};
+typedef struct csnmp_table_values_s csnmp_table_values_t;
+
+/*
+ * Private variables
+ */
+static int do_shutdown = 0;
+
+pthread_t *threads = NULL;
+int threads_num = 0;
+
+static data_definition_t *data_head = NULL;
+static host_definition_t *host_head = NULL;
+
+static pthread_mutex_t host_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t  host_cond = PTHREAD_COND_INITIALIZER;
+
+/*
+ * Private functions
+ */
+/* First there are many functions which do configuration stuff. It's a big
+ * bloated and messy, I'm afraid. */
+
+/*
+ * Callgraph for the config stuff:
+ *  csnmp_config
+ *  +-> call_snmp_init_once
+ *  +-> csnmp_config_add_data
+ *  !   +-> csnmp_config_add_data_type
+ *  !   +-> csnmp_config_add_data_table
+ *  !   +-> csnmp_config_add_data_instance
+ *  !   +-> csnmp_config_add_data_values
+ *  +-> csnmp_config_add_host
+ *      +-> csnmp_config_add_host_address
+ *      +-> csnmp_config_add_host_community
+ *      +-> csnmp_config_add_host_version
+ *      +-> csnmp_config_add_host_collect
+ *      +-> csnmp_config_add_host_interval
+ */
+static void call_snmp_init_once (void)
+{
+  static int have_init = 0;
+
+  if (have_init == 0)
+    init_snmp (PACKAGE_NAME);
+  have_init = 1;
+} /* void call_snmp_init_once */
+
+static int csnmp_config_add_data_type (data_definition_t *dd, oconfig_item_t *ci)
+{
+  if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
+  {
+    WARNING ("snmp plugin: `Type' needs exactly one string argument.");
+    return (-1);
+  }
+
+  if (dd->type != NULL)
+    free (dd->type);
+
+  dd->type = strdup (ci->values[0].value.string);
+  if (dd->type == NULL)
+    return (-1);
+
+  return (0);
+} /* int csnmp_config_add_data_type */
+
+static int csnmp_config_add_data_table (data_definition_t *dd, oconfig_item_t *ci)
+{
+  if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
+  {
+    WARNING ("snmp plugin: `Table' needs exactly one boolean argument.");
+    return (-1);
+  }
+
+  dd->is_table = ci->values[0].value.boolean ? 1 : 0;
+
+  return (0);
+} /* int csnmp_config_add_data_table */
+
+static int csnmp_config_add_data_instance (data_definition_t *dd, oconfig_item_t *ci)
+{
+  if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
+  {
+    WARNING ("snmp plugin: `Instance' needs exactly one string argument.");
+    return (-1);
+  }
+
+  if (dd->is_table)
+  {
+    /* Instance is an OID */
+    dd->instance.oid.oid_len = MAX_OID_LEN;
+
+    if (!read_objid (ci->values[0].value.string,
+         dd->instance.oid.oid, &dd->instance.oid.oid_len))
+    {
+      ERROR ("snmp plugin: read_objid (%s) failed.",
+         ci->values[0].value.string);
+      return (-1);
+    }
+  }
+  else
+  {
+    /* Instance is a simple string */
+    strncpy (dd->instance.string, ci->values[0].value.string, DATA_MAX_NAME_LEN - 1);
+  }
+
+  return (0);
+} /* int csnmp_config_add_data_instance */
+
+static int csnmp_config_add_data_values (data_definition_t *dd, oconfig_item_t *ci)
+{
+  int i;
+
+  if (ci->values_num < 1)
+  {
+    WARNING ("snmp plugin: `Values' needs at least one argument.");
+    return (-1);
+  }
+
+  for (i = 0; i < ci->values_num; i++)
+    if (ci->values[i].type != OCONFIG_TYPE_STRING)
+    {
+      WARNING ("snmp plugin: `Values' needs only string argument.");
+      return (-1);
+    }
+
+  if (dd->values != NULL)
+    free (dd->values);
+  dd->values = (oid_t *) malloc (sizeof (oid_t) * ci->values_num);
+  if (dd->values == NULL)
+    return (-1);
+  dd->values_len = ci->values_num;
+
+  for (i = 0; i < ci->values_num; i++)
+  {
+    dd->values[i].oid_len = MAX_OID_LEN;
+
+    if (NULL == snmp_parse_oid (ci->values[i].value.string,
+         dd->values[i].oid, &dd->values[i].oid_len))
+    {
+      ERROR ("snmp plugin: snmp_parse_oid (%s) failed.",
+         ci->values[i].value.string);
+      free (dd->values);
+      dd->values = NULL;
+      dd->values_len = 0;
+      return (-1);
+    }
+  }
+
+  return (0);
+} /* int csnmp_config_add_data_instance */
+
+static int csnmp_config_add_data (oconfig_item_t *ci)
+{
+  data_definition_t *dd;
+  int status = 0;
+  int i;
+
+  if ((ci->values_num != 1)
+      || (ci->values[0].type != OCONFIG_TYPE_STRING))
+  {
+    WARNING ("snmp plugin: The `Data' config option needs exactly one string argument.");
+    return (-1);
+  }
+
+  dd = (data_definition_t *) malloc (sizeof (data_definition_t));
+  if (dd == NULL)
+    return (-1);
+  memset (dd, '\0', sizeof (data_definition_t));
+
+  dd->name = strdup (ci->values[0].value.string);
+  if (dd->name == NULL)
+  {
+    free (dd);
+    return (-1);
+  }
+
+  for (i = 0; i < ci->children_num; i++)
+  {
+    oconfig_item_t *option = ci->children + i;
+    status = 0;
+
+    if (strcasecmp ("Type", option->key) == 0)
+      status = csnmp_config_add_data_type (dd, option);
+    else if (strcasecmp ("Table", option->key) == 0)
+      status = csnmp_config_add_data_table (dd, option);
+    else if (strcasecmp ("Instance", option->key) == 0)
+      status = csnmp_config_add_data_instance (dd, option);
+    else if (strcasecmp ("Values", option->key) == 0)
+      status = csnmp_config_add_data_values (dd, option);
+    else
+    {
+      WARNING ("snmp plugin: Option `%s' not allowed here.", option->key);
+      status = -1;
+    }
+
+    if (status != 0)
+      break;
+  } /* for (ci->children) */
+
+  while (status == 0)
+  {
+    if (dd->type == NULL)
+    {
+      WARNING ("snmp plugin: `Type' not given for data `%s'", dd->name);
+      status = -1;
+      break;
+    }
+    if (dd->values == NULL)
+    {
+      WARNING ("snmp plugin: No `Value' given for data `%s'", dd->name);
+      status = -1;
+      break;
+    }
+
+    break;
+  } /* while (status == 0) */
+
+  if (status != 0)
+  {
+    sfree (dd->name);
+    sfree (dd->values);
+    sfree (dd);
+    return (-1);
+  }
+
+  DEBUG ("snmp plugin: dd = { name = %s, type = %s, is_table = %s, values_len = %i }",
+      dd->name, dd->type, (dd->is_table != 0) ? "true" : "false", dd->values_len);
+
+  if (data_head == NULL)
+    data_head = dd;
+  else
+  {
+    data_definition_t *last;
+    last = data_head;
+    while (last->next != NULL)
+      last = last->next;
+    last->next = dd;
+  }
+
+  return (0);
+} /* int csnmp_config_add_data */
+
+static int csnmp_config_add_host_address (host_definition_t *hd, oconfig_item_t *ci)
+{
+  if ((ci->values_num != 1)
+      || (ci->values[0].type != OCONFIG_TYPE_STRING))
+  {
+    WARNING ("snmp plugin: The `Address' config option needs exactly one string argument.");
+    return (-1);
+  }
+
+  if (hd->address == NULL)
+    free (hd->address);
+
+  hd->address = strdup (ci->values[0].value.string);
+  if (hd->address == NULL)
+    return (-1);
+
+  DEBUG ("snmp plugin: host = %s; host->address = %s;",
+      hd->name, hd->address);
+
+  return (0);
+} /* int csnmp_config_add_host_address */
+
+static int csnmp_config_add_host_community (host_definition_t *hd, oconfig_item_t *ci)
+{
+  if ((ci->values_num != 1)
+      || (ci->values[0].type != OCONFIG_TYPE_STRING))
+  {
+    WARNING ("snmp plugin: The `Community' config option needs exactly one string argument.");
+    return (-1);
+  }
+
+  if (hd->community == NULL)
+    free (hd->community);
+
+  hd->community = strdup (ci->values[0].value.string);
+  if (hd->community == NULL)
+    return (-1);
+
+  DEBUG ("snmp plugin: host = %s; host->community = %s;",
+      hd->name, hd->community);
+
+  return (0);
+} /* int csnmp_config_add_host_community */
+
+static int csnmp_config_add_host_version (host_definition_t *hd, oconfig_item_t *ci)
+{
+  int version;
+
+  if ((ci->values_num != 1)
+      || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
+  {
+    WARNING ("snmp plugin: The `Version' config option needs exactly one number argument.");
+    return (-1);
+  }
+
+  version = (int) ci->values[0].value.number;
+  if ((version != 1) && (version != 2))
+  {
+    WARNING ("snmp plugin: `Version' must either be `1' or `2'.");
+    return (-1);
+  }
+
+  hd->version = version;
+
+  return (0);
+} /* int csnmp_config_add_host_address */
+
+static int csnmp_config_add_host_collect (host_definition_t *host,
+    oconfig_item_t *ci)
+{
+  data_definition_t *data;
+  data_definition_t **data_list;
+  int data_list_len;
+  int i;
+
+  if (ci->values_num < 1)
+  {
+    WARNING ("snmp plugin: `Collect' needs at least one argument.");
+    return (-1);
+  }
+
+  for (i = 0; i < ci->values_num; i++)
+    if (ci->values[i].type != OCONFIG_TYPE_STRING)
+    {
+      WARNING ("snmp plugin: All arguments to `Collect' must be strings.");
+      return (-1);
+    }
+
+  data_list_len = host->data_list_len + ci->values_num;
+  data_list = (data_definition_t **) realloc (host->data_list,
+      sizeof (data_definition_t *) * data_list_len);
+  if (data_list == NULL)
+    return (-1);
+  host->data_list = data_list;
+
+  for (i = 0; i < ci->values_num; i++)
+  {
+    for (data = data_head; data != NULL; data = data->next)
+      if (strcasecmp (ci->values[i].value.string, data->name) == 0)
+       break;
+
+    if (data == NULL)
+    {
+      WARNING ("snmp plugin: No such data configured: `%s'",
+         ci->values[i].value.string);
+      continue;
+    }
+
+    DEBUG ("snmp plugin: Collect: host = %s, data[%i] = %s;",
+       host->name, host->data_list_len, data->name);
+
+    host->data_list[host->data_list_len] = data;
+    host->data_list_len++;
+  } /* for (values_num) */
+
+  return (0);
+} /* int csnmp_config_add_host_collect */
+
+static int csnmp_config_add_host_interval (host_definition_t *hd, oconfig_item_t *ci)
+{
+  int interval;
+
+  if ((ci->values_num != 1)
+      || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
+  {
+    WARNING ("snmp plugin: The `Interval' config option needs exactly one number argument.");
+    return (-1);
+  }
+
+  interval = (int) ci->values[0].value.number;
+  hd->skip_num = interval;
+  if (hd->skip_num < 0)
+    hd->skip_num = 0;
+
+  return (0);
+} /* int csnmp_config_add_host_interval */
+
+static int csnmp_config_add_host (oconfig_item_t *ci)
+{
+  host_definition_t *hd;
+  int status = 0;
+  int i;
+
+  if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
+  {
+    WARNING ("snmp plugin: `Host' needs exactly one string argument.");
+    return (-1);
+  }
+
+  hd = (host_definition_t *) malloc (sizeof (host_definition_t));
+  if (hd == NULL)
+    return (-1);
+  memset (hd, '\0', sizeof (host_definition_t));
+  hd->version = 2;
+
+  hd->name = strdup (ci->values[0].value.string);
+  if (hd->name == NULL)
+  {
+    free (hd);
+    return (-1);
+  }
+
+  hd->sess_handle = NULL;
+  hd->skip_num = 0;
+  hd->skip_left = 0;
+  hd->state = STATE_IDLE;
+
+  for (i = 0; i < ci->children_num; i++)
+  {
+    oconfig_item_t *option = ci->children + i;
+    status = 0;
+
+    if (strcasecmp ("Address", option->key) == 0)
+      status = csnmp_config_add_host_address (hd, option);
+    else if (strcasecmp ("Community", option->key) == 0)
+      status = csnmp_config_add_host_community (hd, option);
+    else if (strcasecmp ("Version", option->key) == 0)
+      status = csnmp_config_add_host_version (hd, option);
+    else if (strcasecmp ("Collect", option->key) == 0)
+      csnmp_config_add_host_collect (hd, option);
+    else if (strcasecmp ("Interval", option->key) == 0)
+      csnmp_config_add_host_interval (hd, option);
+    else
+    {
+      WARNING ("snmp plugin: csnmp_config_add_host: Option `%s' not allowed here.", option->key);
+      status = -1;
+    }
+
+    if (status != 0)
+      break;
+  } /* for (ci->children) */
+
+  while (status == 0)
+  {
+    if (hd->address == NULL)
+    {
+      WARNING ("snmp plugin: `Address' not given for host `%s'", hd->name);
+      status = -1;
+      break;
+    }
+    if (hd->community == NULL)
+    {
+      WARNING ("snmp plugin: `Community' not given for host `%s'", hd->name);
+      status = -1;
+      break;
+    }
+
+    break;
+  } /* while (status == 0) */
+
+  if (status != 0)
+  {
+    sfree (hd->name);
+    sfree (hd);
+    return (-1);
+  }
+
+  DEBUG ("snmp plugin: hd = { name = %s, address = %s, community = %s, version = %i }",
+      hd->name, hd->address, hd->community, hd->version);
+
+  if (host_head == NULL)
+    host_head = hd;
+  else
+  {
+    host_definition_t *last;
+    last = host_head;
+    while (last->next != NULL)
+      last = last->next;
+    last->next = hd;
+  }
+
+  return (0);
+} /* int csnmp_config_add_host */
+
+static int csnmp_config (oconfig_item_t *ci)
+{
+  int i;
+
+  call_snmp_init_once ();
+
+  for (i = 0; i < ci->children_num; i++)
+  {
+    oconfig_item_t *child = ci->children + i;
+    if (strcasecmp ("Data", child->key) == 0)
+      csnmp_config_add_data (child);
+    else if (strcasecmp ("Host", child->key) == 0)
+      csnmp_config_add_host (child);
+    else
+    {
+      WARNING ("snmp plugin: Ignoring unknown config option `%s'.", child->key);
+    }
+  } /* for (ci->children) */
+
+  return (0);
+} /* int csnmp_config */
+
+/* End of the config stuff. Now the interesting part begins */
+
+static void csnmp_host_close_session (host_definition_t *host)
+{
+  int status;
+
+  if (host->sess_handle == NULL)
+    return;
+
+  status = snmp_sess_close (host->sess_handle);
+
+  if (status != 0)
+  {
+    char *errstr = NULL;
+
+    snmp_sess_error (host->sess_handle, NULL, NULL, &errstr);
+
+    ERROR ("snmp plugin: snmp_sess_close failed: %s",
+       (errstr == NULL) ? "Unknown problem" : errstr);
+    sfree (errstr);
+  }
+
+  host->sess_handle = NULL;
+} /* void csnmp_host_close_session */
+
+static void csnmp_host_open_session (host_definition_t *host)
+{
+  struct snmp_session sess;
+
+  if (host->sess_handle != NULL)
+    csnmp_host_close_session (host);
+
+  snmp_sess_init (&sess);
+  sess.peername = host->address;
+  sess.community = (u_char *) host->community;
+  sess.community_len = strlen (host->community);
+  sess.version = (host->version == 1) ? SNMP_VERSION_1 : SNMP_VERSION_2c;
+
+  /* snmp_sess_open will copy the `struct snmp_session *'. */
+  host->sess_handle = snmp_sess_open (&sess);
+
+  if (host->sess_handle == NULL)
+  {
+    char *errstr = NULL;
+
+    snmp_error (&sess, NULL, NULL, &errstr);
+
+    ERROR ("snmp plugin: snmp_sess_open failed: %s",
+       (errstr == NULL) ? "Unknown problem" : errstr);
+    sfree (errstr);
+  }
+} /* void csnmp_host_open_session */
+
+static value_t csnmp_value_list_to_value (struct variable_list *vl, int type)
+{
+  value_t ret;
+  uint64_t temp = 0;
+  int defined = 1;
+
+  if ((vl->type == ASN_INTEGER)
+      || (vl->type == ASN_UINTEGER)
+      || (vl->type == ASN_COUNTER)
+      || (vl->type == ASN_GAUGE))
+  {
+    temp = (uint32_t) *vl->val.integer;
+    DEBUG ("snmp plugin: Parsed int32 value is %llu.", temp);
+  }
+  else if (vl->type == ASN_COUNTER64)
+  {
+    temp = (uint32_t) vl->val.counter64->high;
+    temp = temp << 32;
+    temp += (uint32_t) vl->val.counter64->low;
+    DEBUG ("snmp plugin: Parsed int64 value is %llu.", temp);
+  }
+  else
+  {
+    WARNING ("snmp plugin: I don't know the ASN type `%i'", (int) vl->type);
+    defined = 0;
+  }
+
+  if (type == DS_TYPE_COUNTER)
+  {
+    ret.counter = temp;
+  }
+  else if (type == DS_TYPE_GAUGE)
+  {
+    ret.gauge = NAN;
+    if (defined != 0)
+      ret.gauge = temp;
+  }
+
+  return (ret);
+} /* value_t csnmp_value_list_to_value */
+
+static int csnmp_dispatch_table (host_definition_t *host, data_definition_t *data,
+    csnmp_list_instances_t *instance_list,
+    csnmp_table_values_t **value_table)
+{
+  const data_set_t *ds;
+  value_list_t vl = VALUE_LIST_INIT;
+
+  csnmp_list_instances_t *instance_list_ptr;
+  csnmp_table_values_t **value_table_ptr;
+
+  int i;
+
+  ds = plugin_get_ds (data->type);
+  if (!ds)
+  {
+    ERROR ("snmp plugin: DataSet `%s' not defined.", data->type);
+    return (-1);
+  }
+  assert (ds->ds_num == data->values_len);
+
+  value_table_ptr = (csnmp_table_values_t **) malloc (sizeof (csnmp_table_values_t *)
+      * data->values_len);
+  if (value_table_ptr == NULL)
+    return (-1);
+  for (i = 0; i < data->values_len; i++)
+    value_table_ptr[i] = value_table[i];
+
+  vl.values_len = ds->ds_num;
+  vl.values = (value_t *) malloc (sizeof (value_t) * vl.values_len);
+  if (vl.values == NULL)
+  {
+    sfree (value_table_ptr);
+    return (-1);
+  }
+
+  strncpy (vl.host, host->name, sizeof (vl.host));
+  vl.host[sizeof (vl.host) - 1] = '\0';
+  strcpy (vl.plugin, "snmp");
+
+  vl.interval = host->skip_num;
+  vl.time = time (NULL);
+
+  for (instance_list_ptr = instance_list;
+      instance_list_ptr != NULL;
+      instance_list_ptr = instance_list_ptr->next)
+  {
+    strncpy (vl.type_instance, instance_list_ptr->instance, sizeof (vl.type_instance));
+    vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
+
+    for (i = 0; i < data->values_len; i++)
+    {
+      while ((value_table_ptr[i] != NULL)
+         && (value_table_ptr[i]->subid < instance_list_ptr->subid))
+       value_table_ptr[i] = value_table_ptr[i]->next;
+      if ((value_table_ptr[i] == NULL)
+         || (value_table_ptr[i]->subid != instance_list_ptr->subid))
+       break;
+      vl.values[i] = value_table_ptr[i]->value;
+    } /* for (data->values_len) */
+
+    /* If the for-loop was aborted early, not all subid's match. */
+    if (i < data->values_len)
+    {
+      DEBUG ("snmp plugin: host = %s; data = %s; i = %i; "
+         "Skipping SUBID %i",
+         host->name, data->name, i, instance_list_ptr->subid);
+      continue;
+    }
+
+    /* If we get here `vl.type_instance' and all `vl.values' have been set */
+    plugin_dispatch_values (data->type, &vl);
+  } /* for (instance_list) */
+
+  sfree (vl.values);
+  sfree (value_table_ptr);
+
+  return (0);
+} /* int csnmp_dispatch_table */
+
+static int csnmp_read_table (host_definition_t *host, data_definition_t *data)
+{
+  struct snmp_pdu *req;
+  struct snmp_pdu *res;
+  struct variable_list *vb;
+
+  const data_set_t *ds;
+  oid_t *oid_list;
+  uint32_t oid_list_len;
+
+  int status;
+  int i;
+
+  /* `value_table' and `value_table_ptr' implement a linked list for each
+   * value. `instance_list' and `instance_list_ptr' implement a linked list of
+   * instance names. This is used to jump gaps in the table. */
+  csnmp_list_instances_t *instance_list;
+  csnmp_list_instances_t *instance_list_ptr;
+  csnmp_table_values_t **value_table;
+  csnmp_table_values_t **value_table_ptr;
+
+  DEBUG ("snmp plugin: csnmp_read_table (host = %s, data = %s)",
+      host->name, data->name);
+
+  ds = plugin_get_ds (data->type);
+  if (!ds)
+  {
+    ERROR ("snmp plugin: DataSet `%s' not defined.", data->type);
+    return (-1);
+  }
+
+  if (ds->ds_num != data->values_len)
+  {
+    ERROR ("snmp plugin: DataSet `%s' requires %i values, but config talks about %i",
+       data->type, ds->ds_num, data->values_len);
+    return (-1);
+  }
+
+  /* We need a copy of all the OIDs, because GETNEXT will destroy them. */
+  oid_list_len = data->values_len + 1;
+  oid_list = (oid_t *) malloc (sizeof (oid_t) * (oid_list_len));
+  if (oid_list == NULL)
+    return (-1);
+  memcpy (oid_list, &data->instance.oid, sizeof (oid_t));
+  for (i = 0; i < data->values_len; i++)
+    memcpy (oid_list + (i + 1), data->values + i, sizeof (oid_t));
+
+  /* Allocate the `value_table' */
+  value_table = (csnmp_table_values_t **) malloc (sizeof (csnmp_table_values_t *)
+      * 2 * data->values_len);
+  if (value_table == NULL)
+  {
+    sfree (oid_list);
+    return (-1);
+  }
+  memset (value_table, '\0', sizeof (csnmp_table_values_t *) * 2 * data->values_len);
+  value_table_ptr = value_table + data->values_len;
+  
+  instance_list = NULL;
+  instance_list_ptr = NULL;
+
+  status = 0;
+  while (status == 0)
+  {
+    csnmp_list_instances_t *il;
+
+    req = snmp_pdu_create (SNMP_MSG_GETNEXT);
+    if (req == NULL)
+    {
+      ERROR ("snmp plugin: snmp_pdu_create failed.");
+      status = -1;
+      break;
+    }
+
+    for (i = 0; i < oid_list_len; i++)
+      snmp_add_null_var (req, oid_list[i].oid, oid_list[i].oid_len);
+
+    status = snmp_sess_synch_response (host->sess_handle, req, &res);
+
+    if (status != STAT_SUCCESS)
+    {
+      char *errstr = NULL;
+
+      snmp_sess_error (host->sess_handle, NULL, NULL, &errstr);
+      ERROR ("snmp plugin: snmp_sess_synch_response failed: %s",
+         (errstr == NULL) ? "Unknown problem" : errstr);
+      csnmp_host_close_session (host);
+
+      status = -1;
+      break;
+    }
+    status = 0;
+    assert (res != NULL);
+
+    vb = res->variables;
+    if (vb == NULL)
+    {
+      status = -1;
+      break;
+    }
+
+    /* Check if we left the subtree */
+    if (snmp_oid_ncompare (data->instance.oid.oid, data->instance.oid.oid_len,
+         vb->name, vb->name_length,
+         data->instance.oid.oid_len) != 0)
+      break;
+
+    /* Allocate a new `csnmp_list_instances_t', insert the instance name and
+     * add it to the list */
+    il = (csnmp_list_instances_t *) malloc (sizeof (csnmp_list_instances_t));
+    if (il == NULL)
+    {
+      status = -1;
+      break;
+    }
+    il->subid = vb->name[vb->name_length - 1];
+    il->next = NULL;
+
+    /* Get instance name */
+    if ((vb->type == ASN_OCTET_STR) || (vb->type == ASN_BIT_STR))
+    {
+      char *ptr;
+      size_t instance_len;
+
+      instance_len = sizeof (il->instance) - 1;
+      if (instance_len > vb->val_len)
+       instance_len = vb->val_len;
+
+      strncpy (il->instance, (char *) ((vb->type == ASN_OCTET_STR)
+           ? vb->val.string
+           : vb->val.bitstring),
+         instance_len);
+      il->instance[instance_len] = '\0';
+
+      for (ptr = il->instance; *ptr != '\0'; ptr++)
+      {
+       if ((*ptr > 0) && (*ptr < 32))
+         *ptr = ' ';
+       else if (*ptr == '/')
+         *ptr = '_';
+      }
+      DEBUG ("snmp plugin: il->instance = `%s';", il->instance);
+    }
+    else
+    {
+      value_t val = csnmp_value_list_to_value (vb, DS_TYPE_COUNTER);
+      snprintf (il->instance, sizeof (il->instance),
+         "%llu", val.counter);
+    }
+    il->instance[sizeof (il->instance) - 1] = '\0';
+    DEBUG ("snmp plugin: data = `%s'; il->instance = `%s';",
+       data->name, il->instance);
+
+    if (instance_list_ptr == NULL)
+      instance_list = il;
+    else
+      instance_list_ptr->next = il;
+    instance_list_ptr = il;
+
+    /* Copy OID to oid_list[0] */
+    memcpy (oid_list[0].oid, vb->name, sizeof (oid) * vb->name_length);
+    oid_list[0].oid_len = vb->name_length;
+
+    for (i = 0; i < data->values_len; i++)
+    {
+      csnmp_table_values_t *vt;
+
+      vb = vb->next_variable;
+      if (vb == NULL)
+      {
+       status = -1;
+       break;
+      }
+
+      /* Check if we left the subtree */
+      if (snmp_oid_ncompare (data->values[i].oid,
+           data->values[i].oid_len,
+           vb->name, vb->name_length,
+           data->values[i].oid_len) != 0)
+      {
+       DEBUG ("snmp plugin: host = %s; data = %s; Value %i left its subtree.",
+           host->name, data->name, i);
+       continue;
+      }
+
+      if ((value_table_ptr[i] != NULL)
+         && (vb->name[vb->name_length - 1] <= value_table_ptr[i]->subid))
+      {
+       DEBUG ("snmp plugin: host = %s; data = %s; i = %i; SUBID is not increasing.",
+           host->name, data->name, i);
+       continue;
+      }
+
+      vt = (csnmp_table_values_t *) malloc (sizeof (csnmp_table_values_t));
+      if (vt != NULL)
+      {
+       vt->subid = vb->name[vb->name_length - 1];
+       vt->value = csnmp_value_list_to_value (vb, ds->ds[i].type);
+       vt->next = NULL;
+
+       if (value_table_ptr[i] == NULL)
+         value_table[i] = vt;
+       else
+         value_table_ptr[i]->next = vt;
+       value_table_ptr[i] = vt;
+      }
+
+      /* Copy OID to oid_list[i + 1] */
+      memcpy (oid_list[i + 1].oid, vb->name, sizeof (oid) * vb->name_length);
+      oid_list[i + 1].oid_len = vb->name_length;
+    } /* for (i = data->values_len) */
+
+    if (res != NULL)
+      snmp_free_pdu (res);
+    res = NULL;
+  } /* while (status == 0) */
+
+  if (status == 0)
+    csnmp_dispatch_table (host, data, instance_list, value_table);
+
+  /* Free all allocated variables here */
+  while (instance_list != NULL)
+  {
+    instance_list_ptr = instance_list->next;
+    sfree (instance_list);
+    instance_list = instance_list_ptr;
+  }
+
+  for (i = 0; i < data->values_len; i++)
+  {
+    csnmp_table_values_t *tmp;
+    while (value_table[i] != NULL)
+    {
+      tmp = value_table[i]->next;
+      sfree (value_table[i]);
+      value_table[i] = tmp;
+    }
+  }
+
+  sfree (value_table);
+  sfree (oid_list);
+
+  return (0);
+} /* int csnmp_read_table */
+
+static int csnmp_read_value (host_definition_t *host, data_definition_t *data)
+{
+  struct snmp_pdu *req;
+  struct snmp_pdu *res;
+  struct variable_list *vb;
+
+  const data_set_t *ds;
+  value_list_t vl = VALUE_LIST_INIT;
+
+  int status;
+  int i;
+
+  DEBUG ("snmp plugin: csnmp_read_value (host = %s, data = %s)",
+      host->name, data->name);
+
+  ds = plugin_get_ds (data->type);
+  if (!ds)
+  {
+    ERROR ("snmp plugin: DataSet `%s' not defined.", data->type);
+    return (-1);
+  }
+
+  if (ds->ds_num != data->values_len)
+  {
+    ERROR ("snmp plugin: DataSet `%s' requires %i values, but config talks about %i",
+       data->type, ds->ds_num, data->values_len);
+    return (-1);
+  }
+
+  vl.values_len = ds->ds_num;
+  vl.values = (value_t *) malloc (sizeof (value_t) * vl.values_len);
+  if (vl.values == NULL)
+    return (-1);
+  for (i = 0; i < vl.values_len; i++)
+  {
+    if (ds->ds[i].type == DS_TYPE_COUNTER)
+      vl.values[i].counter = 0;
+    else
+      vl.values[i].gauge = NAN;
+  }
+
+  strncpy (vl.host, host->name, sizeof (vl.host));
+  vl.host[sizeof (vl.host) - 1] = '\0';
+  strcpy (vl.plugin, "snmp");
+  strncpy (vl.type_instance, data->instance.string, sizeof (vl.type_instance));
+  vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
+
+  vl.interval = host->skip_num;
+
+  req = snmp_pdu_create (SNMP_MSG_GET);
+  if (req == NULL)
+  {
+    ERROR ("snmp plugin: snmp_pdu_create failed.");
+    sfree (vl.values);
+    return (-1);
+  }
+
+  for (i = 0; i < data->values_len; i++)
+    snmp_add_null_var (req, data->values[i].oid, data->values[i].oid_len);
+  status = snmp_sess_synch_response (host->sess_handle, req, &res);
+
+  if (status != STAT_SUCCESS)
+  {
+    char *errstr = NULL;
+
+    snmp_sess_error (host->sess_handle, NULL, NULL, &errstr);
+    ERROR ("snmp plugin: snmp_sess_synch_response failed: %s",
+       (errstr == NULL) ? "Unknown problem" : errstr);
+    csnmp_host_close_session (host);
+    sfree (errstr);
+
+    return (-1);
+  }
+
+  vl.time = time (NULL);
+
+  for (vb = res->variables; vb != NULL; vb = vb->next_variable)
+  {
+    char buffer[1024];
+    snprint_variable (buffer, sizeof (buffer),
+       vb->name, vb->name_length, vb);
+    DEBUG ("snmp plugin: Got this variable: %s", buffer);
+
+    for (i = 0; i < data->values_len; i++)
+      if (snmp_oid_compare (data->values[i].oid, data->values[i].oid_len,
+           vb->name, vb->name_length) == 0)
+       vl.values[i] = csnmp_value_list_to_value (vb, ds->ds[i].type);
+  } /* for (res->variables) */
+
+  snmp_free_pdu (res);
+
+  DEBUG ("snmp plugin: -> plugin_dispatch_values (%s, &vl);", data->type);
+  plugin_dispatch_values (data->type, &vl);
+  sfree (vl.values);
+
+  return (0);
+} /* int csnmp_read_value */
+
+static int csnmp_read_host (host_definition_t *host)
+{
+  int i;
+
+  DEBUG ("snmp plugin: csnmp_read_host (%s);", host->name);
+
+  if (host->sess_handle == NULL)
+    csnmp_host_open_session (host);
+
+  if (host->sess_handle == NULL)
+    return (-1);
+
+  for (i = 0; i < host->data_list_len; i++)
+  {
+    data_definition_t *data = host->data_list[i];
+
+    if (data->is_table)
+      csnmp_read_table (host, data);
+    else
+      csnmp_read_value (host, data);
+  }
+
+  return (0);
+} /* int csnmp_read_host */
+
+static void *csnmp_read_thread (void *data)
+{
+  host_definition_t *host;
+
+  pthread_mutex_lock (&host_lock);
+  while (do_shutdown == 0)
+  {
+    pthread_cond_wait (&host_cond, &host_lock);
+
+    for (host = host_head; host != NULL; host = host->next)
+    {
+      if (do_shutdown != 0)
+       break;
+      if (host->state != STATE_WAIT)
+       continue;
+
+      host->state = STATE_BUSY;
+      pthread_mutex_unlock (&host_lock);
+      csnmp_read_host (host);
+      pthread_mutex_lock (&host_lock);
+      host->state = STATE_IDLE;
+    } /* for (host) */
+  } /* while (do_shutdown == 0) */
+  pthread_mutex_unlock (&host_lock);
+
+  pthread_exit ((void *) 0);
+  return ((void *) 0);
+} /* void *csnmp_read_thread */
+
+static int csnmp_init (void)
+{
+  host_definition_t *host;
+  int i;
+
+  if (host_head == NULL)
+    return (-1);
+
+  call_snmp_init_once ();
+
+  threads_num = 0;
+  for (host = host_head; host != NULL; host = host->next)
+  {
+    threads_num++;
+    /* We need to initialize `skip_num' here, because `interval_g' isn't
+     * initialized during `configure'. */
+    host->skip_left = interval_g;
+    if (host->skip_num == 0)
+    {
+      host->skip_num = interval_g;
+    }
+    else if (host->skip_num < interval_g)
+    {
+      host->skip_num = interval_g;
+      WARNING ("snmp plugin: Data for host `%s' will be collected every %i seconds.",
+         host->name, host->skip_num);
+    }
+
+    csnmp_host_open_session (host);
+  } /* for (host) */
+
+  /* Now start the reading threads */
+  if (threads_num > 3)
+  {
+    threads_num = 3 + ((threads_num - 3) / 10);
+    if (threads_num > 10)
+      threads_num = 10;
+  }
+
+  threads = (pthread_t *) malloc (threads_num * sizeof (pthread_t));
+  if (threads == NULL)
+    return (-1);
+  memset (threads, '\0', threads_num * sizeof (pthread_t));
+
+  for (i = 0; i < threads_num; i++)
+      pthread_create (threads + i, NULL, csnmp_read_thread, (void *) 0);
+
+  return (0);
+} /* int csnmp_init */
+
+static int csnmp_read (void)
+{
+  host_definition_t *host;
+  time_t now;
+
+  if (host_head == NULL)
+  {
+    INFO ("snmp plugin: No hosts configured.");
+    return (-1);
+  }
+
+  now = time (NULL);
+
+  pthread_mutex_lock (&host_lock);
+  for (host = host_head; host != NULL; host = host->next)
+  {
+    if (host->state != STATE_IDLE)
+      continue;
+
+    host->skip_left -= interval_g;
+    if (host->skip_left >= interval_g)
+      continue;
+
+    host->state = STATE_WAIT;
+
+    host->skip_left = host->skip_num;
+  } /* for (host) */
+
+  pthread_cond_broadcast (&host_cond);
+  pthread_mutex_unlock (&host_lock);
+
+  return (0);
+} /* int csnmp_read */
+
+static int csnmp_shutdown (void)
+{
+  host_definition_t *host_this;
+  host_definition_t *host_next;
+
+  data_definition_t *data_this;
+  data_definition_t *data_next;
+
+  int i;
+
+  pthread_mutex_lock (&host_lock);
+  do_shutdown = 1;
+  pthread_cond_broadcast (&host_cond);
+  pthread_mutex_unlock (&host_lock);
+
+  for (i = 0; i < threads_num; i++)
+    pthread_join (threads[i], NULL);
+
+  /* Now that all the threads have exited, let's free all the global variables.
+   * This isn't really neccessary, I guess, but I think it's good stile to do
+   * so anyway. */
+  host_this = host_head;
+  host_head = NULL;
+  while (host_this != NULL)
+  {
+    host_next = host_this->next;
+
+    csnmp_host_close_session (host_this);
+
+    sfree (host_this->name);
+    sfree (host_this->address);
+    sfree (host_this->community);
+    sfree (host_this->data_list);
+    sfree (host_this);
+
+    host_this = host_next;
+  }
+
+  data_this = data_head;
+  data_head = NULL;
+  while (data_this != NULL)
+  {
+    data_next = data_this->next;
+
+    sfree (data_this->name);
+    sfree (data_this->type);
+    sfree (data_this->values);
+    sfree (data_this);
+
+    data_this = data_next;
+  }
+
+  return (0);
+} /* int csnmp_shutdown */
+
+void module_register (void)
+{
+  plugin_register_complex_config ("snmp", csnmp_config);
+  plugin_register_init ("snmp", csnmp_init);
+  plugin_register_read ("snmp", csnmp_read);
+  plugin_register_shutdown ("snmp", csnmp_shutdown);
+} /* void module_register */
+
+/*
+ * vim: shiftwidth=2 softtabstop=2 tabstop=8
+ */
index 3018cb9..4a414b7 100644 (file)
 #  include <kvm.h>
 #endif
 
-#if KERNEL_LINUX || HAVE_LIBKSTAT || defined(VM_SWAPUSAGE) || HAVE_LIBKVM || HAVE_LIBSTATGRAB
-# define SWAP_HAVE_READ 1
-#else
-# define SWAP_HAVE_READ 0
-#endif
-
 #undef  MAX
 #define MAX(x,y) ((x) > (y) ? (x) : (y))
 
-#if SWAP_HAVE_READ
 #if KERNEL_LINUX
 /* No global variables */
 /* #endif KERNEL_LINUX */
@@ -66,6 +59,10 @@ int kvm_pagesize;
 
 #elif HAVE_LIBSTATGRAB
 /* No global variables */
+/* #endif HAVE_LIBSTATGRAB */
+
+#else
+# error "No applicable input method."
 #endif /* HAVE_LIBSTATGRAB */
 
 static int swap_init (void)
@@ -300,12 +297,9 @@ static int swap_read (void)
 
        return (0);
 } /* int swap_read */
-#endif /* SWAP_HAVE_READ */
 
 void module_register (void)
 {
-#if SWAP_HAVE_READ
        plugin_register_init ("swap", swap_init);
        plugin_register_read ("swap", swap_read);
-#endif /* SWAP_HAVE_READ */
 } /* void module_register */
index 5e01f0d..465688e 100644 (file)
 #include "common.h"
 #include "plugin.h"
 
-#if defined(HAVE_LIBKSTAT)
-# define TAPE_HAVE_READ 1
-#else
-# define TAPE_HAVE_READ 0
+#if !HAVE_LIBKSTAT
+# error "No applicable input method."
 #endif
 
-#if TAPE_HAVE_READ
-#if defined(HAVE_LIBKSTAT)
 #define MAX_NUMTAPE 256
 extern kstat_ctl_t *kc;
 static kstat_t *ksp[MAX_NUMTAPE];
 static int numtape = 0;
-#endif /* HAVE_LIBKSTAT */
 
 static int tape_init (void)
 {
-#ifdef HAVE_LIBKSTAT
        kstat_t *ksp_chain;
 
        numtape = 0;
@@ -58,10 +52,9 @@ static int tape_init (void)
                        continue;
                ksp[numtape++] = ksp_chain;
        }
-#endif
 
        return (0);
-}
+} /* int tape_init */
 
 static void tape_submit (const char *plugin_instance,
                const char *type,
@@ -87,24 +80,23 @@ static void tape_submit (const char *plugin_instance,
 static int tape_read (void)
 {
 
-#if defined(HAVE_LIBKSTAT)
-# if HAVE_KSTAT_IO_T_WRITES && HAVE_KSTAT_IO_T_NWRITES && HAVE_KSTAT_IO_T_WTIME
-#  define KIO_ROCTETS reads
-#  define KIO_WOCTETS writes
-#  define KIO_ROPS    nreads
-#  define KIO_WOPS    nwrites
-#  define KIO_RTIME   rtime
-#  define KIO_WTIME   wtime
-# elif HAVE_KSTAT_IO_T_NWRITTEN && HAVE_KSTAT_IO_T_WRITES && HAVE_KSTAT_IO_T_WTIME
-#  define KIO_ROCTETS nread
-#  define KIO_WOCTETS nwritten
-#  define KIO_ROPS    reads
-#  define KIO_WOPS    writes
-#  define KIO_RTIME   rtime
-#  define KIO_WTIME   wtime
-# else
-#  error "kstat_io_t does not have the required members"
-# endif
+#if HAVE_KSTAT_IO_T_WRITES && HAVE_KSTAT_IO_T_NWRITES && HAVE_KSTAT_IO_T_WTIME
+# define KIO_ROCTETS reads
+# define KIO_WOCTETS writes
+# define KIO_ROPS    nreads
+# define KIO_WOPS    nwrites
+# define KIO_RTIME   rtime
+# define KIO_WTIME   wtime
+#elif HAVE_KSTAT_IO_T_NWRITTEN && HAVE_KSTAT_IO_T_WRITES && HAVE_KSTAT_IO_T_WTIME
+# define KIO_ROCTETS nread
+# define KIO_WOCTETS nwritten
+# define KIO_ROPS    reads
+# define KIO_WOPS    writes
+# define KIO_RTIME   rtime
+# define KIO_WTIME   wtime
+#else
+# error "kstat_io_t does not have the required members"
+#endif
        static kstat_io_t kio;
        int i;
 
@@ -130,16 +122,12 @@ static int tape_read (void)
                                        kio.KIO_RTIME, kio.KIO_WTIME);
                }
        }
-#endif /* defined(HAVE_LIBKSTAT) */
 
        return (0);
 }
-#endif /* TAPE_HAVE_READ */
 
 void module_register (void)
 {
-#if TAPE_HAVE_READ
        plugin_register_init ("tape", tape_init);
        plugin_register_read ("tape", tape_read);
-#endif /* TAPE_HAVE_READ */
 }
index 68b966b..e193205 100644 (file)
@@ -2,6 +2,7 @@ apache_bytes            count:COUNTER:0:134217728
 apache_connections     count:GAUGE:0:65535
 apache_requests                count:COUNTER:0:134217728
 apache_scoreboard      count:GAUGE:0:65535
+bitrate                        value:GAUGE:0:4294967295
 charge                 value:GAUGE:0:U
 counter                        value:COUNTER:U:U
 cpu                    value:COUNTER:0:4294967295
index 215abdd..82c15a8 100644 (file)
@@ -36,7 +36,7 @@
 # define UNIX_PATH_MAX sizeof (((struct sockaddr_un *)0)->sun_path)
 #endif
 
-#define US_DEFAULT_PATH PREFIX"/var/run/"PACKAGE_NAME"-unixsock"
+#define US_DEFAULT_PATH LOCALSTATEDIR"/run/"PACKAGE_NAME"-unixsock"
 
 /*
  * Private data structures
@@ -329,7 +329,7 @@ static void cache_flush (int max_age)
        } /* while (this != NULL) */
 
        pthread_mutex_unlock (&cache_lock);
-} /* int cache_flush */
+} /* void cache_flush */
 
 static int us_open_socket (void)
 {
@@ -630,6 +630,56 @@ static int us_handle_putval (FILE *fh, char **fields, int fields_num)
        return (0);
 } /* int us_handle_putval */
 
+static int us_handle_listval (FILE *fh, char **fields, int fields_num)
+{
+       char buffer[1024];
+       char **value_list = NULL;
+       int value_list_len = 0;
+       value_cache_t *entry;
+       int i;
+
+       if (fields_num != 1)
+       {
+               DEBUG ("unixsock plugin: us_handle_listval: "
+                               "Wrong number of fields: %i", fields_num);
+               fprintf (fh, "-1 Wrong number of fields: Got %i, expected 1.\n",
+                               fields_num);
+               fflush (fh);
+               return (-1);
+       }
+
+       pthread_mutex_lock (&cache_lock);
+
+       for (entry = cache_head; entry != NULL; entry = entry->next)
+       {
+               char **tmp;
+
+               snprintf (buffer, sizeof (buffer), "%u %s\n",
+                               (unsigned int) entry->time, entry->name);
+               buffer[sizeof (buffer) - 1] = '\0';
+               
+               tmp = realloc (value_list, sizeof (char *) * (value_list_len + 1));
+               if (tmp == NULL)
+                       continue;
+               value_list = tmp;
+
+               value_list[value_list_len] = strdup (buffer);
+
+               if (value_list[value_list_len] != NULL)
+                       value_list_len++;
+       } /* for (entry) */
+
+       pthread_mutex_unlock (&cache_lock);
+
+       DEBUG ("unixsock plugin: us_handle_listval: value_list_len = %i", value_list_len);
+       fprintf (fh, "%i Values found\n", value_list_len);
+       for (i = 0; i < value_list_len; i++)
+               fputs (value_list[i], fh);
+       fflush (fh);
+
+       return (0);
+} /* int us_handle_listval */
+
 static void *us_handle_client (void *arg)
 {
        int fd;
@@ -685,6 +735,10 @@ static void *us_handle_client (void *arg)
                {
                        us_handle_putval (fh, fields, fields_num);
                }
+               else if (strcasecmp (fields[0], "listval") == 0)
+               {
+                       us_handle_listval (fh, fields, fields_num);
+               }
                else
                {
                        fprintf (fh, "-1 Unknown command: %s\n", fields[0]);
index 7df06c2..afe26e1 100644 (file)
 
 #if HAVE_UTMPX_H
 # include <utmpx.h>
-#else /* !HAVE_UTMPX_H */
-# if HAVE_UTMP_H
-#  include <utmp.h>
-# endif /* HAVE_UTMP_H */
-#endif /* HAVE_UTMPX_H */
+/* #endif HAVE_UTMPX_H */
 
-#define MODULE_NAME "users"
+#elif HAVE_UTMP_H
+# include <utmp.h>
+/* #endif HAVE_UTMP_H */
 
-#if HAVE_GETUTXENT || HAVE_GETUTENT
-# define USERS_HAVE_READ 1
 #else
-# define USERS_HAVE_READ 0
+# error "No applicable input method."
 #endif
 
-#if USERS_HAVE_READ
 static void users_submit (gauge_t value)
 {
        value_t values[1];
@@ -92,15 +87,16 @@ static int users_read (void)
        endutent();
 
        users_submit (users);
-#endif /* HAVE_GETUTENT */
+/* #endif HAVE_GETUTENT */
+
+#else
+# error "No applicable input method."
+#endif
 
        return (0);
 } /* int users_read */
-#endif /* USERS_HAVE_READ */
 
 void module_register (void)
 {
-#if USERS_HAVE_READ
        plugin_register_read ("users", users_read);
-#endif
 } /* void module_register(void) */
index 8d524e7..7b83c61 100644 (file)
 
 #define BUFSIZE 512
 
-#define MODULE_NAME "vserver"
 #define PROCDIR "/proc/virtual"
 
-#if defined(KERNEL_LINUX)
-# define VSERVER_HAVE_READ 1
-#else
-# define VSERVER_HAVE_READ 0
-#endif /* defined(KERNEL_LINUX) */
+#if !KERNEL_LINUX
+# error "No applicable input method."
+#endif
 
-#if VSERVER_HAVE_READ
 static int pagesize = 0;
 
 static int vserver_init (void)
@@ -306,14 +302,11 @@ static int vserver_read (void)
 
        return (0);
 } /* int vserver_read */
-#endif /* VSERVER_HAVE_READ */
 
 void module_register (void)
 {
-#if VSERVER_HAVE_READ
        plugin_register_init ("vserver", vserver_init);
        plugin_register_read ("vserver", vserver_read);
-#endif /* VSERVER_HAVE_READ */
 } /* void module_register(void) */
 
 /* vim: set ts=4 sw=4 noexpandtab : */
index 81c968e..09df407 100644 (file)
 #include "common.h"
 #include "plugin.h"
 
-#if defined(KERNEL_LINUX)
-# define WIRELESS_HAVE_READ 1
-#else
-# define WIRELESS_HAVE_READ 0
+#if !KERNEL_LINUX
+# error "No applicable input method."
 #endif
 
 #define WIRELESS_PROC_FILE "/proc/net/wireless"
 
-#if WIRELESS_HAVE_READ
 #if 0
 static double wireless_dbm_to_watt (double dbm)
 {
@@ -140,11 +137,8 @@ static int wireless_read (void)
 
        return (0);
 } /* int wireless_read */
-#endif /* WIRELESS_HAVE_READ */
 
 void module_register (void)
 {
-#if WIRELESS_HAVE_READ
        plugin_register_read ("wireless", wireless_read);
-#endif /* WIRELESS_HAVE_READ */
 } /* void module_register */
diff --git a/src/xmms.c b/src/xmms.c
new file mode 100644 (file)
index 0000000..238a8ee
--- /dev/null
@@ -0,0 +1,73 @@
+/**
+ * collectd - src/xmms.c
+ * Copyright (C) 2007  Florian octo Forster
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; only version 2 of the License is applicable.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ *
+ * Authors:
+ *   Florian octo Forster <octo at verplant.org>
+ **/
+
+#include "collectd.h"
+#include "plugin.h"
+#include "common.h"
+
+#include <xmms/xmmsctrl.h>
+
+static gint xmms_session;
+
+static void cxmms_submit (const char *type, 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;
+       vl.time = time (NULL);
+       strcpy (vl.host, hostname_g);
+       strcpy (vl.plugin, "xmms");
+
+       plugin_dispatch_values (type, &vl);
+} /* void cxmms_submit */
+
+int cxmms_read (void)
+{
+  gint rate;
+  gint freq;
+  gint nch;
+
+  if (!xmms_remote_is_running (xmms_session))
+    return (0);
+
+  xmms_remote_get_info (xmms_session, &rate, &freq, &nch);
+
+  if ((freq == 0) || (nch == 0))
+    return (0);
+
+  cxmms_submit ("bitrate", rate);
+  cxmms_submit ("frequency", freq);
+
+  return (0);
+} /* int read */
+
+void module_register (void)
+{
+  plugin_register_read ("xmms", cxmms_read);
+} /* void module_register */
+
+/*
+ * vim: shiftwidth=2:softtabstop=2:textwidth=78
+ */