mirror of
https://github.com/hpd840321/starRiverProperty.git
synced 2026-06-09 08:20:31 +08:00
feat: add health-check script for all components
Former-commit-id: 2e9a8f37462c5f71ac25a7e7fe707f935584167b
This commit is contained in:
Executable
+53
@@ -0,0 +1,53 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# health-check.sh — 全组件探活检查
|
||||||
|
source "$(dirname "${BASH_SOURCE[0]}")/config/env.sh"
|
||||||
|
|
||||||
|
log_info "=== Health Check ==="
|
||||||
|
FAILED=0
|
||||||
|
PASSED=0
|
||||||
|
|
||||||
|
check_http() {
|
||||||
|
local name="$1"; local url="$2"
|
||||||
|
if curl -sf --max-time 5 "$url" &>/dev/null; then
|
||||||
|
log_ok " $name ($url)"
|
||||||
|
((PASSED++))
|
||||||
|
else
|
||||||
|
log_error " $name ($url) FAILED"
|
||||||
|
((FAILED++))
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_tcp() {
|
||||||
|
local name="$1"; local host="$2"; local port="$3"
|
||||||
|
if nc -z -w3 "$host" "$port" &>/dev/null; then
|
||||||
|
log_ok " $name ($host:$port)"
|
||||||
|
((PASSED++))
|
||||||
|
else
|
||||||
|
log_error " $name ($host:$port) FAILED"
|
||||||
|
((FAILED++))
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
log_info "--- Infrastructure ---"
|
||||||
|
check_http "Consul" "http://$CONSUL_HOST:$CONSUL_PORT/v1/status/leader"
|
||||||
|
check_tcp "Redis" "$REDIS_HOST" "$REDIS_PORT"
|
||||||
|
check_tcp "Kafka" "$KAFKA_HOST" "$KAFKA_PORT"
|
||||||
|
check_http "Nginx" "http://$CONSUL_HOST:$PORT_NGINX"
|
||||||
|
|
||||||
|
log_info "--- Application Services ---"
|
||||||
|
check_http "elevator-v2" "http://127.0.0.1:$PORT_ELEVATOR_V2/actuator/health"
|
||||||
|
check_http "elevator-v1" "http://127.0.0.1:$PORT_ELEVATOR_V1/actuator/health"
|
||||||
|
check_http "crk-std" "http://127.0.0.1:$PORT_CRK_MGMT/actuator/health"
|
||||||
|
check_http "alarm-app" "http://127.0.0.1:$PORT_ALARM_MGMT/actuator/health"
|
||||||
|
|
||||||
|
log_info "--- Databases ---"
|
||||||
|
check_tcp "MySQL" "$MYSQL_HOST" "$MYSQL_PORT"
|
||||||
|
|
||||||
|
log_info "--- Consul Registration ---"
|
||||||
|
CONSUL_SVCS=$(curl -sf "http://$CONSUL_HOST:$CONSUL_PORT/v1/agent/services" 2>/dev/null | python3 -c "import sys,json; print(len(json.load(sys.stdin)))" 2>/dev/null || echo "0")
|
||||||
|
log_info " Registered services: $CONSUL_SVCS"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
log_info "=== Result: $PASSED passed, $FAILED failed ==="
|
||||||
|
|
||||||
|
[[ $FAILED -eq 0 ]] && exit 0 || exit 1
|
||||||
Reference in New Issue
Block a user