octo@leeloo:~/collectd $ svn merge -r786:HEAD branches/freebsd trunk
authorocto <octo>
Thu, 15 Jun 2006 21:51:52 +0000 (21:51 +0000)
committerocto <octo>
Thu, 15 Jun 2006 21:51:52 +0000 (21:51 +0000)
1  2 
configure.in
src/Makefile.am
src/memory.c

diff --combined configure.in
@@@ -44,7 -44,6 +44,7 @@@ AC_CHECK_HEADERS(assert.h
  AC_CHECK_HEADERS(sys/types.h)
  AC_CHECK_HEADERS(sys/socket.h)
  AC_CHECK_HEADERS(sys/select.h)
 +AC_CHECK_HEADERS(sys/poll.h)
  AC_CHECK_HEADERS(netdb.h)
  AC_CHECK_HEADERS(arpa/inet.h)
  AC_CHECK_HEADERS(sys/resource.h)
@@@ -263,6 -262,9 +263,9 @@@ AC_CHECK_HEADERS(sys/statvfs.h
  AC_CHECK_HEADERS(sys/vfs.h)
  AC_CHECK_HEADERS(sys/vfstab.h)
  
+ # For the swap plugin, FreeBSD
+ AC_CHECK_HEADERS(kvm.h)
  # For debugging interface (variable number of arguments)
  AC_CHECK_HEADERS(stdarg.h)
  
@@@ -605,7 -607,6 +608,6 @@@ AM_CONDITIONAL(BUILD_WITH_LIBIOKIT, tes
  
  with_libstatgrab="yes"
  with_libdevstat="no"
- with_libkvm="no"
  AC_ARG_WITH(libstatgrab, [AS_HELP_STRING([--with-libstatgrab@<:@=PREFIX@:>@], [Path to libstatgrab.])],
  [
        if test "x$withval" != "xno" -a "x$withval" != "xyes"
@@@ -634,7 -635,6 +636,6 @@@ f
  if test "x$with_libstatgrab" = "xyes"
  then
        AC_CHECK_LIB(devstat, getdevs, [with_libdevstat="yes"], [with_libdevstat="no"])
-       AC_CHECK_LIB(kvm, kvm_getargv, [with_libkvm="yes"],     [with_libkvm="no"])
  fi
  if test "x$with_libstatgrab" = "xyes"
  then
@@@ -646,7 -646,13 +647,13 @@@ AC_DEFINE_UNQUOTED(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")
- AM_CONDITIONAL(BUILD_WITH_LIBKVM,      test "x$with_libkvm"      = "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.])],
  [
@@@ -902,7 -908,6 +909,7 @@@ AC_COLLECTD([load],      [disable], [mo
  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])
@@@ -949,7 -954,6 +956,7 @@@ Configuration
      memory  . . . . . . $enable_memory
      mysql . . . . . . . $enable_mysql
      nfs . . . . . . . . $enable_nfs
 +    ntpd  . . . . . . . $enable_ntpd
      ping  . . . . . . . $enable_ping
      processes . . . . . $enable_processes
      sensors . . . . . . $enable_sensors
diff --combined src/Makefile.am
@@@ -236,17 -236,6 +236,17 @@@ collectd_LDADD += "-dlopen" nfs.l
  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
@@@ -302,10 -291,10 +302,10 @@@ endi
  if BUILD_WITH_LIBDEVINFO
  swap_la_LDFLAGS += -ldevinfo
  endif
- if BUILD_WITH_LIBSTATGRAB
  if BUILD_WITH_LIBKVM
  swap_la_LDFLAGS += -lkvm
  endif
+ if BUILD_WITH_LIBSTATGRAB
  if BUILD_WITH_LIBDEVSTAT
  swap_la_LDFLAGS += -ldevstat
  endif
diff --combined 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
@@@ -67,11 -72,15 +72,15 @@@ static mach_port_t port_host
  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 */
@@@ -83,6 -92,10 +92,10 @@@ static void memory_init (void
        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 */
@@@ -170,6 -183,57 +183,57 @@@ static void memory_read (void
        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];