Compare commits
9 Commits
dev_1.0.0_
...
a1cdd05950
| Author | SHA1 | Date | |
|---|---|---|---|
| a1cdd05950 | |||
| 0b1ccbd87f | |||
| 1d9a8ec695 | |||
|
|
b0d451cbe7 | ||
|
|
835e81282f | ||
|
|
c4582c99bc | ||
|
|
299765ed40 | ||
|
|
a8bbf2d6e9 | ||
|
|
d1b89c0cf6 |
@@ -10,6 +10,7 @@ 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
|
||||||
-h, --help Show this help message
|
-h, --help Show this help message
|
||||||
|
|
||||||
@@ -17,13 +18,15 @@ 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 --intranet --master-offline
|
$0 --metric # Additionally build metric module images
|
||||||
|
$0 --intranet --master-offline --metric
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
use_intranet=false
|
use_intranet=false
|
||||||
build_master=true
|
build_master=true
|
||||||
build_master_offline=false
|
build_master_offline=false
|
||||||
|
build_metric=true
|
||||||
no_cache=false
|
no_cache=false
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
@@ -41,6 +44,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
|
||||||
@@ -115,14 +122,22 @@ 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" .; then
|
if docker build "${build_args[@]}" "${extra_args[@]}" -f "$dockerfile_path" -t "$tag" "$context"; then
|
||||||
echo "✅ $image_name image built successfully"
|
echo "✅ $image_name image built successfully"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
@@ -131,6 +146,28 @@ build_image() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pull_base_image() {
|
||||||
|
local image_ref=$1
|
||||||
|
local attempts=${2:-3}
|
||||||
|
local delay=${3:-5}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
@@ -184,6 +221,87 @@ 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
|
||||||
|
# =======================================
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
echo "======================================="
|
echo "======================================="
|
||||||
echo "📦 Build Summary"
|
echo "📦 Build Summary"
|
||||||
echo "======================================="
|
echo "======================================="
|
||||||
@@ -210,7 +328,6 @@ 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 # 导出镜像"
|
||||||
|
|||||||
@@ -68,6 +68,12 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
# 函数:检查镜像是否存在
|
# 函数:检查镜像是否存在
|
||||||
|
|||||||
@@ -1,13 +1,31 @@
|
|||||||
# Alertmanager
|
# Alertmanager
|
||||||
|
|
||||||
## 启动示例
|
## 构建
|
||||||
|
1. 首先设置构建和部署的环境变量, 在项目根目录下执行:
|
||||||
|
```bash
|
||||||
|
cp src/alert/tests/.env.example src/alert/tests/.env
|
||||||
|
```
|
||||||
|
|
||||||
|
然后找到复制出来的.env文件,修改环境变量。
|
||||||
|
|
||||||
|
2. 使用脚本构建,在项目根目录下执行:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run -d --name alertmanager \
|
bash src/alert/alertmanager/build/build.sh
|
||||||
-p 9093:9093 \
|
```
|
||||||
-v /opt/alertmanager/data:/alertmanager \
|
|
||||||
argus-alert:latest
|
构建成功后,会在项目根目录下生成argus-alertmanager-latest.tar
|
||||||
|
|
||||||
|
## 部署
|
||||||
|
|
||||||
|
提供docker-compose部署。在src/alert/tests目录下
|
||||||
|
```bash
|
||||||
|
docker-compose up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
## 动态配置
|
## 动态配置
|
||||||
修改alertmanager.yml后,调用`/-/reload`接口可以重新加载配置
|
配置文件放在`/private/argus/alert/alertmanager/alertmanager.yml`下,修改alertmanager.yml后,调用`http://alertmanager.alert.argus.com:9093/-/reload`接口(POST)可以重新加载配置.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST http://localhost:9093/-/reload
|
||||||
|
```
|
||||||
|
|||||||
@@ -19,8 +19,11 @@ RUN wget https://github.com/prometheus/alertmanager/releases/download/v${ALERTMA
|
|||||||
rm 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
|
||||||
ENV ARGUS_UID=2133
|
|
||||||
ENV ARGUS_GID=2015
|
ARG ARGUS_BUILD_UID=2133
|
||||||
|
ARG ARGUS_BUILD_GID=2015
|
||||||
|
ENV ARGUS_BUILD_UID=${ARGUS_BUILD_UID}
|
||||||
|
ENV ARGUS_BUILD_GID=${ARGUS_BUILD_GID}
|
||||||
|
|
||||||
RUN mkdir -p /usr/share/alertmanager && \
|
RUN mkdir -p /usr/share/alertmanager && \
|
||||||
mkdir -p ${ALERTMANAGER_BASE_PATH} && \
|
mkdir -p ${ALERTMANAGER_BASE_PATH} && \
|
||||||
@@ -30,16 +33,25 @@ RUN mkdir -p /usr/share/alertmanager && \
|
|||||||
|
|
||||||
# 创建 alertmanager 用户(可自定义 UID/GID)
|
# 创建 alertmanager 用户(可自定义 UID/GID)
|
||||||
# 创建 alertmanager 用户组
|
# 创建 alertmanager 用户组
|
||||||
RUN groupadd -g ${ARGUS_GID} alertmanager
|
RUN set -eux; \
|
||||||
|
if ! getent group "${ARGUS_BUILD_GID}" >/dev/null; then \
|
||||||
|
groupadd -g "${ARGUS_BUILD_GID}" alertmanager || true; \
|
||||||
|
fi; \
|
||||||
|
if id alertmanager >/dev/null 2>&1; then \
|
||||||
|
current_uid="$(id -u alertmanager)"; \
|
||||||
|
if [ "$current_uid" != "${ARGUS_BUILD_UID}" ] && ! getent passwd "${ARGUS_BUILD_UID}" >/dev/null; then \
|
||||||
|
usermod -u "${ARGUS_BUILD_UID}" alertmanager; \
|
||||||
|
fi; \
|
||||||
|
usermod -g "${ARGUS_BUILD_GID}" alertmanager || 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}" alertmanager; \
|
||||||
|
else \
|
||||||
|
echo "UID ${ARGUS_BUILD_UID} already exists; skip creating user 'alertmanager'"; \
|
||||||
|
fi; \
|
||||||
|
fi
|
||||||
|
|
||||||
# 创建 alertmanager 用户并指定组
|
RUN chown -R "${ARGUS_BUILD_UID}:${ARGUS_BUILD_GID}" /usr/share/alertmanager /alertmanager ${ALERTMANAGER_BASE_PATH} /private/argus/etc /usr/local/bin || true
|
||||||
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 \
|
||||||
@@ -83,4 +95,3 @@ 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"]
|
||||||
|
|
||||||
|
|||||||
13
src/alert/alertmanager/build/build.sh
Normal file
13
src/alert/alertmanager/build/build.sh
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
docker pull ubuntu:24.04
|
||||||
|
|
||||||
|
source src/alert/tests/.env
|
||||||
|
|
||||||
|
docker build \
|
||||||
|
--build-arg ARGUS_BUILD_UID=${ARGUS_BUILD_UID} \
|
||||||
|
--build-arg ARGUS_BUILD_GID=${ARGUS_BUILD_GID} \
|
||||||
|
-f src/alert/alertmanager/build/Dockerfile \
|
||||||
|
-t argus-alertmanager:latest .
|
||||||
|
|
||||||
|
docker save -o argus-alertmanager-latest.tar argus-alertmanager:latest
|
||||||
@@ -18,6 +18,7 @@ DOMAIN=alertmanager.alert.argus.com
|
|||||||
IP=$(ifconfig | grep -A 1 eth0 | grep inet | awk '{print $2}')
|
IP=$(ifconfig | grep -A 1 eth0 | grep inet | awk '{print $2}')
|
||||||
echo "current IP: ${IP}"
|
echo "current IP: ${IP}"
|
||||||
echo "${IP}" > /private/argus/etc/${DOMAIN}
|
echo "${IP}" > /private/argus/etc/${DOMAIN}
|
||||||
|
chmod 755 /private/argus/etc/${DOMAIN}
|
||||||
|
|
||||||
|
|
||||||
echo "[INFO] Starting Alertmanager process..."
|
echo "[INFO] Starting Alertmanager process..."
|
||||||
|
|||||||
@@ -55,6 +55,6 @@ alerting:
|
|||||||
alertmanagers:
|
alertmanagers:
|
||||||
- static_configs:
|
- static_configs:
|
||||||
- targets:
|
- targets:
|
||||||
- "localhost:9093" # Alertmanager 地址
|
- "alertmanager.alert.argus.com:9093" # Alertmanager 地址
|
||||||
|
|
||||||
```
|
```
|
||||||
5
src/alert/tests/.env
Normal file
5
src/alert/tests/.env
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
DATA_ROOT=/home/argus/tmp/private/argus
|
||||||
|
ARGUS_BUILD_UID=1048
|
||||||
|
ARGUS_BUILD_GID=1048
|
||||||
|
|
||||||
|
USE_INTRANET=false
|
||||||
5
src/alert/tests/.env.example
Normal file
5
src/alert/tests/.env.example
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
DATA_ROOT=/home/argus/tmp/private/argus
|
||||||
|
ARGUS_UID=1048
|
||||||
|
ARGUS_GID=1048
|
||||||
|
|
||||||
|
USE_INTRANET=false
|
||||||
@@ -1,36 +1,36 @@
|
|||||||
version: '3.8'
|
|
||||||
services:
|
services:
|
||||||
alertmanager:
|
alertmanager:
|
||||||
build:
|
build:
|
||||||
context: ../../../
|
context: ../../../
|
||||||
dockerfile: src/alert/alertmanager/build/Dockerfile
|
dockerfile: src/alert/alertmanager/build/Dockerfile
|
||||||
args:
|
args:
|
||||||
ARGUS_UID: ${ARGUS_UID:-2133}
|
ARGUS_BUILD_UID: ${ARGUS_BUILD_UID:-2133}
|
||||||
ARGUS_GID: ${ARGUS_GID:-2015}
|
ARGUS_BUILD_GID: ${ARGUS_BUILD_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_UID=${ARGUS_UID:-2133}
|
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
|
||||||
- ARGUS_GID=${ARGUS_GID:-2015}
|
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
|
||||||
ports:
|
ports:
|
||||||
- "${ARGUS_PORT:-9093}:9093"
|
- "${ARGUS_PORT:-9093}:9093"
|
||||||
volumes:
|
volumes:
|
||||||
- ${DATA_ROOT:-./data}/alertmanager:/private/argus/alert/alertmanager
|
- ${DATA_ROOT:-./data}/alert/alertmanager:/private/argus/alert/alertmanager
|
||||||
- ${DATA_ROOT:-./data}/etc:/private/argus/etc
|
- ${DATA_ROOT:-./data}/etc:/private/argus/etc
|
||||||
networks:
|
networks:
|
||||||
- argus-network
|
- argus-debug-net
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
logging:
|
logging:
|
||||||
driver: "json-file"
|
driver: "json-file"
|
||||||
options:
|
options:
|
||||||
max-size: "10m"
|
max-size: "10m"
|
||||||
max-file: "3"
|
max-file: "3"
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
argus-network:
|
argus-debug-net:
|
||||||
driver: bridge
|
driver: bridge
|
||||||
name: argus-network
|
name: argus-debug-net
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
alertmanager_data:
|
alertmanager_data:
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ 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 \
|
||||||
|
|||||||
@@ -104,7 +104,26 @@ log_info "文件所有者: $OWNER"
|
|||||||
|
|
||||||
# 确保发布目录存在
|
# 确保发布目录存在
|
||||||
log_info "确保发布目录存在: $PUBLISH_DIR"
|
log_info "确保发布目录存在: $PUBLISH_DIR"
|
||||||
sudo mkdir -p "$PUBLISH_DIR"
|
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-$$"
|
||||||
@@ -208,26 +227,31 @@ 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"
|
||||||
sudo tar -czf "$PUBLISH_DIR/$TAR_NAME" *
|
tar -czf "$PUBLISH_DIR/$TAR_NAME" *
|
||||||
cd - > /dev/null
|
cd - > /dev/null
|
||||||
|
|
||||||
# 设置文件所有者
|
if [[ "$NEED_CHOWN" == true ]]; then
|
||||||
log_info "设置文件所有者为: $OWNER"
|
log_info "设置文件所有者为: $OWNER"
|
||||||
sudo chown "$OWNER" "$PUBLISH_DIR/$TAR_NAME"
|
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" | sudo tee "$PUBLISH_DIR/LATEST_VERSION" > /dev/null
|
echo "$VERSION" > "$PUBLISH_DIR/LATEST_VERSION"
|
||||||
sudo chown "$OWNER" "$PUBLISH_DIR/LATEST_VERSION"
|
if [[ "$NEED_CHOWN" == true ]]; then
|
||||||
|
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 配置文件到发布目录根目录..."
|
||||||
sudo cp "config/dns.conf" "$PUBLISH_DIR/"
|
cp "config/dns.conf" "$PUBLISH_DIR/"
|
||||||
sudo chown "$OWNER" "$PUBLISH_DIR/dns.conf"
|
if [[ "$NEED_CHOWN" == true ]]; then
|
||||||
|
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 配置文件复制"
|
||||||
@@ -236,8 +260,10 @@ 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 到发布目录..."
|
||||||
sudo cp "scripts/setup.sh" "$PUBLISH_DIR/"
|
cp "scripts/setup.sh" "$PUBLISH_DIR/"
|
||||||
sudo chown "$OWNER" "$PUBLISH_DIR/setup.sh"
|
if [[ "$NEED_CHOWN" == true ]]; then
|
||||||
|
chown "$OWNER" "$PUBLISH_DIR/setup.sh"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 显示发布结果
|
# 显示发布结果
|
||||||
|
|||||||
@@ -2,6 +2,18 @@ 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 \
|
||||||
@@ -10,6 +22,11 @@ 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
|
||||||
|
|
||||||
@@ -48,6 +65,8 @@ 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
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ datasources:
|
|||||||
type: prometheus
|
type: prometheus
|
||||||
access: proxy
|
access: proxy
|
||||||
uid: eezk1zvkie4g0a
|
uid: eezk1zvkie4g0a
|
||||||
url: http://10.211.55.5:9090
|
url: http://prom.metric.argus.com:9090
|
||||||
isDefault: true
|
isDefault: true
|
||||||
editable: true
|
editable: true
|
||||||
jsonData:
|
jsonData:
|
||||||
|
|||||||
@@ -44,12 +44,18 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# 复制数据源配置文件到挂载目录
|
# 复制数据源配置文件到挂载目录
|
||||||
if [ -f "/tmp/datasources.yml" ]; then
|
DS_OUT="/private/argus/metric/grafana/provisioning/datasources/datasources.yml"
|
||||||
echo "[INFO] Copying datasource configuration to /private/argus/metric/grafana/provisioning/datasources/"
|
PROM_DOMAIN="prom.metric.argus.com:9090"
|
||||||
cp /tmp/datasources.yml /private/argus/metric/grafana/provisioning/datasources/datasources.yml
|
|
||||||
echo "[INFO] Datasource configuration copied successfully"
|
if [ -f "/tmp/datasources.yml" ] && [ ! -f "$DS_OUT" ]; then
|
||||||
elif [ -d "/private/argus/metric/grafana/provisioning/datasources" ] && [ "$(ls -A /private/argus/metric/grafana/provisioning/datasources)" ]; then
|
echo "[INFO] Initializing datasource provisioning file from /tmp"
|
||||||
echo "[INFO] Found existing datasource provisioning files in /private/argus/metric/grafana/provisioning/datasources"
|
cp /tmp/datasources.yml "$DS_OUT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 统一将数据源 URL 规范为 prom.metric.argus.com:9090
|
||||||
|
if [ -f "$DS_OUT" ]; then
|
||||||
|
sed -i -E "s#^\s*url:\s*http://[^[:space:]]+# url: http://$PROM_DOMAIN#g" "$DS_OUT" || true
|
||||||
|
echo "[INFO] Datasource URL normalized to http://$PROM_DOMAIN"
|
||||||
elif [ -d "/etc/grafana/provisioning/datasources" ] && [ "$(ls -A /etc/grafana/provisioning/datasources)" ]; then
|
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"
|
||||||
# 确保数据源配置目录权限正确
|
# 确保数据源配置目录权限正确
|
||||||
@@ -65,11 +71,33 @@ if [ -f "/tmp/dashboards.yml" ]; then
|
|||||||
echo "[INFO] Dashboard configuration copied successfully"
|
echo "[INFO] Dashboard configuration copied successfully"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 复制默认仪表板到挂载目录
|
# 复制默认仪表板到挂载目录(按需,不覆盖已存在文件)
|
||||||
if [ -f "/tmp/default_dashboard.json" ]; then
|
copy_dashboard_if_missing() {
|
||||||
echo "[INFO] Copying default dashboard to /private/argus/metric/grafana/provisioning/dashboards/"
|
local src="$1"; local dst_name="$2"
|
||||||
cp /tmp/default_dashboard.json /private/argus/metric/grafana/provisioning/dashboards/default_dashboard.json
|
local dst_dir="/private/argus/metric/grafana/provisioning/dashboards"
|
||||||
echo "[INFO] Default dashboard copied successfully"
|
local dst="$dst_dir/$dst_name"
|
||||||
|
if [ -f "$src" ]; then
|
||||||
|
if [ ! -f "$dst" ]; then
|
||||||
|
echo "[INFO] Installing dashboard: $dst_name"
|
||||||
|
cp "$src" "$dst"
|
||||||
|
else
|
||||||
|
echo "[INFO] Dashboard exists, skip: $dst_name"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
copy_dashboard_if_missing "/tmp/default_dashboard.json" "default_dashboard.json"
|
||||||
|
copy_dashboard_if_missing "/tmp/default_cluster_dashboard.json" "default_cluster_dashboard.json"
|
||||||
|
copy_dashboard_if_missing "/tmp/default_dashboard_by_instance.json" "default_dashboard_by_instance.json"
|
||||||
|
|
||||||
|
# 规范面板中的数据源字段:将字符串 "prometheus" 替换为 null(使用默认数据源)
|
||||||
|
DB_DIR="/private/argus/metric/grafana/provisioning/dashboards"
|
||||||
|
if [ -d "$DB_DIR" ]; then
|
||||||
|
for f in "$DB_DIR"/*.json; do
|
||||||
|
[ -f "$f" ] || continue
|
||||||
|
sed -i -E 's/"datasource"\s*:\s*"prometheus"/"datasource": null/g' "$f" || true
|
||||||
|
done
|
||||||
|
echo "[INFO] Normalized dashboard datasource to default (null)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 启动 Grafana
|
# 启动 Grafana
|
||||||
|
|||||||
@@ -61,10 +61,25 @@ 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 usermod -u ${ARGUS_BUILD_UID} nobody && \
|
RUN set -eux; \
|
||||||
groupmod -g ${ARGUS_BUILD_GID} nogroup && \
|
existing_user=""; \
|
||||||
chown -h nobody:nogroup /prometheus && \
|
if getent passwd "${ARGUS_BUILD_UID}" >/dev/null 2>&1; then \
|
||||||
chown -R nobody:nogroup ${PROMETHEUS_BASE_PATH} && \
|
existing_user="$(getent passwd "${ARGUS_BUILD_UID}" | cut -d: -f1)"; \
|
||||||
|
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 配置
|
||||||
|
|||||||
@@ -5,13 +5,6 @@ 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
|
||||||
@@ -41,13 +34,6 @@ 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
|
||||||
@@ -73,12 +59,6 @@ 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
|
||||||
@@ -109,9 +89,6 @@ 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
|
||||||
@@ -143,9 +120,6 @@ 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
|
||||||
|
|||||||
@@ -3,15 +3,8 @@ 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" $REBUILD_FLAG
|
bash "$SCRIPT_DIR/common/start-all.sh"
|
||||||
|
|
||||||
echo "[01] 等待服务就绪..."
|
echo "[01] 等待服务就绪..."
|
||||||
sleep 5
|
sleep 5
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
#!/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!}"
|
||||||
@@ -8,26 +11,37 @@ FTP_PORT="${FTP_PORT:-21}"
|
|||||||
|
|
||||||
FTP_HOST="${FTP_SERVER}"
|
FTP_HOST="${FTP_SERVER}"
|
||||||
|
|
||||||
echo "[03] 进入测试节点执行安装..."
|
echo "[04] 检测GPU环境..."
|
||||||
echo "[03] 使用 FTP 地址: ${FTP_HOST}:${FTP_PORT}"
|
# 检测GPU环境
|
||||||
|
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 '[03] curl 未安装,正在安装...'
|
echo '[04] curl 未安装,正在安装...'
|
||||||
apt-get update && apt-get install -y curl
|
apt-get update && apt-get install -y curl
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd /tmp
|
cd /tmp
|
||||||
echo '[03] 下载 setup.sh...'
|
echo '[04] 下载 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 '[03] 执行安装...'
|
echo '[04] 执行安装...'
|
||||||
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 '[03] 安装完成'
|
echo '[04] 安装完成'
|
||||||
"
|
"
|
||||||
|
|
||||||
echo "[03] 完成"
|
echo "[04] 完成"
|
||||||
|
|||||||
59
src/metric/tests/scripts/common/check-gpu.sh
Executable file
59
src/metric/tests/scripts/common/check-gpu.sh
Executable file
@@ -0,0 +1,59 @@
|
|||||||
|
#!/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
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# 一键启动脚本
|
# 一键启动脚本
|
||||||
# 用于初始化目录、构建镜像并启动所有服务
|
# 用于初始化目录并启动所有服务
|
||||||
|
# 镜像构建已移至 build/build_images.sh
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
@@ -9,12 +10,6 @@ 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 "=========================================="
|
||||||
@@ -37,26 +32,6 @@ 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
|
||||||
@@ -84,118 +59,65 @@ echo "1. 初始化目录结构..."
|
|||||||
bash "$SCRIPT_DIR/init-directories.sh"
|
bash "$SCRIPT_DIR/init-directories.sh"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "2. 准备 Docker 镜像..."
|
echo "2. 检测GPU环境..."
|
||||||
|
# 检测GPU环境
|
||||||
# 检查镜像是否存在
|
if bash "$SCRIPT_DIR/check-gpu.sh"; then
|
||||||
IMAGE_CACHE_DIR="$TEST_DIR/images-cache"
|
echo "GPU环境可用,将启动GPU节点"
|
||||||
IMAGES=("argus-metric-ftp:latest" "argus-metric-prometheus:latest" "argus-metric-grafana:latest" "argus-metric-test-node:latest" "argus-metric-test-gpu-node:latest")
|
GPU_AVAILABLE=true
|
||||||
all_images_exist=true
|
|
||||||
|
|
||||||
for image in "${IMAGES[@]}"; do
|
|
||||||
if ! docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "^${image}$"; then
|
|
||||||
all_images_exist=false
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if $FORCE_REBUILD; then
|
|
||||||
echo "强制重新构建镜像(--rebuild 模式)..."
|
|
||||||
cd "$TEST_DIR"
|
|
||||||
docker compose build --no-cache
|
|
||||||
echo "镜像重新构建完成"
|
|
||||||
elif $all_images_exist; then
|
|
||||||
echo "所有镜像已存在,跳过构建"
|
|
||||||
else
|
else
|
||||||
echo "检测到缺失镜像,尝试从缓存加载..."
|
echo "GPU环境不可用,跳过GPU节点"
|
||||||
|
GPU_AVAILABLE=false
|
||||||
# 尝试从缓存加载
|
|
||||||
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
|
|
||||||
need_build=true
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if $need_build; then
|
|
||||||
echo ""
|
|
||||||
echo "部分镜像缺失,开始构建..."
|
|
||||||
echo "工作目录: $(pwd)"
|
|
||||||
cd "$TEST_DIR"
|
|
||||||
docker compose build --no-cache
|
|
||||||
|
|
||||||
# 询问是否保存镜像
|
|
||||||
echo ""
|
|
||||||
read -p "是否保存镜像到缓存以便下次快速启动? (Y/n): " -n 1 -r
|
|
||||||
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 "3. 启动基础服务..."
|
echo "3. 检查 Docker 镜像..."
|
||||||
|
|
||||||
|
# 检查必要的镜像是否存在
|
||||||
|
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
|
||||||
|
missing_images+=("$image")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# 检查GPU镜像(如果GPU环境可用)
|
||||||
|
if [ "$GPU_AVAILABLE" = true ]; then
|
||||||
|
for image in "${GPU_IMAGES[@]}"; do
|
||||||
|
if ! docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "^${image}$"; then
|
||||||
|
missing_images+=("$image")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${#missing_images[@]} -gt 0 ]; then
|
||||||
|
echo "以下镜像缺失,请先运行 build/build_images.sh 构建镜像:"
|
||||||
|
for image in "${missing_images[@]}"; do
|
||||||
|
echo " • $image"
|
||||||
|
done
|
||||||
|
echo ""
|
||||||
|
echo "构建命令:"
|
||||||
|
echo " ./build/build_images.sh --metric"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "所有必要镜像已存在"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "4. 启动基础服务..."
|
||||||
cd "$TEST_DIR"
|
cd "$TEST_DIR"
|
||||||
# 启动除GPU节点外的所有服务
|
|
||||||
docker compose up -d ftp prometheus grafana test-node test-gpu-node
|
# 根据GPU环境决定启动的服务
|
||||||
|
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. 等待服务启动..."
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
version: "3.8"
|
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
default:
|
sysnet:
|
||||||
name: argus-sys-net
|
|
||||||
driver: bridge
|
driver: bridge
|
||||||
ipam:
|
ipam:
|
||||||
driver: default
|
driver: default
|
||||||
@@ -14,7 +11,7 @@ services:
|
|||||||
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:
|
||||||
default:
|
sysnet:
|
||||||
ipv4_address: 172.29.0.2
|
ipv4_address: 172.29.0.2
|
||||||
volumes:
|
volumes:
|
||||||
- ./private:/private
|
- ./private:/private
|
||||||
@@ -38,7 +35,7 @@ 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:
|
||||||
default:
|
sysnet:
|
||||||
ipv4_address: 172.29.0.10
|
ipv4_address: 172.29.0.10
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
@@ -57,6 +54,9 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "9200:9200"
|
- "9200:9200"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
sysnet:
|
||||||
|
ipv4_address: 172.29.0.3
|
||||||
|
|
||||||
kibana:
|
kibana:
|
||||||
image: argus-kibana:latest
|
image: argus-kibana:latest
|
||||||
@@ -73,6 +73,9 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "5601:5601"
|
- "5601:5601"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
sysnet:
|
||||||
|
ipv4_address: 172.29.0.4
|
||||||
|
|
||||||
node-a:
|
node-a:
|
||||||
image: ubuntu:22.04
|
image: ubuntu:22.04
|
||||||
@@ -105,6 +108,8 @@ services:
|
|||||||
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
|
||||||
@@ -137,3 +142,178 @@ services:
|
|||||||
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.29.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.29.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.29.0.42
|
||||||
|
depends_on:
|
||||||
|
- prometheus
|
||||||
|
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.29.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.29.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.29.0.51
|
||||||
|
logging:
|
||||||
|
driver: "json-file"
|
||||||
|
options:
|
||||||
|
max-size: "10m"
|
||||||
|
max-file: "3"
|
||||||
|
|||||||
@@ -3,6 +3,38 @@ 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"
|
||||||
@@ -12,6 +44,11 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,4 +60,3 @@ for script in "${SCRIPTS[@]}"; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
echo "[SYS-E2E] All tests completed"
|
echo "[SYS-E2E] All tests completed"
|
||||||
|
|
||||||
|
|||||||
@@ -22,24 +22,61 @@ 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/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 expect UID/GID inside container)
|
# Align ownership for supervisor-managed services (ES/Kibana/Grafana 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/metric/ftp" \
|
||||||
|
"$PRIVATE_CORE/argus/agent" \
|
||||||
"$PRIVATE_CORE/argus/etc" 2>/dev/null || true
|
"$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"
|
||||||
@@ -55,6 +92,9 @@ 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"
|
||||||
|
|
||||||
echo "[INFO] Building agent binary..."
|
echo "[INFO] Building agent binary..."
|
||||||
pushd "$REPO_ROOT/src/agent" >/dev/null
|
pushd "$REPO_ROOT/src/agent" >/dev/null
|
||||||
@@ -68,10 +108,50 @@ if [[ ! -x "$AGENT_BIN" ]]; then
|
|||||||
fi
|
fi
|
||||||
echo "$AGENT_BIN" > "$TMP_DIR/agent_binary_path"
|
echo "$AGENT_BIN" > "$TMP_DIR/agent_binary_path"
|
||||||
|
|
||||||
echo "[INFO] Writing .env with UID/GID"
|
# 检测GPU环境
|
||||||
|
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"
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ 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
|
||||||
@@ -13,10 +14,52 @@ 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
|
||||||
|
|
||||||
|
# 根据GPU可用性决定启动的服务
|
||||||
|
if [[ "$GPU_AVAILABLE" == true ]]; then
|
||||||
|
echo "[INFO] 启动所有服务(包含 gpu profile)..."
|
||||||
|
compose -p argus-sys --profile gpu up -d
|
||||||
|
else
|
||||||
|
echo "[INFO] 启动基础服务(不含 gpu profile)..."
|
||||||
|
compose -p argus-sys up -d
|
||||||
|
fi
|
||||||
|
|
||||||
popd >/dev/null
|
popd >/dev/null
|
||||||
|
|
||||||
echo "[OK] Services started: master:32300 es:9200 kibana:5601 node-a:2020 node-b:2021"
|
if [[ "$GPU_AVAILABLE" == true ]]; then
|
||||||
|
echo "[OK] Services started: master:32300 es:9200 kibana:5601 node-a:2020 node-b:2021 test-gpu-node:172.29.0.51"
|
||||||
|
else
|
||||||
|
echo "[OK] Services started: master:32300 es:9200 kibana:5601 node-a:2020 node-b:2021 (gpu skipped)"
|
||||||
|
fi
|
||||||
|
|||||||
@@ -4,20 +4,15 @@ 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)"
|
||||||
|
|
||||||
compose() {
|
# 直接根据 container_name 获取容器ID,避免 compose project 名称不一致导致查找失败
|
||||||
if docker compose version >/dev/null 2>&1; then
|
cid_by_name() {
|
||||||
docker compose "$@"
|
docker ps -aqf "name=^$1$"
|
||||||
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
|
||||||
@@ -28,7 +23,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="$(service_id bind)"
|
BIN_ID="$(cid_by_name argus-bind-sys)"
|
||||||
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"
|
||||||
@@ -39,8 +34,8 @@ else
|
|||||||
echo "[WARN] bind container not found; skip dig"
|
echo "[WARN] bind container not found; skip dig"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for node in node-a node-b; do
|
for node in argus-node-a argus-node-b; do
|
||||||
CID="$(service_id "$node")"
|
CID="$(cid_by_name "$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
|
||||||
@@ -50,5 +45,6 @@ for node in node-a node-b; do
|
|||||||
echo "[OK] $node resolved master.argus.com -> $RES"
|
echo "[OK] $node resolved master.argus.com -> $RES"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "[OK] DNS routing verified"
|
popd >/dev/null
|
||||||
|
|
||||||
|
echo "[OK] DNS routing verified"
|
||||||
|
|||||||
@@ -49,8 +49,35 @@ 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 "[ERR] Agents did not register in time" >&2
|
echo "[WARN] node-a or node-b not registered in first window; restarting node-b and retrying..." >&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
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,19 @@ 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 idx="$1"; local tmp; tmp=$(mktemp)
|
||||||
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}'
|
local code
|
||||||
|
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-*")
|
||||||
@@ -32,11 +42,26 @@ 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..."
|
||||||
sleep 10
|
# Proactively refresh indices (ignore errors if not created yet)
|
||||||
|
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
|
||||||
|
|
||||||
train1=$(get_count "train-*")
|
# Retry up to 120s for counts to increase and reach threshold (>=4)
|
||||||
infer1=$(get_count "infer-*")
|
final=0
|
||||||
final=$((train1 + infer1))
|
threshold=4
|
||||||
|
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
|
||||||
@@ -44,6 +69,7 @@ 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
|
||||||
|
|||||||
@@ -58,10 +58,25 @@ 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 argus-sys-net \
|
--network "$SYSNET_NAME" \
|
||||||
--ip 172.29.0.200 \
|
--ip 172.29.0.200 \
|
||||||
--dns 172.29.0.2 \
|
--dns 172.29.0.2 \
|
||||||
-e MASTER_ENDPOINT=http://master.argus.com:3000 \
|
-e MASTER_ENDPOINT=http://master.argus.com:3000 \
|
||||||
|
|||||||
@@ -12,12 +12,33 @@ 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
|
||||||
|
|||||||
66
src/sys/tests/scripts/10_metric_publish.sh
Executable file
66
src/sys/tests/scripts/10_metric_publish.sh
Executable file
@@ -0,0 +1,66 @@
|
|||||||
|
#!/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"
|
||||||
50
src/sys/tests/scripts/11_metric_node_install.sh
Executable file
50
src/sys/tests/scripts/11_metric_node_install.sh
Executable file
@@ -0,0 +1,50 @@
|
|||||||
|
#!/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.29.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 安装流程完成"
|
||||||
64
src/sys/tests/scripts/12_metric_gpu_install.sh
Executable file
64
src/sys/tests/scripts/12_metric_gpu_install.sh
Executable file
@@ -0,0 +1,64 @@
|
|||||||
|
#!/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.29.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 节点安装流程完成"
|
||||||
40
src/sys/tests/scripts/13_metric_verify.sh
Executable file
40
src/sys/tests/scripts/13_metric_verify.sh
Executable file
@@ -0,0 +1,40 @@
|
|||||||
|
#!/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"
|
||||||
47
src/sys/tests/scripts/13_metric_verify_dataplane.sh
Executable file
47
src/sys/tests/scripts/13_metric_verify_dataplane.sh
Executable file
@@ -0,0 +1,47 @@
|
|||||||
|
#!/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.29.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"
|
||||||
39
src/sys/tests/scripts/13_metric_verify_grafana.sh
Executable file
39
src/sys/tests/scripts/13_metric_verify_grafana.sh
Executable file
@@ -0,0 +1,39 @@
|
|||||||
|
#!/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"
|
||||||
70
src/sys/tests/scripts/13_metric_verify_grafana_panels.sh
Executable file
70
src/sys/tests/scripts/13_metric_verify_grafana_panels.sh
Executable file
@@ -0,0 +1,70 @@
|
|||||||
|
#!/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"
|
||||||
|
|
||||||
105
src/sys/tests/scripts/13_metric_verify_master.sh
Executable file
105
src/sys/tests/scripts/13_metric_verify_master.sh
Executable file
@@ -0,0 +1,105 @@
|
|||||||
|
#!/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"
|
||||||
142
src/sys/tests/scripts/13_metric_verify_prometheus.sh
Executable file
142
src/sys/tests/scripts/13_metric_verify_prometheus.sh
Executable file
@@ -0,0 +1,142 @@
|
|||||||
|
#!/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"
|
||||||
18
src/sys/tests/scripts/14_metric_cleanup.sh
Executable file
18
src/sys/tests/scripts/14_metric_cleanup.sh
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/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 清理完成"
|
||||||
45
src/sys/tests/scripts/metric/test-node-entrypoint.sh
Executable file
45
src/sys/tests/scripts/metric/test-node-entrypoint.sh
Executable file
@@ -0,0 +1,45 @@
|
|||||||
|
#!/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 "$@"
|
||||||
@@ -46,7 +46,9 @@ 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"
|
||||||
bash -lc '/private/start-fluent-bit.sh' &
|
sysctl -w fs.inotify.max_user_instances=512 >/dev/null 2>&1 || true
|
||||||
|
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
|
||||||
@@ -54,4 +56,3 @@ 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"
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,34 @@
|
|||||||
# Argus-web
|
# Argus-web
|
||||||
|
|
||||||
架构:React + Vite + Mantine
|
前端页面架构:React + Vite + Mantine
|
||||||
|
|
||||||
|
该模块分为两个部分,argus-web-frontend和argus-web-proxy。其中argus-web-frontend负责前端页面展示,argus-web-proxy负责反向代理,实现对其他网站的反向代理功能
|
||||||
|
|
||||||
## 打包部署
|
## 构建
|
||||||
|
在构建前需要设置构建和部署的环境变量。根目录下运行:
|
||||||
|
```bash
|
||||||
|
cp src/web/tests/.env.example src/web/tests/.env
|
||||||
|
```
|
||||||
|
修改.env的内容。
|
||||||
|
|
||||||
|
### argus-web-frontend
|
||||||
根目录下运行
|
根目录下运行
|
||||||
```bash
|
```bash
|
||||||
bash src/web/buld_tools/frontend/build.sh
|
bash src/web/buld_tools/frontend/build.sh
|
||||||
```
|
```
|
||||||
|
构建成功后,会在根目录下有一个打包好的tar包argus-web-frontend-latest.tar。
|
||||||
|
|
||||||
|
### argus-web-proxy
|
||||||
|
根目录下运行
|
||||||
|
```bash
|
||||||
|
bash src/web/build_tools/proxy/build.sh
|
||||||
|
```
|
||||||
|
构建成功后,会在根目录下有一个打包好的tar包argus-web-proxy-latest.tar。
|
||||||
|
|
||||||
|
## 部署
|
||||||
|
|
||||||
|
提供docker-compose部署。在src/web/tests目录下
|
||||||
|
```bash
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
会同时启动argus-web-frontend和argus-web-proxy两个容器服务。
|
||||||
|
|||||||
@@ -24,22 +24,37 @@ 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
|
||||||
ENV ARGUS_UID=2133
|
ARG ARGUS_BUILD_UID=2133
|
||||||
ENV ARGUS_GID=2015
|
ARG ARGUS_BUILD_GID=2015
|
||||||
|
ENV ARGUS_BUILD_UID=${ARGUS_BUILD_UID}
|
||||||
|
ENV ARGUS_BUILD_GID=${ARGUS_BUILD_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 groupadd -g ${ARGUS_GID} web
|
RUN set -eux; \
|
||||||
|
# 确保目标 GID 存在(组名可不固定)\
|
||||||
# 创建 web 用户并指定组
|
if ! getent group "${ARGUS_BUILD_GID}" >/dev/null; then \
|
||||||
RUN useradd -M -s /usr/sbin/nologin -u ${ARGUS_UID} -g ${ARGUS_GID} web
|
groupadd -g "${ARGUS_BUILD_GID}" web || true; \
|
||||||
|
fi; \
|
||||||
RUN chown -R web:web ${FRONTEND_BASE_PATH} && \
|
# 若存在 web 用户则尽量对齐 UID/GID;否则仅在 UID 未被占用时创建
|
||||||
chown -R web:web /private/argus/etc && \
|
if id web >/dev/null 2>&1; then \
|
||||||
chown -R web:web /usr/local/bin
|
current_uid="$(id -u web)"; \
|
||||||
|
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 \
|
||||||
@@ -82,7 +97,7 @@ COPY src/web/build_tools/frontend/health-check.sh /usr/local/bin/health-check.sh
|
|||||||
RUN chmod +x /usr/local/bin/health-check.sh
|
RUN chmod +x /usr/local/bin/health-check.sh
|
||||||
|
|
||||||
# 暴露端口
|
# 暴露端口
|
||||||
EXPOSE 80
|
EXPOSE 8080
|
||||||
|
|
||||||
# 保持 root 用户,由 supervisor 控制 user 切换
|
# 保持 root 用户,由 supervisor 控制 user 切换
|
||||||
USER root
|
USER root
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
docker pull node:20
|
docker pull node:20
|
||||||
docker pull ubuntu:24.04
|
docker pull ubuntu:24.04
|
||||||
docker build -f src/web/build_tools/frontend/Dockerfile -t argus-web:0.1.1 .
|
|
||||||
rm -f argus-web-0.1.1.tar && sudo docker image save argus-web:0.1.1 > argus-web-0.1.1.tar
|
source src/web/tests/.env
|
||||||
|
|
||||||
|
docker build \
|
||||||
|
--build-arg ARGUS_BUILD_UID=${ARGUS_BUILD_UID} \
|
||||||
|
--build-arg ARGUS_BUILD_GID=${ARGUS_BUILD_GID} \
|
||||||
|
-f src/web/build_tools/frontend/Dockerfile -t argus-web-frontend:latest .
|
||||||
|
docker save -o argus-web-frontend-latest.tar argus-web-frontend:latest
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
URL="http://127.0.0.1:80"
|
URL="http://127.0.0.1:8080"
|
||||||
|
|
||||||
echo "[INFO] Starting Argus web health check loop for $URL..."
|
echo "[INFO] Starting Argus web health check loop for $URL..."
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ http {
|
|||||||
|
|
||||||
# React 前端服务
|
# React 前端服务
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 8080;
|
||||||
server_name web.argus.com;
|
server_name web.argus.com;
|
||||||
|
|
||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
@@ -25,32 +25,4 @@ http {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Master 服务,需要增加 CORS 支持
|
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
server_name master.argus.com;
|
|
||||||
|
|
||||||
location / {
|
|
||||||
proxy_pass http://master.argus.com;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,14 +14,6 @@ RUNTIME_GID="${ARGUS_BUILD_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
|
||||||
|
|
||||||
if [[ -x "$DNS_SCRIPT" ]]; then
|
|
||||||
echo "[INFO] Running update-dns.sh before master starts"
|
|
||||||
# 若脚本存在则执行,保证容器使用 bind 作为 DNS
|
|
||||||
"$DNS_SCRIPT" || echo "[WARN] update-dns.sh execution failed"
|
|
||||||
else
|
|
||||||
echo "[WARN] DNS update script not found or not executable: $DNS_SCRIPT"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# 记录容器 IP
|
# 记录容器 IP
|
||||||
IP=$(ifconfig | grep -A 1 eth0 | grep inet | awk '{print $2}' || true)
|
IP=$(ifconfig | grep -A 1 eth0 | grep inet | awk '{print $2}' || true)
|
||||||
@@ -32,6 +24,7 @@ if [[ -n "${IP}" ]]; then
|
|||||||
else
|
else
|
||||||
echo "[WARN] Failed to detect web IP via ifconfig"
|
echo "[WARN] Failed to detect web IP via ifconfig"
|
||||||
fi
|
fi
|
||||||
|
chmod 755 "$WEB_DOMAIN_FILE"
|
||||||
|
|
||||||
echo "[INFO] Launching nginx..."
|
echo "[INFO] Launching nginx..."
|
||||||
|
|
||||||
|
|||||||
@@ -8,22 +8,34 @@ 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
|
||||||
ENV ARGUS_UID=2133
|
ARG ARGUS_BUILD_UID=2133
|
||||||
ENV ARGUS_GID=2015
|
ARG ARGUS_BUILD_GID=2015
|
||||||
|
ENV ARGUS_BUILD_UID=${ARGUS_BUILD_UID}
|
||||||
|
ENV ARGUS_BUILD_GID=${ARGUS_BUILD_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 groupadd -g ${ARGUS_GID} web_proxy
|
RUN set -eux; \
|
||||||
|
if ! getent group "${ARGUS_BUILD_GID}" >/dev/null; then \
|
||||||
# 创建 proxy 用户并指定组
|
groupadd -g "${ARGUS_BUILD_GID}" web_proxy || true; \
|
||||||
RUN useradd -M -s /usr/sbin/nologin -u ${ARGUS_UID} -g ${ARGUS_GID} web_proxy
|
fi; \
|
||||||
|
if id web_proxy >/dev/null 2>&1; then \
|
||||||
RUN chown -R web_proxy:web_proxy ${FRONTEND_BASE_PATH} && \
|
current_uid="$(id -u web_proxy)"; \
|
||||||
chown -R web_proxy:web_proxy /private/argus/etc && \
|
if [ "$current_uid" != "${ARGUS_BUILD_UID}" ] && ! getent passwd "${ARGUS_BUILD_UID}" >/dev/null; then \
|
||||||
chown -R web_proxy:web_proxy /usr/local/bin
|
usermod -u "${ARGUS_BUILD_UID}" web_proxy; \
|
||||||
|
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 \
|
||||||
|
|||||||
9
src/web/build_tools/proxy/build.sh
Normal file
9
src/web/build_tools/proxy/build.sh
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
docker pull ubuntu:24.04
|
||||||
|
|
||||||
|
source src/web/tests/.env
|
||||||
|
|
||||||
|
docker build \
|
||||||
|
--build-arg ARGUS_BUILD_UID=${ARGUS_BUILD_UID} \
|
||||||
|
--build-arg ARGUS_BUILD_GID=${ARGUS_BUILD_GID} \
|
||||||
|
-f src/web/build_tools/proxy/Dockerfile -t argus-web-proxy:latest .
|
||||||
|
docker save -o argus-web-proxy-latest.tar argus-web-proxy:latest
|
||||||
@@ -3,6 +3,7 @@ server {
|
|||||||
server_name alertmanager.alert.argus.com;
|
server_name alertmanager.alert.argus.com;
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
proxy_pass http://alertmanager.alert.argus.com:9093;
|
set $alert_backend http://alertmanager.alert.argus.com:9093;
|
||||||
|
proxy_pass $alert_backend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ server {
|
|||||||
server_name es.log.argus.com;
|
server_name es.log.argus.com;
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
proxy_pass http://es.log.argus.com;
|
set $es_backend http://es.log.argus.com:9200;
|
||||||
|
proxy_pass $es_backend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -14,6 +15,7 @@ server {
|
|||||||
server_name kibana.log.argus.com;
|
server_name kibana.log.argus.com;
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
proxy_pass http://kibana.log.argus.com;
|
set $kibana_backend http://kibana.log.argus.com:5601;
|
||||||
|
proxy_pass $kibana_backend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,25 +3,25 @@ server {
|
|||||||
server_name master.argus.com;
|
server_name master.argus.com;
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
# proxy_pass http://master.argus.com;
|
set $master_backend http://master.argus.com:3000;
|
||||||
proxy_pass http://master.argus.com;
|
proxy_pass $master_backend;
|
||||||
# proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
# proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
# proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
|
||||||
# # CORS 支持
|
# CORS 支持
|
||||||
# add_header 'Access-Control-Allow-Origin' 'http://web.argus.com' always;
|
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-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
|
||||||
# add_header 'Access-Control-Allow-Headers' 'Origin, Content-Type, Accept, Authorization' always;
|
add_header 'Access-Control-Allow-Headers' 'Origin, Content-Type, Accept, Authorization' always;
|
||||||
|
|
||||||
# if ($request_method = OPTIONS) {
|
if ($request_method = OPTIONS) {
|
||||||
# add_header 'Access-Control-Allow-Origin' 'http://web.argus.com' always;
|
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-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
|
||||||
# add_header 'Access-Control-Allow-Headers' 'Origin, Content-Type, Accept, Authorization' always;
|
add_header 'Access-Control-Allow-Headers' 'Origin, Content-Type, Accept, Authorization' always;
|
||||||
# add_header 'Content-Length' 0;
|
add_header 'Content-Length' 0;
|
||||||
# add_header 'Content-Type' 'text/plain';
|
add_header 'Content-Type' 'text/plain';
|
||||||
# return 204;
|
return 204;
|
||||||
# }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,18 @@ server {
|
|||||||
server_name prometheus.metric.argus.com;
|
server_name prometheus.metric.argus.com;
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
proxy_pass http://prom.metric.argus.com;
|
set $prom_backend http://prom.metric.argus.com:9090;
|
||||||
|
proxy_pass $prom_backend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# # Grafana
|
# Grafana
|
||||||
# server {
|
server {
|
||||||
# listen 80;
|
listen 80;
|
||||||
# server_name grafana.metric.argus.com;
|
server_name grafana.metric.argus.com;
|
||||||
|
|
||||||
# location / {
|
location / {
|
||||||
# proxy_pass http://grafana.metric.argus.com;
|
set $grafana_backend http://grafana.metric.argus.com:3000;
|
||||||
# }
|
proxy_pass $grafana_backend;
|
||||||
# }
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ server {
|
|||||||
server_name web.argus.com;
|
server_name web.argus.com;
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
proxy_pass http://web.argus.com:80;
|
set $web_backend http://web.argus.com:8080;
|
||||||
|
proxy_pass $web_backend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,14 +5,6 @@ events {
|
|||||||
worker_connections 1024;
|
worker_connections 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
server {
|
|
||||||
listen 80 default_server;
|
|
||||||
server_name _;
|
|
||||||
|
|
||||||
location / {
|
|
||||||
proxy_pass http://web.argus.com:80;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
http {
|
http {
|
||||||
include mime.types;
|
include mime.types;
|
||||||
@@ -32,5 +24,16 @@ http {
|
|||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 80 default_server;
|
||||||
|
server_name _;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
set $web_backend http://web.argus.com:8080;
|
||||||
|
proxy_pass $web_backend;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
include /etc/nginx/conf.d/*.conf;
|
include /etc/nginx/conf.d/*.conf;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ export function AlertFilters({ filters, setFilters, nodeOptions }) {
|
|||||||
value={filters.severity}
|
value={filters.severity}
|
||||||
onChange={(value) => setFilters((f) => ({ ...f, severity: value }))}
|
onChange={(value) => setFilters((f) => ({ ...f, severity: value }))}
|
||||||
data={[
|
data={[
|
||||||
{ value: "all", label: "全部" },
|
{ value: "all", label: "all" },
|
||||||
{ value: "critical", label: "严重" },
|
{ value: "critical", label: "critical" },
|
||||||
{ value: "warning", label: "警告" },
|
{ value: "warning", label: "warning" },
|
||||||
{ value: "info", label: "信息" },
|
{ value: "info", label: "info" },
|
||||||
]}
|
]}
|
||||||
w={150}
|
w={150}
|
||||||
/>
|
/>
|
||||||
@@ -20,7 +20,7 @@ export function AlertFilters({ filters, setFilters, nodeOptions }) {
|
|||||||
value={filters.state}
|
value={filters.state}
|
||||||
onChange={(value) => setFilters((f) => ({ ...f, state: value }))}
|
onChange={(value) => setFilters((f) => ({ ...f, state: value }))}
|
||||||
data={[
|
data={[
|
||||||
{ value: "all", label: "全部" },
|
{ value: "all", label: "all" },
|
||||||
{ value: "active", label: "Active" },
|
{ value: "active", label: "Active" },
|
||||||
{ value: "resolved", label: "Resolved" },
|
{ value: "resolved", label: "Resolved" },
|
||||||
]}
|
]}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Table, Group, ActionIcon, Button } from "@mantine/core";
|
import { Table, Group, ActionIcon, Button, Code } from "@mantine/core";
|
||||||
import { IconChevronUp, IconChevronDown } from "@tabler/icons-react";
|
import { IconChevronUp, IconChevronDown, IconInfoCircle } from "@tabler/icons-react";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
export function AlertTable({
|
export function AlertTable({
|
||||||
alerts,
|
alerts,
|
||||||
@@ -16,6 +17,11 @@ export function AlertTable({
|
|||||||
formatRelativeTime,
|
formatRelativeTime,
|
||||||
}) {
|
}) {
|
||||||
const totalPages = Math.ceil(sortedAlerts.length / pageSize);
|
const totalPages = Math.ceil(sortedAlerts.length / pageSize);
|
||||||
|
const [expandedRow, setExpandedRow] = useState(null);
|
||||||
|
|
||||||
|
const toggleExpand = (index) => {
|
||||||
|
setExpandedRow(expandedRow === index ? null : index);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -47,24 +53,52 @@ export function AlertTable({
|
|||||||
</Group>
|
</Group>
|
||||||
</Table.Th>
|
</Table.Th>
|
||||||
))}
|
))}
|
||||||
|
<Table.Th>更多信息</Table.Th>
|
||||||
</Table.Tr>
|
</Table.Tr>
|
||||||
</Table.Thead>
|
</Table.Thead>
|
||||||
|
|
||||||
<Table.Tbody>
|
<Table.Tbody>
|
||||||
{paginatedAlerts.map((alert, i) => (
|
{paginatedAlerts.map((alert, i) => (
|
||||||
<Table.Tr key={i} style={{ backgroundColor: getRowColor(alert) }}>
|
<>
|
||||||
<Table.Td>{alert.labels?.alertname || "-"}</Table.Td>
|
<Table.Tr key={i} style={{ backgroundColor: getRowColor(alert) }}>
|
||||||
<Table.Td>{alert.labels?.instance || "-"}</Table.Td>
|
<Table.Td>{alert.labels?.alertname || "-"}</Table.Td>
|
||||||
<Table.Td style={{ color: getSeverityColor(alert.labels?.severity) }}>
|
<Table.Td>{alert.labels?.instance || "-"}</Table.Td>
|
||||||
{alert.labels?.severity || "info"}
|
<Table.Td style={{ color: getSeverityColor(alert.labels?.severity) }}>
|
||||||
</Table.Td>
|
{alert.labels?.severity || "info"}
|
||||||
<Table.Td>{getStateBadge(alert.status?.state)}</Table.Td>
|
</Table.Td>
|
||||||
<Table.Td title={alert.startsAt || "-"}>{formatRelativeTime(alert.startsAt)}</Table.Td>
|
<Table.Td>{getStateBadge(alert.status?.state)}</Table.Td>
|
||||||
<Table.Td title={alert.endsAt || "-"}>
|
<Table.Td title={alert.startsAt || "-"}>{formatRelativeTime(alert.startsAt)}</Table.Td>
|
||||||
{alert.endsAt ? new Date(alert.endsAt).toLocaleString() : "-"}
|
<Table.Td title={alert.endsAt || "-"}>
|
||||||
</Table.Td>
|
{alert.endsAt ? new Date(alert.endsAt).toLocaleString() : "-"}
|
||||||
<Table.Td title={alert.updatedAt || "-"}>{formatRelativeTime(alert.updatedAt)}</Table.Td>
|
</Table.Td>
|
||||||
<Table.Td>{alert.annotations?.summary || "-"}</Table.Td>
|
<Table.Td title={alert.updatedAt || "-"}>{formatRelativeTime(alert.updatedAt)}</Table.Td>
|
||||||
</Table.Tr>
|
<Table.Td>{alert.annotations?.summary || "-"}</Table.Td>
|
||||||
|
<Table.Td>
|
||||||
|
<ActionIcon
|
||||||
|
onClick={() => toggleExpand(i)}
|
||||||
|
variant="subtle"
|
||||||
|
color="blue"
|
||||||
|
title="显示/隐藏更多信息"
|
||||||
|
>
|
||||||
|
<IconInfoCircle size={18} />
|
||||||
|
</ActionIcon>
|
||||||
|
</Table.Td>
|
||||||
|
</Table.Tr>
|
||||||
|
|
||||||
|
{expandedRow === i && (
|
||||||
|
<Table.Tr key={`details-${i}`} style={{ backgroundColor: "#f9fafb" }}>
|
||||||
|
<Table.Td colSpan={9}>
|
||||||
|
<div style={{ fontSize: "0.85rem", lineHeight: 1.5 }}>
|
||||||
|
{Object.entries(alert.labels || {}).map(([k, v]) => (
|
||||||
|
<div key={k}>
|
||||||
|
<Code color="blue">{k}</Code> :{v}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</Table.Td>
|
||||||
|
</Table.Tr>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
))}
|
))}
|
||||||
</Table.Tbody>
|
</Table.Tbody>
|
||||||
</Table>
|
</Table>
|
||||||
|
|||||||
@@ -102,11 +102,6 @@ export default function NodeDetailDrawer({ opened, nodeId, onClose }) {
|
|||||||
{/* 滚动内容 */}
|
{/* 滚动内容 */}
|
||||||
<ScrollArea style={{ flex: 1 }}>
|
<ScrollArea style={{ flex: 1 }}>
|
||||||
<Stack spacing="md">
|
<Stack spacing="md">
|
||||||
{/* 配置信息 */}
|
|
||||||
<NodeConfigCard nodeId={node.id} config={node.config || {}} onSaved={() => fetchNodeDetail(node.id)} />
|
|
||||||
|
|
||||||
{/* 标签信息 */}
|
|
||||||
<NodeLabelCard nodeId={node.id} labels={Array.isArray(node.label) ? node.label : []} onSaved={() => fetchNodeDetail(node.id)} />
|
|
||||||
|
|
||||||
{/* 元数据 */}
|
{/* 元数据 */}
|
||||||
<NodeMetaCard node={node} />
|
<NodeMetaCard node={node} />
|
||||||
@@ -114,6 +109,12 @@ export default function NodeDetailDrawer({ opened, nodeId, onClose }) {
|
|||||||
{/* 健康信息 */}
|
{/* 健康信息 */}
|
||||||
<NodeHealthCard node={node} />
|
<NodeHealthCard node={node} />
|
||||||
|
|
||||||
|
{/* 配置信息 */}
|
||||||
|
<NodeConfigCard nodeId={node.id} config={node.config || {}} onSaved={() => fetchNodeDetail(node.id)} />
|
||||||
|
|
||||||
|
{/* 标签信息 */}
|
||||||
|
<NodeLabelCard nodeId={node.id} labels={Array.isArray(node.label) ? node.label : []} onSaved={() => fetchNodeDetail(node.id)} />
|
||||||
|
|
||||||
{/* 其他基础信息展示 */}
|
{/* 其他基础信息展示 */}
|
||||||
<Stack spacing="xs">
|
<Stack spacing="xs">
|
||||||
<Text fw={500}>注册时间: <Text span c="dimmed">{new Date(node.register_time).toLocaleString()}</Text></Text>
|
<Text fw={500}>注册时间: <Text span c="dimmed">{new Date(node.register_time).toLocaleString()}</Text></Text>
|
||||||
|
|||||||
@@ -2,54 +2,62 @@ import { useState } from "react";
|
|||||||
import { Card, Text, Stack, Group, ActionIcon, Badge, Popover } from "@mantine/core";
|
import { Card, Text, Stack, Group, ActionIcon, Badge, Popover } from "@mantine/core";
|
||||||
import { IconInfoCircle } from "@tabler/icons-react";
|
import { IconInfoCircle } from "@tabler/icons-react";
|
||||||
|
|
||||||
|
|
||||||
|
// 子组件:单条健康信息
|
||||||
|
function HealthItem({ moduleName, data }) {
|
||||||
|
const status = data?.status || "unknown";
|
||||||
|
const color = status === "healthy" ? "green" : status === "unhealthy" ? "red" : "gray";
|
||||||
|
const [opened, setOpened] = useState(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Group key={moduleName} spacing="xs" align="center">
|
||||||
|
<Text size="sm" fw={500}>{moduleName}</Text>
|
||||||
|
<Badge color={color} variant="light">{status}</Badge>
|
||||||
|
{(data?.error || data?.timestamp) && (
|
||||||
|
<Popover
|
||||||
|
opened={opened}
|
||||||
|
onClose={() => setOpened(false)}
|
||||||
|
position="bottom"
|
||||||
|
withArrow
|
||||||
|
shadow="sm"
|
||||||
|
>
|
||||||
|
<Popover.Target>
|
||||||
|
<ActionIcon
|
||||||
|
size="xs"
|
||||||
|
color="blue"
|
||||||
|
variant="light"
|
||||||
|
onClick={() => setOpened((o) => !o)}
|
||||||
|
>
|
||||||
|
<IconInfoCircle size={14} />
|
||||||
|
</ActionIcon>
|
||||||
|
</Popover.Target>
|
||||||
|
<Popover.Dropdown>
|
||||||
|
<Stack spacing={4}>
|
||||||
|
{data.error && <Text size="xs" c="red">Error: {data.error}</Text>}
|
||||||
|
{data.timestamp && (
|
||||||
|
<Text size="xs" c="dimmed">
|
||||||
|
Updated: {new Date(data.timestamp).toLocaleString()}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
</Popover.Dropdown>
|
||||||
|
</Popover>
|
||||||
|
)}
|
||||||
|
</Group>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 主组件:健康信息卡片
|
||||||
export default function NodeHealthCard({ node }) {
|
export default function NodeHealthCard({ node }) {
|
||||||
const health = node.health || {};
|
const health = node.health || {};
|
||||||
|
|
||||||
const renderHealthItem = (moduleName, data) => {
|
|
||||||
const status = data?.status || "unknown";
|
|
||||||
const color = status === "healthy" ? "green" : status === "unhealthy" ? "red" : "gray";
|
|
||||||
const [opened, setOpened] = useState(false);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Group key={moduleName} spacing="xs" align="center">
|
|
||||||
<Text size="sm" fw={500}>{moduleName}</Text>
|
|
||||||
<Badge color={color} variant="light">{status}</Badge>
|
|
||||||
{(data?.error || data?.timestamp) && (
|
|
||||||
<Popover
|
|
||||||
opened={opened}
|
|
||||||
onClose={() => setOpened(false)}
|
|
||||||
position="bottom"
|
|
||||||
withArrow
|
|
||||||
shadow="sm"
|
|
||||||
>
|
|
||||||
<Popover.Target>
|
|
||||||
<ActionIcon size="xs" color="blue" variant="light" onClick={() => setOpened((o) => !o)}>
|
|
||||||
<IconInfoCircle size={14} />
|
|
||||||
</ActionIcon>
|
|
||||||
</Popover.Target>
|
|
||||||
<Popover.Dropdown>
|
|
||||||
<Stack spacing={4}>
|
|
||||||
{data.error && <Text size="xs" c="red">Error: {data.error}</Text>}
|
|
||||||
{data.timestamp && (
|
|
||||||
<Text size="xs" c="dimmed">
|
|
||||||
Updated: {new Date(data.timestamp).toLocaleString()}
|
|
||||||
</Text>
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
</Popover.Dropdown>
|
|
||||||
</Popover>
|
|
||||||
)}
|
|
||||||
</Group>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card shadow="xs" radius="md" withBorder>
|
<Card shadow="xs" radius="md" withBorder>
|
||||||
<Text fw={600} mb="sm">健康信息</Text>
|
<Text fw={600} mb="sm">健康信息</Text>
|
||||||
<Stack spacing="xs">
|
<Stack spacing="xs">
|
||||||
{Object.entries(health).map(([moduleName, data]) =>
|
{Object.entries(health).map(([moduleName, data]) => (
|
||||||
renderHealthItem(moduleName, data)
|
<HealthItem key={moduleName} moduleName={moduleName} data={data} />
|
||||||
)}
|
))}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { Link } from "react-router-dom";
|
|||||||
import NodeStatus from "./NodeStatus";
|
import NodeStatus from "./NodeStatus";
|
||||||
import PaginationControl from "./PaginationControl";
|
import PaginationControl from "./PaginationControl";
|
||||||
import { apiRequest } from "../config/request";
|
import { apiRequest } from "../config/request";
|
||||||
import { MASTER_API } from "../config/api";
|
import { MASTER_API, EXTERNAL_HOST } from "../config/api";
|
||||||
|
|
||||||
export function NodeTable({
|
export function NodeTable({
|
||||||
withSearch = false,
|
withSearch = false,
|
||||||
@@ -56,13 +56,28 @@ export function NodeTable({
|
|||||||
<Table.Td>{node.version}</Table.Td>
|
<Table.Td>{node.version}</Table.Td>
|
||||||
{withActions && (
|
{withActions && (
|
||||||
<Table.Td>
|
<Table.Td>
|
||||||
<Button
|
<Group spacing="xs">
|
||||||
size="xs"
|
{/* 查看详情 */}
|
||||||
variant="light"
|
<Button
|
||||||
onClick={() => fetchDetail && fetchDetail(node.id)}
|
size="xs"
|
||||||
>
|
variant="light"
|
||||||
查看详情
|
onClick={() => fetchDetail && fetchDetail(node.id)}
|
||||||
</Button>
|
>
|
||||||
|
查看详情
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
{/* Grafana Dashboard 链接 */}
|
||||||
|
<Button
|
||||||
|
size="xs"
|
||||||
|
variant="outline"
|
||||||
|
component="a"
|
||||||
|
href={`${EXTERNAL_HOST.GRAFANA}/d/node_gpu_metrics/node-and-gpu-metrics?var-hostname=${encodeURIComponent(node.name)}`}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
Grafana
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
</Table.Td>
|
</Table.Td>
|
||||||
)}
|
)}
|
||||||
</Table.Tr>
|
</Table.Tr>
|
||||||
@@ -71,8 +86,6 @@ export function NodeTable({
|
|||||||
return (
|
return (
|
||||||
<Card shadow="sm" radius="md" p="lg">
|
<Card shadow="sm" radius="md" p="lg">
|
||||||
{/* 标题 + 查看更多 */}
|
{/* 标题 + 查看更多 */}
|
||||||
|
|
||||||
|
|
||||||
{(title || viewMoreLink) && (
|
{(title || viewMoreLink) && (
|
||||||
<Group position="apart" mb="sm">
|
<Group position="apart" mb="sm">
|
||||||
{title && <Text fw={700} size="lg">{title}</Text>}
|
{title && <Text fw={700} size="lg">{title}</Text>}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export default function Sidebar() {
|
|||||||
const location = useLocation(); // 路由变化时会触发 Sidebar 重新渲染
|
const location = useLocation(); // 路由变化时会触发 Sidebar 重新渲染
|
||||||
|
|
||||||
const links = [
|
const links = [
|
||||||
{ to: "/dashboard", label: "概览仪表盘", icon: <IconGauge size={16} /> },
|
{ to: "/dashboard", label: "仪表盘", icon: <IconGauge size={16} /> },
|
||||||
{ to: "/nodeInfo", label: "节点信息", icon: <IconServer size={16} /> },
|
{ to: "/nodeInfo", label: "节点信息", icon: <IconServer size={16} /> },
|
||||||
{ to: "/metrics", label: "指标详情", icon: <IconActivity size={16} /> },
|
{ to: "/metrics", label: "指标详情", icon: <IconActivity size={16} /> },
|
||||||
{ to: "/logs", label: "日志详情", icon: <IconFileText size={16} /> },
|
{ to: "/logs", label: "日志详情", icon: <IconFileText size={16} /> },
|
||||||
|
|||||||
@@ -17,14 +17,14 @@ export const MASTER_API = {
|
|||||||
|
|
||||||
// 其他外部 API
|
// 其他外部 API
|
||||||
export const EXTERNAL_API = {
|
export const EXTERNAL_API = {
|
||||||
ALERTS_INFOS: "http://localhost:9093/api/v2/alerts",
|
ALERTS_INFOS: "http://alertmanager.alert.argus.com/api/v2/alerts",
|
||||||
};
|
};
|
||||||
|
|
||||||
// 外部服务 Host
|
// 外部服务 Host
|
||||||
export const EXTERNAL_HOST = {
|
export const EXTERNAL_HOST = {
|
||||||
ALERTS: "http://localhost:9093",
|
ALERTS: "http://alertmanager.alert.argus.com",
|
||||||
GRAFANA: "http://grafana.metric.argus.com",
|
GRAFANA: "http://grafana.metric.argus.com",
|
||||||
|
GRAFANA_DASHBOARD: "http://grafana.metric.argus.com/d/cluster-dashboard/cluster-dashboard",
|
||||||
PROMETHEUS: "http://prometheus.metric.argus.com",
|
PROMETHEUS: "http://prometheus.metric.argus.com",
|
||||||
ES: "http://es.log.argus.com",
|
KIBANA: "http://kibana.log.argus.com/app/discover",
|
||||||
KIBANA: "http://kibana.log.argus.com",
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,12 +5,11 @@ import kibanaLogo from "../assets/kibana.png";
|
|||||||
import { EXTERNAL_HOST } from "./api";
|
import { EXTERNAL_HOST } from "./api";
|
||||||
|
|
||||||
export const metricsEntries = [
|
export const metricsEntries = [
|
||||||
{ label: "Grafana", href: EXTERNAL_HOST.GRAFANA, icon: grafanaLogo },
|
{ label: "Grafana", href: EXTERNAL_HOST.GRAFANA_DASHBOARD, icon: grafanaLogo },
|
||||||
{ label: "Prometheus", href: EXTERNAL_HOST.PROMETHEUS, icon: prometheusLogo },
|
{ label: "Prometheus", href: EXTERNAL_HOST.PROMETHEUS, icon: prometheusLogo },
|
||||||
];
|
];
|
||||||
|
|
||||||
export const logsEntries = [
|
export const logsEntries = [
|
||||||
{ label: "Elasticsearch", href: EXTERNAL_HOST.ES, icon: esLogo },
|
|
||||||
{ label: "Kibana", href: EXTERNAL_HOST.KIBANA, icon: kibanaLogo },
|
{ label: "Kibana", href: EXTERNAL_HOST.KIBANA, icon: kibanaLogo },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useEffect, useState, useMemo } from "react";
|
import { useEffect, useState, useMemo } from "react";
|
||||||
import { Stack, Title, Loader, Center, Group, Button, Badge, ActionIcon } from "@mantine/core";
|
import { Stack, Title, Loader, Center, Group, Button, Badge, ActionIcon, Switch } from "@mantine/core";
|
||||||
import { IconRefresh } from "@tabler/icons-react";
|
import { IconRefresh } from "@tabler/icons-react";
|
||||||
import { apiRequest } from "../config/request";
|
import { apiRequest } from "../config/request";
|
||||||
import { EXTERNAL_API } from "../config/api";
|
import { EXTERNAL_API } from "../config/api";
|
||||||
@@ -17,18 +17,20 @@ export default function Alerts() {
|
|||||||
const [page, setPage] = useState(1);
|
const [page, setPage] = useState(1);
|
||||||
const pageSize = 10;
|
const pageSize = 10;
|
||||||
const [sortConfig, setSortConfig] = useState({ key: "startsAt", direction: "desc" });
|
const [sortConfig, setSortConfig] = useState({ key: "startsAt", direction: "desc" });
|
||||||
|
const [autoRefresh, setAutoRefresh] = useState(true); // 默认开启自动刷新
|
||||||
|
|
||||||
async function fetchAlerts() {
|
async function fetchAlerts() {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const data = await apiRequest(EXTERNAL_API.ALERTS_INFOS);
|
const data = await apiRequest(EXTERNAL_API.ALERTS_INFOS);
|
||||||
if (data && Array.isArray(data)) {
|
if (data && Array.isArray(data)) {
|
||||||
setAlerts(data);
|
setAlerts(data);
|
||||||
const counts = { critical: 0, warning: 0, info: 0 };
|
const counts = { critical: 0, warning: 0, info: 0, total: 0 };
|
||||||
data.forEach((alert) => {
|
data.forEach((alert) => {
|
||||||
const sev = alert.labels?.severity || "info";
|
const sev = alert.labels?.severity || "info";
|
||||||
if (sev === "critical") counts.critical++;
|
if (sev === "critical") counts.critical++;
|
||||||
else if (sev === "warning") counts.warning++;
|
else if (sev === "warning") counts.warning++;
|
||||||
else counts.info++;
|
else counts.info++;
|
||||||
|
counts.total++;
|
||||||
});
|
});
|
||||||
setStats(counts);
|
setStats(counts);
|
||||||
}
|
}
|
||||||
@@ -37,9 +39,14 @@ export default function Alerts() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchAlerts();
|
fetchAlerts();
|
||||||
const timer = setInterval(fetchAlerts, 30000);
|
|
||||||
|
let timer;
|
||||||
|
if (autoRefresh) {
|
||||||
|
timer = setInterval(fetchAlerts, 30000);
|
||||||
|
}
|
||||||
|
|
||||||
return () => clearInterval(timer);
|
return () => clearInterval(timer);
|
||||||
}, []);
|
}, [autoRefresh]);
|
||||||
|
|
||||||
// 节点选项
|
// 节点选项
|
||||||
const nodeOptions = useMemo(() => {
|
const nodeOptions = useMemo(() => {
|
||||||
@@ -124,7 +131,14 @@ export default function Alerts() {
|
|||||||
<Stack spacing="lg" p="md">
|
<Stack spacing="lg" p="md">
|
||||||
<Group position="apart">
|
<Group position="apart">
|
||||||
<Title order={2}>告警详情</Title>
|
<Title order={2}>告警详情</Title>
|
||||||
<Button component="a" href="{EXTERNAL_HOST.ALERTS}" target="_blank" variant="outline">
|
<Switch
|
||||||
|
checked={autoRefresh}
|
||||||
|
onChange={(e) => setAutoRefresh(e.currentTarget.checked)}
|
||||||
|
label="自动刷新"
|
||||||
|
color="green"
|
||||||
|
size="sm"
|
||||||
|
/>
|
||||||
|
<Button component="a" href={EXTERNAL_HOST.ALERTS} target="_blank" variant="outline">
|
||||||
打开 Alertmanager
|
打开 Alertmanager
|
||||||
</Button>
|
</Button>
|
||||||
<ActionIcon onClick={fetchAlerts} color="blue" variant="filled" size="lg" title="刷新">
|
<ActionIcon onClick={fetchAlerts} color="blue" variant="filled" size="lg" title="刷新">
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Grid, Text } from "@mantine/core";
|
import { Grid, Text, Stack, Title } from "@mantine/core";
|
||||||
import { NodeTable } from "../components/NodeTable";
|
import { NodeTable } from "../components/NodeTable";
|
||||||
import { HealthCard } from "../components/HealthCard";
|
import { HealthCard } from "../components/HealthCard";
|
||||||
import { AlertStats } from "../components/AlertStats";
|
import { AlertStats } from "../components/AlertStats";
|
||||||
@@ -14,12 +14,13 @@ export default function Dashboard() {
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
const countAlerts = (data) => {
|
const countAlerts = (data) => {
|
||||||
const stats = { critical: 0, warning: 0, info: 0 };
|
const stats = { critical: 0, warning: 0, info: 0, total: 0 };
|
||||||
data?.forEach((alert) => {
|
data?.forEach((alert) => {
|
||||||
const severity = alert.labels?.severity || "info";
|
const severity = alert.labels?.severity || "info";
|
||||||
if (severity === "critical") stats.critical++;
|
if (severity === "critical") stats.critical++;
|
||||||
else if (severity === "warning") stats.warning++;
|
else if (severity === "warning") stats.warning++;
|
||||||
else stats.info++;
|
else stats.info++;
|
||||||
|
stats.total++;
|
||||||
});
|
});
|
||||||
return stats;
|
return stats;
|
||||||
};
|
};
|
||||||
@@ -41,7 +42,7 @@ export default function Dashboard() {
|
|||||||
status_statistics: healthRes?.status_statistics || [],
|
status_statistics: healthRes?.status_statistics || [],
|
||||||
});
|
});
|
||||||
|
|
||||||
setAlerts(countAlerts(alertsRes?.data || []));
|
setAlerts(countAlerts(alertsRes || []));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("获取 Dashboard 数据失败:", err);
|
console.error("获取 Dashboard 数据失败:", err);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -61,13 +62,16 @@ export default function Dashboard() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid>
|
<Stack spacing="lg" p="md">
|
||||||
|
<Title order={1} mb="md">仪表盘</Title>
|
||||||
|
<Grid>
|
||||||
|
|
||||||
<Grid.Col span={6}><HealthCard health={health} /></Grid.Col>
|
<Grid.Col span={6}><HealthCard health={health} /></Grid.Col>
|
||||||
<Grid.Col span={6}>
|
<Grid.Col span={6}>
|
||||||
<AlertStats stats={alerts} layout="column" title="告警统计" link="/alerts" />
|
<AlertStats stats={alerts} layout="column" title="告警统计" link="/alerts" />
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={12}><NodeTable clusterData={cluster} title="集群节点" viewMoreLink="/nodeInfo" /></Grid.Col>
|
<Grid.Col span={12}><NodeTable clusterData={cluster} title="集群节点" viewMoreLink="/nodeInfo" /></Grid.Col>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
</Stack>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { metricsEntries } from "../config/entries";
|
|||||||
export default function Metrics() {
|
export default function Metrics() {
|
||||||
return (
|
return (
|
||||||
<Stack spacing="lg" p="md">
|
<Stack spacing="lg" p="md">
|
||||||
<Title order={2}>指标入口</Title>
|
<Title order={2}>指标详情</Title>
|
||||||
<Grid gutter="lg">
|
<Grid gutter="lg">
|
||||||
{metricsEntries.map((entry) => (
|
{metricsEntries.map((entry) => (
|
||||||
<Grid.Col key={entry.href} span={{ base: 12, sm: 4, md: 3 }}>
|
<Grid.Col key={entry.href} span={{ base: 12, sm: 4, md: 3 }}>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Grid } from "@mantine/core";
|
import { Grid, Stack, Title } from "@mantine/core";
|
||||||
import { apiRequest } from "../config/request";
|
import { apiRequest } from "../config/request";
|
||||||
import { MASTER_API } from "../config/api";
|
import { MASTER_API } from "../config/api";
|
||||||
import { NodeTable } from "../components/NodeTable";
|
import { NodeTable } from "../components/NodeTable";
|
||||||
@@ -23,24 +23,30 @@ export default function NodePage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid gutter="lg">
|
<Stack spacing="lg" p="md">
|
||||||
{/* 左侧:节点表格 */}
|
<Title order={2} mb="md">
|
||||||
<Grid.Col span={drawerOpen ? 8 : 12}>
|
节点信息
|
||||||
<NodeTable
|
</Title>
|
||||||
withSearch
|
|
||||||
withPagination
|
|
||||||
withActions
|
|
||||||
fetchDetail={fetchNodeDetail}
|
|
||||||
/>
|
|
||||||
</Grid.Col>
|
|
||||||
|
|
||||||
{/* 节点详情 Drawer */}
|
<Grid gutter="lg">
|
||||||
<NodeDetailDrawer
|
{/* 左侧:节点表格 */}
|
||||||
opened={drawerOpen}
|
<Grid.Col span={drawerOpen ? 8 : 12}>
|
||||||
onClose={() => setDrawerOpen(false)}
|
<NodeTable
|
||||||
nodeId={selectedNodeId}
|
withSearch
|
||||||
loading={detailLoading}
|
withPagination
|
||||||
/>
|
withActions
|
||||||
</Grid>
|
fetchDetail={fetchNodeDetail}
|
||||||
|
/>
|
||||||
|
</Grid.Col>
|
||||||
|
|
||||||
|
{/* 节点详情 Drawer */}
|
||||||
|
<NodeDetailDrawer
|
||||||
|
opened={drawerOpen}
|
||||||
|
onClose={() => setDrawerOpen(false)}
|
||||||
|
nodeId={selectedNodeId}
|
||||||
|
loading={detailLoading}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
</Stack>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
5
src/web/tests/.env.example
Normal file
5
src/web/tests/.env.example
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
DATA_ROOT=/home/argus/tmp/private/argus
|
||||||
|
ARGUS_UID=1048
|
||||||
|
ARGUS_GID=1048
|
||||||
|
|
||||||
|
USE_INTRANET=false
|
||||||
@@ -1,26 +1,25 @@
|
|||||||
version: '3.8'
|
|
||||||
services:
|
services:
|
||||||
web-frontend:
|
web-frontend:
|
||||||
build:
|
build:
|
||||||
context: ../../../
|
context: ../../../
|
||||||
dockerfile: src/web/build_tools/frontend/Dockerfile
|
dockerfile: src/web/build_tools/frontend/Dockerfile
|
||||||
args:
|
args:
|
||||||
ARGUS_UID: ${ARGUS_UID:-2133}
|
ARGUS_BUILD_UID: ${ARGUS_BUILD_UID:-2133}
|
||||||
ARGUS_GID: ${ARGUS_GID:-2015}
|
ARGUS_BUILD_GID: ${ARGUS_BUILD_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_UID=${ARGUS_UID:-2133}
|
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
|
||||||
- ARGUS_GID=${ARGUS_GID:-2015}
|
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
|
||||||
ports:
|
ports:
|
||||||
- "${ARGUS_WEB_PORT:-8080}:80"
|
- "${ARGUS_WEB_PORT:-8080}:80"
|
||||||
volumes:
|
volumes:
|
||||||
- ${DATA_ROOT:-./data}/web:/private/argus/web/frontend
|
- ${DATA_ROOT:-./data}/web:/private/argus/web/frontend
|
||||||
- ${DATA_ROOT:-./data}/etc:/private/argus/etc
|
- ${DATA_ROOT:-./data}/etc:/private/argus/etc
|
||||||
networks:
|
networks:
|
||||||
- argus-network
|
- argus-debug-net
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
logging:
|
logging:
|
||||||
driver: "json-file"
|
driver: "json-file"
|
||||||
@@ -32,20 +31,20 @@ services:
|
|||||||
context: ../../../
|
context: ../../../
|
||||||
dockerfile: src/web/build_tools/proxy/Dockerfile
|
dockerfile: src/web/build_tools/proxy/Dockerfile
|
||||||
args:
|
args:
|
||||||
ARGUS_UID: ${ARGUS_UID:-2133}
|
ARGUS_BUILD_UID: ${ARGUS_BUILD_UID:-2133}
|
||||||
ARGUS_GID: ${ARGUS_GID:-2015}
|
ARGUS_BUILD_GID: ${ARGUS_BUILD_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_UID=${ARGUS_UID:-2133}
|
- ARGUS_BUILD_UID=${ARGUS_BUILD_UID:-2133}
|
||||||
- ARGUS_GID=${ARGUS_GID:-2015}
|
- ARGUS_BUILD_GID=${ARGUS_BUILD_GID:-2015}
|
||||||
ports:
|
ports:
|
||||||
- "8088:80"
|
- "8088:80"
|
||||||
volumes:
|
volumes:
|
||||||
- ${DATA_ROOT:-./data}/etc:/private/argus/etc
|
- ${DATA_ROOT:-./data}/etc:/private/argus/etc
|
||||||
networks:
|
networks:
|
||||||
- argus-network
|
- argus-debug-net
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
logging:
|
logging:
|
||||||
driver: "json-file"
|
driver: "json-file"
|
||||||
@@ -54,9 +53,8 @@ services:
|
|||||||
max-file: "3"
|
max-file: "3"
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
argus-network:
|
argus-debug-net:
|
||||||
driver: bridge
|
external: true
|
||||||
name: argus-network
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
web-frontend_data:
|
web-frontend_data:
|
||||||
|
|||||||
Reference in New Issue
Block a user