#!/usr/bin/env python

import sys
import re
import datetime

nebulousPattern = re.compile('POST /nebulous HTTP/1.1')
# Resolution: 10 minutes of 60 seconds of 1000000 microseconds
datetime.resolution = 10*60*1000000

def message(size):
    if size == 488:
        # delete == 488
        return 2
    elif size > 1800:
        # failure_stat
        # 1577 + 3*ext_key for stat, 1597 + 3*ext_key for delete
        return 3
    elif size > 850:
        # stat
        # 819 + ext_key for stat
        return 4
    elif size > 650:
        # find_instance
        # 600 + ext_key
        return 1
    elif size > 575:
        # create
        # 526 + ext_key
        return 0
    else:
        # unknown
        return 5

def show_results(counts, output=sys.stderr):
    output.write('#             Epoch | Create | FindIn | Delete | FailSt |   Stat |  Unkn. | NonNeb\n')
    for count in sorted(counts.iterkeys()):
        output.write('%19s | %6d | %6d | %6d | %6d | %6d | %6d | %6d\n' % (count, 
                                                                           counts[count][0],
                                                                           counts[count][1],
                                                                           counts[count][2],
                                                                           counts[count][3],
                                                                           counts[count][4],
                                                                           counts[count][5],
                                                                           counts[count][6]))

if __name__ == '__main__':
    counts = dict()

    linesCount = 1
    for line in sys.stdin:
        if linesCount % 10000 == 0:
            sys.stderr.write('Analyzed lines: %d\n' % linesCount)
            if linesCount % 100000 == 0:
                show_results(counts)
        linesCount += 1
        if nebulousPattern.search(line):
            elements = line.split(' ')
            date = elements[3]
            date = date[1:]
            size = elements[-1]
            # print '[%s] %s' % (date, size)
            dt = datetime.datetime.strptime(date, 
                                            '%d/%b/%Y:%H:%M:%S')
            dt = dt.replace(minute = int(dt.minute/10)*10,
                            second = 0)
            try:
                counts[dt.isoformat()][message(int(size))] += 1
            except KeyError:
                counts[dt.isoformat()] = [0, 0, 0, 0, 0, 0, 0]
                counts[dt.isoformat()][message(int(size))] += 1
        else:
            elements = line.split(' ')
            date = elements[3]
            date = date[1:]
            size = elements[-1]
            # print '[%s] %s' % (date, size)
            dt = datetime.datetime.strptime(date, 
                                            '%d/%b/%Y:%H:%M:%S')
            dt = dt.replace(minute = int(dt.minute/10)*10,
                            second = 0)
            try:
                counts[dt.isoformat()][6] += 1
            except KeyError:
                counts[dt.isoformat()] = [0, 0, 0, 0, 0, 0, 0]
                counts[dt.isoformat()][6] += 1

    show_results(counts, sys.stdout)
