2 * collectd - src/conntrack.c
3 * Copyright (C) 2009 Tomasz Pala
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Tomasz Pala <gotar at pld-linux.org>
20 * based on entropy.c by:
21 * Florian octo Forster <octo at verplant.org>
29 # error "No applicable input method."
32 #define CONNTRACK_FILE "/proc/sys/net/netfilter/nf_conntrack_count"
34 static void conntrack_submit (value_t conntrack)
36 value_list_t vl = VALUE_LIST_INIT;
38 vl.values = &conntrack;
40 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
41 sstrncpy (vl.plugin, "conntrack", sizeof (vl.plugin));
42 sstrncpy (vl.type, "conntrack", sizeof (vl.type));
44 plugin_dispatch_values (&vl);
45 } /* static void conntrack_submit */
47 static int conntrack_read (void)
54 fh = fopen (CONNTRACK_FILE, "r");
58 memset (buffer, 0, sizeof (buffer));
59 if (fgets (buffer, sizeof (buffer), fh) == NULL)
66 /* strip trailing newline. */
67 buffer_len = strlen (buffer);
68 while ((buffer_len > 0) && isspace ((int) buffer[buffer_len - 1]))
70 buffer[buffer_len - 1] = 0;
74 if (parse_value (buffer, &conntrack, DS_TYPE_GAUGE) != 0)
77 conntrack_submit (conntrack);
80 } /* static int conntrack_read */
82 void module_register (void)
84 plugin_register_read ("conntrack", conntrack_read);
85 } /* void module_register */