#!/bin/bash
# RocketMQ 集群状态检查脚本

echo "=========================================="
echo "  RocketMQ 集群状态检查"
echo "=========================================="
echo ""

# 检查容器状态
echo "容器状态:"
docker ps --filter "name=rocketmq" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"

echo ""
echo "NameServer状态:"
for port in 9876 9877; do
    result=$(curl -s -m 3 "http://localhost:$port" 2>/dev/null || echo "不可用")
    if [[ "$result" != "不可用" ]]; then
        echo "  localhost:$port - 正常"
    else
        echo "  localhost:$port - 异常"
    fi
done

echo ""
echo "Broker集群状态:"
for broker in master-1 master-2 slave-1 slave-2; do
    container="rocketmq-broker-$broker"
    if docker ps --filter "name=$container" --format "{{.Names}}" | grep -q "$container"; then
        echo "  $broker - 运行中"
    else
        echo "  $broker - 已停止"
    fi
done

echo ""
echo "Dashboard状态:"
dashboard=$(curl -s -m 3 "http://localhost:8080" 2>/dev/null && echo "正常" || echo "不可用")
echo "  http://localhost:8080 - $dashboard"

echo ""
