Last active
September 16, 2015 15:50
-
-
Save ScheerMT/d5ddad9a2bbdf2ef3f71 to your computer and use it in GitHub Desktop.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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