[collectd] Variables in collectd.conf

Dan Fandrich dan at coneharvesters.com
Thu Mar 27 23:26:30 CET 2014


This patch seems to have been forgotten in the year since I posted it. I've
rebased it against HEAD, slightly improved it and am attaching it again.

On Wed, Apr 10, 2013 at 02:30:18PM +0200, Yves Mettier wrote:
> Hello,
> 
> Probably useful. I like it.
> 
> Regards,
> Yves
> 
> Le 2013-04-09 22:23, Dan Fandrich a écrit :
> >Any comments on this patch?
> >
> >>>>Dan
> >
> >The default collectd.conf file created for me by autoconf from the
> >collectd.conf.in file contains this for the first four entries with
> >variable
> >substitutions:
> >
> >#BaseDir     "${prefix}/var/lib/collectd"
> >#PIDFile     "${prefix}/var/run/collectd.pid"
> >#PluginDir   "${exec_prefix}/lib/collectd"
> >#TypesDB     "/usr/local/share/collectd/types.db"
> >
> >That is, all but the last contains variable references like
> >${prefix}. Needless to say, collectd doesn't expand these references
> >and it ends up creating files in directories named literally
> >"${prefix}". Looking at the autoconf output, it appears that all
> >autoconf
> >substitution variables except for @prefix@ do this, and some (like
> >@execdir@) go through two levels of variable indirection.
> >
> >It looks like this is by design, as the autoconf documentation says
> >"...you should not use these variables except in makefiles". The
> >workaround
> >they suggest is to use sed to do the variable substitution manually
> >for each
> >desired variable, instead of using AC_CONFIG_FILES.
> >
> >The attached patch changes collectd to use the specified method of
> >replacing
> >the directory variables.
> >
> >>>>Dan
-------------- next part --------------
From 4b149cdf4748d4c686b5f65cd1e67ec2df08d753 Mon Sep 17 00:00:00 2001
From: Dan Fandrich <dan at coneharvesters.com>
Date: Sat, 2 Mar 2013 13:08:01 +0100
Subject: [PATCH] collectd.conf: Fixed the installation directory paths

These variables are designed to be used from within a makefile,
so they must be substituted from a script called from there.
---
 configure.ac                                  | 13 ++++++++++--
 src/Makefile.am                               | 13 ++++++++++++
 src/{collectd.conf.in => collectd.conf.in.in} | 30 +++++++++++++--------------
 3 files changed, 39 insertions(+), 17 deletions(-)
 rename src/{collectd.conf.in => collectd.conf.in.in} (97%)

diff --git a/configure.ac b/configure.ac
index f1c7b8a..2fbf96c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5365,9 +5365,18 @@ AC_SUBST(LCC_VERSION_PATCH)
 AC_SUBST(LCC_VERSION_EXTRA)
 AC_SUBST(LCC_VERSION_STRING)
 
-AC_CONFIG_FILES(src/libcollectdclient/collectd/lcc_features.h)
+AC_CONFIG_FILES(
+	Makefile
+	src/Makefile
+	src/collectd.conf.in
+	src/libcollectdclient/Makefile
+	src/libcollectdclient/collectd/lcc_features.h
+	src/libcollectdclient/libcollectdclient.pc
+	src/liboconfig/Makefile
+	bindings/Makefile
+	bindings/java/Makefile
+)
 
-AC_CONFIG_FILES([Makefile src/Makefile src/collectd.conf src/libcollectdclient/Makefile src/libcollectdclient/libcollectdclient.pc src/liboconfig/Makefile bindings/Makefile bindings/java/Makefile])
 AC_OUTPUT
 
 if test "x$with_librrd" = "xyes" \
diff --git a/src/Makefile.am b/src/Makefile.am
index a9d8582..4ac08d5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1441,6 +1441,10 @@ collectd_LDADD += "-dlopen" zfs_arc.la
 collectd_DEPENDENCIES += zfs_arc.la
 endif
 
+collectd_conf_DATA = collectd.conf
+collectd_confdir =
+CLEANFILES += collectd.conf
+
 BUILT_SOURCES += $(dist_man_MANS)
 
 dist_man_MANS = collectd.1 \
@@ -1517,6 +1521,15 @@ riemann.pb-c.c riemann.pb-c.h: riemann.proto
 	protoc-c -I$(srcdir) --c_out . $(srcdir)/riemann.proto
 endif
 
+# This is the autoconf-recommended way to substitute build path variables
+# instead of AC_CONFIG_FILES
+collectd.conf: collectd.conf.in
+	$(SED) -e 's|@localstatedir_conf[@]|$(localstatedir)|' \
+	       -e 's|@libdir_conf[@]|$(libdir)|' \
+	       -e 's|@prefix_conf[@]|$(prefix)|' \
+	       -e 's|@sysconfdir_conf[@]|$(sysconfdir)|' \
+	       $< >collectd.conf.tmp.$$$$ && mv -f collectd.conf.tmp.$$$$ $@
+
 install-exec-hook:
 	$(mkinstalldirs) $(DESTDIR)$(sysconfdir)
 	if test -e $(DESTDIR)$(sysconfdir)/collectd.conf; \
diff --git a/src/collectd.conf.in b/src/collectd.conf.in.in
similarity index 97%
rename from src/collectd.conf.in
rename to src/collectd.conf.in.in
index 830add9..8513292 100644
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in.in
@@ -12,10 +12,10 @@
 
 #Hostname    "localhost"
 #FQDNLookup   true
-#BaseDir     "@localstatedir@/lib/@PACKAGE_NAME@"
-#PIDFile     "@localstatedir@/run/@PACKAGE_NAME at .pid"
-#PluginDir   "@libdir@/@PACKAGE_NAME@"
-#TypesDB     "@prefix@/share/@PACKAGE_NAME@/types.db"
+#BaseDir     "@localstatedir_conf@/lib/@PACKAGE_NAME@"
+#PIDFile     "@localstatedir_conf@/run/@PACKAGE_NAME at .pid"
+#PluginDir   "@libdir_conf@/@PACKAGE_NAME@"
+#TypesDB     "@prefix_conf@/share/@PACKAGE_NAME@/types.db"
 
 #----------------------------------------------------------------------------#
 # When enabled, plugins are loaded automatically with the default options    #
@@ -278,7 +278,7 @@
 #</Plugin>
 
 #<Plugin csv>
-#	DataDir "@localstatedir@/lib/@PACKAGE_NAME@/csv"
+#	DataDir "@localstatedir_conf@/lib/@PACKAGE_NAME@/csv"
 #	StoreRates false
 #</Plugin>
 
@@ -394,7 +394,7 @@
 #</Plugin>
 
 #<Plugin email>
-#	SocketFile "@localstatedir@/run/@PACKAGE_NAME at -email"
+#	SocketFile "@localstatedir_conf@/run/@PACKAGE_NAME at -email"
 #	SocketGroup "collectd"
 #	SocketPerms "0770"
 #	MaxConns 5
@@ -469,7 +469,7 @@
 
 #<Plugin "java">
 #	JVMArg "-verbose:jni"
-#	JVMArg "-Djava.class.path=@prefix@/share/collectd/java/collectd-api.jar"
+#	JVMArg "-Djava.class.path=@prefix_conf@/share/collectd/java/collectd-api.jar"
 #
 #	LoadPlugin "org.collectd.java.Foobar"
 #	<Plugin "org.collectd.java.Foobar">
@@ -575,7 +575,7 @@
 #
 #	<Database db_name2>
 #		Host "localhost"
-#		Socket "/var/run/mysql/mysqld.sock"
+#		Socket "@localstatedir_conf@/run/mysql/mysqld.sock"
 #		SlaveStats true
 #		SlaveNotifications true
 #	</Database>
@@ -657,7 +657,7 @@
 #	Listen "ff18::efc0:4a42" "25826"
 #	<Listen "239.192.74.66" "25826">
 #		SecurityLevel Sign
-#		AuthFile "/etc/collectd/passwd"
+#		AuthFile "@sysconfdir_conf@/collectd/passwd"
 #		Interface "eth0"
 #	</Listen>
 #	MaxPacketSize 1024
@@ -836,14 +836,14 @@
 #  <Server "server_name">
 #    Collect "latency"
 #    Collect "udp-answers" "udp-queries"
-#    Socket "/var/run/pdns.controlsocket"
+#    Socket "@localstatedir_conf@/run/pdns.controlsocket"
 #  </Server>
 #  <Recursor "recursor_name">
 #    Collect "questions"
 #    Collect "cache-hits" "cache-misses"
-#    Socket "/var/run/pdns_recursor.controlsocket"
+#    Socket "@localstatedir_conf@/run/pdns_recursor.controlsocket"
 #  </Recursor>
-#  LocalSocket "/opt/collectd/var/run/collectd-powerdns"
+#  LocalSocket "@localstatedir_conf@/run/collectd-powerdns"
 #</Plugin>
 
 #<Plugin processes>
@@ -891,14 +891,14 @@
 
 #<Plugin rrdcached>
 #	DaemonAddress "unix:/tmp/rrdcached.sock"
-#	DataDir "@localstatedir@/lib/@PACKAGE_NAME@/rrd"
+#	DataDir "@localstatedir_conf@/lib/@PACKAGE_NAME@/rrd"
 #	CreateFiles true
 #	CreateFilesAsync false
 #	CollectStatistics true
 #</Plugin>
 
 #<Plugin rrdtool>
-#	DataDir "@localstatedir@/lib/@PACKAGE_NAME@/rrd"
+#	DataDir "@localstatedir_conf@/lib/@PACKAGE_NAME@/rrd"
 #	CreateFilesAsync false
 #	CacheTimeout 120
 #	CacheFlush   900
@@ -1079,7 +1079,7 @@
 #</Plugin>
 
 #<Plugin unixsock>
-#	SocketFile "@prefix@/var/run/@PACKAGE_NAME at -unixsock"
+#	SocketFile "@localstatedir_conf@/run/@PACKAGE_NAME at -unixsock"
 #	SocketGroup "collectd"
 #	SocketPerms "0660"
 #	DeleteSocket false
-- 
1.8.1.5



More information about the collectd mailing list