Files
junhong_cmp_fiber/scripts/ops/README.md
huang 20b5d70af9 1. 清理预充值SQL
2. 查日志的脚本
2026-05-25 14:30:09 +08:00

96 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 线上日志查询工具
## 编译和打包
Rust 工具是单文件实现,不依赖 Cargo 包:
```bash
rustc scripts/ops/search-worker-logs.rs -O -o /tmp/jh-logq
```
上面命令只编译当前机器可运行的版本。本机是 macOS 时,不能把这个默认产物直接放到 Linux 服务器。
打 Linux x86_64 服务器包:
```bash
mkdir -p dist
rustup target add x86_64-unknown-linux-musl
HOST_TRIPLE="$(rustc -vV | awk '/^host:/ {print $2}')"
RUST_LLD="$(rustc --print sysroot)/lib/rustlib/${HOST_TRIPLE}/bin/rust-lld"
rustc --target x86_64-unknown-linux-musl \
-C linker="$RUST_LLD" \
scripts/ops/search-worker-logs.rs \
-O \
-o dist/jh-logq-linux-amd64
tar -czf dist/jh-logq-linux-amd64.tar.gz -C dist jh-logq-linux-amd64
```
如果服务器是 ARM64
```bash
mkdir -p dist
rustup target add aarch64-unknown-linux-musl
HOST_TRIPLE="$(rustc -vV | awk '/^host:/ {print $2}')"
RUST_LLD="$(rustc --print sysroot)/lib/rustlib/${HOST_TRIPLE}/bin/rust-lld"
rustc --target aarch64-unknown-linux-musl \
-C linker="$RUST_LLD" \
scripts/ops/search-worker-logs.rs \
-O \
-o dist/jh-logq-linux-arm64
tar -czf dist/jh-logq-linux-arm64.tar.gz -C dist jh-logq-linux-arm64
```
上传并安装到服务器:
```bash
scp dist/jh-logq-linux-amd64.tar.gz user@server:/tmp/
ssh user@server
cd /tmp
tar -xzf jh-logq-linux-amd64.tar.gz
sudo install -m 0755 jh-logq-linux-amd64 /usr/local/bin/jh-logq
jh-logq --help
```
如果交叉编译仍报 linker 相关错误,用 Docker 编译 Linux 产物兜底:
```bash
mkdir -p dist
docker run --rm -v "$PWD":/work -w /work rust:1-bookworm \
sh -lc 'rustc scripts/ops/search-worker-logs.rs -O -o dist/jh-logq-linux-amd64'
```
## 目录选择
```bash
# 推荐:直接打开交互向导,自动发现日志目录并按编号选择
/tmp/jh-logq
# 自动发现候选日志目录
/tmp/jh-logq --list-roots
# 已经知道 ICCID 时,也会先自动发现目录并让你按编号选择
/tmp/jh-logq --choose --iccid 8986000000000000000 --date 2026-05-24 --interface realname
```
目录选择支持:
- 回车或 `all`:扫描全部候选目录
- `1,3-4`:只扫描第 1、3、4 个目录
- `all,!2,!5-7`:扫描全部,但排除第 2、5、6、7 个目录
显式传目录仍然保留给自动化脚本使用:
```bash
/tmp/jh-logq \
--roots "/data/worker-1/logs:/data/worker-2/logs:/data/worker-3/logs:/data/worker-4/logs" \
--iccid 8986000000000000000 \
--date 2026-05-24 \
--interface realname
```
默认只输出汇总、命中文件和少量样例,不会把窗口刷满。需要原始行时再加:
```bash
/tmp/jh-logq ... --lines --limit 100
```