summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3c7af52)
raw | patch | inline | side by side (parent: 3c7af52)
author | Pierre-Yves Ritschard <pyr@spootnik.org> | |
Wed, 15 Jan 2014 13:10:13 +0000 (14:10 +0100) | ||
committer | Pierre-Yves Ritschard <pyr@spootnik.org> | |
Wed, 15 Jan 2014 13:10:13 +0000 (14:10 +0100) |
src/conntrack.c | patch | blob | history |
diff --git a/src/conntrack.c b/src/conntrack.c
index 33236c45975c4d9c5c519e4defbfcd029c0b0821..52cc876f5be488f27cded22e193d3c5deca04cb6 100644 (file)
--- a/src/conntrack.c
+++ b/src/conntrack.c
#endif
#define CONNTRACK_FILE "/proc/sys/net/netfilter/nf_conntrack_count"
+#define CONNTRACK_MAX_FILE "/proc/sys/net/netfilter/nf_conntrack_max"
-static void conntrack_submit (value_t conntrack)
+static void conntrack_submit (const char *type_instance,
+ const char *type, value_t conntrack)
{
value_list_t vl = VALUE_LIST_INIT;
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "conntrack", sizeof (vl.plugin));
sstrncpy (vl.type, "conntrack", sizeof (vl.type));
+ if (type_instance != NULL)
+ sstrncpy (vl.type_instance, type_instance,
+ sizeof (vl.type_instance));
plugin_dispatch_values (&vl);
} /* static void conntrack_submit */
static int conntrack_read (void)
{
- value_t conntrack;
+ value_t conntrack, conntrack_max, conntrack_pct;
FILE *fh;
char buffer[64];
size_t buffer_len;
if (parse_value (buffer, &conntrack, DS_TYPE_GAUGE) != 0)
return (-1);
- conntrack_submit (conntrack);
+ conntrack_submit (NULL, "conntrack", conntrack);
+
+ fh = fopen (CONNTRACK_MAX_FILE, "r");
+ if (fh == NULL)
+ return (-1);
+
+ memset (buffer, 0, sizeof (buffer));
+ if (fgets (buffer, sizeof (buffer), fh) == NULL)
+ {
+ fclose (fh);
+ return (-1);
+ }
+ fclose (fh);
+
+ /* strip trailing newline. */
+ buffer_len = strlen (buffer);
+ while ((buffer_len > 0) && isspace ((int) buffer[buffer_len - 1]))
+ {
+ buffer[buffer_len - 1] = 0;
+ buffer_len--;
+ }
+
+ if (parse_value (buffer, &conntrack_max, DS_TYPE_GAUGE) != 0)
+ return (-1);
+
+ conntrack_submit ("max", "conntrack", conntrack_max);
+
+ conntrack_pct.gauge = (conntrack.gauge / conntrack_max.gauge) * 100;
+ conntrack_submit ("percent", "percent", conntrack_pct);
+
return (0);
} /* static int conntrack_read */