完善中央与边缘部署、远程写入与监控文档

- 增加中央与边缘完整配置和部署脚本
- 引入 VictoriaMetrics 数据源与 remote_write 故障排查说明
- 新增 edge-agent 配置脚本、ONVIF 自建 exporter 与 ping 监控示例

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Super User
2026-02-25 04:24:40 -05:00
parent 9e37f79a36
commit 95a09fd9d8
52 changed files with 5978 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
#!/bin/bash
# CSV转JSON脚本 - 将设备CSV表格转换为Prometheus监控JSON配置
# 使用方法: ./csv-to-json.sh devices.csv > onvif-targets.json
set -e
CSV_FILE=${1:-"devices.csv"}
OUTPUT_FILE=${2:-"onvif-targets.json"}
# 检查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
# 检查CSV文件是否存在
if [ ! -f "$CSV_FILE" ]; then
echo "❌ CSV文件 $CSV_FILE 不存在"
exit 1
fi
echo "🔄 正在转换 $CSV_FILE$OUTPUT_FILE..."
# 使用jq将CSV转换为JSON
# 1. 读取CSV文件跳过标题行
# 2. 将每行转换为JSON对象
# 3. 构建Prometheus targets格式
tail -n +2 "$CSV_FILE" | while IFS=',' read -r ip device_type model location username password onvif_port; do
# 构建labels对象
labels="{
\"device_type\": \"$device_type\",
\"model\": \"$model\",
\"location\": \"$location\",
\"username\": \"$username\",
\"password\": \"$password\""
# 如果onvif_port不是默认的80则添加到labels中
if [ "$onvif_port" != "80" ] && [ -n "$onvif_port" ]; then
labels="$labels,
\"onvif_port\": \"$onvif_port\""
fi
labels="$labels
}"
# 输出JSON对象
echo "{
\"targets\": [\"$ip\"],
\"labels\": $labels
}"
done | jq -s '.' > "$OUTPUT_FILE"
echo "✅ 转换完成!"
echo "📊 生成了 $(jq length "$OUTPUT_FILE") 个设备配置"
echo "📁 输出文件: $OUTPUT_FILE"
echo ""
echo "🔍 预览生成的JSON:"
jq . "$OUTPUT_FILE"