Created
January 19, 2024 08:57
-
-
Save fthiery/972d54e0a5f112ece28547b9279ba1f8 to your computer and use it in GitHub Desktop.
CDN77 debug tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
from datetime import datetime, timedelta | |
FILE = sys.argv[1] | |
with open(FILE, "r") as f: | |
d = f.read().strip() | |
stats = {} | |
total_ts_requests = 0 | |
old_ts_requests = 0 | |
for line in d.split('\n'): | |
fields = line.strip().split() | |
date = fields[0] | |
ip = fields[4] | |
file = fields[8].split('/')[-1] | |
status = fields[9] | |
processing_time = float(fields[13]) | |
cache_status = fields[10] | |
try: | |
# cannot be trusted (they said) | |
cache_age = int(fields[11]) | |
except Exception: | |
cache_age = 0 | |
if file.endswith('.ts'): | |
total_ts_requests += 1 | |
ts = int(int(file.split('-')[1].replace('.ts', '')) / 1000) | |
timestamp_date = datetime.fromtimestamp(ts) | |
# 16/Jan/2024:22:33:40> | |
request_end_date = datetime.strptime(date, "%d/%b/%Y:%H:%M:%S") + timedelta(hours=1) | |
request_start_date = request_end_date - timedelta(seconds=int(processing_time)) | |
diff = request_start_date - timestamp_date | |
diff_seconds = abs(diff.total_seconds()) | |
if diff_seconds > 60: | |
old_ts_requests += 1 | |
stats.setdefault(status, 0) | |
stats[status] += 1 | |
print(f"IP {ip} HTTP {status}, req: {request_start_date}, ts_timestamp: {timestamp_date}, difference: {diff}, {file}") | |
print(stats) | |
old_ts = 100 * old_ts_requests / total_ts_requests | |
print(f"[{old_ts_requests}/{total_ts_requests}] {old_ts:.4f}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment