feat:新增自动化拉取并汇总分析数据功能

This commit is contained in:
nnbcccscdscdsc
2026-03-24 16:05:14 +08:00
parent 9503862eda
commit f0d297f272
5 changed files with 411 additions and 1 deletions

View File

@@ -0,0 +1,122 @@
#!/usr/bin/env bash
set -u
set -o pipefail
repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
remote_source="boll@175.178.116.187:/home/boll/LMJWork/OmniSocketGo/peer-b-latency.jsonl"
local_peer_a="$repo_dir/peer-a-latency.jsonl"
local_peer_b="$repo_dir/peer-b-latency.jsonl"
summary_output="$repo_dir/latency-summary.jsonl"
chart_output="$repo_dir/latency-summary.html"
latency_binary="$repo_dir/bin/latencysummary"
go_cache_dir="${GOCACHE:-/tmp/omnisocketgo-go-build}"
poll_interval_seconds=1
remote_tmp=""
summary_tmp=""
chart_tmp=""
log() {
printf '[%s] %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$*"
}
cleanup_temp_file() {
local path="$1"
if [[ -n "$path" && -e "$path" ]]; then
rm -f "$path"
fi
}
cleanup() {
cleanup_temp_file "$remote_tmp"
cleanup_temp_file "$summary_tmp"
cleanup_temp_file "$chart_tmp"
}
trap cleanup EXIT INT TERM
cd "$repo_dir" || exit 1
mkdir -p "$repo_dir/bin"
mkdir -p "$go_cache_dir"
if ! GOCACHE="$go_cache_dir" go build -o "$latency_binary" ./cmd/latencysummary; then
log "build failed; exiting"
exit 1
fi
log "starting 1-second refresh loop"
while true; do
remote_tmp="$(mktemp "$repo_dir/peer-b-latency.jsonl.tmp.XXXXXX")" || exit 1
if scp -P 10022 "$remote_source" "$remote_tmp"; then
if mv -f "$remote_tmp" "$local_peer_b"; then
remote_tmp=""
else
status=$?
log "failed to replace $(basename "$local_peer_b") after scp (exit $status)"
cleanup_temp_file "$remote_tmp"
remote_tmp=""
sleep "$poll_interval_seconds"
continue
fi
else
status=$?
log "scp refresh failed (exit $status)"
cleanup_temp_file "$remote_tmp"
remote_tmp=""
sleep "$poll_interval_seconds"
continue
fi
summary_tmp="$(mktemp "$repo_dir/latency-summary.tmp.XXXXXX.jsonl")" || exit 1
chart_tmp="${summary_tmp%.jsonl}.html"
if "$latency_binary" \
-input "$local_peer_a" \
-input "$local_peer_b" \
-shared-max-offset 1 \
-output "$summary_tmp"; then
if [[ ! -f "$summary_tmp" || ! -f "$chart_tmp" ]]; then
log "summary succeeded but temporary outputs are incomplete"
cleanup_temp_file "$summary_tmp"
cleanup_temp_file "$chart_tmp"
summary_tmp=""
chart_tmp=""
sleep "$poll_interval_seconds"
continue
fi
if ! mv -f "$summary_tmp" "$summary_output"; then
status=$?
log "failed to replace $(basename "$summary_output") (exit $status)"
cleanup_temp_file "$summary_tmp"
cleanup_temp_file "$chart_tmp"
summary_tmp=""
chart_tmp=""
sleep "$poll_interval_seconds"
continue
fi
summary_tmp=""
if ! mv -f "$chart_tmp" "$chart_output"; then
status=$?
log "failed to replace $(basename "$chart_output") (exit $status)"
cleanup_temp_file "$chart_tmp"
chart_tmp=""
sleep "$poll_interval_seconds"
continue
fi
chart_tmp=""
else
status=$?
log "latency summary refresh failed (exit $status)"
cleanup_temp_file "$summary_tmp"
cleanup_temp_file "$chart_tmp"
summary_tmp=""
chart_tmp=""
sleep "$poll_interval_seconds"
continue
fi
sleep "$poll_interval_seconds"
done