From a402509d6e3aae0f882feb6febe332d9aa146598 Mon Sep 17 00:00:00 2001 From: John Date: Thu, 2 Jul 2026 08:12:02 +0800 Subject: [PATCH] chore: schedule runtime slo reports --- .env.example | 5 ++ .runtime/portal/RUNBOOK.txt | 2 + .../install-runtime-slo-report-agent.sh | 72 +++++++++++++++++++ scripts/build-portal-runtime.mjs | 7 ++ scripts/install-runtime-slo-report-agent.sh | 72 +++++++++++++++++++ 5 files changed, 158 insertions(+) create mode 100755 .runtime/portal/scripts/install-runtime-slo-report-agent.sh create mode 100644 scripts/install-runtime-slo-report-agent.sh diff --git a/.env.example b/.env.example index 36ccdee..c801fe3 100644 --- a/.env.example +++ b/.env.example @@ -35,6 +35,11 @@ H5_PUBLIC_BASE_URL=http://127.0.0.1:5173 # MEMIND_AGENT_RUN_WORKER_POLL_MS=1000 # MEMIND_AGENT_RUN_WORKER_BATCH_SIZE=1 +# Runtime SLO 日报(默认每日 23:55 写 reports/runtime-slo)。 +# MEMIND_RUNTIME_REPORT_DIR=/Users/john/Project/Memind/reports/runtime-slo +# MEMIND_RUNTIME_SLO_HOUR=23 +# MEMIND_RUNTIME_SLO_MINUTE=55 + # ===== memind_adm(独立后台服务)===== # 平台超管 /admin-api/* 与广场运营 /api/ops/v1/* 已从公网服务拆出,独立进程运行。 # 登录仍在主域完成;后台凭 H5_COOKIE_DOMAIN=.tkmind.cn 共享的会话 Cookie 鉴权(生产务必设置)。 diff --git a/.runtime/portal/RUNBOOK.txt b/.runtime/portal/RUNBOOK.txt index c260cad..6070dfb 100644 --- a/.runtime/portal/RUNBOOK.txt +++ b/.runtime/portal/RUNBOOK.txt @@ -42,6 +42,8 @@ Streaming runtime operations: node scripts/runtime-worker-metrics.mjs sample bash scripts/install-runtime-metrics-agent.sh node scripts/runtime-slo-report.mjs + node scripts/runtime-slo-report.mjs --write-report + bash scripts/install-runtime-slo-report-agent.sh node scripts/runtime-worker-drain.mjs drain goosed-3 node scripts/runtime-worker-drain.mjs undrain goosed-3 node scripts/check-tool-runtime.mjs diff --git a/.runtime/portal/scripts/install-runtime-slo-report-agent.sh b/.runtime/portal/scripts/install-runtime-slo-report-agent.sh new file mode 100755 index 0000000..336f84c --- /dev/null +++ b/.runtime/portal/scripts/install-runtime-slo-report-agent.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT="$(cd "$(dirname "$0")/.." && pwd)" +NODE_BIN="${NODE_BIN:-/opt/homebrew/opt/node@24/bin/node}" +SCRIPT="${MEMIND_RUNTIME_SLO_SCRIPT:-$ROOT/scripts/runtime-slo-report.mjs}" +LABEL="${MEMIND_RUNTIME_SLO_LABEL:-cn.tkmind.memind-runtime-slo-report}" +PLIST="$HOME/Library/LaunchAgents/${LABEL}.plist" +LOG="$HOME/Library/Logs/memind-runtime-slo-report.log" +GUI="gui/$(id -u)" +HOUR="${MEMIND_RUNTIME_SLO_HOUR:-23}" +MINUTE="${MEMIND_RUNTIME_SLO_MINUTE:-55}" +REPORT_DIR="${MEMIND_RUNTIME_REPORT_DIR:-$ROOT/reports/runtime-slo}" + +mkdir -p "$HOME/Library/LaunchAgents" "$HOME/Library/Logs" "$REPORT_DIR" + +if [[ ! -x "$NODE_BIN" ]]; then + NODE_BIN="$(command -v node)" +fi +if [[ ! -f "$SCRIPT" ]]; then + echo "runtime SLO script not found: $SCRIPT" >&2 + exit 1 +fi + +cat > "$PLIST" < + + + + Label + $LABEL + ProgramArguments + + $NODE_BIN + $SCRIPT + --write-report + --report-dir + $REPORT_DIR + + WorkingDirectory + $ROOT + StartCalendarInterval + + Hour + $HOUR + Minute + $MINUTE + + StandardOutPath + $LOG + StandardErrorPath + $LOG + EnvironmentVariables + + PATH + /opt/homebrew/bin:/opt/homebrew/opt/node@24/bin:/usr/local/bin:/usr/bin:/bin + + + +EOF + +plutil -lint "$PLIST" +launchctl bootout "$GUI/$LABEL" 2>/dev/null || true +launchctl bootstrap "$GUI" "$PLIST" +launchctl enable "$GUI/$LABEL" +launchctl kickstart -k "$GUI/$LABEL" + +echo "installed $PLIST" +echo "script: $SCRIPT" +echo "schedule: daily ${HOUR}:${MINUTE}" +echo "report_dir: $REPORT_DIR" +echo "log: $LOG" diff --git a/scripts/build-portal-runtime.mjs b/scripts/build-portal-runtime.mjs index 4e8f50a..e779328 100755 --- a/scripts/build-portal-runtime.mjs +++ b/scripts/build-portal-runtime.mjs @@ -307,6 +307,10 @@ async function writeMetadata() { path.join(root, 'scripts', 'install-runtime-metrics-agent.sh'), path.join(runtimeRoot, 'scripts', 'install-runtime-metrics-agent.sh'), ); + await fs.copyFile( + path.join(root, 'scripts', 'install-runtime-slo-report-agent.sh'), + path.join(runtimeRoot, 'scripts', 'install-runtime-slo-report-agent.sh'), + ); await fs.copyFile( path.join(root, 'scripts', 'check-tool-runtime.mjs'), path.join(runtimeRoot, 'scripts', 'check-tool-runtime.mjs'), @@ -362,6 +366,8 @@ async function writeMetadata() { ' node scripts/runtime-worker-metrics.mjs sample', ' bash scripts/install-runtime-metrics-agent.sh', ' node scripts/runtime-slo-report.mjs', + ' node scripts/runtime-slo-report.mjs --write-report', + ' bash scripts/install-runtime-slo-report-agent.sh', ' node scripts/runtime-worker-drain.mjs drain goosed-3', ' node scripts/runtime-worker-drain.mjs undrain goosed-3', ' node scripts/check-tool-runtime.mjs', @@ -393,6 +399,7 @@ async function main() { await fs.chmod(path.join(runtimeRoot, 'scripts', 'runtime-slo-report.mjs'), 0o755); await fs.chmod(path.join(runtimeRoot, 'scripts', 'agent-run-worker.mjs'), 0o755); await fs.chmod(path.join(runtimeRoot, 'scripts', 'install-runtime-metrics-agent.sh'), 0o755); + await fs.chmod(path.join(runtimeRoot, 'scripts', 'install-runtime-slo-report-agent.sh'), 0o755); await fs.chmod(path.join(runtimeRoot, 'scripts', 'check-tool-runtime.mjs'), 0o755); await fs.chmod(path.join(runtimeRoot, 'scripts', 'memind-portal-tunnel.sh'), 0o755); console.log(''); diff --git a/scripts/install-runtime-slo-report-agent.sh b/scripts/install-runtime-slo-report-agent.sh new file mode 100644 index 0000000..336f84c --- /dev/null +++ b/scripts/install-runtime-slo-report-agent.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT="$(cd "$(dirname "$0")/.." && pwd)" +NODE_BIN="${NODE_BIN:-/opt/homebrew/opt/node@24/bin/node}" +SCRIPT="${MEMIND_RUNTIME_SLO_SCRIPT:-$ROOT/scripts/runtime-slo-report.mjs}" +LABEL="${MEMIND_RUNTIME_SLO_LABEL:-cn.tkmind.memind-runtime-slo-report}" +PLIST="$HOME/Library/LaunchAgents/${LABEL}.plist" +LOG="$HOME/Library/Logs/memind-runtime-slo-report.log" +GUI="gui/$(id -u)" +HOUR="${MEMIND_RUNTIME_SLO_HOUR:-23}" +MINUTE="${MEMIND_RUNTIME_SLO_MINUTE:-55}" +REPORT_DIR="${MEMIND_RUNTIME_REPORT_DIR:-$ROOT/reports/runtime-slo}" + +mkdir -p "$HOME/Library/LaunchAgents" "$HOME/Library/Logs" "$REPORT_DIR" + +if [[ ! -x "$NODE_BIN" ]]; then + NODE_BIN="$(command -v node)" +fi +if [[ ! -f "$SCRIPT" ]]; then + echo "runtime SLO script not found: $SCRIPT" >&2 + exit 1 +fi + +cat > "$PLIST" < + + + + Label + $LABEL + ProgramArguments + + $NODE_BIN + $SCRIPT + --write-report + --report-dir + $REPORT_DIR + + WorkingDirectory + $ROOT + StartCalendarInterval + + Hour + $HOUR + Minute + $MINUTE + + StandardOutPath + $LOG + StandardErrorPath + $LOG + EnvironmentVariables + + PATH + /opt/homebrew/bin:/opt/homebrew/opt/node@24/bin:/usr/local/bin:/usr/bin:/bin + + + +EOF + +plutil -lint "$PLIST" +launchctl bootout "$GUI/$LABEL" 2>/dev/null || true +launchctl bootstrap "$GUI" "$PLIST" +launchctl enable "$GUI/$LABEL" +launchctl kickstart -k "$GUI/$LABEL" + +echo "installed $PLIST" +echo "script: $SCRIPT" +echo "schedule: daily ${HOUR}:${MINUTE}" +echo "report_dir: $REPORT_DIR" +echo "log: $LOG"