- check-alert.sh 新增 Step0 数据新鲜度前置检查:business_metrics 超 30min 过期 → 先告警采集脚本挂了,跳过业务层检测,防止读旧数据乱报推送断档 - collect-business.sh msg_log_hourly 窗口从 1h 改为 15min(和 crontab 频率对齐) - CURR_HOUR 用 10# 算术强制十进制,防 08/09 被解析成 octal
32 lines
1.2 KiB
Bash
Executable File
32 lines
1.2 KiB
Bash
Executable File
#!/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 ;; # 连不上 = 挂了
|
|
5*) healthy=0 ;; # 5xx = 服务异常
|
|
*) healthy=1 ;; # 2xx/3xx/4xx 都算活着(4xx 是业务路径不对,但服务本身通了)
|
|
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] 全部完成"
|