[collectd] conntrack patch against 4.6.2
Tomasz Pala
gotar at polanet.pl
Mon Mar 30 11:23:33 CEST 2009
Hello,
I've adapted entropy plugin to get nf_conntrack entries, which is
important on Linux routers. Attached patch.
BTW you may want to take a look at PLD Linux spec file at
http://cvs.pld-linux.org/cgi-bin/cvsweb/SPECS/collectd.spec or
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SPECS/collectd.spec
as it's much more complex than Fedora, RH or SLES ones which are shipped
in contrib.
--
Tomasz Pala <gotar at pld-linux.org>
-------------- next part --------------
diff -purN collectd-4.6.2.orig/configure.in collectd-4.6.2/configure.in
--- collectd-4.6.2.orig/configure.in 2009-03-18 11:56:26.000000000 +0100
+++ collectd-4.6.2/configure.in 2009-03-30 11:03:56.000000000 +0200
@@ -2841,6 +2841,7 @@ dependency_error="no"
plugin_ascent="no"
plugin_battery="no"
plugin_bind="no"
+plugin_conntrack="no"
plugin_cpu="no"
plugin_cpufreq="no"
plugin_df="no"
@@ -2871,6 +2872,7 @@ plugin_wireless="no"
if test "x$ac_system" = "xLinux"
then
plugin_battery="yes"
+ plugin_conntrack="yes"
plugin_cpu="yes"
plugin_cpufreq="yes"
plugin_disk="yes"
@@ -3044,6 +3046,7 @@ AC_PLUGIN([apple_sensors], [$with_libiok
AC_PLUGIN([ascent], [$plugin_ascent], [AscentEmu player statistics])
AC_PLUGIN([battery], [$plugin_battery], [Battery statistics])
AC_PLUGIN([bind], [$plugin_bind], [ISC Bind nameserver statistics])
+AC_PLUGIN([conntrack], [$plugin_conntrack], [nf_conntrack statistics])
AC_PLUGIN([cpufreq], [$plugin_cpufreq], [CPU frequency statistics])
AC_PLUGIN([cpu], [$plugin_cpu], [CPU usage statistics])
AC_PLUGIN([csv], [yes], [CSV output plugin])
@@ -3243,6 +3246,7 @@ Configuration:
ascent . . . . . . . $enable_ascent
battery . . . . . . . $enable_battery
bind . . . . . . . . $enable_bind
+ conntrack . . . . . . $enable_conntrack
cpu . . . . . . . . . $enable_cpu
cpufreq . . . . . . . $enable_cpufreq
csv . . . . . . . . . $enable_csv
diff -purN collectd-4.6.2.orig/contrib/collection3/etc/collection.conf collectd-4.6.2/contrib/collection3/etc/collection.conf
--- collectd-4.6.2.orig/contrib/collection3/etc/collection.conf 2009-03-14 18:52:59.000000000 +0100
+++ collectd-4.6.2/contrib/collection3/etc/collection.conf 2009-03-30 10:59:15.000000000 +0200
@@ -131,6 +131,13 @@ GraphWidth 400
RRDVerticalLabel "Queries/s"
RRDFormat "%6.1lf"
</Type>
+<Type conntrack>
+ DataSources conntrack
+ DSName conntrack Conntrack count
+ RRDTitle "nf_conntrack connections on {hostname}"
+ RRDVerticalLabel "Count"
+ RRDFormat "%4.0lf"
+</Type>
<Type entropy>
DataSources entropy
DSName entropy Entropy bits
diff -purN collectd-4.6.2.orig/contrib/collection.cgi collectd-4.6.2/contrib/collection.cgi
--- collectd-4.6.2.orig/contrib/collection.cgi 2009-02-18 16:00:13.000000000 +0100
+++ collectd-4.6.2/contrib/collection.cgi 2009-03-30 10:48:19.000000000 +0200
@@ -1301,6 +1301,18 @@ sub load_graph_definitions
'GPRINT:max:MAX:%4.1lf Max,',
'GPRINT:avg:LAST:%4.1lf Last\l'
],
+ conntrack => ['-v', 'Entries',
+ 'DEF:avg={file}:entropy:AVERAGE',
+ 'DEF:min={file}:entropy:MIN',
+ 'DEF:max={file}:entropy:MAX',
+ "AREA:max#$HalfBlue",
+ "AREA:min#$Canvas",
+ "LINE1:avg#$FullBlue:Count",
+ 'GPRINT:min:MIN:%4.0lf Min,',
+ 'GPRINT:avg:AVERAGE:%4.0lf Avg,',
+ 'GPRINT:max:MAX:%4.0lf Max,',
+ 'GPRINT:avg:LAST:%4.0lf Last\l'
+ ],
entropy => ['-v', 'Bits',
'DEF:avg={file}:entropy:AVERAGE',
'DEF:min={file}:entropy:MIN',
diff -purN collectd-4.6.2.orig/contrib/fedora/collectd.spec collectd-4.6.2/contrib/fedora/collectd.spec
--- collectd-4.6.2.orig/contrib/fedora/collectd.spec 2009-03-17 14:47:15.000000000 +0100
+++ collectd-4.6.2/contrib/fedora/collectd.spec 2009-03-30 10:59:49.000000000 +0200
@@ -119,6 +119,9 @@ exit 0
%attr(0644,root,root) %{_libdir}/%{name}/battery.so*
%attr(0644,root,root) %{_libdir}/%{name}/battery.la
+%attr(0644,root,root) %{_libdir}/%{name}/conntrack.so*
+%attr(0644,root,root) %{_libdir}/%{name}/conntrack.la
+
%attr(0644,root,root) %{_libdir}/%{name}/cpufreq.so*
%attr(0644,root,root) %{_libdir}/%{name}/cpufreq.la
diff -purN collectd-4.6.2.orig/contrib/php-collection/definitions.php collectd-4.6.2/contrib/php-collection/definitions.php
--- collectd-4.6.2.orig/contrib/php-collection/definitions.php 2009-03-14 18:52:59.000000000 +0100
+++ collectd-4.6.2/contrib/php-collection/definitions.php 2009-03-30 10:57:22.000000000 +0200
@@ -386,6 +386,18 @@ function load_graph_definitions($logarit
'GPRINT:avg:AVERAGE:%4.1lf Avg,',
'GPRINT:max:MAX:%4.1lf Max,',
'GPRINT:avg:LAST:%4.1lf Last\l');
+ $GraphDefs['conntrack'] = array(
+ '-v', 'Entries',
+ 'DEF:avg={file}:entropy:AVERAGE',
+ 'DEF:min={file}:entropy:MIN',
+ 'DEF:max={file}:entropy:MAX',
+ "AREA:max#$HalfBlue",
+ "AREA:min#$Canvas",
+ "LINE1:avg#$FullBlue:Count",
+ 'GPRINT:min:MIN:%4.0lf Min,',
+ 'GPRINT:avg:AVERAGE:%4.0lf Avg,',
+ 'GPRINT:max:MAX:%4.0lf Max,',
+ 'GPRINT:avg:LAST:%4.0lf Last\l');
$GraphDefs['entropy'] = array(
'-v', 'Bits',
'DEF:avg={file}:entropy:AVERAGE',
diff -purN collectd-4.6.2.orig/contrib/redhat/collectd.conf collectd-4.6.2/contrib/redhat/collectd.conf
--- collectd-4.6.2.orig/contrib/redhat/collectd.conf 2009-03-17 14:47:15.000000000 +0100
+++ collectd-4.6.2/contrib/redhat/collectd.conf 2009-03-30 11:00:05.000000000 +0200
@@ -16,6 +16,7 @@ ReadThreads 5
LoadPlugin apcups
#LoadPlugin apple_sensors
LoadPlugin battery
+LoadPlugin conntrack
LoadPlugin cpu
LoadPlugin cpufreq
LoadPlugin csv
diff -purN collectd-4.6.2.orig/contrib/redhat/collectd.spec collectd-4.6.2/contrib/redhat/collectd.spec
--- collectd-4.6.2.orig/contrib/redhat/collectd.spec 2009-03-17 14:47:15.000000000 +0100
+++ collectd-4.6.2/contrib/redhat/collectd.spec 2009-03-30 11:00:26.000000000 +0200
@@ -139,6 +139,9 @@ exit 0
%attr(0644,root,root) %{_libdir}/%{name}/battery.so*
%attr(0644,root,root) %{_libdir}/%{name}/battery.la
+%attr(0644,root,root) %{_libdir}/%{name}/conntrack.so*
+%attr(0644,root,root) %{_libdir}/%{name}/conntrack.la
+
%attr(0644,root,root) %{_libdir}/%{name}/cpufreq.so*
%attr(0644,root,root) %{_libdir}/%{name}/cpufreq.la
diff -purN collectd-4.6.2.orig/README collectd-4.6.2/README
--- collectd-4.6.2.orig/README 2009-03-18 11:55:39.000000000 +0100
+++ collectd-4.6.2/README 2009-03-30 11:01:19.000000000 +0200
@@ -40,6 +40,9 @@ Features
Name server and resolver statistics from the `statistics-channel'
interface of BIND 9.5, 9,6 and later.
+ - conntrack
+ Number of nf_conntrack entries.
+
- cpu
CPU utilization: Time spent in the system, user, nice, idle, and related
states.
diff -purN collectd-4.6.2.orig/src/collectd.conf.in collectd-4.6.2/src/collectd.conf.in
--- collectd-4.6.2.orig/src/collectd.conf.in 2009-03-18 11:55:39.000000000 +0100
+++ collectd-4.6.2/src/collectd.conf.in 2009-03-30 11:02:45.000000000 +0200
@@ -32,6 +32,7 @@ FQDNLookup true
@BUILD_PLUGIN_ASCENT_TRUE at LoadPlugin ascent
@BUILD_PLUGIN_BATTERY_TRUE at LoadPlugin battery
@BUILD_PLUGIN_BIND_TRUE at LoadPlugin bind
+ at BUILD_PLUGIN_CONNTRACK_TRUE@LoadPlugin conntrack
@BUILD_PLUGIN_CPU_TRUE at LoadPlugin cpu
@BUILD_PLUGIN_CPUFREQ_TRUE at LoadPlugin cpufreq
@BUILD_PLUGIN_CSV_TRUE at LoadPlugin csv
diff -purN collectd-4.6.2.orig/src/config.h.in collectd-4.6.2/src/config.h.in
--- collectd-4.6.2.orig/src/config.h.in 2009-03-18 12:02:23.000000000 +0100
+++ collectd-4.6.2/src/config.h.in 2009-03-30 11:04:37.000000000 +0200
@@ -450,6 +450,9 @@
/* Define to 1 if the bind plugin is enabled. */
#undef HAVE_PLUGIN_BIND
+/* Define to 1 if the conntrack plugin is enabled. */
+#undef HAVE_PLUGIN_CONNTRACK
+
/* Define to 1 if the cpu plugin is enabled. */
#undef HAVE_PLUGIN_CPU
diff -purN collectd-4.6.2.orig/src/conntrack.c collectd-4.6.2/src/conntrack.c
--- collectd-4.6.2.orig/src/conntrack.c 1970-01-01 01:00:00.000000000 +0100
+++ collectd-4.6.2/src/conntrack.c 2009-03-30 10:55:24.000000000 +0200
@@ -0,0 +1,78 @@
+/**
+ * collectd - src/conntrack.c
+ * Copyright (C) 2009 Tomasz Pala
+ *
+ * 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
+ * Free Software Foundation; only version 2 of the License is applicable.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Tomasz Pala <gotar at pld-linux.org>
+ * based on entropy.c by:
+ * Florian octo Forster <octo at verplant.org>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+#if !KERNEL_LINUX
+# error "No applicable input method."
+#endif
+
+#define CONNTRACK_FILE "/proc/sys/net/netfilter/nf_conntrack_count"
+
+static void conntrack_submit (double conntrack)
+{
+ value_t values[1];
+ value_list_t vl = VALUE_LIST_INIT;
+
+ values[0].gauge = conntrack;
+
+ vl.values = values;
+ vl.values_len = 1;
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+ sstrncpy (vl.plugin, "conntrack", sizeof (vl.plugin));
+ sstrncpy (vl.type, "conntrack", sizeof (vl.type));
+
+ plugin_dispatch_values (&vl);
+} /* static void conntrack_submit */
+
+static int conntrack_read (void)
+{
+ double conntrack;
+ FILE *fh;
+ char buffer[64];
+
+ fh = fopen (CONNTRACK_FILE, "r");
+ if (fh == NULL)
+ return (-1);
+
+ if (fgets (buffer, sizeof (buffer), fh) == NULL)
+ {
+ fclose (fh);
+ return (-1);
+ }
+ fclose (fh);
+
+ conntrack = atof (buffer);
+
+ if (conntrack > 0.0)
+ conntrack_submit (conntrack);
+
+ return (0);
+} /* static int conntrack_read */
+
+void module_register (void)
+{
+ plugin_register_read ("conntrack", conntrack_read);
+} /* void module_register */
diff -purN collectd-4.6.2.orig/src/Makefile.am collectd-4.6.2/src/Makefile.am
--- collectd-4.6.2.orig/src/Makefile.am 2009-03-18 11:55:39.000000000 +0100
+++ collectd-4.6.2/src/Makefile.am 2009-03-30 11:02:15.000000000 +0200
@@ -165,6 +165,14 @@ collectd_LDADD += "-dlopen" bind.la
collectd_DEPENDENCIES += bind.la
endif
+if BUILD_PLUGIN_CONNTRACK
+pkglib_LTLIBRARIES += conntrack.la
+conntrack_la_SOURCES = conntrack.c
+conntrack_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" conntrack.la
+collectd_DEPENDENCIES += conntrack.la
+endif
+
if BUILD_PLUGIN_CPU
pkglib_LTLIBRARIES += cpu.la
cpu_la_SOURCES = cpu.c
diff -purN collectd-4.6.2.orig/src/types.db collectd-4.6.2/src/types.db
--- collectd-4.6.2.orig/src/types.db 2009-03-18 11:55:39.000000000 +0100
+++ collectd-4.6.2/src/types.db 2009-03-30 10:43:30.000000000 +0200
@@ -9,6 +9,7 @@ cache_size value:GAUGE:0:4294967295
charge value:GAUGE:0:U
compression_ratio value:GAUGE:0:2
connections value:COUNTER:0:U
+conntrack entropy:GAUGE:0:4294967295
counter value:COUNTER:U:U
cpufreq value:GAUGE:0:U
cpu value:COUNTER:0:4294967295
diff -purN collectd-4.6.2.orig/AUTHORS collectd-4.6.2/AUTHORS
--- collectd-4.6.2.orig/AUTHORS 2009-03-17 14:47:15.000000000 +0100
+++ collectd-4.6.2/AUTHORS 2009-03-30 11:09:55.000000000 +0200
@@ -116,6 +116,9 @@ Sjoerd van der Berg <harekiet at gmail.c
Stefan Hacker <stefan.hacker at web.de>
- teamspeak2 plugin.
+Tomasz Pala <gotar at pld-linux.org>
+ - conntrack plugin.
+
Tommie Gannert <d00-tga at d.kth.se>
- PID-file patch.
More information about the collectd
mailing list