monitor_real_time_performance
Monitor AWS Lambda function performance metrics and receive alerts in real-time to identify issues and optimize execution.
Instructions
Get real-time performance metrics and alerts for Lambda functions
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| functionName | Yes | Name of the Lambda function | |
| duration | No | Monitoring duration in minutes (default: 5) |
Implementation Reference
- index.js:475-505 (handler)Primary tool handler: destructures args, calls LambdaAnalyzer.monitorRealTime(), formats and returns the response content.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')}` } ] }; }
- src/lambda-analyzer.js:217-239 (handler)Core implementation logic: fetches real-time metrics from CloudWatch, recent activity from logs, checks alerts, computes error rate and returns monitoring data.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 }; }
- index.js:184-201 (schema)Tool schema definition including input schema with functionName (required) and optional duration.{ 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-233 (registration)Tool dispatch/registration in the CallToolRequestSchema switch statement.case 'monitor_real_time_performance': return await this.monitorRealTimePerformance(args);