From f47fafadba730f0758e1718a103a970dd45dc5c5 Mon Sep 17 00:00:00 2001 From: Fabian Schuh Date: Fri, 19 Mar 2010 10:07:50 +0100 Subject: [PATCH] Name changes - removed transfer statistics (doesn't make sense here) --- src/openvpn.c | 157 ++++++++++++++++++++------------------------------ 1 file changed, 64 insertions(+), 93 deletions(-) diff --git a/src/openvpn.c b/src/openvpn.c index 359410b8..b03ae964 100644 --- a/src/openvpn.c +++ b/src/openvpn.c @@ -52,14 +52,14 @@ static int vpn_num = 0; static int store_compression = 1; static int new_naming_schema = 0; -static int sumover_allusers = 0; +static int number_connectedusers = 0; static const char *config_keys[] = { "StatusFile", "Compression", "ImprovedNamingSchema", - "SumOverAllUsers" + "AggregateUsers" }; static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); @@ -88,7 +88,7 @@ static int openvpn_strsplit (char *string, char **fields, size_t size) } /* int openvpn_strsplit */ /* dispatches number of users */ -static void sumusers_submit (char *pinst, char *tinst, gauge_t value) +static void numusers_submit (char *pinst, char *tinst, gauge_t value) { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; @@ -106,7 +106,7 @@ static void sumusers_submit (char *pinst, char *tinst, gauge_t value) sstrncpy (vl.type_instance, tinst, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); -} /* void sumusers_submit */ +} /* void numusers_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) @@ -261,8 +261,6 @@ static int multi1_read (char *name, FILE *fh) char buffer[1024]; char *fields[10]; 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) */ @@ -287,42 +285,34 @@ static int multi1_read (char *name, FILE *fh) if (fields_num < 4) continue; - if (sumover_allusers) - /* If so, sum over all users, ignore the individuals*/ + if (number_connectedusers) + /* If so, sum all users, ignore the individuals*/ { sum_users += 1; - sum_rx += atoll(fields[2]); - sum_tx += atoll(fields[3]); + } + + if (new_naming_schema) + { + iostats_submit (fields[0], /* "Common Name" */ + NULL, /* unused when in multimode */ + atoll (fields[2]), /* "Bytes Received" */ + atoll (fields[3])); /* "Bytes Sent" */ } else { - if (new_naming_schema) - { - iostats_submit (fields[0], /* "Common Name" */ - NULL, /* unused when in multimode */ - atoll (fields[2]), /* "Bytes Received" */ - atoll (fields[3])); /* "Bytes Sent" */ - } - else - { - iostats_submit (name, /* vpn instance */ - fields[0], /* "Common Name" */ - atoll (fields[2]), /* "Bytes Received" */ - atoll (fields[3])); /* "Bytes Sent" */ - } + iostats_submit (name, /* vpn instance */ + fields[0], /* "Common Name" */ + atoll (fields[2]), /* "Bytes Received" */ + atoll (fields[3])); /* "Bytes Sent" */ } read = 1; } - if (sumover_allusers) + if (number_connectedusers && read == 1) { - iostats_submit (name, /* vpn instance */ - "OverAllTraffic", /* "Common Name" */ - sum_rx, /* "Bytes Received" */ - sum_tx); /* "Bytes Sent" */ - sumusers_submit(name, name, sum_users); - } + numusers_submit(name, name, sum_users); + } return (read); } /* int multi1_read */ @@ -334,9 +324,7 @@ static int multi2_read (char *name, FILE *fh) char *fields[10]; const int max_fields = STATIC_ARRAY_SIZE (fields); int fields_num, read = 0; - long long sum_rx = 0; - long long sum_tx = 0; - long long sum_users = 1; + long long sum_users = 0; while (fgets (buffer, sizeof (buffer), fh) != NULL) { @@ -354,42 +342,35 @@ static int multi2_read (char *name, FILE *fh) if (strcmp (fields[0], "CLIENT_LIST") != 0) continue; - if (sumover_allusers) - /* If so, sum over all users, ignore the individuals*/ + if (number_connectedusers) + /* If so, sum all users, ignore the individuals*/ { sum_users += 1; - sum_rx += atoll(fields[2]); - sum_tx += atoll(fields[3]); + } + + if (new_naming_schema) + { + /* plugin inst = file name, type inst = fields[1] */ + iostats_submit (name, /* vpn instance */ + fields[1], /* "Common Name" */ + atoll (fields[4]), /* "Bytes Received" */ + atoll (fields[5])); /* "Bytes Sent" */ } else { - if (new_naming_schema) - { - /* plugin inst = file name, type inst = fields[1] */ - iostats_submit (name, /* vpn instance */ - fields[1], /* "Common Name" */ - atoll (fields[4]), /* "Bytes Received" */ - atoll (fields[5])); /* "Bytes Sent" */ - } - else - { - /* plugin inst = fields[1], type inst = "" */ - iostats_submit (fields[1], /* "Common Name" */ - NULL, /* unused when in multimode */ - atoll (fields[4]), /* "Bytes Received" */ - atoll (fields[5])); /* "Bytes Sent" */ - } + /* plugin inst = fields[1], type inst = "" */ + iostats_submit (fields[1], /* "Common Name" */ + NULL, /* unused when in multimode */ + atoll (fields[4]), /* "Bytes Received" */ + atoll (fields[5])); /* "Bytes Sent" */ } + read = 1; } - if (sumover_allusers) + if (number_connectedusers && read == 1) { - iostats_submit (name, /* vpn instance */ - "OverAllTraffic", /* "Common Name" */ - sum_rx, /* "Bytes Received" */ - sum_tx); /* "Bytes Sent" */ - sumusers_submit(name, name, sum_users); + numusers_submit(name, name, sum_users); } return (read); @@ -402,8 +383,6 @@ static int multi3_read (char *name, FILE *fh) char *fields[15]; const int max_fields = STATIC_ARRAY_SIZE (fields); 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) @@ -425,43 +404,35 @@ static int multi3_read (char *name, FILE *fh) if (strcmp (fields[0], "CLIENT_LIST") != 0) continue; - if (sumover_allusers) - /* If so, sum over all users, ignore the individuals*/ + if (number_connectedusers) + /* If so, sum all users, ignore the individuals*/ { sum_users += 1; - sum_rx += atoll(fields[2]); - sum_tx += atoll(fields[3]); + } + + if (new_naming_schema) + { + iostats_submit (name, /* vpn instance */ + fields[1], /* "Common Name" */ + atoll (fields[4]), /* "Bytes Received" */ + atoll (fields[5])); /* "Bytes Sent" */ } else { - if (new_naming_schema) - { - iostats_submit (name, /* vpn instance */ - fields[1], /* "Common Name" */ - atoll (fields[4]), /* "Bytes Received" */ - atoll (fields[5])); /* "Bytes Sent" */ - } - else - { - iostats_submit (fields[1], /* "Common Name" */ - NULL, /* unused when in multimode */ - atoll (fields[4]), /* "Bytes Received" */ - atoll (fields[5])); /* "Bytes Sent" */ - } + iostats_submit (fields[1], /* "Common Name" */ + NULL, /* unused when in multimode */ + atoll (fields[4]), /* "Bytes Received" */ + atoll (fields[5])); /* "Bytes Sent" */ } - read = 1; + read = 1; } } - if (sumover_allusers) + if (number_connectedusers && read == 1) { - iostats_submit (name, /* vpn instance */ - "OverAllTraffic", /* "Common Name" */ - sum_rx, /* "Bytes Received" */ - sum_tx); /* "Bytes Sent" */ - sumusers_submit(name, name, sum_users); - } + numusers_submit(name, name, sum_users); + } return (read); } /* int multi3_read */ @@ -679,18 +650,18 @@ static int openvpn_config (const char *key, const char *value) new_naming_schema = 0; } } /* if (strcasecmp ("ImprovedNamingSchema", key) == 0) */ - else if (strcasecmp("SumOverAllUsers", key) == 0) + else if (strcasecmp("AggregateUsers", key) == 0) { if (IS_TRUE(value)) { - DEBUG ("openvpn plugin: Summing up over all users"); - sumover_allusers = 1; + DEBUG ("openvpn plugin: Summing up all users"); + number_connectedusers = 1; } else { - sumover_allusers = 1; + number_connectedusers = 0; } - } /* if (strcasecmp("SumOverAllUsers", key) == 0) */ + } /* if (strcasecmp("AggregateUsers", key) == 0) */ else { return (-1); -- 2.30.2