refactor: 边缘节点与配置精简
- 边缘: Prometheus 改为 vmagent,统一 docker-compose.yml,内存+磁盘缓存 - 边缘脚本: 合并为 deploy.sh [--local],删除 run-edge-local、quick-setup、run-edge-with-cache - 配置: 合并为 update-configs.sh,统一 targets.csv,生成 target-onvif/target-ping/target-topology - 删除 topology-editor、旧格式 devices.csv/ping-targets.csv、setup-remote-write、test-connection - 文档: 更新 EDGE_CACHE、TIANDITU(瓦片改 4090 直连 tile-cache) Made-with: Cursor
This commit is contained in:
@@ -1,68 +1,61 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 更新配置文件脚本 - 从CSV生成所有JSON配置文件
|
||||
# 使用方法: ./update-configs.sh
|
||||
|
||||
# 从 targets.csv 生成 target-onvif.json、target-ping.json、target-topology.geojson
|
||||
# 用法: ./update-configs.sh [targets.csv]
|
||||
set -e
|
||||
|
||||
echo "=== 更新Prometheus监控配置文件 ==="
|
||||
echo ""
|
||||
|
||||
# 检查jq是否安装
|
||||
if ! command -v jq &> /dev/null; then
|
||||
echo "❌ jq未安装,请先安装jq:"
|
||||
echo " Ubuntu/Debian: sudo apt-get install jq"
|
||||
echo " CentOS/RHEL: sudo yum install jq"
|
||||
echo " Alpine: apk add jq"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 进入脚本目录
|
||||
cd "$(dirname "$0")"
|
||||
command -v jq &>/dev/null || { echo "❌ 需要 jq"; exit 1; }
|
||||
|
||||
echo "🔄 正在从CSV文件生成JSON配置..."
|
||||
CSV="${1:-targets.csv}"
|
||||
[ ! -f "$CSV" ] && { echo '[]' > target-onvif.json; echo '[]' > target-ping.json; echo '{"type":"FeatureCollection","features":[]}' > target-topology.geojson; exit 0; }
|
||||
|
||||
# 优先使用统一的 targets.csv
|
||||
if [ -f "targets.csv" ]; then
|
||||
echo "📋 使用统一配置文件 targets.csv..."
|
||||
chmod +x csv-to-targets.sh 2>/dev/null || true
|
||||
./csv-to-targets.sh targets.csv
|
||||
else
|
||||
echo "⚠️ targets.csv 不存在,使用旧格式配置文件..."
|
||||
echo ""
|
||||
|
||||
# 兼容旧格式:生成ONVIF设备配置
|
||||
if [ -f "devices.csv" ]; then
|
||||
echo "📱 生成ONVIF设备配置(从 devices.csv)..."
|
||||
chmod +x csv-to-json.sh 2>/dev/null || true
|
||||
./csv-to-json.sh devices.csv onvif-targets.json
|
||||
else
|
||||
echo "⚠️ devices.csv 不存在,跳过ONVIF设备配置生成"
|
||||
echo "[]" > onvif-targets.json
|
||||
ONVIF=$(mktemp)
|
||||
PING=$(mktemp)
|
||||
TMP=$(mktemp)
|
||||
trap "rm -f $ONVIF $PING $TMP" EXIT
|
||||
|
||||
# target-onvif.json + target-ping.json
|
||||
tail -n +2 "$CSV" | grep -v '^#' | while IFS=',' read -r type ip name role parent uplink_type network device_type model location username password onvif_port lat lon; do
|
||||
type=$(echo "$type" | xargs)
|
||||
ip=$(echo "$ip" | xargs)
|
||||
[ -z "$type" ] && continue
|
||||
|
||||
if [ "$type" = "onvif" ]; then
|
||||
device_type=$(echo "$device_type" | xargs)
|
||||
model=$(echo "$model" | xargs)
|
||||
location=$(echo "$location" | xargs)
|
||||
username=$(echo "$username" | xargs)
|
||||
password=$(echo "$password" | xargs)
|
||||
onvif_port=$(echo "$onvif_port" | xargs)
|
||||
labels="{\"device_type\":\"$device_type\",\"model\":\"$model\",\"location\":\"$location\",\"username\":\"$username\",\"password\":\"$password\""
|
||||
[ -n "$onvif_port" ] && [ "$onvif_port" != "80" ] && labels="${labels%?},\"onvif_port\":\"$onvif_port\"}"
|
||||
echo "{\"targets\":[\"$ip\"],\"labels\":$labels}" >> "$ONVIF"
|
||||
elif [ "$type" = "ping" ]; then
|
||||
name=$(echo "$name" | xargs)
|
||||
network=$(echo "$network" | xargs)
|
||||
role=$(echo "$role" | xargs)
|
||||
parent=$(echo "$parent" | xargs)
|
||||
uplink_type=$(echo "$uplink_type" | xargs)
|
||||
labels="{\"device\":\"$name\""
|
||||
[ -n "$network" ] && labels="$labels,\"network\":\"$network\""
|
||||
[ -n "$role" ] && labels="$labels,\"role\":\"$role\""
|
||||
[ -n "$parent" ] && labels="$labels,\"parent\":\"$parent\""
|
||||
[ -n "$uplink_type" ] && labels="$labels,\"uplink_type\":\"$uplink_type\""
|
||||
labels="$labels}"
|
||||
echo "{\"targets\":[\"$ip\"],\"labels\":$labels}" >> "$PING"
|
||||
fi
|
||||
|
||||
# 兼容旧格式:生成Ping目标配置
|
||||
if [ -f "ping-targets.csv" ]; then
|
||||
echo "🌐 生成Ping目标配置(从 ping-targets.csv)..."
|
||||
chmod +x csv-to-ping-json.sh 2>/dev/null || true
|
||||
./csv-to-ping-json.sh ping-targets.csv ping-targets.json
|
||||
else
|
||||
echo "⚠️ ping-targets.csv 不存在,跳过Ping目标配置生成"
|
||||
echo "[]" > ping-targets.json
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "✅ 所有配置文件已更新!"
|
||||
echo ""
|
||||
echo "📋 生成的文件:"
|
||||
ls -la *.json 2>/dev/null || echo " (无JSON文件生成)"
|
||||
echo ""
|
||||
echo "🔄 配置热重载:"
|
||||
echo " - Prometheus会在5分钟内自动检测并重载配置"
|
||||
echo " - 无需重启Docker容器!"
|
||||
echo ""
|
||||
echo "⚡ 强制立即重载 (可选):"
|
||||
echo " docker-compose restart prometheus-edge"
|
||||
echo ""
|
||||
echo "📝 编辑CSV文件后重新运行此脚本即可更新配置"
|
||||
[ -s "$ONVIF" ] && jq -s '.' "$ONVIF" > target-onvif.json || echo '[]' > target-onvif.json
|
||||
[ -s "$PING" ] && jq -s '.' "$PING" > target-ping.json || echo '[]' > target-ping.json
|
||||
|
||||
# target-topology.geojson
|
||||
tail -n +2 "$CSV" | grep -v '^#' | while IFS=',' read -r type ip name role parent uplink_type network device_type model location username password onvif_port lat lon; do
|
||||
[ -z "$(echo $type | xargs)" ] || [ -z "$(echo $name | xargs)" ] && continue
|
||||
echo "{\"type\":\"$type\",\"ip\":\"$ip\",\"name\":\"$name\",\"role\":\"$role\",\"parent\":\"$parent\",\"uplink_type\":\"$uplink_type\",\"network\":\"$network\",\"device_type\":\"$device_type\",\"model\":\"$model\",\"location\":\"$location\",\"lat\":\"$lat\",\"lon\":\"$lon\"}" >> "$TMP"
|
||||
done
|
||||
jq -s '
|
||||
def toPoint: select(.lat != "" and .lon != "") | {type:"Feature", geometry:{type:"Point", coordinates:[(.lon|tonumber), (.lat|tonumber)]}, properties:{kind:.type, name:.name, role:.role, parent:.parent, ip:.ip, uplink_type:.uplink_type, network:.network, device_type:.device_type, model:.model, location:.location}};
|
||||
def toLine(all): select(.parent != "" and .lat != "" and .lon != "") as $c | (all[] | select(.name == $c.parent and .lat != "" and .lon != "")) as $p | if $p then {type:"Feature", geometry:{type:"LineString", coordinates:[[($p.lon|tonumber), ($p.lat|tonumber)], [($c.lon|tonumber), ($c.lat|tonumber)]]}, properties:{type:"link", from:$p.name, to:$c.name}} else empty end;
|
||||
. as $all | {type:"FeatureCollection", features: ([$all[] | toPoint] + [$all[] | toLine($all)])}
|
||||
' "$TMP" > target-topology.geojson 2>/dev/null || echo '{"type":"FeatureCollection","features":[]}' > target-topology.geojson
|
||||
|
||||
Reference in New Issue
Block a user