get_performance_stats
Retrieve SQL Server performance statistics and health summaries to monitor database efficiency and identify optimization opportunities.
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 performance statistics from the PerformanceMonitor instance and formats them as a JSON text response.getPerformanceStats() { const stats = this.performanceMonitor.getStats(); return [ { type: 'text', text: JSON.stringify( { success: true, data: stats }, null, 2 ) } ]; }
- lib/tools/tool-registry.js:103-117 (schema)The input schema definition for the 'get_performance_stats' tool, defining an 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)The switch case registration in the CallToolRequest handler that routes 'get_performance_stats' calls to the getPerformanceStats() method.case 'get_performance_stats': return { content: this.getPerformanceStats() };
- The core PerformanceMonitor.getStats() method that computes and returns the performance statistics (overall, recent, pool, monitoring) 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 } }; }