#!/bin/bash # Quick Health Check - Simplified version # Wave 75 Agent 6 RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' PASSED=0 FAILED=0 WARNINGS=0 echo -e "${BLUE}=== Foxhunt HFT Quick Health Check ===${NC}\n" # 1. gRPC Services echo -e "${BLUE}[1/4] Checking gRPC Services...${NC}" services=( "Trading Service:50051" "Backtesting Service:50052" "ML Training Service:50053" "API Gateway:50050" ) for svc in "${services[@]}"; do IFS=':' read -r name port <<< "$svc" if timeout 2 grpcurl -plaintext localhost:$port list >/dev/null 2>&1; then echo -e " ${GREEN}✓${NC} $name (port $port)" ((PASSED++)) else echo -e " ${RED}✗${NC} $name (port $port) - NOT RESPONDING" ((FAILED++)) fi done # 2. Infrastructure Services echo -e "\n${BLUE}[2/4] Checking Infrastructure Services...${NC}" # PostgreSQL if PGPASSWORD=test_password psql -h localhost -p 5433 -U foxhunt_test -d foxhunt_test -c "SELECT 1;" >/dev/null 2>&1; then echo -e " ${GREEN}✓${NC} PostgreSQL (port 5433)" ((PASSED++)) else echo -e " ${RED}✗${NC} PostgreSQL (port 5433)" ((FAILED++)) fi # Redis if docker exec api_gateway_test_redis redis-cli PING 2>&1 | grep -q "PONG"; then echo -e " ${GREEN}✓${NC} Redis (port 6380)" ((PASSED++)) else echo -e " ${RED}✗${NC} Redis (port 6380)" ((FAILED++)) fi # Vault if timeout 2 curl -s http://localhost:8200/v1/sys/health | jq -e '.sealed == false' >/dev/null 2>&1; then echo -e " ${GREEN}✓${NC} Vault (port 8200) - UNSEALED" ((PASSED++)) elif timeout 2 curl -s http://localhost:8200/v1/sys/health >/dev/null 2>&1; then echo -e " ${YELLOW}⚠${NC} Vault (port 8200) - SEALED" ((WARNINGS++)) else echo -e " ${RED}✗${NC} Vault (port 8200)" ((FAILED++)) fi # Prometheus if timeout 2 curl -s http://localhost:9099/-/healthy | grep -q "Prometheus"; then echo -e " ${GREEN}✓${NC} Prometheus (port 9099)" ((PASSED++)) else echo -e " ${RED}✗${NC} Prometheus (port 9099)" ((FAILED++)) fi # Grafana if timeout 2 curl -s http://localhost:3000/api/health | jq -e '.database == "ok"' >/dev/null 2>&1; then echo -e " ${GREEN}✓${NC} Grafana (port 3000)" ((PASSED++)) else echo -e " ${YELLOW}⚠${NC} Grafana (port 3000) - responding but may have issues" ((WARNINGS++)) fi # 3. Docker Containers echo -e "\n${BLUE}[3/4] Checking Docker Containers...${NC}" unhealthy=$(docker ps --filter "health=unhealthy" --format "{{.Names}}" 2>/dev/null) if [ -z "$unhealthy" ]; then echo -e " ${GREEN}✓${NC} No unhealthy containers" ((PASSED++)) else echo -e " ${RED}✗${NC} Unhealthy: $unhealthy" ((FAILED++)) fi # 4. Service Processes echo -e "\n${BLUE}[4/4] Checking Service Processes...${NC}" procs=("trading_service" "backtesting_service" "ml_training_service") for proc in "${procs[@]}"; do if pgrep -f "$proc" >/dev/null; then pid=$(pgrep -f "$proc" | head -1) cpu=$(ps -p $pid -o %cpu --no-headers 2>/dev/null | tr -d ' ' || echo "?") mem=$(ps -p $pid -o %mem --no-headers 2>/dev/null | tr -d ' ' || echo "?") echo -e " ${GREEN}✓${NC} $proc (PID: $pid, CPU: ${cpu}%, MEM: ${mem}%)" ((PASSED++)) else echo -e " ${RED}✗${NC} $proc - NOT RUNNING" ((FAILED++)) fi done # Summary TOTAL=$((PASSED + FAILED + WARNINGS)) echo -e "\n${BLUE}=== Summary ===${NC}" echo -e "Total Checks: $TOTAL" echo -e "${GREEN}Passed: $PASSED${NC}" echo -e "${YELLOW}Warnings: $WARNINGS${NC}" echo -e "${RED}Failed: $FAILED${NC}" if [ $FAILED -eq 0 ]; then echo -e "\n${GREEN}Overall Status: HEALTHY${NC}" exit 0 elif [ $FAILED -lt 5 ]; then echo -e "\n${YELLOW}Overall Status: DEGRADED${NC}" exit 1 else echo -e "\n${RED}Overall Status: UNHEALTHY${NC}" exit 2 fi