From 2239c03fe46755183c756e81ac19cd416a8f0184 Mon Sep 17 00:00:00 2001 From: Tomasz Pala Date: Tue, 31 Mar 2009 10:31:29 +0200 Subject: [PATCH] conntrack plugin: Add plugin to collect the connection tracking table size. 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 --- AUTHORS | 3 ++ README | 3 ++ configure.in | 4 ++ contrib/collection.cgi | 12 +++++ contrib/collection3/etc/collection.conf | 7 +++ contrib/fedora/collectd.spec | 3 ++ contrib/php-collection/definitions.php | 12 +++++ contrib/redhat/collectd.conf | 1 + contrib/redhat/collectd.spec | 3 ++ src/Makefile.am | 8 ++++ src/collectd.conf.in | 1 + src/conntrack.c | 78 +++++++++++++++++++++++++++++++++ src/types.db | 1 + 13 files changed, 136 insertions(+) create mode 100644 src/conntrack.c diff --git a/AUTHORS b/AUTHORS index ff879c4d..2c8c94bb 100644 --- a/AUTHORS +++ b/AUTHORS @@ -119,6 +119,9 @@ Sjoerd van der Berg Stefan Hacker - teamspeak2 plugin. +Tomasz Pala + - conntrack plugin. + Tommie Gannert - PID-file patch. diff --git a/README b/README index c556c750..755704d9 100644 --- a/README +++ b/README @@ -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 --git a/configure.in b/configure.in index f0c43121..591de4ff 100644 --- a/configure.in +++ b/configure.in @@ -3152,6 +3152,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" @@ -3185,6 +3186,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" @@ -3367,6 +3369,7 @@ AC_PLUGIN([apple_sensors], [$with_libiokit], [Apple's hardware sensors]) 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]) @@ -3648,6 +3651,7 @@ Configuration: ascent . . . . . . . $enable_ascent battery . . . . . . . $enable_battery bind . . . . . . . . $enable_bind + conntrack . . . . . . $enable_conntrack cpu . . . . . . . . . $enable_cpu cpufreq . . . . . . . $enable_cpufreq csv . . . . . . . . . $enable_csv diff --git a/contrib/collection.cgi b/contrib/collection.cgi index d3a284f8..eeda241d 100755 --- a/contrib/collection.cgi +++ b/contrib/collection.cgi @@ -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 --git a/contrib/collection3/etc/collection.conf b/contrib/collection3/etc/collection.conf index 2511221f..492bfa27 100644 --- a/contrib/collection3/etc/collection.conf +++ b/contrib/collection3/etc/collection.conf @@ -131,6 +131,13 @@ GraphWidth 400 RRDVerticalLabel "Queries/s" RRDFormat "%6.1lf" + + DataSources conntrack + DSName conntrack Conntrack count + RRDTitle "nf_conntrack connections on {hostname}" + RRDVerticalLabel "Count" + RRDFormat "%4.0lf" + DataSources entropy DSName entropy Entropy bits diff --git a/contrib/fedora/collectd.spec b/contrib/fedora/collectd.spec index 35eb8bec..a35923c0 100644 --- a/contrib/fedora/collectd.spec +++ b/contrib/fedora/collectd.spec @@ -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 --git a/contrib/php-collection/definitions.php b/contrib/php-collection/definitions.php index cb3e803e..a0f38180 100644 --- a/contrib/php-collection/definitions.php +++ b/contrib/php-collection/definitions.php @@ -386,6 +386,18 @@ function load_graph_definitions($logarithmic = false, $tinylegend = false) { '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 --git a/contrib/redhat/collectd.conf b/contrib/redhat/collectd.conf index 0aaaee31..f8352ffa 100644 --- a/contrib/redhat/collectd.conf +++ b/contrib/redhat/collectd.conf @@ -16,6 +16,7 @@ ReadThreads 5 LoadPlugin apcups #LoadPlugin apple_sensors LoadPlugin battery +LoadPlugin conntrack LoadPlugin cpu LoadPlugin cpufreq LoadPlugin csv diff --git a/contrib/redhat/collectd.spec b/contrib/redhat/collectd.spec index 62acc184..012fc480 100644 --- a/contrib/redhat/collectd.spec +++ b/contrib/redhat/collectd.spec @@ -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 --git a/src/Makefile.am b/src/Makefile.am index 9b85144f..8f94b01a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -166,6 +166,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 --git a/src/collectd.conf.in b/src/collectd.conf.in index 6783a15c..92df4a7b 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -56,6 +56,7 @@ FQDNLookup true #@BUILD_PLUGIN_ASCENT_TRUE@LoadPlugin ascent #@BUILD_PLUGIN_BATTERY_TRUE@LoadPlugin battery #@BUILD_PLUGIN_BIND_TRUE@LoadPlugin bind +#@BUILD_PLUGIN_CONNTRACK_TRUE@LoadPlugin conntrack @BUILD_PLUGIN_CPU_TRUE@@BUILD_PLUGIN_CPU_TRUE@LoadPlugin cpu #@BUILD_PLUGIN_CPUFREQ_TRUE@LoadPlugin cpufreq @LOAD_PLUGIN_CSV@LoadPlugin csv diff --git a/src/conntrack.c b/src/conntrack.c new file mode 100644 index 00000000..e70ff5f1 --- /dev/null +++ b/src/conntrack.c @@ -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 + * based on entropy.c by: + * Florian octo Forster + **/ + +#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 --git a/src/types.db b/src/types.db index b38c207a..e07329c2 100644 --- a/src/types.db +++ b/src/types.db @@ -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 -- 2.11.0