Add a very basic aggregator client written in python

Meant for example/educational uses only
This commit is contained in:
R. Tyler Croy 2011-03-29 11:04:27 -07:00
parent d5f6595451
commit 0450dbf09a
1 changed files with 32 additions and 0 deletions

32
aggclient.py Normal file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env python
import socket
import time
AGGREGATED_HOST = '127.0.0.1'
AGGREGATED_PORT = 22034
def aggregator_host():
return (AGGREGATED_HOST, AGGREGATED_PORT)
def record_multi(dataset):
"""
Expecting an iterable of (label, value) tuples
"""
now = time.time()
lines = ('%s %s %s' % (l, v, now) for l, v in dataset)
message = '\n'.join(lines) + '\n'
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(message, aggregator_host())
def record(label, value):
return record_multi(((label, value,),))
def incr(label):
return record_multi(((label, 1,),))
def timing(label, delta):
return record(label, '%f|s' % delta)