From 5d64da91085252c12fcfa4d28abc1ba50dc08bba Mon Sep 17 00:00:00 2001 From: Fabian Schuh Date: Thu, 18 Mar 2010 10:50:15 +0100 Subject: [PATCH] [openvpn] new feature 'SumOverAllUsers' --- src/openvpn.c | 128 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 97 insertions(+), 31 deletions(-) diff --git a/src/openvpn.c b/src/openvpn.c index 1ac50830..a2745376 100644 --- a/src/openvpn.c +++ b/src/openvpn.c @@ -52,12 +52,16 @@ static int vpn_num = 0; static int store_compression = 1; static int new_naming_schema = 0; +static int sumover_allusers = 0; +static long long sum_rx = 0; +static long long sum_tx = 0; static const char *config_keys[] = { "StatusFile", "Compression", - "ImprovedNamingSchema" + "ImprovedNamingSchema", + "SumOverAllUsers" }; static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); @@ -261,24 +265,41 @@ static int multi1_read (char *name, FILE *fh) if (fields_num < 4) continue; - if (new_naming_schema) + if (sumover_allusers) + /* If so, sum over all users, ignore the individuals*/ { - iostats_submit (fields[0], /* "Common Name" */ - NULL, /* unused when in multimode */ - atoll (fields[2]), /* "Bytes Received" */ - atoll (fields[3])); /* "Bytes Sent" */ + sum_rx += atoll(fields[2]); + sum_tx += atoll(fields[3]); } else { - iostats_submit (name, /* vpn instance */ - fields[0], /* "Common Name" */ - atoll (fields[2]), /* "Bytes Received" */ - atoll (fields[3])); /* "Bytes Sent" */ + 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" */ + } } read = 1; } + if (sumover_allusers) + { + iostats_submit (name, /* vpn instance */ + "OverAllTraffic", /* "Common Name" */ + sum_rx, /* "Bytes Received" */ + sum_rx); /* "Bytes Sent" */ + } + return (read); } /* int multi1_read */ @@ -306,26 +327,42 @@ static int multi2_read (char *name, FILE *fh) if (strcmp (fields[0], "CLIENT_LIST") != 0) continue; - if (new_naming_schema) + if (sumover_allusers) + /* If so, sum over all users, ignore the individuals*/ { - /* 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" */ + sum_rx += atoll(fields[2]); + sum_tx += atoll(fields[3]); } 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" */ + 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" */ + } } - read = 1; } + if (sumover_allusers) + { + iostats_submit (name, /* vpn instance */ + "OverAllTraffic", /* "Common Name" */ + sum_rx, /* "Bytes Received" */ + sum_rx); /* "Bytes Sent" */ + } + return (read); } /* int multi2_read */ @@ -356,25 +393,42 @@ static int multi3_read (char *name, FILE *fh) if (strcmp (fields[0], "CLIENT_LIST") != 0) continue; - if (new_naming_schema) + if (sumover_allusers) + /* If so, sum over all users, ignore the individuals*/ { - iostats_submit (name, /* vpn instance */ - fields[1], /* "Common Name" */ - atoll (fields[4]), /* "Bytes Received" */ - atoll (fields[5])); /* "Bytes Sent" */ + sum_rx += atoll(fields[2]); + sum_tx += atoll(fields[3]); } else { - iostats_submit (fields[1], /* "Common Name" */ - NULL, /* unused when in multimode */ - atoll (fields[4]), /* "Bytes Received" */ - atoll (fields[5])); /* "Bytes Sent" */ + 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" */ + } } read = 1; } } + if (sumover_allusers) + { + iostats_submit (name, /* vpn instance */ + "OverAllTraffic", /* "Common Name" */ + sum_rx, /* "Bytes Received" */ + sum_rx); /* "Bytes Sent" */ + } + return (read); } /* int multi3_read */ @@ -591,6 +645,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) + { + if (IS_TRUE(value)) + { + DEBUG ("openvpn plugin: Summing up over all users"); + sumover_allusers = 1; + } + else + { + sumover_allusers = 1; + } + } /* if (strcasecmp("SumOverAllUsers", key) == 0) */ else { return (-1); -- 2.11.0