Skip to main content
Glama
healthcheck.sh5.54 kB
#!/bin/sh # Health check script for Azure AI MCP Server # This script performs comprehensive health checks for the containerized application set -e # Configuration HEALTH_ENDPOINT="http://localhost:3000/health" READY_ENDPOINT="http://localhost:3000/ready" TIMEOUT=10 MAX_RETRIES=3 # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Logging function log() { echo "$(date '+%Y-%m-%d %H:%M:%S') [HEALTHCHECK] $1" } # Check if curl is available if ! command -v curl >/dev/null 2>&1; then log "${RED}ERROR: curl is not available${NC}" exit 1 fi # Function to check HTTP endpoint check_endpoint() { local endpoint=$1 local expected_status=${2:-200} local retry_count=0 while [ $retry_count -lt $MAX_RETRIES ]; do if response=$(curl -s -w "%{http_code}" -o /dev/null --max-time $TIMEOUT "$endpoint" 2>/dev/null); then if [ "$response" = "$expected_status" ]; then log "${GREEN}✓ $endpoint responded with status $response${NC}" return 0 else log "${YELLOW}⚠ $endpoint responded with status $response (expected $expected_status)${NC}" fi else log "${YELLOW}⚠ Failed to connect to $endpoint (attempt $((retry_count + 1))/$MAX_RETRIES)${NC}" fi retry_count=$((retry_count + 1)) if [ $retry_count -lt $MAX_RETRIES ]; then sleep 2 fi done log "${RED}✗ $endpoint health check failed after $MAX_RETRIES attempts${NC}" return 1 } # Function to check process check_process() { if pgrep -f "node.*index.js" >/dev/null 2>&1; then log "${GREEN}✓ Node.js process is running${NC}" return 0 else log "${RED}✗ Node.js process is not running${NC}" return 1 fi } # Function to check memory usage check_memory() { local memory_limit_mb=2048 # 2GB limit local memory_usage_mb if command -v free >/dev/null 2>&1; then memory_usage_mb=$(free -m | awk 'NR==2{printf "%.0f", $3}') if [ "$memory_usage_mb" -lt "$memory_limit_mb" ]; then log "${GREEN}✓ Memory usage: ${memory_usage_mb}MB (limit: ${memory_limit_mb}MB)${NC}" return 0 else log "${RED}✗ Memory usage: ${memory_usage_mb}MB exceeds limit: ${memory_limit_mb}MB${NC}" return 1 fi else log "${YELLOW}⚠ Cannot check memory usage (free command not available)${NC}" return 0 fi } # Function to check disk space check_disk_space() { local disk_usage_percent local disk_limit_percent=90 disk_usage_percent=$(df /app | awk 'NR==2 {print $5}' | sed 's/%//') if [ "$disk_usage_percent" -lt "$disk_limit_percent" ]; then log "${GREEN}✓ Disk usage: ${disk_usage_percent}% (limit: ${disk_limit_percent}%)${NC}" return 0 else log "${RED}✗ Disk usage: ${disk_usage_percent}% exceeds limit: ${disk_limit_percent}%${NC}" return 1 fi } # Function to check log files check_logs() { local log_dir="/app/logs" local max_log_size_mb=100 if [ -d "$log_dir" ]; then # Check if logs directory is writable if [ -w "$log_dir" ]; then log "${GREEN}✓ Logs directory is writable${NC}" else log "${RED}✗ Logs directory is not writable${NC}" return 1 fi # Check log file sizes for log_file in "$log_dir"/*.log; do if [ -f "$log_file" ]; then log_size_mb=$(du -m "$log_file" | cut -f1) if [ "$log_size_mb" -gt "$max_log_size_mb" ]; then log "${YELLOW}⚠ Log file $log_file is ${log_size_mb}MB (exceeds ${max_log_size_mb}MB)${NC}" fi fi done else log "${YELLOW}⚠ Logs directory does not exist${NC}" fi return 0 } # Function to check environment variables check_environment() { local required_vars="AZURE_OPENAI_ENDPOINT AZURE_OPENAI_API_KEY AZURE_COGNITIVE_SERVICES_ENDPOINT" local missing_vars="" for var in $required_vars; do if [ -z "$(eval echo \$$var)" ]; then missing_vars="$missing_vars $var" fi done if [ -z "$missing_vars" ]; then log "${GREEN}✓ All required environment variables are set${NC}" return 0 else log "${RED}✗ Missing required environment variables:$missing_vars${NC}" return 1 fi } # Main health check function main() { log "Starting comprehensive health check..." local exit_code=0 # Check if the main process is running if ! check_process; then exit_code=1 fi # Check environment variables if ! check_environment; then exit_code=1 fi # Check system resources if ! check_memory; then exit_code=1 fi if ! check_disk_space; then exit_code=1 fi # Check log files check_logs # Check application endpoints if ! check_endpoint "$HEALTH_ENDPOINT" 200; then exit_code=1 fi if ! check_endpoint "$READY_ENDPOINT" 200; then exit_code=1 fi # Final status if [ $exit_code -eq 0 ]; then log "${GREEN}✓ All health checks passed${NC}" else log "${RED}✗ One or more health checks failed${NC}" fi return $exit_code } # Run the health check main "$@"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/caiotk/nexguideai-azure-ai-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server