get_performance_stats
Retrieve SQL Server performance statistics and health summary for monitoring database operations, with timeframe options for recent, session, or all-time data.
Instructions
Get overall performance statistics and health summary
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| timeframe | No | Time period for stats: "recent" (last 5 min), "session" (since startup), "all" (default) |
Implementation Reference
- index.js:578-593 (handler)The main handler function for the 'get_performance_stats' tool. It retrieves stats from the PerformanceMonitor instance and formats them as JSON text content.getPerformanceStats() { const stats = this.performanceMonitor.getStats(); return [ { type: 'text', text: JSON.stringify( { success: true, data: stats }, null, 2 ) } ]; }
- lib/tools/tool-registry.js:104-117 (schema)Input schema definition for the get_performance_stats tool, including optional timeframe parameter.name: 'get_performance_stats', description: 'Get overall performance statistics and health summary', inputSchema: { type: 'object', properties: { timeframe: { type: 'string', description: 'Time period for stats: "recent" (last 5 min), "session" (since startup), "all" (default)', enum: ['recent', 'session', 'all'] } } } },
- index.js:313-316 (registration)Registration and dispatch of the get_performance_stats handler in the main tool switch statement.case 'get_performance_stats': return { content: this.getPerformanceStats() };
- Core helper method PerformanceMonitor.getStats() that computes and returns the performance statistics used by the tool handler.getStats() { if (!this.config.enabled) { return { enabled: false }; } const now = Date.now(); const uptime = now - this.startTime; // Calculate recent performance (last 5 minutes) const recentThreshold = now - 5 * 60 * 1000; const recentQueries = this.metrics.queries.filter( q => q.startTime > recentThreshold && q.status === 'completed' ); const recentStats = this.calculateQueryStats(recentQueries); return { enabled: true, uptime, overall: this.metrics.aggregates, recent: recentStats, pool: this.metrics.poolStats, monitoring: { totalQueriesTracked: this.metrics.queries.length, totalConnectionEvents: this.metrics.connections.length, samplingRate: this.config.samplingRate, slowQueryThreshold: this.config.slowQueryThreshold } }; }
- index.js:241-243 (registration)Registration of tool list handler that includes get_performance_stats via getAllTools() from tool-registry.this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: getAllTools() }));