← back to Designer Wallcoverings
DW-Agents/agent-health-check.sh
111 lines
#!/bin/bash
# DW-Agents Comprehensive Health Check Script
# Tests all agent endpoints and reports status
echo "================================================"
echo "DW-AGENTS HEALTH CHECK REPORT"
echo "Date: $(date)"
echo "================================================"
echo ""
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Counter variables
TOTAL=0
ONLINE=0
OFFLINE=0
ERRORS=0
# Function to check agent health
check_agent() {
local name=$1
local port=$2
local url="http://45.61.58.125:$port"
TOTAL=$((TOTAL + 1))
# Test with curl
response=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 5 "$url" 2>/dev/null)
if [ "$response" = "200" ] || [ "$response" = "302" ] || [ "$response" = "401" ]; then
echo -e "${GREEN}✅${NC} $name (Port $port): ONLINE - HTTP $response"
ONLINE=$((ONLINE + 1))
elif [ "$response" = "000" ]; then
echo -e "${RED}❌${NC} $name (Port $port): OFFLINE - Connection refused"
OFFLINE=$((OFFLINE + 1))
else
echo -e "${YELLOW}⚠️${NC} $name (Port $port): ERROR - HTTP $response"
ERRORS=$((ERRORS + 1))
fi
}
echo "CHECKING MAIN AGENTS:"
echo "----------------------"
check_agent "Master Hub" 9893
check_agent "Digital Samples" 9879
check_agent "Legal Team" 9878
check_agent "Purchasing Office" 9880
check_agent "Marketing" 9881
check_agent "Agent SKU" 9877
check_agent "Accounting" 9885
check_agent "Zendesk Chat" 9884
check_agent "Server Uptime" 9888
check_agent "Trend Research" 9883
check_agent "Needs Attention" 9886
check_agent "Skills Manager" 9894
check_agent "Crash Loop Resolver" 9895
check_agent "Dashboard Monitor" 9990
echo ""
echo "CHECKING EXECUTIVE DASHBOARDS:"
echo "-------------------------------"
check_agent "Executive CEO" 7120
check_agent "Executive CFO" 7121
check_agent "Executive COO" 7122
check_agent "Executive VP Ops" 7125
check_agent "Shopify Store" 7238
check_agent "Log Monitor" 7239
check_agent "UI Manager" 7240
check_agent "BigQuery Gov" 7677
echo ""
echo "================================================"
echo "SUMMARY:"
echo "================================================"
echo -e "Total Agents: $TOTAL"
echo -e "${GREEN}Online: $ONLINE${NC}"
echo -e "${RED}Offline: $OFFLINE${NC}"
echo -e "${YELLOW}Errors: $ERRORS${NC}"
echo ""
# Check PM2 status
echo "PM2 AGENT STATUS:"
echo "-----------------"
pm2 list | grep -E "dw-|master-hub|legal-team|marketing|accounting|trend|shopify-store|server-uptime" | awk '{print $4" "$6": "$10" (Restarts: "$8")"}'
echo ""
echo "================================================"
echo "RECOMMENDATIONS:"
echo "================================================"
if [ $OFFLINE -gt 0 ]; then
echo "• Some agents are offline. Check PM2 logs for details:"
echo " pm2 logs [agent-name]"
fi
if [ $ERRORS -gt 0 ]; then
echo "• Some agents returned error codes. May need authentication or have issues."
fi
# Check for high restart counts
echo ""
echo "HIGH RESTART COUNTS (>100):"
pm2 jlist 2>/dev/null | jq -r '.[] | select(.name | startswith("dw-")) | select(.pm2_env.restart_time > 100) | "\(.name): \(.pm2_env.restart_time) restarts"' 2>/dev/null
echo ""
echo "Health check complete!"