示例#1
0
文件: openvpn.c 项目: brd/collectd
/* for reading status version 2 */
static int multi2_read (const 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)
	{
		fields_num = openvpn_strsplit (buffer, fields, max_fields);

		/* status file is generated by openvpn/multi.c:multi_print_status()
		 * http://svn.openvpn.net/projects/openvpn/trunk/openvpn/multi.c
		 *
		 * The line we're expecting has 8 fields. We ignore all lines
		 *  with more or less fields.
		 */
		if (fields_num != 8)
			continue;

		if (strcmp (fields[0], "CLIENT_LIST") != 0)
			continue;

		if (collect_user_count)
			/* If so, sum all users, ignore the individuals*/
		{
			sum_users += 1;
		}
		if (collect_individual_users)
		{
			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 (collect_user_count)
	{
		numusers_submit(name, name, sum_users);
		read = 1;
	}

	return (read);
} /* int multi2_read */
示例#2
0
/* 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;

	/* 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 (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;
	}

	return (read);
} /* int multi1_read */
示例#3
0
/* for reading status version 3 */
static int multi3_read (char *name, FILE *fh)
{
	char buffer[1024];
	char *fields[15];
	const int max_fields = STATIC_ARRAY_SIZE (fields);
	int  fields_num, read = 0;

	while (fgets (buffer, sizeof (buffer), fh) != NULL)
	{
		fields_num = strsplit (buffer, fields, max_fields);

		/* status file is generated by openvpn/multi.c:multi_print_status()
		 * http://svn.openvpn.net/projects/openvpn/trunk/openvpn/multi.c
		 *
		 * The line we're expecting has 12 fields. We ignore all lines
		 *  with more or less fields.
		 */
		if (fields_num != 12)
		{
			continue;
		}
		else
		{
			if (strcmp (fields[0], "CLIENT_LIST") != 0)
				continue;

			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;
		}
	}

	return (read);
} /* int multi3_read */
示例#4
0
文件: openvpn.c 项目: brd/collectd
static int single_read (const char *name, FILE *fh)
{
	char buffer[1024];
	char *fields[4];
	const int max_fields = STATIC_ARRAY_SIZE (fields);
	int  fields_num, read = 0;

	derive_t link_rx, link_tx;
	derive_t tun_rx, tun_tx;
	derive_t pre_compress, post_compress;
	derive_t pre_decompress, post_decompress;
	derive_t overhead_rx, overhead_tx;

	link_rx = 0;
	link_tx = 0;
	tun_rx = 0;
	tun_tx = 0;
	pre_compress = 0;
	post_compress = 0;
	pre_decompress = 0;
	post_decompress = 0;

	while (fgets (buffer, sizeof (buffer), fh) != NULL)
	{
		fields_num = openvpn_strsplit (buffer, fields, max_fields);

		/* status file is generated by openvpn/sig.c:print_status()
		 * http://svn.openvpn.net/projects/openvpn/trunk/openvpn/sig.c
		 *
		 * The line we're expecting has 2 fields. We ignore all lines
		 *  with more or less fields.
		 */
		if (fields_num != 2)
		{
			continue;
		}

		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 */