def test_build_message(self): Statsd.set_transport(UDPTransport()) # no nothing self.assertEqual(Statsd._build_message({"test":"1|c"}),{'test': '1|c'}) # with timestamp self.assertEqual(Statsd._build_message({"testg":"1|g"}, 1, timestamp=1339793258), {"testg":"1|g|1339793258"})
def test_AFTransport_with_UDP(self): shlib = MagicMock() # TODO: not finished transport = AFTransport(useUDP=True) Statsd.set_transport(transport) # shlib.mq_open.return_value = 1 # shlib.mq_send.return_value = 0 Statsd.increment("mqtest") self.assertEqual(shlib.mq_open.call_count, 0) #post = "mqtest:1|c" self.assertEqual(shlib.mq_send.call_count, 0)
def test_AFTransport(self): shlib = MagicMock() transport = AFTransport() transport.shlib = shlib Statsd.set_transport(transport) shlib.mq_open.return_value = 1 shlib.mq_send.return_value = 0 Statsd.increment("mqtest") shlib.mq_open.assert_called_once_with("/afcollectorapi", 04001) self.assertEqual(shlib.mq_open.call_args[0][0], "/afcollectorapi") self.assertEqual(shlib.mq_open.call_args[0][1], 04001) post = "mqtest:1|c" shlib.mq_send.assert_called_once_with(1, post, len(post), 3) self.assertEqual(shlib.mq_send.call_args[0][0], 1) self.assertEqual(shlib.mq_send.call_args[0][1], post) self.assertEqual(shlib.mq_send.call_args[0][2], len(post)) self.assertEqual(shlib.mq_send.call_args[0][3], 3)
def test_build_message(self): Statsd.set_transport(UDPTransport()) # no nothing self.assertEqual(Statsd._build_message({"test": "1|c"}), {'test': '1|c'}) # with message self.assertEqual(Statsd._build_message({"test": "1|c"}, 1, "hello"), {"test": "1|c||hello"}) # with timestamp self.assertEqual( Statsd._build_message({"testg": "1|g"}, 1, timestamp=1339793258), {"testg": "1|g|1339793258"}) # with timestamp and message self.assertEqual( Statsd._build_message({"testg": "1|g"}, 1, "hello", 1339793258), {"testg": "1|g|1339793258|hello"})
def do_nothing(): Statsd.timing("python.test.timer",500) Statsd.gauge("python.test.gauge",500) Statsd.increment("python.test.counter") Statsd.decrement("python.test.counter") Statsd.update_stats("python.test.counter", 5, sample_rate=1, message="ok") Statsd.update_stats("python.test.counter", -5, sample_rate=0)
class MQError(Exception): def __init__(self, msg=None): self.msg = msg or "Statsd Error" def __str__(self): return str(self.msg) class MQSendError(Exception): def __init__(self, rc, msg=None): self.rc = rc self.msg = msg or "Statsd Error" def __str__(self): return str(self.msg) + " return errcode %s" % errno.errorcode(self.rc) Statsd.set_transport(AFTransport()) Statsd.set_strategy(GeyserStategy()) if __name__ == "__main__": # import time Statsd.set_transport(AFTransport(verbosity=True)) max_count = 1000000 count = 1 @Statsd.count("python.test.count") @Statsd.time("python.test.time") def do_nothing(): Statsd.timing("python.test.timer",500) Statsd.gauge("python.test.gauge",500) Statsd.increment("python.test.counter") Statsd.decrement("python.test.counter") Statsd.update_stats("python.test.counter", 5, sample_rate=1, message="ok")
from client import Statsd Statsd.increment("test.ten") Statsd.increment("test.ten") Statsd.increment("test.ten") Statsd.increment("test.ten") Statsd.increment("test.ten")
def test_stats(): Statsd.timing('python.test.timer', 500) Statsd.gauge('python.test.gauge', 500) Statsd.increment('python.test.counter') Statsd.decrement('python.test.counter') Statsd.update_stats('python.test.counter', 5, sample_rate=1) Statsd.update_stats('python.test.counter', -5, sample_rate=0)
self.msg = msg or "Statsd Error" def __str__(self): return str(self.msg) class MQSendError(Exception): def __init__(self, rc, msg=None): self.rc = rc self.msg = msg if msg is not None else 'Statsd Error' def __str__(self): return "{0}; return errcode: {1}".format(self.msg, errno.errorcode(self.rc)) Statsd.set_transport(AFTransport()) Statsd.set_aggregation(True) if __name__ == '__main__': # Test code Statsd.set_transport(AFTransport(verbosity=True)) count = 1 @Statsd.count('python.test.count') @Statsd.time('python.test.time') def test_stats(): Statsd.timing('python.test.timer', 500) Statsd.gauge('python.test.gauge', 500) Statsd.increment('python.test.counter') Statsd.decrement('python.test.counter') Statsd.update_stats('python.test.counter', 5, sample_rate=1)
class MQError(Exception): def __init__(self, msg=None): self.msg = msg or "Statsd Error" def __str__(self): return str(self.msg) class MQSendError(Exception): def __init__(self, rc, msg=None): self.rc = rc self.msg = msg or "Statsd Error" def __str__(self): return str(self.msg) + " return errcode %s" % errno.errorcode(self.rc) Statsd.set_transport(AFTransport()) Statsd.set_strategy(GeyserStategy()) if __name__ == "__main__": # import time Statsd.set_transport(AFTransport(verbosity=True)) count = 1 while True: Statsd.increment("mqtest") print "send mqtest %s" % count count += 1