Code

Added Users Counter
authorFabian Schuh <mail@xeroc.org>
Thu, 18 Mar 2010 13:41:34 +0000 (14:41 +0100)
committerFabian Schuh <mail@xeroc.org>
Thu, 18 Mar 2010 13:41:34 +0000 (14:41 +0100)
src/openvpn.c

index 81c5343d171af7e3bf1b8295a224844af1b251c9..359410b8413aba190aa6479085a089c135e41e5d 100644 (file)
@@ -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);