summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 15e2832)
raw | patch | inline | side by side (parent: 15e2832)
author | Marc Fournier <marc.fournier@camptocamp.com> | |
Fri, 7 Feb 2014 13:51:31 +0000 (14:51 +0100) | ||
committer | Marc Fournier <marc.fournier@camptocamp.com> | |
Wed, 12 Feb 2014 00:00:20 +0000 (01:00 +0100) |
The plugin is structured for Solaris & FreeBSD's get_kstat_value() &
sysctlbyname() functions, which return a single metric based on its
name. ZFS-on-Linux publishes all the stats together in a file in /proc,
which is quite a different approach.
So the idea is to simulate the Solaris/FreeBSD way of doing by using
llist_search() on a linked-list containing all the key/values from the
/proc file. This prevents having to parse it over and over again for
each metric we request.
sysctlbyname() functions, which return a single metric based on its
name. ZFS-on-Linux publishes all the stats together in a file in /proc,
which is quite a different approach.
So the idea is to simulate the Solaris/FreeBSD way of doing by using
llist_search() on a linked-list containing all the key/values from the
/proc file. This prevents having to parse it over and over again for
each metric we request.
configure.ac | patch | blob | history | |
src/Makefile.am | patch | blob | history | |
src/zfs_arc.c | patch | blob | history |
diff --git a/configure.ac b/configure.ac
index d3687b38760cbe7d453fb040ec7bb4661694b3d0..068acdca9954b6493dfdec29beaa9bdd8f539c57 100644 (file)
--- a/configure.ac
+++ b/configure.ac
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
diff --git a/src/Makefile.am b/src/Makefile.am
index a9d858232a9ec547f42e52d335b1d3e5ff2da5eb..487be2324ba18687afe2e98fb163acd0593f5c27 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..4190a717e01d264431bbd02412e679f925888adc 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
*
* 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>
**/
#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"
+
+#if !defined(kstat_t)
+typedef void kstat_t;
+static llist_t *zfs_stats = NULL;
+#endif
+
+static long long get_zfs_value(kstat_t *dummy __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
+ FILE *fh;
+
+ char buf[1024];
+ char *fields[3];
+ int numfields;
+
+ if ((fh = fopen (ZOL_ARCSTATS_FILE, "r")) == NULL)
+ {
+ char errbuf[1024];
+ ERROR ("zfs_arc plugin: `fopen (%s)' failed: %s",
+ ZOL_ARCSTATS_FILE,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ return (-1);
+ }
+
+ zfs_stats = llist_create ();
+ if (zfs_stats == NULL)
+ {
+ ERROR ("zfs_arc plugin: `llist_create' failed.");
+ fclose (fh);
+ return (-1);
+ }
+
+ while (fgets (buf, 1024, fh) != NULL)
+ {
+ numfields = strsplit (buf, fields, 4);
+ if (numfields != 3)
+ continue;
+
+ char *llkey;
+ long long int llvalue;
+
+ llkey = strdup (fields[0]);
+ if (llkey == NULL) {
+ char errbuf[1024];
+ ERROR ("zfs_arc plugin: `strdup' failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ continue;
+ }
+
+ llvalue = atoll (fields[2]);
+
+ llentry_t *e;
+ e = llentry_create (llkey, (void *)llvalue);
+ if (e == NULL)
+ {
+ ERROR ("zfs_arc plugin: `llentry_create' failed.");
+ free (llkey);
+ continue;
+ }
+
+ free (llkey);
+
+ llist_append (zfs_stats, e);
+ }
+
+ if (fclose (fh))
+ {
+ char errbuf[1024];
+ WARNING ("zfs_arc: `fclose' failed: %s", sstrerror (errno, errbuf, sizeof (errbuf)));
+ }
+
+#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 (zfs_stats != NULL)
+ {
+ llist_destroy (zfs_stats);
+ }
+#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)
{