n8n-workflow-ai
Version:
Enterprise-grade n8n workflow AI with graph-based generation, real-time monitoring, comprehensive testing framework, and production-ready resilience
116 lines (88 loc) • 3.15 kB
Markdown
# Monitoring and Analytics API
## Overview
The monitoring system provides real-time tracking, analytics, and alerting for workflow executions.
## Core Components
### WorkflowMonitoringSystem
The central monitoring service that tracks workflow performance and health.
```typescript
import { WorkflowMonitoringSystem } from '../src/core/monitoring/workflow-monitoring-system';
const monitoring = new WorkflowMonitoringSystem();
```
#### Key Methods
##### `trackExecution(workflow, executionId, status, metrics?)`
Track workflow execution in real-time.
```typescript
await monitoring.trackExecution(workflow, 'exec_123', 'running', {
startTime: Date.now(),
memoryUsage: process.memoryUsage().heapUsed
});
```
##### `getExecutionMetrics(executionId)`
Get detailed metrics for a specific execution.
```typescript
const metrics = await monitoring.getExecutionMetrics('exec_123');
console.log(`Duration: ${metrics.duration}ms, Status: ${metrics.status}`);
```
##### `getWorkflowAnalytics(workflowName, timeRange?)`
Get analytics for a specific workflow over time.
```typescript
const analytics = await monitoring.getWorkflowAnalytics('Email Processor', {
start: Date.now() - 24 * 60 * 60 * 1000, // Last 24 hours
end: Date.now()
});
```
### Alert Configuration
Configure intelligent alerting based on execution patterns:
```typescript
await monitoring.configureAlert({
name: 'High Error Rate',
condition: {
type: 'error_rate',
threshold: 0.05, // 5% error rate
timeWindow: 300000 // 5 minutes
},
actions: [
{ type: 'email', recipients: ['ops@company.com'] },
{ type: 'webhook', url: 'https://hooks.slack.com/...' }
]
});
```
### Analytics Dashboard
Access performance analytics:
```typescript
const dashboard = await monitoring.getDashboardData();
console.log(`Active workflows: ${dashboard.activeWorkflows}`);
console.log(`P95 execution time: ${dashboard.performanceMetrics.p95ExecutionTime}ms`);
```
## Metrics Collected
### Execution Metrics
- **Duration**: Total execution time
- **Status**: Success, failure, timeout, cancelled
- **Memory Usage**: Peak memory consumption
- **Node Performance**: Individual node execution times
- **Error Details**: Stack traces and error categories
### Performance Analytics
- **Throughput**: Executions per time period
- **Percentiles**: P50, P95, P99 execution times
- **Success Rate**: Percentage of successful executions
- **Resource Usage**: CPU and memory patterns
### Business Metrics
- **Workflow Adoption**: Usage patterns over time
- **Cost Analysis**: Resource consumption trends
- **SLA Compliance**: Meeting performance targets
## Real-time Monitoring
Enable real-time monitoring for live tracking:
```typescript
// Subscribe to execution events
monitoring.onExecutionUpdate((executionId, status, metrics) => {
console.log(`Execution ${executionId}: ${status}`);
if (status === 'failed') {
console.error('Execution failed:', metrics.error);
}
});
// Monitor system health
const healthStatus = await monitoring.getSystemHealth();
if (healthStatus.status !== 'healthy') {
console.warn('System degraded:', healthStatus.issues);
}
```