IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 17, 2011, 8:53:01 AM (15 years ago)
Author:
Serge CHASTEL
Message:

Automated measurements of Nebulous activity (experimental)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/log_parsing/parse_apache_log.py

    r30522 r30662  
    44import re
    55import datetime
     6import fileinput
    67
    78nebulousPattern = re.compile('POST /nebulous HTTP/1.1')
     9errorPattern = re.compile('exit signal Segmentation fault')
     10
    811# Resolution: 10 minutes of 60 seconds of 1000000 microseconds
    912datetime.resolution = 10*60*1000000
    1013
    1114def message(size):
     15    """
     16    Guess the message type according to the message size
     17    """
    1218    if size == 488:
    1319        # delete == 488
     
    3440
    3541def show_results(counts, output=sys.stderr):
     42    """
     43    Display results
     44    """
    3645    output.write('#             Epoch | Create | FindIn | Delete | FailSt |   Stat |  Unkn. | NonNeb\n')
    3746    for count in sorted(counts.iterkeys()):
     
    4554                                                                           counts[count][6]))
    4655
    47 if __name__ == '__main__':
     56def process(linesInFile = None):
     57    """
     58    Process Nebulous entries in apache2 log file
     59    """
    4860    counts = dict()
    49 
    5061    linesCount = 1
    51     for line in sys.stdin:
    52         if linesCount % 10000 == 0:
    53             sys.stderr.write('Analyzed lines: %d\n' % linesCount)
    54             if linesCount % 100000 == 0:
     62    if linesInFile == None:
     63        input = fileinput.input()
     64    else:
     65        input = linesInFile
     66    for line in input:
     67        if linesCount % 100000 == 0:
     68            sys.stderr.write('\tAnalyzed lines: %d\n' % linesCount)
     69            if linesCount % 500000 == 0:
    5570                show_results(counts)
    5671        linesCount += 1
     
    85100                counts[dt.isoformat()] = [0, 0, 0, 0, 0, 0, 0]
    86101                counts[dt.isoformat()][6] += 1
     102    return counts
    87103
    88     show_results(counts, sys.stdout)
     104def show_errors(counts, output=sys.stderr):
     105    """
     106    Display error results
     107    """
     108    output.write('#             Epoch | Errors\n')
     109    for count in sorted(counts.iterkeys()):
     110        output.write('%19s | %6d\n' % (count, counts[count]))
     111
     112def processErrorLog(linesInFile = None):
     113    """
     114    Process errors in apache2 error log file
     115    """
     116    counts = dict()
     117    linesCount = 1
     118    if linesInFile == None:
     119        input = fileinput.input()
     120    else:
     121        input = linesInFile
     122    for line in input:
     123        if linesCount % 100000 == 0:
     124            sys.stderr.write('\tAnalyzed lines: %d\n' % linesCount)
     125            if linesCount % 500000 == 0:
     126                show_errors(counts)
     127        linesCount += 1
     128        if errorPattern.search(line):
     129            elements = line.split(']')
     130            date = elements[0]
     131            date = date[1:]
     132            # print '[%s]' % (date)
     133            dt = datetime.datetime.strptime(date,
     134                                            '%a %b %d %H:%M:%S %Y')
     135            dt = dt.replace(minute = int(dt.minute/10)*10,
     136                            second = 0)
     137            # print dt.isoformat()
     138            try:
     139                counts[dt.isoformat()] += 1
     140            except KeyError:
     141                counts[dt.isoformat()] = 1
     142    return counts
     143
     144def usage():
     145    sys.stderr.write(main.__doc__)
     146
     147def main(arguments):
     148    """
     149Usage: parse_apache_log [-a <nebulous apache access_log file>] [-e <nebulous apache error_log file>]
     150"""
     151    mainName = arguments.pop()
     152    if len(arguments) == 0:
     153        sys.stderr.write('Reading from /dev/stdin\n')
     154        counts = process()
     155        show_results(counts, sys.stdout)
     156    elif len(arguments) % 2 != 0:
     157        sys.stderr.write('Arguments length: %d\n' % (len(arguments)))
     158        usage()
     159        sys.exit(1)
     160    else:
     161        accessFilenames = []
     162        errorFilenames = []
     163        while len(arguments) != 0:
     164            flag = arguments.pop()
     165            filename = arguments.pop()
     166            if flag == '-a':
     167                accessFilenames.append(filename)
     168            elif flag == '-e':
     169                errorFilenames.append(filename)
     170            else:
     171                sys.stderr.write('Unknown flag: [%s]' % (flag))
     172                usage()
     173                sys.exit(1)
     174        for accessFilename in accessFilenames:
     175            sys.stderr.write('Processing: [%s]' % (accessFilename))
     176            inFile = open(accessFilename)
     177            counts = process(inFile)
     178            show_results(counts, sys.stdout)
     179        for errorFilename in errorFilenames:
     180            counts = processErrorLog(errorFilename)
     181            show_errors(counts, sys.stdout)
     182
     183if __name__ == '__main__':
     184    main(sys.argv)
Note: See TracChangeset for help on using the changeset viewer.