author | Florian Forster <octo@huhu.verplant.org> | |
Sun, 9 Jul 2006 08:16:49 +0000 (10:16 +0200) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Sun, 9 Jul 2006 08:16:49 +0000 (10:16 +0200) |
32 files changed:
diff --git a/.gitignore b/.gitignore
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,58 @@
+# svn stuff:
+.svn
+contrib/.svn
+debian/.svn
+src/.svn
+src/libconfig/.svn
+src/liboping/.svn
+
+# build.sh stuff:
+INSTALL
+Makefile.in
+aclocal.m4
+autom4te.cache
+compile
+config.guess
+config.sub
+configure
+depcomp
+install-sh
+libltdl
+ltmain.sh
+missing
+src/Makefile.in
+src/config.h.in
+src/libconfig/Makefile.in
+src/liboping/Makefile.in
+
+# configure stuff:
+Makefile
+config.log
+config.status
+libtool
+src/.deps
+src/Makefile
+src/config.h
+src/libconfig/Makefile
+src/liboping/Makefile
+src/stamp-h1
+
+# make stuff:
+src/.libs
+src/*.la
+src/*.lo
+src/*.o
+src/collectd
+src/collectd.1
+src/collectd.conf.5
+src/config.h.in~
+src/libconfig/.libs
+src/libconfig/*.la
+src/libconfig/*.lo
+src/liboping/.libs
+src/liboping/*.la
+src/liboping/*.lo
+
+# make dist stuff:
+collectd-*.tar.gz
+collectd-*.tar.bz2
index 84e313db515a812e782a0f290779446a1a3fb9c9..7fbc7430e1041048ac4abdf820b99c6890ef525d 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
This package was written by:
Florian octo Forster <octo at verplant.org>
+apcups plugin by:
+ Anthony Gialluca <tonyabg at charter.net>
+
cpufreq module by:
Peter Holik <peter at holik.at>
diff --git a/ChangeLog b/ChangeLog
index bfca172ebdb5310941b767aa894d51a65366f0a7..0a181fe94e083b5a064899c10e0305b45f3c3afd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
+ * The `disk' plugin has been ported to Darwin.
+ * The `battery' plugin should work on many Apple computers now.
+ * The `traffic' plugin can now ignore certain interfaces. Also,
+ statistics for sent/received packets and errors have been added.
+ * A plugin to monitor APC UPSes using `apcupsd' has been added. Thanks
+ to Anthony Gialluca for contributing this plugin and providing me
+ with a test environment :)
+ * A plugin for moniroting an NTP instance and the local clock drift
+ has been added.
+
2006-06-25, Version 3.9.4
* The Solaris code in the `swap' plugin has been changed to reflect
the numbers returned by `swap -s'. Thanks to Christophe Kalt for
sequence checking the `ping' plugin stopped working after
approximately 7.6 days.
+2006-05-09, Version 3.8.5
+ * Applied a patch to the `liboping' library. Due to a bug in the
+ sequence checking the `ping' plugin stopped working after
+ approximately 7.6 days.
+
2006-04-21, Version 3.9.1
* Build issues with Solaris and possible other architectures have been
resolved.
been resolved.
* A bug in the `ping' plugin has been fixed. Sorry folks.
-2006-04-15, Version 3.9.0
+2006-04-02, Version 3.9.0
* A plugin to monitor the Apache webserver has been added.
<http://httpd.apache.org/>
* A plugin to collect statistics about virtual servers using VServer.
diff --git a/Makefile.am b/Makefile.am
index 30beb6397998679dfb342bf03f770e06522b97f4..7dda784e75277ed143a67abb84eda51569c2b6be 100644 (file)
--- a/Makefile.am
+++ b/Makefile.am
SUBDIRS = libltdl src
+
INCLUDES = $(LTDLINCL)
EXTRA_DIST = collectd.spec contrib debian
index d3bab87101e9164ca32697cc0c72a2fac1031600..511683f7e1f29dd767a5ea3bf6be3053477c8185 100644 (file)
--- a/README
+++ b/README
(Number of bytes transfered, number of requests handled and detailed
scoreboard statistics)
+ - APC UPS Daemon
+ (UPS charge, load, input/output/battery voltage, etc)
+
- Apple Sensors
(Temperature, fanspeed and voltage sensors of apple computers)
- NFS Procedures
(Which NFS command were called how often. Only NFSv2 and NFSv3 right now)
+ - NTP Daemon
+ (Local clock drift, offset to peers, etc)
+
- Ping latency
(Time to reach the default gateway or another given host)
diff --git a/collectd.spec b/collectd.spec
index 1b180899d27af6b27db9c21c68f302de812e9d74..fe6430aad5b9513de2c7c9da8c8e06b0da3dda67 100644 (file)
--- a/collectd.spec
+++ b/collectd.spec
%attr(0444,root,root) %{_mandir}/man1/*
%attr(0444,root,root) %{_mandir}/man5/*
%attr(0444,root,root) %{_libdir}/%{name}/apple_sensors.so*
+%attr(0444,root,root) %{_libdir}/%{name}/apcups.so*
%attr(0444,root,root) %{_libdir}/%{name}/battery.so*
%attr(0444,root,root) %{_libdir}/%{name}/cpu.so*
%attr(0444,root,root) %{_libdir}/%{name}/cpufreq.so*
* Tue May 09 2006 Florian octo Forster <octo@verplant.org> 3.9.2-1
- New upstream version
+* Tue May 09 2006 Florian octo Forster <octo@verplant.org> 3.8.5-1
+- New upstream version
+
* Fri Apr 21 2006 Florian octo Forster <octo@verplant.org> 3.9.1-1
- New upstream version
diff --git a/configure.in b/configure.in
index eefdf5b9830b143ad9a151d9896c19ae67dc0046..a1dbca62fa11cc94d5bd94c988c6d8f793603d18 100644 (file)
--- a/configure.in
+++ b/configure.in
dnl Process this file with autoconf to produce a configure script.
-AC_INIT(collectd, 3.9.4)
+AC_INIT(collectd, 3.10.0-alpha3)
AC_CONFIG_SRCDIR(src/collectd.c)
AC_CONFIG_HEADERS(src/config.h)
AM_INIT_AUTOMAKE(dist-bzip2)
AC_CHECK_HEADERS(sys/types.h)
AC_CHECK_HEADERS(sys/socket.h)
AC_CHECK_HEADERS(sys/select.h)
+AC_CHECK_HEADERS(sys/poll.h)
AC_CHECK_HEADERS(netdb.h)
AC_CHECK_HEADERS(arpa/inet.h)
AC_CHECK_HEADERS(sys/resource.h)
])
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)
AC_CHECK_HEADERS(sys/vfs.h)
AC_CHECK_HEADERS(sys/vfstab.h)
+# For the swap plugin, FreeBSD
+AC_CHECK_HEADERS(kvm.h)
+
# For debugging interface (variable number of arguments)
AC_CHECK_HEADERS(stdarg.h)
fi
# Check for structures
-AC_CHECK_MEMBERS([struct if_data.ifi_ibytes, struct if_data.ifi_obytes],
+AC_CHECK_MEMBERS([struct if_data.ifi_ibytes, struct if_data.ifi_opackets, struct if_data.ifi_ierrors],
[AC_DEFINE(HAVE_STRUCT_IF_DATA, 1, [Define if struct if_data exists and is usable.])],
[],
[
#include <sys/socket.h>
#include <net/if.h>
])
-AC_CHECK_MEMBERS([struct net_device_stats.rx_bytes, struct net_device_stats.tx_bytes],
+AC_CHECK_MEMBERS([struct net_device_stats.rx_bytes, struct net_device_stats.tx_packets, struct net_device_stats.rx_errors],
[AC_DEFINE(HAVE_STRUCT_NET_DEVICE_STATS, 1, [Define if struct net_device_stats exists and is usable.])],
[],
[
AC_DEFINE_UNQUOTED(COLLECT_LIBIOKIT, [$collect_libiokit], [Wether or not to use the IOKit library])
AM_CONDITIONAL(BUILD_WITH_LIBIOKIT, test "x$with_libiokit" = "xyes")
+with_libstatgrab="yes"
+with_libdevstat="no"
AC_ARG_WITH(libstatgrab, [AS_HELP_STRING([--with-libstatgrab@<:@=PREFIX@:>@], [Path to libstatgrab.])],
[
if test "x$withval" != "xno" -a "x$withval" != "xyes"
@@ -617,15 +627,17 @@ AC_ARG_WITH(libstatgrab, [AS_HELP_STRING([--with-libstatgrab@<:@=PREFIX@:>@], [P
])
if test "x$with_libstatgrab" = "xyes"
then
- AC_CHECK_LIB(devstat, getdevs)
- AC_CHECK_LIB(kvm, kvm_getargv)
- AC_CHECK_LIB(statgrab, sg_init,, [with_libstatgrab="no (libstatgrab not found)"])
+ AC_CHECK_LIB(statgrab, sg_init, [with_libstatgrab="yes"], [with_libstatgrab="no (libstatgrab not found)"])
fi
if test "x$with_libstatgrab" = "xyes"
then
AC_CHECK_HEADERS(statgrab.h,, [with_libstatgrab="no (statgrab.h not found)"])
fi
if test "x$with_libstatgrab" = "xyes"
+then
+ AC_CHECK_LIB(devstat, getdevs, [with_libdevstat="yes"], [with_libdevstat="no"])
+fi
+if test "x$with_libstatgrab" = "xyes"
then
collect_libstatgrab=1
else
AC_DEFINE_UNQUOTED(COLLECT_LIBSTATGRAB, [$collect_libstatgrab],
[Wether or not to use statgrab library])
AM_CONDITIONAL(BUILD_WITH_LIBSTATGRAB, test "x$with_libstatgrab" = "xyes")
+AM_CONDITIONAL(BUILD_WITH_LIBDEVSTAT, test "x$with_libdevstat" = "xyes")
+
+AC_CHECK_LIB(kvm, kvm_getswapinfo, [with_libkvm="yes"], [with_libkvm="no"])
+if test "x$with_libkvm" = "xyes"
+then
+ AC_DEFINE(HAVE_LIBKVM, 1, [Define to 1 if you have the 'kvm' library (-lkvm)])
+fi
+AM_CONDITIONAL(BUILD_WITH_LIBKVM, test "x$with_libkvm" = "xyes")
AC_ARG_WITH(lm-sensors, [AS_HELP_STRING([--with-lm-sensors@<:@=PREFIX@:>@], [Path to lm_sensors.])],
[
[Wether or not to use mysql library])
AM_CONDITIONAL(BUILD_WITH_LIBMYSQL, test "x$with_libmysql" = "xyes")
+#with_liboping="yes"
+with_own_liboping="no"
+liboping_LDFLAGS="$LDFLAGS"
+liboping_CPPFLAGS="$CPPFLAGS"
+AC_ARG_WITH(liboping, [AS_HELP_STRING([--with-liboping@<:@=PREFIX@:>@], [Path to liboping.])],
+[
+ if test "x$withval" != "xno" && test "x$withval" != "xyes"
+ then
+ if test -d "$withval/lib"
+ then
+ liboping_LDFLAGS="$LDFLAGS -L$withval/lib"
+ fi
+ if test -d "$withval/include"
+ then
+ liboping_CPPFLAGS="$CPPFLAGS -I$withval/include"
+ fi
+ fi
+ if test "x$withval" = "xno"
+ then
+ with_liboping="no"
+ with_own_liboping="no"
+ fi
+],
+[
+ #753
+ with_liboping="yes"
+])
+
+if test "x$with_liboping" = "xyes"
+then
+ save_LDFLAGS="$LDFLAGS"
+ save_CPPFLAGS="$CPPFLAGS"
+ LDFLAGS="$liboping_LDFLAGS"
+ CPPFLAGS="$liboping_CPPFLAGS"
+ AC_CHECK_LIB(oping, ping_construct,
+ [
+ with_liboping="yes"
+ with_own_liboping="no"
+ ],
+ [
+ with_liboping="yes"
+ with_own_liboping="yes"
+ LDFLAGS="$save_LDFLAGS"
+ CPPFLAGS="$save_CPPFLAGS"
+ ])
+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
+
# Define `step' and `hearbeat' values..
declare -i collectd_step=10
declare -i collectd_heartbeat=25
collectd features:])
AC_COLLECTD([debug], [enable], [feature], [debugging])
AC_COLLECTD([daemon], [disable], [feature], [daemon mode])
+AC_COLLECTD([getifaddrs],[enable], [feature], [getifaddrs under Linux])
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([memory], [disable], [module], [memory statistics])
AC_COLLECTD([mysql], [disable], [module], [mysql statistics])
AC_COLLECTD([nfs], [disable], [module], [nfs statistics])
+AC_COLLECTD([ntpd], [disable], [module], [nfs statistics])
AC_COLLECTD([ping], [disable], [module], [ping statistics])
AC_COLLECTD([processes], [disable], [module], [processes statistics])
AC_COLLECTD([sensors], [disable], [module], [lm_sensors statistics])
AC_COLLECTD([vserver], [disable], [module], [vserver statistics])
AC_COLLECTD([wireless], [disable], [module], [wireless link statistics])
-#m4_divert_once([HELP_ENABLE], [
-#collectd modules:])
-#AC_ARG_ENABLE(cpu, AC_HELP_STRING([--disable-cpu], [Disable CPU usage statistics]),, [enable_cpu="yes"])
-#if test "x$enable_cpu" != "xno"
-#then
-# if test "x$ac_system" = "xLinux" -o "x$with_kstat" = "xyes" -o "x$have_sysctlbyname" = "xyes"
-# then
-# enable_cpu="yes"
-# else
-# enable_cpu="no"
-# fi
-#fi
-#if test "x$enable_cpu" = "xno"
-#then
-# AC_DEFINE(COLLECT_CPU, 0, [Wether or not to collect CPU usage statistics])
-#fi
-#AM_CONDITIONAL(BUILD_MODULE_CPU, test "x$enable_cpu" = "xyes")
-
-#AC_ARG_ENABLE(cpufreq, AC_HELP_STRING([--disable-cpufreq], [Disable system cpu frequency statistics]),, [enable_cpufreq="yes"])
-#if test "x$enable_cpufreq" != "xno"
-#then
-# if test "x$ac_system" = "xLinux"
-# then
-# enable_cpufreq="yes"
-# else
-# enable_cpufreq="no"
-# fi
-#fi
-#if test "x$enable_cpufreq" = "xno"
-#then
-# AC_DEFINE(COLLECT_CPUFREQ, 0, [Wether or not to collect cpu frequency statistics])
-#fi
-#AM_CONDITIONAL(BUILD_MODULE_CPUFREQ, test "x$enable_cpufreq" = "xyes")
-
-#AC_ARG_ENABLE(disk, AC_HELP_STRING([--disable-disk], [Disable disk/partition statistics]),, [enable_disk="yes"])
-#if test "x$enable_disk" != "xno"
-#then
-# if test "x$ac_system" = "xLinux" -o "x$with_kstat" = "xyes"
-# then
-# enable_disk="yes"
-# else
-# enable_disk="no"
-# fi
-#fi
-#if test "x$enable_disk" = "xno"
-#then
-# AC_DEFINE(COLLECT_DISK, 0, [Wether or not to collect diskstats])
-#fi
-#AM_CONDITIONAL(BUILD_MODULE_DISK, test "x$enable_disk" = "xyes")
-
-#AC_ARG_ENABLE(hddtemp, AC_HELP_STRING([--disable-hddtemp], [Disable hdd temperature statistics]),, [enable_hddtemp="yes"])
-#if test "x$enable_hddtemp" = "xno"
-#then
-# AC_DEFINE(COLLECT_HDDTEMP, 0, [Wether or not to collect hdd temperature statistics])
-#fi
-#AM_CONDITIONAL(BUILD_MODULE_HDDTEMP, test "x$enable_hddtemp" = "xyes")
-
-#AC_ARG_ENABLE(load, AC_HELP_STRING([--disable-load], [Disable system load statistics]),, [enable_load="yes"])
-#if test "x$enable_load" != "xno"
-#then
-# if test "x$have_getloadavg" = "xyes" -o "x$ac_system" = "xLinux" -o "x$with_libstatgrab" = "xyes"
-# then
-# enable_load="yes"
-# else
-# enable_load="no"
-# fi
-#fi
-#if test "x$enable_load" = "xno"
-#then
-# AC_DEFINE(COLLECT_LOAD, 0, [Wether or not to collect system load statistics])
-#fi
-#AM_CONDITIONAL(BUILD_MODULE_LOAD, test "x$enable_load" = "xyes")
-
-#AC_ARG_ENABLE(memory, AC_HELP_STRING([--disable-memory], [Disable memory statistics]),, [enable_memory="yes"])
-#if test "x$enable_memory" != "xno"
-#then
-# if test "x$ac_system" = "xLinux" -o "x$with_kstat" = "xyes" -o "x$with_libstatgrab" = "xyes"
-# then
-# enable_memory="yes"
-# else
-# enable_memory="no"
-# fi
-#fi
-#if test "x$enable_memory" = "xno"
-#then
-# AC_DEFINE(COLLECT_MEMORY, 0, [Wether or not to collect memory statistics])
-#fi
-#AM_CONDITIONAL(BUILD_MODULE_MEMORY, test "x$enable_memory" = "xyes")
-
-#AC_ARG_ENABLE(nfs, AC_HELP_STRING([--disable-nfs], [Disable nfs statistics]),, [enable_nfs="yes"])
-#if test "x$enable_nfs" != "xno"
-#then
-# if test "x$ac_system" = "xLinux"
-# then
-# enable_nfs="yes"
-# else
-# enable_nfs="no"
-# fi
-#fi
-#if test "x$enable_nfs" = "xno"
-#then
-# AC_DEFINE(COLLECT_NFS, 0, [Wether or not to collect nfs statistics])
-#fi
-#AM_CONDITIONAL(BUILD_MODULE_NFS, test "x$enable_nfs" = "xyes")
-
-#AC_ARG_ENABLE(ping, AC_HELP_STRING([--disable-ping], [Disable ping statistics]),, [enable_ping="yes"])
-#if test "x$enable_ping" != "xno"
-#then
-# enable_ping="yes"
-#fi
-#if test "x$enable_ping" = "xno"
-#then
-# AC_DEFINE(COLLECT_PING, 0, [Wether or not to collect ping statistics])
-#fi
-#AM_CONDITIONAL(BUILD_MODULE_PING, test "x$enable_ping" = "xyes")
-
-#AC_ARG_ENABLE(processes, AC_HELP_STRING([--disable-processes], [Disable processes statistics]),, [enable_processes="yes"])
-#if test "x$enable_processes" != "xno"
-#then
-# if test "x$ac_system" = "xLinux"
-# then
-# enable_processes="yes"
-# else
-# enable_processes="no"
-# fi
-#fi
-#if test "x$enable_processes" = "xno"
-#then
-# AC_DEFINE(COLLECT_PROCESSES, 0, [Wether or not to collect processes statistics])
-#fi
-#AM_CONDITIONAL(BUILD_MODULE_PROCESSES, test "x$enable_processes" = "xyes")
-
-##AC_COLLECTD([quota], [enable], [module], [quota statistics (experimental)])
-
-#AC_ARG_ENABLE(sensors, AC_HELP_STRING([--disable-sensors], [Disable lm_sensors statistics]),, [enable_sensors=$with_lm_sensors])
-#if test "x$enable_sensors" != "xno"
-#then
-# if test "x$with_lm_sensors" = "xyes"
-# then
-# enable_sensors="yes"
-# else
-# enable_sensors="no"
-# fi
-#fi
-#if test "x$enable_sensors" = "xno"
-#then
-# AC_DEFINE(COLLECT_SENSORS, 0, [Wether or not to collect lm_sensors statistics])
-#fi
-#AM_CONDITIONAL(BUILD_MODULE_SENSORS, test "x$enable_sensors" = "xyes")
-
-#AC_ARG_ENABLE(serial, AC_HELP_STRING([--disable-serial], [Disable serial statistics]),, [enable_serial="yes"])
-#if test "x$enable_serial" != "xno"
-#then
-# if test "x$ac_system" = "xLinux"
-# then
-# enable_serial="yes"
-# else
-# enable_serial="no"
-# fi
-#fi
-#if test "x$enable_serial" = "xno"
-#then
-# AC_DEFINE(COLLECT_SERIAL, 0, [Wether or not to collect serial statistics])
-#fi
-#AM_CONDITIONAL(BUILD_MODULE_SERIAL, test "x$enable_serial" = "xyes")
-
-#AC_ARG_ENABLE(swap, AC_HELP_STRING([--disable-swap], [Disable swap statistics]),, [enable_swap="yes"])
-#if test "x$enable_swap" != "xno"
-#then
-# if test "x$ac_system" = "xLinux" -o "x$with_kstat" = "xyes" -o "x$with_libstatgrab" = "xyes"
-# then
-# enable_swap="yes"
-# else
-# enable_swap="no"
-# fi
-#fi
-#if test "x$enable_swap" = "xno"
-#then
-# AC_DEFINE(COLLECT_SWAP, 0, [Wether or not to collect swap statistics])
-#fi
-#AM_CONDITIONAL(BUILD_MODULE_SWAP, test "x$enable_swap" = "xyes")
-
-#AC_ARG_ENABLE(tape, AC_HELP_STRING([--disable-tape], [Disable tape statistics]),, [enable_tape="yes"])
-#if test "x$enable_tape" != "xno"
-#then
-# if test "x$with_kstat" = "xyes"
-# then
-# enable_tape="yes"
-# else
-# enable_tape="no"
-# fi
-#fi
-#if test "x$enable_tape" = "xno"
-#then
-# AC_DEFINE(COLLECT_TAPE, 0, [Wether or not to collect tape statistics])
-#fi
-#AM_CONDITIONAL(BUILD_MODULE_TAPE, test "x$enable_tape" = "xyes")
-
-#AC_ARG_ENABLE(traffic, AC_HELP_STRING([--disable-traffic], [Disable system traffic statistics]),, [enable_traffic="yes"])
-#if test "x$enable_traffic" != "xno"
-#then
-# if test "x$ac_system" = "xLinux" -o "x$with_kstat" = "xyes" -o "x$with_libstatgrab" = "xyes"
-# then
-# enable_traffic="yes"
-# else
-# enable_traffic="no"
-# fi
-#fi
-#if test "x$enable_traffic" = "xno"
-#then
-# AC_DEFINE(COLLECT_TRAFFIC, 0, [Wether or not to collect network traffic statistics])
-#fi
-#AM_CONDITIONAL(BUILD_MODULE_TRAFFIC, test "x$enable_traffic" = "xyes")
-
-#AC_COLLECTD([users], [disable], [module], [user count statistics])
-
-AC_OUTPUT(Makefile src/libconfig/Makefile src/liboping/Makefile src/Makefile)
+AC_OUTPUT(Makefile src/Makefile src/libconfig/Makefile src/liboping/Makefile)
cat <<EOF;
Libraries:
libcurl . . . . . . $with_libcurl
libiokit . . . . . $with_libiokit
+ liboping . . . . . $with_liboping
librrd . . . . . . $with_rrdtool
lm_sensors . . . . $with_lm_sensors
libstatgrab . . . . $with_libstatgrab
Modules:
apache . . . . . . $enable_apache
+ apcups . . . . . . $enable_apcups
apple_sensors . . . $enable_apple_sensors
battery . . . . . . $enable_battery
cpu . . . . . . . . $enable_cpu
memory . . . . . . $enable_memory
mysql . . . . . . . $enable_mysql
nfs . . . . . . . . $enable_nfs
+ ntpd . . . . . . . $enable_ntpd
ping . . . . . . . $enable_ping
processes . . . . . $enable_processes
sensors . . . . . . $enable_sensors
diff --git a/contrib/README b/contrib/README
--- /dev/null
+++ b/contrib/README
@@ -0,0 +1,31 @@
+The files in this directory may be used to perform common tasks that aren't
+exactly `collectd's job. They may or may not require in-depth knowlege of RRD
+files and/or `collectd's inner workings. Use at your own risk.
+
+add_rra.sh
+----------
+ Before version 3.9.0 collectd used to create a different set of RRAs. The
+most detailed of these old RRAs hat a one minute resolution. This script can be
+used to add three more RRAs: minimum, maximum and average with a ten second
+resolution and 2200 rows (~6 hours). This will make houly statistics much more
+interesting. Please note that no sanity- checking whatsoever is performed. You
+can seriously fuck up your RRD files if you don't know what you're doing.
+
+collectd2html.pl
+----------------
+ This script by Vincent Stehlé will search for RRD files in
+`/var/lib/collectd/' and generate an HTML file and a directory containing
+several PNG files which are graphs of the RRD files found.
+
+collectd.conf
+-------------
+ A sample config file. Used by the Debian package.
+
+collection.cgi
+--------------
+ Sample CGI script that creates graphs on the fly. The Perl module `RRDs' is
+needed (Debian package `librrds-perl').
+
+init.d-rh7
+----------
+ Sample init script. Used by the RPM specfile.
diff --git a/contrib/add_rra.sh b/contrib/add_rra.sh
--- /dev/null
+++ b/contrib/add_rra.sh
@@ -0,0 +1,67 @@
+#!/bin/bash
+
+INPUT=$1
+OUTPUT=$2
+
+if [ -z "$INPUT" -o -z "$OUTPUT" ]
+then
+ cat <<USAGE
+Usage: $0 <input> <output>
+USAGE
+ exit 1
+fi
+
+if [ ! -e "$INPUT" ]
+then
+ echo "No such file: $INPUT"
+ exit 1
+fi
+
+if [ -e "$OUTPUT" ]
+then
+ echo "File exists: $OUTPUT"
+ exit 1
+fi
+
+NUM_DS=0
+rrdtool dump "$INPUT" | while read LINE
+do
+ echo "$LINE"
+
+ if [ "$LINE" = "<ds>" ]
+ then
+ NUM_DS=$(($NUM_DS + 1))
+ fi
+
+ if [ "$LINE" = "<!-- Round Robin Archives -->" ]
+ then
+ for CF in MIN MAX AVERAGE
+ do
+ cat <<RRA
+ <rra>
+ <cf> $CF </cf>
+ <pdp_per_row> 1 </pdp_per_row>
+ <xff> 0.0000000000e+00 </xff>
+
+ <cdp_prep>
+RRA
+ for ((i=0; i < $NUM_DS; i++))
+ do
+ echo " <ds><value> NaN </value> <unknown_datapoints> 1 </unknown_datapoints></ds>"
+ done
+ echo " </cdp_prep>"
+ echo " <database>"
+
+ DS_VALUES=`for ((i=0; i < $NUM_DS; i++)); do echo -n "<v> NaN </v>"; done`
+ for ((i=0; i < 2200; i++))
+ do
+ echo " <!-- $i --> <row>$DS_VALUES</row>"
+ done
+ echo " </database>"
+ echo " </rra>"
+ done
+ fi
+done >"$OUTPUT.xml"
+
+rrdtool restore "$OUTPUT.xml" "$OUTPUT" -r >/dev/null
+rm -f "$OUTPUT.xml"
diff --git a/contrib/collection.cgi b/contrib/collection.cgi
index 54cde20bc0fa8abe172360f7dc9cb7d746430250..eb97d63825941d6b25b54f1c81ff31bb1c8b6733 100755 (executable)
--- a/contrib/collection.cgi
+++ b/contrib/collection.cgi
'GPRINT:max:MAX:%5.1lf%sAh Max,',
'GPRINT:avg:LAST:%5.1lf%sAh Last\l'
],
+ charge_percent => [
+ 'DEF:avg={file}:percent:AVERAGE',
+ 'DEF:min={file}:percent:MIN',
+ 'DEF:max={file}:percent:MAX',
+ "AREA:max#$HalfBlue",
+ "AREA:min#$Canvas",
+ "LINE1:avg#$FullBlue:Charge",
+ 'GPRINT:min:MIN:%5.1lf%s%% Min,',
+ 'GPRINT:avg:AVERAGE:%5.1lf%s%% Avg,',
+ 'GPRINT:max:MAX:%5.1lf%s%% Max,',
+ 'GPRINT:avg:LAST:%5.1lf%s%% Last\l'
+ ],
cpu => ['DEF:user_avg={file}:user:AVERAGE',
'DEF:user_min={file}:user:MIN',
'DEF:user_max={file}:user:MAX',
'GPRINT:total_max_ms:MAX:%5.1lf%s Max,',
'GPRINT:total_avg_ms:LAST:%5.1lf%s Last'
],
+ fanspeed => [
+ 'DEF:temp_avg={file}:value:AVERAGE',
+ 'DEF:temp_min={file}:value:MIN',
+ 'DEF:temp_max={file}:value:MAX',
+ "AREA:temp_max#$HalfBlue",
+ "AREA:temp_min#$Canvas",
+ "LINE1:temp_avg#$FullBlue:RPM",
+ 'GPRINT:temp_min:MIN:%4.1lf Min,',
+ 'GPRINT:temp_avg:AVERAGE:%4.1lf Avg,',
+ 'GPRINT:temp_max:MAX:%4.1lf Max,',
+ 'GPRINT:temp_avg:LAST:%4.1lf Last\l'
+ ],
+ frequency_offset => [ # NTPd
+ 'DEF:ppm_avg={file}:ppm:AVERAGE',
+ 'DEF:ppm_min={file}:ppm:MIN',
+ 'DEF:ppm_max={file}:ppm:MAX',
+ "AREA:ppm_max#$HalfBlue",
+ "AREA:ppm_min#$Canvas",
+ "LINE1:ppm_avg#$FullBlue:{inst}",
+ 'GPRINT:ppm_min:MIN:%5.2lf Min,',
+ 'GPRINT:ppm_avg:AVERAGE:%5.2lf Avg,',
+ 'GPRINT:ppm_max:MAX:%5.2lf Max,',
+ 'GPRINT:ppm_avg:LAST:%5.2lf Last'
+ ],
hddtemp => [
'DEF:temp_avg={file}:value:AVERAGE',
'DEF:temp_min={file}:value:MIN',
'GPRINT:l_max:MAX:%4.2lf Max,',
'GPRINT:l_avg:LAST:%4.2lf Last'
],
+ load_percent => [
+ 'DEF:avg={file}:percent:AVERAGE',
+ 'DEF:min={file}:percent:MIN',
+ 'DEF:max={file}:percent:MAX',
+ "AREA:max#$HalfBlue",
+ "AREA:min#$Canvas",
+ "LINE1:avg#$FullBlue:Load",
+ 'GPRINT:min:MIN:%5.1lf%s%% Min,',
+ 'GPRINT:avg:AVERAGE:%5.1lf%s%% Avg,',
+ 'GPRINT:max:MAX:%5.1lf%s%% Max,',
+ 'GPRINT:avg:LAST:%5.1lf%s%% Last\l'
+ ],
mails => ['DEF:rawgood={file}:good:AVERAGE',
'DEF:rawspam={file}:spam:AVERAGE',
'CDEF:good=rawgood,UN,0,rawgood,IF',
'GPRINT:sleeping_max:MAX:%5.1lf Max,',
'GPRINT:sleeping_avg:LAST:%5.1lf Last\l'
],
- sensors => [
- 'DEF:temp_avg={file}:value:AVERAGE',
- 'DEF:temp_min={file}:value:MIN',
- 'DEF:temp_max={file}:value:MAX',
- "AREA:temp_max#$HalfBlue",
- "AREA:temp_min#$Canvas",
- "LINE1:temp_avg#$FullBlue:Value",
- 'GPRINT:temp_min:MIN:%4.1lf Min,',
- 'GPRINT:temp_avg:AVERAGE:%4.1lf Avg,',
- 'GPRINT:temp_max:MAX:%4.1lf Max,',
- 'GPRINT:temp_avg:LAST:%4.1lf Last\l'
- ],
swap => [
'DEF:used_avg={file}:used:AVERAGE',
'DEF:used_min={file}:used:MIN',
'GPRINT:used_max:MAX:%5.1lf%s Max,',
'GPRINT:used_avg:LAST:%5.1lf%s Last\l'
],
+ temperature => [
+ 'DEF:temp_avg={file}:value:AVERAGE',
+ 'DEF:temp_min={file}:value:MIN',
+ 'DEF:temp_max={file}:value:MAX',
+ "AREA:temp_max#$HalfBlue",
+ "AREA:temp_min#$Canvas",
+ "LINE1:temp_avg#$FullBlue:Value",
+ 'GPRINT:temp_min:MIN:%4.1lf Min,',
+ 'GPRINT:temp_avg:AVERAGE:%4.1lf Avg,',
+ 'GPRINT:temp_max:MAX:%4.1lf Max,',
+ 'GPRINT:temp_avg:LAST:%4.1lf Last\l'
+ ],
+ timeleft => [
+ 'DEF:avg={file}:timeleft:AVERAGE',
+ 'DEF:min={file}:timeleft:MIN',
+ 'DEF:max={file}:timeleft:MAX',
+ "AREA:max#$HalfBlue",
+ "AREA:min#$Canvas",
+ "LINE1:avg#$FullBlue:Time left [min]",
+ 'GPRINT:min:MIN:%5.1lf%s Min,',
+ 'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
+ 'GPRINT:max:MAX:%5.1lf%s Max,',
+ 'GPRINT:avg:LAST:%5.1lf%s Last\l'
+ ],
+ time_offset => [ # NTPd
+ 'DEF:s_avg={file}:seconds:AVERAGE',
+ 'DEF:s_min={file}:seconds:MIN',
+ 'DEF:s_max={file}:seconds:MAX',
+ "AREA:s_max#$HalfBlue",
+ "AREA:s_min#$Canvas",
+ "LINE1:s_avg#$FullBlue:{inst}",
+ 'GPRINT:s_min:MIN:%7.3lf%s Min,',
+ 'GPRINT:s_avg:AVERAGE:%7.3lf%s Avg,',
+ 'GPRINT:s_max:MAX:%7.3lf%s Max,',
+ 'GPRINT:s_avg:LAST:%7.3lf%s Last'
+ ],
traffic => ['DEF:out_min_raw={file}:outgoing:MIN',
'DEF:out_avg_raw={file}:outgoing:AVERAGE',
'DEF:out_max_raw={file}:outgoing:MAX',
'GPRINT:max:MAX:%5.1lf%sV Max,',
'GPRINT:avg:LAST:%5.1lf%sV Last\l'
],
- threads => [
+ vs_threads => [
"DEF:total_avg={file}:total:AVERAGE",
"DEF:total_min={file}:total:MIN",
"DEF:total_max={file}:total:MAX",
};
$GraphDefs->{'disk'} = $GraphDefs->{'partition'};
$GraphDefs->{'meminfo'} = $GraphDefs->{'memory'};
+ $GraphDefs->{'sensors'} = $GraphDefs->{'temperature'};
+
+ $GraphDefs->{'delay'} = $GraphDefs->{'time_offset'};
+ $GraphDefs->{'time_dispersion'} = $GraphDefs->{'time_offset'};
}
our $GraphArgs =
apache_requests => ['-t', 'apache requests', '-v', 'Requests/s'],
apache_scoreboard => ['-t', 'apache scoreboard {inst}', '-v', 'Processes'],
charge => ['-t', '{host} charge', '-v', 'Ampere hours'],
+ charge_percent => ['-t', '{host} charge', '-v', 'Percent'],
cpu => ['-t', '{host} cpu{inst} usage', '-v', 'Percent', '-l', '0'],
cpufreq => ['-t', '{host} cpu{inst} usage', '-v', 'Mhz'],
current => ['-t', '{host} current', '-v', 'Ampere'],
#disk => ['-t', '{host} disk {inst} IO wait', '-v', 'Seconds'],
+ delay => ['-t', 'NTPd peer delay ({inst})', '-v', 'Seconds'],
df => ['-t', '{host}:{inst} usage', '-v', 'Percent', '-l', '0'],
disk => ['-t', '{host} disk {inst} usage', '-v', 'Byte/s'],
+ fanspeed => ['-t', '{host} fanspeed {inst}', '-v', 'rpm'],
+ frequency_offset => ['-t', 'NTPd frequency offset ({inst})', '-v', 'Parts per million'],
hddtemp => ['-t', '{host} hdd temperature {inst}', '-v', '°Celsius'],
load => ['-t', '{host} load average', '-v', 'System load', '-X', '0'],
+ load_percent => ['-t', '{host} load', '-v', 'Percent'],
mails => ['-t', '{host} mail count', '-v', 'Amount', '-X', '0'],
memory => ['-t', '{host} memory usage', '-v', 'Bytes', '-b', '1024', '-l', '0'],
mysql_commands => ['-t', 'mysql command {inst}', '-v', 'Issues/s' ],
processes => ['-t', '{host} processes', '-v', 'Processes'],
sensors => ['-t', '{host} sensor {inst}', '-v', '°Celsius'],
swap => ['-t', '{host} swap usage', '-v', 'Bytes', '-b', '1024', '-l', '0'],
+ temperature => ['-t', '{host} temperature {inst}', '-v', '°Celsius'],
+ timeleft => ['-t', '{host} UPS time left', '-v', 'Time [min]'],
+ time_offset => ['-t', 'NTPd time offset ({inst})', '-v', 'Seconds'],
+ time_dispersion => ['-t', 'NTPd time dispersion ({inst})', '-v', 'Seconds'],
traffic => ['-t', '{host} {inst} traffic', '-v', 'Bit/s'],
users => ['-t', '{host} users', '-v', 'Users'],
voltage => ['-t', '{host} voltage', '-v', 'Volts'],
- threads => ['-t', '{host} threads', '-v', 'Threads'],
+ vs_threads => ['-t', '{host} threads', '-v', 'Threads'],
vs_memory => ['-t', '{host} memory usage', '-v', 'Bytes'],
vs_processes => ['-t', '{host} processes', '-v', 'Processes'],
};
diff --git a/debian/changelog b/debian/changelog
index c9a5bff2aca6a1888e9cf98cd664e1722298e519..fb3e5c714c8c7d8b4074b10a5b05004534a1f119 100644 (file)
--- a/debian/changelog
+++ b/debian/changelog
-- Florian Forster <octo@verplant.org> Tue, 9 May 2006 11:12:00 +0200
+collectd (3.8.5-1) unstable; urgency=low
+
+ * New upstream version
+
+ -- Florian Forster <octo@verplant.org> Tue, 9 May 2006 10:56:00 +0200
+
collectd (3.9.1-1) unstable; urgency=low
* New upstream version
diff --git a/src/Makefile.am b/src/Makefile.am
index 9cafbbf50c3bbd88522fc1b28fa72a907a69860b..c868f5e7d9e915f0ca4e9f280577d5c00071e08a 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
SUBDIRS = libconfig
-if BUILD_MODULE_PING
+if BUILD_WITH_OWN_LIBOPING
SUBDIRS += liboping
endif
collectd_LDFLAGS += -ldevinfo
endif
+if BUILD_WITH_LIBSTATGRAB
+if BUILD_WITH_LIBKVM
+collectd_LDFLAGS += -lkvm
+endif
+if BUILD_WITH_LIBDEVSTAT
+collectd_LDFLAGS += -ldevstat
+endif
+collectd_LDFLAGS += -lstatgrab
+endif
+
+
collectd_LDADD = $(LIBLTDL) libconfig/libconfig.la "-dlopen" self
collectd_DEPENDENCIES = $(LIBLTDL) libconfig/libconfig.la
collectd_DEPENDENCIES += apache.la
endif
+if BUILD_MODULE_APCUPS
+pkglib_LTLIBRARIES += apcups.la
+apcups_la_SOURCES = apcups.c
+apcups_la_LDFLAGS = -module -avoid-version
+if BUILD_WITH_LIBSOCKET
+apcups_la_LDFLAGS += -lsocket
+endif
+collectd_LDADD += "-dlopen" apcups.la
+collectd_DEPENDENCIES += apcups.la
+endif
+
if BUILD_MODULE_APPLE_SENSORS
pkglib_LTLIBRARIES += apple_sensors.la
apple_sensors_la_SOURCES = apple_sensors.c
if BUILD_WITH_LIBDEVINFO
disk_la_LDFLAGS += -ldevinfo
endif
+if BUILD_WITH_LIBIOKIT
+disk_la_LDFLAGS += -lIOKit
+endif
collectd_LDADD += "-dlopen" disk.la
collectd_DEPENDENCIES += disk.la
endif
load_la_LDFLAGS = -module -avoid-version
collectd_LDADD += "-dlopen" load.la
collectd_DEPENDENCIES += load.la
+if BUILD_WITH_LIBSTATGRAB
+if BUILD_WITH_LIBKVM
+load_la_LDFLAGS += -lkvm
+endif
+if BUILD_WITH_LIBDEVSTAT
+load_la_LDFLAGS += -ldevstat
+endif
+load_la_LDFLAGS += -lstatgrab
+endif
endif
if BUILD_MODULE_MEMORY
pkglib_LTLIBRARIES += memory.la
memory_la_SOURCES = memory.c
memory_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" memory.la
+collectd_DEPENDENCIES += memory.la
if BUILD_WITH_LIBKSTAT
memory_la_LDFLAGS += -lkstat
endif
if BUILD_WITH_LIBDEVINFO
memory_la_LDFLAGS += -ldevinfo
endif
-collectd_LDADD += "-dlopen" memory.la
-collectd_DEPENDENCIES += memory.la
+if BUILD_WITH_LIBSTATGRAB
+if BUILD_WITH_LIBKVM
+memory_la_LDFLAGS += -lkvm
+endif
+if BUILD_WITH_LIBDEVSTAT
+memory_la_LDFLAGS += -ldevstat
+endif
+memory_la_LDFLAGS += -lstatgrab
+endif
endif
if BUILD_MODULE_MYSQL
collectd_DEPENDENCIES += nfs.la
endif
+if BUILD_MODULE_NTPD
+pkglib_LTLIBRARIES += ntpd.la
+ntpd_la_SOURCES = ntpd.c
+ntpd_la_LDFLAGS = -module -avoid-version
+if BUILD_WITH_LIBSOCKET
+ntpd_la_LDFLAGS += -lsocket
+endif
+collectd_LDADD += "-dlopen" ntpd.la
+collectd_DEPENDENCIES += ntpd.la
+endif
+
if BUILD_MODULE_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
pkglib_LTLIBRARIES += swap.la
swap_la_SOURCES = swap.c
swap_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" swap.la
+collectd_DEPENDENCIES += swap.la
if BUILD_WITH_LIBKSTAT
swap_la_LDFLAGS += -lkstat
endif
if BUILD_WITH_LIBDEVINFO
swap_la_LDFLAGS += -ldevinfo
endif
-collectd_LDADD += "-dlopen" swap.la
-collectd_DEPENDENCIES += swap.la
+if BUILD_WITH_LIBKVM
+swap_la_LDFLAGS += -lkvm
+endif
+if BUILD_WITH_LIBSTATGRAB
+if BUILD_WITH_LIBDEVSTAT
+swap_la_LDFLAGS += -ldevstat
+endif
+swap_la_LDFLAGS += -lstatgrab
+endif
endif
if BUILD_MODULE_TAPE
pkglib_LTLIBRARIES += traffic.la
traffic_la_SOURCES = traffic.c
traffic_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" traffic.la
+collectd_DEPENDENCIES += traffic.la
if BUILD_WITH_LIBKSTAT
traffic_la_LDFLAGS += -lkstat
endif
if BUILD_WITH_LIBDEVINFO
traffic_la_LDFLAGS += -ldevinfo
endif
-collectd_LDADD += "-dlopen" traffic.la
-collectd_DEPENDENCIES += traffic.la
+if BUILD_WITH_LIBSTATGRAB
+if BUILD_WITH_LIBKVM
+traffic_la_LDFLAGS += -lkvm
+endif
+if BUILD_WITH_LIBDEVSTAT
+traffic_la_LDFLAGS += -ldevstat
+endif
+traffic_la_LDFLAGS += -lstatgrab
+endif
endif
if BUILD_MODULE_USERS
diff --git a/src/apache.c b/src/apache.c
index c731908a291cb05dfa75ce000c369892757baac7..156ad5dc905d757d2fd2fd05f97c1b5a8e748633 100644 (file)
--- a/src/apache.c
+++ b/src/apache.c
# define APACHE_HAVE_READ 0
#endif
-static char *url = NULL;
-static char *user = NULL;
-static char *pass = NULL;
+static char *url = NULL;
+static char *user = NULL;
+static char *pass = NULL;
+static char *cacert = NULL;
#if HAVE_LIBCURL
static CURL *curl = NULL;
"URL",
"User",
"Password",
+ "CACert",
NULL
};
-static int config_keys_num = 3;
+static int config_keys_num = 4;
#if HAVE_LIBCURL
static size_t apache_curl_callback (void *buf, size_t size, size_t nmemb, void *stream)
return (config_set (&user, value));
else if (strcasecmp (key, "password") == 0)
return (config_set (&pass, value));
+ else if (strcasecmp (key, "cacert") == 0)
+ return (config_set (&cacert, value));
else
return (-1);
}
{
curl_easy_setopt (curl, CURLOPT_URL, url);
}
+
+ if (cacert != NULL)
+ {
+ curl_easy_setopt (curl, CURLOPT_CAINFO, cacert);
+ }
#endif /* HAVE_LIBCURL */
}
if (url == NULL)
return;
+ apache_buffer_len = 0;
if (curl_easy_perform (curl) != 0)
{
syslog (LOG_WARNING, "apache: curl_easy_perform failed: %s", apache_curl_error);
diff --git a/src/apcups.c b/src/apcups.c
--- /dev/null
+++ b/src/apcups.c
@@ -0,0 +1,570 @@
+/*
+ * collectd - src/apcups.c
+ * 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.
+ *
+ * This program is distributed in the hope that 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., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ *
+ * Authors:
+ * Anthony Gialluca <tonyabg at charter.net>
+ **/
+
+/*
+ * FIXME: Don't know why but without this here atof() was not returning
+ * correct values for me. This is behavior that I don't understand and
+ * should be examined in closer detail.
+ */
+#include <stdlib.h>
+
+#include "collectd.h"
+#include "common.h" /* rrd_update_file */
+#include "plugin.h" /* plugin_register, plugin_submit */
+#include "configfile.h" /* cf_register */
+#include "utils_debug.h"
+
+#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#endif
+#if HAVE_NETDB_H
+# include <netdb.h>
+#endif
+
+#if HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+
+#ifndef APCMAIN
+# define APCMAIN 0
+#endif
+
+#define NISPORT 3551
+#define MAXSTRING 256
+#define MODULE_NAME "apcups"
+
+#define APCUPS_DEFAULT_HOST "localhost"
+
+/* Default values for contacting daemon */
+static char *global_host = NULL;
+static int global_port = NISPORT;
+
+/*
+ * The following are only if not compiled to test the module with its own main.
+*/
+#if !APCMAIN
+static char *bvolt_file_template = "apcups/voltage-%s.rrd";
+static char *bvolt_ds_def[] =
+{
+ "DS:voltage:GAUGE:"COLLECTD_HEARTBEAT":0:U",
+};
+static int bvolt_ds_num = 1;
+
+static char *load_file_template = "apcups/load_percent.rrd";
+static char *load_ds_def[] =
+{
+ "DS:percent:GAUGE:"COLLECTD_HEARTBEAT":0:110",
+};
+static int load_ds_num = 1;
+
+static char *charge_file_template = "apcups/charge_percent.rrd";
+static char *charge_ds_def[] =
+{
+ "DS:percent:GAUGE:"COLLECTD_HEARTBEAT":0:110",
+};
+static int charge_ds_num = 1;
+
+static char *time_file_template = "apcups/timeleft.rrd";
+static char *time_ds_def[] =
+{
+ "DS:timeleft:GAUGE:"COLLECTD_HEARTBEAT":0:100",
+};
+static int time_ds_num = 1;
+
+static char *temp_file_template = "apcups/temperature.rrd";
+static char *temp_ds_def[] =
+{
+ /* -273.15 is absolute zero */
+ "DS:value:GAUGE:"COLLECTD_HEARTBEAT":-274:U",
+};
+static int temp_ds_num = 1;
+
+static char *freq_file_template = "apcups/frequency-%s.rrd";
+static char *freq_ds_def[] =
+{
+ "DS:frequency:GAUGE:"COLLECTD_HEARTBEAT":0:U",
+};
+static int freq_ds_num = 1;
+
+static char *config_keys[] =
+{
+ "Host",
+ "Port",
+ NULL
+};
+static int config_keys_num = 2;
+
+#endif /* if APCMAIN */
+
+struct apc_detail_s
+{
+ double linev;
+ double loadpct;
+ double bcharge;
+ double timeleft;
+ double outputv;
+ double itemp;
+ double battv;
+ double linefreq;
+};
+
+#define BIG_BUF 4096
+
+#if APCMAIN
+/* Close the network connection */
+static void net_close (int *fd)
+{
+ uint16_t packet_size = 0;
+
+ assert (*fd >= 0);
+
+ DBG ("Gracefully shutting down socket %i.", *fd);
+
+ /* send EOF sentinel */
+ swrite (*fd, (void *) &packet_size, sizeof (packet_size));
+
+ close (*fd);
+ *fd = -1;
+}
+#endif /* APCMAIN */
+
+/*
+ * Open a TCP connection to the UPS network server
+ * Returns -1 on error
+ * Returns socket file descriptor otherwise
+ */
+static int net_open (char *host, char *service, int port)
+{
+ int sd;
+ int status;
+ char port_str[8];
+ struct addrinfo ai_hints;
+ struct addrinfo *ai_return;
+ struct addrinfo *ai_list;
+
+ assert ((port > 0x00000000) && (port <= 0x0000FFFF));
+
+ /* Convert the port to a string */
+ snprintf (port_str, 8, "%i", port);
+ port_str[7] = '\0';
+
+ /* Resolve name */
+ memset ((void *) &ai_hints, '\0', sizeof (ai_hints));
+ ai_hints.ai_family = AF_INET; /* XXX: Change this to `AF_UNSPEC' if apcupsd can handle IPv6 */
+ ai_hints.ai_socktype = SOCK_STREAM;
+
+ status = getaddrinfo (host, port_str, &ai_hints, &ai_return);
+ if (status != 0)
+ {
+ DBG ("getaddrinfo failed: %s", status == EAI_SYSTEM ? strerror (errno) : gai_strerror (status));
+ return (-1);
+ }
+
+ /* Create socket */
+ sd = -1;
+ for (ai_list = ai_return; ai_list != NULL; ai_list = ai_list->ai_next)
+ {
+ sd = socket (ai_list->ai_family, ai_list->ai_socktype, ai_list->ai_protocol);
+ if (sd >= 0)
+ break;
+ }
+ /* `ai_list' still holds the current description of the socket.. */
+
+ if (sd < 0)
+ {
+ DBG ("Unable to open a socket");
+ freeaddrinfo (ai_return);
+ return (-1);
+ }
+
+ status = connect (sd, ai_list->ai_addr, ai_list->ai_addrlen);
+
+ freeaddrinfo (ai_return);
+
+ if (status != 0) /* `connect(2)' failed */
+ {
+ DBG ("connect failed: %s", strerror (errno));
+ return (-1);
+ }
+
+ DBG ("Done opening a socket %i", sd);
+
+ return (sd);
+} /* int net_open (char *host, char *service, int port) */
+
+/*
+ * Receive a message from the other end. Each message consists of
+ * two packets. The first is a header that contains the size
+ * of the data that follows in the second packet.
+ * Returns number of bytes read
+ * Returns 0 on end of file
+ * Returns -1 on hard end of file (i.e. network connection close)
+ * Returns -2 on error
+ */
+static int net_recv (int *sockfd, char *buf, int buflen)
+{
+ uint16_t packet_size;
+
+ /* get data size -- in short */
+ if (sread (*sockfd, (void *) &packet_size, sizeof (packet_size)) != 0)
+ {
+ *sockfd = -1;
+ return (-1);
+ }
+
+ packet_size = ntohs (packet_size);
+ if (packet_size > buflen)
+ {
+ DBG ("record length too large");
+ return (-2);
+ }
+
+ if (packet_size == 0)
+ return (0);
+
+ /* now read the actual data */
+ if (sread (*sockfd, (void *) buf, packet_size) != 0)
+ {
+ *sockfd = -1;
+ return (-1);
+ }
+
+ return ((int) packet_size);
+} /* static int net_recv (int *sockfd, char *buf, int buflen) */
+
+/*
+ * Send a message over the network. The send consists of
+ * two network packets. The first is sends a short containing
+ * the length of the data packet which follows.
+ * Returns zero on success
+ * Returns non-zero on error
+ */
+static int net_send (int *sockfd, char *buff, int len)
+{
+ uint16_t packet_size;
+
+ assert (len > 0);
+ assert (*sockfd >= 0);
+
+ /* send short containing size of data packet */
+ packet_size = htons ((uint16_t) len);
+
+ if (swrite (*sockfd, (void *) &packet_size, sizeof (packet_size)) != 0)
+ {
+ *sockfd = -1;
+ return (-1);
+ }
+
+ /* send data packet */
+ if (swrite (*sockfd, (void *) buff, len) != 0)
+ {
+ *sockfd = -1;
+ return (-2);
+ }
+
+ return (0);
+}
+
+/* Get and print status from apcupsd NIS server */
+static int apc_query_server (char *host, int port,
+ struct apc_detail_s *apcups_detail)
+{
+ int n;
+ char recvline[1024];
+ char *tokptr;
+ char *key;
+ double value;
+
+ static int sockfd = -1;
+ static unsigned int complain = 0;
+
+#if APCMAIN
+# define PRINT_VALUE(name, val) printf(" Found property: name = %s; value = %f;\n", name, val)
+#else
+# define PRINT_VALUE(name, val) /**/
+#endif
+
+ if (sockfd < 0)
+ {
+ if ((sockfd = net_open (host, NULL, port)) < 0)
+ {
+ /* Complain once every six hours. */
+ int complain_step = 21600 / atoi (COLLECTD_STEP);
+
+ if ((complain % complain_step) == 0)
+ syslog (LOG_ERR, "apcups plugin: Connecting to the apcupsd failed.");
+ complain++;
+
+ return (-1);
+ }
+ else if (complain > 1)
+ {
+ syslog (LOG_NOTICE, "apcups plugin: Connection re-established to the apcupsd.");
+ complain = 0;
+ }
+ }
+
+ if (net_send (&sockfd, "status", 6) < 0)
+ {
+ syslog (LOG_ERR, "apcups plugin: Writing to the socket failed.");
+ return (-1);
+ }
+
+ while ((n = net_recv (&sockfd, recvline, sizeof (recvline) - 1)) > 0)
+ {
+ assert (n < sizeof (recvline));
+ recvline[n] = '\0';
+#if APCMAIN
+ printf ("net_recv = `%s';\n", recvline);
+#endif /* if APCMAIN */
+
+ tokptr = strtok (recvline, " :\t");
+ while (tokptr != NULL)
+ {
+ key = tokptr;
+ if ((tokptr = strtok (NULL, " :\t")) == NULL)
+ continue;
+ value = atof (tokptr);
+
+ PRINT_VALUE (key, value);
+
+ if (strcmp ("LINEV", key) == 0)
+ apcups_detail->linev = value;
+ else if (strcmp ("BATTV", key) == 0)
+ apcups_detail->battv = value;
+ else if (strcmp ("ITEMP", key) == 0)
+ apcups_detail->itemp = value;
+ else if (strcmp ("LOADPCT", key) == 0)
+ apcups_detail->loadpct = value;
+ else if (strcmp ("BCHARGE", key) == 0)
+ apcups_detail->bcharge = value;
+ else if (strcmp ("OUTPUTV", key) == 0)
+ apcups_detail->outputv = value;
+ else if (strcmp ("LINEFREQ", key) == 0)
+ apcups_detail->linefreq = value;
+ else if (strcmp ("TIMELEFT", key) == 0)
+ apcups_detail->timeleft = value;
+
+ tokptr = strtok (NULL, ":");
+ } /* while (tokptr != NULL) */
+ }
+
+ if (n < 0)
+ {
+ syslog (LOG_WARNING, "apcups plugin: Error reading from socket");
+ return (-1);
+ }
+#if APCMAIN
+ else
+ {
+ /* close the opened socket */
+ net_close (&sockfd);
+ }
+#endif /* APCMAIN */
+
+ return (0);
+}
+
+#if APCMAIN
+/*
+ * This is used for testing apcups in a standalone mode.
+ * Usefull for debugging.
+ */
+int main (int argc, char **argv)
+{
+ /* we are not really going to use this */
+ struct apc_detail_s apcups_detail;
+
+ openlog ("apcups", LOG_PID | LOG_NDELAY | LOG_LOCAL1, LOG_USER);
+
+ if (global_host == NULL || strcmp (global_host, "0.0.0.0") == 0)
+ global_host = "localhost";
+
+ if(apc_query_server (global_host, global_port, &apcups_detail) < 0)
+ {
+ printf("apcups: Failed...\n");
+ return(-1);
+ }
+
+ return 0;
+}
+#else
+static int apcups_config (char *key, char *value)
+{
+ if (strcasecmp (key, "host") == 0)
+ {
+ if (global_host != NULL)
+ {
+ free (global_host);
+ global_host = NULL;
+ }
+ if ((global_host = strdup (value)) == NULL)
+ return (1);
+ }
+ else if (strcasecmp (key, "Port") == 0)
+ {
+ int port_tmp = atoi (value);
+ if (port_tmp < 1 || port_tmp > 65535)
+ {
+ syslog (LOG_WARNING, "apcups plugin: Invalid port: %i", port_tmp);
+ return (1);
+ }
+ global_port = port_tmp;
+ }
+ else
+ {
+ return (-1);
+ }
+ return (0);
+}
+
+static void apcups_init (void)
+{
+ return;
+}
+
+static void apc_write_voltage (char *host, char *inst, char *val)
+{
+ char file[512];
+ int status;
+
+ status = snprintf (file, 512, bvolt_file_template, inst);
+ if ((status < 1) || (status >= 512))
+ return;
+
+ rrd_update_file (host, file, val, bvolt_ds_def, bvolt_ds_num);
+}
+
+static void apc_write_charge (char *host, char *inst, char *val)
+{
+ rrd_update_file (host, charge_file_template, val, charge_ds_def, charge_ds_num);
+}
+
+static void apc_write_percent (char *host, char *inst, char *val)
+{
+ rrd_update_file (host, load_file_template, val, load_ds_def, load_ds_num);
+}
+
+static void apc_write_timeleft (char *host, char *inst, char *val)
+{
+ rrd_update_file (host, time_file_template, val, time_ds_def, time_ds_num);
+}
+
+static void apc_write_temperature (char *host, char *inst, char *val)
+{
+ rrd_update_file (host, temp_file_template, val, temp_ds_def, temp_ds_num);
+}
+
+static void apc_write_frequency (char *host, char *inst, char *val)
+{
+ char file[512];
+ int status;
+
+ status = snprintf (file, 512, freq_file_template, inst);
+ if ((status < 1) || (status >= 512))
+ return;
+
+ rrd_update_file (host, file, val, freq_ds_def, freq_ds_num);
+}
+
+static void apc_submit_generic (char *type, char *inst,
+ double value)
+{
+ char buf[512];
+ int status;
+
+ status = snprintf (buf, 512, "%u:%f",
+ (unsigned int) curtime, value);
+ if ((status < 1) || (status >= 512))
+ return;
+
+ DBG ("plugin_submit (%s, %s, %s);", type, inst, buf);
+ plugin_submit (type, inst, buf);
+}
+
+static void apc_submit (struct apc_detail_s *apcups_detail)
+{
+ apc_submit_generic ("apcups_voltage", "input", apcups_detail->linev);
+ apc_submit_generic ("apcups_voltage", "output", apcups_detail->outputv);
+ apc_submit_generic ("apcups_voltage", "battery", apcups_detail->battv);
+ apc_submit_generic ("apcups_charge", "-", apcups_detail->bcharge);
+ apc_submit_generic ("apcups_charge_pct", "-", apcups_detail->loadpct);
+ apc_submit_generic ("apcups_timeleft", "-", apcups_detail->timeleft);
+ apc_submit_generic ("apcups_temp", "-", apcups_detail->itemp);
+ apc_submit_generic ("apcups_frequency", "input", apcups_detail->linefreq);
+}
+
+static void apcups_read (void)
+{
+ struct apc_detail_s apcups_detail;
+ int status;
+
+ apcups_detail.linev = -1.0;
+ apcups_detail.outputv = -1.0;
+ apcups_detail.battv = -1.0;
+ apcups_detail.loadpct = -1.0;
+ apcups_detail.bcharge = -1.0;
+ apcups_detail.timeleft = -1.0;
+ apcups_detail.itemp = -300.0;
+ apcups_detail.linefreq = -1.0;
+
+ status = apc_query_server (global_host == NULL
+ ? APCUPS_DEFAULT_HOST
+ : global_host,
+ global_port, &apcups_detail);
+
+ /*
+ * if we did not connect then do not bother submitting
+ * zeros. We want rrd files to have NAN.
+ */
+ if (status != 0)
+ {
+ DBG ("apc_query_server (%s, %i) = %i",
+ global_host == NULL
+ ? APCUPS_DEFAULT_HOST
+ : global_host,
+ global_port, status);
+ return;
+ }
+
+ apc_submit (&apcups_detail);
+} /* apcups_read */
+
+void module_register (void)
+{
+ plugin_register (MODULE_NAME, apcups_init, apcups_read, NULL);
+ plugin_register ("apcups_voltage", NULL, NULL, apc_write_voltage);
+ plugin_register ("apcups_charge", NULL, NULL, apc_write_charge);
+ plugin_register ("apcups_charge_pct", NULL, NULL, apc_write_percent);
+ plugin_register ("apcups_timeleft", NULL, NULL, apc_write_timeleft);
+ plugin_register ("apcups_temp", NULL, NULL, apc_write_temperature);
+ plugin_register ("apcups_frequency", NULL, NULL, apc_write_frequency);
+ cf_register (MODULE_NAME, apcups_config, config_keys, config_keys_num);
+}
+
+#endif /* if APCMAIN */
+#undef MODULE_NAME
diff --git a/src/battery.c b/src/battery.c
index fa93b1c66a6b81903fe4f53a63925176590cdb33..2141a58c725f3515963f71e29566ac0315b0fca8 100644 (file)
--- a/src/battery.c
+++ b/src/battery.c
# include <IOKit/ps/IOPSKeys.h>
#endif
-#if HAVE_IOKIT_PS_IOPOWERSOURCES_H || KERNEL_LINUX
+#if HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H || KERNEL_LINUX
# define BATTERY_HAVE_READ 1
#else
# define BATTERY_HAVE_READ 0
};
static int ds_num_charge = 1;
-#if HAVE_IOKIT_PS_IOPOWERSOURCES_H
+#if HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H
/* No global variables */
-/* #endif HAVE_IOKIT_PS_IOPOWERSOURCES_H */
+/* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */
#elif KERNEL_LINUX
static int battery_pmu_num = 0;
static void battery_init (void)
{
-#if HAVE_IOKIT_PS_IOPOWERSOURCES_H
+#if HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H
/* No init neccessary */
-/* #endif HAVE_IOKIT_PS_IOPOWERSOURCES_H */
+/* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */
#elif KERNEL_LINUX
int len;
@@ -202,23 +202,70 @@ static void battery_submit (char *inst, double current, double voltage, double c
}
}
-static void battery_read (void)
+#if HAVE_IOKIT_PS_IOPOWERSOURCES_H || HAVE_IOKIT_IOKITLIB_H
+double dict_get_double (CFDictionaryRef dict, char *key_string)
{
+ double val_double;
+ long long val_int;
+ CFNumberRef val_obj;
+ CFStringRef key_obj;
+
+ key_obj = CFStringCreateWithCString (kCFAllocatorDefault, key_string,
+ kCFStringEncodingASCII);
+ if (key_obj == NULL)
+ {
+ DBG ("CFStringCreateWithCString (%s) failed.\n", key_string);
+ return (INVALID_VALUE);
+ }
+
+ if ((val_obj = CFDictionaryGetValue (dict, key_obj)) == NULL)
+ {
+ DBG ("CFDictionaryGetValue (%s) failed.", key_string);
+ CFRelease (key_obj);
+ return (INVALID_VALUE);
+ }
+ CFRelease (key_obj);
+
+ if (CFGetTypeID (val_obj) == CFNumberGetTypeID ())
+ {
+ if (CFNumberIsFloatType (val_obj))
+ {
+ CFNumberGetValue (val_obj,
+ kCFNumberDoubleType,
+ &val_double);
+ }
+ else
+ {
+ CFNumberGetValue (val_obj,
+ kCFNumberLongLongType,
+ &val_int);
+ val_double = val_int;
+ }
+ }
+ else
+ {
+ DBG ("CFGetTypeID (val_obj) = %i", (int) CFGetTypeID (val_obj));
+ return (INVALID_VALUE);
+ }
+
+ return (val_double);
+}
+#endif /* HAVE_IOKIT_PS_IOPOWERSOURCES_H || HAVE_IOKIT_IOKITLIB_H */
+
#if HAVE_IOKIT_PS_IOPOWERSOURCES_H
+static void get_via_io_power_sources (double *ret_charge,
+ double *ret_current,
+ double *ret_voltage)
+{
CFTypeRef ps_raw;
CFArrayRef ps_array;
int ps_array_len;
CFDictionaryRef ps_dict;
CFTypeRef ps_obj;
- CFTypeRef ps_value;
+ double temp_double;
int i;
- char name[128];
- double charge = INVALID_VALUE;
- double current = INVALID_VALUE;
- double voltage = INVALID_VALUE;
-
ps_raw = IOPSCopyPowerSourcesInfo ();
ps_array = IOPSCopyPowerSourcesList (ps_raw);
ps_array_len = CFArrayGetCount (ps_array);
ps_obj = CFArrayGetValueAtIndex (ps_array, i);
ps_dict = IOPSGetPowerSourceDescription (ps_raw, ps_obj);
+ if (ps_dict == NULL)
+ {
+ DBG ("IOPSGetPowerSourceDescription failed.");
+ continue;
+ }
+
if (CFGetTypeID (ps_dict) != CFDictionaryGetTypeID ())
{
DBG ("IOPSGetPowerSourceDescription did not return a CFDictionaryRef");
continue;
}
- if (ps_dict != NULL)
+ /* FIXME: Check if this is really an internal battery */
+
+ if (*ret_charge == INVALID_VALUE)
{
- /* Get the current capacity/charge */
- ps_value = NULL;
- charge = INVALID_VALUE;
- if (CFDictionaryGetValueIfPresent (ps_dict,
- CFSTR (kIOPSCurrentCapacityKey),
- &ps_value))
- {
- if (CFGetTypeID (ps_value) != CFNumberGetTypeID ())
- CFNumberGetValue (ps_value,
- kCFNumberDoubleType,
- &charge);
- else
- DBG ("kIOPSCurrentCapacityKey: Not a CFNumber");
+ /* This is the charge in percent. */
+ temp_double = dict_get_double (ps_dict,
+ kIOPSCurrentCapacityKey);
+ if ((temp_double != INVALID_VALUE)
+ && (temp_double >= 0.0)
+ && (temp_double <= 100.0))
+ *ret_charge = temp_double;
+ }
- DBG ("charge = %f", charge);
- }
- else
- DBG ("`%s' does not exist", kIOPSCurrentCapacityKey);
-
- /* Get the current */
- ps_value = NULL;
- current = INVALID_VALUE;
- if (CFDictionaryGetValueIfPresent (ps_dict,
- CFSTR (kIOPSCurrentKey),
- &ps_value))
- {
- if (CFGetTypeID (ps_value) != CFNumberGetTypeID ())
- CFNumberGetValue (ps_value,
- kCFNumberDoubleType,
- ¤t);
- else
- DBG ("kIOPSCurrentKey: Not a CFNumber");
- DBG ("current = %f", current);
- }
- else
- DBG ("`%s' does not exist", kIOPSCurrentKey);
-
- /* Get the voltage */
- ps_value = NULL;
- voltage = INVALID_VALUE;
- if (CFDictionaryGetValueIfPresent (ps_dict,
- CFSTR (kIOPSVoltageKey),
- &ps_value))
- {
- if (CFGetTypeID (ps_value) != CFNumberGetTypeID ())
- CFNumberGetValue (ps_value,
- kCFNumberDoubleType,
- &voltage);
- else
- DBG ("kIOPSVoltageKey: Not a CFNumber");
- DBG ("voltage = %f", voltage);
- }
- else
- DBG ("`%s' does not exist", kIOPSVoltageKey);
+ if (*ret_current == INVALID_VALUE)
+ {
+ temp_double = dict_get_double (ps_dict,
+ kIOPSCurrentKey);
+ if (temp_double != INVALID_VALUE)
+ *ret_current = temp_double / 1000.0;
+ }
+
+ if (*ret_voltage == INVALID_VALUE)
+ {
+ temp_double = dict_get_double (ps_dict,
+ kIOPSVoltageKey);
+ if (temp_double != INVALID_VALUE)
+ *ret_voltage = temp_double / 1000.0;
+ }
+ }
+
+ CFRelease(ps_array);
+ CFRelease(ps_raw);
+}
+#endif /* HAVE_IOKIT_PS_IOPOWERSOURCES_H */
+
+#if HAVE_IOKIT_IOKITLIB_H
+static void get_via_generic_iokit (double *ret_charge,
+ double *ret_current,
+ double *ret_voltage)
+{
+ kern_return_t status;
+ io_iterator_t iterator;
+ io_object_t io_obj;
+
+ CFDictionaryRef bat_root_dict;
+ CFArrayRef bat_info_arry;
+ CFIndex bat_info_arry_len;
+ CFIndex bat_info_arry_pos;
+ CFDictionaryRef bat_info_dict;
+
+ double temp_double;
+
+ status = IOServiceGetMatchingServices (kIOMasterPortDefault,
+ IOServiceNameMatching ("battery"),
+ &iterator);
+ if (status != kIOReturnSuccess)
+ {
+ DBG ("IOServiceGetMatchingServices failed.");
+ return;
+ }
- /* Get the name of the device.. */
- ps_value = NULL;
- if (CFDictionaryGetValueIfPresent (ps_dict,
- CFSTR (kIOPSNameKey),
- &ps_value))
+ while ((io_obj = IOIteratorNext (iterator)))
+ {
+ status = IORegistryEntryCreateCFProperties (io_obj,
+ (CFMutableDictionaryRef *) &bat_root_dict,
+ kCFAllocatorDefault,
+ kNilOptions);
+ if (status != kIOReturnSuccess)
+ {
+ DBG ("IORegistryEntryCreateCFProperties failed.");
+ continue;
+ }
+
+ bat_info_arry = (CFArrayRef) CFDictionaryGetValue (bat_root_dict,
+ CFSTR ("IOBatteryInfo"));
+ if (bat_info_arry == NULL)
+ {
+ CFRelease (bat_root_dict);
+ continue;
+ }
+ bat_info_arry_len = CFArrayGetCount (bat_info_arry);
+
+ for (bat_info_arry_pos = 0;
+ bat_info_arry_pos < bat_info_arry_len;
+ bat_info_arry_pos++)
+ {
+ bat_info_dict = (CFDictionaryRef) CFArrayGetValueAtIndex (bat_info_arry, bat_info_arry_pos);
+
+ if (*ret_charge == INVALID_VALUE)
{
- if (CFGetTypeID (ps_value) != CFStringGetTypeID ())
- {
- if (!CFStringGetCString (ps_value,
- name, 128,
- kCFStringEncodingASCII))
- continue;
- }
- else
- {
- DBG ("kIOPSNameKey: Not a CFStringGetTypeID");
- }
- DBG ("Original string: `%s'", name);
+ temp_double = dict_get_double (bat_info_dict,
+ "Capacity");
+ if (temp_double != INVALID_VALUE)
+ *ret_charge = temp_double / 1000.0;
}
- else
+
+ if (*ret_current == INVALID_VALUE)
{
- strncpy (name, "unknown", 128);
+ temp_double = dict_get_double (bat_info_dict,
+ "Current");
+ if (temp_double != INVALID_VALUE)
+ *ret_current = temp_double / 1000.0;
}
- name[127] = '\0';
- for (i = 0; i < 128; i++)
+
+ if (*ret_voltage == INVALID_VALUE)
{
- if (name[i] == '\0')
- break;
- else if (isalnum (name[i]))
- name[i] = (char) tolower (name[i]);
- else
- name[i] = '_';
+ temp_double = dict_get_double (bat_info_dict,
+ "Voltage");
+ if (temp_double != INVALID_VALUE)
+ *ret_voltage = temp_double / 1000.0;
}
-
- battery_submit (name, current, voltage, charge);
}
+
+ CFRelease (bat_root_dict);
}
- CFRelease(ps_array);
- CFRelease(ps_raw);
-/* #endif HAVE_IOKIT_PS_IOPOWERSOURCES_H */
+ IOObjectRelease (iterator);
+}
+#endif /* HAVE_IOKIT_IOKITLIB_H */
+
+static void battery_read (void)
+{
+#if HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H
+ double charge = INVALID_VALUE; /* Current charge in Ah */
+ double current = INVALID_VALUE; /* Current in A */
+ double voltage = INVALID_VALUE; /* Voltage in V */
+
+ double charge_rel = INVALID_VALUE; /* Current charge in percent */
+ double charge_abs = INVALID_VALUE; /* Total capacity */
+
+#if HAVE_IOKIT_PS_IOPOWERSOURCES_H
+ get_via_io_power_sources (&charge_rel, ¤t, &voltage);
+#endif
+#if HAVE_IOKIT_IOKITLIB_H
+ get_via_generic_iokit (&charge_abs, ¤t, &voltage);
+#endif
+
+ if ((charge_rel != INVALID_VALUE) && (charge_abs != INVALID_VALUE))
+ charge = charge_abs * charge_rel / 100.0;
+
+ if ((charge != INVALID_VALUE)
+ || (current != INVALID_VALUE)
+ || (voltage != INVALID_VALUE))
+ battery_submit ("0", current, voltage, charge);
+/* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */
#elif KERNEL_LINUX
FILE *fh;
diff --git a/src/collectd.c b/src/collectd.c
index e9bc0d5dcc89ccd032976af8beb7d6a08be1b00f..0d9c90fce19a5dd2fe1e222c8a61f3d07e63a67d 100644 (file)
--- a/src/collectd.c
+++ b/src/collectd.c
if (timeval_sub_timespec (&tv_next, &tv_now, &ts_wait) != 0)
{
- syslog (LOG_WARNING, "No sleeping because `timeval_sub_timespec' returned non-zero!");
+ syslog (LOG_WARNING, "Not sleeping because `timeval_sub_timespec' returned non-zero!");
continue;
}
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index a00bbb21f8fe8142234032e5b6de1089c818269c..791489158530c445703486d9425f38f90e13efa5 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
=head2 Plugin C<apache>
+To configure the C<apache>-plugin you first need to configure the Apache
+webserver correctly. The Apache-plugin C<mod_status> needs to be loaded and
+working and the C<ExtendedStatus> directive needs to be B<enabled>. You can use
+the following snipped to base your Apache config upon:
+
+ ExtendedStatus on
+ <IfModule mod_status.c>
+ <Location /mod_status>
+ SetHandler server-status
+ </Location>
+ </IfModule>
+
+The following options are accepted by the C<apache>-plugin:
+
=over 4
=item B<URL> I<http://host/mod_status?auto>
Optional password needed for authentication.
+=item B<CACert> I<File>
+
+File that holds one or more SSL certificates. If you want to use HTTPS you will
+possibly need this option. What CA certificates come bundeled with C<libcurl>
+and are checked by default depends on the distribution you use.
+
+=back
+
+=head2 Plugin C<apcups>
+
+=over 4
+
+=item B<Host> I<Hostname>
+
+Hostname of the host running B<apcupsd>. Defaults to B<localhost>. Please note
+that IPv6 support has been disabled unless someone can confirm or decline that
+B<apcupsd> can handle it.
+
+=item B<Port> I<Port>
+
+TCP-Port to connect to. Defaults to B<3551>.
+
=back
=head2 Plugin C<hddtemp>
=back
+=head2 Plugin C<ntpd>
+
+=over 4
+
+=item B<Host> I<Hostname>
+
+Hostname of the host running B<ntpd>. Defaults to B<localhost>.
+
+=item B<Port> I<Port>
+
+UDP-Port to connect to. Defaults to B<123>.
+
+=back
+
=head2 Plugin C<mysql>
=over 4
=back
+=head2 Plugin C<traffic>
+
+=over 4
+
+=item B<Interface> I<Interface>
+
+Select this interface. By default these interfaces will then be collected. For a more detailed description see B<IgnoreSelected> below.
+
+=item B<IgnoreSelected> I<true>|I<false>
+
+If no configuration if given, the B<traffic>-plugin will collect data from
+all interfaces. This may not be practical, especially for loopback- and
+similar interfaces. Thus, you can use the B<Interface>-option to pick the
+interfaces you're interested in. Sometimes, however, it's easier/prefered
+to collect all interfaces I<except> a few ones. This option enables you to
+do that: By setting B<IgnoreSelected> to I<true> the effect of
+B<Interface> is inversed: All selected interfaces are ignored and all
+other interfaces are collected.
+
+=back
+
=head1 SEE ALSO
L<collectd(1)>
diff --git a/src/collectd.pod b/src/collectd.pod
index 488fbe22f28bc2c69cb6c6a62f3bc74630a39d1b..fcad460919c8582423f0f03ca1421e2af68e5c4d 100644 (file)
--- a/src/collectd.pod
+++ b/src/collectd.pod
=over 4
+=item Apache traffic (F<apache/apache_bytes.rrd>)
+
+ DS:count:COUNTER:HEARTBEAT:0:134217728
+
+=item Apache requests (F<apache/apache_requests.rrd>)
+
+ DS:count:COUNTER:HEARTBEAT:0:1048576
+
+=item Apache scoreboard (F<apache/apache_scoreboard-I<E<lt>nameE<gt>>.rrd>)
+
+ DS:count:GAUGE:HEARTBEAT:0:U
+
+=item Apple temperature sensor (F<apple_sensors/temperature-I<E<lt>nameE<gt>>.rrd>)
+
+ DS:value:GAUGE:HEARTBEAT:U:U
+
+=item Apple fanspeed sensor (F<apple_sensors/fanspeed-I<E<lt>nameE<gt>>.rrd>)
+
+ DS:value:GAUGE:HEARTBEAT:U:U
+
=item Battery charge (F<battery-I<E<lt>nameE<gt>>/charge.rrd>)
- DS:charge:GAUGE:25:0:U
+ DS:charge:GAUGE:HEARTBEAT:0:U
=item Battery current (F<battery-I<E<lt>nameE<gt>>/current.rrd>)
- DS:current:GAUGE:25:U:U
+ DS:current:GAUGE:HEARTBEAT:U:U
=item Battery voltage (F<battery-I<E<lt>nameE<gt>>/voltage.rrd>)
- DS:voltage:GAUGE:25:U:U
+ DS:voltage:GAUGE:HEARTBEAT:U:U
=item CPU (F<cpu-I<E<lt>numE<gt>>.rrd>)
- DS:user:COUNTER:25:0:100
- DS:nice:COUNTER:25:0:100
- DS:syst:COUNTER:25:0:100
- DS:idle:COUNTER:25:0:100
- DS:wait:COUNTER:25:0:100
+ DS:user:COUNTER:HEARTBEAT:0:100
+ DS:nice:COUNTER:HEARTBEAT:0:100
+ DS:syst:COUNTER:HEARTBEAT:0:100
+ DS:idle:COUNTER:HEARTBEAT:0:100
+ DS:wait:COUNTER:HEARTBEAT:0:100
+
+=item CPU frequency (F<cpufreq-I<E<lt>numE<gt>>.rrd>)
+
+ DS:value:GAUGE:HEARTBEAT:0:U
=item Mountpoints (F<df-I<E<lt>pathE<gt>>.rrd>)
- DS:used:GAUGE:25:0:U
- DS:free:GAUGE:25:0:U
+ DS:used:GAUGE:HEARTBEAT:0:U
+ DS:free:GAUGE:HEARTBEAT:0:U
=item Diskstats (F<disk-I<E<lt>majorE<gt>>-I<E<lt>minorE<gt>>.rrd>)
- DS:rcount:COUNTER:25:0:U
- DS:rmerged:COUNTER:25:0:U
- DS:rbytes:COUNTER:25:0:U
- DS:rtime:COUNTER:25:0:U
- DS:wcount:COUNTER:25:0:U
- DS:wmerged:COUNTER:25:0:U
- DS:wbytes:COUNTER:25:0:U
- DS:wtime:COUNTER:25:0:U
+ DS:rcount:COUNTER:HEARTBEAT:0:U
+ DS:rmerged:COUNTER:HEARTBEAT:0:U
+ DS:rbytes:COUNTER:HEARTBEAT:0:U
+ DS:rtime:COUNTER:HEARTBEAT:0:U
+ DS:wcount:COUNTER:HEARTBEAT:0:U
+ DS:wmerged:COUNTER:HEARTBEAT:0:U
+ DS:wbytes:COUNTER:HEARTBEAT:0:U
+ DS:wtime:COUNTER:HEARTBEAT:0:U
=item Diskstats (F<partition-I<E<lt>majorE<gt>>-I<E<lt>minorE<gt>>.rrd>)
- DS:rcount:COUNTER:25:0:U
- DS:rbytes:COUNTER:25:0:U
- DS:wcount:COUNTER:25:0:U
- DS:wbytes:COUNTER:25:0:U
+ DS:rcount:COUNTER:HEARTBEAT:0:U
+ DS:rbytes:COUNTER:HEARTBEAT:0:U
+ DS:wcount:COUNTER:HEARTBEAT:0:U
+ DS:wbytes:COUNTER:HEARTBEAT:0:U
=item HDD Temperature (F<hddtemp-I<E<lt>majorE<gt>>-I<E<lt>minorE<gt>>.rrd>)
- DS:value:GAUGE:25:U:U
+ DS:value:GAUGE:HEARTBEAT:U:U
=item System load (F<load.rrd>)
- DS:shortterm:GAUGE:25:0:100
- DS:midterm:GAUGE:25:0:100
- DS:longterm:GAUGE:25:0:100
+ DS:shortterm:GAUGE:HEARTBEAT:0:100
+ DS:midterm:GAUGE:HEARTBEAT:0:100
+ DS:longterm:GAUGE:HEARTBEAT:0:100
=item Memory usage (F<memory.rrd>)
- DS:used:GAUGE:25:0:9223372036854775807
- DS:free:GAUGE:25:0:9223372036854775807
- DS:buffers:GAUGE:25:0:9223372036854775807
- DS:cached:GAUGE:25:0:9223372036854775807
+ DS:used:GAUGE:HEARTBEAT:0:9223372036854775807
+ DS:free:GAUGE:HEARTBEAT:0:9223372036854775807
+ DS:buffers:GAUGE:HEARTBEAT:0:9223372036854775807
+ DS:cached:GAUGE:HEARTBEAT:0:9223372036854775807
=item MySQL commands and handlers (F<mysql_commands-I<E<lt>commandE<gt>>.rrd> and F<mysql_handler-I<E<lt>handlerE<gt>>.rrd>)
- DS:value:COUNTER:25:0:U
+ DS:value:COUNTER:HEARTBEAT:0:U
=item MySQL query cache (F<mysql_qcache.rrd>)
- DS:hits:COUNTER:25:0:U
- DS:inserts:COUNTER:25:0:U
- DS:not_cached:COUNTER:25:0:U
- DS:lowmem_prunes:COUNTER:25:0:U
- DS:queries_in_cache:GAUGE:25:0:U
+ DS:hits:COUNTER:HEARTBEAT:0:U
+ DS:inserts:COUNTER:HEARTBEAT:0:U
+ DS:not_cached:COUNTER:HEARTBEAT:0:U
+ DS:lowmem_prunes:COUNTER:HEARTBEAT:0:U
+ DS:queries_in_cache:GAUGE:HEARTBEAT:0:U
=item MySQL threads (F<mysql_threads.rrd>)
- DS:running:GAUGE:25:0:U
- DS:connected:GAUGE:25:0:U
- DS:cached:GAUGE:25:0:U
- DS:created:COUNTER:25:0:U
+ DS:running:GAUGE:HEARTBEAT:0:U
+ DS:connected:GAUGE:HEARTBEAT:0:U
+ DS:cached:GAUGE:HEARTBEAT:0:U
+ DS:created:COUNTER:HEARTBEAT:0:U
=item NFSv2 Procedures (F<nfs2_procedures-I<(client|server)>.rrd>)
- DS:null:COUNTER:25:0:U
- DS:getattr:COUNTER:25:0:U
- DS:setattr:COUNTER:25:0:U
- DS:root:COUNTER:25:0:U
- DS:lookup:COUNTER:25:0:U
- DS:readlink:COUNTER:25:0:U
- DS:read:COUNTER:25:0:U
- DS:wrcache:COUNTER:25:0:U
- DS:write:COUNTER:25:0:U
- DS:create:COUNTER:25:0:U
- DS:remove:COUNTER:25:0:U
- DS:rename:COUNTER:25:0:U
- DS:link:COUNTER:25:0:U
- DS:symlink:COUNTER:25:0:U
- DS:mkdir:COUNTER:25:0:U
- DS:rmdir:COUNTER:25:0:U
- DS:readdir:COUNTER:25:0:U
- DS:fsstat:COUNTER:25:0:U
+ DS:null:COUNTER:HEARTBEAT:0:U
+ DS:getattr:COUNTER:HEARTBEAT:0:U
+ DS:setattr:COUNTER:HEARTBEAT:0:U
+ DS:root:COUNTER:HEARTBEAT:0:U
+ DS:lookup:COUNTER:HEARTBEAT:0:U
+ DS:readlink:COUNTER:HEARTBEAT:0:U
+ DS:read:COUNTER:HEARTBEAT:0:U
+ DS:wrcache:COUNTER:HEARTBEAT:0:U
+ DS:write:COUNTER:HEARTBEAT:0:U
+ DS:create:COUNTER:HEARTBEAT:0:U
+ DS:remove:COUNTER:HEARTBEAT:0:U
+ DS:rename:COUNTER:HEARTBEAT:0:U
+ DS:link:COUNTER:HEARTBEAT:0:U
+ DS:symlink:COUNTER:HEARTBEAT:0:U
+ DS:mkdir:COUNTER:HEARTBEAT:0:U
+ DS:rmdir:COUNTER:HEARTBEAT:0:U
+ DS:readdir:COUNTER:HEARTBEAT:0:U
+ DS:fsstat:COUNTER:HEARTBEAT:0:U
=item NFSv3 Procedures (F<nfs3_procedures-I<(client|server)>.rrd>)
- DS:null:COUNTER:25:0:U
- DS:getattr:COUNTER:25:0:U
- DS:setattr:COUNTER:25:0:U
- DS:lookup:COUNTER:25:0:U
- DS:access:COUNTER:25:0:U
- DS:readlink:COUNTER:25:0:U
- DS:read:COUNTER:25:0:U
- DS:write:COUNTER:25:0:U
- DS:create:COUNTER:25:0:U
- DS:mkdir:COUNTER:25:0:U
- DS:symlink:COUNTER:25:0:U
- DS:mknod:COUNTER:25:0:U
- DS:remove:COUNTER:25:0:U
- DS:rmdir:COUNTER:25:0:U
- DS:rename:COUNTER:25:0:U
- DS:link:COUNTER:25:0:U
- DS:readdir:COUNTER:25:0:U
- DS:readdirplus:COUNTER:25:0:U
- DS:fsstat:COUNTER:25:0:U
- DS:fsinfo:COUNTER:25:0:U
- DS:pathconf:COUNTER:25:0:U
- DS:commit:COUNTER:25:0:U
+ DS:null:COUNTER:HEARTBEAT:0:U
+ DS:getattr:COUNTER:HEARTBEAT:0:U
+ DS:setattr:COUNTER:HEARTBEAT:0:U
+ DS:lookup:COUNTER:HEARTBEAT:0:U
+ DS:access:COUNTER:HEARTBEAT:0:U
+ DS:readlink:COUNTER:HEARTBEAT:0:U
+ DS:read:COUNTER:HEARTBEAT:0:U
+ DS:write:COUNTER:HEARTBEAT:0:U
+ DS:create:COUNTER:HEARTBEAT:0:U
+ DS:mkdir:COUNTER:HEARTBEAT:0:U
+ DS:symlink:COUNTER:HEARTBEAT:0:U
+ DS:mknod:COUNTER:HEARTBEAT:0:U
+ DS:remove:COUNTER:HEARTBEAT:0:U
+ DS:rmdir:COUNTER:HEARTBEAT:0:U
+ DS:rename:COUNTER:HEARTBEAT:0:U
+ DS:link:COUNTER:HEARTBEAT:0:U
+ DS:readdir:COUNTER:HEARTBEAT:0:U
+ DS:readdirplus:COUNTER:HEARTBEAT:0:U
+ DS:fsstat:COUNTER:HEARTBEAT:0:U
+ DS:fsinfo:COUNTER:HEARTBEAT:0:U
+ DS:pathconf:COUNTER:HEARTBEAT:0:U
+ DS:commit:COUNTER:HEARTBEAT:0:U
=item Network latency / Ping (F<ping-I<E<lt>hostnameE<gt>>.rrd>)
- DS:ping:GAUGE:25:0:65535
+ DS:ping:GAUGE:HEARTBEAT:0:65535
=item Processes (F<processes.rrd>)
- DS:running:GAUGE:25:0:65535
- DS:sleeping:GAUGE:25:0:65535
- DS:zombies:GAUGE:25:0:65535
- DS:stopped:GAUGE:25:0:65535
- DS:paging:GAUGE:25:0:65535
- DS:blocked:GAUGE:25:0:65535
+ DS:running:GAUGE:HEARTBEAT:0:65535
+ DS:sleeping:GAUGE:HEARTBEAT:0:65535
+ DS:zombies:GAUGE:HEARTBEAT:0:65535
+ DS:stopped:GAUGE:HEARTBEAT:0:65535
+ DS:paging:GAUGE:HEARTBEAT:0:65535
+ DS:blocked:GAUGE:HEARTBEAT:0:65535
=item lm_sensors (F<sensors-I<E<lt>chipE<gt>>-I<E<lt>featureE<gt>>.rrd>)
- DS:value:GAUGE:25:U:U
+ DS:value:GAUGE:HEARTBEAT:U:U
=item Serial port traffic (F<serial-I<E<lt>numE<gt>>.rrd>)
- DS:incoming:COUNTER:25:0:U
- DS:outgoing:COUNTER:25:0:U
+ DS:incoming:COUNTER:HEARTBEAT:0:U
+ DS:outgoing:COUNTER:HEARTBEAT:0:U
=item Swap usage (F<swap.rrd>)
- DS:used:GAUGE:25:0:1099511627776
- DS:free:GAUGE:25:0:1099511627776
- DS:cached:GAUGE:25:0:1099511627776
- DS:resv:GAUGE:25:0:1099511627776
+ DS:used:GAUGE:HEARTBEAT:0:1099511627776
+ DS:free:GAUGE:HEARTBEAT:0:1099511627776
+ DS:cached:GAUGE:HEARTBEAT:0:1099511627776
+ DS:resv:GAUGE:HEARTBEAT:0:1099511627776
=item Tape drive usage (F<tape-I<E<lt>nameE<gt>>.rrd>)
- DS:rcount:COUNTER:25:0:
- DS:rmerged:COUNTER:25:0:U
- DS:rbytes:COUNTER:25:0:U
- DS:rtime:COUNTER:25:0:U
- DS:wcount:COUNTER:25:0:U
- DS:wmerged:COUNTER:25:0:U
- DS:wbytes:COUNTER:25:0:U
- DS:wtime:COUNTER:25:0:U
+ DS:rcount:COUNTER:HEARTBEAT:0:
+ DS:rmerged:COUNTER:HEARTBEAT:0:U
+ DS:rbytes:COUNTER:HEARTBEAT:0:U
+ DS:rtime:COUNTER:HEARTBEAT:0:U
+ DS:wcount:COUNTER:HEARTBEAT:0:U
+ DS:wmerged:COUNTER:HEARTBEAT:0:U
+ DS:wbytes:COUNTER:HEARTBEAT:0:U
+ DS:wtime:COUNTER:HEARTBEAT:0:U
+
+=item Network traffic (F<traffic-I<E<lt>interfaceE<gt>>.rrd>)
+
+ DS:incoming:COUNTER:HEARTBEAT:0:U
+ DS:outgoing:COUNTER:HEARTBEAT:0:U
-=item Network traffic (F<traffic-I<E<lt>nameE<gt>>.rrd>)
+=item Interface packets (F<if_packets-I<E<lt>interfaceE<gt>>.rrd>)
- DS:incoming:COUNTER:25:0:U
- DS:outgoing:COUNTER:25:0:U
+ DS:rx:COUNTER:HEARTBEAT:0:U
+ DS:tx:COUNTER:HEARTBEAT:0:U
+
+=item Interface errors (F<if_errors-I<E<lt>interfaceE<gt>>.rrd>)
+
+ DS:rx:COUNTER:HEARTBEAT:0:U
+ DS:tx:COUNTER:HEARTBEAT:0:U
=item Users (F<users.rrd>)
- DS:users:GAUGE:25:0:65535
+ DS:users:GAUGE:HEARTBEAT:0:65535
=item VServer load (F<vserver-I<E<lt>xidE<gt>>/load.rrd>)
- DS:shortterm:GAUGE:25:0:100
- DS:midterm:GAUGE:25:0:100
- DS:longterm:GAUGE:25:0:100
+ DS:shortterm:GAUGE:HEARTBEAT:0:100
+ DS:midterm:GAUGE:HEARTBEAT:0:100
+ DS:longterm:GAUGE:HEARTBEAT:0:100
=item VServer threads (F<vserver-I<E<lt>xidE<gt>>/threads.rrd>)
- DS:total:GAUGE:25:0:65535
- DS:running:GAUGE:25:0:65535
- DS:uninterruptible:GAUGE:25:0:65535
- DS:onhold:GAUGE:25:0:65535
+ DS:total:GAUGE:HEARTBEAT:0:65535
+ DS:running:GAUGE:HEARTBEAT:0:65535
+ DS:uninterruptible:GAUGE:HEARTBEAT:0:65535
+ DS:onhold:GAUGE:HEARTBEAT:0:65535
=item VServer network traffic (F<vserver-I<E<lt>xidE<gt>>/traffic-I<E<lt>nameE<gt>>.rrd>)
- DS:incoming:COUNTER:25:0:9223372036854775807
- DS:outgoing:COUNTER:25:0:9223372036854775807
- DS:failed:COUNTER:25:0:9223372036854775807
+ DS:incoming:COUNTER:HEARTBEAT:0:9223372036854775807
+ DS:outgoing:COUNTER:HEARTBEAT:0:9223372036854775807
+ DS:failed:COUNTER:HEARTBEAT:0:9223372036854775807
=item VServer processes (F<vserver-I<E<lt>xidE<gt>>/vs_processes.rrd>)
- DS:total:GAUGE:25:0:65535
+ DS:total:GAUGE:HEARTBEAT:0:65535
=item VServer memory usage (F<vserver-I<E<lt>xidE<gt>>/vs_memory.rrd>)
- DS:vm:GAUGE:25:0:9223372036854775807
- DS:vml:GAUGE:25:0:9223372036854775807
- DS:rss:GAUGE:25:0:9223372036854775807
- DS:anon:GAUGE:25:0:9223372036854775807
+ DS:vm:GAUGE:HEARTBEAT:0:9223372036854775807
+ DS:vml:GAUGE:HEARTBEAT:0:9223372036854775807
+ DS:rss:GAUGE:HEARTBEAT:0:9223372036854775807
+ DS:anon:GAUGE:HEARTBEAT:0:9223372036854775807
+
+=item Wireless link quality (F<wireless-I<E<lt>interfaceE<gt>>.rrd>)
+
+ DS:quality:GAUGE:HEARTBEAT:0:U
+ DS:power:GAUGE:HEARTBEAT:U:0
+ DS:noise:GAUGE:HEARTBEAT:U:0
=back
diff --git a/src/common.c b/src/common.c
index 78be3afce48a6318336367b618c7660b0bad3034..5487b326fd34ac31eb8adfe20fa6971ecd0c4fec 100644 (file)
--- a/src/common.c
+++ b/src/common.c
}
#endif
+ssize_t sread (int fd, void *buf, size_t count)
+{
+ char *ptr;
+ size_t nleft;
+ ssize_t status;
+
+ ptr = (char *) buf;
+ nleft = count;
+
+ while (nleft > 0)
+ {
+ status = read (fd, (void *) ptr, nleft);
+
+ if ((status < 0) && ((errno == EAGAIN) || (errno == EINTR)))
+ continue;
+
+ if (status < 0)
+ return (status);
+
+ if (status == 0)
+ {
+ DBG ("Received EOF from fd %i. "
+ "Closing fd and returning error.",
+ fd);
+ close (fd);
+ return (-1);
+ }
+
+ assert (nleft >= status);
+
+ nleft = nleft - status;
+ ptr = ptr + status;
+ }
+
+ return (0);
+}
+
+
+ssize_t swrite (int fd, const void *buf, size_t count)
+{
+ const char *ptr;
+ size_t nleft;
+ ssize_t status;
+
+ ptr = (const char *) buf;
+ nleft = count;
+
+ while (nleft > 0)
+ {
+ status = write (fd, (const void *) ptr, nleft);
+
+ if ((status < 0) && ((errno == EAGAIN) || (errno == EINTR)))
+ continue;
+
+ if (status < 0)
+ return (status);
+
+ nleft = nleft - status;
+ ptr = ptr + status;
+ }
+
+ return (0);
+}
+
int strsplit (char *string, char **fields, size_t size)
{
size_t i;
diff --git a/src/common.h b/src/common.h
index 4dc34b07f0420c5f2e8cf5e68c74efb717a6839e..2be2ff504b84f58276bc3304ef5696c5623ec52d 100644 (file)
--- a/src/common.h
+++ b/src/common.h
char *sstrdup(const char *s);
void *smalloc(size_t size);
+/*
+ * NAME
+ * sread
+ *
+ * DESCRIPTION
+ * Reads exactly `n' bytes or failes. Syntax and other behavior is analogous
+ * to `read(2)'. If EOF is received the file descriptor is closed and an
+ * error is returned.
+ *
+ * PARAMETERS
+ * `fd' File descriptor to write to.
+ * `buf' Buffer that is to be written.
+ * `count' Numver of bytes in the buffer.
+ *
+ * RETURN VALUE
+ * Zero upon success or non-zero if an error occured. `errno' is set in this
+ * case.
+ */
+ssize_t sread (int fd, void *buf, size_t count);
+
+/*
+ * NAME
+ * swrite
+ *
+ * DESCRIPTION
+ * Writes exactly `n' bytes or failes. Syntax and other behavior is analogous
+ * to `write(2)'.
+ *
+ * PARAMETERS
+ * `fd' File descriptor to write to.
+ * `buf' Buffer that is to be written.
+ * `count' Numver of bytes in the buffer.
+ *
+ * RETURN VALUE
+ * Zero upon success or non-zero if an error occured. `errno' is set in this
+ * case.
+ */
+ssize_t swrite (int fd, const void *buf, size_t count);
+
/*
* NAME
* strsplit
diff --git a/src/cpufreq.c b/src/cpufreq.c
index b26c35e161eb09d17c329ce8d22c1c498f76f3c8..ba0149ad1f390298af4049690cc56c9458f4c8b7 100644 (file)
--- a/src/cpufreq.c
+++ b/src/cpufreq.c
if (fgets (buffer, 16, fp) == NULL)
{
syslog (LOG_WARNING, "cpufreq: fgets: %s", strerror (errno));
+ fclose (fp);
return;
}
diff --git a/src/disk.c b/src/disk.c
index ded2080626f1a12dfba17f776909127153ce945d..ca3531eb5a14748327570bdd76d19618a90fa13b 100644 (file)
--- a/src/disk.c
+++ b/src/disk.c
#include "collectd.h"
#include "common.h"
#include "plugin.h"
+#include "utils_debug.h"
#define MODULE_NAME "disk"
-#if defined(KERNEL_LINUX) || defined(HAVE_LIBKSTAT)
+#if HAVE_MACH_MACH_TYPES_H
+# include <mach/mach_types.h>
+#endif
+#if HAVE_MACH_MACH_INIT_H
+# include <mach/mach_init.h>
+#endif
+#if HAVE_MACH_MACH_ERROR_H
+# include <mach/mach_error.h>
+#endif
+#if HAVE_MACH_MACH_PORT_H
+# include <mach/mach_port.h>
+#endif
+#if HAVE_COREFOUNDATION_COREFOUNDATION_H
+# include <CoreFoundation/CoreFoundation.h>
+#endif
+#if HAVE_IOKIT_IOKITLIB_H
+# include <IOKit/IOKitLib.h>
+#endif
+#if HAVE_IOKIT_IOTYPES_H
+# include <IOKit/IOTypes.h>
+#endif
+#if HAVE_IOKIT_STORAGE_IOBLOCKSTORAGEDRIVER_H
+# include <IOKit/storage/IOBlockStorageDriver.h>
+#endif
+#if HAVE_IOKIT_IOBSD_H
+# include <IOKit/IOBSD.h>
+#endif
+
+#if HAVE_IOKIT_IOKITLIB_H || KERNEL_LINUX || HAVE_LIBKSTAT
# define DISK_HAVE_READ 1
#else
# define DISK_HAVE_READ 0
};
static int part_ds_num = 4;
-#ifdef KERNEL_LINUX
+#if HAVE_IOKIT_IOKITLIB_H
+static mach_port_t io_master_port = MACH_PORT_NULL;
+/* #endif HAVE_IOKIT_IOKITLIB_H */
+
+#elif KERNEL_LINUX
typedef struct diskstats
{
char *name;
/* This overflows in roughly 1361 year */
unsigned int poll_count;
- unsigned int read_sectors;
- unsigned int write_sectors;
+ unsigned long long read_sectors;
+ unsigned long long write_sectors;
unsigned long long read_bytes;
unsigned long long write_bytes;
} diskstats_t;
static diskstats_t *disklist;
-/* #endif defined(KERNEL_LINUX) */
+static int min_poll_count;
+/* #endif KERNEL_LINUX */
-#elif defined(HAVE_LIBKSTAT)
+#elif HAVE_LIBKSTAT
#define MAX_NUMDISK 256
extern kstat_ctl_t *kc;
static kstat_t *ksp[MAX_NUMDISK];
static void disk_init (void)
{
-#ifdef HAVE_LIBKSTAT
+#if HAVE_IOKIT_IOKITLIB_H
+ kern_return_t status;
+
+ if (io_master_port != MACH_PORT_NULL)
+ {
+ mach_port_deallocate (mach_task_self (),
+ io_master_port);
+ io_master_port = MACH_PORT_NULL;
+ }
+
+ status = IOMasterPort (MACH_PORT_NULL, &io_master_port);
+ if (status != kIOReturnSuccess)
+ {
+ syslog (LOG_ERR, "IOMasterPort failed: %s",
+ mach_error_string (status));
+ io_master_port = MACH_PORT_NULL;
+ return;
+ }
+/* #endif HAVE_IOKIT_IOKITLIB_H */
+
+#elif KERNEL_LINUX
+ int step;
+ int heartbeat;
+
+ step = atoi (COLLECTD_STEP);
+ heartbeat = atoi (COLLECTD_HEARTBEAT);
+
+ assert (step > 0);
+ assert (heartbeat >= step);
+
+ min_poll_count = 1 + (heartbeat / step);
+ DBG ("min_poll_count = %i;", min_poll_count);
+/* #endif KERNEL_LINUX */
+
+#elif HAVE_LIBKSTAT
kstat_t *ksp_chain;
numdisk = 0;
continue;
ksp[numdisk++] = ksp_chain;
}
-#endif
+#endif /* HAVE_LIBKSTAT */
return;
}
write_time) >= BUFSIZE)
return;
+ DBG ("disk_name = %s; buf = %s;",
+ disk_name, buf);
+
plugin_submit (MODULE_NAME, disk_name, buf);
}
+#if KERNEL_LINUX || HAVE_LIBKSTAT
static void partition_submit (char *part_name,
unsigned long long read_count,
unsigned long long read_bytes,
plugin_submit ("partition", part_name, buf);
}
+#endif /* KERNEL_LINUX || HAVE_LIBKSTAT */
#undef BUFSIZE
+#if HAVE_IOKIT_IOKITLIB_H
+static signed long long dict_get_value (CFDictionaryRef dict, const char *key)
+{
+ signed long long val_int;
+ CFNumberRef val_obj;
+ CFStringRef key_obj;
+
+ /* `key_obj' needs to be released. */
+ key_obj = CFStringCreateWithCString (kCFAllocatorDefault, key,
+ kCFStringEncodingASCII);
+ if (key_obj == NULL)
+ {
+ DBG ("CFStringCreateWithCString (%s) failed.", key);
+ return (-1LL);
+ }
+
+ /* get => we don't need to release (== free) the object */
+ val_obj = (CFNumberRef) CFDictionaryGetValue (dict, key_obj);
+
+ CFRelease (key_obj);
+
+ if (val_obj == NULL)
+ {
+ DBG ("CFDictionaryGetValue (%s) failed.", key);
+ return (-1LL);
+ }
+
+ if (!CFNumberGetValue (val_obj, kCFNumberSInt64Type, &val_int))
+ {
+ DBG ("CFNumberGetValue (%s) failed.", key);
+ return (-1LL);
+ }
+
+ return (val_int);
+}
+#endif /* HAVE_IOKIT_IOKITLIB_H */
+
static void disk_read (void)
{
-#ifdef KERNEL_LINUX
+#if HAVE_IOKIT_IOKITLIB_H
+ io_registry_entry_t disk;
+ io_registry_entry_t disk_child;
+ io_iterator_t disk_list;
+ CFDictionaryRef props_dict;
+ CFDictionaryRef stats_dict;
+ CFDictionaryRef child_dict;
+ kern_return_t status;
+
+ signed long long read_ops;
+ signed long long read_byt;
+ signed long long read_tme;
+ signed long long write_ops;
+ signed long long write_byt;
+ signed long long write_tme;
+
+ int disk_major;
+ int disk_minor;
+ char disk_name[64];
+
+ /* Get the list of all disk objects. */
+ if (IOServiceGetMatchingServices (io_master_port,
+ IOServiceMatching (kIOBlockStorageDriverClass),
+ &disk_list) != kIOReturnSuccess)
+ {
+ syslog (LOG_ERR, "disk-plugin: IOServiceGetMatchingServices failed.");
+ return;
+ }
+
+ while ((disk = IOIteratorNext (disk_list)) != 0)
+ {
+ props_dict = NULL;
+ stats_dict = NULL;
+ child_dict = NULL;
+
+ /* `disk_child' must be released */
+ if ((status = IORegistryEntryGetChildEntry (disk, kIOServicePlane, &disk_child))
+ != kIOReturnSuccess)
+ {
+ /* This fails for example for DVD/CD drives.. */
+ DBG ("IORegistryEntryGetChildEntry (disk) failed: 0x%08x", status);
+ IOObjectRelease (disk);
+ continue;
+ }
+
+ /* We create `props_dict' => we need to release it later */
+ if (IORegistryEntryCreateCFProperties (disk,
+ (CFMutableDictionaryRef *) &props_dict,
+ kCFAllocatorDefault,
+ kNilOptions)
+ != kIOReturnSuccess)
+ {
+ syslog (LOG_ERR, "disk-plugin: IORegistryEntryCreateCFProperties failed.");
+ IOObjectRelease (disk_child);
+ IOObjectRelease (disk);
+ continue;
+ }
+
+ if (props_dict == NULL)
+ {
+ DBG ("IORegistryEntryCreateCFProperties (disk) failed.");
+ IOObjectRelease (disk_child);
+ IOObjectRelease (disk);
+ continue;
+ }
+
+ stats_dict = (CFDictionaryRef) CFDictionaryGetValue (props_dict,
+ CFSTR (kIOBlockStorageDriverStatisticsKey));
+
+ if (stats_dict == NULL)
+ {
+ DBG ("CFDictionaryGetValue (%s) failed.",
+ kIOBlockStorageDriverStatisticsKey);
+ CFRelease (props_dict);
+ IOObjectRelease (disk_child);
+ IOObjectRelease (disk);
+ continue;
+ }
+
+ if (IORegistryEntryCreateCFProperties (disk_child,
+ (CFMutableDictionaryRef *) &child_dict,
+ kCFAllocatorDefault,
+ kNilOptions)
+ != kIOReturnSuccess)
+ {
+ DBG ("IORegistryEntryCreateCFProperties (disk_child) failed.");
+ IOObjectRelease (disk_child);
+ CFRelease (props_dict);
+ IOObjectRelease (disk);
+ continue;
+ }
+
+ disk_major = (int) dict_get_value (child_dict,
+ kIOBSDMajorKey);
+ disk_minor = (int) dict_get_value (child_dict,
+ kIOBSDMinorKey);
+ read_ops = dict_get_value (stats_dict,
+ kIOBlockStorageDriverStatisticsReadsKey);
+ read_byt = dict_get_value (stats_dict,
+ kIOBlockStorageDriverStatisticsBytesReadKey);
+ read_tme = dict_get_value (stats_dict,
+ kIOBlockStorageDriverStatisticsTotalReadTimeKey);
+ write_ops = dict_get_value (stats_dict,
+ kIOBlockStorageDriverStatisticsWritesKey);
+ write_byt = dict_get_value (stats_dict,
+ kIOBlockStorageDriverStatisticsBytesWrittenKey);
+ write_tme = dict_get_value (stats_dict,
+ kIOBlockStorageDriverStatisticsTotalWriteTimeKey);
+
+ if (snprintf (disk_name, 64, "%i-%i", disk_major, disk_minor) >= 64)
+ {
+ DBG ("snprintf (major, minor) failed.");
+ CFRelease (child_dict);
+ IOObjectRelease (disk_child);
+ CFRelease (props_dict);
+ IOObjectRelease (disk);
+ continue;
+ }
+ DBG ("disk_name = %s", disk_name);
+
+ if ((read_ops != -1LL)
+ || (read_byt != -1LL)
+ || (read_tme != -1LL)
+ || (write_ops != -1LL)
+ || (write_byt != -1LL)
+ || (write_tme != -1LL))
+ disk_submit (disk_name,
+ read_ops, 0ULL, read_byt, read_tme,
+ write_ops, 0ULL, write_byt, write_tme);
+
+ CFRelease (child_dict);
+ IOObjectRelease (disk_child);
+ CFRelease (props_dict);
+ IOObjectRelease (disk);
+ }
+ IOObjectRelease (disk_list);
+/* #endif HAVE_IOKIT_IOKITLIB_H */
+
+#elif KERNEL_LINUX
FILE *fh;
char buffer[1024];
char disk_name[128];
int major = 0;
int minor = 0;
- unsigned int read_sectors;
- unsigned int write_sectors;
-
- unsigned long long read_count = 0;
- unsigned long long read_merged = 0;
- unsigned long long read_bytes = 0;
- unsigned long long read_time = 0;
- unsigned long long write_count = 0;
- unsigned long long write_merged = 0;
- unsigned long long write_bytes = 0;
- unsigned long long write_time = 0;
+ unsigned long long read_sectors = 0ULL;
+ unsigned long long write_sectors = 0ULL;
+
+ unsigned long long read_count = 0ULL;
+ unsigned long long read_merged = 0ULL;
+ unsigned long long read_bytes = 0ULL;
+ unsigned long long read_time = 0ULL;
+ unsigned long long write_count = 0ULL;
+ unsigned long long write_merged = 0ULL;
+ unsigned long long write_bytes = 0ULL;
+ unsigned long long write_time = 0ULL;
int is_disk = 0;
diskstats_t *ds, *pre_ds;
{
/* Kernel 2.6, Partition */
read_count = atoll (fields[3]);
- read_sectors = atoi (fields[4]);
+ read_sectors = atoll (fields[4]);
write_count = atoll (fields[5]);
- write_sectors = atoi (fields[6]);
+ write_sectors = atoll (fields[6]);
}
else if (numfields == (14 + fieldshift))
{
read_count = atoll (fields[3 + fieldshift]);
write_count = atoll (fields[7 + fieldshift]);
- read_sectors = atoi (fields[5 + fieldshift]);
- write_sectors = atoi (fields[9 + fieldshift]);
+ read_sectors = atoll (fields[5 + fieldshift]);
+ write_sectors = atoll (fields[9 + fieldshift]);
if ((fieldshift == 0) || (minor == 0))
{
}
else
{
+ DBG ("numfields = %i; => unknown file format.", numfields);
continue;
}
-
- if (read_sectors >= ds->read_sectors)
- ds->read_bytes += 512 * (read_sectors - ds->read_sectors);
+ /* If the counter wraps around, it's only 32 bits.. */
+ if (read_sectors < ds->read_sectors)
+ ds->read_bytes += 512 * ((0xFFFFFFFF - ds->read_sectors) + read_sectors);
else
- ds->read_bytes += 512 * ((UINT_MAX - ds->read_sectors) + read_sectors);
+ ds->read_bytes += 512 * (read_sectors - ds->read_sectors);
- if (write_sectors >= ds->write_sectors)
- ds->write_bytes += 512 * (write_sectors - ds->write_sectors);
+ if (write_sectors < ds->write_sectors)
+ ds->write_bytes += 512 * ((0xFFFFFFFF - ds->write_sectors) + write_sectors);
else
- ds->write_bytes += 512 * ((UINT_MAX - ds->write_sectors) + write_sectors);
+ ds->write_bytes += 512 * (write_sectors - ds->write_sectors);
ds->read_sectors = read_sectors;
ds->write_sectors = write_sectors;
/* Don't write to the RRDs if we've just started.. */
ds->poll_count++;
- if (ds->poll_count <= 6)
+ if (ds->poll_count <= min_poll_count)
+ {
+ DBG ("(ds->poll_count = %i) <= (min_poll_count = %i); => Not writing.",
+ ds->poll_count, min_poll_count);
continue;
+ }
if ((read_count == 0) && (write_count == 0))
+ {
+ DBG ("((read_count == 0) && (write_count == 0)); => Not writing.");
continue;
+ }
if (is_disk)
disk_submit (disk_name, read_count, read_merged, read_bytes, read_time,
fclose (fh);
/* #endif defined(KERNEL_LINUX) */
-#elif defined(HAVE_LIBKSTAT)
+#elif HAVE_LIBKSTAT
static kstat_io_t kio;
int i;
diff --git a/src/hddtemp.c b/src/hddtemp.c
index cbe6e80ab541f6f0b0a003f74d93d7bccfa8a90f..80b3419bee76d3e96efacb242bdba4f946efc5be 100644 (file)
--- a/src/hddtemp.c
+++ b/src/hddtemp.c
fd = -1;
continue;
}
+
+ /* A socket could be opened and connecting succeeded. We're
+ * done. */
+ break;
}
freeaddrinfo (ai_list);
syslog (LOG_ERR, "hddtemp: Error reading from socket: %s",
strerror (errno));
+ close (fd);
return (-1);
}
buffer_fill += status;
first_hddname = entry;
}
}
+ fclose (fh);
}
else
DBG ("Could not open /proc/partitions: %s",
index 1ee239301d7a2804911507136a3cdfff81fe11b0..debd432fd7f7793d7345858094c575aad0997c01 100644 (file)
--- a/src/liboping/liboping.c
+++ b/src/liboping/liboping.c
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
#endif
#if HAVE_SYS_SOCKET_H
# include <netinet/icmp6.h>
#endif
-#include "liboping.h"
+#include "oping.h"
-#if DEBUG
+#if WITH_DEBUG
# define dprintf(...) printf ("%s[%4i]: %-20s: ", __FILE__, __LINE__, __FUNCTION__); printf (__VA_ARGS__)
#else
# define dprintf(...) /**/
#endif
-#define PING_DATA "Florian Forster <octo@verplant.org> http://verplant.org/"
+#define PING_ERRMSG_LEN 256
+
+struct pinghost
+{
+ char *hostname;
+ struct sockaddr_storage *addr;
+ socklen_t addrlen;
+ int addrfamily;
+ int fd;
+ int ident;
+ int sequence;
+ struct timeval *timer;
+ double latency;
+ char *data;
+
+ void *context;
+
+ struct pinghost *next;
+};
+
+struct pingobj
+{
+ double timeout;
+ int ttl;
+ int addrfamily;
+ char *data;
+
+ char errmsg[PING_ERRMSG_LEN];
+
+ pinghost_t *head;
+};
/*
* private (static) functions
*/
+static void ping_set_error (pingobj_t *obj, const char *function,
+ const char *message)
+{
+ snprintf (obj->errmsg, PING_ERRMSG_LEN, "%s: %s", function, message);
+ obj->errmsg[PING_ERRMSG_LEN - 1] = '\0';
+}
+
static int ping_timeval_add (struct timeval *tv1, struct timeval *tv2,
struct timeval *res)
{
return (-1);
}
- dprintf ("Read %i bytes from fd = %i\n", buffer_len, fd);
+ dprintf ("Read %u bytes from fd = %i\n", (unsigned int) buffer_len, fd);
if (sa.ss_family == AF_INET)
{
ptr->latency = -1.0;
if (gettimeofday (&nowtime, NULL) == -1)
+ {
+ ping_set_error (obj, "gettimeofday", strerror (errno));
return (-1);
+ }
/* Set up timeout */
timeout.tv_sec = (time_t) obj->timeout;
break;
if (gettimeofday (&nowtime, NULL) == -1)
+ {
+ ping_set_error (obj, "gettimeofday", strerror (errno));
return (-1);
+ }
if (ping_timeval_sub (&endtime, &nowtime, &timeout) == -1)
break;
status = select (max_readfds + 1, &readfds, NULL, NULL, &timeout);
if (gettimeofday (&nowtime, NULL) == -1)
+ {
+ ping_set_error (obj, "gettimeofday", strerror (errno));
return (-1);
+ }
if ((status == -1) && (errno == EINTR))
{
* +-> ping_send_one_ipv4 *
* `-> ping_send_one_ipv6 *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-ssize_t ping_sendto (pinghost_t *ph, const void *buf, size_t buflen)
+static ssize_t ping_sendto (pingobj_t *obj, pinghost_t *ph,
+ const void *buf, size_t buflen)
{
ssize_t ret;
ret = sendto (ph->fd, buf, buflen, 0,
(struct sockaddr *) ph->addr, ph->addrlen);
+ if (ret < 0)
+ ping_set_error (obj, "sendto", strerror (errno));
+
return (ret);
}
-static int ping_send_one_ipv4 (pinghost_t *ph)
+static int ping_send_one_ipv4 (pingobj_t *obj, pinghost_t *ph)
{
struct icmp *icmp4;
int status;
icmp4->icmp_id = htons (ph->ident);
icmp4->icmp_seq = htons (ph->sequence);
- strcpy (data, PING_DATA);
+ buflen = 4096 - sizeof (struct icmp);
+ strncpy (data, ph->data, buflen);
datalen = strlen (data);
buflen = datalen + sizeof (struct icmp);
dprintf ("Sending ICMPv4 package with ID 0x%04x\n", ph->ident);
- status = ping_sendto (ph, buf, buflen);
+ status = ping_sendto (obj, ph, buf, buflen);
if (status < 0)
{
perror ("ping_sendto");
return (0);
}
-static int ping_send_one_ipv6 (pinghost_t *ph)
+static int ping_send_one_ipv6 (pingobj_t *obj, pinghost_t *ph)
{
struct icmp6_hdr *icmp6;
int status;
icmp6->icmp6_type = ICMP6_ECHO_REQUEST;
icmp6->icmp6_code = 0;
/* The checksum will be calculated by the TCP/IP stack. */
+ /* FIXME */
icmp6->icmp6_cksum = 0;
icmp6->icmp6_id = htons (ph->ident);
icmp6->icmp6_seq = htons (ph->sequence);
- strcpy (data, PING_DATA);
+ buflen = 4096 - sizeof (struct icmp6_hdr);
+ strncpy (data, ph->data, buflen);
datalen = strlen (data);
buflen = datalen + sizeof (struct icmp6_hdr);
dprintf ("Sending ICMPv6 package with ID 0x%04x\n", ph->ident);
- status = ping_sendto (ph, buf, buflen);
+ status = ping_sendto (obj, ph, buf, buflen);
if (status < 0)
{
perror ("ping_sendto");
return (0);
}
-static int ping_send_all (pinghost_t *ph)
+static int ping_send_all (pingobj_t *obj)
{
+ pinghost_t *ph;
pinghost_t *ptr;
+ int ret;
+
+ ret = 0;
+ ph = obj->head;
+
for (ptr = ph; ptr != NULL; ptr = ptr->next)
{
/* start timer.. The GNU `ping6' starts the timer before
{
dprintf ("gettimeofday: %s\n", strerror (errno));
timerclear (ptr->timer);
+ ret--;
continue;
}
else
if (ptr->addrfamily == AF_INET6)
{
dprintf ("Sending ICMPv6 echo request to `%s'\n", ptr->hostname);
- if (ping_send_one_ipv6 (ptr) != 0)
+ if (ping_send_one_ipv6 (obj, ptr) != 0)
{
timerclear (ptr->timer);
+ ret--;
continue;
}
}
else if (ptr->addrfamily == AF_INET)
{
dprintf ("Sending ICMPv4 echo request to `%s'\n", ptr->hostname);
- if (ping_send_one_ipv4 (ptr) != 0)
+ if (ping_send_one_ipv4 (obj, ptr) != 0)
{
timerclear (ptr->timer);
+ ret--;
continue;
}
}
{
dprintf ("Unknown address family: %i\n", ptr->addrfamily);
timerclear (ptr->timer);
+ ret--;
continue;
}
ptr->sequence++;
}
- /* FIXME */
- return (0);
+ return (ret);
}
/*
if (ph->hostname != NULL)
free (ph->hostname);
+ if (ph->data != NULL)
+ free (ph->data);
+
free (ph);
}
/*
* public methods
*/
+const char *ping_get_error (pingobj_t *obj)
+{
+ return (obj->errmsg);
+}
+
pingobj_t *ping_construct (void)
{
pingobj_t *obj;
obj->timeout = PING_DEF_TIMEOUT;
obj->ttl = PING_DEF_TTL;
obj->addrfamily = PING_DEF_AF;
+ obj->data = strdup (PING_DEF_DATA);
return (obj);
}
current = next;
}
+ if (obj->data != NULL)
+ free (obj->data);
+
free (obj);
return;
}
break;
+ case PING_OPT_DATA:
+ if (obj->data != NULL)
+ {
+ free (obj->data);
+ obj->data = NULL;
+ }
+ obj->data = strdup ((const char *) value);
+ break;
+
default:
ret = -2;
} /* switch (option) */
{
int ret;
- if (ping_send_all (obj->head) < 0)
+ if (ping_send_all (obj) < 0)
return (-1);
if ((ret = ping_receive_all (obj)) < 0)
if ((ph->hostname = strdup (host)) == NULL)
{
dprintf ("Out of memory!\n");
+ ping_set_error (obj, "strdup", strerror (errno));
+ ping_free (ph);
+ return (-1);
+ }
+
+ /* obj->data is not garuanteed to be != NULL */
+ if ((ph->data = strdup (obj->data == NULL ? PING_DEF_DATA : obj->data)) == NULL)
+ {
+ dprintf ("Out of memory!\n");
+ ping_set_error (obj, "strdup", strerror (errno));
ping_free (ph);
return (-1);
}
if ((ai_return = getaddrinfo (host, NULL, &ai_hints, &ai_list)) != 0)
{
dprintf ("getaddrinfo failed\n");
+ ping_set_error (obj, "getaddrinfo",
+ (ai_return == EAI_SYSTEM)
+ ? strerror (errno)
+ : gai_strerror (ai_return));
ping_free (ph);
return (-1);
}
+ if (ai_list == NULL)
+ ping_set_error (obj, "getaddrinfo", "No hosts returned");
+
for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
ph->fd = -1;
si->sin_port = htons (ph->ident);
si->sin_addr.s_addr = htonl (INADDR_ANY);
+ ai_ptr->ai_socktype = SOCK_RAW;
ai_ptr->ai_protocol = IPPROTO_ICMP;
}
else if (ai_ptr->ai_family == AF_INET6)
si->sin6_port = htons (ph->ident);
si->sin6_addr = in6addr_any;
+ ai_ptr->ai_socktype = SOCK_RAW;
ai_ptr->ai_protocol = IPPROTO_ICMPV6;
}
else
{
- dprintf ("Unknown `ai_family': %i\n", ai_ptr->ai_family);
+ char errmsg[PING_ERRMSG_LEN];
+
+ snprintf (errmsg, PING_ERRMSG_LEN, "Unknown `ai_family': %i", ai_ptr->ai_family);
+ errmsg[PING_ERRMSG_LEN - 1] = '\0';
+
+ dprintf (errmsg);
+ ping_set_error (obj, "getaddrinfo", errmsg);
continue;
}
+ /* TODO: Move this to a static function `ping_open_socket' and
+ * call it whenever the socket dies. */
ph->fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (ph->fd == -1)
{
dprintf ("socket: %s\n", strerror (errno));
+ ping_set_error (obj, "socket", strerror (errno));
continue;
}
+/*
+ * The majority vote of operating systems has decided that you don't need to
+ * bind here. This code should be reactivated to bind to a specific address,
+ * though. See the `-I' option of `ping(1)' (GNU). -octo
+ */
#if 0
if (bind (ph->fd, (struct sockaddr *) &sockaddr, sockaddr_len) == -1)
{
dprintf ("bind: %s\n", strerror (errno));
+ ping_set_error (obj, "bind", strerror (errno));
close (ph->fd);
ph->fd = -1;
continue;
return (-1);
}
- ph->next = obj->head;
- obj->head = ph;
+ /*
+ * Adding in the front is much easier, but then the iterator will
+ * return the host that was added last as first host. That's just not
+ * nice. -octo
+ */
+ if (obj->head == NULL)
+ {
+ obj->head = ph;
+ }
+ else
+ {
+ pinghost_t *hptr;
+
+ hptr = obj->head;
+ while (hptr->next != NULL)
+ hptr = hptr->next;
+
+ assert ((hptr != NULL) && (hptr->next == NULL));
+ hptr->next = ph;
+ }
ping_set_ttl (ph, obj->ttl);
}
if (cur == NULL)
+ {
+ ping_set_error (obj, "ping_host_remove", "Host not found");
return (-1);
+ }
if (pre == NULL)
obj->head = cur->next;
return ((pingobj_iter_t *) iter->next);
}
-const char *ping_iterator_get_host (pingobj_iter_t *iter)
+int ping_iterator_get_info (pingobj_iter_t *iter, int info,
+ void *buffer, size_t *buffer_len)
+{
+ int ret = EINVAL;
+
+ size_t orig_buffer_len = *buffer_len;
+
+ switch (info)
+ {
+ case PING_INFO_HOSTNAME:
+ ret = ENOMEM;
+ *buffer_len = strlen (iter->hostname);
+ if (orig_buffer_len <= *buffer_len)
+ break;
+ /* Since (orig_buffer_len > *buffer_len) `strncpy'
+ * will copy `*buffer_len' and pad the rest of
+ * `buffer' with null-bytes */
+ strncpy (buffer, iter->hostname, orig_buffer_len);
+ ret = 0;
+ break;
+
+ case PING_INFO_ADDRESS:
+ ret = getnameinfo ((struct sockaddr *) iter->addr,
+ iter->addrlen,
+ (char *) buffer,
+ *buffer_len,
+ NULL, 0,
+ NI_NUMERICHOST);
+ if (ret != 0)
+ {
+ if ((ret == EAI_MEMORY)
+#ifdef EAI_OVERFLOW
+ || (ret == EAI_OVERFLOW)
+#endif
+ )
+ ret = ENOMEM;
+ else if (ret == EAI_SYSTEM)
+ /* XXX: Not thread-safe! */
+ ret = errno;
+ else
+ ret = EINVAL;
+ }
+ break;
+
+ case PING_INFO_FAMILY:
+ ret = ENOMEM;
+ *buffer_len = sizeof (int);
+ if (orig_buffer_len < sizeof (int))
+ break;
+ *((int *) buffer) = iter->addrfamily;
+ ret = 0;
+ break;
+
+ case PING_INFO_LATENCY:
+ ret = ENOMEM;
+ *buffer_len = sizeof (double);
+ if (orig_buffer_len < sizeof (double))
+ break;
+ *((double *) buffer) = iter->latency;
+ ret = 0;
+ break;
+
+ case PING_INFO_SEQUENCE:
+ ret = ENOMEM;
+ *buffer_len = sizeof (unsigned int);
+ if (orig_buffer_len < sizeof (unsigned int))
+ break;
+ *((unsigned int *) buffer) = (unsigned int) iter->sequence;
+ ret = 0;
+ break;
+
+ case PING_INFO_IDENT:
+ ret = ENOMEM;
+ *buffer_len = sizeof (uint16_t);
+ if (orig_buffer_len < sizeof (uint16_t))
+ break;
+ *((uint16_t *) buffer) = (uint16_t) iter->ident;
+ ret = 0;
+ break;
+
+ case PING_INFO_DATA:
+ ret = ENOMEM;
+ *buffer_len = strlen (iter->data);
+ if (orig_buffer_len < *buffer_len)
+ break;
+ strncpy ((char *) buffer, iter->data, orig_buffer_len);
+ ret = 0;
+ break;
+ }
+
+ return (ret);
+}
+
+void *ping_iterator_get_context (pingobj_iter_t *iter)
{
- return (iter->hostname);
+ return (iter->context);
}
-double ping_iterator_get_latency (pingobj_iter_t *iter)
+void ping_iterator_set_context (pingobj_iter_t *iter, void *context)
{
- return (iter->latency);
+ iter->context = context;
}
index 065ae9509854e6b757855bade63b4abdf55a3a6d..9fd7597fa04dc264188734f8fcc969e14dfd6c41 100644 (file)
--- a/src/liboping/liboping.h
+++ b/src/liboping/liboping.h
/*
* Type definitions
*/
-typedef struct pinghost
-{
- char *hostname;
- struct sockaddr_storage *addr;
- socklen_t addrlen;
- int addrfamily;
- int fd;
- int ident;
- int sequence;
- struct timeval *timer;
- double latency;
-
- struct pinghost *next;
-} pinghost_t;
+struct pinghost;
+typedef struct pinghost pinghost_t;
typedef pinghost_t pingobj_iter_t;
-typedef struct pingobj
-{
- double timeout;
- int ttl;
- int addrfamily;
-
- pinghost_t *head;
-} pingobj_t;
+struct pingobj;
+typedef struct pingobj pingobj_t;
#define PING_OPT_TIMEOUT 0x01
#define PING_OPT_TTL 0x02
const char *ping_iterator_get_host (pingobj_iter_t *iter);
double ping_iterator_get_latency (pingobj_iter_t *iter);
+const char *ping_get_error (pingobj_t *obj);
+
#endif /* OCTO_PING_H */
diff --git a/src/load.c b/src/load.c
index 4d43dd45cb7f9a93f391117d2048b70ced049261..019f952c07066e7c753dbd193cc40d58ccab11d6 100644 (file)
--- a/src/load.c
+++ b/src/load.c
if (fgets (buffer, 16, loadavg) == NULL)
{
syslog (LOG_WARNING, "load: fgets: %s", strerror (errno));
+ fclose (loadavg);
return;
}
diff --git a/src/memory.c b/src/memory.c
index d8bbb6ee66049033786852cc168c646086e2efda..b8b7229f6de74db7f6a2161370c58f08934ff28b 100644 (file)
--- a/src/memory.c
+++ b/src/memory.c
#include "collectd.h"
#include "common.h"
#include "plugin.h"
+#include "utils_debug.h"
+
+#ifdef HAVE_SYS_SYSCTL_H
+# include <sys/sysctl.h>
+#endif
#ifdef HAVE_MACH_KERN_RETURN_H
# include <mach/kern_return.h>
#ifdef HAVE_MACH_HOST_PRIV_H
# include <mach/host_priv.h>
#endif
-#ifdef MACH_VM_STATISTICS_H
+#ifdef HAVE_MACH_VM_STATISTICS_H
# include <mach/vm_statistics.h>
#endif
-#if defined (HOST_VM_INFO) || defined(KERNEL_LINUX) || defined(HAVE_LIBKSTAT)
+#if defined (HOST_VM_INFO) || HAVE_SYSCTLBYNAME || KERNEL_LINUX || HAVE_LIBKSTAT
# define MEMORY_HAVE_READ 1
#else
# define MEMORY_HAVE_READ 0
static vm_size_t pagesize;
/* #endif HOST_VM_INFO */
-#elif defined(KERNEL_LINUX)
+#elif HAVE_SYSCTLBYNAME
+/* no global variables */
+/* #endif HAVE_SYSCTLBYNAME */
+
+#elif KERNEL_LINUX
/* no global variables */
/* #endif KERNEL_LINUX */
-#elif defined(HAVE_LIBKSTAT)
+#elif HAVE_LIBKSTAT
static int pagesize;
static kstat_t *ksp;
#endif /* HAVE_LIBKSTAT */
host_page_size (port_host, &pagesize);
/* #endif HOST_VM_INFO */
+#elif HAVE_SYSCTLBYNAME
+/* no init stuff */
+/* #endif HAVE_SYSCTLBYNAME */
+
#elif defined(KERNEL_LINUX)
/* no init stuff */
/* #endif KERNEL_LINUX */
memory_submit (wired + active, -1, inactive, free);
/* #endif HOST_VM_INFO */
+#elif HAVE_SYSCTLBYNAME
+ /*
+ * vm.stats.vm.v_page_size: 4096
+ * vm.stats.vm.v_page_count: 246178
+ * vm.stats.vm.v_free_count: 28760
+ * vm.stats.vm.v_wire_count: 37526
+ * vm.stats.vm.v_active_count: 55239
+ * vm.stats.vm.v_inactive_count: 113730
+ * vm.stats.vm.v_cache_count: 10809
+ */
+ char *sysctl_keys[8] =
+ {
+ "vm.stats.vm.v_page_size",
+ "vm.stats.vm.v_page_count",
+ "vm.stats.vm.v_free_count",
+ "vm.stats.vm.v_wire_count",
+ "vm.stats.vm.v_active_count",
+ "vm.stats.vm.v_inactive_count",
+ "vm.stats.vm.v_cache_count",
+ NULL
+ };
+ int sysctl_vals[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
+
+ size_t len;
+ int i;
+ int status;
+
+ for (i = 0; sysctl_keys[i] != NULL; i++)
+ {
+ len = sizeof (int);
+ if ((status = sysctlbyname (sysctl_keys[i],
+ (void *) &sysctl_vals[i], &len,
+ NULL, 0)) < 0)
+ {
+ syslog (LOG_ERR, "memory plugin: sysctlbyname (%s): %s",
+ sysctl_keys[i], strerror (errno));
+ return;
+ }
+ DBG ("%26s: %6i", sysctl_keys[i], sysctl_vals[i]);
+ } /* for i */
+
+ /* multiply all all page counts with the pagesize */
+ for (i = 1; sysctl_keys[i] != NULL; i++)
+ sysctl_vals[i] = sysctl_vals[i] * sysctl_vals[0];
+
+ memory_submit (sysctl_vals[3] + sysctl_vals[4], /* wired + active */
+ sysctl_vals[6], /* cache */
+ sysctl_vals[5], /* inactive */
+ sysctl_vals[2]); /* free */
+/* #endif HAVE_SYSCTLBYNAME */
+
#elif defined(KERNEL_LINUX)
FILE *fh;
char buffer[1024];
diff --git a/src/ntpd.c b/src/ntpd.c
--- /dev/null
+++ b/src/ntpd.c
@@ -0,0 +1,999 @@
+/**
+ * collectd - src/ntpd.c
+ * Copyright (C) 2006 Florian octo Forster
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; only version 2 of the License is applicable.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Florian octo Forster <octo at verplant.org>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+#include "configfile.h"
+#include "utils_debug.h"
+
+#define MODULE_NAME "ntpd"
+
+#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
+#if HAVE_NETDB_H
+# include <netdb.h>
+#endif
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#endif
+#if HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+#if HAVE_ARPA_INET_H
+# include <arpa/inet.h> /* inet_ntoa */
+#endif
+#if HAVE_NETINET_TCP_H
+# include <netinet/tcp.h>
+#endif
+#if HAVE_SYS_POLL_H
+# include <sys/poll.h>
+#endif
+
+static char *config_keys[] =
+{
+ "Host",
+ "Port",
+ NULL
+};
+static int config_keys_num = 2;
+
+/* drift */
+static char *time_offset_file = "ntpd/time_offset-%s.rrd";
+static char *time_dispersion_file = "ntpd/time_dispersion-%s.rrd";
+static char *time_delay_file = "ntpd/delay-%s.rrd";
+
+/* used for `time_offset', `time_dispersion', and `delay' */
+static char *sec_ds_def[] =
+{
+ "DS:seconds:GAUGE:"COLLECTD_HEARTBEAT":-1000000:1000000",
+ NULL
+};
+static int sec_ds_num = 1;
+
+static char *frequency_offset_file = "ntpd/frequency_offset-%s.rrd";
+static char *frequency_offset_ds_def[] =
+{
+ "DS:ppm:GAUGE:"COLLECTD_HEARTBEAT":-1000000:1000000",
+ NULL
+};
+static int frequency_offset_ds_num = 1;
+
+#if NTPD_HAVE_READ
+# define NTPD_DEFAULT_HOST "localhost"
+# define NTPD_DEFAULT_PORT "123"
+static int sock_descr = -1;
+static char *ntpd_host = NULL;
+static char *ntpd_port = NULL;
+#endif
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * The following definitions were copied from the NTPd distribution *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+#define MAXFILENAME 128
+#define MAXSEQ 127
+#define MODE_PRIVATE 7
+#define NTP_OLDVERSION ((u_char) 1) /* oldest credible version */
+#define IMPL_XNTPD 3
+#define FP_FRAC 65536.0
+
+#define REFCLOCK_ADDR 0x7f7f0000 /* 127.127.0.0 */
+#define REFCLOCK_MASK 0xffff0000 /* 255.255.0.0 */
+
+/* This structure is missing the message authentication code, since collectd
+ * doesn't use it. */
+struct req_pkt
+{
+ uint8_t rm_vn_mode;
+ uint8_t auth_seq;
+ uint8_t implementation; /* implementation number */
+ uint8_t request; /* request number */
+ uint16_t err_nitems; /* error code/number of data items */
+ uint16_t mbz_itemsize; /* item size */
+ char data[MAXFILENAME + 48]; /* data area [32 prev](176 byte max) */
+ /* struct conf_peer must fit */
+};
+#define REQ_LEN_NOMAC (sizeof(struct req_pkt))
+
+/*
+ * A response packet. The length here is variable, this is a
+ * maximally sized one. Note that this implementation doesn't
+ * authenticate responses.
+ */
+#define RESP_HEADER_SIZE (8)
+#define RESP_DATA_SIZE (500)
+
+struct resp_pkt
+{
+ uint8_t rm_vn_mode; /* response, more, version, mode */
+ uint8_t auth_seq; /* key, sequence number */
+ uint8_t implementation; /* implementation number */
+ uint8_t request; /* request number */
+ uint16_t err_nitems; /* error code/number of data items */
+ uint16_t mbz_itemsize; /* item size */
+ char data[RESP_DATA_SIZE]; /* data area */
+};
+
+/*
+ * Bit setting macros for multifield items.
+ */
+#define RESP_BIT 0x80
+#define MORE_BIT 0x40
+
+#define ISRESPONSE(rm_vn_mode) (((rm_vn_mode)&RESP_BIT)!=0)
+#define ISMORE(rm_vn_mode) (((rm_vn_mode)&MORE_BIT)!=0)
+#define INFO_VERSION(rm_vn_mode) ((u_char)(((rm_vn_mode)>>3)&0x7))
+#define INFO_MODE(rm_vn_mode) ((rm_vn_mode)&0x7)
+
+#define RM_VN_MODE(resp, more, version) \
+ ((u_char)(((resp)?RESP_BIT:0)\
+ |((more)?MORE_BIT:0)\
+ |((version?version:(NTP_OLDVERSION+1))<<3)\
+ |(MODE_PRIVATE)))
+
+#define INFO_IS_AUTH(auth_seq) (((auth_seq) & 0x80) != 0)
+#define INFO_SEQ(auth_seq) ((auth_seq)&0x7f)
+#define AUTH_SEQ(auth, seq) ((u_char)((((auth)!=0)?0x80:0)|((seq)&0x7f)))
+
+#define INFO_ERR(err_nitems) ((u_short)((ntohs(err_nitems)>>12)&0xf))
+#define INFO_NITEMS(err_nitems) ((u_short)(ntohs(err_nitems)&0xfff))
+#define ERR_NITEMS(err, nitems) (htons((u_short)((((u_short)(err)<<12)&0xf000)\
+ |((u_short)(nitems)&0xfff))))
+
+#define INFO_MBZ(mbz_itemsize) ((ntohs(mbz_itemsize)>>12)&0xf)
+#define INFO_ITEMSIZE(mbz_itemsize) ((u_short)(ntohs(mbz_itemsize)&0xfff))
+#define MBZ_ITEMSIZE(itemsize) (htons((u_short)(itemsize)))
+
+/* negate a long float type */
+#define M_NEG(v_i, v_f) \
+ do { \
+ if ((v_f) == 0) \
+ (v_i) = -((uint32_t)(v_i)); \
+ else { \
+ (v_f) = -((uint32_t)(v_f)); \
+ (v_i) = ~(v_i); \
+ } \
+ } while(0)
+/* l_fp to double */
+#define M_LFPTOD(r_i, r_uf, d) \
+ do { \
+ register int32_t i; \
+ register uint32_t f; \
+ \
+ i = (r_i); \
+ f = (r_uf); \
+ if (i < 0) { \
+ M_NEG(i, f); \
+ (d) = -((double) i + ((double) f) / 4294967296.0); \
+ } else { \
+ (d) = (double) i + ((double) f) / 4294967296.0; \
+ } \
+ } while (0)
+
+#define REQ_PEER_LIST_SUM 1
+struct info_peer_summary
+{
+ uint32_t dstadr; /* local address (zero for undetermined) */
+ uint32_t srcadr; /* source address */
+ uint16_t srcport; /* source port */
+ uint8_t stratum; /* stratum of peer */
+ int8_t hpoll; /* host polling interval */
+ int8_t ppoll; /* peer polling interval */
+ uint8_t reach; /* reachability register */
+ uint8_t flags; /* flags, from above */
+ uint8_t hmode; /* peer mode */
+ int32_t delay; /* peer.estdelay; s_fp */
+ int32_t offset_int; /* peer.estoffset; integral part */
+ int32_t offset_frc; /* peer.estoffset; fractional part */
+ uint32_t dispersion; /* peer.estdisp; u_fp */
+ uint32_t v6_flag; /* is this v6 or not */
+ uint32_t unused1; /* (unused) padding for dstadr6 */
+ struct in6_addr dstadr6; /* local address (v6) */
+ struct in6_addr srcadr6; /* source address (v6) */
+};
+
+#define REQ_SYS_INFO 4
+struct info_sys
+{
+ uint32_t peer; /* system peer address (v4) */
+ uint8_t peer_mode; /* mode we are syncing to peer in */
+ uint8_t leap; /* system leap bits */
+ uint8_t stratum; /* our stratum */
+ int8_t precision; /* local clock precision */
+ int32_t rootdelay; /* distance from sync source */
+ uint32_t rootdispersion; /* dispersion from sync source */
+ uint32_t refid; /* reference ID of sync source */
+ uint64_t reftime; /* system reference time */
+ uint32_t poll; /* system poll interval */
+ uint8_t flags; /* system flags */
+ uint8_t unused1; /* unused */
+ uint8_t unused2; /* unused */
+ uint8_t unused3; /* unused */
+ int32_t bdelay; /* default broadcast offset */
+ int32_t frequency; /* frequency residual (scaled ppm) */
+ uint64_t authdelay; /* default authentication delay */
+ uint32_t stability; /* clock stability (scaled ppm) */
+ int32_t v6_flag; /* is this v6 or not */
+ int32_t unused4; /* unused, padding for peer6 */
+ struct in6_addr peer6; /* system peer address (v6) */
+};
+
+#define REQ_GET_KERNEL 38
+struct info_kernel
+{
+ int32_t offset;
+ int32_t freq;
+ int32_t maxerror;
+ int32_t esterror;
+ uint16_t status;
+ uint16_t shift;
+ int32_t constant;
+ int32_t precision;
+ int32_t tolerance;
+ /* pps stuff */
+ int32_t ppsfreq;
+ int32_t jitter;
+ int32_t stabil;
+ int32_t jitcnt;
+ int32_t calcnt;
+ int32_t errcnt;
+ int32_t stbcnt;
+};
+
+/* List of reference clock names */
+static char *refclock_names[] =
+{
+ "UNKNOWN", "LOCAL", "GPS_TRAK", "WWV_PST", /* 0- 3 */
+ "SPECTRACOM", "TRUETIME", "IRIG_AUDIO", "CHU_AUDIO", /* 4- 7 */
+ "GENERIC", "GPS_MX4200", "GPS_AS2201", "GPS_ARBITER", /* 8-11 */
+ "IRIG_TPRO", "ATOM_LEITCH", "MSF_EES", "GPSTM_TRUE", /* 12-15 */
+ "GPS_BANC", "GPS_DATUM", "ACTS_NIST", "WWV_HEATH", /* 16-19 */
+ "GPS_NMEA", "GPS_VME", "PPS", "ACTS_PTB", /* 20-23 */
+ "ACTS_USNO", "TRUETIME", "GPS_HP", "MSF_ARCRON", /* 24-27 */
+ "SHM", "GPS_PALISADE", "GPS_ONCORE", "GPS_JUPITER", /* 28-31 */
+ "CHRONOLOG", "DUMBCLOCK", "ULINK_M320", "PCF", /* 32-35 */
+ "WWV_AUDIO", "GPS_FG", "HOPF_S", "HOPF_P", /* 36-39 */
+ "JJY", "TT_IRIG", "GPS_ZYFER", "GPS_RIPENCC", /* 40-43 */
+ "NEOCLK4X", NULL /* 44 */
+};
+static int refclock_names_num = 45;
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * End of the copied stuff.. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+static int ntpd_config (char *key, char *value)
+{
+ if (strcasecmp (key, "host") == 0)
+ {
+ if (ntpd_host != NULL)
+ free (ntpd_host);
+ if ((ntpd_host = strdup (value)) == NULL)
+ return (1);
+ }
+ else if (strcasecmp (key, "port") == 0)
+ {
+ if (ntpd_port != NULL)
+ free (ntpd_port);
+ if ((ntpd_port = strdup (value)) == NULL)
+ return (1);
+ }
+ else
+ {
+ return (-1);
+ }
+
+ return (0);
+}
+
+static void ntpd_init (void)
+{
+ return;
+}
+
+static void ntpd_write_sec (char *host, char *inst, char *val, char *file)
+{
+ char buf[256];
+ int status;
+
+ status = snprintf (buf, 256, file, inst);
+ if ((status < 1) || (status >= 256))
+ return;
+
+ rrd_update_file (host, buf, val,
+ sec_ds_def, sec_ds_num);
+}
+
+static void ntpd_write_time_offset (char *host, char *inst, char *val)
+{
+ ntpd_write_sec (host, inst, val, time_offset_file);
+}
+
+static void ntpd_write_time_dispersion (char *host, char *inst, char *val)
+{
+ ntpd_write_sec (host, inst, val, time_dispersion_file);
+}
+
+static void ntpd_write_delay (char *host, char *inst, char *val)
+{
+ ntpd_write_sec (host, inst, val, time_delay_file);
+}
+
+static void ntpd_write_frequency_offset (char *host, char *inst, char *val)
+{
+ char buf[256];
+ int status;
+
+ status = snprintf (buf, 256, frequency_offset_file, inst);
+ if ((status < 1) || (status >= 256))
+ return;
+
+ rrd_update_file (host, buf, val,
+ frequency_offset_ds_def, frequency_offset_ds_num);
+}
+
+#if NTPD_HAVE_READ
+static void ntpd_submit (char *type, char *inst, double value)
+{
+ char buf[256];
+
+ if (snprintf (buf, 256, "%u:%.8f", (unsigned int) curtime, value) >= 256)
+ return;
+
+ DBG ("type = %s; inst = %s; value = %s;",
+ type, inst, buf);
+
+ plugin_submit (type, inst, buf);
+}
+
+/* returns `tv0 - tv1' in milliseconds or 0 if `tv1 > tv0' */
+static int timeval_sub (const struct timeval *tv0, const struct timeval *tv1)
+{
+ int sec;
+ int usec;
+
+ if ((tv0->tv_sec < tv1->tv_sec)
+ || ((tv0->tv_sec == tv1->tv_sec) && (tv0->tv_usec < tv1->tv_usec)))
+ return (0);
+
+ sec = tv0->tv_sec - tv1->tv_sec;
+ usec = tv0->tv_usec - tv1->tv_usec;
+
+ while (usec < 0)
+ {
+ usec += 1000000;
+ sec -= 1;
+ }
+
+ if (sec < 0)
+ return (0);
+
+ return ((sec * 1000) + ((usec + 500) / 1000));
+}
+
+static int ntpd_connect (void)
+{
+ char *host;
+ char *port;
+
+ struct addrinfo ai_hints;
+ struct addrinfo *ai_list;
+ struct addrinfo *ai_ptr;
+ int status;
+
+ if (sock_descr >= 0)
+ return (sock_descr);
+
+ DBG ("Opening a new socket");
+
+ host = ntpd_host;
+ if (host == NULL)
+ host = NTPD_DEFAULT_HOST;
+
+ port = ntpd_port;
+ if (port == NULL)
+ port = NTPD_DEFAULT_PORT;
+
+ memset (&ai_hints, '\0', sizeof (ai_hints));
+ ai_hints.ai_flags = AI_ADDRCONFIG;
+ ai_hints.ai_family = PF_UNSPEC;
+ ai_hints.ai_socktype = SOCK_DGRAM;
+ ai_hints.ai_protocol = IPPROTO_UDP;
+
+ if ((status = getaddrinfo (host, port, &ai_hints, &ai_list)) != 0)
+ {
+ DBG ("getaddrinfo (%s, %s): %s",
+ host, port,
+ status == EAI_SYSTEM ? strerror (errno) : gai_strerror (status));
+ syslog (LOG_ERR, "ntpd plugin: getaddrinfo (%s, %s): %s",
+ host, port,
+ status == EAI_SYSTEM ? strerror (errno) : gai_strerror (status));
+ return (-1);
+ }
+
+ for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ {
+ /* create our socket descriptor */
+ if ((sock_descr = socket (ai_ptr->ai_family,
+ ai_ptr->ai_socktype,
+ ai_ptr->ai_protocol)) < 0)
+ continue;
+
+ /* connect to the ntpd */
+ if (connect (sock_descr, ai_ptr->ai_addr, ai_ptr->ai_addrlen))
+ {
+ close (sock_descr);
+ sock_descr = -1;
+ continue;
+ }
+
+ break;
+ }
+
+ freeaddrinfo (ai_list);
+
+ if (sock_descr < 0)
+ {
+ DBG ("Unable to connect to server.");
+ syslog (LOG_ERR, "ntpd plugin: Unable to connect to server.");
+ }
+
+ return (sock_descr);
+}
+
+/* For a description of the arguments see `ntpd_do_query' below. */
+static int ntpd_receive_response (int req_code, int *res_items, int *res_size,
+ char **res_data, int res_item_size)
+{
+ int sd;
+ struct pollfd poll_s;
+ struct resp_pkt res;
+ int status;
+ int done;
+ int i;
+
+ char *items;
+ size_t items_num;
+
+ struct timeval time_end;
+ struct timeval time_now;
+ int timeout;
+
+ int pkt_item_num; /* items in this packet */
+ int pkt_item_len; /* size of the items in this packet */
+ int pkt_sequence;
+ char pkt_recvd[MAXSEQ+1]; /* sequence numbers that have been received */
+ int pkt_recvd_num; /* number of packets that have been received */
+ int pkt_lastseq; /* the last sequence number */
+ ssize_t pkt_padding; /* Padding in this packet */
+
+ if ((sd = ntpd_connect ()) < 0)
+ return (-1);
+
+ items = NULL;
+ items_num = 0;
+
+ memset (pkt_recvd, '\0', sizeof (pkt_recvd));
+ pkt_recvd_num = 0;
+ pkt_lastseq = -1;
+
+ *res_items = 0;
+ *res_size = 0;
+ *res_data = NULL;
+
+ if (gettimeofday (&time_end, NULL) < 0)
+ {
+ syslog (LOG_ERR, "ntpd plugin: gettimeofday failed: %s",
+ strerror (errno));
+ return (-1);
+ }
+ time_end.tv_sec++; /* wait for a most one second */
+
+ done = 0;
+ while (done == 0)
+ {
+ if (gettimeofday (&time_now, NULL) < 0)
+ {
+ syslog (LOG_ERR, "ntpd plugin: gettimeofday failed: %s",
+ strerror (errno));
+ return (-1);
+ }
+
+ /* timeout reached */
+ if ((timeout = timeval_sub (&time_end, &time_now)) == 0)
+ break;
+
+ poll_s.fd = sd;
+ poll_s.events = POLLIN | POLLPRI;
+ poll_s.revents = 0;
+
+ DBG ("Polling for %ims", timeout);
+ status = poll (&poll_s, 1, timeout);
+
+ if ((status < 0) && ((errno == EAGAIN) || (errno == EINTR)))
+ continue;
+
+ if (status < 0)
+ {
+ DBG ("poll failed: %s", strerror (errno));
+ syslog (LOG_ERR, "ntpd plugin: poll failed: %s",
+ strerror (errno));
+ return (-1);
+ }
+
+ if (status == 0) /* timeout */
+ {
+ DBG ("timeout reached.");
+ break;
+ }
+
+ memset ((void *) &res, '\0', sizeof (res));
+ status = recv (sd, (void *) &res, sizeof (res), 0 /* no flags */);
+
+ if ((status < 0) && ((errno == EAGAIN) || (errno == EINTR)))
+ continue;
+
+ if (status < 0)
+ {
+ DBG ("recv(2) failed: %s", strerror (errno));
+ DBG ("Closing socket #%i", sd);
+ close (sd);
+ sock_descr = sd = -1;
+ return (-1);
+ }
+
+ DBG ("recv'd %i bytes", status);
+
+ /*
+ * Do some sanity checks first
+ */
+ if (status < RESP_HEADER_SIZE)
+ {
+ syslog (LOG_WARNING, "ntpd plugin: Short (%i bytes) packet received",
+ (int) status);
+ continue;
+ }
+ if (INFO_MODE (res.rm_vn_mode) != MODE_PRIVATE)
+ {
+ syslog (LOG_NOTICE, "ntpd plugin: Packet received with mode %i",
+ INFO_MODE (res.rm_vn_mode));
+ continue;
+ }
+ if (INFO_IS_AUTH (res.auth_seq))
+ {
+ syslog (LOG_NOTICE, "ntpd plugin: Encrypted packet received");
+ continue;
+ }
+ if (!ISRESPONSE (res.rm_vn_mode))
+ {
+ syslog (LOG_NOTICE, "ntpd plugin: Received request packet, "
+ "wanted response");
+ continue;
+ }
+ if (INFO_MBZ (res.mbz_itemsize))
+ {
+ syslog (LOG_WARNING, "ntpd plugin: Received packet with nonzero "
+ "MBZ field!");
+ continue;
+ }
+ if (res.implementation != IMPL_XNTPD)
+ {
+ syslog (LOG_WARNING, "ntpd plugin: Asked for request of type %i, "
+ "got %i", (int) IMPL_XNTPD, (int) res.implementation);
+ continue;
+ }
+
+ /* Check for error code */
+ if (INFO_ERR (res.err_nitems) != 0)
+ {
+ syslog (LOG_ERR, "ntpd plugin: Received error code %i",
+ (int) INFO_ERR(res.err_nitems));
+ return ((int) INFO_ERR (res.err_nitems));
+ }
+
+ /* extract number of items in this packet and the size of these items */
+ pkt_item_num = INFO_NITEMS (res.err_nitems);
+ pkt_item_len = INFO_ITEMSIZE (res.mbz_itemsize);
+ DBG ("pkt_item_num = %i; pkt_item_len = %i;",
+ pkt_item_num, pkt_item_len);
+
+ /* Check if the reported items fit in the packet */
+ if ((pkt_item_num * pkt_item_len) > (status - RESP_HEADER_SIZE))
+ {
+ syslog (LOG_ERR, "ntpd plugin: %i items * %i bytes > "
+ "%i bytes - %i bytes header",
+ (int) pkt_item_num, (int) pkt_item_len,
+ (int) status, (int) RESP_HEADER_SIZE);
+ continue;
+ }
+
+ /* If this is the first packet (time wise, not sequence wise),
+ * set `res_size'. If it's not the first packet check if the
+ * items have the same size. Discard invalid packets. */
+ if (items_num == 0) /* first packet */
+ {
+ DBG ("*res_size = %i", pkt_item_len);
+ *res_size = pkt_item_len;
+ }
+ else if (*res_size != pkt_item_len)
+ {
+ DBG ("Error: *res_size = %i; pkt_item_len = %i;",
+ *res_size, pkt_item_len);
+ syslog (LOG_ERR, "Item sizes differ.");
+ continue;
+ }
+
+ /* Calculate the padding. No idea why there might be any padding.. */
+ pkt_padding = 0;
+ if (res_item_size > pkt_item_len)
+ pkt_padding = res_item_size - pkt_item_len;
+ DBG ("res_item_size = %i; pkt_padding = %i;",
+ res_item_size, pkt_padding);
+
+ /* Extract the sequence number */
+ pkt_sequence = INFO_SEQ (res.auth_seq);
+ if ((pkt_sequence < 0) || (pkt_sequence > MAXSEQ))
+ {
+ syslog (LOG_ERR, "ntpd plugin: Received packet with sequence %i",
+ pkt_sequence);
+ continue;
+ }
+
+ /* Check if this sequence has been received before. If so, discard it. */
+ if (pkt_recvd[pkt_sequence] != '\0')
+ {
+ syslog (LOG_NOTICE, "ntpd plugin: Sequence %i received twice",
+ pkt_sequence);
+ continue;
+ }
+
+ /* If `pkt_lastseq != -1' another packet without `more bit' has
+ * been received. */
+ if (!ISMORE (res.rm_vn_mode))
+ {
+ if (pkt_lastseq != -1)
+ {
+ syslog (LOG_ERR, "ntpd plugin: Two packets which both "
+ "claim to be the last one in the "
+ "sequence have been received.");
+ continue;
+ }
+ pkt_lastseq = pkt_sequence;
+ DBG ("Last sequence = %i;", pkt_lastseq);
+ }
+
+ /*
+ * Enough with the checks. Copy the data now.
+ * We start by allocating some more memory.
+ */
+ DBG ("realloc (%p, %i)", (void *) *res_data,
+ (items_num + pkt_item_num) * res_item_size);
+ items = realloc ((void *) *res_data,
+ (items_num + pkt_item_num) * res_item_size);
+ if (items == NULL)
+ {
+ items = *res_data;
+ syslog (LOG_ERR, "ntpd plugin: realloc failed.");
+ continue;
+ }
+ *res_data = items;
+
+ for (i = 0; i < pkt_item_num; i++)
+ {
+ void *dst = (void *) (*res_data + ((*res_items) * res_item_size));
+ void *src = (void *) (((char *) res.data) + (i * pkt_item_len));
+
+ /* Set the padding to zeros */
+ if (pkt_padding != 0)
+ memset (dst, '\0', res_item_size);
+ memcpy (dst, src, (size_t) pkt_item_len);
+
+ (*res_items)++;
+ }
+
+ pkt_recvd[pkt_sequence] = (char) 1;
+ pkt_recvd_num++;
+
+ if ((pkt_recvd_num - 1) == pkt_lastseq)
+ done = 1;
+ } /* while (done == 0) */
+
+ return (0);
+}
+
+/* For a description of the arguments see `ntpd_do_query' below. */
+static int ntpd_send_request (int req_code, int req_items, int req_size, char *req_data)
+{
+ int sd;
+ struct req_pkt req;
+ size_t req_data_len;
+ int status;
+
+ assert (req_items >= 0);
+ assert (req_size >= 0);
+
+ if ((sd = ntpd_connect ()) < 0)
+ return (-1);
+
+ memset ((void *) &req, '\0', sizeof (req));
+ req.rm_vn_mode = RM_VN_MODE(0, 0, 0);
+ req.auth_seq = AUTH_SEQ (0, 0);
+ req.implementation = IMPL_XNTPD;
+ req.request = (unsigned char) req_code;
+
+ req_data_len = (size_t) (req_items * req_size);
+
+ assert (((req_data != NULL) && (req_data_len > 0))
+ || ((req_data == NULL) && (req_items == 0) && (req_size == 0)));
+
+ req.err_nitems = ERR_NITEMS (0, req_items);
+ req.mbz_itemsize = MBZ_ITEMSIZE (req_size);
+
+ if (req_data != NULL)
+ memcpy ((void *) req.data, (const void *) req_data, req_data_len);
+
+ DBG ("req_items = %i; req_size = %i; req_data = %p;",
+ req_items, req_size, (void *) req_data);
+
+ status = swrite (sd, (const char *) &req, REQ_LEN_NOMAC);
+ if (status < 0)
+ {
+ DBG ("`swrite' failed. Closing socket #%i", sd);
+ close (sd);
+ sock_descr = sd = -1;
+ return (status);
+ }
+
+ return (0);
+}
+
+/*
+ * ntpd_do_query:
+ *
+ * req_code: Type of request packet
+ * req_items: Numver of items in the request
+ * req_size: Size of one item in the request
+ * req_data: Data of the request packet
+ * res_items: Pointer to where the number returned items will be stored.
+ * res_size: Pointer to where the size of one returned item will be stored.
+ * res_data: This is where a pointer to the (allocated) data will be stored.
+ * res_item_size: Size of one returned item. (used to calculate padding)
+ *
+ * returns: zero upon success, non-zero otherwise.
+ */
+static int ntpd_do_query (int req_code, int req_items, int req_size, char *req_data,
+ int *res_items, int *res_size, char **res_data, int res_item_size)
+{
+ int status;
+
+ status = ntpd_send_request (req_code, req_items, req_size, req_data);
+ if (status != 0)
+ return (status);
+
+ status = ntpd_receive_response (req_code, res_items, res_size, res_data,
+ res_item_size);
+ return (status);
+}
+
+static double ntpd_read_fp (int32_t val_int)
+{
+ double val_double;
+
+ val_int = ntohl (val_int);
+ val_double = ((double) val_int) / FP_FRAC;
+
+ return (val_double);
+}
+
+static void ntpd_read (void)
+{
+ struct info_kernel *ik;
+ int ik_num;
+ int ik_size;
+
+ struct info_peer_summary *ps;
+ int ps_num;
+ int ps_size;
+
+ int status;
+ int i;
+
+ ik = NULL;
+ ik_num = 0;
+ ik_size = 0;
+
+ status = ntpd_do_query (REQ_GET_KERNEL,
+ 0, 0, NULL, /* request data */
+ &ik_num, &ik_size, (char **) ((void *) &ik), /* response data */
+ sizeof (struct info_kernel));
+
+ if (status != 0)
+ {
+ DBG ("ntpd_do_query failed with status %i", status);
+ return;
+ }
+ if ((ik == NULL) || (ik_num == 0) || (ik_size == 0))
+ {
+ DBG ("ntpd_do_query returned: ik = %p; ik_num = %i; ik_size = %i;",
+ (void *) ik, ik_num, ik_size);
+ return;
+ }
+
+ /* kerninfo -> estimated error */
+
+ DBG ("info_kernel:\n"
+ " pll offset = %.8f\n"
+ " pll frequency = %.8f\n" /* drift compensation */
+ " est error = %.8f\n",
+ ntpd_read_fp (ik->offset),
+ ntpd_read_fp (ik->freq),
+ ntpd_read_fp (ik->esterror));
+
+ ntpd_submit ("ntpd_frequency_offset", "loop", ntpd_read_fp (ik->freq));
+ ntpd_submit ("ntpd_time_offset", "loop", ntpd_read_fp (ik->offset));
+ ntpd_submit ("ntpd_time_offset", "error", ntpd_read_fp (ik->esterror));
+
+ free (ik);
+ ik = NULL;
+
+ status = ntpd_do_query (REQ_PEER_LIST_SUM,
+ 0, 0, NULL, /* request data */
+ &ps_num, &ps_size, (char **) ((void *) &ps), /* response data */
+ sizeof (struct info_peer_summary));
+ if (status != 0)
+ {
+ DBG ("ntpd_do_query failed with status %i", status);
+ return;
+ }
+ if ((ps == NULL) || (ps_num == 0) || (ps_size == 0))
+ {
+ DBG ("ntpd_do_query returned: ps = %p; ps_num = %i; ps_size = %i;",
+ (void *) ps, ps_num, ps_size);
+ return;
+ }
+
+ for (i = 0; i < ps_num; i++)
+ {
+ struct info_peer_summary *ptr;
+ double offset;
+
+ char peername[512];
+ int refclock_id;
+
+ ptr = ps + i;
+ refclock_id = 0;
+
+ /*
+ if (((ntohl (ptr->dstadr) & 0xFFFFFF00) == 0x7F000000) || (ptr->dstadr == 0))
+ continue;
+ */
+
+ /* Convert the `long floating point' offset value to double */
+ M_LFPTOD (ntohl (ptr->offset_int), ntohl (ptr->offset_frc), offset);
+
+ if (ptr->v6_flag)
+ {
+ status = getnameinfo ((const struct sockaddr *) &ptr->srcadr6,
+ sizeof (ptr->srcadr6),
+ peername, sizeof (peername),
+ NULL, 0, 0 /* no flags */);
+ if (status != 0)
+ {
+ syslog (LOG_ERR, "ntpd plugin: getnameinfo failed: %s",
+ status == EAI_SYSTEM
+ ? strerror (errno)
+ : gai_strerror (status));
+ continue;
+ }
+ }
+ else if ((ntohl (ptr->srcadr) & REFCLOCK_MASK) == REFCLOCK_ADDR)
+ {
+ struct in_addr addr_obj;
+ char *addr_str;
+
+ refclock_id = (ntohl (ptr->srcadr) >> 8) & 0x000000FF;
+
+ if (refclock_id < refclock_names_num)
+ {
+ strncpy (peername, refclock_names[refclock_id],
+ sizeof (peername));
+ }
+ else
+ {
+ memset ((void *) &addr_obj, '\0', sizeof (addr_obj));
+ addr_obj.s_addr = ptr->srcadr;
+ addr_str = inet_ntoa (addr_obj);
+
+ strncpy (peername, addr_str, sizeof (peername));
+ }
+ }
+ else /* IPv4 */
+ {
+ struct in_addr addr_obj;
+ struct hostent *addr_he;
+ char *addr_str;
+
+ memset ((void *) &addr_obj, '\0', sizeof (addr_obj));
+ addr_obj.s_addr = ptr->srcadr;
+ addr_str = inet_ntoa (addr_obj);
+
+ addr_he = gethostbyaddr ((const void *) &addr_obj,
+ sizeof (addr_obj), AF_INET);
+ if (addr_he != NULL)
+ {
+ strncpy (peername, addr_he->h_name, sizeof (peername));
+ }
+ else
+ {
+ strncpy (peername, addr_str, sizeof (peername));
+ }
+ }
+
+ DBG ("peer %i:\n"
+ " peername = %s\n"
+ " srcadr = 0x%08x\n"
+ " delay = %f\n"
+ " offset_int = %i\n"
+ " offset_frc = %i\n"
+ " offset = %f\n"
+ " dispersion = %f\n",
+ i,
+ peername,
+ ntohl (ptr->srcadr),
+ ntpd_read_fp (ptr->delay),
+ ntohl (ptr->offset_int),
+ ntohl (ptr->offset_frc),
+ offset,
+ ntpd_read_fp (ptr->dispersion));
+
+ if (refclock_id != 1) /* not the system clock (offset will always be zero.. */
+ ntpd_submit ("ntpd_time_offset", peername, offset);
+ ntpd_submit ("ntpd_time_dispersion", peername, ntpd_read_fp (ptr->dispersion));
+ if (refclock_id == 0) /* not a reference clock */
+ ntpd_submit ("ntpd_delay", peername, ntpd_read_fp (ptr->delay));
+ }
+
+ free (ps);
+ ps = NULL;
+
+ return;
+}
+#else
+# define ntpd_read NULL
+#endif /* NTPD_HAVE_READ */
+
+void module_register (void)
+{
+ plugin_register (MODULE_NAME, ntpd_init, ntpd_read, NULL);
+ plugin_register ("ntpd_time_offset", NULL, NULL, ntpd_write_time_offset);
+ plugin_register ("ntpd_time_dispersion", NULL, NULL, ntpd_write_time_dispersion);
+ plugin_register ("ntpd_delay", NULL, NULL, ntpd_write_delay);
+ plugin_register ("ntpd_frequency_offset", NULL, NULL, ntpd_write_frequency_offset);
+ cf_register (MODULE_NAME, ntpd_config, config_keys, config_keys_num);
+}
+
+#undef MODULE_NAME
diff --git a/src/ping.c b/src/ping.c
index d82ce06e3fea93bf8c0ea0e20527577b3ca3aa1a..91e0dbcc01072fd7601695349f08684adcd53523 100644 (file)
--- a/src/ping.c
+++ b/src/ping.c
{
if ((pingobj = ping_construct ()) == NULL)
{
- syslog (LOG_ERR, "ping: `ping_construct' failed.\n");
+ syslog (LOG_ERR, "ping: `ping_construct' failed: %s",
+ ping_get_error (pingobj));
return (1);
}
}
{
if (ping_host_add (pingobj, value) < 0)
{
- syslog (LOG_WARNING, "ping: `ping_host_add' failed.");
+ syslog (LOG_WARNING, "ping: `ping_host_add' failed: %s",
+ ping_get_error (pingobj));
return (1);
}
}
if (ping_send (pingobj) < 0)
{
- syslog (LOG_ERR, "ping: `ping_send' failed.");
+ syslog (LOG_ERR, "ping: `ping_send' failed: %s",
+ ping_get_error (pingobj));
return;
}
diff --git a/src/processes.c b/src/processes.c
index fae1c2d02536cb4fc9387d0fb3c40832968ae3bb..dba29eff628c5d058e02b5f14e9d658fbda96b73 100644 (file)
--- a/src/processes.c
+++ b/src/processes.c
blocked) >= BUFSIZE)
return;
+ DBG ("running = %i; sleeping = %i; zombies = %i; stopped = %i; paging = %i; blocked = %i;",
+ running, sleeping, zombies, stopped, paging, blocked);
+
plugin_submit (MODULE_NAME, "-", buf);
}
if ((fh = fopen (filename, "r")) == NULL)
{
- syslog (LOG_ERR, "Cannot open `%s': %s", filename, strerror (errno));
+ syslog (LOG_NOTICE, "Cannot open `%s': %s", filename,
+ strerror (errno));
continue;
}
if (fgets (buf, BUFSIZE, fh) == NULL)
{
+ syslog (LOG_NOTICE, "Unable to read from `%s': %s",
+ filename, strerror (errno));
fclose (fh);
continue;
}
fclose (fh);
if (strsplit (buf, fields, BUFSIZE) < 3)
+ {
+ DBG ("Line has less than three fields.");
continue;
+ }
switch (fields[2][0])
{
}
}
- closedir(proc);
+ closedir (proc);
ps_submit (running, sleeping, zombies, stopped, paging, blocked);
#endif /* KERNEL_LINUX */
diff --git a/src/swap.c b/src/swap.c
index f8ce93f328fd697d7e1979ac5f25031a6c74c54c..f906c99dd1413e64819075a0edf2aff2e4a85b51 100644 (file)
--- a/src/swap.c
+++ b/src/swap.c
#include "common.h"
#include "plugin.h"
+#if HAVE_SYS_SWAP_H
+# include <sys/swap.h>
+#endif
+#if HAVE_SYS_PARAM_H
+# include <sys/param.h>
+#endif
+#if HAVE_SYS_SYSCTL_H
+# include <sys/sysctl.h>
+#endif
+#if HAVE_KVM_H
+# include <kvm.h>
+#endif
+
#define MODULE_NAME "swap"
-#if defined(KERNEL_LINUX) || defined(KERNEL_SOLARIS) || defined(HAVE_LIBSTATGRAB)
+#if KERNEL_LINUX || HAVE_LIBKSTAT || defined(VM_SWAPUSAGE) || HAVE_LIBKVM || HAVE_LIBSTATGRAB
# define SWAP_HAVE_READ 1
#else
# define SWAP_HAVE_READ 0
#endif
-#if HAVE_SYS_SWAP_H
-# include <sys/swap.h>
-#endif
-
#undef MAX
#define MAX(x,y) ((x) > (y) ? (x) : (y))
};
static int ds_num = 4;
-#ifdef KERNEL_SOLARIS
+#if KERNEL_LINUX
+/* No global variables */
+/* #endif KERNEL_LINUX */
+
+#elif HAVE_LIBKSTAT
static unsigned long long pagesize;
static kstat_t *ksp;
-#endif /* KERNEL_SOLARIS */
+/* #endif HAVE_LIBKSTAT */
+
+#elif defined(VM_SWAPUSAGE)
+/* No global variables */
+/* #endif defined(VM_SWAPUSAGE) */
+
+#elif HAVE_LIBKVM
+static kvm_t *kvm_obj = NULL;
+int kvm_pagesize;
+/* #endif HAVE_LIBKVM */
+
+#elif HAVE_LIBSTATGRAB
+/* No global variables */
+#endif /* HAVE_LIBSTATGRAB */
static void swap_init (void)
{
-#ifdef KERNEL_SOLARIS
+#if KERNEL_LINUX
+ /* No init stuff */
+/* #endif KERNEL_LINUX */
+
+#elif HAVE_LIBKSTAT
/* getpagesize(3C) tells me this does not fail.. */
pagesize = (unsigned long long) getpagesize ();
if (get_kstat (&ksp, "unix", 0, "system_pages"))
ksp = NULL;
-#endif /* KERNEL_SOLARIS */
+/* #endif HAVE_LIBKSTAT */
+
+#elif defined(VM_SWAPUSAGE)
+ /* No init stuff */
+/* #endif defined(VM_SWAPUSAGE) */
+
+#elif HAVE_LIBKVM
+ if (kvm_obj != NULL)
+ {
+ kvm_close (kvm_obj);
+ kvm_obj = NULL;
+ }
+
+ kvm_pagesize = getpagesize ();
+
+ if ((kvm_obj = kvm_open (NULL, /* execfile */
+ NULL, /* corefile */
+ NULL, /* swapfile */
+ O_RDONLY, /* flags */
+ NULL)) /* errstr */
+ == NULL)
+ {
+ syslog (LOG_ERR, "swap plugin: kvm_open failed.");
+ return;
+ }
+/* #endif HAVE_LIBKVM */
+
+#elif HAVE_LIBSTATGRAB
+ /* No init stuff */
+#endif /* HAVE_LIBSTATGRAB */
return;
}
static void swap_read (void)
{
-#ifdef KERNEL_LINUX
+#if KERNEL_LINUX
FILE *fh;
char buffer[1024];
swap_used = swap_total - (swap_free + swap_cached);
swap_submit (swap_used, swap_free, swap_cached, -1LL);
-/* #endif defined(KERNEL_LINUX) */
+/* #endif KERNEL_LINUX */
-#elif defined(KERNEL_SOLARIS)
+#elif HAVE_LIBKSTAT
unsigned long long swap_alloc;
unsigned long long swap_resv;
unsigned long long swap_avail;
swap_avail = ai.ani_max - ai.ani_resv;
swap_avail *= pagesize;
- swap_submit (swap_alloc, swap_avail, -1LL, swap_resv);
-/* #endif defined(KERNEL_SOLARIS) */
+ swap_submit (swap_alloc, swap_avail, -1LL, swap_resv - swap_alloc);
+/* #endif HAVE_LIBKSTAT */
+
+#elif defined(VM_SWAPUSAGE)
+ int mib[3];
+ size_t mib_len;
+ struct xsw_usage sw_usage;
+ size_t sw_usage_len;
+ int status;
+
+ mib_len = 2;
+ mib[0] = CTL_VM;
+ mib[1] = VM_SWAPUSAGE;
+
+ sw_usage_len = sizeof (struct xsw_usage);
+
+ if (sysctl (mib, mib_len, &sw_usage, &sw_usage_len, NULL, 0) != 0)
+ return;
+
+ /* The returned values are bytes. */
+ swap_submit (sw_usage.xsu_used, sw_usage.xsu_avail, -1LL, -1LL);
+/* #endif VM_SWAPUSAGE */
+
+#elif HAVE_LIBKVM
+ struct kvm_swap data_s;
+ int status;
+
+ unsigned long long used;
+ unsigned long long free;
+ unsigned long long total;
+
+ if (kvm_obj == NULL)
+ return;
+
+ /* only one structure => only get the grand total, no details */
+ status = kvm_getswapinfo (kvm_obj, &data_s, 1, 0);
+ if (status == -1)
+ return;
+
+ total = (unsigned long long) data_s.ksw_total;
+ used = (unsigned long long) data_s.ksw_used;
+
+ total *= (unsigned long long) kvm_pagesize;
+ used *= (unsigned long long) kvm_pagesize;
+
+ free = total - used;
+
+ swap_submit (used, free, -1LL, -1LL);
+/* #endif HAVE_LIBKVM */
-#elif defined(HAVE_LIBSTATGRAB)
+#elif HAVE_LIBSTATGRAB
sg_swap_stats *swap;
if ((swap = sg_get_swap_stats ()) != NULL)
diff --git a/src/traffic.c b/src/traffic.c
index 929589e32baedc0864c7a26e1426e70286eefccf..18a2063ff52c0a760aeecef323e871e65543f3f9 100644 (file)
--- a/src/traffic.c
+++ b/src/traffic.c
*
* Authors:
* Florian octo Forster <octo at verplant.org>
+ * Sune Marcher <sm at flork.dk>
**/
#include "collectd.h"
#include "common.h"
#include "plugin.h"
+#include "configfile.h"
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
#define MODULE_NAME "traffic"
-#if HAVE_GETIFADDRS || defined(KERNEL_LINUX) || defined(HAVE_LIBKSTAT) || defined(HAVE_LIBSTATGRAB)
+/*
+ * Various people have reported problems with `getifaddrs' and varying versions
+ * of `glibc'. That's why it's disabled by default. Since more statistics are
+ * available this way one may enable it using the `--enable-getifaddrs' option
+ * of the configure script. -octo
+ */
+#if KERNEL_LINUX
+# if !COLLECT_GETIFADDRS
+# undef HAVE_GETIFADDRS
+# endif /* !COLLECT_GETIFADDRS */
+#endif /* KERNEL_LINUX */
+
+#if HAVE_GETIFADDRS || KERNEL_LINUX || HAVE_LIBKSTAT || HAVE_LIBSTATGRAB
# define TRAFFIC_HAVE_READ 1
#else
# define TRAFFIC_HAVE_READ 0
#define BUFSIZE 512
-static char *traffic_filename_template = "traffic-%s.rrd";
+/*
+ * (Module-)Global variables
+ */
+/* TODO: Move this to `interface-%s/<blah>.rrd' in version 4. */
+static char *bytes_file = "traffic-%s.rrd";
+static char *packets_file = "if_packets-%s.rrd";
+static char *errors_file = "if_errors-%s.rrd";
+/* TODO: Maybe implement multicast and broadcast counters */
-static char *ds_def[] =
+static char *config_keys[] =
+{
+ "Interface",
+ "IgnoreSelected",
+ NULL
+};
+static int config_keys_num = 2;
+
+static char *bytes_ds_def[] =
{
"DS:incoming:COUNTER:"COLLECTD_HEARTBEAT":0:U",
"DS:outgoing:COUNTER:"COLLECTD_HEARTBEAT":0:U",
NULL
};
-static int ds_num = 2;
+static int bytes_ds_num = 2;
+
+static char *packets_ds_def[] =
+{
+ "DS:rx:COUNTER:"COLLECTD_HEARTBEAT":0:U",
+ "DS:tx:COUNTER:"COLLECTD_HEARTBEAT":0:U",
+ NULL
+};
+static int packets_ds_num = 2;
+
+static char *errors_ds_def[] =
+{
+ "DS:rx:COUNTER:"COLLECTD_HEARTBEAT":0:U",
+ "DS:tx:COUNTER:"COLLECTD_HEARTBEAT":0:U",
+ NULL
+};
+static int errors_ds_num = 2;
+
+static char **if_list = NULL;
+static int if_list_num = 0;
+/*
+ * if_list_action:
+ * 0 => default is to collect selected interface
+ * 1 => ignore selcted interfaces
+ */
+static int if_list_action = 0;
#ifdef HAVE_LIBKSTAT
#define MAX_NUMIF 256
static int numif = 0;
#endif /* HAVE_LIBKSTAT */
+static int traffic_config (char *key, char *value)
+{
+ char **temp;
+
+ if (strcasecmp (key, "Interface") == 0)
+ {
+ temp = (char **) realloc (if_list, (if_list_num + 1) * sizeof (char *));
+ if (temp == NULL)
+ {
+ syslog (LOG_EMERG, "Cannot allocate more memory.");
+ return (1);
+ }
+ if_list = temp;
+
+ if ((if_list[if_list_num] = strdup (value)) == NULL)
+ {
+ syslog (LOG_EMERG, "Cannot allocate memory.");
+ return (1);
+ }
+ if_list_num++;
+ }
+ else if (strcasecmp (key, "IgnoreSelected") == 0)
+ {
+ if ((strcasecmp (value, "True") == 0)
+ || (strcasecmp (value, "Yes") == 0)
+ || (strcasecmp (value, "On") == 0))
+ if_list_action = 1;
+ else
+ if_list_action = 0;
+ }
+ else
+ {
+ return (-1);
+ }
+
+ return (0);
+}
+
static void traffic_init (void)
{
#if HAVE_GETIFADDRS
return;
}
-static void traffic_write (char *host, char *inst, char *val)
+/*
+ * Check if this interface/instance should be ignored. This is called from
+ * both, `submit' and `write' to give client and server the ability to
+ * ignore certain stuff..
+ */
+static int check_ignore_if (const char *interface)
{
- char file[BUFSIZE];
+ int i;
+
+ /* If no interfaces are given collect all interfaces. Mostly to be
+ * backwards compatible, but also because this is much easier. */
+ if (if_list_num < 1)
+ return (0);
+
+ for (i = 0; i < if_list_num; i++)
+ if (strcasecmp (interface, if_list[i]) == 0)
+ return (if_list_action);
+ return (1 - if_list_action);
+}
+
+static void generic_write (char *host, char *inst, char *val,
+ char *file_template,
+ char **ds_def, int ds_num)
+{
+ char file[512];
int status;
- status = snprintf (file, BUFSIZE, traffic_filename_template, inst);
+ if (check_ignore_if (inst))
+ return;
+
+ status = snprintf (file, BUFSIZE, file_template, inst);
if (status < 1)
return;
- else if (status >= BUFSIZE)
+ else if (status >= 512)
return;
rrd_update_file (host, file, val, ds_def, ds_num);
}
+static void bytes_write (char *host, char *inst, char *val)
+{
+ generic_write (host, inst, val, bytes_file, bytes_ds_def, bytes_ds_num);
+}
+
+static void packets_write (char *host, char *inst, char *val)
+{
+ generic_write (host, inst, val, packets_file, packets_ds_def, packets_ds_num);
+}
+
+static void errors_write (char *host, char *inst, char *val)
+{
+ generic_write (host, inst, val, errors_file, errors_ds_def, errors_ds_num);
+}
+
#if TRAFFIC_HAVE_READ
-static void traffic_submit (char *device,
- unsigned long long incoming,
- unsigned long long outgoing)
+static void bytes_submit (char *dev,
+ unsigned long long rx,
+ unsigned long long tx)
+{
+ char buf[512];
+ int status;
+
+ if (check_ignore_if (dev))
+ return;
+
+ status = snprintf (buf, 512, "%u:%lld:%lld",
+ (unsigned int) curtime,
+ rx, tx);
+ if ((status >= 512) || (status < 1))
+ return;
+
+ plugin_submit (MODULE_NAME, dev, buf);
+}
+
+#if HAVE_GETIFADDRS || KERNEL_LINUX || HAVE_LIBKSTAT
+static void packets_submit (char *dev,
+ unsigned long long rx,
+ unsigned long long tx)
+{
+ char buf[512];
+ int status;
+
+ if (check_ignore_if (dev))
+ return;
+
+ status = snprintf (buf, 512, "%u:%lld:%lld",
+ (unsigned int) curtime,
+ rx, tx);
+ if ((status >= 512) || (status < 1))
+ return;
+ plugin_submit ("if_packets", dev, buf);
+}
+
+static void errors_submit (char *dev,
+ unsigned long long rx,
+ unsigned long long tx)
{
- char buf[BUFSIZE];
+ char buf[512];
+ int status;
- if (snprintf (buf, BUFSIZE, "%u:%lld:%lld", (unsigned int) curtime, incoming, outgoing) >= BUFSIZE)
+ if (check_ignore_if (dev))
return;
- plugin_submit (MODULE_NAME, device, buf);
+ status = snprintf (buf, 512, "%u:%lld:%lld",
+ (unsigned int) curtime,
+ rx, tx);
+ if ((status >= 512) || (status < 1))
+ return;
+ plugin_submit ("if_errors", dev, buf);
}
+#endif /* HAVE_GETIFADDRS || KERNEL_LINUX || HAVE_LIBKSTAT */
static void traffic_read (void)
{
struct ifaddrs *if_list;
struct ifaddrs *if_ptr;
+/* Darin/Mac OS X and possible other *BSDs */
#if HAVE_STRUCT_IF_DATA
# define IFA_DATA if_data
-# define IFA_INCOMING ifi_ibytes
-# define IFA_OUTGOING ifi_obytes
+# define IFA_RX_BYTES ifi_ibytes
+# define IFA_TX_BYTES ifi_obytes
+# define IFA_RX_PACKT ifi_ipackets
+# define IFA_TX_PACKT ifi_opackets
+# define IFA_RX_ERROR ifi_ierrors
+# define IFA_TX_ERROR ifi_oerrors
+/* #endif HAVE_STRUCT_IF_DATA */
+
#elif HAVE_STRUCT_NET_DEVICE_STATS
# define IFA_DATA net_device_stats
-# define IFA_INCOMING rx_bytes
-# define IFA_OUTGOING tx_bytes
+# define IFA_RX_BYTES rx_bytes
+# define IFA_TX_BYTES tx_bytes
+# define IFA_RX_PACKT rx_packets
+# define IFA_TX_PACKT tx_packets
+# define IFA_RX_ERROR rx_errors
+# define IFA_TX_ERROR tx_errors
#else
# error "No suitable type for `struct ifaddrs->ifa_data' found."
#endif
if ((if_data = (struct IFA_DATA *) if_ptr->ifa_data) == NULL)
continue;
- traffic_submit (if_ptr->ifa_name,
- if_data->IFA_INCOMING,
- if_data->IFA_OUTGOING);
+ bytes_submit (if_ptr->ifa_name,
+ if_data->IFA_RX_BYTES,
+ if_data->IFA_TX_BYTES);
+ packets_submit (if_ptr->ifa_name,
+ if_data->IFA_RX_PACKT,
+ if_data->IFA_TX_PACKT);
+ errors_submit (if_ptr->ifa_name,
+ if_data->IFA_RX_ERROR,
+ if_data->IFA_TX_ERROR);
}
freeifaddrs (if_list);
while (fgets (buffer, 1024, fh) != NULL)
{
- if (buffer[6] != ':')
+ if (!(dummy = strchr(buffer, ':')))
continue;
- buffer[6] = '\0';
+ dummy[0] = '\0';
+ dummy++;
device = buffer;
while (device[0] == ' ')
if (device[0] == '\0')
continue;
- dummy = buffer + 7;
numfields = strsplit (dummy, fields, 16);
- if (numfields < 9)
+ if (numfields < 11)
continue;
incoming = atoll (fields[0]);
outgoing = atoll (fields[8]);
+ bytes_submit (device, incoming, outgoing);
- traffic_submit (device, incoming, outgoing);
+ incoming = atoll (fields[1]);
+ outgoing = atoll (fields[9]);
+ packets_submit (device, incoming, outgoing);
+
+ incoming = atoll (fields[2]);
+ outgoing = atoll (fields[10]);
+ errors_submit (device, incoming, outgoing);
}
fclose (fh);
/* #endif KERNEL_LINUX */
-#elif defined(HAVE_LIBKSTAT)
+#elif HAVE_LIBKSTAT
int i;
- unsigned long long incoming, outgoing;
+ unsigned long long rx;
+ unsigned long long tx;
if (kc == NULL)
return;
if (kstat_read (kc, ksp[i], NULL) == -1)
continue;
- if ((incoming = get_kstat_value (ksp[i], "rbytes")) == -1LL)
- continue;
- if ((outgoing = get_kstat_value (ksp[i], "obytes")) == -1LL)
- continue;
+ rx = get_kstat_value (ksp[i], "rbytes");
+ tx = get_kstat_value (ksp[i], "obytes");
+ if ((rx != -1LL) || (tx != -1LL))
+ bytes_submit (ksp[i]->ks_name, rx, tx);
+
+ rx = get_kstat_value (ksp[i], "ipackets");
+ tx = get_kstat_value (ksp[i], "opackets");
+ if ((rx != -1LL) || (tx != -1LL))
+ packets_submit (ksp[i]->ks_name, rx, tx);
- traffic_submit (ksp[i]->ks_name, incoming, outgoing);
+ rx = get_kstat_value (ksp[i], "ierrors");
+ tx = get_kstat_value (ksp[i], "oerrors");
+ if ((rx != -1LL) || (tx != -1LL))
+ errors_submit (ksp[i]->ks_name, rx, tx);
}
/* #endif HAVE_LIBKSTAT */
ios = sg_get_network_io_stats (&num);
for (i = 0; i < num; i++)
- traffic_submit (ios[i].interface_name, ios[i].rx, ios[i].tx);
+ bytes_submit (ios[i].interface_name, ios[i].rx, ios[i].tx);
#endif /* HAVE_LIBSTATGRAB */
}
#else
void module_register (void)
{
- plugin_register (MODULE_NAME, traffic_init, traffic_read, traffic_write);
+ plugin_register (MODULE_NAME, traffic_init, traffic_read, bytes_write);
+ plugin_register ("if_packets", NULL, NULL, packets_write);
+ plugin_register ("if_errors", NULL, NULL, errors_write);
+ cf_register (MODULE_NAME, traffic_config, config_keys, config_keys_num);
}
#undef BUFSIZE