+ if (strcmp (fields[0], "TUN/TAP read bytes") == 0)
+ {
+ /* read from the system and sent over the tunnel */
+ tun_tx = atoll (fields[1]);
+ }
+ else if (strcmp (fields[0], "TUN/TAP write bytes") == 0)
+ {
+ /* read from the tunnel and written in the system */
+ tun_rx = atoll (fields[1]);
+ }
+ else if (strcmp (fields[0], "TCP/UDP read bytes") == 0)
+ {
+ link_rx = atoll (fields[1]);
+ }
+ else if (strcmp (fields[0], "TCP/UDP write bytes") == 0)
+ {
+ link_tx = atoll (fields[1]);
+ }
+ else if (strcmp (fields[0], "pre-compress bytes") == 0)
+ {
+ pre_compress = atoll (fields[1]);
+ }
+ else if (strcmp (fields[0], "post-compress bytes") == 0)
+ {
+ post_compress = atoll (fields[1]);
+ }
+ else if (strcmp (fields[0], "pre-decompress bytes") == 0)
+ {
+ pre_decompress = atoll (fields[1]);
+ }
+ else if (strcmp (fields[0], "post-decompress bytes") == 0)
+ {
+ post_decompress = atoll (fields[1]);
+ }
+ }
+
+ iostats_submit (name, "traffic", link_rx, link_tx);
+
+ /* we need to force this order to avoid negative values with these unsigned */
+ overhead_rx = (((link_rx - pre_decompress) + post_decompress) - tun_rx);
+ overhead_tx = (((link_tx - post_compress) + pre_compress) - tun_tx);
+
+ iostats_submit (name, "overhead", overhead_rx, overhead_tx);
+
+ if (collect_compression)
+ {
+ compression_submit (name, "data_in", post_decompress, pre_decompress);
+ compression_submit (name, "data_out", pre_compress, post_compress);
+ }
+
+ read = 1;
+
+ return (read);
+} /* int single_read */
+
+/* for reading status version 1 */
+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_users = 0;
+
+ /* read the file until the "ROUTING TABLE" line is found (no more info after) */
+ while (fgets (buffer, sizeof (buffer), fh) != NULL)
+ {
+ if (strcmp (buffer, "ROUTING TABLE\n") == 0)
+ break;
+
+ if (strcmp (buffer, V1STRING) == 0)
+ {
+ found_header = 1;
+ continue;
+ }
+
+ /* skip the first lines until the client list section is found */
+ if (found_header == 0)
+ /* we can't start reading data until this string is found */
+ continue;
+
+ fields_num = openvpn_strsplit (buffer,
+ fields, STATIC_ARRAY_SIZE (fields));
+ if (fields_num < 4)
+ continue;
+
+ if (collect_user_count)
+ /* If so, sum all users, ignore the individuals*/
+ {
+ sum_users += 1;
+ }
+ if (collect_individual_users)
+ {
+ if (new_naming_schema)
+ {
+ iostats_submit (name, /* vpn instance */
+ fields[0], /* "Common Name" */
+ atoll (fields[2]), /* "Bytes Received" */
+ atoll (fields[3])); /* "Bytes Sent" */
+ }
+ else
+ {
+ iostats_submit (fields[0], /* "Common Name" */
+ NULL, /* unused when in multimode */
+ atoll (fields[2]), /* "Bytes Received" */
+ atoll (fields[3])); /* "Bytes Sent" */
+ }
+ }
+
+ read = 1;
+ }
+
+ if (collect_user_count)
+ {
+ numusers_submit(name, name, sum_users);
+ read = 1;
+ }
+
+ return (read);
+} /* int multi1_read */
+
+/* for reading status version 2 */
+static int multi2_read (char *name, FILE *fh)
+{
+ char buffer[1024];
+ char *fields[10];
+ const int max_fields = STATIC_ARRAY_SIZE (fields);
+ int fields_num, read = 0;
+ long long sum_users = 0;
+
+ while (fgets (buffer, sizeof (buffer), fh) != NULL)
+ {