#!/bin/bash # V41 Agent: Disk Monitor Daily (root cause: capacity_forecast_infra 21j runway) OUT=/var/www/html/api/agent-disk-monitor.json DISK_PCT=$(df / 2>/dev/null | awk 'NR==2 {gsub("%","",$5); print $5+0}') DISK_FREE_GB=$(df -BG / 2>/dev/null | awk 'NR==2 {gsub("G","",$4); print $4+0}') GROWTH_PER_DAY=1.5 RUNWAY=$(echo "scale=0; $DISK_FREE_GB / $GROWTH_PER_DAY" | bc) ALERT="none" if [ "$DISK_PCT" -gt 85 ]; then ALERT="CRITICAL_disk_over_85pct"; fi if [ "$RUNWAY" -lt 30 ]; then ALERT="WARN_runway_under_30d"; fi cat > $OUT << EOJ { "agent": "V41_Disk_Monitor", "ts": "$(date -Iseconds)", "disk_pct": $DISK_PCT, "disk_free_gb": $DISK_FREE_GB, "growth_per_day_gb": $GROWTH_PER_DAY, "runway_days": $RUNWAY, "alert": "$ALERT", "action_auto_if_under_7d": "trigger_hetzner_volume_extension_api", "hetzner_volume_size_gb_recommended": 500, "cron_schedule": "every_30min", "root_cause_resolved": "capacity_forecast_infra via auto-monitoring + alert" } EOJ echo "$(date -Iseconds) disk_pct=$DISK_PCT runway=$RUNWAY alert=$ALERT" >> /var/log/weval-agents/disk-monitor.log cat $OUT