#!/usr/bin/env bash
# 检查三个服务的运行状态

set -euo pipefail

echo "=== 服务状态检查 ==="
echo ""

# 检查进程
echo "【进程状态】"
ps aux | grep -E "(vllm|embedding_server|rerank_server)" | grep -v grep || echo "无服务运行"
echo ""

# 检查 GPU
echo "【GPU 显存占用】"
nvidia-smi --query-gpu=memory.used,memory.total --format=csv,noheader
echo ""

# 检查健康端点
echo "【健康检查】"

echo -n "LLM (8100):       "
if curl -sf http://localhost:8100/health > /dev/null 2>&1; then
  echo "✓ 正常"
else
  echo "✗ 异常"
fi

echo -n "Embedding (8200): "
if curl -sf http://localhost:8200/health > /dev/null 2>&1; then
  echo "✓ 正常"
else
  echo "✗ 异常"
fi

echo -n "Reranker (8300):  "
if curl -sf http://localhost:8300/health > /dev/null 2>&1; then
  echo "✓ 正常"
else
  echo "✗ 异常"
fi

echo -n "OCR     (8400):   "
if curl -sf http://localhost:8400/health > /dev/null 2>&1; then
  echo "✓ 正常"
else
  echo "✗ 异常 (dev 模式才启动)"
fi

echo ""
echo "【日志文件】"
echo "LLM:       /lsinfo/ai/hellotax_ai/llm_service/logs/vllm-8100.log"
echo "Embedding: /lsinfo/ai/hellotax_ai/llm_service/logs/embedding-8200.log"
echo "Reranker:  /lsinfo/ai/hellotax_ai/llm_service/logs/reranker-8300.log"
