Dump accesses by code and minutes in tsplotv format

This commit is contained in:
Peter J. Holzer 2022-10-23 13:46:45 +02:00
commit 85682c5d43
1 changed files with 25 additions and 0 deletions

25
httplog2code_perminute_ts Normal file
View File

@ -0,0 +1,25 @@
#!/usr/bin/python3
import re
import sys
import dateutil.parser
codes = ["200", "301", "302", "400", "401", "403", "404", "405", "408"]
data = {}
with open(sys.argv[1]) as f:
for ln in f:
if m := re.match(r'\S+ - \S+ \[(../.../....:..:..:.. .....)\] "[^"]*" (\d+) ', ln):
dt = dateutil.parser.parse(m.group(1).replace(':', ' ', 1))
ts = int(dt.timestamp() // 60) * 60 # truncate to minute
code = m.group(2)
if ts not in data:
data[ts] = {c: 0 for c in codes}
data[ts][code] += 1
empty = {c: 0 for c in codes}
for ts in range(min(data.keys()), max(data.keys()) + 1, 60):
if ts not in data:
data[ts] = empty
for code in codes:
print(ts, code, data[ts][code], sep="\t")
# vim: tw=99