Skip to content

Instantly share code, notes, and snippets.

@queertypes
Created December 12, 2013 20:21
Show Gist options
  • Save queertypes/7934752 to your computer and use it in GitHub Desktop.
Save queertypes/7934752 to your computer and use it in GitHub Desktop.
Simple UDP server to capture statsd repeater-counter events.
import re
import socket
# Handles only counter events
stats_capture = re.compile(r'^(.*):(\d+)\|c$')
s = socket.socket(socket.AF_INET,
socket.SOCK_DGRAM)
s.bind(('127.0.0.1', 8001))
while True:
data, addr = s.recvfrom(1024)
try:
bucket, count = stats_capture.match(data).groups()
print('Incrementing bucket {0} by {1}'.format(bucket, count))
except AttributeError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment