Ejemplo n.º 1
0
def test_bucketize():
    a = [dict(timestamp=datetime(2015, 10, 7, hour=21, minute=33, second=27),
              status='404'),
         dict(timestamp=datetime(2015, 10, 7, hour=21, minute=33, second=42),
              status='404'),
         dict(timestamp=datetime(2015, 10, 7, hour=21, minute=33, second=27),
              status='200'),
         dict(timestamp=datetime(2015, 10, 7, hour=21, minute=42, second=27),
              status='200'),
         ]
    for t, b in bucketize(a):
        g = group_by(b, 'status')
        for status, line in g.items():
            print(status, len(line))
Ejemplo n.º 2
0
    lines = grok_parser("%{HAPROXYHTTP}", source,
                        cb_oups=oups,
                        date_key="accept_date",
                        date_format="%d/%b/%Y:%H:%M:%S.%f")
    for ts, bucket in bucketize(lines):
        points = [dict(measurement="latency",
                       tags=dict(backend=v['backend_name'],
                                 status_code=v['http_status_code']),
                       # time=ts,
                       fields=dict(latency=int(v.get('time_backend_response',
                                                     0)))
                       )
                  for v in bucket]
        print(points)

        backends = group_by(bucket, 'backend_name')

        for backend, values in backends.items():
            latencies = [int(v['time_backend_response']) for v in values
                         if v['http_status_code'] in ['200', '201']]
            a, hits = apdex(latencies, 3)
            print(backend, latencies, a)
            assert a is None or a <= 1.0
            if a is not None:
                carbon.send(APDEX.format(backend=backend), int(a * 100), ts)
                carbon.send(HITS.format(backend=backend), hits, ts)
            for status, values in group_by(values, 'http_status_code').items():
                carbon.send(STATUS.format(service=backend, status=status),
                            len(values), ts)
                print(backend, status, len(values))
            v = [int(v['time_backend_response']) for v in values