feat(监控): 管理员排行榜实时并发监控 + 真正停止对话 + 409 中文化
- 排行榜页顶部新增「实时并发监控」面板(admin-only):当前并发大模型调用数 +
调用列表(用户/智能体/类型/已运行时长),每行「停止」+「全部停止」经
RunManager.cancel 真正中断 LLM 流式调用,减轻大模型压力
- 并发量折线图(峰值/均值,按分钟/小时):新增轻量后台采样器写入新表
concurrency_samples(create_all 自动建表),可按分/时聚合
- 大模型出字速度折线图(tokens/秒,按分钟/小时):复用 llm_call_metrics 聚合,
便于定位是模型/供应商慢
- 后台采样可开关、默认关闭(opt-in)、运行时切换免重启、对线上零影响
(单条极小 INSERT、保留期清理、查询有上限、全程 best-effort)
- 409 中文化:上一轮未结束又发新问题时返回中文提示,前端 onError 友好映射
后端:runtime/runs/manager.py(list_active)、persistence/concurrency(新模块)、
config/system_settings(ConcurrencyMonitorSettings)、gateway/routers/admin_active_runs、
app.py(采样后台任务)、services.py(409)。前端:core/admin/{active-runs,hooks}、
components/workspace/admin/concurrency-monitor、AdminUserLeaderboardPage、threads/hooks。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
158d157af4
commit
26f8010a57
17 files changed
+1488
-1
No files matched your search
@@ -17,6 +17,96 @@ import {
|
||||
updateAdminV1Fact,
|
||||
updateAdminV1Section,
|
||||
} from "./api";
|
||||
import {
|
||||
cancelActiveRun,
|
||||
cancelAllActiveRuns,
|
||||
getMonitorSettings,
|
||||
loadActiveRuns,
|
||||
loadConcurrencySeries,
|
||||
loadTokenSpeedSeries,
|
||||
updateMonitorSettings,
|
||||
type Granularity,
|
||||
} from "./active-runs";
|
||||
|
||||
// ── 实时并发监控 (admin) ─────────────────────────────────────────────────────
|
||||
|
||||
/** Live snapshot of in-flight runs. Polls every `intervalMs` while `enabled`. */
|
||||
export function useActiveRuns(enabled = true, intervalMs = 4000) {
|
||||
return useQuery({
|
||||
queryKey: ["admin-active-runs", "live"],
|
||||
queryFn: loadActiveRuns,
|
||||
enabled,
|
||||
refetchInterval: enabled ? intervalMs : false,
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
}
|
||||
|
||||
/** 并发量时序 (peak/avg per minute|hour). */
|
||||
export function useConcurrencySeries(
|
||||
granularity: Granularity,
|
||||
hours: number | undefined,
|
||||
enabled = true,
|
||||
intervalMs = 15000,
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: ["admin-active-runs", "concurrency", granularity, hours ?? null],
|
||||
queryFn: () => loadConcurrencySeries(granularity, hours),
|
||||
enabled,
|
||||
refetchInterval: enabled ? intervalMs : false,
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
}
|
||||
|
||||
/** 大模型 token 出字速度时序 (tokens/sec per minute|hour). */
|
||||
export function useTokenSpeedSeries(
|
||||
granularity: Granularity,
|
||||
hours: number | undefined,
|
||||
enabled = true,
|
||||
intervalMs = 15000,
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: ["admin-active-runs", "token-speed", granularity, hours ?? null],
|
||||
queryFn: () => loadTokenSpeedSeries(granularity, hours),
|
||||
enabled,
|
||||
refetchInterval: enabled ? intervalMs : false,
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function useCancelActiveRun() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (runId: string) => cancelActiveRun(runId),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: ["admin-active-runs", "live"] }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCancelAllActiveRuns() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: () => cancelAllActiveRuns(),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: ["admin-active-runs", "live"] }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useMonitorSettings(enabled = true) {
|
||||
return useQuery({
|
||||
queryKey: ["admin-active-runs", "settings"],
|
||||
queryFn: getMonitorSettings,
|
||||
enabled,
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateMonitorSettings() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (nextEnabled: boolean) => updateMonitorSettings(nextEnabled),
|
||||
onSuccess: (data) => {
|
||||
qc.setQueryData(["admin-active-runs", "settings"], data);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUserLeaderboard(
|
||||
range: {
|
||||
|
||||
Reference in new issue
Block a user