huangyuheng/dsh-token-usage ↗★ 0
dsh-token-usage
Real-time token usage dashboard for DeepSeek Harness — live totals (input/output/cache/reasoning), filters by model, day, month and project, and a smooth trend chart. · 实时 Token 用量仪表盘:总量/输入/输出/缓存命中按模型、按天、按月、按项目随选,附趋势曲线。
安装
npx -p @deepseek-ai/dsh dsh plugin --profile web add github:huangyuheng/dsh-token-usage说明文档
阅读完整 README ↗dsh-token-usage
DeepSeek Harness 实时 Token 用量插件:安装后在 设置 → Token 用量 查看用量(自带设置侧边栏一级入口),页面每 5 秒刷新(页面隐藏时暂停,零轮询浪费)。
功能
- 总量卡片:总计(输入+输出+缓存)、输入、输出、缓存读、缓存写、推理、调用次数。
- 范围筛选:按天 / 按月 / 全部三个 tab,默认「按天=今天」;可选日期、月份。
- 模型筛选:时间筛选旁的下拉框按模型过滤(含该模型的项目/按天维度明细),默认全部模型。
- 用量趋势折线图:基于 ECharts(按需打包、随插件离线分发,不依赖 CDN)展示最近 30 天总计、输入、输出、缓存命中、调用次数五条折线;token 维度共用左轴,调用次数用右轴,悬停轴提示显示当日全部明细。图表用命令式渲染,鼠标移动不触发 React 重渲染。
- 单位切换:中文(亿 / 万 / 千)与英文(B / M / K)一键切换,记忆选择。
- 明细表:按模型、按日期、按项目三张表,含总计列。
为什么值得装
你在烧 token,但你说不清烧在哪:哪个项目最贵、哪个模型最吃缓存、这周比上周涨了多少。
dsh-token-usage 把这些变成一眼看得懂的数字。 它跟着每一次调用实时累加,把总量、输入、输出、缓存命中、推理和调用次数摊开在设置页里,按模型、按天、按月、按项目随手切换,趋势用一条平滑曲线讲清楚。装完即用:不用配置、不用重启会话、不会在你写代码的时候跳出来打扰你。
看不见的成本最贵——把它变成看得见的。
💡 Your agent's token spend, live and legible. Totals with input, output, cache hits, reasoning and call counts — sliced by model, day, month or project, with a smooth trend chart. It boots instantly, scans history once on a worker thread, then only folds live events: no polling, no writes, nothing in your way.
安装
dsh plugin --profile web add git+https://github.com/huangyuheng/dsh-token-usage.git
重启 dsh web 后生效。下载 zip 解压后的本地目录安装:
dsh plugin --profile web add /解压路径/dsh-token-usage
性能设计
- 宿主侧 不轮询、不写盘、不加定时器:通过
session/event事件总线做 O(1) 增量累加(每条assistant/message一次字典加法)。 - 启动时做 一次性历史重建:流式解压
$DSH_HOME/sessions/**/session.jsonl.zstd(node:zlib原生 zstd),每读一个文件主动让出事件循环(scheduler.yield()),不阻塞会话处理;重建与实时事件用「会话 seq 水位」去重,任意先后顺序都不会重复计数。 - 只暴露一个只读 JSON 接口
GET /dsh-token-usage(仅回环可访问,内存快照,no-store)。
## 配置(cordis.patch.yml 可覆盖)
```yaml
- id: dsh-token-usage
name: 'dsh-token-usage'
config:
endpoint: /dsh-token-usage
scanAtBoot: true # false 则只统计插件启动之后的实时用量
allowRemote: false # 局域网(非回环)访问时设为 true,仅接受同源请求