/ scripts / utils / monitor_llm_server.sh
monitor_llm_server.sh
 1  #!/bin/bash
 2  # Monitor Mac Mini LLM Server Status
 3  # Usage: ./monitor_llm_server.sh
 4  
 5  MAC_MINI_IP="${MAC_MINI_IP:-192.168.1.100}"
 6  OLLAMA_ENDPOINT="${OLLAMA_ENDPOINT:-http://${MAC_MINI_IP}:11434}"
 7  
 8  echo "🖥️  ECHO LLM Server Monitor"
 9  echo "================================"
10  echo "Endpoint: $OLLAMA_ENDPOINT"
11  echo ""
12  
13  # Test 1: Network connectivity
14  echo "Test 1: Network Ping..."
15  if ping -c 2 -W 2000 "$MAC_MINI_IP" > /dev/null 2>&1; then
16    echo "✅ Mac Mini is reachable"
17  else
18    echo "❌ Mac Mini is not reachable"
19    echo "   - Check if Mac Mini is on"
20    echo "   - Check network connection"
21    exit 1
22  fi
23  
24  # Test 2: Ollama service
25  echo ""
26  echo "Test 2: Ollama Service..."
27  HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "${OLLAMA_ENDPOINT}/api/tags" --connect-timeout 5)
28  
29  if [ "$HTTP_CODE" = "200" ]; then
30    echo "✅ Ollama service is running"
31  else
32    echo "❌ Ollama service not responding (HTTP: $HTTP_CODE)"
33    echo "   - Check if Ollama is running on Mac Mini"
34    echo "   - Run: launchctl list | grep ollama"
35    exit 1
36  fi
37  
38  # Test 3: Available models
39  echo ""
40  echo "Test 3: Available Models..."
41  MODELS=$(curl -s "${OLLAMA_ENDPOINT}/api/tags" | python3 -m json.tool 2>/dev/null | grep '"name"' | cut -d'"' -f4)
42  
43  if [ -z "$MODELS" ]; then
44    echo "⚠️  No models found"
45  else
46    echo "✅ Found models:"
47    echo "$MODELS" | while read -r model; do
48      echo "   - $model"
49    done
50  fi
51  
52  # Test 4: Response time
53  echo ""
54  echo "Test 4: Response Time..."
55  START_TIME=$(date +%s%3N)
56  curl -s "${OLLAMA_ENDPOINT}/api/tags" > /dev/null
57  END_TIME=$(date +%s%3N)
58  RESPONSE_TIME=$((END_TIME - START_TIME))
59  
60  if [ "$RESPONSE_TIME" -lt 100 ]; then
61    echo "✅ Excellent response time: ${RESPONSE_TIME}ms"
62  elif [ "$RESPONSE_TIME" -lt 500 ]; then
63    echo "⚠️  Good response time: ${RESPONSE_TIME}ms"
64  else
65    echo "❌ Slow response time: ${RESPONSE_TIME}ms"
66    echo "   - Consider using Ethernet instead of WiFi"
67  fi
68  
69  # Test 5: Quick inference test
70  echo ""
71  echo "Test 5: Quick Inference Test..."
72  FIRST_MODEL=$(echo "$MODELS" | head -n 1)
73  
74  if [ -n "$FIRST_MODEL" ]; then
75    echo "Testing with model: $FIRST_MODEL"
76    START_TIME=$(date +%s)
77  
78    RESPONSE=$(curl -s "${OLLAMA_ENDPOINT}/api/generate" \
79      -H "Content-Type: application/json" \
80      -d "{\"model\":\"$FIRST_MODEL\",\"prompt\":\"Say hi\",\"stream\":false,\"options\":{\"num_predict\":10}}" \
81      --max-time 30)
82  
83    END_TIME=$(date +%s)
84    INFERENCE_TIME=$((END_TIME - START_TIME))
85  
86    if echo "$RESPONSE" | grep -q '"response"'; then
87      echo "✅ Inference successful (${INFERENCE_TIME}s)"
88    else
89      echo "❌ Inference failed"
90      echo "   Response: $RESPONSE"
91    fi
92  else
93    echo "⚠️  Skipping (no models available)"
94  fi
95  
96  echo ""
97  echo "================================"
98  echo "✅ All checks passed!"
99  echo ""