Exemple #1
0
 def __init__(self, host, port, packet_size=512, flush_interval=0.5):
     self.host = host
     self.port = port
     self.collector = MetricCollector(packet_size)
     self._udp_client = None
     self._running = False
     self._done = asyncio.Future()
     self.flush_interval = flush_interval
Exemple #2
0
 def test_batching_1(self):
     MTU = 24
     collector = MetricCollector(MTU)
     for i in range(8):
         met_name = "m%i" % i
         collector.push_gauge(met_name, 100 + i)
     result = list(collector.flush())
     self.assertEqual([
         b"m0:100|g\nm1:101|g", b"m2:102|g\nm3:103|g",
         b"m4:104|g\nm5:105|g", b"m6:106|g\nm7:107|g"
     ], result)
Exemple #3
0
 def test_batching_1(self):
     MTU = 512
     collector = MetricCollector(MTU)
     for i in range(8):
         met_name = "m%i" % i
         collector.push_gauge(met_name, 100 + i)
     result = list(collector.flush())
     print('RESULT', result)
     self.assertEqual([
         b"m0:100.000000|g\nm1:101.000000|g\n"
         b"m2:102.000000|g\nm3:103.000000|g\n"
         b"m4:104.000000|g\nm5:105.000000|g\n"
         b"m6:106.000000|g\nm7:107.000000|g"
     ], result)
Exemple #4
0
def encode_timer(name, val, rate=1.0):
    collector = MetricCollector()
    collector.push_timer(name, val, rate)
    result = list(collector.flush())
    assert len(result) == 1
    return result[0]
Exemple #5
0
def encode_gauge(name, val, rate=1.0, delta=False):
    collector = MetricCollector()
    collector.push_gauge(name, val, rate, delta)
    result = list(collector.flush())
    assert len(result) == 1
    return result[0]