author | Marc Fournier <marc.fournier@camptocamp.com> | |
Fri, 22 Aug 2014 21:22:34 +0000 (23:22 +0200) | ||
committer | Marc Fournier <marc.fournier@camptocamp.com> | |
Fri, 22 Aug 2014 21:22:34 +0000 (23:22 +0200) |
Conflicts:
configure.ac
configure.ac
AUTHORS | patch | blob | history | |
configure.ac | patch | blob | history | |
contrib/redhat/collectd.spec | patch | blob | history | |
src/Makefile.am | patch | blob | history | |
src/zfs_arc.c | patch | blob | history |
index 6ecc6881f7eb79f76d4b4584251935c1abf9849e..680ad071f7ff096db4caa97284929ce905675a11 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
- 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.
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.
diff --git a/configure.ac b/configure.ac
index 0df5678245b1483dc4810a90c7984db51da39270..0d0d04359ce9f1076bf3f639944fdafec53c29a1 100644 (file)
--- a/configure.ac
+++ b/configure.ac
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*)
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])
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"
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 9facca839623a8d865203bbec51c7efe504f7b04..3322059899d6cdde7423aa750242b466debf1a7c 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
diff --git a/src/Makefile.am b/src/Makefile.am
index d72756659200b6a96a0ebe574a99f071fbbe4433..b8623653118416a5790f9b1fd1096d4747e85f5d 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
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
diff --git a/src/zfs_arc.c b/src/zfs_arc.c
index 96ffc54957aae84a8fb548e3df352307a9a9d168..b784ee3a3fc1374a66e03f12b432c625ae48dce1 100644 (file)
--- a/src/zfs_arc.c
+++ b/src/zfs_arc.c
* 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
* 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)
return (get_kstat_value(ksp, name));
}
-#else
+#else // FreeBSD
#include <sys/types.h>
#include <sys/sysctl.h>
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)
{
/* 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");
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)
{