commit 85682c5d43152b42c004a5a12d000c902a759cc9 Author: Peter J. Holzer Date: Sun Oct 23 13:46:45 2022 +0200 Dump accesses by code and minutes in tsplotv format diff --git a/httplog2code_perminute_ts b/httplog2code_perminute_ts new file mode 100644 index 0000000..163c250 --- /dev/null +++ b/httplog2code_perminute_ts @@ -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