Merge branch 'feature/ZOL'
authorMarc Fournier <marc.fournier@camptocamp.com>
Fri, 22 Aug 2014 21:22:34 +0000 (23:22 +0200)
committerMarc Fournier <marc.fournier@camptocamp.com>
Fri, 22 Aug 2014 21:22:34 +0000 (23:22 +0200)
Conflicts:
configure.ac

AUTHORS
configure.ac
contrib/redhat/collectd.spec
src/Makefile.am
src/zfs_arc.c

diff --git a/AUTHORS b/AUTHORS
index 6ecc688..680ad07 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -147,6 +147,7 @@ Marc Fournier <marc.fournier at camptocamp.com>
  - Various fixes to the varnish plugin.
  - RPM specfile update.
  - libmnl support in the netlink plugin.
+ - linux support in the zfs_arc plugin.
 
 Marco Chiappero <marco at absence.it>
  - uptime plugin.
@@ -259,6 +260,9 @@ Tommie Gannert <d00-tga at d.kth.se>
 Vincent StehlĂ© <vincent.stehle at free.fr>
  - hddtemp plugin.
 
+Wilfried Goesgens <dothebart at citadel.org>
+ - linux support in the zfs_arc plugin.
+
 Xin Li <delphij at freebsd.org>
  - FreeBSD port of the ZFS-ARC plugin.
 
index 0df5678..0d0d043 100644 (file)
@@ -70,9 +70,11 @@ case $host_os in
        ac_system="Solaris"
        ;;
        *darwin*)
+       AC_DEFINE([KERNEL_DARWIN], 1, [True if program is to be compiled for a Darwin kernel])
        ac_system="Darwin"
        ;;
        *openbsd*)
+       AC_DEFINE([KERNEL_OPENBSD], 1, [True if program is to be compiled for an OpenBSD kernel])
        ac_system="OpenBSD"
        ;;
        *aix*)
@@ -88,6 +90,13 @@ case $host_os in
 esac
 AC_MSG_RESULT([$ac_system])
 
+AM_CONDITIONAL([BUILD_LINUX],[test "x$x$ac_system" = "xLinux"])
+AM_CONDITIONAL([BUILD_SOLARIS],[test "x$x$ac_system" = "xSolaris"])
+AM_CONDITIONAL([BUILD_DARWIN],[test "x$x$ac_system" = "xDarwin"])
+AM_CONDITIONAL([BUILD_OPENBSD],[test "x$x$ac_system" = "xOpenBSD"])
+AM_CONDITIONAL([BUILD_AIX],[test "x$x$ac_system" = "xAIX"])
+AM_CONDITIONAL([BUILD_FREEBSD],[test "x$x$ac_system" = "xFreeBSD"])
+
 if test "x$ac_system" = "xLinux"
 then
        AC_ARG_VAR([KERNEL_DIR], [path to Linux kernel sources])
@@ -1398,10 +1407,6 @@ fi
 m4_divert_once([HELP_WITH], [
 collectd additional packages:])
 
-AM_CONDITIONAL([BUILD_FREEBSD],[test "x$x$ac_system" = "xFreeBSD"])
-
-AM_CONDITIONAL([BUILD_AIX],[test "x$x$ac_system" = "xAIX"])
-
 if test "x$ac_system" = "xAIX"
 then
        with_perfstat="yes"
@@ -5011,6 +5016,7 @@ then
        plugin_vmem="yes"
        plugin_vserver="yes"
        plugin_wireless="yes"
+       plugin_zfs_arc="yes"
 
        if test "x$have_linux_ip_vs_h" = "xyes" || test "x$have_net_ip_vs_h" = "xyes" || test "x$have_ip_vs_h" = "xyes"
        then
index 9facca8..3322059 100644 (file)
 %define with_write_graphite 0%{!?_without_write_graphite:1}
 %define with_write_http 0%{!?_without_write_http:1}
 %define with_write_riemann 0%{!?_without_write_riemann:1}
+%define with_zfs_arc 0%{!?_without_zfs_arc:1}
 
 # Plugins not built by default because of dependencies on libraries not
 # available in RHEL or EPEL:
 %define with_write_redis 0%{!?_without_write_redis:0}
 # plugin xmms disabled, requires xmms
 %define with_xmms 0%{!?_without_xmms:0}
-# plugin zfs_arc disabled, requires FreeBSD/Solaris
-%define with_zfs_arc 0%{!?_without_zfs_arc:0}
 
 Summary:       Statistics collection daemon for filling RRD files
 Name:          collectd
index d727566..b862365 100644 (file)
@@ -1493,8 +1493,13 @@ zfs_arc_la_LDFLAGS = -module -avoid-version
 if BUILD_FREEBSD
 zfs_arc_la_LIBADD = -lm
 else
+if BUILD_LINUX
+# zfs_arc requires no library on linux
+else
+# solaris
 zfs_arc_la_LIBADD = -lkstat
 endif
+endif
 collectd_LDADD += "-dlopen" zfs_arc.la
 collectd_DEPENDENCIES += zfs_arc.la
 endif
index 96ffc54..b784ee3 100644 (file)
@@ -3,6 +3,8 @@
  * Copyright (C) 2009  Anthony Dewhurst
  * Copyright (C) 2012  Aurelien Rougemont
  * Copyright (C) 2013  Xin Li
+ * Copyright (C) 2014  Marc Fournier
+ * Copyright (C) 2014  Wilfried Goesgens
  *
  * 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
@@ -21,6 +23,8 @@
  *   Anthony Dewhurst <dewhurst at gmail>
  *   Aurelien Rougemont <beorn at gandi.net>
  *   Xin Li <delphij at FreeBSD.org>
+ *   Marc Fournier <marc.fournier at camptocamp.com>
+ *   Wilfried Goesgens <dothebart at citadel.org>
  **/
 
 #include "collectd.h"
  * Global variables
  */
 
-#if !defined(__FreeBSD__)
+#if defined(KERNEL_LINUX)
+#include "utils_llist.h"
+#define ZOL_ARCSTATS_FILE "/proc/spl/kstat/zfs/arcstats"
+
+typedef        llist_t kstat_t;
+
+static long long get_zfs_value(kstat_t *zfs_stats  __attribute__((unused)),
+               char *name)
+{
+       llentry_t *e;
+
+       e = llist_search (zfs_stats, name);
+       if (e == NULL)
+       {
+               ERROR ("zfs_arc plugin: `llist_search` failed for key: '%s'.", name);
+               return (-1);
+       }
+
+       return (*(long long int*)e->value);
+}
+
+#elif !defined(__FreeBSD__) // Solaris
 extern kstat_ctl_t *kc;
 
 static long long get_zfs_value(kstat_t *ksp, char *name)
@@ -39,7 +64,7 @@ static long long get_zfs_value(kstat_t *ksp, char *name)
 
        return (get_kstat_value(ksp, name));
 }
-#else
+#else // FreeBSD
 #include <sys/types.h>
 #include <sys/sysctl.h>
 
@@ -147,7 +172,75 @@ static int za_read (void)
        value_t  l2_io[2];
        kstat_t  *ksp   = NULL;
 
-#if !defined(__FreeBSD__)
+#if KERNEL_LINUX
+       long long int *llvalues = NULL;
+       char file_contents[1024 * 10];
+       char *fields[3];
+       int numfields;
+       ssize_t len;
+
+       ksp = llist_create ();
+       if (ksp == NULL)
+       {
+               ERROR ("zfs_arc plugin: `llist_create' failed.");
+               return (-1);
+       }
+
+       len = read_file_contents (ZOL_ARCSTATS_FILE, file_contents, sizeof(file_contents));
+       if (len > 1)
+       {
+
+               int i=0;
+               char *pnl = file_contents;
+               char *pnnl;
+
+               file_contents[len] = '\0';
+
+               while (pnl != NULL)
+               {
+                       pnl = strchr(pnl, '\n');
+                       i++;
+                       if (pnl && (*pnl != '\0'))
+                               pnl++;
+               }
+
+               if (i > 0)
+               {
+                       llentry_t *e;
+                       llvalues = malloc(sizeof(long long int) * i);
+                       int j = 0;
+
+                       pnl = file_contents;
+                       while (pnl != NULL)
+                       {
+                               pnnl = strchr(pnl, '\n');
+                               if (pnnl != NULL)
+                                       *pnnl = '\0';
+
+                               numfields = strsplit (pnl, fields, 4);
+                               if (numfields == 3)
+                               {
+                                       llvalues[j] = atoll (fields[2]);
+
+                                       e = llentry_create (fields[0], &llvalues[j]);
+                                       if (e == NULL)
+                                       {
+                                               ERROR ("zfs_arc plugin: `llentry_create' failed.");
+                                       }
+                                       else
+                                       {
+                                               llist_append (ksp, e);
+                                       }
+                                       j++;
+                               }
+                               pnl = pnnl;
+                               if (pnl != NULL)
+                                       pnl ++;
+                       }
+               }
+       }
+
+#elif !defined(__FreeBSD__) // Solaris
        get_kstat (&ksp, "zfs", 0, "arcstats");
        if (ksp == NULL)
        {
@@ -170,7 +263,7 @@ static int za_read (void)
        /* Issue indicators */
        za_read_derive (ksp, "mutex_miss", "mutex_operations", "miss");
        za_read_derive (ksp, "hash_collisions", "hash_collisions", "");
-       
+
        /* Evictions */
        za_read_derive (ksp, "evict_l2_cached",     "cache_eviction", "cached");
        za_read_derive (ksp, "evict_l2_eligible",   "cache_eviction", "eligible");
@@ -201,12 +294,23 @@ static int za_read (void)
 
        za_submit ("io_octets", "L2", l2_io, /* num values = */ 2);
 
+#if defined(KERNEL_LINUX)
+       if (llvalues != NULL)
+       {
+               free(llvalues);
+       }
+       if (ksp != NULL)
+       {
+               llist_destroy (ksp);
+       }
+#endif
+
        return (0);
 } /* int za_read */
 
 static int za_init (void) /* {{{ */
 {
-#if !defined(__FreeBSD__)
+#if !defined(__FreeBSD__) && !defined(KERNEL_LINUX) // Solaris
        /* kstats chain already opened by update_kstat (using *kc), verify everything went fine. */
        if (kc == NULL)
        {