根因:sqlite_exec 吞掉 stderr(2>/dev/null),查询失败返回空串, 0 默认为 0 导致误报 修复:业务层取数显式调用 sqlite3 + 检查退出码 + 正则校验, 查询失败跳过检测并 warn 日志
33 lines
1.1 KiB
Bash
33 lines
1.1 KiB
Bash
#!/usr/bin/env bash
|
|
# ============================================================================
|
|
# OA Monitor · HTTP 端点健康检查(每 30 秒)
|
|
# 在 DSH 上直接 curl
|
|
# ============================================================================
|
|
set -u
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
source "${SCRIPT_DIR}/../lib/common.sh"
|
|
|
|
NOW=$(date +%s)
|
|
|
|
for endpoint in "${OA_ENDPOINTS[@]}"; do
|
|
result=$(curl -sk -o /dev/null -w '%{http_code}|%{time_total}' --max-time 10 "${endpoint}" 2>/dev/null)
|
|
status=$(echo "${result}" | cut -d'|' -f1)
|
|
time_ms=$(echo "${result}" | cut -d'|' -f2 | awk '{printf "%d", $1*1000}')
|
|
status=${status:-0}
|
|
time_ms=${time_ms:-0}
|
|
|
|
case "${status}" in
|
|
000) healthy=0 ;;
|
|
2*) healthy=1 ;;
|
|
3*) healthy=1 ;;
|
|
*) healthy=0 ;;
|
|
esac
|
|
|
|
sqlite_exec "INSERT INTO http_metrics (ts, endpoint, status_code, resp_time_ms, healthy)
|
|
VALUES (${NOW}, '${endpoint}', ${status}, ${time_ms}, ${healthy});"
|
|
|
|
log_info "[HTTP] ${endpoint} status=${status} time=${time_ms}ms healthy=${healthy}"
|
|
done
|
|
|
|
log_info "[HTTP] 全部完成"
|