diff options
Diffstat (limited to 'monitor/josef_logreader.py')
| -rwxr-xr-x | monitor/josef_logreader.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/monitor/josef_logreader.py b/monitor/josef_logreader.py new file mode 100755 index 0000000..62edfff --- /dev/null +++ b/monitor/josef_logreader.py @@ -0,0 +1,59 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import sys +import time +import datetime +import os + +from monitor_conf import * + +TIME_LEN = 21 +NEW_STH_STR = "STH updated" +START_STR = "Starting monitor" + +def get_logs(): + logs = [] + for file in os.listdir("./" + OUTPUT_DIR): + if file.endswith(".log"): + logs.append(file) + return logs + +def get_age_from_line(line): + past = datetime.datetime.strptime(line[:20], '%Y-%m-%d, %H:%M:%S') + present = datetime.datetime.now() + return present - past + +def read_loglog(filename): + with open(OUTPUT_DIR + filename) as f: + content = f.readlines() + return content + +def print_log_stats(l): + print l + log = read_loglog(l) + rev_log = list(reversed(log)) + last = rev_log[0] + + # Stats from last STH update + for item in rev_log: + line = item[TIME_LEN:] + # if line[:len(START_STR)] == START_STR: + # break + if line[:len(NEW_STH_STR)] == NEW_STH_STR: + timestamp = datetime.datetime.strptime(line[-20:-1], '%Y-%m-%d %H:%M:%S') + age = datetime.datetime.now() - timestamp + size = line.split("Size: ")[1].split(",")[0] + # print line[:-1] + print "STH age: " + str(age)[:-7] + print "Size: " + size + break + # else: + # print "No STH update found in log." + + print "" + +if __name__ == "__main__": + logs = get_logs() + for log in logs: + print_log_stats(log)
\ No newline at end of file |
