-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.py
33 lines (27 loc) · 911 Bytes
/
errors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
Produce error report from access log
"""
from . import logfile
if __name__ == '__main__':
cache_path = 'data/access.log.pickled'
try:
# Attempt to load pre-cached data
with open(cache_path, 'rb') as fp:
requests = pickle.load(fp)
except:
# Data not pre-cached! :-O
parser = logfile.ApacheParser()
input_file = logfile.LogFile('data/access.log.gz', parser)
requests = input_file.read_data()
parser.clear_cache()
with open(cache_path, 'wb') as fp:
pickle.dump(requests, fp)
# We only want LogEntry objects with status code of 404
errors = [x for x in requests if x.status == 404]
# Build report
error_stats = collections.defaultdict(int)
for r in errors:
key = r.host + r.request
error_stats[key] += 1
for key in error_stats:
print(error_stats[key], key)