#!/bin/bash # Foxhunt HFT System - Comprehensive Health Check # Generated by Wave 79 Agent 10 set -e # Color codes GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Check functions check_service() { local name=$1 local port=$2 if netstat -an 2>/dev/null | grep -q "$port.*LISTEN" || ss -an 2>/dev/null | grep -q "$port.*LISTEN"; then echo -e "${GREEN}✓${NC} $name (port $port)" return 0 else echo -e "${RED}✗${NC} $name (port $port) - NOT LISTENING" return 1 fi } check_http() { local name=$1 local url=$2 if curl -s -f "$url" > /dev/null 2>&1; then echo -e "${GREEN}✓${NC} $name - HTTP OK" return 0 else echo -e "${RED}✗${NC} $name - HTTP FAILED" return 1 fi } check_docker() { local container=$1 if docker ps --filter "name=$container" --filter "status=running" | grep -q "$container"; then local health=$(docker inspect --format='{{.State.Health.Status}}' "$container" 2>/dev/null || echo "unknown") if [ "$health" = "healthy" ] || [ "$health" = "unknown" ]; then echo -e "${GREEN}✓${NC} $container (running)" return 0 else echo -e "${YELLOW}⚠${NC} $container (running but $health)" return 1 fi else echo -e "${RED}✗${NC} $container - NOT RUNNING" return 1 fi } # Main health check echo "================================================================================" echo "Foxhunt HFT System - Health Check" echo "================================================================================" echo "" date echo "" # Foxhunt Services echo -e "${BLUE}Foxhunt Services:${NC}" check_service "Trading Service" "50051" check_service "Backtesting Service" "50052" check_service "ML Training Service" "50053" check_service "API Gateway" "50050" echo "" # Infrastructure echo -e "${BLUE}Infrastructure Services:${NC}" check_docker "api_gateway_test_postgres" check_docker "api_gateway_test_redis" check_docker "foxhunt-vault" check_docker "foxhunt-prometheus" check_docker "foxhunt-grafana" echo "" # HTTP Endpoints echo -e "${BLUE}HTTP Health Endpoints:${NC}" check_http "Trading Service" "http://localhost:8080/health" check_http "Prometheus" "http://localhost:9099/-/healthy" check_http "Grafana" "http://localhost:3000/api/health" check_http "Vault" "http://localhost:8200/v1/sys/health" echo "" # Database connectivity echo -e "${BLUE}Database Connectivity:${NC}" if docker exec api_gateway_test_postgres psql -U foxhunt_test -d foxhunt_test -c "SELECT 1" > /dev/null 2>&1; then TABLE_COUNT=$(docker exec api_gateway_test_postgres psql -U foxhunt_test -d foxhunt_test -t -c "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'public'" 2>&1 | tr -d ' ') echo -e "${GREEN}✓${NC} PostgreSQL - $TABLE_COUNT tables" else echo -e "${RED}✗${NC} PostgreSQL - CONNECTION FAILED" fi if docker exec api_gateway_test_redis redis-cli PING 2>&1 | grep -q "PONG"; then MEMORY=$(docker exec api_gateway_test_redis redis-cli INFO memory 2>&1 | grep used_memory_human | cut -d: -f2 | tr -d '\r') echo -e "${GREEN}✓${NC} Redis - $MEMORY memory" else echo -e "${RED}✗${NC} Redis - CONNECTION FAILED" fi echo "" # Process stats echo -e "${BLUE}Process Resources:${NC}" ps aux | grep -E "(trading_service|backtesting_service|ml_training_service|api_gateway)" | grep -v grep | awk '{printf " %-30s CPU: %4s%% MEM: %4s%% Uptime: %s\n", substr($11,1,30), $3, $4, $9}' | sort echo "" # Summary echo "================================================================================" echo "Health check complete" echo "================================================================================"