Permalink
Browse files

Add a very basic aggregator client written in python

Meant for example/educational uses only
  • Loading branch information...
1 parent d5f6595 commit 0450dbf09aa3408daf0b2d6e739a034c34da61bb @rtyler committed Mar 29, 2011
Showing with 32 additions and 0 deletions.
  1. +32 −0 aggclient.py
View
32 aggclient.py
@@ -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)
+
+

0 comments on commit 0450dbf

Please sign in to comment.