import output
import socket
import sys

class Statsd(output.Output):
	requiredData = ["host","port","prefix"]
	optionalData = []
	def __init__(self,data):
		self.host=data["host"]
		self.port=data["port"]
		self.prefix=data["prefix"]
		self.socket=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
		self.address = (self.host,int(self.port))
	def outputData(self,dataPoints):
		for i in dataPoints:
			try:
				message = self.prefix + i["name"].lower() + ":" + str(i["value"]) + "|g"
				print "Echo to StatsD " + message
				sent = self.socket.sendto(message,self.address)
			except Exception:
				raise
				return False
		return True

