monitor_real_time_performance
Track and analyze real-time performance metrics for AWS Lambda functions, including cold starts and memory usage, to optimize performance and reduce costs effectively.
Instructions
Get real-time performance metrics and alerts for Lambda functions
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| duration | No | Monitoring duration in minutes (default: 5) | |
| functionName | Yes | Name of the Lambda function |
Implementation Reference
- index.js:475-505 (handler)The main handler function for the monitor_real_time_performance tool, which delegates to LambdaAnalyzer.monitorRealTime and formats the MCP response.async monitorRealTimePerformance(args) { const { functionName, duration = 5 } = args; const monitoring = await this.lambdaAnalyzer.monitorRealTime( functionName, duration ); return { content: [ { type: 'text', text: `# Real-time Performance Monitoring: ${functionName}\n\n` + `## Live Metrics (Last ${duration} minutes)\n` + `- **Active Invocations**: ${monitoring.activeInvocations}\n` + `- **Recent Invocations**: ${monitoring.recentInvocations}\n` + `- **Average Duration**: ${monitoring.avgDuration}ms\n` + `- **Error Rate**: ${monitoring.errorRate}%\n` + `- **Cold Starts**: ${monitoring.coldStarts}\n\n` + `## Performance Alerts\n` + `${monitoring.alerts.length > 0 ? monitoring.alerts.map(alert => `${alert}`).join('\n') : 'No performance issues detected'}\n\n` + `## Recent Activity\n` + `${monitoring.recentActivity.map(activity => `- ${activity.timestamp}: ${activity.event} (${activity.duration}ms)` ).join('\n')}` } ] }; }
- index.js:184-201 (schema)Schema definition for the tool input parameters in the ListTools response.{ name: 'monitor_real_time_performance', description: 'Get real-time performance metrics and alerts for Lambda functions', inputSchema: { type: 'object', properties: { functionName: { type: 'string', description: 'Name of the Lambda function' }, duration: { type: 'number', description: 'Monitoring duration in minutes (default: 5)' } }, required: ['functionName'] } }
- index.js:232-234 (registration)Tool dispatch registration in the central CallToolRequestSchema handler switch statement.case 'monitor_real_time_performance': return await this.monitorRealTimePerformance(args);
- src/lambda-analyzer.js:217-239 (helper)Supporting function implementing core real-time monitoring logic by querying CloudWatch metrics, logs, and generating alerts.async monitorRealTime(functionName, duration) { const endTime = new Date(); const startTime = new Date(endTime.getTime() - (duration * 60 * 1000)); // Get recent metrics const metrics = await this.getMetrics(functionName, startTime, endTime); // Get recent log events const recentActivity = await this.getRecentActivity(functionName, startTime, endTime); // Check for alerts const alerts = await this.checkPerformanceAlerts(functionName, metrics); return { activeInvocations: metrics.concurrentExecutions || 0, recentInvocations: metrics.invocations || 0, avgDuration: metrics.avgDuration || 0, errorRate: this.calculateErrorRate(metrics.errors, metrics.invocations), coldStarts: await this.getRecentColdStarts(functionName, startTime, endTime), alerts, recentActivity }; }