#!/usr/bin/env python3
"""Auto-generated by AGI Loop cycle #1042
Task: Write a Python function that checks disk usage of /Eden with os.statvfs and writes a warning to /Eden/DATA/alerts.json if usage exceeds 80 percent
Generated: 2026-02-12T18:02:06.597046
"""

import json
import os

def check_disk_usage():
    path = "/Eden"
    try:
        statvfs = os.statvfs(path)
        block_size = statvfs.f_frsize
        total_blocks = statvfs.f_blocks
        free_blocks = statvfs.f_bfree

        total_space = block_size * total_blocks
        free_space = block_size * free_blocks
        used_percent = ((total_space - free_space) / total_space) * 100

        if used_percent > 80:
            alert_path = "/Eden/DATA/alerts.json"
            alert_data = {
                "alert": "Disk usage exceeds 80%",
                "percent_used": round(used_percent, 2)
            }
            with open(alert_path, 'w') as f:
                json.dump(alert_data, f)
            print("Disk usage exceeds 80% - alert written to alerts.json")
        else:
            print("Disk usage is under 80% - no alert needed")
    except Exception as e:
        print(f"Error checking disk usage: {e}")

if __name__ == '__main__':
    check_disk_usage()