feat(cmd/stats): /v1/stats 的终端查看入口——按模型的可读表格 - #172
Merged
Merged
Conversation
为 Sliverkiss#161 引入的 GET /v1/stats 补一个终端展示层。形态对标既有的 cmd/credit 与 cmd/acct:读 config.json 的 listen/api_key、走 HTTP、 无状态、用完即退。 为什么需要:/v1/stats 目前只能 curl | jq 查看。这类查看是高频、重复、 以「比较」为目的的操作——模型一多,单行 JSON 没法竖着扫,看「哪个模型 首字慢」「缓存命中率掉了没」要在嵌套结构里逐字段比对。 不新增采集、不动端点契约:本工具只做渲染,数据全部来自 /v1/stats。 无状态、无外部依赖(纯标准库)、不引入常驻服务——与「不内嵌 Web 管理 面板」的边界一致,是 CLI 不是面板。 功能: - 默认按模型一行的表格:请求/失败/首字/耗时/吞吐/token/缓存命中率/ 扣费/流式数/最后活动;多模型时附「合计」行 - 按终端尺寸自适应:窗口宽时纳入更多列,窄时依次让位次要列、压缩模型 列、折叠多余行;窄于最简表则回落为滚动输出(不原地覆盖,避免错位) - -json 透传原始响应(供脚本消费) - -watch 原地刷新(-alt-screen 用备用屏,退出还原) - -sort requests|ttfb|tokens|credit 口径说明(与端点语义一致): - 窗口起点取响应的 since,展示「统计窗口」而非进程 uptime——/v1/stats 是纯内存累加器,重启清零是预期行为,工具不做补偿 - 缺字段一律显示占位符(- / 0),不让整表崩掉 配置解析与 cmd/acct 同口径: - 地址:-server > WB2A_URL > config.json 的 listen - 密钥:WB2A_API_KEY > config.json 的 api_key - listen 归一用 net.SplitHostPort(与 acct 的 normalizeListen 逐字一致), 覆盖 "[::]:7863" / 裸 "::" 等 IPv6 形态 验证: - linux/darwin/windows 三平台 go build 通过;linux/darwin 测试编译通过 - go test ./cmd/stats/ 全绿;go vet 干净 - 对运行中的网关实测取数正常(表格与 -json 两条路径)
|
🤖 本机器人已对这条 PR 做要点提炼,并关联到对应主题的规范 issue(机器人整理,如有异议请联系维护者)。 要点:为 /v1/stats 增加一个终端查看入口,以按模型的可读表格形式展示请求统计。
此 PR 保持开启,治理机器人不会关闭它。 |
4 tasks
SunshineR04
added a commit
to SunshineR04/workbuddy2api
that referenced
this pull request
Sep 19, 2026
PR Sliverkiss#172 已合并(上游 41a0e32),cmd/stats/ 不再属于本 fork。更新 「本仓库与上游的区别」段以反映实际差异: - 归属表:cmd/stats 从「本 fork」移到「上游」(附 PR 号) - 「本 fork 新增的内容」→「唯一新增」,只列 stats.ps1 - 对上游文件的改动:由「新增 cmd/stats/ 与 stats.ps1」改为「只新增 stats.ps1」 - 补上游 cmd/stats 的完整用法(含 -server / -alt-screen), stats.ps1 段说明其相对上游脚本的额外能力(按需重编译)
Owner
|
已合并(commit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 canonical issue
Related to #171
Closes #171
动机
GET /v1/stats(#161 引入)提供了按模型聚合的请求统计,但只能通过curl | jq查看:实际排障时这类查看是高频、重复、以「比较」为目的的:模型一多,单行 JSON 没法竖着扫,看「哪个模型首字慢」「缓存命中率掉了没」要在嵌套结构里逐字段比对。PR #161 里那个很好的洞察——「输入是输出的 638 倍,成本几乎全在输入侧」——用
jq手工拼也要好几步才看得出来。本 PR 补一个终端展示层,形态对标既有的
cmd/credit与cmd/acct。效果
用法
与既有约定的对齐
配置解析与
cmd/acct同口径(同仓库两个读 config.json 的工具不应有两套约定):-server>WB2A_URL>config.json的listenWB2A_API_KEY>config.json的api_keylisten归一采用与acct的normalizeListen逐字一致的实现(net.SplitHostPort+ 通配收敛回环),覆盖[::]:7863/ 裸::等 IPv6 形态;测试表也与acct的TestNormalizeListen同表,避免两处实现各自走样。设计取向
/v1/stats,本工具只做渲染。since,显示「统计窗口」而非进程 uptime。/v1/stats是纯内存累加器,重启清零是预期行为,工具侧不做任何补偿或掩饰。已知的可选复杂度
main.go约 1.2k 行,其中排版引擎占大头(按终端尺寸淘汰次要列、压缩模型列、折叠多余行、resize 时重算绘制基线)。这部分是可选体验,不是功能必需。若维护者认为体量过大,可以砍到「按
-json字段平铺的最简表格」(约 200 行),去掉自适应排版与 watch 原地刷新。请评判哪种粒度更合适。验证
go build ./...通过;go vet干净term_windows.go/term_unix.go/term_other.go/term_ansi_nosize.go,build tag 覆盖 windows / unix / solaris+aix / other)go test ./cmd/stats/全绿(2000 行测试:布局、填充、resize、屏幕控制、地址解析、错误路径)-json两条路径均正常取数说明
本 PR 零修改既有文件——只新增
cmd/stats/目录,其余文件与 master 逐字一致。