You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.4 KiB

import json
from collections import defaultdict
LOG_FILE = "logs/app.log"
total_requests = 0
total_latency = 0
query_count = defaultdict(int)
slow_requests = []
with open(LOG_FILE, "r") as f:
for line in f:
try:
log = json.loads(line)
total_requests += 1
latency = log.get("latency_ms", 0)
query = log.get("query", "")
total_latency += latency
query_count[query] += 1
if latency > 1000: # slow threshold
slow_requests.append((query, latency))
except:
continue
# Results
print("\n📊 BASIC METRICS")
print("=" * 30)
if total_requests > 0:
print(f"Total Requests: {total_requests}")
print(f"Avg Latency: {total_latency // total_requests} ms")
print("\n🔥 Top Queries:")
for q, count in sorted(query_count.items(), key=lambda x: x[1], reverse=True)[:5]:
print(f"{q}{count} times")
print("\n⚠️ Slow Requests (>1000ms):")
for q, lat in slow_requests[:5]:
print(f"{q}{lat} ms")
cache_hits = 0
if log.get("latency_ms", 0) < 500:
cache_hits += 1
print(f"\n⚡ Fast Requests (<500ms): {cache_hits}")
hit_count = 0
if log.get("cache_status") in ["strong_hit", "refined_hit"]:
hit_count += 1
hit_rate = (hit_count / total_requests) * 100
fallback_count = 0
if log.get("cache_status") == "miss":
fallback_count += 1
fallback_rate = (fallback_count / total_requests) * 100