[#29] 整合metric模块端到端测试跑通;整合web/alert模块镜像构建
This commit is contained in:
@@ -44,12 +44,18 @@ else
|
||||
fi
|
||||
|
||||
# 复制数据源配置文件到挂载目录
|
||||
if [ -f "/tmp/datasources.yml" ]; then
|
||||
echo "[INFO] Copying datasource configuration to /private/argus/metric/grafana/provisioning/datasources/"
|
||||
cp /tmp/datasources.yml /private/argus/metric/grafana/provisioning/datasources/datasources.yml
|
||||
echo "[INFO] Datasource configuration copied successfully"
|
||||
elif [ -d "/private/argus/metric/grafana/provisioning/datasources" ] && [ "$(ls -A /private/argus/metric/grafana/provisioning/datasources)" ]; then
|
||||
echo "[INFO] Found existing datasource provisioning files in /private/argus/metric/grafana/provisioning/datasources"
|
||||
DS_OUT="/private/argus/metric/grafana/provisioning/datasources/datasources.yml"
|
||||
PROM_DOMAIN="prom.metric.argus.com:9090"
|
||||
|
||||
if [ -f "/tmp/datasources.yml" ] && [ ! -f "$DS_OUT" ]; then
|
||||
echo "[INFO] Initializing datasource provisioning file from /tmp"
|
||||
cp /tmp/datasources.yml "$DS_OUT"
|
||||
fi
|
||||
|
||||
# 统一将数据源 URL 规范为 prom.metric.argus.com:9090
|
||||
if [ -f "$DS_OUT" ]; then
|
||||
sed -i -E "s#^\s*url:\s*http://[^[:space:]]+# url: http://$PROM_DOMAIN#g" "$DS_OUT" || true
|
||||
echo "[INFO] Datasource URL normalized to http://$PROM_DOMAIN"
|
||||
elif [ -d "/etc/grafana/provisioning/datasources" ] && [ "$(ls -A /etc/grafana/provisioning/datasources)" ]; then
|
||||
echo "[INFO] Found datasource provisioning files in /etc/grafana/provisioning/datasources"
|
||||
# 确保数据源配置目录权限正确
|
||||
@@ -65,11 +71,33 @@ if [ -f "/tmp/dashboards.yml" ]; then
|
||||
echo "[INFO] Dashboard configuration copied successfully"
|
||||
fi
|
||||
|
||||
# 复制默认仪表板到挂载目录
|
||||
if [ -f "/tmp/default_dashboard.json" ]; then
|
||||
echo "[INFO] Copying default dashboard to /private/argus/metric/grafana/provisioning/dashboards/"
|
||||
cp /tmp/default_dashboard.json /private/argus/metric/grafana/provisioning/dashboards/default_dashboard.json
|
||||
echo "[INFO] Default dashboard copied successfully"
|
||||
# 复制默认仪表板到挂载目录(按需,不覆盖已存在文件)
|
||||
copy_dashboard_if_missing() {
|
||||
local src="$1"; local dst_name="$2"
|
||||
local dst_dir="/private/argus/metric/grafana/provisioning/dashboards"
|
||||
local dst="$dst_dir/$dst_name"
|
||||
if [ -f "$src" ]; then
|
||||
if [ ! -f "$dst" ]; then
|
||||
echo "[INFO] Installing dashboard: $dst_name"
|
||||
cp "$src" "$dst"
|
||||
else
|
||||
echo "[INFO] Dashboard exists, skip: $dst_name"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
copy_dashboard_if_missing "/tmp/default_dashboard.json" "default_dashboard.json"
|
||||
copy_dashboard_if_missing "/tmp/default_cluster_dashboard.json" "default_cluster_dashboard.json"
|
||||
copy_dashboard_if_missing "/tmp/default_dashboard_by_instance.json" "default_dashboard_by_instance.json"
|
||||
|
||||
# 规范面板中的数据源字段:将字符串 "prometheus" 替换为 null(使用默认数据源)
|
||||
DB_DIR="/private/argus/metric/grafana/provisioning/dashboards"
|
||||
if [ -d "$DB_DIR" ]; then
|
||||
for f in "$DB_DIR"/*.json; do
|
||||
[ -f "$f" ] || continue
|
||||
sed -i -E 's/"datasource"\s*:\s*"prometheus"/"datasource": null/g' "$f" || true
|
||||
done
|
||||
echo "[INFO] Normalized dashboard datasource to default (null)"
|
||||
fi
|
||||
|
||||
# 启动 Grafana
|
||||
|
||||
Reference in New Issue
Block a user