# Path: amonagent/utils.py
# def split_and_slugify(string, separator=":"):
# 	_string = string.strip().split(separator)
# 	
# 	if len(_string) == 2: # Only key, value
# 		data = {}
# 		key = slugify(unicode(_string[0]))
# 		
# 		try:
# 			if len(_string[1]) > 0:
# 				data[key] = str(_string[1].strip())
# 		except:
# 			pass
# 
# 		return data
# 	
# 	else:
# 		return None
# 
# def to_float(value):
# 	result = value
# 	if not isinstance(value, int):
# 		result = float(value.replace(",", "."))
# 	
# 	return result


import subprocess
import re
import logging
from amonagent.utils import split_and_slugify, to_float

		return data



def get_network_traffic():

	try:
		stats = subprocess.Popen(['sar','-n','DEV','1','1'], 
		stdout=subprocess.PIPE, close_fds=True)\
			.communicate()[0]
	except:
		log.exception('Unable to collect network metrics.')
		return False

	network_data = stats.splitlines()
	data = {}
	for line in network_data:
		if line.startswith('Average'):
			elements = line.split()
			interface = elements[1]
			
			# interface name with . 
			if '.' in interface:
				interface = interface.replace('.','-')

			if interface not in ['IFACE', 'lo']:
				# rxkB/s - Total number of kilobytes received per second  
				# txkB/s - Total number of kilobytes transmitted per second
				

# Path: amonagent/utils.py
# def split_and_slugify(string, separator=":"):
# 	_string = string.strip().split(separator)
# 	
# 	if len(_string) == 2: # Only key, value
# 		data = {}
# 		key = slugify(unicode(_string[0]))
# 		
# 		try:
# 			if len(_string[1]) > 0:
# 				data[key] = str(_string[1].strip())
# 		except:
# 			pass
# 
# 		return data
# 	
# 	else:
# 		return None
# 
# def to_float(value):
# 	result = value
# 	if not isinstance(value, int):
# 		result = float(value.replace(",", "."))
# 	
# 	return result


# Path: amonagent/modules/core.py
import subprocess
import re
import logging
from amonagent.utils import split_and_slugify, to_float


		return data



def get_network_traffic():

	try:
		stats = subprocess.Popen(['sar','-n','DEV','1','1'], 
		stdout=subprocess.PIPE, close_fds=True)\
			.communicate()[0]
	except:
		log.exception('Unable to collect network metrics.')
		return False

	network_data = stats.splitlines()
	data = {}
	for line in network_data:
		if line.startswith('Average'):
			elements = line.split()
			interface = elements[1]
			
			# interface name with . 
			if '.' in interface:
				interface = interface.replace('.','-')

			if interface not in ['IFACE', 'lo']:
				# rxkB/s - Total number of kilobytes received per second  
				# txkB/s - Total number of kilobytes transmitted per second
				

				inbound = to_float(elements[4])