๐พ Disk Space Management Patterns¶
Prevent "Disk Full" outages before they happen.
This pattern goes beyond simple log rotation. It intelligently manages disk space based on usage trends, file types, and application priority.
๐ง The AI Advantage¶
Standard tools just delete files older than X days. ANSAI adds intelligence:
- Predictive Cleaning: "Disk will fill up in 3 days at current rate -> Clean now."
- Context-Aware: "Is this a temp file or a critical backup?"
- Safe Expansion: "Volume is 90% full -> Auto-expand EBS volume (if cloud)."
๐ ๏ธ Implementation¶
1. The Cleanup Policy¶
Define rules in defaults/main.yml:
disk_cleanup_rules:
- path: /var/log/app
pattern: "*.log"
age: 7d
strategy: "archive_then_delete"
- path: /tmp/scratch
pattern: "*"
threshold_percent: 85
strategy: "aggressive_delete"
2. The Playbook¶
3. Intelligent Sensors¶
The monitoring agent watches for: - Rapid fill rate (Log explosion?) - Inode exhaustion (Too many small files?) - Large orphaned files (Deleted but open?)
๐ค Example Workflow¶
- Sensor detects
/varis at 85%. - AI Analyzer checks growth rate. "It's growing 1% per hour."
- Decision Engine triggers
disk_cleanerrole withstrategy: normal. - Validation confirms disk usage dropped to 60%.
- Notification sent to Slack: "Prevented disk outage on web-01. Cleaned 5GB of logs."