
import json
import os

def detect_anomaly(metrics):
    alerts = []
    if metrics["cpu"] > 80:
        alerts.append("CPU usage is too high!")
    if metrics["memory"] > 80:
        alerts.append("Memory usage is too high!")
    return alerts

if __name__ == "__main__":
    with open(os.path.join(os.path.dirname(__file__), "../sample_data/metrics.json")) as f:
        metrics = json.load(f)
    alerts = detect_anomaly(metrics)
    for alert in alerts:
        print("[ALERT]", alert)
