13 Commits

Author SHA1 Message Date
xiuting.xu
2a45d40726 Merge branch 'dev_1.0.0_xuxt' into dev_1.0.0_xuxt_2 2025-10-17 17:39:25 +08:00
xiuting.xu
bab771b5e4 [#14] 更新grafana链接 2025-10-17 15:38:24 +08:00
xiuting.xu
9032608e79 [#24] 更新alertmanager的README 2025-10-17 14:11:12 +08:00
xiuting.xu
2b367f9ba1 更新README文档 2025-10-16 17:09:57 +08:00
xiuting.xu
084c0a3719 [#24] 优化alertmanager和web的构建
[#25] 反向代理功能实现
[#14] 前端页面优化
2025-10-16 15:34:20 +08:00
xiuting.xu
abc739b1be [#19] alert和web增加系统集成测试 2025-10-13 16:48:05 +08:00
xiuting.xu
cb213df6f8 [#6] 修改打包镜像 2025-10-13 10:13:36 +08:00
xiuting.xu
ade9dd7d62 [#5] 修改web页面;更新镜像打包 2025-10-13 10:13:35 +08:00
xiuting.xu
54f99b854c [#6] 提供在Prometheus上部署Alertmanager配置,提供配置文件片段; 2025-10-13 10:13:35 +08:00
xiuting.xu
ac15595c8e [#6] 修改Alertmanager的镜像打包,适配算力平台环境 2025-10-13 10:13:35 +08:00
xiuting.xu
f17bc6d312 [#6] alertmanager的容器化部署 2025-10-13 10:13:35 +08:00
xiuting.xu
ac0eb558e9 [#6] 修改web页面 2025-10-13 10:13:34 +08:00
xiuting.xu
ef89e5d7e6 [#5] web网页代码初始化 2025-10-13 10:13:34 +08:00
64 changed files with 525 additions and 2077 deletions

View File

@@ -10,27 +10,20 @@ Usage: $0 [OPTIONS]
Options: Options:
--intranet Use intranet mirror for log/bind builds --intranet Use intranet mirror for log/bind builds
--master-offline Build master offline image (requires src/master/offline_wheels.tar.gz) --master-offline Build master offline image (requires src/master/offline_wheels.tar.gz)
--metric Build metric module images (ftp, prometheus, grafana, test nodes)
--no-cache Build all images without using Docker layer cache --no-cache Build all images without using Docker layer cache
--only LIST Comma-separated targets to build: core,master,metric,web,alert,all
-h, --help Show this help message -h, --help Show this help message
Examples: Examples:
$0 # Build with default sources $0 # Build with default sources
$0 --intranet # Build with intranet mirror $0 --intranet # Build with intranet mirror
$0 --master-offline # Additionally build argus-master:offline $0 --master-offline # Additionally build argus-master:offline
$0 --metric # Additionally build metric module images $0 --intranet --master-offline
$0 --intranet --master-offline --metric
EOF EOF
} }
use_intranet=false use_intranet=false
build_core=true
build_master=true build_master=true
build_master_offline=false build_master_offline=false
build_metric=true
build_web=true
build_alert=true
no_cache=false no_cache=false
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
@@ -48,34 +41,10 @@ while [[ $# -gt 0 ]]; do
build_master_offline=true build_master_offline=true
shift shift
;; ;;
--metric)
build_metric=true
shift
;;
--no-cache) --no-cache)
no_cache=true no_cache=true
shift shift
;; ;;
--only)
if [[ -z ${2:-} ]]; then
echo "--only requires a target list" >&2; exit 1
fi
sel="$2"; shift 2
# reset all, then enable selected
build_core=false; build_master=false; build_metric=false; build_web=false; build_alert=false
IFS=',' read -ra parts <<< "$sel"
for p in "${parts[@]}"; do
case "$p" in
core) build_core=true ;;
master) build_master=true ;;
metric) build_metric=true ;;
web) build_web=true ;;
alert) build_alert=true ;;
all) build_core=true; build_master=true; build_metric=true; build_web=true; build_alert=true ;;
*) echo "Unknown --only target: $p" >&2; exit 1 ;;
esac
done
;;
-h|--help) -h|--help)
show_help show_help
exit 0 exit 0
@@ -146,22 +115,14 @@ build_image() {
local image_name=$1 local image_name=$1
local dockerfile_path=$2 local dockerfile_path=$2
local tag=$3 local tag=$3
local context="."
shift 3 shift 3
if [[ $# -gt 0 ]]; then
context=$1
shift
fi
local extra_args=("$@") local extra_args=("$@")
echo "🔄 Building $image_name image..." echo "🔄 Building $image_name image..."
echo " Dockerfile: $dockerfile_path" echo " Dockerfile: $dockerfile_path"
echo " Tag: $tag" echo " Tag: $tag"
echo " Context: $context"
if docker build "${build_args[@]}" "${extra_args[@]}" -f "$dockerfile_path" -t "$tag" "$context"; then if docker build "${build_args[@]}" "${extra_args[@]}" -f "$dockerfile_path" -t "$tag" .; then
echo "✅ $image_name image built successfully" echo "✅ $image_name image built successfully"
return 0 return 0
else else
@@ -170,59 +131,29 @@ build_image() {
fi fi
} }
pull_base_image() {
local image_ref=$1
local attempts=${2:-3}
local delay=${3:-5}
# If the image already exists locally, skip pulling.
if docker image inspect "$image_ref" >/dev/null 2>&1; then
echo " Local image present; skip pull: $image_ref"
return 0
fi
for ((i=1; i<=attempts; i++)); do
echo " Pulling base image ($i/$attempts): $image_ref"
if docker pull "$image_ref" >/dev/null; then
echo " Base image ready: $image_ref"
return 0
fi
echo " Pull failed: $image_ref"
if (( i < attempts )); then
echo " Retrying in ${delay}s..."
sleep "$delay"
fi
done
echo "❌ Unable to pull base image after ${attempts} attempts: $image_ref"
return 1
}
images_built=() images_built=()
build_failed=false build_failed=false
if [[ "$build_core" == true ]]; then if build_image "Elasticsearch" "src/log/elasticsearch/build/Dockerfile" "argus-elasticsearch:latest"; then
if build_image "Elasticsearch" "src/log/elasticsearch/build/Dockerfile" "argus-elasticsearch:latest"; then images_built+=("argus-elasticsearch:latest")
images_built+=("argus-elasticsearch:latest") else
else build_failed=true
build_failed=true fi
fi
echo "" echo ""
if build_image "Kibana" "src/log/kibana/build/Dockerfile" "argus-kibana:latest"; then if build_image "Kibana" "src/log/kibana/build/Dockerfile" "argus-kibana:latest"; then
images_built+=("argus-kibana:latest") images_built+=("argus-kibana:latest")
else else
build_failed=true build_failed=true
fi fi
echo "" echo ""
if build_image "BIND9" "src/bind/build/Dockerfile" "argus-bind9:latest"; then if build_image "BIND9" "src/bind/build/Dockerfile" "argus-bind9:latest"; then
images_built+=("argus-bind9:latest") images_built+=("argus-bind9:latest")
else else
build_failed=true build_failed=true
fi
fi fi
echo "" echo ""
@@ -253,91 +184,6 @@ if [[ "$build_master" == true ]]; then
popd >/dev/null popd >/dev/null
fi fi
if [[ "$build_metric" == true ]]; then
echo ""
echo "Building Metric module images..."
metric_base_images=(
"ubuntu:22.04"
"ubuntu/prometheus:3-24.04_stable"
"grafana/grafana:11.1.0"
)
for base_image in "${metric_base_images[@]}"; do
if ! pull_base_image "$base_image"; then
build_failed=true
fi
done
metric_builds=(
"Metric FTP|src/metric/ftp/build/Dockerfile|argus-metric-ftp:latest|src/metric/ftp/build"
"Metric Prometheus|src/metric/prometheus/build/Dockerfile|argus-metric-prometheus:latest|src/metric/prometheus/build"
"Metric Grafana|src/metric/grafana/build/Dockerfile|argus-metric-grafana:latest|src/metric/grafana/build"
)
for build_spec in "${metric_builds[@]}"; do
IFS='|' read -r image_label dockerfile_path image_tag build_context <<< "$build_spec"
if build_image "$image_label" "$dockerfile_path" "$image_tag" "$build_context"; then
images_built+=("$image_tag")
else
build_failed=true
fi
echo ""
done
fi
# =======================================
# Web & Alert module images
# =======================================
if [[ "$build_web" == true || "$build_alert" == true ]]; then
echo ""
echo "Building Web and Alert module images..."
# Pre-pull commonly used base images for stability
web_alert_base_images=(
"node:20"
"ubuntu:24.04"
)
for base_image in "${web_alert_base_images[@]}"; do
if ! pull_base_image "$base_image"; then
build_failed=true
fi
done
if [[ "$build_web" == true ]]; then
web_builds=(
"Web Frontend|src/web/build_tools/frontend/Dockerfile|argus-web-frontend:latest|."
"Web Proxy|src/web/build_tools/proxy/Dockerfile|argus-web-proxy:latest|."
)
for build_spec in "${web_builds[@]}"; do
IFS='|' read -r image_label dockerfile_path image_tag build_context <<< "$build_spec"
if build_image "$image_label" "$dockerfile_path" "$image_tag" "$build_context"; then
images_built+=("$image_tag")
else
build_failed=true
fi
echo ""
done
fi
if [[ "$build_alert" == true ]]; then
alert_builds=(
"Alertmanager|src/alert/alertmanager/build/Dockerfile|argus-alertmanager:latest|."
)
for build_spec in "${alert_builds[@]}"; do
IFS='|' read -r image_label dockerfile_path image_tag build_context <<< "$build_spec"
if build_image "$image_label" "$dockerfile_path" "$image_tag" "$build_context"; then
images_built+=("$image_tag")
else
build_failed=true
fi
echo ""
done
fi
fi
echo "=======================================" echo "======================================="
echo "📦 Build Summary" echo "📦 Build Summary"
echo "=======================================" echo "======================================="
@@ -364,6 +210,7 @@ if [[ "$build_master_offline" == true ]]; then
echo "" echo ""
echo "🧳 Master offline wheels 已解压到 $master_offline_dir" echo "🧳 Master offline wheels 已解压到 $master_offline_dir"
fi fi
echo "" echo ""
echo "🚀 Next steps:" echo "🚀 Next steps:"
echo " ./build/save_images.sh --compress # 导出镜像" echo " ./build/save_images.sh --compress # 导出镜像"

View File

@@ -68,12 +68,6 @@ declare -A images=(
["argus-kibana:latest"]="argus-kibana-latest.tar" ["argus-kibana:latest"]="argus-kibana-latest.tar"
["argus-bind9:latest"]="argus-bind9-latest.tar" ["argus-bind9:latest"]="argus-bind9-latest.tar"
["argus-master:offline"]="argus-master-offline.tar" ["argus-master:offline"]="argus-master-offline.tar"
["argus-metric-ftp:latest"]="argus-metric-ftp-latest.tar"
["argus-metric-prometheus:latest"]="argus-metric-prometheus-latest.tar"
["argus-metric-grafana:latest"]="argus-metric-grafana-latest.tar"
["argus-web-frontend:latest"]="argus-web-frontend-latest.tar"
["argus-web-proxy:latest"]="argus-web-proxy-latest.tar"
["argus-alertmanager:latest"]="argus-alertmanager-latest.tar"
) )
# 函数:检查镜像是否存在 # 函数:检查镜像是否存在

View File

@@ -12,8 +12,6 @@ VENV_DIR="$BUILD_ROOT/venv"
AGENT_BUILD_IMAGE="${AGENT_BUILD_IMAGE:-python:3.11-slim-bullseye}" AGENT_BUILD_IMAGE="${AGENT_BUILD_IMAGE:-python:3.11-slim-bullseye}"
AGENT_BUILD_USE_DOCKER="${AGENT_BUILD_USE_DOCKER:-1}" AGENT_BUILD_USE_DOCKER="${AGENT_BUILD_USE_DOCKER:-1}"
# 默认在容器内忽略代理以避免公司内网代理在 Docker 网络不可达导致 pip 失败(可用 0 关闭)
AGENT_BUILD_IGNORE_PROXY="${AGENT_BUILD_IGNORE_PROXY:-1}"
USED_DOCKER=0 USED_DOCKER=0
run_host_build() { run_host_build() {
@@ -73,7 +71,6 @@ run_docker_build() {
pass_env_if_set http_proxy pass_env_if_set http_proxy
pass_env_if_set https_proxy pass_env_if_set https_proxy
pass_env_if_set no_proxy pass_env_if_set no_proxy
pass_env_if_set AGENT_BUILD_IGNORE_PROXY
build_script=$(cat <<'INNER' build_script=$(cat <<'INNER'
set -euo pipefail set -euo pipefail
@@ -85,10 +82,6 @@ rm -rf build dist
mkdir -p build/pyinstaller dist mkdir -p build/pyinstaller dist
python3 -m venv --copies build/venv python3 -m venv --copies build/venv
source build/venv/bin/activate source build/venv/bin/activate
# 若指定忽略代理,则清空常见代理与 pip 镜像环境变量,避免容器内代理不可达
if [ "${AGENT_BUILD_IGNORE_PROXY:-1}" = "1" ]; then
unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY PIP_INDEX_URL PIP_EXTRA_INDEX_URL PIP_TRUSTED_HOST
fi
pip install --upgrade pip pip install --upgrade pip
pip install . pip install .
pip install pyinstaller==6.6.0 pip install pyinstaller==6.6.0

View File

@@ -9,21 +9,21 @@ RUN apt-get update && \
apt-get install -y wget supervisor net-tools inetutils-ping vim ca-certificates passwd && \ apt-get install -y wget supervisor net-tools inetutils-ping vim ca-certificates passwd && \
apt-get clean && rm -rf /var/lib/apt/lists/* apt-get clean && rm -rf /var/lib/apt/lists/*
# 设置 Alertmanager 版本(与本地离线包保持一致) # 设置 Alertmanager 版本
ARG ALERTMANAGER_VERSION=0.28.1 ARG ALERTMANAGER_VERSION=0.28.1
# 使用仓库内预置的离线包构建(无需联网) # 下载并解压 Alertmanager 二进制
COPY src/alert/alertmanager/build/alertmanager-${ALERTMANAGER_VERSION}.linux-amd64.tar.gz /tmp/ RUN wget https://github.com/prometheus/alertmanager/releases/download/v${ALERTMANAGER_VERSION}/alertmanager-${ALERTMANAGER_VERSION}.linux-amd64.tar.gz && \
RUN tar xvf /tmp/alertmanager-${ALERTMANAGER_VERSION}.linux-amd64.tar.gz -C /tmp && \ tar xvf alertmanager-${ALERTMANAGER_VERSION}.linux-amd64.tar.gz && \
mv /tmp/alertmanager-${ALERTMANAGER_VERSION}.linux-amd64 /usr/local/alertmanager && \ mv alertmanager-${ALERTMANAGER_VERSION}.linux-amd64 /usr/local/alertmanager && \
rm -f /tmp/alertmanager-${ALERTMANAGER_VERSION}.linux-amd64.tar.gz rm alertmanager-${ALERTMANAGER_VERSION}.linux-amd64.tar.gz
ENV ALERTMANAGER_BASE_PATH=/private/argus/alert/alertmanager ENV ALERTMANAGER_BASE_PATH=/private/argus/alert/alertmanager
ARG ARGUS_BUILD_UID=2133 ARG ARGUS_UID=2133
ARG ARGUS_BUILD_GID=2015 ARG ARGUS_GID=2015
ENV ARGUS_BUILD_UID=${ARGUS_BUILD_UID} ENV ARGUS_UID=${ARGUS_UID}
ENV ARGUS_BUILD_GID=${ARGUS_BUILD_GID} ENV ARGUS_GID=${ARGUS_GID}
RUN mkdir -p /usr/share/alertmanager && \ RUN mkdir -p /usr/share/alertmanager && \
mkdir -p ${ALERTMANAGER_BASE_PATH} && \ mkdir -p ${ALERTMANAGER_BASE_PATH} && \
@@ -33,24 +33,16 @@ RUN mkdir -p /usr/share/alertmanager && \
# 创建 alertmanager 用户(可自定义 UID/GID) # 创建 alertmanager 用户(可自定义 UID/GID)
# 创建 alertmanager 用户组 # 创建 alertmanager 用户组
RUN set -eux; \ RUN groupadd -g ${ARGUS_GID} alertmanager
# 确保目标 GID 存在;若已被占用,直接使用该 GID(组名不限)\
if ! getent group "${ARGUS_BUILD_GID}" >/dev/null; then \
groupadd -g "${ARGUS_BUILD_GID}" alertmanager || true; \
fi; \
# 确保存在 alertmanager 用户;若 UID 已被占用,跳过并继续使用现有 UID 的用户
if ! id alertmanager >/dev/null 2>&1; then \
if getent passwd "${ARGUS_BUILD_UID}" >/dev/null; then \
# UID 已占用,则创建同名用户但不指定 UID(避免冲突),仅保证 user 存在
useradd -M -s /usr/sbin/nologin -g "${ARGUS_BUILD_GID}" alertmanager || true; \
else \
useradd -M -s /usr/sbin/nologin -u "${ARGUS_BUILD_UID}" -g "${ARGUS_BUILD_GID}" alertmanager || true; \
fi; \
else \
usermod -g "${ARGUS_BUILD_GID}" alertmanager || true; \
fi
RUN chown -R "${ARGUS_BUILD_UID}:${ARGUS_BUILD_GID}" /usr/share/alertmanager /alertmanager ${ALERTMANAGER_BASE_PATH} /private/argus/etc /usr/local/bin || true # 创建 alertmanager 用户并指定组
RUN useradd -M -s /usr/sbin/nologin -u ${ARGUS_UID} -g ${ARGUS_GID} alertmanager
RUN chown -R alertmanager:alertmanager /usr/share/alertmanager && \
chown -R alertmanager:alertmanager /alertmanager && \
chown -R alertmanager:alertmanager ${ALERTMANAGER_BASE_PATH} && \
chown -R alertmanager:alertmanager /private/argus/etc && \
chown -R alertmanager:alertmanager /usr/local/bin
# 配置内网 apt 源 (如果指定了内网选项) # 配置内网 apt 源 (如果指定了内网选项)
RUN if [ "$USE_INTRANET" = "true" ]; then \ RUN if [ "$USE_INTRANET" = "true" ]; then \
@@ -94,3 +86,4 @@ EXPOSE 9093
# 使用 supervisor 作为入口点 # 使用 supervisor 作为入口点
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

View File

@@ -5,8 +5,8 @@ docker pull ubuntu:24.04
source src/alert/tests/.env source src/alert/tests/.env
docker build \ docker build \
--build-arg ARGUS_BUILD_UID=${ARGUS_BUILD_UID} \ --build-arg ARGUS_UID=${ARGUS_UID} \
--build-arg ARGUS_BUILD_GID=${ARGUS_BUILD_GID} \ --build-arg ARGUS_GID=${ARGUS_GID} \
-f src/alert/alertmanager/build/Dockerfile \ -f src/alert/alertmanager/build/Dockerfile \
-t argus-alertmanager:latest . -t argus-alertmanager:latest .

View File

@@ -1,22 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
# 下载 Alertmanager 离线安装包到本目录,用于 Docker 构建时 COPY
# 用法:
# ./fetch-dist.sh [version]
# 示例:
# ./fetch-dist.sh 0.28.1
VER="${1:-0.28.1}"
OUT="alertmanager-${VER}.linux-amd64.tar.gz"
URL="https://github.com/prometheus/alertmanager/releases/download/v${VER}/${OUT}"
if [[ -f "$OUT" ]]; then
echo "[INFO] $OUT already exists, skip download"
exit 0
fi
echo "[INFO] Downloading $URL"
curl -fL --retry 3 --connect-timeout 10 -o "$OUT" "$URL"
echo "[OK] Saved to $(pwd)/$OUT"

View File

@@ -7,8 +7,10 @@ ALERTMANAGER_BASE_PATH=${ALERTMANAGER_BASE_PATH:-/private/argus/alert/alertmanag
echo "[INFO] Alertmanager base path: ${ALERTMANAGER_BASE_PATH}" echo "[INFO] Alertmanager base path: ${ALERTMANAGER_BASE_PATH}"
# 使用容器内的 /etc/alertmanager/alertmanager.yml 作为配置文件,避免写入挂载卷导致的权限问题 # 生成配置文件
echo "[INFO] Using /etc/alertmanager/alertmanager.yml as configuration" echo "[INFO] Generating Alertmanager configuration file..."
sed "s|\${ALERTMANAGER_BASE_PATH}|${ALERTMANAGER_BASE_PATH}|g" \
/etc/alertmanager/alertmanager.yml > ${ALERTMANAGER_BASE_PATH}/alertmanager.yml
# 记录容器 IP 地址 # 记录容器 IP 地址

View File

@@ -1,5 +1,5 @@
DATA_ROOT=/home/argus/tmp/private/argus DATA_ROOT=/home/argus/tmp/private/argus
ARGUS_BUILD_UID=1048 ARGUS_UID=1048
ARGUS_BUILD_GID=1048 ARGUS_GID=1048
USE_INTRANET=false USE_INTRANET=false

View File

@@ -4,15 +4,15 @@ services:
context: ../../../ context: ../../../
dockerfile: src/alert/alertmanager/build/Dockerfile dockerfile: src/alert/alertmanager/build/Dockerfile
args: args:
ARGUS_BUILD_UID: ${ARGUS_BUILD_UID:-2133} ARGUS_UID: ${ARGUS_UID:-2133}
ARGUS_BUILD_GID: ${ARGUS_BUILD_GID:-2015} ARGUS_GID: ${ARGUS_GID:-2015}
USE_INTRANET: ${USE_INTRANET:-false} USE_INTRANET: ${USE_INTRANET:-false}
image: argus-alertmanager:latest image: argus-alertmanager:latest
container_name: argus-alertmanager container_name: argus-alertmanager
environment: environment:
- ALERTMANAGER_BASE_PATH=/private/argus/alert/alertmanager - ALERTMANAGER_BASE_PATH=/private/argus/alert/alertmanager
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133} - ARGUS_UID=${ARGUS_UID:-2133}
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015} - ARGUS_GID=${ARGUS_GID:-2015}
ports: ports:
- "${ARGUS_PORT:-9093}:9093" - "${ARGUS_PORT:-9093}:9093"
volumes: volumes:

View File

@@ -26,7 +26,6 @@ RUN apt-get update && \
apt-get install -y \ apt-get install -y \
bind9 \ bind9 \
bind9utils \ bind9utils \
dnsutils \
bind9-doc \ bind9-doc \
supervisor \ supervisor \
net-tools \ net-tools \

View File

@@ -104,26 +104,7 @@ log_info "文件所有者: $OWNER"
# 确保发布目录存在 # 确保发布目录存在
log_info "确保发布目录存在: $PUBLISH_DIR" log_info "确保发布目录存在: $PUBLISH_DIR"
mkdir -p "$PUBLISH_DIR" sudo mkdir -p "$PUBLISH_DIR"
IFS=':' read -r OWNER_UID OWNER_GID <<< "$OWNER"
if [[ -z "$OWNER_UID" || -z "$OWNER_GID" ]]; then
log_error "--owner 格式不正确,应为 uid:gid"
exit 1
fi
CURRENT_UID=$(id -u)
CURRENT_GID=$(id -g)
if [[ "$OWNER_UID" != "$CURRENT_UID" || "$OWNER_GID" != "$CURRENT_GID" ]]; then
if [[ "$CURRENT_UID" -ne 0 ]]; then
log_error "当前用户 (${CURRENT_UID}:${CURRENT_GID}) 无法设置所有者为 ${OWNER_UID}:${OWNER_GID}"
log_error "请以目标用户运行脚本或预先调整目录权限"
exit 1
fi
NEED_CHOWN=true
else
NEED_CHOWN=false
fi
# 创建临时目录用于打包 # 创建临时目录用于打包
TEMP_PACKAGE_DIR="/tmp/argus-metric-package-$$" TEMP_PACKAGE_DIR="/tmp/argus-metric-package-$$"
@@ -227,31 +208,26 @@ fi
TAR_NAME="argus-metric_$(echo $VERSION | tr '.' '_').tar.gz" TAR_NAME="argus-metric_$(echo $VERSION | tr '.' '_').tar.gz"
log_info "创建发布包: $TAR_NAME" log_info "创建发布包: $TAR_NAME"
cd "$TEMP_PACKAGE_DIR" cd "$TEMP_PACKAGE_DIR"
tar -czf "$PUBLISH_DIR/$TAR_NAME" * sudo tar -czf "$PUBLISH_DIR/$TAR_NAME" *
cd - > /dev/null cd - > /dev/null
if [[ "$NEED_CHOWN" == true ]]; then # 设置文件所有者
log_info "设置文件所有者为: $OWNER" log_info "设置文件所有者为: $OWNER"
chown "$OWNER" "$PUBLISH_DIR/$TAR_NAME" sudo chown "$OWNER" "$PUBLISH_DIR/$TAR_NAME"
fi
# 清理临时目录 # 清理临时目录
rm -rf "$TEMP_PACKAGE_DIR" rm -rf "$TEMP_PACKAGE_DIR"
# 更新 LATEST_VERSION 文件 # 更新 LATEST_VERSION 文件
log_info "更新 LATEST_VERSION 文件..." log_info "更新 LATEST_VERSION 文件..."
echo "$VERSION" > "$PUBLISH_DIR/LATEST_VERSION" echo "$VERSION" | sudo tee "$PUBLISH_DIR/LATEST_VERSION" > /dev/null
if [[ "$NEED_CHOWN" == true ]]; then sudo chown "$OWNER" "$PUBLISH_DIR/LATEST_VERSION"
chown "$OWNER" "$PUBLISH_DIR/LATEST_VERSION"
fi
# 复制 DNS 配置文件到发布目录根目录(直接从 config 目录复制) # 复制 DNS 配置文件到发布目录根目录(直接从 config 目录复制)
if [[ -f "config/dns.conf" ]]; then if [[ -f "config/dns.conf" ]]; then
log_info "复制 DNS 配置文件到发布目录根目录..." log_info "复制 DNS 配置文件到发布目录根目录..."
cp "config/dns.conf" "$PUBLISH_DIR/" sudo cp "config/dns.conf" "$PUBLISH_DIR/"
if [[ "$NEED_CHOWN" == true ]]; then sudo chown "$OWNER" "$PUBLISH_DIR/dns.conf"
chown "$OWNER" "$PUBLISH_DIR/dns.conf"
fi
log_success "DNS 配置文件复制完成: $PUBLISH_DIR/dns.conf" log_success "DNS 配置文件复制完成: $PUBLISH_DIR/dns.conf"
else else
log_warning "未找到 config/dns.conf 文件,跳过 DNS 配置文件复制" log_warning "未找到 config/dns.conf 文件,跳过 DNS 配置文件复制"
@@ -260,10 +236,8 @@ fi
# 复制 setup.sh 到发布目录 # 复制 setup.sh 到发布目录
if [[ -f "scripts/setup.sh" ]]; then if [[ -f "scripts/setup.sh" ]]; then
log_info "复制 setup.sh 到发布目录..." log_info "复制 setup.sh 到发布目录..."
cp "scripts/setup.sh" "$PUBLISH_DIR/" sudo cp "scripts/setup.sh" "$PUBLISH_DIR/"
if [[ "$NEED_CHOWN" == true ]]; then sudo chown "$OWNER" "$PUBLISH_DIR/setup.sh"
chown "$OWNER" "$PUBLISH_DIR/setup.sh"
fi
fi fi
# 显示发布结果 # 显示发布结果

View File

@@ -2,18 +2,6 @@ FROM grafana/grafana:11.1.0
USER root USER root
# 构建参数:是否使用内网镜像
ARG USE_INTRANET=false
# 根据是否为内网构建切换 apk 源
RUN if [ "$USE_INTRANET" = "true" ]; then \
echo "Configuring intranet apk repositories..." && \
sed -i 's#https\?://[^/]\+#http://10.68.64.1#g' /etc/apk/repositories; \
else \
echo "Configuring public apk repositories..." && \
sed -i 's#https\?://[^/]\+#https://mirrors.aliyun.com#g' /etc/apk/repositories; \
fi
# 安装必要的工具 # 安装必要的工具
RUN apk add --no-cache \ RUN apk add --no-cache \
supervisor \ supervisor \
@@ -22,11 +10,6 @@ RUN apk add --no-cache \
vim \ vim \
bash bash
# 部署镜像时恢复到部署侧使用的内网镜像源
RUN if [ "$USE_INTRANET" = "true" ]; then \
sed -i 's#https\?://[^/]\+#https://10.92.132.52/mirrors#g' /etc/apk/repositories; \
fi
# supervisor 日志目录 # supervisor 日志目录
RUN mkdir -p /var/log/supervisor RUN mkdir -p /var/log/supervisor
@@ -65,8 +48,6 @@ COPY grafana.ini /tmp/grafana.ini
COPY datasources/datasources.yml /tmp/datasources.yml COPY datasources/datasources.yml /tmp/datasources.yml
COPY dashboards/dashboards.yml /tmp/dashboards.yml COPY dashboards/dashboards.yml /tmp/dashboards.yml
COPY dashboards/default_dashboard_by_hostname.json /tmp/default_dashboard.json COPY dashboards/default_dashboard_by_hostname.json /tmp/default_dashboard.json
COPY dashboards/default_cluster_dashboard.json /tmp/default_cluster_dashboard.json
COPY dashboards/default_dashboard_by_instance.json /tmp/default_dashboard_by_instance.json
# supervisor 配置 # supervisor 配置
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

View File

@@ -8,7 +8,7 @@ datasources:
type: prometheus type: prometheus
access: proxy access: proxy
uid: eezk1zvkie4g0a uid: eezk1zvkie4g0a
url: http://prom.metric.argus.com:9090 url: http://10.211.55.5:9090
isDefault: true isDefault: true
editable: true editable: true
jsonData: jsonData:

View File

@@ -44,18 +44,12 @@ else
fi fi
# 复制数据源配置文件到挂载目录 # 复制数据源配置文件到挂载目录
DS_OUT="/private/argus/metric/grafana/provisioning/datasources/datasources.yml" if [ -f "/tmp/datasources.yml" ]; then
PROM_DOMAIN="prom.metric.argus.com:9090" echo "[INFO] Copying datasource configuration to /private/argus/metric/grafana/provisioning/datasources/"
cp /tmp/datasources.yml /private/argus/metric/grafana/provisioning/datasources/datasources.yml
if [ -f "/tmp/datasources.yml" ] && [ ! -f "$DS_OUT" ]; then echo "[INFO] Datasource configuration copied successfully"
echo "[INFO] Initializing datasource provisioning file from /tmp" elif [ -d "/private/argus/metric/grafana/provisioning/datasources" ] && [ "$(ls -A /private/argus/metric/grafana/provisioning/datasources)" ]; then
cp /tmp/datasources.yml "$DS_OUT" echo "[INFO] Found existing datasource provisioning files in /private/argus/metric/grafana/provisioning/datasources"
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 elif [ -d "/etc/grafana/provisioning/datasources" ] && [ "$(ls -A /etc/grafana/provisioning/datasources)" ]; then
echo "[INFO] Found datasource provisioning files in /etc/grafana/provisioning/datasources" echo "[INFO] Found datasource provisioning files in /etc/grafana/provisioning/datasources"
# 确保数据源配置目录权限正确 # 确保数据源配置目录权限正确
@@ -71,33 +65,11 @@ if [ -f "/tmp/dashboards.yml" ]; then
echo "[INFO] Dashboard configuration copied successfully" echo "[INFO] Dashboard configuration copied successfully"
fi fi
# 复制默认仪表板到挂载目录(按需,不覆盖已存在文件) # 复制默认仪表板到挂载目录
copy_dashboard_if_missing() { if [ -f "/tmp/default_dashboard.json" ]; then
local src="$1"; local dst_name="$2" echo "[INFO] Copying default dashboard to /private/argus/metric/grafana/provisioning/dashboards/"
local dst_dir="/private/argus/metric/grafana/provisioning/dashboards" cp /tmp/default_dashboard.json /private/argus/metric/grafana/provisioning/dashboards/default_dashboard.json
local dst="$dst_dir/$dst_name" echo "[INFO] Default dashboard copied successfully"
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 fi
# 启动 Grafana # 启动 Grafana

View File

@@ -61,25 +61,10 @@ RUN mkdir -p ${PROMETHEUS_BASE_PATH}/rules \
&& ln -s ${PROMETHEUS_BASE_PATH} /prometheus && ln -s ${PROMETHEUS_BASE_PATH} /prometheus
# 修改 Prometheus 用户 UID/GID 并授权 # 修改 Prometheus 用户 UID/GID 并授权
RUN set -eux; \ RUN usermod -u ${ARGUS_BUILD_UID} nobody && \
existing_user=""; \ groupmod -g ${ARGUS_BUILD_GID} nogroup && \
if getent passwd "${ARGUS_BUILD_UID}" >/dev/null 2>&1; then \ chown -h nobody:nogroup /prometheus && \
existing_user="$(getent passwd "${ARGUS_BUILD_UID}" | cut -d: -f1)"; \ chown -R nobody:nogroup ${PROMETHEUS_BASE_PATH} && \
fi; \
if [ -n "$existing_user" ] && [ "$existing_user" != "nobody" ]; then \
userdel -r "$existing_user" || true; \
fi; \
existing_group=""; \
if getent group "${ARGUS_BUILD_GID}" >/dev/null 2>&1; then \
existing_group="$(getent group "${ARGUS_BUILD_GID}" | cut -d: -f1)"; \
fi; \
if [ -n "$existing_group" ] && [ "$existing_group" != "nogroup" ]; then \
groupdel "$existing_group" || true; \
fi; \
usermod -u ${ARGUS_BUILD_UID} nobody; \
groupmod -g ${ARGUS_BUILD_GID} nogroup; \
chown -h nobody:nogroup /prometheus; \
chown -R nobody:nogroup ${PROMETHEUS_BASE_PATH}; \
chown -R nobody:nogroup /etc/prometheus chown -R nobody:nogroup /etc/prometheus
# supervisor 配置 # supervisor 配置

View File

@@ -5,6 +5,13 @@ networks:
services: services:
ftp: ftp:
build:
context: ../ftp/build
dockerfile: Dockerfile
args:
ARGUS_BUILD_UID: ${ARGUS_BUILD_UID:-2133}
ARGUS_BUILD_GID: ${ARGUS_BUILD_GID:-2015}
USE_INTRANET: ${USE_INTRANET:-false}
image: argus-metric-ftp:latest image: argus-metric-ftp:latest
container_name: argus-ftp container_name: argus-ftp
restart: unless-stopped restart: unless-stopped
@@ -34,6 +41,13 @@ services:
max-file: "3" max-file: "3"
prometheus: prometheus:
build:
context: ../prometheus/build
dockerfile: Dockerfile
args:
ARGUS_BUILD_UID: ${ARGUS_BUILD_UID:-2133}
ARGUS_BUILD_GID: ${ARGUS_BUILD_GID:-2015}
USE_INTRANET: ${USE_INTRANET:-false}
image: argus-metric-prometheus:latest image: argus-metric-prometheus:latest
container_name: argus-prometheus container_name: argus-prometheus
restart: unless-stopped restart: unless-stopped
@@ -59,6 +73,12 @@ services:
max-file: "3" max-file: "3"
grafana: grafana:
build:
context: ../grafana/build
dockerfile: Dockerfile
args:
ARGUS_BUILD_UID: ${ARGUS_BUILD_UID:-2133}
ARGUS_BUILD_GID: ${ARGUS_BUILD_GID:-2015}
image: argus-metric-grafana:latest image: argus-metric-grafana:latest
container_name: argus-grafana container_name: argus-grafana
restart: unless-stopped restart: unless-stopped
@@ -89,6 +109,9 @@ services:
max-file: "3" max-file: "3"
test-node: test-node:
build:
context: ./client-test-node/build
dockerfile: Dockerfile
image: argus-metric-test-node:latest image: argus-metric-test-node:latest
container_name: argus-metric-test-node container_name: argus-metric-test-node
hostname: test-metric-node-001 hostname: test-metric-node-001
@@ -120,6 +143,9 @@ services:
max-file: "3" max-file: "3"
test-gpu-node: test-gpu-node:
build:
context: ./client-test-gpu-node/build
dockerfile: Dockerfile
image: argus-metric-test-gpu-node:latest image: argus-metric-test-gpu-node:latest
container_name: argus-metric-test-gpu-node container_name: argus-metric-test-gpu-node
hostname: test-metric-gpu-node-001 hostname: test-metric-gpu-node-001

View File

@@ -3,8 +3,15 @@ set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# 解析参数
REBUILD_FLAG=""
if [[ "$1" == "--rebuild" || "$1" == "-r" ]]; then
REBUILD_FLAG="--rebuild"
echo "[01] 启用强制重新构建模式"
fi
echo "[01] 启动所有服务..." echo "[01] 启动所有服务..."
bash "$SCRIPT_DIR/common/start-all.sh" bash "$SCRIPT_DIR/common/start-all.sh" $REBUILD_FLAG
echo "[01] 等待服务就绪..." echo "[01] 等待服务就绪..."
sleep 5 sleep 5

View File

@@ -1,9 +1,6 @@
#!/bin/bash #!/bin/bash
set -e set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
COMMON_DIR="$SCRIPT_DIR/common"
FTP_SERVER="${FTP_SERVER:-172.30.0.40}" FTP_SERVER="${FTP_SERVER:-172.30.0.40}"
FTP_USER="${FTP_USER:-ftpuser}" FTP_USER="${FTP_USER:-ftpuser}"
FTP_PASSWORD="${FTP_PASSWORD:-ZGClab1234!}" FTP_PASSWORD="${FTP_PASSWORD:-ZGClab1234!}"
@@ -11,37 +8,26 @@ FTP_PORT="${FTP_PORT:-21}"
FTP_HOST="${FTP_SERVER}" FTP_HOST="${FTP_SERVER}"
echo "[04] 检测GPU环境..." echo "[03] 进入测试节点执行安装..."
# 检测GPU环境 echo "[03] 使用 FTP 地址: ${FTP_HOST}:${FTP_PORT}"
if bash "$COMMON_DIR/check-gpu.sh"; then
echo "[04] GPU环境可用,继续执行GPU节点安装"
GPU_AVAILABLE=true
else
echo "[04] GPU环境不可用,跳过GPU节点安装"
GPU_AVAILABLE=false
exit 0
fi
echo "[04] 进入测试节点执行安装..."
echo "[04] 使用 FTP 地址: ${FTP_HOST}:${FTP_PORT}"
docker exec argus-metric-test-gpu-node bash -c " docker exec argus-metric-test-gpu-node bash -c "
set -e set -e
if ! command -v curl &>/dev/null; then if ! command -v curl &>/dev/null; then
echo '[04] curl 未安装,正在安装...' echo '[03] curl 未安装,正在安装...'
apt-get update && apt-get install -y curl apt-get update && apt-get install -y curl
fi fi
cd /tmp cd /tmp
echo '[04] 下载 setup.sh...' echo '[03] 下载 setup.sh...'
curl -u ${FTP_USER}:${FTP_PASSWORD} ftp://${FTP_HOST}:${FTP_PORT}/setup.sh -o setup.sh curl -u ${FTP_USER}:${FTP_PASSWORD} ftp://${FTP_HOST}:${FTP_PORT}/setup.sh -o setup.sh
echo '[04] 执行安装...' echo '[03] 执行安装...'
chmod +x setup.sh chmod +x setup.sh
bash setup.sh --server ${FTP_HOST} --user ${FTP_USER} --password '${FTP_PASSWORD}' --port ${FTP_PORT} bash setup.sh --server ${FTP_HOST} --user ${FTP_USER} --password '${FTP_PASSWORD}' --port ${FTP_PORT}
echo '[04] 安装完成' echo '[03] 安装完成'
" "
echo "[04] 完成" echo "[03] 完成"

View File

@@ -1,59 +0,0 @@
#!/bin/bash
# GPU环境检测脚本
# 检测系统是否有NVIDIA GPU硬件
set -e
# 检测函数
check_gpu_support() {
echo "检测GPU环境..."
# 方法1: 检测GPU设备文件
if ls /dev/nvidia* &>/dev/null; then
echo "✓ 检测到NVIDIA GPU设备文件"
return 0
fi
# 方法2: 检测lspci中的NVIDIA设备(Linux)
if command -v lspci &> /dev/null; then
if lspci | grep -i nvidia &> /dev/null; then
echo "✓ 检测到NVIDIA GPU硬件"
return 0
fi
fi
# 方法3: 检测nvidia-smi
if command -v nvidia-smi &> /dev/null; then
if nvidia-smi &> /dev/null; then
echo "✓ 检测到NVIDIA GPU硬件"
return 0
fi
fi
echo "✗ 未检测到NVIDIA GPU硬件"
return 1
}
# 主函数
main() {
echo "=========================================="
echo " GPU环境检测"
echo "=========================================="
echo ""
if check_gpu_support; then
echo ""
echo "结果: GPU环境可用"
exit 0
else
echo ""
echo "结果: GPU环境不可用,将跳过GPU相关服务"
exit 1
fi
}
# 如果直接运行此脚本
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
main "$@"
fi

View File

@@ -1,8 +1,7 @@
#!/bin/bash #!/bin/bash
# 一键启动脚本 # 一键启动脚本
# 用于初始化目录并启动所有服务 # 用于初始化目录、构建镜像并启动所有服务
# 镜像构建已移至 build/build_images.sh
set -e set -e
@@ -10,6 +9,12 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEST_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" TEST_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
cd "$TEST_DIR" cd "$TEST_DIR"
# 解析参数
FORCE_REBUILD=false
if [[ "$1" == "--rebuild" ]]; then
FORCE_REBUILD=true
fi
echo "==========================================" echo "=========================================="
echo " Argus Metrics 一键启动脚本" echo " Argus Metrics 一键启动脚本"
echo "==========================================" echo "=========================================="
@@ -32,6 +37,26 @@ echo "使用: docker compose"
echo "Compose 文件: $TEST_DIR/docker-compose.yml" echo "Compose 文件: $TEST_DIR/docker-compose.yml"
echo "" echo ""
# 检查必要的构建目录
echo "检查构建目录..."
BUILD_DIRS=(
"../ftp/build"
"../prometheus/build"
"../grafana/build"
"client-test-node/build"
"client-test-gpu-node/build"
)
for dir in "${BUILD_DIRS[@]}"; do
if [ ! -d "$dir" ]; then
echo "错误: 构建目录不存在: $dir"
echo "完整路径: $(cd "$(dirname "$dir")" 2>/dev/null && pwd)/$(basename "$dir")"
exit 1
else
echo " ✓ 找到: $dir"
fi
done
echo ""
# 检查并创建 .env 文件 # 检查并创建 .env 文件
if [ ! -f .env ]; then if [ ! -f .env ]; then
@@ -59,65 +84,118 @@ echo "1. 初始化目录结构..."
bash "$SCRIPT_DIR/init-directories.sh" bash "$SCRIPT_DIR/init-directories.sh"
echo "" echo ""
echo "2. 检测GPU环境..." echo "2. 准备 Docker 镜像..."
# 检测GPU环境
if bash "$SCRIPT_DIR/check-gpu.sh"; then
echo "GPU环境可用,将启动GPU节点"
GPU_AVAILABLE=true
else
echo "GPU环境不可用,跳过GPU节点"
GPU_AVAILABLE=false
fi
echo "" # 检查镜像是否存在
echo "3. 检查 Docker 镜像..." IMAGE_CACHE_DIR="$TEST_DIR/images-cache"
IMAGES=("argus-metric-ftp:latest" "argus-metric-prometheus:latest" "argus-metric-grafana:latest" "argus-metric-test-node:latest" "argus-metric-test-gpu-node:latest")
all_images_exist=true
# 检查必要的镜像是否存在 for image in "${IMAGES[@]}"; do
BASE_IMAGES=("argus-metric-ftp:latest" "argus-metric-prometheus:latest" "argus-metric-grafana:latest" "argus-metric-test-node:latest")
GPU_IMAGES=("argus-metric-test-gpu-node:latest")
# 先检查基础镜像
missing_images=()
for image in "${BASE_IMAGES[@]}"; do
if ! docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "^${image}$"; then if ! docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "^${image}$"; then
missing_images+=("$image") all_images_exist=false
break
fi fi
done done
# 检查GPU镜像(如果GPU环境可用) if $FORCE_REBUILD; then
if [ "$GPU_AVAILABLE" = true ]; then echo "强制重新构建镜像(--rebuild 模式)..."
for image in "${GPU_IMAGES[@]}"; do cd "$TEST_DIR"
docker compose build --no-cache
echo "镜像重新构建完成"
elif $all_images_exist; then
echo "所有镜像已存在,跳过构建"
else
echo "检测到缺失镜像,尝试从缓存加载..."
# 尝试从缓存加载
loaded_from_cache=false
if [ -d "$IMAGE_CACHE_DIR" ]; then
for image in "${IMAGES[@]}"; do
if ! docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "^${image}$"; then
# 镜像不存在,尝试加载
case "$image" in
"argus-metric-ftp:latest")
cache_file="${IMAGE_CACHE_DIR}/argus-ftp.tar"
;;
"argus-metric-prometheus:latest")
cache_file="${IMAGE_CACHE_DIR}/argus-prometheus.tar"
;;
"argus-metric-grafana:latest")
cache_file="${IMAGE_CACHE_DIR}/argus-grafana.tar"
;;
"argus-metric-test-node:latest")
cache_file="${IMAGE_CACHE_DIR}/argus-test-node.tar"
;;
"argus-metric-test-gpu-node:latest")
cache_file="${IMAGE_CACHE_DIR}/argus-test-gpu-node.tar"
;;
esac
if [ -f "$cache_file" ]; then
echo " 从缓存加载: $image"
docker load -i "$cache_file"
loaded_from_cache=true
fi
fi
done
fi
# 检查加载后是否还有缺失的镜像
need_build=false
for image in "${IMAGES[@]}"; do
if ! docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "^${image}$"; then if ! docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "^${image}$"; then
missing_images+=("$image") need_build=true
break
fi fi
done done
fi
if [ ${#missing_images[@]} -gt 0 ]; then if $need_build; then
echo "以下镜像缺失,请先运行 build/build_images.sh 构建镜像:" echo ""
for image in "${missing_images[@]}"; do echo "部分镜像缺失,开始构建..."
echo " • $image" echo "工作目录: $(pwd)"
done cd "$TEST_DIR"
echo "" docker compose build --no-cache
echo "构建命令:"
echo " ./build/build_images.sh --metric" # 询问是否保存镜像
exit 1 echo ""
else read -p "是否保存镜像到缓存以便下次快速启动? (Y/n): " -n 1 -r
echo "所有必要镜像已存在" echo
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
mkdir -p "$IMAGE_CACHE_DIR"
echo "保存镜像到缓存..."
for image in "${IMAGES[@]}"; do
case "$image" in
"argus-metric-ftp:latest")
docker save -o "${IMAGE_CACHE_DIR}/argus-ftp.tar" "$image" && echo " 已保存: argus-ftp.tar"
;;
"argus-metric-prometheus:latest")
docker save -o "${IMAGE_CACHE_DIR}/argus-prometheus.tar" "$image" && echo " 已保存: argus-prometheus.tar"
;;
"argus-metric-grafana:latest")
docker save -o "${IMAGE_CACHE_DIR}/argus-grafana.tar" "$image" && echo " 已保存: argus-grafana.tar"
;;
"argus-metric-test-node:latest")
docker save -o "${IMAGE_CACHE_DIR}/argus-test-node.tar" "$image" && echo " 已保存: argus-test-node.tar"
;;
"argus-metric-test-gpu-node:latest")
docker save -o "${IMAGE_CACHE_DIR}/argus-test-gpu-node.tar" "$image" && echo " 已保存: argus-test-gpu-node.tar"
;;
esac
done
echo "镜像已保存到: $IMAGE_CACHE_DIR/"
fi
elif $loaded_from_cache; then
echo ""
echo "所有镜像已从缓存加载完成!"
fi
fi fi
echo "" echo ""
echo "4. 启动基础服务..." echo "3. 启动基础服务..."
cd "$TEST_DIR" cd "$TEST_DIR"
# 启动除GPU节点外的所有服务
# 根据GPU环境决定启动的服务 docker compose up -d ftp prometheus grafana test-node test-gpu-node
if [ "$GPU_AVAILABLE" = true ]; then
echo "启动所有服务(包括GPU节点)..."
docker compose up -d ftp prometheus grafana test-node test-gpu-node
else
echo "启动基础服务(跳过GPU节点)..."
docker compose up -d ftp prometheus grafana test-node
fi
echo "" echo ""
echo "4. 等待服务启动..." echo "4. 等待服务启动..."

View File

@@ -42,7 +42,7 @@
- `./scripts/05_agent_register.sh` 获取两个节点的 `node_id` 与初始 IP,检查本地 `node.json` - `./scripts/05_agent_register.sh` 获取两个节点的 `node_id` 与初始 IP,检查本地 `node.json`
- `./scripts/06_write_health_and_assert.sh` 写健康文件并断言 `nodes.json` 仅包含 2 个在线节点 - `./scripts/06_write_health_and_assert.sh` 写健康文件并断言 `nodes.json` 仅包含 2 个在线节点
- `./scripts/07_logs_send_and_assert.sh` 向两个节点写日志,断言 ES `train-*`/`infer-*` 计数增长 - `./scripts/07_logs_send_and_assert.sh` 向两个节点写日志,断言 ES `train-*`/`infer-*` 计数增长
- `./scripts/08_restart_agent_reregister.sh` `node-b` 改为固定 IP `172.31.0.200`,验证保持同一节点 ID 且 IP/时间戳更新 - `./scripts/08_restart_agent_reregister.sh` `node-b` 改为固定 IP `172.29.0.200`,验证保持同一节点 ID 且 IP/时间戳更新
- `./scripts/09_down.sh` 回收容器、网络并清理 `private*/`、`tmp/` - `./scripts/09_down.sh` 回收容器、网络并清理 `private*/`、`tmp/`
- 重置环境 - 重置环境
@@ -53,8 +53,8 @@
## 二、测试部署架构(docker-compose) ## 二、测试部署架构(docker-compose)
- 网络 - 网络
- 自定义 bridge:`argus-sys-net`,子网 `172.31.0.0/16` - 自定义 bridge:`argus-sys-net`,子网 `172.29.0.0/16`
- 固定地址:bind=`172.31.0.2`,master=`172.31.0.10` - 固定地址:bind=`172.29.0.2`,master=`172.29.0.10`
- 服务与端口 - 服务与端口
- `bind`(`argus-bind9:latest`):监听 53/tcp+udp;负责同步 `*.argus.com` 记录 - `bind`(`argus-bind9:latest`):监听 53/tcp+udp;负责同步 `*.argus.com` 记录
@@ -72,7 +72,7 @@
- 节点容器的 Fluent Bit/agent 资产以只读方式挂载到 `/assets`/`/usr/local/bin/argus-agent` - 节点容器的 Fluent Bit/agent 资产以只读方式挂载到 `/assets`/`/usr/local/bin/argus-agent`
- DNS 配置 - DNS 配置
- 节点容器通过 compose 配置 `dns: [172.31.0.2]` 指向 bind,不挂载 `/etc/resolv.conf`,也不依赖 `update-dns.sh` - 节点容器通过 compose 配置 `dns: [172.29.0.2]` 指向 bind,不挂载 `/etc/resolv.conf`,也不依赖 `update-dns.sh`
- master/es/kibana 仍共享 `./private`,master 启动会写 `/private/argus/etc/master.argus.com` 供 bind 同步 A 记录 - master/es/kibana 仍共享 `./private`,master 启动会写 `/private/argus/etc/master.argus.com` 供 bind 同步 A 记录
- 节点入口 - 节点入口

View File

@@ -1,18 +1,21 @@
version: "3.8"
networks: networks:
sysnet: default:
name: argus-sys-net
driver: bridge driver: bridge
ipam: ipam:
driver: default driver: default
config: config:
- subnet: 172.31.0.0/16 - subnet: 172.29.0.0/16
services: services:
bind: bind:
image: ${BIND_IMAGE_TAG:-argus-bind9:latest} image: ${BIND_IMAGE_TAG:-argus-bind9:latest}
container_name: argus-bind-sys container_name: argus-bind-sys
networks: networks:
sysnet: default:
ipv4_address: 172.31.0.2 ipv4_address: 172.29.0.2
volumes: volumes:
- ./private:/private - ./private:/private
restart: unless-stopped restart: unless-stopped
@@ -35,8 +38,8 @@ services:
- ./private/argus/metric/prometheus:/private/argus/metric/prometheus - ./private/argus/metric/prometheus:/private/argus/metric/prometheus
- ./private/argus/etc:/private/argus/etc - ./private/argus/etc:/private/argus/etc
networks: networks:
sysnet: default:
ipv4_address: 172.31.0.10 ipv4_address: 172.29.0.10
restart: unless-stopped restart: unless-stopped
es: es:
@@ -54,9 +57,6 @@ services:
ports: ports:
- "9200:9200" - "9200:9200"
restart: unless-stopped restart: unless-stopped
networks:
sysnet:
ipv4_address: 172.31.0.3
kibana: kibana:
image: argus-kibana:latest image: argus-kibana:latest
@@ -73,9 +73,6 @@ services:
ports: ports:
- "5601:5601" - "5601:5601"
restart: unless-stopped restart: unless-stopped
networks:
sysnet:
ipv4_address: 172.31.0.4
node-a: node-a:
image: ubuntu:22.04 image: ubuntu:22.04
@@ -104,12 +101,10 @@ services:
entrypoint: entrypoint:
- /usr/local/bin/node-entrypoint.sh - /usr/local/bin/node-entrypoint.sh
dns: dns:
- 172.31.0.2 - 172.29.0.2
ports: ports:
- "2020:2020" - "2020:2020"
restart: unless-stopped restart: unless-stopped
networks:
- sysnet
node-b: node-b:
image: ubuntu:22.04 image: ubuntu:22.04
@@ -138,256 +133,7 @@ services:
entrypoint: entrypoint:
- /usr/local/bin/node-entrypoint.sh - /usr/local/bin/node-entrypoint.sh
dns: dns:
- 172.31.0.2 - 172.29.0.2
ports: ports:
- "2021:2020" - "2021:2020"
restart: unless-stopped restart: unless-stopped
networks:
- sysnet
ftp:
image: argus-metric-ftp:latest
container_name: argus-ftp
restart: unless-stopped
environment:
- TZ=Asia/Shanghai
- FTP_BASE_PATH=/private/argus/ftp
- FTP_PASSWORD=${FTP_PASSWORD:-ZGClab1234!}
- DOMAIN=${FTP_DOMAIN:-ftp.metric.argus.com}
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
ports:
- "${FTP_PORT:-21}:21"
- "${FTP_DATA_PORT:-20}:20"
- "21100-21110:21100-21110"
volumes:
- ./private/argus/metric/ftp:/private/argus/ftp
- ./private/argus/etc:/private/argus/etc
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
networks:
sysnet:
ipv4_address: 172.31.0.40
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
prometheus:
image: argus-metric-prometheus:latest
container_name: argus-prometheus
restart: unless-stopped
environment:
- TZ=Asia/Shanghai
- PROMETHEUS_BASE_PATH=/private/argus/metric/prometheus
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
ports:
- "${PROMETHEUS_PORT:-9090}:9090"
volumes:
- ./private/argus/metric/prometheus:/private/argus/metric/prometheus
- ./private/argus/etc:/private/argus/etc
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
networks:
sysnet:
ipv4_address: 172.31.0.41
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
grafana:
image: argus-metric-grafana:latest
container_name: argus-grafana
restart: unless-stopped
environment:
- TZ=Asia/Shanghai
- GRAFANA_BASE_PATH=/private/argus/metric/grafana
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
- GF_SERVER_HTTP_PORT=3000
- GF_LOG_LEVEL=warn
- GF_LOG_MODE=console
- GF_PATHS_PROVISIONING=/private/argus/metric/grafana/provisioning
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Viewer
ports:
- "${GRAFANA_PORT:-3000}:3000"
volumes:
- ./private/argus/metric/grafana:/private/argus/metric/grafana
- ./private/argus/etc:/private/argus/etc
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
networks:
sysnet:
ipv4_address: 172.31.0.42
depends_on:
- prometheus
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# --- Added: Web Frontend (no host port; resolved by DNS as web.argus.com) ---
web-frontend:
image: argus-web-frontend:latest
container_name: argus-web-frontend
environment:
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
volumes:
- ./private/argus/etc:/private/argus/etc
networks:
sysnet:
ipv4_address: 172.31.0.80
restart: unless-stopped
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
test-node:
image: ubuntu:22.04
container_name: argus-metric-test-node
hostname: test-metric-node-001
restart: unless-stopped
privileged: true
depends_on:
- ftp
- prometheus
environment:
- TZ=Asia/Shanghai
- DEBIAN_FRONTEND=noninteractive
- FTP_DOMAIN=${FTP_DOMAIN:-ftp.metric.argus.com}
- FTP_SERVER=${FTP_SERVER:-172.31.0.40}
- FTP_USER=${FTP_USER:-ftpuser}
- FTP_PASSWORD=${FTP_PASSWORD:-ZGClab1234!}
- FTP_PORT=${FTP_PORT:-21}
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
- METRIC_NODE_ROLE=cpu
volumes:
- ./private/argus/agent:/private/argus/agent
- ./scripts/metric/test-node-entrypoint.sh:/usr/local/bin/metric-test-node-entrypoint.sh:ro
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
entrypoint:
- /usr/local/bin/metric-test-node-entrypoint.sh
command:
- sleep
- infinity
networks:
sysnet:
ipv4_address: 172.31.0.50
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
test-gpu-node:
profiles: ["gpu"]
image: nvidia/cuda:12.2.2-runtime-ubuntu22.04
container_name: argus-metric-test-gpu-node
hostname: test-metric-gpu-node-001
restart: unless-stopped
privileged: true
runtime: nvidia
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities:
- gpu
depends_on:
- ftp
- prometheus
environment:
- TZ=Asia/Shanghai
- DEBIAN_FRONTEND=noninteractive
- NVIDIA_VISIBLE_DEVICES=all
- NVIDIA_DRIVER_CAPABILITIES=compute,utility
- GPU_MODE=gpu
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
- METRIC_NODE_ROLE=gpu
volumes:
- ./private/argus/agent:/private/argus/agent
- ./scripts/metric/test-node-entrypoint.sh:/usr/local/bin/metric-test-node-entrypoint.sh:ro
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
entrypoint:
- /usr/local/bin/metric-test-node-entrypoint.sh
command:
- sleep
- infinity
networks:
sysnet:
ipv4_address: 172.31.0.51
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# --- Added: Alertmanager ---
alertmanager:
image: argus-alertmanager:latest
container_name: argus-alertmanager
environment:
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
volumes:
- ./private/argus/etc:/private/argus/etc
- ./private/argus/alert/alertmanager:/private/argus/alert/alertmanager
networks:
sysnet:
ipv4_address: 172.31.0.82
ports:
- "9093:9093"
restart: unless-stopped
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# --- Added: Web Proxy (multi-port gateway) ---
web-proxy:
image: argus-web-proxy:latest
container_name: argus-web-proxy
depends_on:
- bind
- master
- grafana
- prometheus
- kibana
- alertmanager
environment:
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
volumes:
- ./private/argus/etc:/private/argus/etc
networks:
sysnet:
ipv4_address: 172.31.0.81
ports:
- "8080:8080"
- "8081:8081"
- "8082:8082"
- "8083:8083"
- "8084:8084"
- "8085:8085"
restart: unless-stopped
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"

View File

@@ -3,38 +3,6 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ENABLE_GPU=false
usage() {
cat <<'EOF'
Usage: 00_e2e_test.sh [options]
Options:
--enable-gpu 启用 GPU 相关拓扑与测试流程
-h, --help 显示帮助信息
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
--enable-gpu)
ENABLE_GPU=true
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown argument: $1" >&2
usage
exit 1
;;
esac
done
export ARGUS_SYS_ENABLE_GPU=$ENABLE_GPU
SCRIPTS=( SCRIPTS=(
"01_bootstrap.sh" "01_bootstrap.sh"
"02_up.sh" "02_up.sh"
@@ -44,11 +12,6 @@ SCRIPTS=(
"06_write_health_and_assert.sh" "06_write_health_and_assert.sh"
"07_logs_send_and_assert.sh" "07_logs_send_and_assert.sh"
"08_restart_agent_reregister.sh" "08_restart_agent_reregister.sh"
"10_metric_publish.sh"
"11_metric_node_install.sh"
"12_metric_gpu_install.sh"
"13_metric_verify.sh"
"14_metric_cleanup.sh"
"09_down.sh" "09_down.sh"
) )
@@ -60,3 +23,4 @@ for script in "${SCRIPTS[@]}"; do
done done
echo "[SYS-E2E] All tests completed" echo "[SYS-E2E] All tests completed"

View File

@@ -22,66 +22,24 @@ ensure_image() {
} }
echo "[INFO] Preparing directories..." echo "[INFO] Preparing directories..."
ensure_writable_dir() {
local path="$1"
local parent
parent="$(dirname "$path")"
mkdir -p "$parent" 2>/dev/null || true
mkdir -p "$path" 2>/dev/null || true
if [[ ! -w "$path" ]]; then
docker run --rm -v "$parent:/target" ubuntu:24.04 bash -lc "chown -R $(id -u):$(id -g) /target" >/dev/null 2>&1 || true
fi
mkdir -p "$path"
}
# preflight: make base dirs writable if inherited from root-owned mounts
ensure_writable_dir "$PRIVATE_CORE/argus"
ensure_writable_dir "$PRIVATE_CORE/argus/metric"
ensure_writable_dir "$PRIVATE_CORE/argus/metric/grafana"
ensure_writable_dir "$PRIVATE_CORE/argus/metric/prometheus"
mkdir -p \ mkdir -p \
"$PRIVATE_CORE/argus/etc" \ "$PRIVATE_CORE/argus/etc" \
"$PRIVATE_CORE/argus/bind" \ "$PRIVATE_CORE/argus/bind" \
"$PRIVATE_CORE/argus/master" \ "$PRIVATE_CORE/argus/master" \
"$PRIVATE_CORE/argus/metric/prometheus" \ "$PRIVATE_CORE/argus/metric/prometheus" \
"$PRIVATE_CORE/argus/alert/alertmanager" \
"$PRIVATE_CORE/argus/metric/ftp/share" \
"$PRIVATE_CORE/argus/metric/grafana/data" \
"$PRIVATE_CORE/argus/metric/grafana/logs" \
"$PRIVATE_CORE/argus/metric/grafana/plugins" \
"$PRIVATE_CORE/argus/metric/grafana/provisioning/datasources" \
"$PRIVATE_CORE/argus/metric/grafana/provisioning/dashboards" \
"$PRIVATE_CORE/argus/metric/grafana/data/sessions" \
"$PRIVATE_CORE/argus/metric/grafana/data/dashboards" \
"$PRIVATE_CORE/argus/metric/grafana/config" \
"$PRIVATE_CORE/argus/metric/prometheus/data" \
"$PRIVATE_CORE/argus/metric/prometheus/rules" \
"$PRIVATE_CORE/argus/metric/prometheus/targets" \
"$PRIVATE_CORE/argus/agent" \
"$PRIVATE_CORE/argus/log/elasticsearch" \ "$PRIVATE_CORE/argus/log/elasticsearch" \
"$PRIVATE_CORE/argus/log/kibana" \ "$PRIVATE_CORE/argus/log/kibana" \
"$PRIVATE_NODEA/argus/agent/dev-yyrshare-nbnyx10-cp2f-pod-0/health" \ "$PRIVATE_NODEA/argus/agent/dev-yyrshare-nbnyx10-cp2f-pod-0/health" \
"$PRIVATE_NODEB/argus/agent/dev-yyrshare-uuuu10-ep2f-pod-0/health" \ "$PRIVATE_NODEB/argus/agent/dev-yyrshare-uuuu10-ep2f-pod-0/health" \
"$TMP_DIR" "$TMP_DIR"
# Align ownership for supervisor-managed services (ES/Kibana/Grafana expect UID/GID inside container) # Align ownership for supervisor-managed services (ES/Kibana expect UID/GID inside container)
echo "[INFO] Fixing ownership for core private directories..." echo "[INFO] Fixing ownership for core private directories..."
chown -R "${ARGUS_BUILD_UID}:${ARGUS_BUILD_GID}" \ chown -R "${ARGUS_BUILD_UID}:${ARGUS_BUILD_GID}" \
"$PRIVATE_CORE/argus/log/elasticsearch" \ "$PRIVATE_CORE/argus/log/elasticsearch" \
"$PRIVATE_CORE/argus/log/kibana" \ "$PRIVATE_CORE/argus/log/kibana" \
"$PRIVATE_CORE/argus/metric/grafana" \
"$PRIVATE_CORE/argus/metric/prometheus" \
"$PRIVATE_CORE/argus/alert" \
"$PRIVATE_CORE/argus/metric/ftp" \
"$PRIVATE_CORE/argus/agent" \
"$PRIVATE_CORE/argus/etc" 2>/dev/null || true "$PRIVATE_CORE/argus/etc" 2>/dev/null || true
# 确保 alert 与 etc 目录组可写,便于非 root 且仅匹配 GID 的服务写入运行文件
chmod -R g+w "$PRIVATE_CORE/argus/alert" "$PRIVATE_CORE/argus/etc" 2>/dev/null || true
echo "[INFO] Using compose-managed network (auto-created by docker compose)"
echo "[INFO] Distributing update-dns.sh for core services (bind/master/es/kibana)" echo "[INFO] Distributing update-dns.sh for core services (bind/master/es/kibana)"
BIND_UPDATE_SRC="$REPO_ROOT/src/bind/build/update-dns.sh" BIND_UPDATE_SRC="$REPO_ROOT/src/bind/build/update-dns.sh"
BIND_UPDATE_DEST="$PRIVATE_CORE/argus/etc/update-dns.sh" BIND_UPDATE_DEST="$PRIVATE_CORE/argus/etc/update-dns.sh"
@@ -97,12 +55,6 @@ ensure_image "argus-elasticsearch:latest"
ensure_image "argus-kibana:latest" ensure_image "argus-kibana:latest"
ensure_image "argus-bind9:latest" ensure_image "argus-bind9:latest"
ensure_image "argus-master:latest" ensure_image "argus-master:latest"
ensure_image "argus-metric-ftp:latest"
ensure_image "argus-metric-prometheus:latest"
ensure_image "argus-metric-grafana:latest"
ensure_image "argus-web-frontend:latest"
ensure_image "argus-web-proxy:latest"
ensure_image "argus-alertmanager:latest"
echo "[INFO] Building agent binary..." echo "[INFO] Building agent binary..."
pushd "$REPO_ROOT/src/agent" >/dev/null pushd "$REPO_ROOT/src/agent" >/dev/null
@@ -116,50 +68,10 @@ if [[ ! -x "$AGENT_BIN" ]]; then
fi fi
echo "$AGENT_BIN" > "$TMP_DIR/agent_binary_path" echo "$AGENT_BIN" > "$TMP_DIR/agent_binary_path"
# 检测GPU环境 echo "[INFO] Writing .env with UID/GID"
REQUEST_GPU=${ARGUS_SYS_ENABLE_GPU:-false}
GPU_CHECK_SCRIPT="$REPO_ROOT/src/metric/tests/scripts/common/check-gpu.sh"
if [[ "$REQUEST_GPU" == "true" ]]; then
echo "[INFO] --enable-gpu 已启用,开始检测GPU环境..."
if [[ -f "$GPU_CHECK_SCRIPT" ]]; then
if bash "$GPU_CHECK_SCRIPT" >/dev/null 2>&1; then
echo "[INFO] GPU环境可用,将在 compose 中启用 test-gpu-node"
GPU_AVAILABLE=true
else
echo "[ERROR] 未检测到可用 GPU,但指定了 --enable-gpu" >&2
exit 1
fi
else
echo "[ERROR] 未找到 GPU 检测脚本: $GPU_CHECK_SCRIPT" >&2
exit 1
fi
else
GPU_AVAILABLE=false
echo "[INFO] GPU 支持未启用,跳过 GPU 检测"
fi
echo "[INFO] Writing .env with UID/GID and metric configuration"
cat > "$TEST_ROOT/.env" <<EOF cat > "$TEST_ROOT/.env" <<EOF
ARGUS_BUILD_UID=$ARGUS_BUILD_UID ARGUS_BUILD_UID=$ARGUS_BUILD_UID
ARGUS_BUILD_GID=$ARGUS_BUILD_GID ARGUS_BUILD_GID=$ARGUS_BUILD_GID
# GPU 配置
ENABLE_GPU=$GPU_AVAILABLE
# FTP 配置
FTP_PORT=21
FTP_DATA_PORT=20
FTP_PASSWORD=ZGClab1234!
FTP_DOMAIN=ftp.metric.argus.com
# Prometheus 配置
PROMETHEUS_PORT=9090
# Grafana 配置
GRAFANA_PORT=3000
# 网络配置
USE_INTRANET=false
EOF EOF
echo "[OK] Bootstrap completed" echo "[OK] Bootstrap completed"

View File

@@ -3,7 +3,6 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
REPO_ROOT="$(cd "$TEST_ROOT/../../.." && pwd)"
compose() { compose() {
if docker compose version >/dev/null 2>&1; then if docker compose version >/dev/null 2>&1; then
@@ -14,73 +13,10 @@ compose() {
} }
echo "[INFO] Bringing up system stack..." echo "[INFO] Bringing up system stack..."
REQUEST_GPU=${ARGUS_SYS_ENABLE_GPU:-false}
GPU_AVAILABLE=false
GPU_CHECK_SCRIPT="$REPO_ROOT/src/metric/tests/scripts/common/check-gpu.sh"
if [[ "$REQUEST_GPU" == "true" ]]; then
echo "[INFO] --enable-gpu 生效,验证主机 GPU..."
if [[ -f "$GPU_CHECK_SCRIPT" ]]; then
if bash "$GPU_CHECK_SCRIPT" >/dev/null 2>&1; then
GPU_AVAILABLE=true
echo "[INFO] GPU 检测通过,将启动 gpu profile"
else
echo "[ERROR] 主机缺少可用 GPU,无法继续 --enable-gpu 流程" >&2
exit 1
fi
else
echo "[ERROR] 未找到 GPU 检测脚本: $GPU_CHECK_SCRIPT" >&2
exit 1
fi
else
echo "[INFO] 未启用 GPU 流程"
fi
pushd "$TEST_ROOT" >/dev/null pushd "$TEST_ROOT" >/dev/null
compose -p argus-sys down --remove-orphans || true compose -p argus-sys down --remove-orphans || true
compose -p argus-sys up -d
# 清理可能由 08 脚本创建的同名容器,避免 compose up 冲突
for name in argus-node-b; do
if docker ps -aqf "name=^${name}$" >/dev/null 2>&1 && [[ -n "$(docker ps -aqf "name=^${name}$")" ]]; then
docker rm -f "$name" >/dev/null 2>&1 || true
fi
done
# 预检:检查多端口网关所需宿主端口是否空闲
check_port_free() {
local p="$1"
if ss -ltnp 2>/dev/null | grep -q ":${p} "; then
echo "[ERR] Host port ${p} is already in use. Please free it before running 02_up.sh" >&2
ss -ltnp | awk -v p=":${p} " '$0 ~ p {print " " $0}' || true
return 1
fi
return 0
}
for port in 8080 8081 8082 8083 8084 8085; do
check_port_free "$port" || { echo "[ERR] Required port busy: $port"; exit 1; }
done
# 根据GPU可用性决定启动的服务
if [[ "$GPU_AVAILABLE" == true ]]; then
echo "[INFO] 启动所有服务(包含 gpu profile)..."
compose -p argus-sys --profile gpu up -d || true
else
echo "[INFO] 启动基础服务(不含 gpu profile)..."
compose -p argus-sys up -d || true
fi
# 若 web-proxy 处于 Created 状态,尝试单独启动一次(处理偶发 Address already in use 后端已释放的场景)
if docker ps -a --format '{{.Names}}\t{{.Status}}' | grep -q '^argus-web-proxy\s\+Created'; then
echo "[WARN] web-proxy in Created state; retry starting it..."
docker start argus-web-proxy || true
fi
popd >/dev/null popd >/dev/null
if [[ "$GPU_AVAILABLE" == true ]]; then echo "[OK] Services started: master:32300 es:9200 kibana:5601 node-a:2020 node-b:2021"
echo "[OK] Services started: master:32300 es:9200 kibana:5601 node-a:2020 node-b:2021 test-gpu-node:172.31.0.51"
else
echo "[OK] Services started: master:32300 es:9200 kibana:5601 node-a:2020 node-b:2021 (gpu skipped)"
fi

View File

@@ -29,7 +29,6 @@ echo "[INFO] Waiting for ES/Kibana/Master/Fluent Bit/Bind..."
# ES (>= yellow) # ES (>= yellow)
attempt=1; max=120 attempt=1; max=120
ES_T0=$(date +%s)
while (( attempt <= max )); do while (( attempt <= max )); do
if curl -fsS "http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=1s" >/dev/null 2>&1; then if curl -fsS "http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=1s" >/dev/null 2>&1; then
break break
@@ -37,19 +36,16 @@ while (( attempt <= max )); do
echo "[..] waiting ES ($attempt/$max)"; sleep 5; ((attempt++)) echo "[..] waiting ES ($attempt/$max)"; sleep 5; ((attempt++))
done done
[[ $attempt -le $max ]] || { echo "[ERR] ES not ready" >&2; exit 1; } [[ $attempt -le $max ]] || { echo "[ERR] ES not ready" >&2; exit 1; }
ES_T1=$(date +%s); echo "[TIME] ES ready in $((ES_T1-ES_T0))s"
# Kibana: must be HTTP 200 and overall.level=available # Kibana: must be HTTP 200 and overall.level=available
echo "[INFO] Waiting for Kibana to be available (HTTP 200)..." echo "[INFO] Waiting for Kibana to be available (HTTP 200)..."
kb_attempt=1; kb_max=180 kb_attempt=1; kb_max=180
KB_T0=$(date +%s)
while (( kb_attempt <= kb_max )); do while (( kb_attempt <= kb_max )); do
body=$(curl -sS "http://localhost:5601/api/status" 2>/dev/null || true) body=$(curl -sS "http://localhost:5601/api/status" 2>/dev/null || true)
code=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:5601/api/status" || echo 000) code=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:5601/api/status" || echo 000)
if [[ "$code" == "200" ]]; then if [[ "$code" == "200" ]]; then
if echo "$body" | grep -q '"level":"available"'; then if echo "$body" | grep -q '"level":"available"'; then
KB_T1=$(date +%s) echo "[OK] Kibana available (HTTP 200)"
echo "[OK] Kibana available (HTTP 200) in $((KB_T1-KB_T0))s"
break break
fi fi
fi fi
@@ -62,13 +58,11 @@ if (( kb_attempt > kb_max )); then
fi fi
# Master # Master
MASTER_T0=$(date +%s)
wait_http "http://localhost:32300/readyz" 120 wait_http "http://localhost:32300/readyz" 120
MASTER_T1=$(date +%s); echo "[TIME] Master readyz in $((MASTER_T1-MASTER_T0))s"
# Fluent Bit (host metrics on host ports) # Fluent Bit (host metrics on host ports)
FB1_T0=$(date +%s); wait_http "http://localhost:2020/api/v2/metrics" 120; FB1_T1=$(date +%s); echo "[TIME] FluentBit:2020 in $((FB1_T1-FB1_T0))s" wait_http "http://localhost:2020/api/v2/metrics" 120
FB2_T0=$(date +%s); wait_http "http://localhost:2021/api/v2/metrics" 120; FB2_T1=$(date +%s); echo "[TIME] FluentBit:2021 in $((FB2_T1-FB2_T0))s" wait_http "http://localhost:2021/api/v2/metrics" 120
# Bind config check # Bind config check
BIND_ID="$(service_id bind)" BIND_ID="$(service_id bind)"
@@ -78,63 +72,4 @@ else
echo "[WARN] bind container id not found" echo "[WARN] bind container id not found"
fi fi
# ========== Additional module readiness checks ==========
# Prometheus
PROM_T0=$(date +%s); wait_http "http://localhost:9090/-/ready" 120; PROM_T1=$(date +%s); echo "[TIME] Prometheus ready in $((PROM_T1-PROM_T0))s"
# Grafana health (database: ok)
echo "[INFO] Waiting for Grafana health..."
gf_attempt=1; gf_max=120
while (( gf_attempt <= gf_max )); do
gf_body=$(curl -sS "http://localhost:3000/api/health" 2>/dev/null || true)
gf_code=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:3000/api/health" || echo 000)
if [[ "$gf_code" == "200" ]] && echo "$gf_body" | grep -q '"database"\s*:\s*"ok"'; then
echo "[OK] Grafana health database=ok"
break
fi
echo "[..] waiting grafana health ($gf_attempt/$gf_max), last_code=$gf_code"
sleep 3; ((gf_attempt++))
done
if (( gf_attempt > gf_max )); then
echo "[ERR] Grafana /api/health not ready" >&2; exit 1
fi
# Alertmanager
wait_http "http://localhost:9093/api/v2/status" 120
# Web proxy checks(按端口细化)
code_for() { curl -s -o /dev/null -w "%{http_code}" "$1" || echo 000; }
header_val() { curl -s -D - -o /dev/null "$@" | awk -F': ' 'BEGIN{IGNORECASE=1}$1=="Access-Control-Allow-Origin"{gsub("\r","",$2);print $2}'; }
echo "[INFO] Checking web-proxy ports..."
# 8080 首页必须 200
tries=1; max=60; P8080_T0=$(date +%s)
while (( tries <= max )); do
c=$(code_for "http://localhost:8080/")
if [[ "$c" == "200" ]]; then P8080_T1=$(date +%s); echo "[OK] 8080 / ($c) in $((P8080_T1-P8080_T0))s"; break; fi
echo "[..] waiting 8080/ ($tries/$max), code=$c"; sleep 3; ((tries++))
done
(( tries <= max )) || { echo "[ERR] 8080/ not ready" >&2; exit 1; }
# 8083 Kibana 允许 200/302(上面已就绪,端口侧再快速确认)
tries=1; max=40; P8083_T0=$(date +%s)
while (( tries <= max )); do
c=$(code_for "http://localhost:8083/")
if [[ "$c" == "200" || "$c" == "302" ]]; then P8083_T1=$(date +%s); echo "[OK] 8083 / ($c) in $((P8083_T1-P8083_T0))s"; break; fi
echo "[..] waiting 8083/ ($tries/$max), code=$c"; sleep 3; ((tries++))
done
(( tries <= max )) || { echo "[ERR] 8083/ not ready" >&2; exit 1; }
# 8084 Alertmanager + CORS
P8084_T0=$(date +%s); wait_http "http://localhost:8084/api/v2/status" 60; P8084_T1=$(date +%s)
cors=$(header_val -H "Origin: http://localhost:8080" "http://localhost:8084/api/v2/status" || true)
if [[ -z "$cors" ]]; then echo "[ERR] 8084 CORS missing" >&2; exit 1; else echo "[OK] 8084 CORS: $cors in $((P8084_T1-P8084_T0))s"; fi
# 8085 Master /readyz + CORS(API 走 8085 才需跨域)
P8085_T0=$(date +%s); wait_http "http://localhost:8085/readyz" 60; P8085_T1=$(date +%s)
cors=$(header_val -H "Origin: http://localhost:8080" "http://localhost:8085/api/v1/master/nodes" || true)
if [[ -z "$cors" ]]; then echo "[ERR] 8085 CORS missing" >&2; exit 1; else echo "[OK] 8085 CORS: $cors in $((P8085_T1-P8085_T0))s"; fi
echo "[OK] All services are ready" echo "[OK] All services are ready"

View File

@@ -4,15 +4,20 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
# 直接根据 container_name 获取容器ID,避免 compose project 名称不一致导致查找失败 compose() {
cid_by_name() { if docker compose version >/dev/null 2>&1; then
docker ps -aqf "name=^$1$" docker compose "$@"
else
docker-compose "$@"
fi
}
service_id() {
compose -p argus-sys ps -q "$1"
} }
echo "[INFO] Verifying DNS routing via bind..." echo "[INFO] Verifying DNS routing via bind..."
pushd "$TEST_ROOT" >/dev/null
# Check master IP file exists in shared private # Check master IP file exists in shared private
MASTER_FILE="$TEST_ROOT/private/argus/etc/master.argus.com" MASTER_FILE="$TEST_ROOT/private/argus/etc/master.argus.com"
if [[ ! -f "$MASTER_FILE" ]]; then if [[ ! -f "$MASTER_FILE" ]]; then
@@ -23,7 +28,7 @@ MASTER_IP_HOST="$(cat "$MASTER_FILE" | tr -d '\r\n' || true)"
echo "[INFO] master.argus.com file content: ${MASTER_IP_HOST}" echo "[INFO] master.argus.com file content: ${MASTER_IP_HOST}"
# dig inside bind container # dig inside bind container
BIN_ID="$(cid_by_name argus-bind-sys)" BIN_ID="$(service_id bind)"
if [[ -n "$BIN_ID" ]]; then if [[ -n "$BIN_ID" ]]; then
DIG_IP="$(docker exec "$BIN_ID" dig +short master.argus.com A | tail -n1 || true)" DIG_IP="$(docker exec "$BIN_ID" dig +short master.argus.com A | tail -n1 || true)"
echo "[INFO] dig(master.argus.com) from bind container -> $DIG_IP" echo "[INFO] dig(master.argus.com) from bind container -> $DIG_IP"
@@ -34,8 +39,8 @@ else
echo "[WARN] bind container not found; skip dig" echo "[WARN] bind container not found; skip dig"
fi fi
for node in argus-node-a argus-node-b; do for node in node-a node-b; do
CID="$(cid_by_name "$node")" CID="$(service_id "$node")"
echo "[INFO] Checking resolution inside $node..." echo "[INFO] Checking resolution inside $node..."
if ! docker exec "$CID" getent hosts master.argus.com >/dev/null 2>&1; then if ! docker exec "$CID" getent hosts master.argus.com >/dev/null 2>&1; then
echo "[ERR] $node cannot resolve master.argus.com" >&2 echo "[ERR] $node cannot resolve master.argus.com" >&2
@@ -45,6 +50,5 @@ for node in argus-node-a argus-node-b; do
echo "[OK] $node resolved master.argus.com -> $RES" echo "[OK] $node resolved master.argus.com -> $RES"
done done
popd >/dev/null
echo "[OK] DNS routing verified" echo "[OK] DNS routing verified"

View File

@@ -49,35 +49,8 @@ for _ in {1..60}; do
fi fi
done done
# 若仍未全部注册,尝试重启 node-b 并再等待一轮(兼容 DNS/启动时序抖动)
if [[ ! -s "$TMP_DIR/node_id_a" || ! -s "$TMP_DIR/node_id_b" ]]; then if [[ ! -s "$TMP_DIR/node_id_a" || ! -s "$TMP_DIR/node_id_b" ]]; then
echo "[WARN] node-a or node-b not registered in first window; restarting node-b and retrying..." >&2 echo "[ERR] Agents did not register in time" >&2
# 仅重启 node-b,避免影响 es/kibana/master
if docker ps --format '{{.Names}}' | grep -q '^argus-node-b$'; then
docker restart argus-node-b >/dev/null 2>&1 || true
fi
# 再等待一轮(最多 120 秒)
> "$TMP_DIR/node_id_b"
for _ in {1..60}; do
sleep 2
resp=$(curl -fsS "$API_BASE/nodes" 2>/dev/null || true)
[[ -z "$resp" ]] && continue
if ! echo "$resp" | head -c1 | grep -q '\['; then
continue
fi
echo "$resp" > "$TMP_DIR/nodes_list.json"
ID_A=$(extract_node "$HOST_A" "$TMP_DIR/node_id_a" "$TMP_DIR/nodes_list.json" 2>/dev/null || true)
ID_B=$(extract_node "$HOST_B" "$TMP_DIR/node_id_b" "$TMP_DIR/nodes_list.json" 2>/dev/null || true)
if [[ -s "$TMP_DIR/node_id_a" && -s "$TMP_DIR/node_id_b" ]]; then
break
fi
done
fi
if [[ ! -s "$TMP_DIR/node_id_a" || ! -s "$TMP_DIR/node_id_b" ]]; then
echo "[ERR] Agents did not register in time (after retry)" >&2
echo "[HINT] Current /nodes response:" >&2
sed -n '1,200p' "$TMP_DIR/nodes_list.json" >&2 || true
exit 1 exit 1
fi fi

View File

@@ -3,19 +3,9 @@ set -euo pipefail
echo "[INFO] Sending logs via node-a/node-b and asserting ES counts..." echo "[INFO] Sending logs via node-a/node-b and asserting ES counts..."
# Robust count helper: tolerates 404/503 and non-JSON responses, returns integer >=0
get_count() { get_count() {
local idx="$1"; local tmp; tmp=$(mktemp) local idx="$1"
local code curl -s "http://localhost:9200/${idx}/_count?ignore_unavailable=true&allow_no_indices=true" | sed -E 's/.*"count":([0-9]+).*/\1/' | awk 'NF{print $0;exit} END{if(NR==0)print 0}'
code=$(curl -s -o "$tmp" -w "%{http_code}" "http://localhost:9200/${idx}/_count?ignore_unavailable=true&allow_no_indices=true" || true)
if [[ "$code" == "200" ]]; then
local val
val=$(jq -r '(.count // 0) | tonumber? // 0' "$tmp" 2>/dev/null || echo 0)
echo "$val"
else
echo 0
fi
rm -f "$tmp"
} }
train0=$(get_count "train-*") train0=$(get_count "train-*")
@@ -42,26 +32,11 @@ send_logs "$node_a" "host01"
send_logs "$node_b" "host02" send_logs "$node_b" "host02"
echo "[INFO] Waiting for ES to ingest..." echo "[INFO] Waiting for ES to ingest..."
# Proactively refresh indices (ignore errors if not created yet) sleep 10
curl -s -X POST "http://localhost:9200/train-*/_refresh" >/dev/null 2>&1 || true
curl -s -X POST "http://localhost:9200/infer-*/_refresh" >/dev/null 2>&1 || true
# Retry up to 120s for counts to increase and reach threshold (>=4) train1=$(get_count "train-*")
final=0 infer1=$(get_count "infer-*")
threshold=4 final=$((train1 + infer1))
for attempt in {1..60}; do
train1=$(get_count "train-*")
infer1=$(get_count "infer-*")
final=$((train1 + infer1))
if (( final > base && final >= threshold )); then
break
fi
echo "[..] waiting ES counts increase to >=${threshold} ($attempt/60) current=${final} base=${base}"
# refresh indices again to speed up visibility
curl -s -X POST "http://localhost:9200/train-*/_refresh" >/dev/null 2>&1 || true
curl -s -X POST "http://localhost:9200/infer-*/_refresh" >/dev/null 2>&1 || true
sleep 2
done
echo "[INFO] final counts: train=${train1} infer=${infer1} total=${final}" echo "[INFO] final counts: train=${train1} infer=${infer1} total=${final}"
if (( final <= base )); then if (( final <= base )); then
@@ -69,7 +44,6 @@ if (( final <= base )); then
exit 1 exit 1
fi fi
# Minimal threshold to be tolerant: expect at least 4 documents (2 train + 1 infer per node)
if (( final < 4 )); then if (( final < 4 )); then
echo "[ERR] ES total below expected threshold: ${final} < 4" >&2 echo "[ERR] ES total below expected threshold: ${final} < 4" >&2
exit 1 exit 1

View File

@@ -49,7 +49,7 @@ compose() {
fi fi
} }
echo "[INFO] Recreating node-b with static IP 172.31.0.200..." echo "[INFO] Recreating node-b with static IP 172.29.0.200..."
pushd "$TEST_ROOT" >/dev/null pushd "$TEST_ROOT" >/dev/null
compose -p argus-sys rm -sf node-b || true compose -p argus-sys rm -sf node-b || true
popd >/dev/null popd >/dev/null
@@ -58,27 +58,12 @@ docker rm -f argus-node-b >/dev/null 2>&1 || true
AGENT_BIN_PATH="$(cat "$TMP_DIR/agent_binary_path")" AGENT_BIN_PATH="$(cat "$TMP_DIR/agent_binary_path")"
# 选择 compose 管理的网络名(默认 argus-sys_sysnet)。
detect_sysnet() {
if docker network inspect argus-sys_sysnet >/dev/null 2>&1; then
echo argus-sys_sysnet; return
fi
# 回退:从 master 容器推断所连网络(取第一个)
local n
n=$(docker inspect -f '{{range $k, $_ := .NetworkSettings.Networks}}{{println $k}}{{end}}' argus-master-sys 2>/dev/null | head -n1 || true)
if [[ -n "$n" ]]; then echo "$n"; return; fi
# 最后兜底:尝试项目默认网络(不保证有 IPAM)
echo argus-sys_default
}
SYSNET_NAME=$(detect_sysnet)
echo "[INFO] Using docker network: $SYSNET_NAME"
docker run -d \ docker run -d \
--name argus-node-b \ --name argus-node-b \
--hostname dev-yyrshare-uuuu10-ep2f-pod-0 \ --hostname dev-yyrshare-uuuu10-ep2f-pod-0 \
--network "$SYSNET_NAME" \ --network argus-sys-net \
--ip 172.31.0.200 \ --ip 172.29.0.200 \
--dns 172.31.0.2 \ --dns 172.29.0.2 \
-e MASTER_ENDPOINT=http://master.argus.com:3000 \ -e MASTER_ENDPOINT=http://master.argus.com:3000 \
-e REPORT_INTERVAL_SECONDS=2 \ -e REPORT_INTERVAL_SECONDS=2 \
-e ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133} \ -e ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133} \
@@ -105,15 +90,15 @@ node=json.load(open(sys.argv[1]))
last0=sys.argv[2] last0=sys.argv[2]
ip=node.get("meta_data",{}).get("ip") ip=node.get("meta_data",{}).get("ip")
lu=node.get("last_updated") lu=node.get("last_updated")
assert ip=="172.31.0.200" assert ip=="172.29.0.200"
assert lu and lu!=last0 assert lu and lu!=last0
PY PY
then then
echo "[OK] node-b re-registered with new IP 172.31.0.200" echo "[OK] node-b re-registered with new IP 172.29.0.200"
exit 0 exit 0
fi fi
fi fi
done done
echo "[ERR] node-b did not update to IP 172.31.0.200 in time" >&2 echo "[ERR] node-b did not update to IP 172.29.0.200 in time" >&2
exit 1 exit 1

View File

@@ -12,33 +12,12 @@ compose() {
fi fi
} }
docker rm -f argus-node-b >/dev/null 2>&1 || true
pushd "$TEST_ROOT" >/dev/null pushd "$TEST_ROOT" >/dev/null
compose -p argus-sys down --remove-orphans || true compose -p argus-sys down --remove-orphans || true
compose down --remove-orphans || true
popd >/dev/null popd >/dev/null
echo "[INFO] Force removing containers by name (if any)..."
containers=(
argus-node-a
argus-node-b
argus-metric-test-node
argus-grafana
argus-kibana-sys
argus-master-sys
argus-bind-sys
argus-ftp
argus-es-sys
argus-prometheus
)
for c in "${containers[@]}"; do
id=$(docker ps -aqf "name=^${c}$" || true)
if [[ -n "$id" ]]; then
docker rm -f "$id" >/dev/null 2>&1 || true
fi
done
echo "[INFO] Removing compose networks (handled by compose down)"
echo "[INFO] Cleaning private directories..." echo "[INFO] Cleaning private directories..."
if [[ -d "$TEST_ROOT/private" ]]; then if [[ -d "$TEST_ROOT/private" ]]; then
docker run --rm -v "$TEST_ROOT/private:/target" ubuntu:24.04 chown -R "$(id -u):$(id -g)" /target >/dev/null 2>&1 || true docker run --rm -v "$TEST_ROOT/private:/target" ubuntu:24.04 chown -R "$(id -u):$(id -g)" /target >/dev/null 2>&1 || true

View File

@@ -1,66 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
REPO_ROOT="$(cd "$TEST_ROOT/../../.." && pwd)"
PLUGIN_DIR="$REPO_ROOT/src/metric/client-plugins/all-in-one-full"
FTP_CONTAINER="argus-ftp"
if [[ ! -d "$PLUGIN_DIR" ]]; then
echo "[SYS-METRIC] Metric client plugin directory not found: $PLUGIN_DIR" >&2
exit 1
fi
if [[ -f "$TEST_ROOT/.env" ]]; then
# shellcheck source=/dev/null
source "$TEST_ROOT/.env"
fi
OWNER="${ARGUS_BUILD_UID:-2133}:${ARGUS_BUILD_GID:-2015}"
resolve_output_dir() {
local host_mount
if docker ps --format '{{.Names}}' | grep -q "^${FTP_CONTAINER}$"; then
host_mount=$(docker inspect "$FTP_CONTAINER" --format '{{range .Mounts}}{{if eq .Destination "/private/argus/ftp"}}{{.Source}}{{end}}{{end}}' 2>/dev/null || true)
if [[ -n "$host_mount" ]]; then
echo "$host_mount/share"
return 0
fi
fi
echo "$TEST_ROOT/private/argus/metric/ftp/share"
}
OUTPUT_DIR="$(resolve_output_dir)"
mkdir -p "$OUTPUT_DIR"
if [[ ! -w "$OUTPUT_DIR" ]]; then
echo "[SYS-METRIC] 无法写入 FTP 输出目录: $OUTPUT_DIR" >&2
echo " 请确认目录权限与 ARGUS_BUILD_UID/GID 一致" >&2
exit 1
fi
pushd "$PLUGIN_DIR" >/dev/null
echo "[SYS-METRIC] Bumping metric artifact version..."
bash scripts/version-manager.sh bump minor
VERSION_FILE="config/VERSION"
if [[ ! -f "$VERSION_FILE" ]]; then
echo "[SYS-METRIC] VERSION 文件缺失: $VERSION_FILE" >&2
exit 1
fi
VERSION=$(tr -d '\n' < "$VERSION_FILE")
echo "[SYS-METRIC] 当前版本: $VERSION"
echo "[SYS-METRIC] Packaging metric artifact..."
bash scripts/package_artifact.sh --force
echo "[SYS-METRIC] Publishing artifact to FTP share..."
bash scripts/publish_artifact.sh "$VERSION" --output-dir "$OUTPUT_DIR" --owner "$OWNER"
popd >/dev/null
echo "[SYS-METRIC] Metric artifact published to $OUTPUT_DIR"

View File

@@ -1,50 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
if [[ -f "$TEST_ROOT/.env" ]]; then
# shellcheck source=/dev/null
source "$TEST_ROOT/.env"
fi
CONTAINER="argus-metric-test-node"
if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER}$"; then
echo "[SYS-METRIC] 容器 ${CONTAINER} 未运行,无法执行安装" >&2
exit 1
fi
FTP_HOST="${FTP_SERVER:-172.31.0.40}"
FTP_USER="${FTP_USER:-ftpuser}"
FTP_PASSWORD="${FTP_PASSWORD:-ZGClab1234!}"
FTP_PORT="${FTP_PORT:-21}"
echo "[SYS-METRIC] 在 ${CONTAINER} 内执行安装 (FTP: ${FTP_HOST}:${FTP_PORT})"
docker exec \
-e FTP_HOST="$FTP_HOST" \
-e FTP_USER="$FTP_USER" \
-e FTP_PASSWORD="$FTP_PASSWORD" \
-e FTP_PORT="$FTP_PORT" \
"$CONTAINER" bash -c '
set -e
if ! command -v curl &>/dev/null; then
echo "[SYS-METRIC] curl 未安装,开始安装依赖..."
apt-get update >/dev/null && apt-get install -y curl >/dev/null
fi
cd /tmp
echo "[SYS-METRIC] 下载 setup.sh..."
curl -u "${FTP_USER}:${FTP_PASSWORD}" "ftp://${FTP_HOST}:${FTP_PORT}/setup.sh" -o setup.sh
echo "[SYS-METRIC] 执行安装..."
chmod +x setup.sh
bash setup.sh --server "${FTP_HOST}" --user "${FTP_USER}" --password "${FTP_PASSWORD}" --port "${FTP_PORT}"
echo "[SYS-METRIC] 安装完成"
'
echo "[SYS-METRIC] Metric test node 安装流程完成"

View File

@@ -1,64 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
ENABLE_GPU=${ARGUS_SYS_ENABLE_GPU:-false}
if [[ "$ENABLE_GPU" != "true" ]]; then
echo "[SYS-METRIC] 未启用 GPU 流程,跳过 GPU 节点安装"
exit 0
fi
if [[ -f "$TEST_ROOT/.env" ]]; then
# shellcheck source=/dev/null
source "$TEST_ROOT/.env"
fi
CONTAINER="argus-metric-test-gpu-node"
if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER}$"; then
echo "[SYS-METRIC] 预期启动的 ${CONTAINER} 未运行" >&2
exit 1
fi
FTP_HOST="${FTP_SERVER:-172.31.0.40}"
FTP_USER="${FTP_USER:-ftpuser}"
FTP_PASSWORD="${FTP_PASSWORD:-ZGClab1234!}"
FTP_PORT="${FTP_PORT:-21}"
echo "[SYS-METRIC] 在 GPU 节点执行安装 (FTP: ${FTP_HOST}:${FTP_PORT})"
docker exec \
-e FTP_HOST="$FTP_HOST" \
-e FTP_USER="$FTP_USER" \
-e FTP_PASSWORD="$FTP_PASSWORD" \
-e FTP_PORT="$FTP_PORT" \
"$CONTAINER" bash -c '
set -e
if ! command -v nvidia-smi &>/dev/null; then
echo "[SYS-METRIC] GPU 节点缺少 nvidia-smi" >&2
exit 1
fi
nvidia-smi >/dev/null || true
if ! command -v curl &>/dev/null; then
echo "[SYS-METRIC] curl 未安装,开始安装依赖..."
apt-get update >/dev/null && apt-get install -y curl >/dev/null
fi
cd /tmp
echo "[SYS-METRIC] 下载 setup.sh..."
curl -u "${FTP_USER}:${FTP_PASSWORD}" "ftp://${FTP_HOST}:${FTP_PORT}/setup.sh" -o setup.sh
echo "[SYS-METRIC] 执行安装..."
chmod +x setup.sh
bash setup.sh --server "${FTP_HOST}" --user "${FTP_USER}" --password "${FTP_PASSWORD}" --port "${FTP_PORT}"
echo "[SYS-METRIC] GPU 节点安装完成"
'
echo "[SYS-METRIC] Metric GPU 节点安装流程完成"

View File

@@ -1,40 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "[SYS-METRIC] Verify: master"
"$SCRIPT_DIR/13_metric_verify_master.sh"
echo
echo "[SYS-METRIC] Verify: prometheus"
PROM_RETRIES=${PROM_VERIFY_RETRIES:-2}
PROM_BACKOFF=${PROM_VERIFY_BACKOFF_SECONDS:-30}
attempt=0
while true; do
if "$SCRIPT_DIR/13_metric_verify_prometheus.sh"; then
break
fi
attempt=$((attempt+1))
if (( attempt > PROM_RETRIES )); then
echo "[ERR] prometheus verify failed after $PROM_RETRIES retries" >&2
exit 1
fi
echo "[WARN] prometheus verify failed; retry $attempt/$PROM_RETRIES after ${PROM_BACKOFF}s"
sleep "$PROM_BACKOFF"
done
echo
echo "[SYS-METRIC] Verify: dataplane"
"$SCRIPT_DIR/13_metric_verify_dataplane.sh"
echo
echo "[SYS-METRIC] Verify: grafana"
"$SCRIPT_DIR/13_metric_verify_grafana.sh"
echo
echo "[SYS-METRIC] Verify: grafana panels"
"$SCRIPT_DIR/13_metric_verify_grafana_panels.sh"
echo
echo "[SYS-METRIC] Metric verification completed"

View File

@@ -1,47 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
TMP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)/tmp/metric-verify"
mkdir -p "$TMP_DIR"
PROM_BASE="http://localhost:9090/api/v1"
INSTANCE="${METRIC_TEST_INSTANCE:-172.31.0.50:9100}"
IP_ONLY="${INSTANCE%%:*}"
echo "[VERIFY:DATA] node exporter metrics present in container"
docker exec argus-metric-test-node bash -lc "curl -fsS --max-time 5 http://localhost:9100/metrics | head -n 5" > "$TMP_DIR/node_metrics_head.txt" || { echo "[ERR] cannot fetch node exporter metrics" >&2; exit 1; }
if ! grep -E "node_(exporter_build_info|time_seconds)" -q "$TMP_DIR/node_metrics_head.txt"; then
echo "[WARN] head did not show expected lines; continuing (exporter may output later lines)"
fi
echo "[OK] node exporter endpoint reachable"
echo "[VERIFY:DATA] Prometheus has recent sample for build_info"
curl -fsS --max-time 5 --get "$PROM_BASE/query" --data-urlencode "query=node_exporter_build_info{job=\"node\",ip=\"$IP_ONLY\"}" > "$TMP_DIR/prom_ne_build_info_1.json"
python3 - "$TMP_DIR/prom_ne_build_info_1.json" <<'PY'
import json,sys,time
j=json.load(open(sys.argv[1]))
res=j.get('data',{}).get('result',[])
assert res, 'no result for node_exporter_build_info'
ts=float(res[0]['value'][0])
now=time.time()
assert now-ts<180, f"sample too old: now={now} ts={ts}"
print(int(ts))
PY
T1=$?
sleep 30
curl -fsS --max-time 5 --get "$PROM_BASE/query" --data-urlencode "query=node_exporter_build_info{job=\"node\",ip=\"$IP_ONLY\"}" > "$TMP_DIR/prom_ne_build_info_2.json"
TS1=$(python3 - "$TMP_DIR/prom_ne_build_info_1.json" <<'PY'
import json,sys
print(float(json.load(open(sys.argv[1]))['data']['result'][0]['value'][0]))
PY
)
TS2=$(python3 - "$TMP_DIR/prom_ne_build_info_2.json" <<'PY'
import json,sys
print(float(json.load(open(sys.argv[1]))['data']['result'][0]['value'][0]))
PY
)
awk -v a="$TS1" -v b="$TS2" 'BEGIN{ if (b>=a) exit 0; else exit 1 }' || { echo "[ERR] sample timestamp did not advance" >&2; exit 1; }
echo "[OK] sample timestamp advanced"
echo "[DONE] dataplane verify"

View File

@@ -1,39 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
PROM_DOMAIN="prom.metric.argus.com:9090"
GRAF="http://localhost:3000"
echo "[VERIFY:GRAFANA] /api/health"
TMP_FILE="$(cd "$(dirname "$0")"/.. && pwd)/tmp/metric-verify/graf_health.json"
mkdir -p "$(dirname "$TMP_FILE")"
curl -fsS --max-time 10 "$GRAF/api/health" -o "$TMP_FILE" || { echo "[ERR] failed to GET /api/health" >&2; exit 1; }
python3 - "$TMP_FILE" <<'PY'
import sys,json
with open(sys.argv[1],'r',encoding='utf-8') as f:
j=json.load(f)
assert j.get('database')=='ok', f"health not ok: {j}"
print('OK')
PY
echo "[VERIFY:GRAFANA] datasource URL uses domain: $PROM_DOMAIN"
DS_FILE="/private/argus/metric/grafana/provisioning/datasources/datasources.yml"
if ! docker exec argus-grafana sh -lc "test -f $DS_FILE"; then
DS_FILE="/etc/grafana/provisioning/datasources/datasources.yml"
fi
docker exec argus-grafana sh -lc "grep -E 'url:\s*http://$PROM_DOMAIN' '$DS_FILE'" >/dev/null 2>&1 || { echo "[ERR] datasource not pointing to $PROM_DOMAIN" >&2; exit 1; }
echo "[OK] datasource points to domain"
echo "[VERIFY:GRAFANA] bind resolution inside grafana"
tries=0
until docker exec argus-grafana getent hosts prom.metric.argus.com >/dev/null 2>&1; do
tries=$((tries+1))
if (( tries > 24 )); then
echo "[ERR] grafana cannot resolve prom.metric.argus.com" >&2
exit 1
fi
echo "[..] waiting DNS propagation in grafana ($tries/24)"; sleep 5
done
echo "[OK] domain resolves"
echo "[DONE] grafana verify"

View File

@@ -1,70 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
TMP_DIR="$TEST_ROOT/tmp/metric-verify"
mkdir -p "$TMP_DIR"
GRAF="http://localhost:3000"
HOSTNAME="${METRIC_TEST_HOSTNAME:-test-metric-node-001}"
echo "[VERIFY:GRAF-PANELS] resolve Prometheus datasource UID via Grafana"
DS_JSON="$TMP_DIR/graf_ds.json"
curl -fsS --max-time 10 "$GRAF/api/datasources" >"$DS_JSON"
DS_UID=$(python3 - "$DS_JSON" <<'PY'
import json,sys
arr=json.load(open(sys.argv[1]))
for ds in arr:
if (ds.get('type')=='prometheus'):
print(ds.get('uid',''))
break
PY
)
if [[ -z "$DS_UID" ]]; then echo "[ERR] no prometheus datasource found in grafana" >&2; exit 1; fi
echo "[OK] Prometheus DS UID=$DS_UID"
proxy_query() {
local q="$1"; local out="$2"
curl -fsS --max-time 10 --get "$GRAF/api/datasources/proxy/uid/$DS_UID/api/v1/query" \
--data-urlencode "query=$q" >"$out"
}
assert_vector_recent_nonempty() {
local json="$1"; local max_age_sec="${2:-180}"
python3 - <<'PY' "$json" "$max_age_sec"
import json,sys,time
doc=json.load(open(sys.argv[1]))
if doc.get('status')!='success':
raise SystemExit('prom status != success')
res=doc.get('data',{}).get('result',[])
assert res, 'empty result'
ts=float(res[0]['value'][0])
assert time.time()-ts < float(sys.argv[2]), f'timestamp too old: {ts}'
print(int(ts))
PY
}
echo "[VERIFY:GRAF-PANELS] Dashboard: Node and GPU Metrics — System Load"
Q_NODE_LOAD="node_load1{hostname=\"$HOSTNAME\"}"
proxy_query "$Q_NODE_LOAD" "$TMP_DIR/graf_panel_node_load.json"
assert_vector_recent_nonempty "$TMP_DIR/graf_panel_node_load.json" 300 >/dev/null
echo "[OK] node_load1 has recent sample via Grafana proxy"
echo "[VERIFY:GRAF-PANELS] Dashboard: Cluster Dashboard — Node online count"
Q_NODE_ONLINE='count(count by(hostname) (up{job="node"} == 1))'
proxy_query "$Q_NODE_ONLINE" "$TMP_DIR/graf_panel_node_online.json"
python3 - "$TMP_DIR/graf_panel_node_online.json" <<'PY'
import json,sys
doc=json.load(open(sys.argv[1]))
assert doc.get('status')=='success', 'prom status not success'
res=doc.get('data',{}).get('result',[])
assert res, 'no series for node online count'
val=float(res[0]['value'][1])
assert val>=1, f'node online < 1: {val}'
print('OK',val)
PY
echo "[OK] cluster node online count >= 1 via Grafana proxy"
echo "[DONE] grafana panels verify"

View File

@@ -1,105 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
TMP_DIR="$TEST_ROOT/tmp/metric-verify"
mkdir -p "$TMP_DIR"
MASTER_BASE="http://localhost:32300/api/v1/master"
HOSTNAME="${METRIC_TEST_HOSTNAME:-test-metric-node-001}"
curl_json() { curl -fsS --max-time 5 "$1"; }
echo "[VERIFY:MASTER] list nodes and locate target hostname=$HOSTNAME"
ALL_NODES_JSON="$TMP_DIR/master_nodes.json"
# 重试等待节点出现在 /nodes 列表(最多 120s)
NODE_ID=""
for attempt in {1..24}; do
curl_json "$MASTER_BASE/nodes" > "$ALL_NODES_JSON" || true
NODE_ID=$(python3 - "$ALL_NODES_JSON" "$HOSTNAME" <<'PY'
import json,sys
try:
nodes=json.load(open(sys.argv[1]))
except Exception:
nodes=[]
name=sys.argv[2]
for n in nodes:
if n.get('name')==name:
print(n.get('id',''))
break
PY
)
if [[ -n "$NODE_ID" ]]; then break; fi
echo "[..] waiting node to appear in /nodes ($attempt/24)"; sleep 5
done
if [[ -z "$NODE_ID" ]]; then
echo "[ERR] master /nodes 中未找到 $HOSTNAME(等待超时)" >&2
echo "[HINT] 当前 /nodes 列表如下:" >&2
sed -n '1,160p' "$ALL_NODES_JSON" >&2 || true
exit 1
fi
echo "[OK] node id=$NODE_ID"
echo "[VERIFY:MASTER] get node detail and assert fields"
DETAIL1_JSON="$TMP_DIR/master_node_${NODE_ID}_detail_1.json"
curl_json "$MASTER_BASE/nodes/$NODE_ID" > "$DETAIL1_JSON"
# 基础字段与健康项检查(不强制立即 online)
python3 - "$DETAIL1_JSON" "$HOSTNAME" <<'PY'
import json,sys,datetime
j=json.load(open(sys.argv[1]))
host=sys.argv[2]
assert j.get('name')==host, f"name mismatch: {j.get('name')} != {host}"
status=j.get('status')
assert status in ('initialized','online','offline'), f"unexpected status: {status}"
md=j.get('meta_data',{})
assert md.get('hostname',j.get('name'))==host, 'meta_data.hostname mismatch'
assert 'last_report' in j and j['last_report'], 'last_report missing'
h=j.get('health',{})
for key in ('metric-node-exporter','metric-fluent-bit','metric-argus-agent'):
if key in h:
assert h[key].get('status')=='healthy', f"{key} not healthy: {h[key]}"
print('OK')
PY
# 轮询等待 last_report 前进并最终转为 online(最多 90s),容忍短暂 5xx/网络错误
attempt=0
T_PRE=0
until [[ $attempt -ge 18 ]]; do
sleep 5
DETAIL_CUR="$TMP_DIR/master_node_${NODE_ID}_detail_cur.json"
if ! curl_json "$MASTER_BASE/nodes/$NODE_ID" > "$DETAIL_CUR" 2>/dev/null; then
echo "[..] retrying node detail fetch ($attempt/18)"; ((attempt++)); continue
fi
read -r STATUS_CUR T_CUR < <(python3 - "$DETAIL_CUR" <<'PY'
import json,sys,datetime
j=json.load(open(sys.argv[1]))
st=j.get('status','')
ts=j.get('last_report','')
if ts.endswith('Z'): ts=ts.replace('Z','+00:00')
try:
t=float(datetime.datetime.fromisoformat(ts).timestamp())
except Exception:
t=0.0
print(st)
print(t)
PY
)
if awk -v a="$T_PRE" -v b="$T_CUR" 'BEGIN{exit !(b>a)}'; then
T_PRE="$T_CUR"
fi
if [[ "$STATUS_CUR" == "online" ]]; then
echo "[OK] status online and last_report progressed"
break
fi
((attempt++))
done
if (( attempt >= 18 )) && [[ "$STATUS_CUR" != "online" ]]; then
echo "[WARN] status did not reach online within timeout; continuing"
fi
echo "$NODE_ID" > "$TMP_DIR/node_id_metric"
echo "[DONE] master verify"

View File

@@ -1,142 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
TMP_DIR="$TEST_ROOT/tmp/metric-verify"
mkdir -p "$TMP_DIR"
PROM_BASE="http://localhost:9090/api/v1"
HOSTNAME="${METRIC_TEST_HOSTNAME:-test-metric-node-001}"
nodes_json="$TEST_ROOT/private/argus/metric/prometheus/nodes.json"
targets_json="$TEST_ROOT/private/argus/metric/prometheus/targets/node_exporter.json"
echo "[VERIFY:PROM] nodes.json present and contains hostname=$HOSTNAME"
[[ -f "$nodes_json" ]] || { echo "[ERR] $nodes_json missing" >&2; exit 1; }
python3 - "$nodes_json" "$HOSTNAME" <<'PY'
import json,sys
arr=json.load(open(sys.argv[1]))
host=sys.argv[2]
assert any((i.get('hostname')==host) for i in arr), f"{host} not found in nodes.json"
PY
echo "[OK] nodes.json contains target"
echo "[VERIFY:PROM] file_sd targets exist for nodes.json entries"
[[ -f "$targets_json" ]] || { echo "[ERR] $targets_json missing" >&2; exit 1; }
python3 - "$nodes_json" "$targets_json" "$HOSTNAME" >"$TMP_DIR/prom_targets_ip_inst.txt" <<'PY'
import json,sys
nodes=json.load(open(sys.argv[1]))
file_sd=json.load(open(sys.argv[2]))
host=sys.argv[3]
targets=set()
for item in file_sd:
for t in item.get('targets',[]): targets.add(t)
# choose node matching hostname; fallback to first metric user node; otherwise first
sel = None
for n in nodes:
if n.get('hostname') == host:
sel = n
break
if not sel:
for n in nodes:
if n.get('user_id') == 'metric':
sel = n
break
if not sel and nodes:
sel = nodes[0]
if not sel:
raise SystemExit('nodes.json empty or no suitable node found')
ip = sel['ip']
inst = f"{ip}:9100"
print(ip)
print(inst)
PY
IP_FIRST=$(sed -n '1p' "$TMP_DIR/prom_targets_ip_inst.txt")
INSTANCE=$(sed -n '2p' "$TMP_DIR/prom_targets_ip_inst.txt")
echo "[INFO] expecting instance in file_sd: $INSTANCE"
# 尝试在 Prometheus 容器内主动刷新 targets(可选加速)
if docker ps --format '{{.Names}}' | grep -q '^argus-prometheus$'; then
echo "[..] triggering update_targets inside argus-prometheus"
docker exec argus-prometheus bash -lc \
'python3 /usr/local/bin/update_targets.py --config /private/argus/metric/prometheus/nodes.json --targets-dir /private/argus/metric/prometheus/targets >/dev/null 2>&1 || true'
fi
# 给 Prometheus 一次初始 scrape 周期
sleep 10
# 若短暂未生成,进行重试(最多 180s),期间多次触发刷新
retry=0
until jq -r '.[].targets[]' "$targets_json" 2>/dev/null | grep -q "^${IP_FIRST}:9100$"; do
if (( retry >= 36 )); then
echo "[ERR] ${IP_FIRST}:9100 not present in file_sd after timeout" >&2
echo "[HINT] current targets file content:" >&2
sed -n '1,200p' "$targets_json" >&2 || true
exit 1
fi
if (( retry % 3 == 0 )) && docker ps --format '{{.Names}}' | grep -q '^argus-prometheus$'; then
docker exec argus-prometheus bash -lc \
'python3 /usr/local/bin/update_targets.py --config /private/argus/metric/prometheus/nodes.json --targets-dir /private/argus/metric/prometheus/targets >/dev/null 2>&1 || true'
fi
echo "[..] waiting file_sd refresh ($retry/36)"; sleep 5; ((retry++))
done
# 改为以 PromQL up 指标作为健康依据,避免 targets 页面状态抖动
echo "[VERIFY:PROM] up{job=\"node\",ip=\"$IP_FIRST\"} > 0"
attempt=0
until (( attempt >= 60 )); do
curl -fsS --max-time 5 --get "$PROM_BASE/query" --data-urlencode "query=up{job=\"node\",ip=\"$IP_FIRST\"}" > "$TMP_DIR/prom_up_inst_active.json" || true
if python3 - "$TMP_DIR/prom_up_inst_active.json" <<'PY'
import json,sys
try:
j=json.load(open(sys.argv[1]))
except Exception:
raise SystemExit(1)
res=j.get('data',{}).get('result',[])
if res:
try:
val=float(res[0]['value'][1])
if val>0: raise SystemExit(0)
except Exception:
pass
raise SystemExit(1)
PY
then
echo "[OK] up > 0 (control-plane scrape works)"; break
fi
if (( attempt % 6 == 0 )) && docker ps --format '{{.Names}}' | grep -q '^argus-prometheus$'; then
docker exec argus-prometheus bash -lc \
'python3 /usr/local/bin/update_targets.py --config /private/argus/metric/prometheus/nodes.json --targets-dir /private/argus/metric/prometheus/targets >/dev/null 2>&1 || true'
fi
echo "[..] waiting up{job=\"node\",ip=\"$IP_FIRST\"} > 0 ($attempt/60)"; sleep 5; ((attempt++))
done
if (( attempt >= 60 )); then
echo "[ERR] up{job=\"node\",ip=\"$IP_FIRST\"} did not become > 0" >&2
exit 1
fi
echo "[VERIFY:PROM] instant up query > 0"
curl -fsS --max-time 5 --get "$PROM_BASE/query" --data-urlencode "query=up{job=\"node\",ip=\"$IP_FIRST\"}" > "$TMP_DIR/prom_up_inst.json"
python3 - "$TMP_DIR/prom_up_inst.json" <<'PY'
import json,sys
j=json.load(open(sys.argv[1]))
res=j.get('data',{}).get('result',[])
assert res, 'empty result for up{job="node",instance=...}'
val=float(res[0]['value'][1])
assert val>0, f"up value not > 0: {val}"
PY
echo "[OK] up > 0"
echo "[VERIFY:PROM] count(up{job=\"node\"}==1) >= 1"
curl -fsS --max-time 5 --get "$PROM_BASE/query" --data-urlencode "query=count(up{job=\"node\"}==1)" > "$TMP_DIR/prom_up_count.json"
python3 - "$TMP_DIR/prom_up_count.json" <<'PY'
import json,sys
j=json.load(open(sys.argv[1]))
res=j.get('data',{}).get('result',[])
assert res, 'empty result for count(up{job="node"}==1)'
val=float(res[0]['value'][1])
assert val>=1, f"count < 1: {val}"
PY
echo "[OK] up count satisfied"
echo "[DONE] prometheus verify"

View File

@@ -1,18 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
FTP_SHARE="$TEST_ROOT/private/argus/metric/ftp/share"
if [[ -d "$FTP_SHARE" ]]; then
echo "[SYS-METRIC] 清理 FTP 发布产物..."
rm -f "$FTP_SHARE"/argus-metric_*.tar.gz 2>/dev/null || true
rm -f "$FTP_SHARE"/LATEST_VERSION 2>/dev/null || true
rm -f "$FTP_SHARE"/dns.conf "$FTP_SHARE"/setup.sh 2>/dev/null || true
else
echo "[SYS-METRIC] FTP 目录不存在,跳过清理"
fi
echo "[SYS-METRIC] Metric 清理完成"

View File

@@ -1,45 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
AGENT_ROOT=${AGENT_ROOT:-/private/argus/agent}
PREPARED_FLAG="/tmp/.metric_node_prepared"
export DEBIAN_FRONTEND=${DEBIAN_FRONTEND:-noninteractive}
if [[ ! -f "$PREPARED_FLAG" ]]; then
apt-get update -qq
apt-get install -y -qq \
curl \
net-tools \
iproute2 \
lsof \
procps \
ca-certificates \
gnupg2 || {
echo "[metric-node] Failed to install base packages" >&2
exit 1
}
mkdir -p "$(dirname "$PREPARED_FLAG")"
touch "$PREPARED_FLAG"
fi
if [[ -n "${TZ:-}" ]]; then
ln -snf "/usr/share/zoneinfo/${TZ}" /etc/localtime 2>/dev/null || true
echo "$TZ" > /etc/timezone 2>/dev/null || true
fi
mkdir -p "$AGENT_ROOT"
chown -R "${ARGUS_BUILD_UID}:${ARGUS_BUILD_GID}" "$AGENT_ROOT" 2>/dev/null || true
if [[ "${METRIC_NODE_ROLE:-cpu}" == "gpu" ]]; then
if ! command -v nvidia-smi >/dev/null 2>&1; then
echo "[metric-node] nvidia-smi not available but GPU role requested" >&2
exit 1
fi
nvidia-smi || true
fi
exec "$@"

View File

@@ -46,9 +46,7 @@ fi
# Start Fluent Bit in background (will block, so run via bash -lc &) # Start Fluent Bit in background (will block, so run via bash -lc &)
if [[ -x /private/start-fluent-bit.sh ]]; then if [[ -x /private/start-fluent-bit.sh ]]; then
log "starting fluent-bit" log "starting fluent-bit"
sysctl -w fs.inotify.max_user_instances=512 >/dev/null 2>&1 || true bash -lc '/private/start-fluent-bit.sh' &
sysctl -w fs.inotify.max_user_watches=524288 >/dev/null 2>&1 || true
bash -lc 'ulimit -n 65536 || true; exec /private/start-fluent-bit.sh' &
else else
log "missing /private/start-fluent-bit.sh; fluent-bit will not start" log "missing /private/start-fluent-bit.sh; fluent-bit will not start"
fi fi
@@ -56,3 +54,4 @@ fi
# Start agent in foreground as runtime user # Start agent in foreground as runtime user
log "starting argus-agent" log "starting argus-agent"
exec su -s /bin/bash -c /usr/local/bin/argus-agent "$RUNTIME_USER" exec su -s /bin/bash -c /usr/local/bin/argus-agent "$RUNTIME_USER"

View File

@@ -24,37 +24,24 @@ RUN apt-get update && \
apt-get clean && rm -rf /var/lib/apt/lists/* apt-get clean && rm -rf /var/lib/apt/lists/*
ENV FRONTEND_BASE_PATH=/private/argus/web/frontend ENV FRONTEND_BASE_PATH=/private/argus/web/frontend
ARG ARGUS_BUILD_UID=2133 ARG ARGUS_UID=2133
ARG ARGUS_BUILD_GID=2015 ARG ARGUS_GID=2015
ENV ARGUS_BUILD_UID=${ARGUS_BUILD_UID} ENV ARGUS_UID=${ARGUS_UID}
ENV ARGUS_BUILD_GID=${ARGUS_BUILD_GID} ENV ARGUS_GID=${ARGUS_GID}
RUN mkdir -p ${FRONTEND_BASE_PATH} && \ RUN mkdir -p ${FRONTEND_BASE_PATH} && \
mkdir -p /private/argus/etc mkdir -p /private/argus/etc
# 创建 web 用户(可自定义 UID/GID) # 创建 web 用户(可自定义 UID/GID)
# 创建 web 用户组 # 创建 web 用户组
RUN set -eux; \ RUN groupadd -g ${ARGUS_GID} web
# 确保目标 GID 存在(组名可不固定)\
if ! getent group "${ARGUS_BUILD_GID}" >/dev/null; then \ # 创建 web 用户并指定组
groupadd -g "${ARGUS_BUILD_GID}" web || true; \ RUN useradd -M -s /usr/sbin/nologin -u ${ARGUS_UID} -g ${ARGUS_GID} web
fi; \
# 若存在 web 用户则尽量对齐 UID/GID;否则仅在 UID 未被占用时创建 RUN chown -R web:web ${FRONTEND_BASE_PATH} && \
if id web >/dev/null 2>&1; then \ chown -R web:web /private/argus/etc && \
current_uid="$(id -u web)"; \ chown -R web:web /usr/local/bin
if [ "$current_uid" != "${ARGUS_BUILD_UID}" ] && ! getent passwd "${ARGUS_BUILD_UID}" >/dev/null; then \
usermod -u "${ARGUS_BUILD_UID}" web; \
fi; \
usermod -g "${ARGUS_BUILD_GID}" web || true; \
else \
if ! getent passwd "${ARGUS_BUILD_UID}" >/dev/null; then \
useradd -M -s /usr/sbin/nologin -u "${ARGUS_BUILD_UID}" -g "${ARGUS_BUILD_GID}" web; \
else \
echo "UID ${ARGUS_BUILD_UID} already exists; skip creating user 'web'"; \
fi; \
fi; \
# 用数值 UID:GID 赋权,避免依赖用户名/组名
chown -R "${ARGUS_BUILD_UID}:${ARGUS_BUILD_GID}" ${FRONTEND_BASE_PATH} /private/argus/etc /usr/local/bin || true
# 配置内网 apt 源 (如果指定了内网选项) # 配置内网 apt 源 (如果指定了内网选项)
RUN if [ "$USE_INTRANET" = "true" ]; then \ RUN if [ "$USE_INTRANET" = "true" ]; then \

View File

@@ -4,7 +4,7 @@ docker pull ubuntu:24.04
source src/web/tests/.env source src/web/tests/.env
docker build \ docker build \
--build-arg ARGUS_BUILD_UID=${ARGUS_BUILD_UID} \ --build-arg ARGUS_UID=${ARGUS_UID} \
--build-arg ARGUS_BUILD_GID=${ARGUS_BUILD_GID} \ --build-arg ARGUS_GID=${ARGUS_GID} \
-f src/web/build_tools/frontend/Dockerfile -t argus-web-frontend:latest . -f src/web/build_tools/frontend/Dockerfile -t argus-web-frontend:latest .
docker save -o argus-web-frontend-latest.tar argus-web-frontend:latest docker save -o argus-web-frontend-latest.tar argus-web-frontend:latest

View File

@@ -1,4 +1,4 @@
user root; user web;
worker_processes auto; worker_processes auto;
events { events {

View File

@@ -8,8 +8,8 @@ DNS_SCRIPT="${DNS_DIR}/update-dns.sh"
DOMAIN=web.argus.com DOMAIN=web.argus.com
WEB_DOMAIN_FILE="${DNS_DIR}/${DOMAIN}" WEB_DOMAIN_FILE="${DNS_DIR}/${DOMAIN}"
RUNTIME_USER="${ARGUS_RUNTIME_USER:-argus}" RUNTIME_USER="${ARGUS_RUNTIME_USER:-argus}"
RUNTIME_UID="${ARGUS_BUILD_UID:-2133}" RUNTIME_UID="${ARGUS_UID:-2133}"
RUNTIME_GID="${ARGUS_BUILD_GID:-2015}" RUNTIME_GID="${ARGUS_GID:-2015}"
mkdir -p "$DNS_DIR" mkdir -p "$DNS_DIR"
chown -R "$RUNTIME_UID:$RUNTIME_GID" "$DNS_DIR" 2>/dev/null || true chown -R "$RUNTIME_UID:$RUNTIME_GID" "$DNS_DIR" 2>/dev/null || true

View File

@@ -18,7 +18,7 @@ stopasgroup=true
[program:web-health] [program:web-health]
command=/usr/local/bin/health-check.sh command=/usr/local/bin/health-check.sh
user=root user=web
stdout_logfile=/var/log/supervisor/web-health.log stdout_logfile=/var/log/supervisor/web-health.log
stderr_logfile=/var/log/supervisor/web-health_error.log stderr_logfile=/var/log/supervisor/web-health_error.log
autorestart=true autorestart=true

View File

@@ -8,34 +8,24 @@ RUN apt-get update && \
apt-get clean && rm -rf /var/lib/apt/lists/* apt-get clean && rm -rf /var/lib/apt/lists/*
ENV FRONTEND_BASE_PATH=/private/argus/web/proxy ENV FRONTEND_BASE_PATH=/private/argus/web/proxy
ARG ARGUS_BUILD_UID=2133 ARG ARGUS_UID=2133
ARG ARGUS_BUILD_GID=2015 ARG ARGUS_GID=2015
ENV ARGUS_BUILD_UID=${ARGUS_BUILD_UID} ENV ARGUS_UID=${ARGUS_UID}
ENV ARGUS_BUILD_GID=${ARGUS_BUILD_GID} ENV ARGUS_GID=${ARGUS_GID}
RUN mkdir -p ${FRONTEND_BASE_PATH} && \ RUN mkdir -p ${FRONTEND_BASE_PATH} && \
mkdir -p /private/argus/etc mkdir -p /private/argus/etc
# 创建 proxy 用户(可自定义 UID/GID) # 创建 proxy 用户(可自定义 UID/GID)
# 创建 proxy 用户组 # 创建 proxy 用户组
RUN set -eux; \ RUN groupadd -g ${ARGUS_GID} web_proxy
if ! getent group "${ARGUS_BUILD_GID}" >/dev/null; then \
groupadd -g "${ARGUS_BUILD_GID}" web_proxy || true; \ # 创建 proxy 用户并指定组
fi; \ RUN useradd -M -s /usr/sbin/nologin -u ${ARGUS_UID} -g ${ARGUS_GID} web_proxy
if id web_proxy >/dev/null 2>&1; then \
current_uid="$(id -u web_proxy)"; \ RUN chown -R web_proxy:web_proxy ${FRONTEND_BASE_PATH} && \
if [ "$current_uid" != "${ARGUS_BUILD_UID}" ] && ! getent passwd "${ARGUS_BUILD_UID}" >/dev/null; then \ chown -R web_proxy:web_proxy /private/argus/etc && \
usermod -u "${ARGUS_BUILD_UID}" web_proxy; \ chown -R web_proxy:web_proxy /usr/local/bin
fi; \
usermod -g "${ARGUS_BUILD_GID}" web_proxy || true; \
else \
if ! getent passwd "${ARGUS_BUILD_UID}" >/dev/null; then \
useradd -M -s /usr/sbin/nologin -u "${ARGUS_BUILD_UID}" -g "${ARGUS_BUILD_GID}" web_proxy; \
else \
echo "UID ${ARGUS_BUILD_UID} already exists; skip creating user 'web_proxy'"; \
fi; \
fi; \
chown -R "${ARGUS_BUILD_UID}:${ARGUS_BUILD_GID}" ${FRONTEND_BASE_PATH} /private/argus/etc /usr/local/bin || true
# 配置内网 apt 源 (如果指定了内网选项) # 配置内网 apt 源 (如果指定了内网选项)
RUN if [ "$USE_INTRANET" = "true" ]; then \ RUN if [ "$USE_INTRANET" = "true" ]; then \
@@ -66,16 +56,13 @@ RUN mkdir -p /var/log/supervisor
# 复制启动脚本 # 复制启动脚本
COPY src/web/build_tools/proxy/start-proxy-supervised.sh /usr/local/bin/start-proxy-supervised.sh COPY src/web/build_tools/proxy/start-proxy-supervised.sh /usr/local/bin/start-proxy-supervised.sh
RUN chmod +x /usr/local/bin/start-proxy-supervised.sh RUN chmod +x /usr/local/bin/start-proxy-supervised.sh
COPY src/web/build_tools/proxy/start-proxy-retry.sh /usr/local/bin/start-proxy-retry.sh
RUN chmod +x /usr/local/bin/start-proxy-retry.sh
# 复制 DNS 监控脚本 # 复制 DNS 监控脚本
# 统一复用 bind 模块的 dns-monitor 脚本,保持行为一致 COPY src/web/build_tools/proxy/dns-monitor.sh /usr/local/bin/dns-monitor.sh
COPY src/bind/build/dns-monitor.sh /usr/local/bin/dns-monitor.sh
RUN chmod +x /usr/local/bin/dns-monitor.sh RUN chmod +x /usr/local/bin/dns-monitor.sh
# 暴露端口 # 暴露端口
EXPOSE 80 8080 8081 8082 8083 8084 8085 EXPOSE 80
# 保持 root 用户,由 supervisor 控制 user 切换 # 保持 root 用户,由 supervisor 控制 user 切换
USER root USER root

View File

@@ -3,7 +3,7 @@ docker pull ubuntu:24.04
source src/web/tests/.env source src/web/tests/.env
docker build \ docker build \
--build-arg ARGUS_BUILD_UID=${ARGUS_BUILD_UID} \ --build-arg ARGUS_UID=${ARGUS_UID} \
--build-arg ARGUS_BUILD_GID=${ARGUS_BUILD_GID} \ --build-arg ARGUS_GID=${ARGUS_GID} \
-f src/web/build_tools/proxy/Dockerfile -t argus-web-proxy:latest . -f src/web/build_tools/proxy/Dockerfile -t argus-web-proxy:latest .
docker save -o argus-web-proxy-latest.tar argus-web-proxy:latest docker save -o argus-web-proxy-latest.tar argus-web-proxy:latest

View File

@@ -0,0 +1,9 @@
server {
listen 80;
server_name alertmanager.alert.argus.com;
location / {
set $alert_backend http://alertmanager.alert.argus.com:9093;
proxy_pass $alert_backend;
}
}

View File

@@ -0,0 +1,21 @@
# Elasticsearch
server {
listen 80;
server_name es.log.argus.com;
location / {
set $es_backend http://es.log.argus.com:9200;
proxy_pass $es_backend;
}
}
# Kibana
server {
listen 80;
server_name kibana.log.argus.com;
location / {
set $kibana_backend http://kibana.log.argus.com:5601;
proxy_pass $kibana_backend;
}
}

View File

@@ -0,0 +1,27 @@
server {
listen 80;
server_name master.argus.com;
location / {
set $master_backend http://master.argus.com:3000;
proxy_pass $master_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# CORS 支持
add_header 'Access-Control-Allow-Origin' 'http://web.argus.com' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Origin, Content-Type, Accept, Authorization' always;
if ($request_method = OPTIONS) {
add_header 'Access-Control-Allow-Origin' 'http://web.argus.com' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Origin, Content-Type, Accept, Authorization' always;
add_header 'Content-Length' 0;
add_header 'Content-Type' 'text/plain';
return 204;
}
}
}

View File

@@ -0,0 +1,21 @@
# Prometheus
server {
listen 80;
server_name prometheus.metric.argus.com;
location / {
set $prom_backend http://prom.metric.argus.com:9090;
proxy_pass $prom_backend;
}
}
# Grafana
server {
listen 80;
server_name grafana.metric.argus.com;
location / {
set $grafana_backend http://grafana.metric.argus.com:3000;
proxy_pass $grafana_backend;
}
}

View File

@@ -1,94 +0,0 @@
map $http_upgrade $connection_upgrade { default upgrade; "" close; }
# 允许的跨域来源(仅用于 8084/8085)
map $http_origin $cors_allow {
default "";
"http://localhost:8080" "http://localhost:8080";
"http://127.0.0.1:8080" "http://127.0.0.1:8080";
}
# 8080 - Portal
server {
listen 8080;
server_name _;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_http_version 1.1;
location / { proxy_pass http://web.argus.com:8080/; }
}
# 8081 - Grafana
server {
listen 8081;
server_name _;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_http_version 1.1;
location / { proxy_pass http://grafana.metric.argus.com:3000/; }
}
# 8082 - Prometheus
server {
listen 8082;
server_name _;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
location / { proxy_pass http://prom.metric.argus.com:9090/; }
}
# 8083 - Kibana
server {
listen 8083;
server_name _;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_http_version 1.1;
location / { proxy_pass http://kibana.log.argus.com:5601/; }
}
# 8084 - Alertmanager(含 CORS)
server {
listen 8084;
server_name _;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
add_header 'Access-Control-Allow-Origin' $cors_allow always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Origin, Content-Type, Accept, Authorization' always;
if ($request_method = OPTIONS) { return 204; }
proxy_http_version 1.1;
location / { proxy_pass http://alertmanager.alert.argus.com:9093/; }
}
# 8085 - Master(新增,含 CORS)
server {
listen 8085;
server_name _;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
add_header 'Access-Control-Allow-Origin' $cors_allow always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Origin, Content-Type, Accept, Authorization' always;
if ($request_method = OPTIONS) { return 204; }
proxy_http_version 1.1;
location / { proxy_pass http://master.argus.com:3000/; }
}

View File

@@ -0,0 +1,9 @@
server {
listen 80;
server_name web.argus.com;
location / {
set $web_backend http://web.argus.com:8080;
proxy_pass $web_backend;
}
}

View File

@@ -0,0 +1,68 @@
#!/bin/bash
# DNS监控脚本 - 每10秒检查dns.conf是否有变化
# 如果有变化则执行update-dns.sh脚本
DNS_CONF="/private/argus/etc/dns.conf"
DNS_BACKUP="/tmp/dns.conf.backup"
UPDATE_SCRIPT="/private/argus/etc/update-dns.sh"
LOG_FILE="/var/log/supervisor/dns-monitor.log"
# 确保日志文件存在
touch "$LOG_FILE"
log_message() {
echo "$(date '+%Y-%m-%d %H:%M:%S') [DNS-Monitor] $1" >> "$LOG_FILE"
}
log_message "DNS监控脚本启动"
while true; do
if [ -f "$DNS_CONF" ]; then
if [ -f "$DNS_BACKUP" ]; then
# 比较文件内容
if ! cmp -s "$DNS_CONF" "$DNS_BACKUP"; then
log_message "检测到DNS配置变化"
# 更新备份文件
cp "$DNS_CONF" "$DNS_BACKUP"
# 执行更新脚本
if [ -x "$UPDATE_SCRIPT" ]; then
log_message "执行DNS更新脚本: $UPDATE_SCRIPT"
"$UPDATE_SCRIPT" >> "$LOG_FILE" 2>&1
if [ $? -eq 0 ]; then
log_message "DNS更新脚本执行成功"
else
log_message "DNS更新脚本执行失败"
fi
else
log_message "警告: 更新脚本不存在或不可执行: $UPDATE_SCRIPT"
fi
fi
else
# 第一次检测到配置文件,执行更新脚本
if [ -x "$UPDATE_SCRIPT" ]; then
log_message "执行DNS更新脚本: $UPDATE_SCRIPT"
"$UPDATE_SCRIPT" >> "$LOG_FILE" 2>&1
if [ $? -eq 0 ]; then
log_message "DNS更新脚本执行成功"
# 第一次运行,创建备份并执行更新
cp "$DNS_CONF" "$DNS_BACKUP"
log_message "创建DNS配置备份文件"
else
log_message "DNS更新脚本执行失败"
fi
else
log_message "警告: 更新脚本不存在或不可执行: $UPDATE_SCRIPT"
fi
fi
else
log_message "警告: DNS配置文件不存在: $DNS_CONF"
fi
sleep 10
done

View File

@@ -1,4 +1,4 @@
user root; user web_proxy;
worker_processes auto; worker_processes auto;
events { events {
@@ -13,7 +13,6 @@ http {
# 使用系统 resolv.conf(由 update-dns.sh 动态更新) # 使用系统 resolv.conf(由 update-dns.sh 动态更新)
resolver __RESOLVERS__ valid=30s ipv6=off; resolver __RESOLVERS__ valid=30s ipv6=off;
resolver_timeout 5s;
# 启用访问日志 # 启用访问日志
access_log /var/log/nginx/access.log; access_log /var/log/nginx/access.log;

View File

@@ -1,20 +0,0 @@
#!/bin/sh
set -eu
MAX=${RETRY_MAX:-10}
DELAY=${RETRY_DELAY:-10}
ATTEMPT=1
echo "[INFO] proxy retry wrapper: max=${MAX}, delay=${DELAY}s"
while [ "$ATTEMPT" -le "$MAX" ]; do
echo "[INFO] starting proxy attempt ${ATTEMPT}/${MAX}"
/usr/local/bin/start-proxy-supervised.sh && exit 0 || true
echo "[WARN] proxy exited (attempt ${ATTEMPT}/${MAX}); sleeping ${DELAY}s before retry"
sleep "$DELAY"
ATTEMPT=$((ATTEMPT+1))
done
echo "[ERROR] proxy failed after ${MAX} attempts"
exit 1

View File

@@ -9,8 +9,8 @@ DNS_CONF_PRIVATE="/private/argus/etc/dns.conf"
DNS_CONF_SYSTEM="/etc/resolv.conf" DNS_CONF_SYSTEM="/etc/resolv.conf"
DNS_DIR="/private/argus/etc" DNS_DIR="/private/argus/etc"
DNS_SCRIPT="${DNS_DIR}/update-dns.sh" DNS_SCRIPT="${DNS_DIR}/update-dns.sh"
RUNTIME_UID="${ARGUS_BUILD_UID:-2133}" RUNTIME_UID="${ARGUS_UID:-2133}"
RUNTIME_GID="${ARGUS_BUILD_GID:-2015}" RUNTIME_GID="${ARGUS_GID:-2015}"
mkdir -p "$DNS_DIR" mkdir -p "$DNS_DIR"
chown -R "$RUNTIME_UID:$RUNTIME_GID" "$DNS_DIR" 2>/dev/null || true chown -R "$RUNTIME_UID:$RUNTIME_GID" "$DNS_DIR" 2>/dev/null || true
@@ -46,10 +46,6 @@ echo "检测到 DNS 服务器列表: $RESOLVERS"
# ========== 生成 nginx.conf ========== # ========== 生成 nginx.conf ==========
if [ -f "$TEMPLATE" ]; then if [ -f "$TEMPLATE" ]; then
echo "从模板生成 nginx.conf ..." echo "从模板生成 nginx.conf ..."
# 合并 Docker 内置 DNS 以保障解析 Compose 服务名
if ! echo " $RESOLVERS " | grep -q " 127.0.0.11 "; then
RESOLVERS="127.0.0.11 ${RESOLVERS}"
fi
sed "s|__RESOLVERS__|$RESOLVERS|" "$TEMPLATE" > "$TARGET" sed "s|__RESOLVERS__|$RESOLVERS|" "$TEMPLATE" > "$TARGET"
else else
echo "错误: 找不到 nginx.conf.template ($TEMPLATE)" echo "错误: 找不到 nginx.conf.template ($TEMPLATE)"
@@ -59,33 +55,6 @@ fi
# 打印生成结果供排查 # 打印生成结果供排查
grep resolver "$TARGET" || true grep resolver "$TARGET" || true
# ========== 等待上游域名准备(避免启动即解析失败) ==========
UPSTREAM_DOMAINS=(
web.argus.com
grafana.metric.argus.com
prom.metric.argus.com
kibana.log.argus.com
alertmanager.alert.argus.com
master.argus.com
)
WAIT_MAX=15
WAITED=0
MISSING=()
while :; do
MISSING=()
for d in "${UPSTREAM_DOMAINS[@]}"; do
if [ ! -s "/private/argus/etc/${d}" ]; then
MISSING+=("$d")
fi
done
if [ ${#MISSING[@]} -eq 0 ] || [ "$WAITED" -ge "$WAIT_MAX" ]; then
break
fi
echo "[INFO] 等待上游域名记录生成(${WAITED}/${WAIT_MAX}) 缺失: ${MISSING[*]}"
sleep 1
WAITED=$((WAITED+1))
done
echo "[INFO] Launching nginx..." echo "[INFO] Launching nginx..."
# 启动 nginx 前台模式 # 启动 nginx 前台模式

View File

@@ -5,12 +5,12 @@ pidfile=/var/run/supervisord.pid
user=root user=root
[program:proxy] [program:proxy]
command=/usr/local/bin/start-proxy-retry.sh command=/usr/local/bin/start-proxy-supervised.sh
user=root user=root
stdout_logfile=/var/log/supervisor/web-proxy.log stdout_logfile=/var/log/supervisor/web-proxy.log
stderr_logfile=/var/log/supervisor/web-proxy_error.log stderr_logfile=/var/log/supervisor/web-proxy_error.log
autorestart=true autorestart=true
startretries=10 startretries=3
startsecs=5 startsecs=5
stopwaitsecs=10 stopwaitsecs=10
killasgroup=true killasgroup=true

View File

@@ -1,42 +1,30 @@
// config/api.js // config/api.js
// 运行时解析主机名,统一按端口访问多服务 // Master 节点相关 API
const HOST = (typeof window !== 'undefined' && (window.__ARGUS_PUBLIC_HOST__ || window.location.hostname)) || 'localhost';
const PORTS = {
MASTER: 8085, // 经网关(含 CORS)
ALERTMANAGER: 8084,
GRAFANA: 8081,
PROMETHEUS: 8082,
KIBANA: 8083,
};
const BASE = {
MASTER: `http://${HOST}:${PORTS.MASTER}`,
ALERT: `http://${HOST}:${PORTS.ALERTMANAGER}`,
GRAFANA: `http://${HOST}:${PORTS.GRAFANA}`,
PROM: `http://${HOST}:${PORTS.PROMETHEUS}`,
KIBANA: `http://${HOST}:${PORTS.KIBANA}`,
};
// Master 节点相关 API(统一走 8085)
export const MASTER_API = { export const MASTER_API = {
LIST: `${BASE.MASTER}/api/v1/master/nodes`, // 节点列表
DETAIL: (nodeId) => `${BASE.MASTER}/api/v1/master/nodes/${nodeId}`, LIST: "http://master.argus.com/api/v1/master/nodes",
CONFIG: (nodeId) => `${BASE.MASTER}/api/v1/master/nodes/${nodeId}/config`,
STATISTICS: `${BASE.MASTER}/api/v1/master/nodes/statistics`, // 节点详情(需要 nodeId)
DETAIL: (nodeId) => `http://master.argus.com/api/v1/master/nodes/${nodeId}`,
// 节点配置(需要 nodeId)
CONFIG: (nodeId) => `http://master.argus.com/api/v1/master/nodes/${nodeId}/config`,
// 节点统计信息
STATISTICS: "http://master.argus.com/api/v1/master/nodes/statistics",
}; };
// 其他外部 API(8084) // 其他外部 API
export const EXTERNAL_API = { export const EXTERNAL_API = {
ALERTS_INFOS: `${BASE.ALERT}/api/v2/alerts`, ALERTS_INFOS: "http://alertmanager.alert.argus.com/api/v2/alerts",
}; };
// 外部服务 Host(端口化) // 外部服务 Host
export const EXTERNAL_HOST = { export const EXTERNAL_HOST = {
ALERTS: `${BASE.ALERT}`, ALERTS: "http://alertmanager.alert.argus.com",
GRAFANA: `${BASE.GRAFANA}`, GRAFANA: "http://grafana.metric.argus.com",
GRAFANA_DASHBOARD: `${BASE.GRAFANA}/d/cluster-dashboard/cluster-dashboard`, GRAFANA_DASHBOARD: "http://grafana.metric.argus.com/d/cluster-dashboard/cluster-dashboard",
PROMETHEUS: `${BASE.PROM}`, PROMETHEUS: "http://prometheus.metric.argus.com",
KIBANA: `${BASE.KIBANA}/app/discover`, KIBANA: "http://kibana.log.argus.com/app/discover",
}; };

View File

@@ -4,15 +4,15 @@ services:
context: ../../../ context: ../../../
dockerfile: src/web/build_tools/frontend/Dockerfile dockerfile: src/web/build_tools/frontend/Dockerfile
args: args:
ARGUS_BUILD_UID: ${ARGUS_BUILD_UID:-2133} ARGUS_UID: ${ARGUS_UID:-2133}
ARGUS_BUILD_GID: ${ARGUS_BUILD_GID:-2015} ARGUS_GID: ${ARGUS_GID:-2015}
USE_INTRANET: ${USE_INTRANET:-false} USE_INTRANET: ${USE_INTRANET:-false}
image: argus-web-frontend:latest image: argus-web-frontend:latest
container_name: argus-web-frontend container_name: argus-web-frontend
environment: environment:
- ALERTMANAGER_BASE_PATH=/private/argus/web/frontend - ALERTMANAGER_BASE_PATH=/private/argus/web/frontend
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133} - ARGUS_UID=${ARGUS_UID:-2133}
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015} - ARGUS_GID=${ARGUS_GID:-2015}
ports: ports:
- "${ARGUS_WEB_PORT:-8080}:80" - "${ARGUS_WEB_PORT:-8080}:80"
volumes: volumes:
@@ -31,14 +31,14 @@ services:
context: ../../../ context: ../../../
dockerfile: src/web/build_tools/proxy/Dockerfile dockerfile: src/web/build_tools/proxy/Dockerfile
args: args:
ARGUS_BUILD_UID: ${ARGUS_BUILD_UID:-2133} ARGUS_UID: ${ARGUS_UID:-2133}
ARGUS_BUILD_GID: ${ARGUS_BUILD_GID:-2015} ARGUS_GID: ${ARGUS_GID:-2015}
USE_INTRANET: ${USE_INTRANET:-false} USE_INTRANET: ${USE_INTRANET:-false}
image: argus-web-proxy:latest image: argus-web-proxy:latest
container_name: argus-web-proxy container_name: argus-web-proxy
environment: environment:
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133} - ARGUS_UID=${ARGUS_UID:-2133}
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015} - ARGUS_GID=${ARGUS_GID:-2015}
ports: ports:
- "8088:80" - "8088:80"
volumes: volumes: