chore: schedule runtime slo reports

This commit is contained in:
John
2026-07-02 08:12:02 +08:00
parent e3ce4032c6
commit a402509d6e
5 changed files with 158 additions and 0 deletions
+7
View File
@@ -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('');
@@ -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" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>$LABEL</string>
<key>ProgramArguments</key>
<array>
<string>$NODE_BIN</string>
<string>$SCRIPT</string>
<string>--write-report</string>
<string>--report-dir</string>
<string>$REPORT_DIR</string>
</array>
<key>WorkingDirectory</key>
<string>$ROOT</string>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>$HOUR</integer>
<key>Minute</key>
<integer>$MINUTE</integer>
</dict>
<key>StandardOutPath</key>
<string>$LOG</string>
<key>StandardErrorPath</key>
<string>$LOG</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/opt/homebrew/bin:/opt/homebrew/opt/node@24/bin:/usr/local/bin:/usr/bin:/bin</string>
</dict>
</dict>
</plist>
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"