- Reset master to upstream/main (16,697 commits) - Overlay 2,271 local-only files (skills, tools, workspace, configs, apps) - Restore IDENTITY.md and USER.md templates - Build verified, gateway running, Discord working Co-Authored-By: Claude Opus 4.6 <[email protected]>
93 lines
3.1 KiB
Bash
93 lines
3.1 KiB
Bash
#!/usr/bin/env bash
|
|
# Jarvis Predictive Alerts
|
|
# Learn patterns and alert before failures
|
|
|
|
set -euo pipefail
|
|
|
|
METRICS_DIR="/home/alex/clawd/data/metrics"
|
|
PREDICT_LOG="/home/alex/clawd/logs/jarvis-predict.log"
|
|
|
|
log() {
|
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$PREDICT_LOG"
|
|
}
|
|
|
|
# Create directories
|
|
mkdir -p "$METRICS_DIR"
|
|
mkdir -p "$(dirname "$PREDICT_LOG")"
|
|
|
|
log "=== PREDICTIVE ANALYSIS STARTED ==="
|
|
|
|
# Collect current metrics
|
|
timestamp=$(date '+%s')
|
|
|
|
# Disk usage (Pi)
|
|
if pi_disk=$(timeout 5 ssh -o ConnectTimeout=3 192.168.1.24 'df / | tail -1 | awk "{print \$5}"' 2>/dev/null | sed 's/%//'); then
|
|
echo "$timestamp $pi_disk" >> "$METRICS_DIR/pi_disk.dat"
|
|
log "📊 Pi disk: ${pi_disk}%"
|
|
|
|
# Predict if disk will hit 90% in next 7 days
|
|
if [ -f "$METRICS_DIR/pi_disk.dat" ]; then
|
|
# Get trend from last 24 hours
|
|
day_ago=$((timestamp - 86400))
|
|
recent_data=$(awk -v cutoff="$day_ago" '$1 > cutoff' "$METRICS_DIR/pi_disk.dat" 2>/dev/null || true)
|
|
|
|
if [ -n "$recent_data" ]; then
|
|
# Simple linear regression would go here
|
|
# For MVP: just warn if > 75%
|
|
if [ "$pi_disk" -gt 75 ]; then
|
|
log "⚠️ PREDICTION: Pi disk usage trending high (${pi_disk}%) - may hit 90% soon"
|
|
fi
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
# Memory usage (Pi)
|
|
if pi_mem=$(timeout 5 ssh -o ConnectTimeout=3 192.168.1.24 'free -m | grep Mem | awk "{print int(100*\$3/\$2)}"' 2>/dev/null); then
|
|
echo "$timestamp $pi_mem" >> "$METRICS_DIR/pi_mem.dat"
|
|
log "📊 Pi memory: ${pi_mem}%"
|
|
|
|
if [ "$pi_mem" -gt 85 ]; then
|
|
log "⚠️ PREDICTION: Pi memory high (${pi_mem}%) - possible OOM soon"
|
|
fi
|
|
fi
|
|
|
|
# Gateway response time
|
|
gateway_start=$(date +%s%N)
|
|
if timeout 5 curl -sfk https://192.168.1.220:18789/ >/dev/null 2>&1; then
|
|
gateway_end=$(date +%s%N)
|
|
gateway_ms=$(( (gateway_end - gateway_start) / 1000000 ))
|
|
echo "$timestamp $gateway_ms" >> "$METRICS_DIR/gateway_response.dat"
|
|
log "📊 Gateway response: ${gateway_ms}ms"
|
|
|
|
if [ "$gateway_ms" -gt 2000 ]; then
|
|
log "⚠️ PREDICTION: Gateway slow (${gateway_ms}ms) - may crash soon"
|
|
fi
|
|
fi
|
|
|
|
# Kanban API response time
|
|
kanban_start=$(date +%s%N)
|
|
if timeout 5 curl -sf http://192.168.1.220:5003/api/tasks?limit=1 >/dev/null 2>&1; then
|
|
kanban_end=$(date +%s%N)
|
|
kanban_ms=$(( (kanban_end - kanban_start) / 1000000 ))
|
|
echo "$timestamp $kanban_ms" >> "$METRICS_DIR/kanban_response.dat"
|
|
log "📊 Kanban response: ${kanban_ms}ms"
|
|
|
|
if [ "$kanban_ms" -gt 1000 ]; then
|
|
log "⚠️ PREDICTION: Kanban slow (${kanban_ms}ms) - database may need optimization"
|
|
fi
|
|
fi
|
|
|
|
# Check for crash patterns
|
|
if [ -f /var/log/syslog ]; then
|
|
recent_crashes=$(tail -1000 /var/log/syslog 2>/dev/null | grep -c "segfault\|Out of memory\|kernel panic" || echo "0")
|
|
|
|
if [ "$recent_crashes" -gt 0 ]; then
|
|
log "⚠️ PATTERN: $recent_crashes crash indicators in syslog - instability detected"
|
|
fi
|
|
fi
|
|
|
|
# Cleanup old metrics (keep 30 days)
|
|
find "$METRICS_DIR" -name "*.dat" -type f -mtime +30 -delete 2>/dev/null || true
|
|
|
|
log "=== PREDICTIVE ANALYSIS COMPLETE ==="
|