summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b9864f6)
raw | patch | inline | side by side (parent: b9864f6)
author | Florian Forster <octo@collectd.org> | |
Mon, 12 Sep 2016 06:47:16 +0000 (08:47 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Mon, 12 Sep 2016 07:28:42 +0000 (09:28 +0200) |
src/conntrack.c | patch | blob | history |
diff --git a/src/conntrack.c b/src/conntrack.c
index ce90ede34749e5e30b4014e99193539119f5ea68..4a72b2f61dc91d2b1eab973363139f65d03e6412 100644 (file)
--- a/src/conntrack.c
+++ b/src/conntrack.c
static int conntrack_read (void)
{
value_t conntrack, conntrack_max, conntrack_pct;
- FILE *fh;
- char buffer[64] = { 0 };
- size_t buffer_len;
- fh = fopen (old_files?CONNTRACK_FILE_OLD:CONNTRACK_FILE, "r");
- if (fh == NULL)
- return (-1);
-
- if (fgets (buffer, sizeof (buffer), fh) == NULL)
+ char const *path = old_files ? CONNTRACK_FILE_OLD : CONNTRACK_FILE;
+ if (parse_value_file (path, &conntrack, DS_TYPE_GAUGE) != 0)
{
- fclose (fh);
+ ERROR ("conntrack plugin: Reading \"%s\" failed.", path);
return (-1);
}
- fclose (fh);
- /* strip trailing newline. */
- buffer_len = strlen (buffer);
- while ((buffer_len > 0) && isspace ((int) buffer[buffer_len - 1]))
+ path = old_files ? CONNTRACK_MAX_FILE_OLD : CONNTRACK_MAX_FILE;
+ if (parse_value_file (path, &conntrack_max, DS_TYPE_GAUGE) != 0)
{
- buffer[buffer_len - 1] = 0;
- buffer_len--;
- }
-
- if (parse_value (buffer, &conntrack, DS_TYPE_GAUGE) != 0)
- return (-1);
-
- conntrack_submit ("conntrack", NULL, conntrack);
-
- fh = fopen (old_files?CONNTRACK_MAX_FILE_OLD:CONNTRACK_MAX_FILE, "r");
- if (fh == NULL)
- return (-1);
-
- memset (buffer, 0, sizeof (buffer));
- if (fgets (buffer, sizeof (buffer), fh) == NULL)
- {
- fclose (fh);
+ ERROR ("conntrack plugin: Reading \"%s\" failed.", path);
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 ("conntrack", "max", conntrack_max);
conntrack_pct.gauge = (conntrack.gauge / conntrack_max.gauge) * 100;
- conntrack_submit ("percent", "used", conntrack_pct);
+ conntrack_submit ("conntrack", NULL, conntrack);
+ conntrack_submit ("conntrack", "max", conntrack_max);
+ conntrack_submit ("percent", "used", conntrack_pct);
return (0);
} /* static int conntrack_read */