def analyze(metrics: dict):
    alerts = []

    if metrics.get("cpu"):
        cpu = float(metrics["cpu"][0]["value"][1])
        if cpu > 85:
            alerts.append({
                "title": "CPU élevée",
                "cause": f"{cpu:.1f} %",
                "severity": "warning",
            })

    if metrics.get("memory"):
        mem = float(metrics["memory"][0]["value"][1])
        if mem > 90:
            alerts.append({
                "title": "Mémoire saturée",
                "cause": f"{mem:.1f} %",
                "severity": "critical",
            })

    if metrics.get("containers_down"):
        down = int(float(metrics["containers_down"][0]["value"][1]))
        if down > 0:
            alerts.append({
                "title": "Containers arrêtés",
                "cause": f"{down} détecté(s)",
                "severity": "critical",
            })

    return alerts
