Skip to content

Instantly share code, notes, and snippets.

@ScheerMT ScheerMT/statsd.py
Last active Sep 16, 2015

Embed
What would you like to do?
Implemented the ruby version in python to handle multiple responses in a single packet. Some client implementations of statsd buffer packets together to be sent as one UDP packet. *NOTE*: You may have to change your location of the python executable in the sha-bang. I put the contents of this gist in /usr/bin/lstatsd so it can be run in terminal
#!/usr/local/bin/python
import socket
from termcolor import colored
UDP_IP = "0.0.0.0"
UDP_PORT = 8125
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(4096)
print "======START PACKET====="
dataArray = data.splitlines()
for line in dataArray:
metric, value = line.split(':')
print "StatsdD Metric:", colored(metric, "blue"), colored(value, "green")
print "=====END PACKET=====\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.