Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ The Overview page reports tokens, cost and requests for the last 24 hours,
follows the last ten minutes. A trend chart stacks tokens or cost by model, and
the model ranking beneath it opens the matching requests. Further sections
cover the prompt cache (hit rate, the net savings it brought and the hit rate
per model), latency (median and 95th-percentile time to first byte, per model
and per upstream) and what each protection found.
per model), latency (median and 95th-percentile time to first token, per model
and per upstream), generation speed (median tokens per second, per model and
per upstream) and what each protection found.

The cost figure states how much of it is estimated, for instance for a
response that was cut off before it finished. Requests whose model has no
Expand All @@ -169,7 +170,8 @@ and the date of the prices it was costed with.
### Traffic and sessions

The Traffic page lists requests as they arrive: status, key, model, upstream,
time to first byte and total time, tokens and cost, with marks for a converted
time to first token and total time (with the generation speed on hover), tokens
and cost, with marks for a converted
API format, redacted keys and a blocked or suspicious tool call. The list can
be filtered by key, upstream and model, or narrowed to failed or unpriced
requests. The Sessions view groups the requests of one conversation into
Expand Down Expand Up @@ -426,7 +428,8 @@ Settings can reduce the item to the icon or to the numbers.
</picture>
</p>

Clicking it opens a native menu with the gateway's address and state, unread
Clicking it opens a native menu with the gateway's address, its generation speed
over the last minute and its state, unread
notices, today's requests, tokens and cost, the quotas and reset times of each
subscription account and GLM Coding Plan upstream (with the credits left under
the bar on a plan billed in credits), and the requests in progress, followed by
Expand Down
6 changes: 3 additions & 3 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ AppImage 通过 FUSE 挂载自身,需要 fuse3 软件包中的 `fusermount3`

### 用量与费用

概览页按最近 24 小时、7 天、30 天或自定义区间统计 token、费用与请求数,并与上一个同等长度的区间对比;实时档显示最近十分钟。趋势图按模型分层显示 token 或费用,其下的模型排行可以直接打开对应的请求。页面下方依次是缓存(命中率、缓存带来的净节省、各模型的命中率)、延迟(首字节时间的中位数与 P95,按模型和按上游)以及各项防护的检出情况。
概览页按最近 24 小时、7 天、30 天或自定义区间统计 token、费用与请求数,并与上一个同等长度的区间对比;实时档显示最近十分钟。趋势图按模型分层显示 token 或费用,其下的模型排行可以直接打开对应的请求。页面下方依次是缓存(命中率、缓存带来的净节省、各模型的命中率)、延迟(首 token 时间的中位数与 P95,按模型和按上游)、生成速度(每秒 token 数的中位数,按模型和按上游)以及各项防护的检出情况。

费用会注明其中估算的部分,例如响应结束前被中断的请求。模型未定价的请求和上游未报告用量的请求单独计数,从不按零计入。价格来自价目表:默认价目表采用 LiteLLM 的公开价格,每天更新一次;自定义价目表在其基础上设置倍率,并可单独为个别模型定价,适用于价格与官方不同的中转服务。ChatGPT 这类订阅账号同样按价目表计价,本地模型等上游可设为不计费。每个请求的费用在请求结束时确定,并注明计价所用的价目表及其数据日期。

### 流量与会话

流量页实时列出请求:状态、密钥、模型、上游、首字节时间与总耗时、token 和费用,并标出格式转换、被脱敏的密钥,以及被拦截或可疑的工具调用。列表可以按密钥、上游和模型筛选,或只看失败、无法计价的请求。「会话」视图把同一段对话的请求归为若干轮次,给出每一轮的输入 token 与费用。
流量页实时列出请求:状态、密钥、模型、上游、首 token 时间与总耗时(悬停时显示生成速度)、token 和费用,并标出格式转换、被脱敏的密钥,以及被拦截或可疑的工具调用。列表可以按密钥、上游和模型筛选,或只看失败、无法计价的请求。「会话」视图把同一段对话的请求归为若干轮次,给出每一轮的输入 token 与费用。

打开一个请求可以查看时间线、路由(命中的规则、经过的策略组,以及每一次尝试的状态与耗时)、请求与响应正文、用量与费用。DeepSeek Harness 发出的请求还会显示所带会话日志的大小:这是客户端随每个请求附带的整段对话记录,发往 DeepSeek 以外的上游之前由网关去除。已结束的请求可以在预估费用后原样发送到另一个上游,两次的响应并排对照。

Expand Down Expand Up @@ -206,7 +206,7 @@ macOS 菜单栏显示今日 token 与今日费用,订阅额度紧张时数字
</picture>
</p>

点开是原生菜单:网关地址与状态、未读的提醒、今日的请求数、token 与费用、各订阅账号与 GLM Coding Plan 上游的额度与重置时间(积分制套餐在额度条下方显示剩余积分)、进行中的请求,以及切换手动选择策略组中的上游、复制网关地址和默认密钥、切换连接、检查更新等常用操作,不必先打开主界面。
点开是原生菜单:网关地址、最近一分钟的生成速度与状态、未读的提醒、今日的请求数、token 与费用、各订阅账号与 GLM Coding Plan 上游的额度与重置时间(积分制套餐在额度条下方显示剩余积分)、进行中的请求,以及切换手动选择策略组中的上游、复制网关地址和默认密钥、切换连接、检查更新等常用操作,不必先打开主界面。

<picture>
<source media="(prefers-color-scheme: dark)" srcset="docs/screenshots/zh/menubar-menu-dark.png">
Expand Down
4 changes: 2 additions & 2 deletions scripts/shots/core/en/status.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"api_version": 24,
"api_version": 27,
"clients": 4,
"config_path": "",
"gateway_addr": null,
Expand All @@ -14,5 +14,5 @@
"reachable": []
},
"uptime_secs": 0,
"version": "0.51.0"
"version": "0.54.0"
}
4 changes: 2 additions & 2 deletions scripts/shots/core/zh/status.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"api_version": 24,
"api_version": 27,
"clients": 4,
"config_path": "",
"gateway_addr": null,
Expand All @@ -14,5 +14,5 @@
"reachable": []
},
"uptime_secs": 0,
"version": "0.51.0"
"version": "0.54.0"
}
3 changes: 2 additions & 1 deletion scripts/shots/mock/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type { UpstreamStats } from "@/upstreams/api";
import type { ClientsResponse, CoreStatus, Dashboard, KeyUsage, McpTargetView, PlanView, ScanReport } from "@/types";
import { CORE, CHATGPT_WINDOWS } from "./core";
import { LOCAL_GATEWAY, status } from "./config";
import { IN_FLIGHT, costBucketsBy, costBy, dashboard, upstreamLatency } from "./traffic";
import { IN_FLIGHT, costBucketsBy, costBy, dashboard, upstreamLatency, upstreamTokenRate } from "./traffic";
import { clientsResponse, mcpTargets, plan, scanReport } from "./clients";
import { NOTICES, APP_VERSION, SERVER, autostart, connView, langView, menubar, noticeMode, tested, themeView, updateView } from "./app";
import { P } from "./params";
Expand Down Expand Up @@ -121,6 +121,7 @@ const COMMANDS: Table = {
return {
costs: costBy(sinceMs, (h) => h.provider || null),
latency: upstreamLatency(sinceMs),
token_rate: upstreamTokenRate(sinceMs),
quotas: [{ provider: "chatgpt", windows: CHATGPT_WINDOWS() }],
// Rust 侧把格宽压到不小于一分钟(upstreams.rs 的 `MIN_BUCKET_MS`)
buckets: costBucketsBy(sinceMs, Math.max(60_000, bucketMs), (h) => h.provider),
Expand Down
49 changes: 43 additions & 6 deletions scripts/shots/mock/traffic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
HistoryRow,
InFlightRequest,
LatencyView,
TokenRateView,
Msg,
PriceFields,
RouteHits,
Expand Down Expand Up @@ -195,6 +196,8 @@ function makeRow(s: Spec, r: () => number): HistoryRow {
const price = priceFor(provider, s.model);
const wait = outcome.kind === "fallback" ? Math.round(1_200 + r() * 1_400) : 0;
const duration = wait + ttfb + Math.round((usage.out / perSec) * 1000);
// `ttfb` is when the first token arrives; a stream's response headers come back well before that
const headers = wait + Math.round(ttfb * 0.3);
// 收到了响应的一跳只记状态码,`error` 留给没收到响应的(tw-gateway 的 `hop`)
const attempts: AttemptView[] =
outcome.kind === "fallback"
Expand All @@ -215,8 +218,10 @@ function makeRow(s: Spec, r: () => number): HistoryRow {
model: s.model,
path,
status: 200,
ttfb_ms: wait + ttfb,
ttfb_ms: headers,
ttft_ms: wait + ttfb,
duration_ms: duration,
tokens_per_sec: rate(usage.out, duration - wait - ttfb),
bytes: Math.round(usage.out * 5.2 + 900),
input_tokens: usage.in,
output_tokens: usage.out,
Expand Down Expand Up @@ -244,7 +249,9 @@ function makeRow(s: Spec, r: () => number): HistoryRow {
Object.assign(row, {
status: null,
ttfb_ms: null,
ttft_ms: null,
duration_ms: ttfb,
tokens_per_sec: null,
bytes: null,
input_tokens: null,
output_tokens: null,
Expand All @@ -261,6 +268,8 @@ function makeRow(s: Spec, r: () => number): HistoryRow {
Object.assign(row, {
output_tokens: out,
duration_ms: ttfb + Math.round((out / perSec) * 1000),
// 没跑完的没有速度(tw-gateway 的 `ending::rate`)
tokens_per_sec: null,
bytes: Math.round(out * 5.2 + 900),
cost_micros: price ? costOf(price, cut) : null,
cost_estimated: true,
Expand All @@ -282,7 +291,9 @@ function localRow(who: Who, at: number, probe: "health_check" | "warmup"): Histo
path: probe,
status: 200,
ttfb_ms: 0,
ttft_ms: null,
duration_ms: 0,
tokens_per_sec: null,
bytes: null,
input_tokens: null,
output_tokens: null,
Expand Down Expand Up @@ -470,7 +481,8 @@ function generate() {
attempts: [{ provider: plan.order[0]!, outcome: "served", status: 200, error: null, ms: 1_320 }],
billing: "per-token",
},
{ kind: "request_headers", id, status: 200, ttfb_ms: 1_320 },
{ kind: "request_headers", id, status: 200, ttfb_ms: 400 },
{ kind: "request_first_token", id, ttft_ms: 1_320 },
],
});

Expand Down Expand Up @@ -590,16 +602,16 @@ export function summary(from: number, to = Infinity): Summary {
}

/**
* 首字节的 P50 / P95,按模型或按上游,照 tw-store 的 `latency_by_model` / `latency_by_provider`:
* 本地应答的和没收到首字节的不算,按名字排,分位取第 ⌈p·n/100⌉ 个
* 第一个 token 的 P50 / P95,按模型或按上游,照 tw-store 的 `latency_by_model` / `latency_by_provider`:
* 本地应答的和没有第一个 token 的不算,按名字排,分位取第 ⌈p·n/100⌉ 个
*/
function latency(rows: HistoryRow[], key: (h: HistoryRow) => string): LatencyView[] {
const by = new Map<string, number[]>();
for (const h of rows) {
if (h.local || h.ttfb_ms == null) continue;
if (h.local || h.ttft_ms == null) continue;
const k = key(h);
if (!k) continue;
by.set(k, [...(by.get(k) ?? []), h.ttfb_ms]);
by.set(k, [...(by.get(k) ?? []), h.ttft_ms]);
}
return [...by.entries()]
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
Expand All @@ -610,6 +622,28 @@ function latency(rows: HistoryRow[], key: (h: HistoryRow) => string): LatencyVie
});
}

/** 生成速度,照 tw-gateway 的 `ending::rate`:生成不到半秒的没有 */
function rate(output: number, genMs: number): number | null {
return output > 0 && genMs >= 500 ? Math.floor((output * 1000) / genMs) : null;
}

/** 生成速度的中位数,按模型或按上游,照 tw-store 的 `token_rate`:分位同 `latency` */
function tokenRate(rows: HistoryRow[], key: (h: HistoryRow) => string): TokenRateView[] {
const by = new Map<string, number[]>();
for (const h of rows) {
if (h.local || h.tokens_per_sec == null) continue;
const k = key(h);
if (!k) continue;
by.set(k, [...(by.get(k) ?? []), h.tokens_per_sec]);
}
return [...by.entries()]
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
.map(([model, xs]) => {
xs.sort((a, b) => a - b);
return { model, p50: xs[Math.max(0, Math.ceil(xs.length / 2) - 1)]!, samples: xs.length };
});
}

export function dashboard(sinceMs: number, bucketMs: number): Dashboard {
const rows = rowsBetween(sinceMs).filter((h) => !h.local);
const buckets = new Map<number, CostBucket>();
Expand Down Expand Up @@ -659,6 +693,8 @@ export function dashboard(sinceMs: number, bucketMs: number): Dashboard {
prev: summary(sinceMs - span, sinceMs),
latency: latency(window, (h) => h.model),
latency_by_provider: latency(window, (h) => h.provider),
token_rate: tokenRate(window, (h) => h.model),
token_rate_by_provider: tokenRate(window, (h) => h.provider),
storage: { recording: true, rows: HISTORY.length, blob_bytes: 412 * 1024 ** 2, forwarding_affected: false },
buckets: [...buckets.values()].sort((a, b) => a.at_ms - b.at_ms),
buckets_by_model: [...byModel.values()].sort((a, b) => a.at_ms - b.at_ms),
Expand Down Expand Up @@ -729,6 +765,7 @@ export function costBucketsBy(from: number, bucketMs: number, key: (h: HistoryRo
}

export const upstreamLatency = (from: number) => latency(rowsBetween(from), (h) => h.provider);
export const upstreamTokenRate = (from: number) => tokenRate(rowsBetween(from), (h) => h.provider);

/**
* 各条路由、各条规则命中了多少(`GET /summary/routes`),照 tw-store 的 `route_stats`:按每一行
Expand Down
44 changes: 22 additions & 22 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading