Ejemplo n.º 1
0
def get_404(log):
    '''
    Find the set of all requests with status 404 in the given `log` sequence
    >>> get_404('access-log')
    []
    '''
    l = []
    for line in apachelog.lines_from_dir(log, 'www'):
        #print line
        for i in apachelog.apache_log(line):
            a = i['status']
            b = i['request']
            if a == '404':
                #print b
                if b not in l:
                    l.append(b)
    return l
Ejemplo n.º 2
0
def get_largest(log):
    '''
    Find the largest data transfer in the given `log` sequence
    >>> get_largest('access-log')
    (4919642, '/dynamic/ffcache.zip')
    '''
    size = 0
    f = 0
    for line in apachelog.lines_from_dir(log, 'www'):
        for i in apachelog.apache_log(line):
            try:
                a = int(i["bytes"])
                b = i["request"]
            except:
                continue
            if a > size:
                size = a
                f = b
    return size, f
Ejemplo n.º 3
0
# realtime404.py
#
# Print all 404 requests as they happen in the log

from apachelog import apache_log
from follow import follow

logfile = open("run/foo/access-log")
loglines = follow(logfile)
log = apache_log(loglines)

r404 = (r for r in log if r["status"] == 404)

for r in r404:
    print(r["host"], r["datetime"], r["request"])
Ejemplo n.º 4
0
def main():
    '''Main function'''
    lines = apachelog.lines_from_dir('access-log*', 'www')
    log = apachelog.apache_log(lines)
    for r in sorted(get_404(log)):
        print r
Ejemplo n.º 5
0
def main():
    '''Main function'''
    lines = apachelog.lines_from_dir('access-log*', 'www')
    log = apachelog.apache_log(lines)
    print 'Total: %d' % get_downloads_count(log, '/ply/ply-2.3.tar.gz')
Ejemplo n.º 6
0
# gentrace.py
#
# Trace a generator by printing items received


def trace(source):
    for item in source:
        print(item)
        yield item


# Example use
if __name__ == "__main__":
    from apachelog import apache_log

    lines = open("access-log")
    log = trace(apache_log(lines))
    r404 = (r for r in log if r["status"] == 404)

    for r in r404:
        pass
Ejemplo n.º 7
0
    def run(self):
        self.target(self.generate())


# Example use:
if __name__ == "__main__":
    from follow import follow
    from apachelog import apache_log
    from broadcast import broadcast

    def find_404(log):
        r404 = (r for r in log if r["status"] == 404)
        for r in r404:
            print(r["status"], r["datetime"], r["request"])

    def bytes_transferred(log):
        total = 0
        for r in log:
            total = r["bytes"]
            print("Total bytes", total)

    c1 = ConsumerThread(find_404)
    c1.start()
    c2 = ConsumerThread(bytes_transferred)
    c2.start()

    lines = follow(open("run/foo/access-log"))  # Foolow a log
    log = apache_log(lines)  # Turn into records
    broadcast(log, [c1, c2])  # Broadcast to consumers
Ejemplo n.º 8
0
def main():
    '''Main function'''
    lines = apachelog.lines_from_dir('access-log*', 'www')
    log = apachelog.apache_log(lines)
    print '%d %s' % get_largest(log)