usage_stats
Monitor model usage statistics including call counts, success rates, and average response times to track performance and optimize resource allocation.
Instructions
查看各模型的使用统计(调用次数、成功率、平均耗时)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server.ts:583-592 (handler)The handler for the 'usage_stats' tool. It retrieves formatted usage statistics from the globalStats instance and returns it as text content.case 'usage_stats': { return { content: [ { type: 'text', text: globalStats.formatStats(), }, ], }; }
- src/server.ts:259-266 (registration)Registration of the 'usage_stats' tool in the ListTools response, including its name, description, and empty input schema (no parameters required).{ name: 'usage_stats', description: '查看各模型的使用统计(调用次数、成功率、平均耗时)', inputSchema: { type: 'object', properties: {}, }, },
- src/collaboration/stats.ts:178-200 (helper)The core helper method formatStats() in UsageStats class that computes and formats the usage statistics into a Markdown table for display.formatStats(): string { const stats = this.getGlobalStats(); const uptime = Math.floor((Date.now() - stats.since) / 1000 / 60); let output = `📊 **使用统计** (运行 ${uptime} 分钟)\n\n`; output += `| 指标 | 数值 |\n|------|------|\n`; output += `| 总调用 | ${stats.totalCalls} 次 |\n`; output += `| 成功 | ${stats.totalSuccess} 次 |\n`; output += `| 失败 | ${stats.totalFailed} 次 |\n`; output += `| 平均耗时 | ${(stats.avgDuration / 1000).toFixed(2)}s |\n`; output += `| 总耗时 | ${(stats.totalDuration / 1000).toFixed(1)}s |\n\n`; if (stats.models.length > 0) { output += `### 各模型统计\n\n`; output += `| 模型 | 调用 | 成功率 | 平均耗时 |\n|------|------|--------|----------|\n`; for (const model of stats.models) { output += `| ${model.model} | ${model.totalCalls} | ${(model.successRate * 100).toFixed(0)}% | ${(model.avgDuration / 1000).toFixed(2)}s |\n`; } } return output; }