From 7b4ce952d1ffae26a0b8c399c1f87a09ade61d0c Mon Sep 17 00:00:00 2001 From: "sundapeng.sdp" Date: Tue, 30 Sep 2025 09:05:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20exporter=5Fconfig.j?= =?UTF-8?q?son=20=E6=8B=B7=E8=B4=9D=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs #9 --- src/metric/prometheus/build/Dockerfile | 18 +++++++++--------- .../prometheus/build/start-targets-updater.sh | 11 +++++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/metric/prometheus/build/Dockerfile b/src/metric/prometheus/build/Dockerfile index 465ec40..ab0a096 100755 --- a/src/metric/prometheus/build/Dockerfile +++ b/src/metric/prometheus/build/Dockerfile @@ -13,10 +13,8 @@ RUN if [ "$USE_INTRANET" = "true" ]; then \ echo 'Acquire::https::Verify-Host "false";' >> /etc/apt/apt.conf.d/99disable-ssl-check; \ else \ echo "Configuring fast apt sources for external network..." && \ - # 查找并替换sources.list文件 find /etc/apt -name "sources.list*" -exec sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' {} \; && \ find /etc/apt -name "sources.list*" -exec sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' {} \; && \ - # 使用阿里云源 echo "deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse" > /etc/apt/sources.list && \ echo "deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse" >> /etc/apt/sources.list && \ echo "deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse" >> /etc/apt/sources.list; \ @@ -74,23 +72,25 @@ COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf # 启动脚本 COPY start-prometheus-supervised.sh /usr/local/bin/start-prometheus-supervised.sh -RUN chmod +x /usr/local/bin/start-prometheus-supervised.sh +RUN chmod +x /usr/local/bin/start-prometheus-supervised.sh && \ + chown nobody:nogroup /usr/local/bin/start-prometheus-supervised.sh # targets 更新脚本 COPY start-targets-updater.sh /usr/local/bin/start-targets-updater.sh -RUN chmod +x /usr/local/bin/start-targets-updater.sh +RUN chmod +x /usr/local/bin/start-targets-updater.sh && \ + chown nobody:nogroup /usr/local/bin/start-targets-updater.sh # targets 更新 Python 脚本 COPY update_targets.py /usr/local/bin/update_targets.py -RUN chmod +x /usr/local/bin/update_targets.py +RUN chmod +x /usr/local/bin/update_targets.py && \ + chown nobody:nogroup /usr/local/bin/update_targets.py -# exporter 配置文件 -COPY exporter_config.json ${PROMETHEUS_BASE_PATH}/exporter_config.json +# exporter 配置文件 - 复制到内部目录 +COPY exporter_config.json /usr/local/bin/exporter_config.json -# 自定义 prometheus 配置文件 COPY prometheus.yml /etc/prometheus/prometheus.yml -RUN chown nobody:nogroup ${PROMETHEUS_BASE_PATH}/exporter_config.json /etc/prometheus/prometheus.yml +RUN chown nobody:nogroup /usr/local/bin/exporter_config.json /etc/prometheus/prometheus.yml USER root diff --git a/src/metric/prometheus/build/start-targets-updater.sh b/src/metric/prometheus/build/start-targets-updater.sh index 68ac11f..a067003 100755 --- a/src/metric/prometheus/build/start-targets-updater.sh +++ b/src/metric/prometheus/build/start-targets-updater.sh @@ -18,8 +18,19 @@ echo "[INFO] Exporter config file: ${EXPORTER_CONFIG_FILE}" echo "[INFO] Check interval: ${CHECK_INTERVAL}s" echo "[INFO] Log level: ${LOG_LEVEL}" +# 确保目录存在 mkdir -p "${TARGETS_DIR}" +# 检查 EXPORTER_CONFIG_FILE 是否存在,没有则从内部复制 +if [ ! -f "${EXPORTER_CONFIG_FILE}" ]; then + echo "[INFO] exporter_config.json not found at ${EXPORTER_CONFIG_FILE}, copying from internal location..." + cp /usr/local/bin/exporter_config.json "${EXPORTER_CONFIG_FILE}" + chown nobody:nogroup "${EXPORTER_CONFIG_FILE}" + echo "[INFO] Successfully copied exporter_config.json to ${EXPORTER_CONFIG_FILE}" +else + echo "[INFO] exporter_config.json already exists at ${EXPORTER_CONFIG_FILE}, skipping copy" +fi + exec python3 /usr/local/bin/update_targets.py \ --config "${NODES_CONFIG_FILE}" \ --targets-dir "${TARGETS_DIR}" \