Files
Distributed-Prometheus/edge-agent/config/test-connection.sh
Super User 95a09fd9d8 完善中央与边缘部署、远程写入与监控文档
- 增加中央与边缘完整配置和部署脚本
- 引入 VictoriaMetrics 数据源与 remote_write 故障排查说明
- 新增 edge-agent 配置脚本、ONVIF 自建 exporter 与 ping 监控示例

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-25 04:24:40 -05:00

91 lines
2.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 测试中央服务器连接脚本
# 使用方法: ./test-connection.sh <中央服务器地址> [端口]
set -e
CENTRAL_HOST=${1:-"192.168.1.10"}
CENTRAL_PORT=${2:-"8428"}
echo "=== 测试中央服务器连接 ==="
echo ""
if [ -z "$1" ]; then
echo "使用方法: $0 <中央服务器地址> [端口]"
echo "示例: $0 192.168.1.10 8428"
echo " $0 prometheus.company.com"
echo " $0 prometheus.local 9090"
echo ""
read -p "请输入中央服务器地址 (IP或域名): " CENTRAL_HOST
read -p "请输入端口 (默认8428): " CENTRAL_PORT_INPUT
if [ -n "$CENTRAL_PORT_INPUT" ]; then
CENTRAL_PORT=$CENTRAL_PORT_INPUT
fi
fi
echo "🔧 测试配置:"
echo " 中央服务器地址: $CENTRAL_HOST"
echo " 端口: $CENTRAL_PORT"
echo ""
# 测试域名解析
echo "🌐 测试域名解析..."
if command -v nslookup &> /dev/null; then
nslookup $CENTRAL_HOST
else
echo " nslookup 不可用跳过DNS测试"
fi
# 测试网络连通性
echo ""
echo "📡 测试网络连通性..."
if ping -c 3 $CENTRAL_HOST > /dev/null 2>&1; then
echo " ✅ Ping 成功"
else
echo " ❌ Ping 失败"
fi
# 测试端口连通性
echo ""
echo "🔌 测试端口连通性..."
if command -v nc &> /dev/null; then
if nc -z $CENTRAL_HOST $CENTRAL_PORT 2>/dev/null; then
echo " ✅ 端口 $CENTRAL_PORT 可访问"
else
echo " ❌ 端口 $CENTRAL_PORT 不可访问"
fi
else
echo " nc 不可用,跳过端口测试"
fi
# 测试HTTP连接
echo ""
echo "🌐 测试HTTP连接..."
HTTP_URL="http://$CENTRAL_HOST:$CENTRAL_PORT"
if command -v curl &> /dev/null; then
if curl -s --connect-timeout 5 $HTTP_URL > /dev/null 2>&1; then
echo " ✅ HTTP连接成功: $HTTP_URL"
# 测试VictoriaMetrics API
if curl -s --connect-timeout 5 "$HTTP_URL/api/v1/status" > /dev/null 2>&1; then
echo " ✅ VictoriaMetrics API 可访问"
else
echo " ⚠️ VictoriaMetrics API 不可访问 (可能不是VictoriaMetrics服务)"
fi
else
echo " ❌ HTTP连接失败: $HTTP_URL"
fi
else
echo " curl 不可用跳过HTTP测试"
fi
echo ""
echo "📋 测试完成!"
echo ""
echo "💡 如果连接失败,请检查:"
echo " 1. 网络连接是否正常"
echo " 2. 防火墙是否开放端口 $CENTRAL_PORT"
echo " 3. 中央服务器是否正在运行"
echo " 4. DNS解析是否正确"