Flow Monitor 是一款专业的 LLM API 流量监控和分析工具,参考 mitmproxy 的 Flow 模型设计,专为 AI 开发者和研究人员打造。
- 捕获所有 LLM API 请求和响应
- 支持 OpenAI、Claude、Gemini、Kiro 等主流 AI 服务
- 实时显示请求状态、耗时、Token 使用量
- 流式响应重建和展示
- 详细的请求/响应内容查看
- Token 使用统计和成本估算
- 延迟分析和性能监控
- 按模型、Provider、状态等多维度统计
- 请求/响应差异对比 (Diff View)
- 高级过滤表达式(类似 mitmproxy 语法)
- 快速过滤器和书签功能
- 相关请求关联分析
- 拦截并修改请求/响应
- 支持断点调试模式
- 自定义拦截规则
- 超时自动放行
- 多种格式导出:JSON、HAR、JSONL、Markdown、CSV
- 代码生成:cURL、Python、TypeScript、Go、Rust
- 批量导出和选择性导出
- 敏感信息脱敏
- 创建和管理调试会话
- 会话内流量分组
- 会话导出和分享
- 自动会话检测
- 打开 ProxyCast 应用
- 进入「插件中心」或「工具箱」页面
- 在推荐插件中找到「Flow Monitor」
- 点击「一键安装」
# 克隆仓库 git clone https://github.com/aiclientproxy/flow-monitor.git cd flow-monitor # 安装依赖 npm install # 开发模式运行 npm run tauri:dev # 构建 npm run tauri:build
Flow Monitor 采用分层架构设计:
┌─────────────────────────────────────────────────────────┐
│ Frontend (React) │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────┐ │
│ │ FlowList │ │ FlowDetail │ │ FilterPanel │ │
│ └─────────────┘ └─────────────┘ └─────────────────┘ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────┐ │
│ │ DiffView │ │ Sessions │ │ Statistics │ │
│ └─────────────┘ └─────────────┘ └─────────────────┘ │
├─────────────────────────────────────────────────────────┤
│ API Layer (Tauri) │
│ ┌─────────────────────────────────────────────────┐ │
│ │ Tauri Commands │ │
│ └─────────────────────────────────────────────────┘ │
├─────────────────────────────────────────────────────────┤
│ Backend (Rust) │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Monitor │ │ Interceptor │ │ Exporter │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ MemoryStore │ │ FileStore │ │ QueryService │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────┘
| 模块 | 说明 |
|---|---|
monitor |
核心监控服务,管理 Flow 生命周期 |
models |
数据模型定义,包括 LLMFlow、Request、Response 等 |
memory_store |
内存存储,支持 LRU 驱逐策略 |
file_store |
文件存储,支持 JSONL 格式和 SQLite 索引 |
query_service |
查询服务,支持多维度过滤、排序、分页 |
filter_parser |
高级过滤表达式解析器 |
interceptor |
流量拦截器,支持请求/响应修改 |
exporter |
导出服务,支持多种格式 |
code_exporter |
代码生成器 |
session |
会话管理 |
diff |
差异对比 |
Flow Monitor 支持类似 mitmproxy 的高级过滤表达式:
# 按模型过滤
model:gpt-4
# 按状态过滤
state:completed
state:error
# 按 Provider 过滤
provider:openai
provider:claude
# 按 Token 数量过滤
tokens:>1000
tokens:<500
# 按延迟过滤
latency:>2000 # 大于 2 秒
# 组合过滤
model:gpt-4 AND state:completed
provider:openai OR provider:claude
NOT state:error
# 内容搜索
content:"hello world"
request:"system prompt"
response:"error"
interface LLMFlow { id: string; // 唯一标识 flow_type: FlowType; // 流类型 state: FlowState; // 状态 request: LLMRequest; // 请求 response?: LLMResponse; // 响应 error?: FlowError; // 错误信息 metadata: FlowMetadata; // 元数据 timestamps: FlowTimestamps; // 时间戳 annotations: FlowAnnotations; // 注解 }
enum FlowState { Pending, // 等待中 Streaming, // 流式传输中 Completed, // 已完成 Error, // 错误 Cancelled, // 已取消 Intercepted, // 已拦截 }
{
"default_settings": {
"max_flows_in_memory": 1000,
"retention_days": 7,
"auto_cleanup": true,
"notification_enabled": true,
"intercept_enabled": false
}
}| 变量 | 说明 | 默认值 |
|---|---|---|
FLOW_MONITOR_DATA_DIR |
数据存储目录 | ~/.flow-monitor |
FLOW_MONITOR_MAX_MEMORY |
最大内存 Flow 数量 | 1000 |
FLOW_MONITOR_RETENTION_DAYS |
数据保留天数 | 7 |
const flows = await flowMonitorApi.getFlows({ filter: "state:completed", sort_by: "timestamp", sort_order: "desc", page: 1, page_size: 50, });
const flow = await flowMonitorApi.getFlow(flowId);
const result = await flowMonitorApi.exportFlows({ flow_ids: ["flow-1", "flow-2"], format: "har", options: { include_request_body: true, include_response_body: true, redact_sensitive: true, }, });
const code = await flowMonitorApi.generateCode(flowId, { format: "python", include_comments: true, });
- 前端: React 18, TypeScript, Tailwind CSS, Radix UI
- 后端: Rust, Tauri 2.0
- 存储: SQLite, JSONL
flow-monitor/
├── src/ # 前端源码
│ ├── components/ # React 组件
│ ├── hooks/ # React Hooks
│ ├── lib/ # 工具库和 API
│ └── pages/ # 页面组件
├── src-tauri/ # Rust 后端
│ └── src/
│ ├── flow_monitor/ # 核心模块
│ └── commands/ # Tauri 命令
├── plugin/ # 插件配置
└── .github/workflows/ # CI/CD
# 开发模式 npm run tauri:dev # 生产构建 npm run tauri:build # 仅构建 CLI cd src-tauri && cargo build --release --bin flow-monitor-cli
# Rust 测试 cd src-tauri && cargo test # 前端测试 npm test
- 基础监控功能
- 流量过滤和搜索
- 多格式导出
- 代码生成
- 会话管理
- 差异对比
- 独立应用模式
- 请求重放(独立模式)
- 插件系统
- 云端同步
- 团队协作
欢迎提交 Issue 和 Pull Request!
- Fork 本仓库
- 创建特性分支 (
git checkout -b feature/amazing-feature) - 提交更改 (
git commit -m 'Add amazing feature') - 推送到分支 (
git push origin feature/amazing-feature) - 创建 Pull Request
MIT License - 详见 LICENSE 文件