Exemplo n.º 1
0
    def test_prefix(self):
        client = statsd.StatsdClient('localhost', 8125, prefix='main.bucket', sample_rate=None)
        client._send(b'subname', b'100|c')
        self.assertEqual(client._socket.data, b'main.bucket.subname:100|c')

        client = statsd.StatsdClient('localhost', 8125, prefix='main', sample_rate=None)
        client._send(b'subname', b'100|c')
        self.assertEqual(client._socket.data, b'main.subname:100|c')
        client._send(b'subname.subsubname', b'100|c')
        self.assertEqual(client._socket.data, b'main.subname.subsubname:100|c')
Exemplo n.º 2
0
 def test_timing(self):
     client = statsd.StatsdClient('localhost',
                                  8125,
                                  prefix='',
                                  sample_rate=None)
     client.timing('buck.timing', 100)
     self.assertEqual(client._socket.data, b'buck.timing:100|ms')
Exemplo n.º 3
0
 def test_startstop(self):
     timer = statsd.StatsdTimer('timeit', statsd.StatsdClient('localhost', 8125, prefix='', sample_rate=None))
     timer.start()
     time.sleep(0.25)
     timer.stop()
     self.assertTrue(timer._client._socket.data.startswith(b'timeit.total:2'))
     self.assertTrue(timer._client._socket.data.endswith(b'|ms'))
Exemplo n.º 4
0
 def test_couter_factory(self):
     client = statsd.StatsdClient('localhost', 8125, prefix='', sample_rate=0.999)
     counter = client.counter('counted')
     counter += 1
     self.assertEqual(counter._client._socket.data, b'counted:1|c|@0.999')
     counter += 5
     self.assertEqual(counter._client._socket.data, b'counted:5|c|@0.999')
Exemplo n.º 5
0
 def test_send(self):
     client = statsd.StatsdClient('localhost',
                                  8125,
                                  prefix='',
                                  sample_rate=None)
     client._send(b'buck', b'50|c')
     self.assertEqual(client._socket.data, b'buck:50|c')
Exemplo n.º 6
0
 def test_incr(self):
     client = statsd.StatsdClient('localhost',
                                  8125,
                                  prefix='',
                                  sample_rate=None)
     client.incr('buck.counter', 5)
     self.assertEqual(client._socket.data, b'buck.counter:5|c')
Exemplo n.º 7
0
 def test_timer_factory(self):
     client = statsd.StatsdClient('localhost', 8125, prefix='', sample_rate=0.999)
     timer = client.timer('timeit')
     timer.start()
     time.sleep(0.25)
     timer.stop()
     self.assertTrue(timer._client._socket.data.startswith(b'timeit.total:2'))
     self.assertTrue(timer._client._socket.data.endswith(b'|ms|@0.999'))
Exemplo n.º 8
0
 def test_timing_sample_rate(self):
     client = statsd.StatsdClient('localhost',
                                  8125,
                                  prefix='',
                                  sample_rate=0.999)
     client.timing('buck.timing', 100)
     self.assertEqual(client._socket.data, b'buck.timing:100|ms|@0.999')
     if client._socket.data != '':
         self.assertTrue(client._socket.data.endswith(b'|@0.999'))
Exemplo n.º 9
0
 def test_send_sample_rate(self):
     client = statsd.StatsdClient('localhost',
                                  8125,
                                  prefix='',
                                  sample_rate=0.999)
     client._send(b'buck', b'50|c')
     self.assertEqual(client._socket.data, b'buck:50|c|@0.999')
     if client._socket.data != 'buck:50|c':
         self.assertTrue(client._socket.data.endswith(b'|@0.999'))
Exemplo n.º 10
0
 def test_incr_sample_rate(self):
     client = statsd.StatsdClient('localhost',
                                  8125,
                                  prefix='',
                                  sample_rate=0.999)
     client.incr('buck.counter', 5)
     self.assertEqual(client._socket.data, b'buck.counter:5|c|@0.999')
     if client._socket.data != 'buck.counter:5|c':
         self.assertTrue(client._socket.data.endswith(b'|@0.999'))
Exemplo n.º 11
0
 def __init__(
     self,
     *args,
     host=DEFAULT_HOST,
     port=DEFAULT_PORT,
     namespace='routemaster',
     tags=None,
 ):
     self.statsd = statsd.StatsdClient(
         host=host,
         port=int(port),
         namespace=namespace,
         tags=tags or {},
     )
     super().__init__(*args)
Exemplo n.º 12
0
 def test_sub(self):
     counter = statsd.StatsdCounter('counted', statsd.StatsdClient('localhost', 8125, prefix='', sample_rate=None))
     counter -= 1
     self.assertEqual(counter._client._socket.data, b'counted:-1|c')
     counter -= 5
     self.assertEqual(counter._client._socket.data, b'counted:-5|c')