From e975b173f612fee4fbc04a7ffb270a6f064a8cf5 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Ritschard Date: Tue, 29 Jul 2014 11:10:45 +0200 Subject: [PATCH] Support older conntrack files with an option supersedes collectd/collectd#605 --- src/collectd.conf.pod | 13 +++++++++++++ src/conntrack.c | 27 +++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 32ed9903..8b9157d9 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -989,6 +989,19 @@ at all, B cgroups are selected. =back +=head2 Plugin C + +This plugin collects IP conntrack statistics. + +=over 4 + +=item B + +Assume the B and B files to be found in +F instead of F. + +=back + =head2 Plugin C The I collects CPU usage metrics. diff --git a/src/conntrack.c b/src/conntrack.c index e7bccad3..b8f8dfd8 100644 --- a/src/conntrack.c +++ b/src/conntrack.c @@ -31,6 +31,27 @@ #define CONNTRACK_FILE "/proc/sys/net/netfilter/nf_conntrack_count" #define CONNTRACK_MAX_FILE "/proc/sys/net/netfilter/nf_conntrack_max" +#define CONNTRACK_FILE_OLD "/proc/sys/net/ipv4/netfilter/ip_conntrack_count" +#define CONNTRACK_MAX_FILE_OLD "/proc/sys/net/ipv4/netfilter/ip_conntrack_max" + +static const char *config_keys[] = +{ + "OldFiles" +}; +static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); +/* + Each table/chain combo that will be queried goes into this list +*/ + +static int old_files = 0; + +static int conntrack_config(const char *key, const char *value) +{ + if (strcmp(key, "OldFiles") == 0) + old_files = 1; + + return 0; +} static void conntrack_submit (const char *type, const char *type_instance, value_t conntrack) @@ -56,7 +77,7 @@ static int conntrack_read (void) char buffer[64]; size_t buffer_len; - fh = fopen (CONNTRACK_FILE, "r"); + fh = fopen (old_files?CONNTRACK_FILE_OLD:CONNTRACK_FILE, "r"); if (fh == NULL) return (-1); @@ -81,7 +102,7 @@ static int conntrack_read (void) conntrack_submit ("conntrack", NULL, conntrack); - fh = fopen (CONNTRACK_MAX_FILE, "r"); + fh = fopen (old_files?CONNTRACK_MAX_FILE_OLD:CONNTRACK_MAX_FILE, "r"); if (fh == NULL) return (-1); @@ -114,5 +135,7 @@ static int conntrack_read (void) void module_register (void) { + plugin_register_config ("conntrack", conntrack_config, + config_keys, config_keys_num); plugin_register_read ("conntrack", conntrack_read); } /* void module_register */ -- 2.30.2