Bug 176107

Summary: net-mgmt/collectd port update: adding zfs support
Product: Ports & Packages Reporter: Krzysztof <ports>
Component: Individual Port(s)Assignee: freebsd-ports-bugs (Nobody) <ports-bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description Krzysztof 2013-02-13 13:10:01 UTC
	Added support for ZFS to current collectd port. Thanks to Paul Guyot
for his time and patience.

How-To-Repeat: 	cd net-mgmt/collectd && make install
Comment 1 Pawel Pekala freebsd_committer freebsd_triage 2013-02-23 12:18:57 UTC
State Changed
From-To: open->feedback

Patching fails: 

===>  Found saved configuration for collectd-4.10.4_1 ===> 
collectd-4.10.8_2 depends on file: /usr/local/sbin/pkg - found ===> 
Extracting for collectd-4.10.8_2 => SHA256 Checksum OK for 
collectd-4.10.8.tar.gz.  ===>  Patching for collectd-4.10.8_2 ===> 
Applying FreeBSD patches for collectd-4.10.8_2 1 out of 1 hunks 
failed--saving rejects to src/network.c.rej => Patch 
patch-src__network.c failed to apply cleanly.  => Patch(es) 
patch-configure.in patch-src__Makefile.am patch-src__collectd.h 
patch-src__dns.c applied cleanly.  *** [do-patch] Error code 1 

Stop in /usr/local/tinderbox/portstrees/FreeBSD/ports/net-mgmt/collectd.
Comment 2 dfilter service freebsd_committer freebsd_triage 2013-02-23 15:37:08 UTC
Author: pawel
Date: Sat Feb 23 15:36:53 2013
New Revision: 312834
URL: http://svnweb.freebsd.org/changeset/ports/312834

Log:
  Add ZFS support
  
  PR:		ports/176107
  Submitted by:	Krzysztof Stryjek <ports@bsdserwis.com> (maintainer)

Added:
  head/net-mgmt/collectd/files/patch-src__zfs_arc.c   (contents, props changed)
Modified:
  head/net-mgmt/collectd/Makefile
  head/net-mgmt/collectd/files/patch-configure.in
  head/net-mgmt/collectd/files/patch-src__Makefile.am
  head/net-mgmt/collectd/pkg-plist

Modified: head/net-mgmt/collectd/Makefile
==============================================================================
--- head/net-mgmt/collectd/Makefile	Sat Feb 23 15:34:28 2013	(r312833)
+++ head/net-mgmt/collectd/Makefile	Sat Feb 23 15:36:53 2013	(r312834)
@@ -3,7 +3,7 @@
 
 PORTNAME=	collectd
 PORTVERSION=	4.10.8
-PORTREVISION=	1
+PORTREVISION=	2
 CATEGORIES=	net-mgmt
 MASTER_SITES=	http://collectd.org/files/
 
@@ -128,7 +128,6 @@ CONFIGURE_ARGS=	--localstatedir=/var \
 		--disable-vmem \
 		--disable-vserver \
 		--disable-wireless \
-		--disable-zfs_arc \
 		--without-perl-bindings \
 		--without-librabbitmq \
 		--disable-varnish \

Modified: head/net-mgmt/collectd/files/patch-configure.in
==============================================================================
--- head/net-mgmt/collectd/files/patch-configure.in	Sat Feb 23 15:34:28 2013	(r312833)
+++ head/net-mgmt/collectd/files/patch-configure.in	Sat Feb 23 15:36:53 2013	(r312834)
@@ -1,6 +1,16 @@
---- configure.in.orig	2011-10-14 12:49:49.000000000 -0800
-+++ configure.in	2012-03-20 08:09:25.000000000 -0800
-@@ -98,7 +98,7 @@
+--- configure.in.orig	2012-11-11 11:43:05.000000000 +0100
++++ configure.in	2012-12-30 23:49:30.000000000 +0100
+@@ -67,6 +67,9 @@
+ 	*openbsd*)
+ 	ac_system="OpenBSD"
+ 	;;
++	*freebsd*)
++	ac_system="FreeBSD"
++	;;
+ 	*aix*)
+ 	AC_DEFINE([KERNEL_AIX], 1, [True if program is to be compiled for a AIX kernel])
+ 	ac_system="AIX"
+@@ -98,7 +101,7 @@
  fi
  
  # Where to install .pc files.
@@ -9,7 +19,16 @@
  AC_SUBST(pkgconfigdir)
  
  # Check for standards compliance mode
-@@ -1745,9 +1745,6 @@
+@@ -1200,6 +1203,8 @@
+ then
+ 	AC_DEFINE(HAVE_LIBKSTAT, 1,
+ 		  [Define to 1 if you have the 'kstat' library (-lkstat)])
++	BUILD_WITH_LIBKSTAT_LIBS="-lkstat"
++	AC_SUBST(BUILD_WITH_LIBKSTAT_LIBS)
+ fi
+ AM_CONDITIONAL(BUILD_WITH_LIBKSTAT, test "x$with_kstat" = "xyes")
+ AM_CONDITIONAL(BUILD_WITH_LIBDEVINFO, test "x$with_devinfo" = "xyes")
+@@ -1562,9 +1567,6 @@
  		[with_libgcrypt="yes"],
  		[with_libgcrypt="no (symbol gcry_md_hash_buffer not found)"])
  
@@ -19,7 +38,7 @@
  fi
  
  CPPFLAGS="$SAVE_CPPFLAGS"
-@@ -3165,7 +3162,7 @@
+@@ -3059,7 +3061,7 @@
  if test "x$with_python" = "xyes"
  then
  	AC_MSG_CHECKING([for Python LIBS])
@@ -28,7 +47,7 @@
  	python_config_status=$?
  
  	if test "$python_config_status" -ne 0 || test "x$python_library_flags" = "x"
-@@ -3180,7 +3177,7 @@
+@@ -3074,7 +3076,7 @@
  if test "x$with_python" = "xyes"
  then
  	LDFLAGS="-L$python_library_path $LDFLAGS"
@@ -37,3 +56,16 @@
  
  	AC_CHECK_FUNC(PyObject_CallFunction,
  		      [with_python="yes"],
+@@ -4171,6 +4173,12 @@
+ 	plugin_zfs_arc="yes"
+ fi
+ 
++# FreeBSD
++if test "x$ac_system" = "xFreeBSD"
++then
++       plugin_zfs_arc="yes"
++fi
++
+ if test "x$with_devinfo$with_kstat" = "xyesyes"
+ then
+ 	plugin_cpu="yes"

Modified: head/net-mgmt/collectd/files/patch-src__Makefile.am
==============================================================================
--- head/net-mgmt/collectd/files/patch-src__Makefile.am	Sat Feb 23 15:34:28 2013	(r312833)
+++ head/net-mgmt/collectd/files/patch-src__Makefile.am	Sat Feb 23 15:36:53 2013	(r312834)
@@ -1,5 +1,5 @@
 --- src/Makefile.am.orig	2012-11-11 11:43:05.000000000 +0100
-+++ src/Makefile.am	2012-12-21 16:19:37.000000000 +0100
++++ src/Makefile.am	2012-12-30 23:34:44.000000000 +0100
 @@ -7,7 +7,7 @@
  endif
  
@@ -9,6 +9,15 @@
  endif
  
  AM_CPPFLAGS = -DPREFIX='"${prefix}"'
+@@ -1198,7 +1198,7 @@
+ zfs_arc_la_SOURCES = zfs_arc.c
+ zfs_arc_la_CFLAGS = $(AM_CFLAGS)
+ zfs_arc_la_LDFLAGS = -module -avoid-version
+-zfs_arc_la_LIBADD = -lkstat
++zfs_arc_la_LIBADD = $(BUILD_WITH_LIBKSTAT_LIBS)
+ collectd_LDADD += "-dlopen" zfs_arc.la
+ collectd_DEPENDENCIES += zfs_arc.la
+ endif
 @@ -1257,12 +1257,7 @@
  
  install-exec-hook:

Added: head/net-mgmt/collectd/files/patch-src__zfs_arc.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/net-mgmt/collectd/files/patch-src__zfs_arc.c	Sat Feb 23 15:36:53 2013	(r312834)
@@ -0,0 +1,161 @@
+--- src/zfs_arc.c.orig	2012-11-11 11:43:05.000000000 +0100
++++ src/zfs_arc.c	2012-12-31 00:59:33.000000000 +0100
+@@ -23,11 +23,58 @@
+ #include "common.h"
+ #include "plugin.h"
+ 
++#if !defined(HAVE_LIBKSTAT) && defined(HAVE_SYSCTLBYNAME)
++#include <sys/sysctl.h>
++#endif
++
+ /*
+  * Global variables
+  */
+ 
+-extern kstat_ctl_t *kc;
++#if defined(HAVE_LIBKSTAT)
++ extern kstat_ctl_t *kc;
++#endif
++
++/*
++ * Context
++ */
++struct za_context {
++#if defined(HAVE_LIBKSTAT)
++    kstat_t *ksp;
++#endif
++};
++
++static int za_init_context(struct za_context *ctx)
++{
++#if defined(HAVE_LIBKSTAT)
++	get_kstat (&ctx->ksp, "zfs", 0, "arcstats");
++	if (ctx->ksp == NULL)
++	{
++		ERROR ("zfs_arc plugin: Cannot find zfs:0:arcstats kstat.");
++		return (-1);
++	}
++#endif
++	return 0;
++}
++
++static long long za_get_value(struct za_context *ctx, const char* name)
++{
++#if defined(HAVE_LIBKSTAT)
++	return get_kstat_value(ctx->ksp, name);
++#elif defined(HAVE_SYSCTLBYNAME)
++	// kstat values are available on FreeBSD through sysctl
++	char fullname[512];
++	long long result = 0;
++	size_t size = sizeof(result);
++	ssnprintf(fullname, sizeof(fullname), "kstat.zfs.misc.arcstats.%s", name);
++	if (sysctlbyname(fullname, &result, &size, NULL, 0) != 0 || size != sizeof(result))
++	{
++		ERROR ("zfs_arc plugin: Cannot find stats using sysctl");
++		result = 0;
++	}
++	return result;
++#endif
++}
+ 
+ static void za_submit (const char* type, const char* type_instance, value_t* values, int values_len)
+ {
+@@ -90,42 +137,40 @@
+ 
+ static int za_read (void)
+ {
+-	gauge_t   arcsize, targetsize, minlimit, maxlimit, hits, misses, l2_size, l2_hits, l2_misses;
+-	counter_t demand_data_hits, demand_metadata_hits, prefetch_data_hits, prefetch_metadata_hits;
+-	counter_t demand_data_misses, demand_metadata_misses, prefetch_data_misses, prefetch_metadata_misses;
+-	counter_t l2_read_bytes, l2_write_bytes;
+-	kstat_t	 *ksp	= NULL;
++	long long   arcsize, targetsize, minlimit, maxlimit, hits, misses, l2_size, l2_hits, l2_misses;
++	long long demand_data_hits, demand_metadata_hits, prefetch_data_hits, prefetch_metadata_hits;
++	long long demand_data_misses, demand_metadata_misses, prefetch_data_misses, prefetch_metadata_misses;
++	long long l2_read_bytes, l2_write_bytes;
++	struct za_context ctx;
+ 
+-	get_kstat (&ksp, "zfs", 0, "arcstats");
+-	if (ksp == NULL)
++	if (za_init_context (&ctx) < 0)
+ 	{
+-		ERROR ("zfs_arc plugin: Cannot find zfs:0:arcstats kstat.");
+ 		return (-1);
+ 	}
+ 
+-	arcsize    = get_kstat_value(ksp, "size");
+-	targetsize = get_kstat_value(ksp, "c");
+-	minlimit   = get_kstat_value(ksp, "c_min");
+-	maxlimit   = get_kstat_value(ksp, "c_max");
+-
+-	demand_data_hits       = get_kstat_value(ksp, "demand_data_hits");
+-	demand_metadata_hits   = get_kstat_value(ksp, "demand_metadata_hits");
+-	prefetch_data_hits     = get_kstat_value(ksp, "prefetch_data_hits");
+-	prefetch_metadata_hits = get_kstat_value(ksp, "prefetch_metadata_hits");
+-
+-	demand_data_misses       = get_kstat_value(ksp, "demand_data_misses");
+-	demand_metadata_misses   = get_kstat_value(ksp, "demand_metadata_misses");
+-	prefetch_data_misses     = get_kstat_value(ksp, "prefetch_data_misses");
+-	prefetch_metadata_misses = get_kstat_value(ksp, "prefetch_metadata_misses");
+-
+-	hits   = get_kstat_value(ksp, "hits");
+-	misses = get_kstat_value(ksp, "misses");
+-
+-	l2_size        = get_kstat_value(ksp, "l2_size");
+-	l2_read_bytes  = get_kstat_value(ksp, "l2_read_bytes");
+-	l2_write_bytes = get_kstat_value(ksp, "l2_write_bytes");
+-	l2_hits        = get_kstat_value(ksp, "l2_hits");
+-	l2_misses      = get_kstat_value(ksp, "l2_misses");
++	arcsize    = za_get_value(&ctx, "size");
++	targetsize = za_get_value(&ctx, "c");
++	minlimit   = za_get_value(&ctx, "c_min");
++	maxlimit   = za_get_value(&ctx, "c_max");
++
++	demand_data_hits       = za_get_value(&ctx, "demand_data_hits");
++	demand_metadata_hits   = za_get_value(&ctx, "demand_metadata_hits");
++	prefetch_data_hits     = za_get_value(&ctx, "prefetch_data_hits");
++	prefetch_metadata_hits = za_get_value(&ctx, "prefetch_metadata_hits");
++
++	demand_data_misses       = za_get_value(&ctx, "demand_data_misses");
++	demand_metadata_misses   = za_get_value(&ctx, "demand_metadata_misses");
++	prefetch_data_misses     = za_get_value(&ctx, "prefetch_data_misses");
++	prefetch_metadata_misses = za_get_value(&ctx, "prefetch_metadata_misses");
++
++	hits   = za_get_value(&ctx, "hits");
++	misses = za_get_value(&ctx, "misses");
++
++	l2_size        = za_get_value(&ctx, "l2_size");
++	l2_read_bytes  = za_get_value(&ctx, "l2_read_bytes");
++	l2_write_bytes = za_get_value(&ctx, "l2_write_bytes");
++	l2_hits        = za_get_value(&ctx, "l2_hits");
++	l2_misses      = za_get_value(&ctx, "l2_misses");
+ 
+ 
+ 	za_submit_size (arcsize, targetsize, minlimit, maxlimit);
+@@ -146,12 +191,23 @@
+ 
+ static int za_init (void) /* {{{ */
+ {
+-	/* kstats chain already opened by update_kstat (using *kc), verify everything went fine. */
+-	if (kc == NULL)
++#if defined(HAVE_LIBKSTAT)
++ 	/* kstats chain already opened by update_kstat (using *kc), verify everything went fine. */
++ 	if (kc == NULL)
++ 	{
++ 		ERROR ("zfs_arc plugin: kstat chain control structure not available.");
++ 		return (-1);
++ 	}
++#elif defined(HAVE_SYSCTLBYNAME)
++	/* make sure ARC is available (arc_size is not null) */
++	unsigned long long arc_size;
++	size_t size = sizeof(arc_size);
++	if (sysctlbyname("kstat.zfs.misc.arcstats.size", &arc_size, &size, NULL, 0) != 0 || arc_size == 0)
+ 	{
+-		ERROR ("zfs_arc plugin: kstat chain control structure not available.");
++		ERROR ("zfs_arc plugin: could not get ARC size using sysctl, is ARC enabled?");
+ 		return (-1);
+ 	}
++#endif
+ 
+ 	return (0);
+ } /* }}} int za_init */

Modified: head/net-mgmt/collectd/pkg-plist
==============================================================================
--- head/net-mgmt/collectd/pkg-plist	Sat Feb 23 15:34:28 2013	(r312833)
+++ head/net-mgmt/collectd/pkg-plist	Sat Feb 23 15:36:53 2013	(r312834)
@@ -107,6 +107,8 @@ lib/collectd/uuid.la
 %%WRITE_HTTP%%lib/collectd/write_http.so
 %%XMMS%%lib/collectd/xmms.la
 %%XMMS%%lib/collectd/xmms.so
+lib/collectd/zfs_arc.la
+lib/collectd/zfs_arc.so
 include/collectd/client.h
 include/collectd/lcc_features.h
 libdata/pkgconfig/libcollectdclient.pc
_______________________________________________
svn-ports-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-ports-all
To unsubscribe, send any mail to "svn-ports-all-unsubscribe@freebsd.org"
Comment 3 Pawel Pekala freebsd_committer freebsd_triage 2013-02-23 15:37:09 UTC
State Changed
From-To: feedback->closed

Committed. Thanks!