Exemplo 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))
Exemplo n.º 2
0
        print("OUPS", line)

    if len(sys.argv) > 1:
        offset = os.getenv("OFFSET_FOLDER", None)
        if offset:
            full = os.path.abspath(sys.argv[1]).replace('/', '-')
            offset = "%s/%s.offset" % (offset, full)
        source = forever_tail(sys.argv[1], offset)
    else:
        source = sys.stdin

    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']]