huiwan-sls
SKILL.md
Huiwan SLS 日志查询 Skill
常用场景快速索引
根据查询目的快速定位 logstore:
- 用户登录/活跃 →
sls_login_log - 聊天消息 →
msgsave - 金币变动 →
coin_change_log - 游戏对局 →
sls_game_log - API 请求 →
http-extranet_api_info - HTTP 网关 →
http-extranet_access_info - TCP 网关 →
connector-info - 内容审核/违规 →
dirtyfilter-info - 风控事件 →
risk-log - 活动相关日志 →
activity_info - 定时任务相关 →
wespy-http-go-cron - 用户成长值日志 →
sls_growth_log
重要规则
脚本路径(按优先级):
$CODEX_HOME/skills/huiwan-sls/scripts/huiwan_sls_cli.py(如果设置了$CODEX_HOME)~/.codex/skills/huiwan-sls/scripts/huiwan_sls_cli.py(默认路径)
重要:
- Agent 调用时必须使用完整路径,不要使用相对路径
- 优先检查
$CODEX_HOME环境变量,如果未设置则使用~/.codex作为默认路径
核心原则:
- 固定区服:本 skill 固定使用阿里云国内
cn-shanghai.log.aliyuncs.com/huiwan-shanghai,无需指定--region - 优先 CLI,避免写代码:使用 CLI 命令完成所有查询操作
- 批量拉取用 query-all:需要拉取超过 500 条记录时,使用
query-all命令自动分页,无需编写分页脚本 - JSON 输出到 stdout:日志数据输出到 stdout(JSON 格式),状态信息和错误输出到 stderr
- 注意查询时间范围:默认查询最近 1 小时,排查问题时注意根据实际情况调整时间范围
配置说明
开箱即用:AK/SK 已内置在 scripts/config.json 中(限制 IP 43.106.128.46 访问),安装 skill 后无需额外配置即可使用。
如需覆盖内置配置,可创建用户配置文件 ~/.huiwan_sls_config.json:
{
"access_key_id": "<your-access-key-id>",
"access_key_secret": "<your-access-key-secret>"
}
也可通过环境变量覆盖:SLS_ACCESS_KEY_ID、SLS_ACCESS_KEY_SECRET
配置优先级:内置 scripts/config.json(最高) > 环境变量 > ~/.huiwan_sls_config.json
endpoint 和 project 已内置,无需在配置文件中指定:
- endpoint:
cn-shanghai.log.aliyuncs.com - project:
huiwan-shanghai
快速参考
| 操作 | 命令 | 示例 |
|---|---|---|
| 查询日志 | query |
huiwan_sls_cli.py query --logstore sls_login_log --query "* and uid: 123" --from 24h |
| 拉取全部 | query-all |
huiwan_sls_cli.py query-all --logstore coin_change_log --query "* and type: 2607" --from "2026-02-09 00:00:00" --to "2026-02-09 14:30:00" |
| 统计数量 | count |
huiwan_sls_cli.py count --logstore sls_login_log --query "* and uid: 123" --from 7d |
| 列出 logstore | list-logstores |
huiwan_sls_cli.py list-logstores |
CLI 命令详细用法
全局参数
--endpoint:手动覆盖 SLS endpoint(默认cn-shanghai.log.aliyuncs.com)--project:手动覆盖 SLS project(默认huiwan-shanghai)
query — 查询日志记录
~/.codex/skills/huiwan-sls/scripts/huiwan_sls_cli.py query \
--logstore <logstore名称> \
--query "<SLS查询语句>" \
[--from <起始时间>] \
[--to <结束时间>] \
[--limit <最大返回条数>] \
[--offset <分页偏移量>] \
[--reverse]
参数说明:
--logstore(required):LogStore 名称,见下方 logstore 列表--query(required):SLS 查询语句,如"* and uid: 123"--from:起始时间(默认1h)- 相对时间:
15m、1h、24h、7d、30d - 日期字符串:
2024-01-01或2024-01-01 00:00:00 - Unix 时间戳:
1704067200
- 相对时间:
--to:结束时间(默认now),格式同--from--limit:最大返回条数(默认 500)--offset:分页偏移量(默认 0)--reverse:倒序排列(最新的在前)
query-all — 自动分页拉取全部记录
~/.codex/skills/huiwan-sls/scripts/huiwan_sls_cli.py query-all \
--logstore <logstore名称> \
--query "<SLS查询语句>" \
[--from <起始时间>] \
[--to <结束时间>] \
[--page-size <每页记录数>] \
[--format json|jsonl] \
[--reverse]
参数说明:
--logstore(required):LogStore 名称--query(required):SLS 查询语句--from:起始时间(默认1h),格式同 query 命令--to:结束时间(默认now)--page-size:每页记录数(默认 500),内部自动循环分页直到拉完--format:输出格式,json(默认,JSON 数组)或jsonl(每行一个 JSON 对象,适合大数据量管道处理)--reverse:倒序排列
适用场景:需要拉取超过 500 条记录的批量分析,无需手动编写分页循环。内置自动重试(incomplete 时最多重试 3 次)。
示例:
# 拉取某天全部金币入场记录(JSON 数组)
huiwan_sls_cli.py query-all --logstore coin_change_log \
--query "* and type: 2607 and subtype: 2005" \
--from "2026-02-09 00:00:00" --to "2026-02-09 14:30:00"
# 拉取并以 JSONL 格式输出(适合 jq 管道处理)
huiwan_sls_cli.py query-all --logstore chip_change_log \
--query "* and type: 2607" \
--from "2026-02-09 00:00:00" --to "2026-02-09 14:30:00" \
--format jsonl
# 保存到文件
huiwan_sls_cli.py query-all --logstore sls_game_log \
--query "* and game_type: 2005" \
--from "2026-02-09 00:00:00" --to "2026-02-09 17:00:00" \
--format jsonl > /tmp/game_logs.jsonl
count — 统计日志数量
~/.codex/skills/huiwan-sls/scripts/huiwan_sls_cli.py count \
--logstore <logstore名称> \
--query "<SLS查询语句>" \
[--from <起始时间>] \
[--to <结束时间>]
内部自动在 query 后追加 | select count(*) as total,返回 {"total": N}。
list-logstores — 列出已知 logstore
~/.codex/skills/huiwan-sls/scripts/huiwan_sls_cli.py list-logstores
列出内置的 logstore 列表,包含名称、说明和常用字段。
已知 LogStore 列表
| LogStore | 说明 | 常用字段 |
|---|---|---|
sls_login_log |
登录/活跃记录 | uid, device_id, ip, platform, log_time, app_version, country, province |
msgsave |
聊天消息 | uid, content, target_id, msg_type |
coin_change_log |
金币变动 | uid, coin, type, subtype, remain_coin, log_time, device_id |
sls_game_log |
游戏记录 | uid, rid, game_type, is_win, bet_level, start_time, end_time |
activity_data_log |
活动事件 | act_id, uid, key |
risk-log |
风控日志 | uid, device_id, risk_source |
dirtyfilter-info |
内容过滤 | uid, content, channel, risk_level, label, sub_label, scene, rid |
http-extranet_api_info |
API 服务日志 | method, path, status, response_time, uid |
http-extranet_access_info |
HTTP 网关日志 | bytes_sent, client_ip, http_code, method, uri, response_ms, uid, ua, referer, protocol, forward_ip |
connector-info |
TCP 网关日志 | uid, command, type, response_time, bytes_sent, c_body_size, rid, version |
tmproom-info |
临时房间信息 | — |
clientupload |
客户端上报 | — |
client_ping |
客户端心跳 | uid, device_name |
user_title_log |
用户称号 | uid |
http-intranet_api_info |
内网 API 信息 | — |
activity_info |
活动相关日志 | act_id, uid |
wespy-http-go-cron |
定时任务相关 | uid |
sls_growth_log |
用户成长值日志 | uid, old_value, new_value |
SLS 查询语法参考
基础语法
# 全量查询
*
# AND 条件
* and uid: 123
# 多条件 AND
* and uid: 123 and platform: android
# OR 条件
* and (type: 1 or type: 2)
# NOT 条件
* and uid: 123 not platform: ios
# 字符串精确匹配(带引号)
* and content: "hello world"
# 数值比较(需要 SQL 子句)
* | select * where coin > 100
SQL 分析子句
SLS 支持在查询后追加 | select ... 进行 SQL 分析:
# 统计总数
* and uid: 123 | select count(*) as total
# 求和
* and uid: 123 | select sum(coin) as total_coin
# 分组统计
* and uid: 123 | select type, count(*) as cnt group by type
# 条件过滤 + 统计
* and uid: 123 | select sum(coin) as total where coin < 0
# 去重计数
* and uid: 123 | select count(distinct device_id) as device_count
# 排序 + 分页
* and uid: 123 | select * order by __time__ desc limit 0, 100
# 时间聚合
* and uid: 123 | select date_format(__time__, '%Y-%m-%d') as day, count(*) as cnt group by day order by day
常用内置字段
__time__:日志时间(Unix 时间戳)__source__:日志来源__topic__:日志 topic
常用查询模板
登录日志 (sls_login_log)
# 查询用户最近登录记录
huiwan_sls_cli.py query --logstore sls_login_log --query "* and uid: 123" --from 7d --reverse
# 查询某设备的登录记录
huiwan_sls_cli.py query --logstore sls_login_log --query "* and device_id: abc123" --from 24h
# 统计用户某段时间登录次数
huiwan_sls_cli.py count --logstore sls_login_log --query "* and uid: 123" --from 30d
金币变动 (coin_change_log)
# 查询用户金币变动
huiwan_sls_cli.py query --logstore coin_change_log --query "* and uid: 123" --from 24h --reverse
# 统计用户金币总收入
huiwan_sls_cli.py query --logstore coin_change_log --query "* and uid: 123 | select sum(coin) as total where coin > 0" --from 30d
活动数据 (activity_data_log)
# 查询用户的活动参与记录
huiwan_sls_cli.py query --logstore activity_data_log --query "* and uid: 123 and act_id: 100" --from 7d
# 统计活动参与人数
huiwan_sls_cli.py query --logstore activity_data_log --query "* and act_id: 100 | select count(distinct uid) as user_count" --from 7d
注意事项
- 固定区服:本工具固定使用
cn-shanghai.log.aliyuncs.com/huiwan-shanghai,无需指定--region - 时间范围:默认查询最近 1 小时,排查历史问题时记得调整
--from参数 - 返回条数:
query默认最多返回 500 条,可通过--limit调整;需要拉取全部数据时使用query-all命令自动分页 - 查询完整性:
query和query-all均内置 incomplete 自动重试(最多 3 次),无需手动处理 - 批量数据分析:优先使用
query-all命令直接拉取全部数据,避免手动编写分页脚本。大数据量场景建议使用--format jsonl输出,便于管道处理 - SQL 子句:使用
| select ...时,统计结果可能需要更长时间,建议缩小时间范围