From 94a30ecc5a2e50301ddb2bdc3b1c4f52b168840e Mon Sep 17 00:00:00 2001 From: Fabian Schuh Date: Thu, 18 Mar 2010 14:41:34 +0100 Subject: [PATCH] Added Users Counter --- src/openvpn.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/openvpn.c b/src/openvpn.c index 81c5343d..359410b8 100644 --- a/src/openvpn.c +++ b/src/openvpn.c @@ -87,6 +87,27 @@ static int openvpn_strsplit (char *string, char **fields, size_t size) return (i); } /* int openvpn_strsplit */ +/* dispatches number of users */ +static void sumusers_submit (char *pinst, char *tinst, gauge_t value) +{ + value_t values[1]; + value_list_t vl = VALUE_LIST_INIT; + + values[0].gauge = value; + + vl.values = values; + vl.values_len = STATIC_ARRAY_SIZE (values); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "openvpn", sizeof (vl.plugin)); + sstrncpy (vl.type, "users", sizeof (vl.type)); + if (pinst != NULL) + sstrncpy (vl.plugin_instance, pinst, sizeof (vl.plugin_instance)); + if (tinst != NULL) + sstrncpy (vl.type_instance, tinst, sizeof (vl.type_instance)); + + plugin_dispatch_values (&vl); +} /* void sumusers_submit */ + /* dispatches stats about traffic (TCP or UDP) generated by the tunnel per single endpoint */ static void iostats_submit (char *pinst, char *tinst, counter_t rx, counter_t tx) { @@ -242,6 +263,7 @@ static int multi1_read (char *name, FILE *fh) int fields_num, read = 0, found_header = 0; long long sum_rx = 0; long long sum_tx = 0; + long long sum_users = 0; /* read the file until the "ROUTING TABLE" line is found (no more info after) */ while (fgets (buffer, sizeof (buffer), fh) != NULL) @@ -268,6 +290,7 @@ static int multi1_read (char *name, FILE *fh) if (sumover_allusers) /* If so, sum over all users, ignore the individuals*/ { + sum_users += 1; sum_rx += atoll(fields[2]); sum_tx += atoll(fields[3]); } @@ -298,6 +321,7 @@ static int multi1_read (char *name, FILE *fh) "OverAllTraffic", /* "Common Name" */ sum_rx, /* "Bytes Received" */ sum_tx); /* "Bytes Sent" */ + sumusers_submit(name, name, sum_users); } return (read); @@ -312,6 +336,7 @@ static int multi2_read (char *name, FILE *fh) int fields_num, read = 0; long long sum_rx = 0; long long sum_tx = 0; + long long sum_users = 1; while (fgets (buffer, sizeof (buffer), fh) != NULL) { @@ -332,6 +357,7 @@ static int multi2_read (char *name, FILE *fh) if (sumover_allusers) /* If so, sum over all users, ignore the individuals*/ { + sum_users += 1; sum_rx += atoll(fields[2]); sum_tx += atoll(fields[3]); } @@ -362,7 +388,8 @@ static int multi2_read (char *name, FILE *fh) iostats_submit (name, /* vpn instance */ "OverAllTraffic", /* "Common Name" */ sum_rx, /* "Bytes Received" */ - sum_rx); /* "Bytes Sent" */ + sum_tx); /* "Bytes Sent" */ + sumusers_submit(name, name, sum_users); } return (read); @@ -377,6 +404,7 @@ static int multi3_read (char *name, FILE *fh) int fields_num, read = 0; long long sum_rx = 0; long long sum_tx = 0; + long long sum_users = 0; while (fgets (buffer, sizeof (buffer), fh) != NULL) { @@ -400,6 +428,7 @@ static int multi3_read (char *name, FILE *fh) if (sumover_allusers) /* If so, sum over all users, ignore the individuals*/ { + sum_users += 1; sum_rx += atoll(fields[2]); sum_tx += atoll(fields[3]); } @@ -430,7 +459,8 @@ static int multi3_read (char *name, FILE *fh) iostats_submit (name, /* vpn instance */ "OverAllTraffic", /* "Common Name" */ sum_rx, /* "Bytes Received" */ - sum_rx); /* "Bytes Sent" */ + sum_tx); /* "Bytes Sent" */ + sumusers_submit(name, name, sum_users); } return (read); -- 2.11.0