Files
argus/src/sys/tests/scripts/13_metric_verify_dataplane.sh
yuyr 59a38513a4 完成a6000测试系统构建、部署、测试整合 (#35)
测试方案:

- lm2机器端口映射到本机:18080, 18081, 8082-8085
- 访问URL: http://localhost:18080/dashboard

![image.png](/attachments/30ed6e20-697a-4d3b-a6d3-6acccd2e9922)

![image.png](/attachments/38ef1751-0f3b-49c6-9100-f70d15617acc)

![image.png](/attachments/3be45005-9b9e-4165-8ef6-1d27405800f1)

![image.png](/attachments/eb916192-edc1-4096-8f9f-9769ab6d9039)

![image.png](/attachments/620e6efc-bd02-45ae-bba1-99a95a1b4c02)

![image.png](/attachments/986e77e7-c687-405f-a760-93282249f72f)

端到端测试通过:

![image.png](/attachments/c6e29875-4a16-4718-8b2f-368f64eb545e)

Co-authored-by: sundapeng.sdp <sundapeng@hashdata.cn>
Reviewed-on: #35
Reviewed-by: xuxt <xuxt@zgclab.edu.cn>
Reviewed-by: sundapeng <sundp@mail.zgclab.edu.cn>
Reviewed-by: huhy <husteryezi@163.com>
2025-10-29 10:04:27 +08:00

67 lines
2.8 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
TMP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)/tmp/metric-verify"
mkdir -p "$TMP_DIR"
# 载入端口变量(由 .env 提供)
TEST_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"
if [[ -f "$TEST_ROOT/.env" ]]; then
set -a; source "$TEST_ROOT/.env"; set +a
fi
PROM_BASE="http://localhost:${PROMETHEUS_PORT:-9090}/api/v1"
INSTANCE="${METRIC_TEST_INSTANCE:-172.31.0.50:9100}"
IP_ONLY="${INSTANCE%%:*}"
echo "[VERIFY:DATA] node exporter metrics present in container"
docker exec argus-metric-test-node bash -lc "curl -fsS --max-time 5 http://localhost:9100/metrics | head -n 5" > "$TMP_DIR/node_metrics_head.txt" || { echo "[ERR] cannot fetch node exporter metrics" >&2; exit 1; }
if ! grep -E "node_(exporter_build_info|time_seconds)" -q "$TMP_DIR/node_metrics_head.txt"; then
echo "[WARN] head did not show expected lines; continuing (exporter may output later lines)"
fi
echo "[OK] node exporter endpoint reachable"
echo "[VERIFY:DATA] Prometheus has recent sample for build_info"
curl -fsS --max-time 5 --get "$PROM_BASE/query" --data-urlencode "query=node_exporter_build_info{job=\"node\",ip=\"$IP_ONLY\"}" > "$TMP_DIR/prom_ne_build_info_1.json"
python3 - "$TMP_DIR/prom_ne_build_info_1.json" <<'PY'
import json,sys,time
j=json.load(open(sys.argv[1]))
res=j.get('data',{}).get('result',[])
assert res, 'no result for node_exporter_build_info'
ts=float(res[0]['value'][0])
now=time.time()
assert now-ts<180, f"sample too old: now={now} ts={ts}"
print(int(ts))
PY
T1=$?
sleep 30
curl -fsS --max-time 5 --get "$PROM_BASE/query" --data-urlencode "query=node_exporter_build_info{job=\"node\",ip=\"$IP_ONLY\"}" > "$TMP_DIR/prom_ne_build_info_2.json"
TS1=$(python3 - "$TMP_DIR/prom_ne_build_info_1.json" <<'PY'
import json,sys
print(float(json.load(open(sys.argv[1]))['data']['result'][0]['value'][0]))
PY
)
TS2=$(python3 - "$TMP_DIR/prom_ne_build_info_2.json" <<'PY'
import json,sys
print(float(json.load(open(sys.argv[1]))['data']['result'][0]['value'][0]))
PY
)
awk -v a="$TS1" -v b="$TS2" 'BEGIN{ if (b>=a) exit 0; else exit 1 }' || { echo "[ERR] sample timestamp did not advance" >&2; exit 1; }
echo "[OK] sample timestamp advanced"
echo "[DONE] dataplane verify"
# 追加:GPU 节点端点连通性检查(启用 GPU 时)
if [[ "${ENABLE_GPU:-false}" == "true" ]]; then
echo
echo "[VERIFY:DATA][GPU] curl endpoints on gpu node"
if ! docker exec argus-metric-test-gpu-node bash -lc 'curl -fsS --max-time 5 http://localhost:9100/metrics >/dev/null'; then
echo "[ERR] gpu node 9100 not reachable" >&2; exit 1
fi
if ! docker exec argus-metric-test-gpu-node bash -lc 'curl -fsS --max-time 5 http://localhost:9400/metrics >/dev/null'; then
echo "[ERR] gpu node 9400 not reachable" >&2; exit 1
fi
echo "[OK] gpu node endpoints reachable"
fi