claude-flow-novice 1.6.2 → 1.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/.claude/settings.json +4 -3
  2. package/.claude-flow-novice/dist/src/api/auth-service.js +84 -38
  3. package/.claude-flow-novice/dist/src/api/auth-service.js.map +1 -1
  4. package/.claude-flow-novice/dist/src/monitoring/apm/apm-integration.js +719 -0
  5. package/.claude-flow-novice/dist/src/monitoring/apm/apm-integration.js.map +1 -0
  6. package/.claude-flow-novice/dist/src/monitoring/apm/datadog-collector.js +363 -0
  7. package/.claude-flow-novice/dist/src/monitoring/apm/datadog-collector.js.map +1 -0
  8. package/.claude-flow-novice/dist/src/monitoring/apm/index.js +97 -0
  9. package/.claude-flow-novice/dist/src/monitoring/apm/index.js.map +1 -0
  10. package/.claude-flow-novice/dist/src/monitoring/apm/newrelic-collector.js +384 -0
  11. package/.claude-flow-novice/dist/src/monitoring/apm/newrelic-collector.js.map +1 -0
  12. package/.claude-flow-novice/dist/src/monitoring/apm/performance-optimizer.js +612 -0
  13. package/.claude-flow-novice/dist/src/monitoring/apm/performance-optimizer.js.map +1 -0
  14. package/.claude-flow-novice/dist/src/monitoring/metrics-collector.js +282 -0
  15. package/.claude-flow-novice/dist/src/monitoring/metrics-collector.js.map +1 -0
  16. package/.claude-flow-novice/dist/src/web/api/apm-routes.js +355 -0
  17. package/.claude-flow-novice/dist/src/web/api/apm-routes.js.map +1 -0
  18. package/.claude-flow-novice/dist/src/web/frontend/src/utils/security.js +425 -0
  19. package/.claude-flow-novice/dist/src/web/frontend/src/utils/security.js.map +1 -0
  20. package/.claude-flow-novice/dist/src/web/security/security-middleware.js +379 -0
  21. package/.claude-flow-novice/dist/src/web/security/security-middleware.js.map +1 -0
  22. package/.claude-flow-novice/dist/src/web/websocket/apm-websocket-handler.js +441 -0
  23. package/.claude-flow-novice/dist/src/web/websocket/apm-websocket-handler.js.map +1 -0
  24. package/.claude-flow-novice/dist/src/web/websocket/websocket-manager.js +255 -1
  25. package/.claude-flow-novice/dist/src/web/websocket/websocket-manager.js.map +1 -1
  26. package/AGENT_PERFORMANCE_GUIDELINES.md +88 -0
  27. package/CLAUDE.md +31 -3
  28. package/MEMORY_LEAK_ROOT_CAUSE.md +149 -0
  29. package/package.json +4 -2
  30. package/scripts/monitor-loop.sh +65 -0
  31. package/scripts/monitor-memory.sh +47 -0
  32. package/scripts/monitor.py +43 -0
@@ -0,0 +1,282 @@
1
+ // Metrics collection system for Claude Flow Novice
2
+ // Integrates with Prometheus, DataDog, and New Relic
3
+ import { createPrometheusMetrics } from './prometheus-collector';
4
+ import { createDataDogMetrics } from './datadog-collector';
5
+ import { createNewRelicMetrics } from './newrelic-collector';
6
+ import { Logger } from '../utils/logger';
7
+ export class MetricsCollector {
8
+ config;
9
+ logger;
10
+ prometheusCollector;
11
+ dataDogCollector;
12
+ newRelicCollector;
13
+ customMetrics = new Map();
14
+ constructor(config){
15
+ this.config = config;
16
+ this.logger = new Logger('MetricsCollector');
17
+ this.initializeCollectors();
18
+ this.registerCustomMetrics();
19
+ }
20
+ initializeCollectors() {
21
+ if (this.config.providers.prometheus?.enabled) {
22
+ this.prometheusCollector = createPrometheusMetrics(this.config.providers.prometheus);
23
+ this.logger.info('Prometheus metrics collector initialized');
24
+ }
25
+ if (this.config.providers.datadog?.enabled) {
26
+ this.dataDogCollector = createDataDogMetrics(this.config.providers.datadog);
27
+ this.logger.info('DataDog metrics collector initialized');
28
+ }
29
+ if (this.config.providers.newrelic?.enabled) {
30
+ this.newRelicCollector = createNewRelicMetrics(this.config.providers.newrelic);
31
+ this.logger.info('New Relic metrics collector initialized');
32
+ }
33
+ }
34
+ registerCustomMetrics() {
35
+ if (!this.config.customMetrics) return;
36
+ for (const [name, definition] of Object.entries(this.config.customMetrics)){
37
+ this.registerMetric(definition);
38
+ }
39
+ }
40
+ registerMetric(definition) {
41
+ this.customMetrics.set(definition.name, definition);
42
+ // Register with each provider
43
+ if (this.prometheusCollector) {
44
+ this.prometheusCollector.registerMetric(definition);
45
+ }
46
+ if (this.dataDogCollector) {
47
+ this.dataDogCollector.registerMetric(definition);
48
+ }
49
+ if (this.newRelicCollector) {
50
+ this.newRelicCollector.registerMetric(definition);
51
+ }
52
+ }
53
+ increment(name, value = 1, labels) {
54
+ this.sendToAllProviders('increment', name, value, labels);
55
+ }
56
+ gauge(name, value, labels) {
57
+ this.sendToAllProviders('gauge', name, value, labels);
58
+ }
59
+ histogram(name, value, labels) {
60
+ this.sendToAllProviders('histogram', name, value, labels);
61
+ }
62
+ timing(name, value, labels) {
63
+ this.sendToAllProviders('timing', name, value, labels);
64
+ }
65
+ sendToAllProviders(type, name, value, labels) {
66
+ try {
67
+ if (this.prometheusCollector) {
68
+ this.prometheusCollector[type](name, value, labels);
69
+ }
70
+ if (this.dataDogCollector) {
71
+ this.dataDogCollector[type](name, value, labels);
72
+ }
73
+ if (this.newRelicCollector) {
74
+ this.newRelicCollector[type](name, value, labels);
75
+ }
76
+ } catch (error) {
77
+ this.logger.error('Failed to send metric to providers', {
78
+ error,
79
+ name,
80
+ type
81
+ });
82
+ }
83
+ }
84
+ // HTTP request metrics
85
+ recordHttpRequest(method, route, statusCode, duration, userAgent) {
86
+ const labels = {
87
+ method,
88
+ route,
89
+ status_code: statusCode.toString(),
90
+ status_class: this.getStatusClass(statusCode),
91
+ user_agent: userAgent ? this.getUserAgentCategory(userAgent) : 'unknown'
92
+ };
93
+ this.increment('http_requests_total', 1, labels);
94
+ this.histogram('http_request_duration_seconds', duration, labels);
95
+ if (statusCode >= 400) {
96
+ this.increment('http_errors_total', 1, labels);
97
+ }
98
+ }
99
+ // Business metrics
100
+ recordAgentOperation(agentType, operation, duration, success, errorType) {
101
+ const labels = {
102
+ agent_type: agentType,
103
+ operation,
104
+ success: success.toString()
105
+ };
106
+ this.increment('agent_operations_total', 1, labels);
107
+ this.histogram('agent_operation_duration_seconds', duration, labels);
108
+ if (!success && errorType) {
109
+ this.increment('agent_errors_total', 1, {
110
+ ...labels,
111
+ error_type: errorType
112
+ });
113
+ }
114
+ }
115
+ recordSwarmActivity(swarmSize, topology, duration, success) {
116
+ const labels = {
117
+ topology,
118
+ success: success.toString()
119
+ };
120
+ this.gauge('active_swarm_size', swarmSize);
121
+ this.increment('swarm_executions_total', 1, labels);
122
+ this.histogram('swarm_execution_duration_seconds', duration, labels);
123
+ }
124
+ // System metrics
125
+ recordMemoryUsage(used, total, component) {
126
+ const labels = {
127
+ component
128
+ };
129
+ const usagePercent = used / total * 100;
130
+ this.gauge('memory_usage_bytes', used, labels);
131
+ this.gauge('memory_usage_percent', usagePercent, labels);
132
+ }
133
+ recordCPUUsage(percent, component) {
134
+ this.gauge('cpu_usage_percent', percent, {
135
+ component
136
+ });
137
+ }
138
+ // Database metrics
139
+ recordDatabaseQuery(operation, table, duration, success, errorType) {
140
+ const labels = {
141
+ operation,
142
+ table,
143
+ success: success.toString()
144
+ };
145
+ this.increment('database_queries_total', 1, labels);
146
+ this.histogram('database_query_duration_seconds', duration, labels);
147
+ if (!success && errorType) {
148
+ this.increment('database_errors_total', 1, {
149
+ ...labels,
150
+ error_type: errorType
151
+ });
152
+ }
153
+ }
154
+ // Cache metrics
155
+ recordCacheOperation(operation, key, duration) {
156
+ const labels = {
157
+ operation,
158
+ key_prefix: key.split(':')[0] || 'unknown'
159
+ };
160
+ this.increment('cache_operations_total', 1, labels);
161
+ if (duration) {
162
+ this.histogram('cache_operation_duration_seconds', duration, labels);
163
+ }
164
+ }
165
+ // Utility methods
166
+ getStatusClass(statusCode) {
167
+ if (statusCode >= 200 && statusCode < 300) return '2xx';
168
+ if (statusCode >= 300 && statusCode < 400) return '3xx';
169
+ if (statusCode >= 400 && statusCode < 500) return '4xx';
170
+ if (statusCode >= 500) return '5xx';
171
+ return 'unknown';
172
+ }
173
+ getUserAgentCategory(userAgent) {
174
+ if (userAgent.includes('curl') || userAgent.includes('wget')) return 'cli';
175
+ if (userAgent.includes('Mozilla')) return 'browser';
176
+ if (userAgent.includes('bot') || userAgent.includes('crawler')) return 'bot';
177
+ return 'other';
178
+ }
179
+ // Health check
180
+ async healthCheck() {
181
+ const providers = {};
182
+ if (this.prometheusCollector) {
183
+ try {
184
+ await this.prometheusCollector.healthCheck();
185
+ providers.prometheus = true;
186
+ } catch {
187
+ providers.prometheus = false;
188
+ }
189
+ }
190
+ if (this.dataDogCollector) {
191
+ try {
192
+ await this.dataDogCollector.healthCheck();
193
+ providers.datadog = true;
194
+ } catch {
195
+ providers.datadog = false;
196
+ }
197
+ }
198
+ if (this.newRelicCollector) {
199
+ try {
200
+ await this.newRelicCollector.healthCheck();
201
+ providers.newrelic = true;
202
+ } catch {
203
+ providers.newrelic = false;
204
+ }
205
+ }
206
+ const allHealthy = Object.values(providers).every((status)=>status);
207
+ return {
208
+ status: allHealthy ? 'healthy' : 'degraded',
209
+ providers
210
+ };
211
+ }
212
+ // Shutdown
213
+ async shutdown() {
214
+ this.logger.info('Shutting down metrics collector');
215
+ if (this.prometheusCollector) {
216
+ await this.prometheusCollector.shutdown();
217
+ }
218
+ if (this.dataDogCollector) {
219
+ await this.dataDogCollector.shutdown();
220
+ }
221
+ if (this.newRelicCollector) {
222
+ await this.newRelicCollector.shutdown();
223
+ }
224
+ this.logger.info('Metrics collector shutdown complete');
225
+ }
226
+ }
227
+ // Factory function
228
+ export function createMetricsCollector(config) {
229
+ return new MetricsCollector(config);
230
+ }
231
+ // Default configuration
232
+ export const defaultMetricsConfig = {
233
+ enabled: true,
234
+ providers: {
235
+ prometheus: {
236
+ enabled: true,
237
+ port: 9090,
238
+ endpoint: '/metrics'
239
+ }
240
+ },
241
+ customMetrics: {
242
+ claude_flow_operations_total: {
243
+ type: 'counter',
244
+ name: 'claude_flow_operations_total',
245
+ description: 'Total number of Claude Flow operations',
246
+ labels: [
247
+ 'operation_type',
248
+ 'agent_type',
249
+ 'status'
250
+ ]
251
+ },
252
+ claude_flow_operation_duration: {
253
+ type: 'histogram',
254
+ name: 'claude_flow_operation_duration_seconds',
255
+ description: 'Duration of Claude Flow operations',
256
+ labels: [
257
+ 'operation_type',
258
+ 'agent_type'
259
+ ],
260
+ buckets: [
261
+ 0.1,
262
+ 0.5,
263
+ 1,
264
+ 2,
265
+ 5,
266
+ 10,
267
+ 30,
268
+ 60
269
+ ]
270
+ },
271
+ active_agents_count: {
272
+ type: 'gauge',
273
+ name: 'active_agents_count',
274
+ description: 'Number of currently active agents',
275
+ labels: [
276
+ 'agent_type'
277
+ ]
278
+ }
279
+ }
280
+ };
281
+
282
+ //# sourceMappingURL=metrics-collector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/monitoring/metrics-collector.ts"],"names":["createPrometheusMetrics","createDataDogMetrics","createNewRelicMetrics","Logger","MetricsCollector","config","logger","prometheusCollector","dataDogCollector","newRelicCollector","customMetrics","Map","initializeCollectors","registerCustomMetrics","providers","prometheus","enabled","info","datadog","newrelic","name","definition","Object","entries","registerMetric","set","increment","value","labels","sendToAllProviders","gauge","histogram","timing","type","error","recordHttpRequest","method","route","statusCode","duration","userAgent","status_code","toString","status_class","getStatusClass","user_agent","getUserAgentCategory","recordAgentOperation","agentType","operation","success","errorType","agent_type","error_type","recordSwarmActivity","swarmSize","topology","recordMemoryUsage","used","total","component","usagePercent","recordCPUUsage","percent","recordDatabaseQuery","table","recordCacheOperation","key","key_prefix","split","includes","healthCheck","allHealthy","values","every","status","shutdown","createMetricsCollector","defaultMetricsConfig","port","endpoint","claude_flow_operations_total","description","claude_flow_operation_duration","buckets","active_agents_count"],"mappings":"AAAA,mDAAmD;AACnD,qDAAqD;AAErD,SAASA,uBAAuB,QAAQ,yBAAyB;AACjE,SAASC,oBAAoB,QAAQ,sBAAsB;AAC3D,SAASC,qBAAqB,QAAQ,uBAAuB;AAC7D,SAASC,MAAM,QAAQ,kBAAkB;AAyCzC,OAAO,MAAMC;IACHC,OAAsB;IACtBC,OAAe;IACfC,oBAA0B;IAC1BC,iBAAuB;IACvBC,kBA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QACvC;QAEA,IAAI,CAACtE,MAAM,CAACW,IAAI,CAAC;IACnB;AACF;AAEA,mBAAmB;AACnB,OAAO,SAAS4D,uBAAuBxE,MAAqB;IAC1D,OAAO,IAAID,iBAAiBC;AAC9B;AAEA,wBAAwB;AACxB,OAAO,MAAMyE,uBAAsC;IACjD9D,SAAS;IACTF,WAAW;QACTC,YAAY;YACVC,SAAS;YACT+D,MAAM;YACNC,UAAU;QACZ;IACF;IACAtE,eAAe;QACbuE,8BAA8B;YAC5BhD,MAAM;YACNb,MAAM;YACN8D,aAAa;YACbtD,QAAQ;gBAAC;gBAAkB;gBAAc;aAAS;QACpD;QACAuD,gCAAgC;YAC9BlD,MAAM;YACNb,MAAM;YACN8D,aAAa;YACbtD,QAAQ;gBAAC;gBAAkB;aAAa;YACxCwD,SAAS;gBAAC;gBAAK;gBAAK;gBAAG;gBAAG;gBAAG;gBAAI;gBAAI;aAAG;QAC1C;QACAC,qBAAqB;YACnBpD,MAAM;YACNb,MAAM;YACN8D,aAAa;YACbtD,QAAQ;gBAAC;aAAa;QACxB;IACF;AACF,EAAE"}
@@ -0,0 +1,355 @@
1
+ /**
2
+ * APM API Routes
3
+ * REST API endpoints for APM integration, health checks, and metrics
4
+ */ import { Router } from 'express';
5
+ import { createAPMIntegration } from '../../monitoring/apm/apm-integration.js';
6
+ const router = Router();
7
+ // Initialize APM integration with environment configuration
8
+ const apmIntegration = createAPMIntegration({
9
+ dataDog: {
10
+ enabled: process.env.DATADOG_ENABLED === 'true',
11
+ apiKey: process.env.DATADOG_API_KEY,
12
+ site: process.env.DATADOG_SITE || 'datadoghq.com',
13
+ serviceName: process.env.DATADOG_SERVICE_NAME || 'claude-flow-novice',
14
+ env: process.env.NODE_ENV || 'production',
15
+ version: process.env.npm_package_version || '1.6.2'
16
+ },
17
+ newRelic: {
18
+ enabled: process.env.NEWRELIC_ENABLED === 'true',
19
+ licenseKey: process.env.NEWRELIC_LICENSE_KEY,
20
+ appName: process.env.NEWRELIC_APP_NAME || 'Claude Flow Novice',
21
+ accountId: process.env.NEWRELIC_ACCOUNT_ID
22
+ },
23
+ distributedTracing: {
24
+ enabled: process.env.DISTRIBUTED_TRACING_ENABLED !== 'false',
25
+ samplingRate: parseFloat(process.env.TRACE_SAMPLING_RATE || '1.0')
26
+ },
27
+ performanceOptimization: {
28
+ enabled: process.env.PERFORMANCE_OPTIMIZATION_ENABLED !== 'false',
29
+ monitoringInterval: parseInt(process.env.PERFORMANCE_MONITORING_INTERVAL || '5000')
30
+ },
31
+ customMetrics: {
32
+ enabled: process.env.CUSTOM_METRICS_ENABLED !== 'false',
33
+ interval: parseInt(process.env.CUSTOM_METRICS_INTERVAL || '10000')
34
+ },
35
+ alerting: {
36
+ enabled: process.env.APM_ALERTING_ENABLED === 'true',
37
+ webhookUrl: process.env.APM_WEBHOOK_URL,
38
+ slackChannel: process.env.APM_SLACK_CHANNEL,
39
+ emailRecipients: process.env.APM_EMAIL_RECIPIENTS?.split(',').filter(Boolean)
40
+ }
41
+ });
42
+ // Health check endpoint
43
+ router.get('/health', async (req, res)=>{
44
+ try {
45
+ const health = await apmIntegration.getHealthStatus();
46
+ const statusCode = health.overall === 'healthy' ? 200 : health.overall === 'degraded' ? 200 : 503;
47
+ res.status(statusCode).json(health);
48
+ } catch (error) {
49
+ console.error('Health check failed:', error);
50
+ res.status(500).json({
51
+ error: 'Health check failed',
52
+ message: error.message
53
+ });
54
+ }
55
+ });
56
+ // Performance metrics endpoint
57
+ router.get('/metrics', async (req, res)=>{
58
+ try {
59
+ const timeRange = req.query.timeRange || '1h';
60
+ const analytics = apmIntegration.getPerformanceAnalytics();
61
+ res.json({
62
+ timeRange,
63
+ timestamp: new Date().toISOString(),
64
+ ...analytics
65
+ });
66
+ } catch (error) {
67
+ console.error('Failed to fetch metrics:', error);
68
+ res.status(500).json({
69
+ error: 'Failed to fetch metrics',
70
+ message: error.message
71
+ });
72
+ }
73
+ });
74
+ // Custom metrics recording endpoint
75
+ router.post('/metrics/custom', async (req, res)=>{
76
+ try {
77
+ const { metricName, value, tags, type } = req.body;
78
+ if (!metricName || value === undefined) {
79
+ return res.status(400).json({
80
+ error: 'Missing required fields: metricName, value'
81
+ });
82
+ }
83
+ apmIntegration.recordBusinessMetric(metricName, value, tags, type);
84
+ res.json({
85
+ success: true,
86
+ message: 'Custom metric recorded successfully',
87
+ metricName,
88
+ value,
89
+ tags,
90
+ type: type || 'gauge'
91
+ });
92
+ } catch (error) {
93
+ console.error('Failed to record custom metric:', error);
94
+ res.status(500).json({
95
+ error: 'Failed to record custom metric',
96
+ message: error.message
97
+ });
98
+ }
99
+ });
100
+ // Agent lifecycle tracing endpoint
101
+ router.post('/trace/agent', async (req, res)=>{
102
+ try {
103
+ const { agentType, lifecycleEvent, agentId, metadata } = req.body;
104
+ if (!agentType || !lifecycleEvent) {
105
+ return res.status(400).json({
106
+ error: 'Missing required fields: agentType, lifecycleEvent'
107
+ });
108
+ }
109
+ apmIntegration.traceAgentLifecycle(agentType, lifecycleEvent, agentId, metadata);
110
+ res.json({
111
+ success: true,
112
+ message: 'Agent lifecycle trace recorded successfully',
113
+ agentType,
114
+ lifecycleEvent,
115
+ agentId,
116
+ metadata
117
+ });
118
+ } catch (error) {
119
+ console.error('Failed to trace agent lifecycle:', error);
120
+ res.status(500).json({
121
+ error: 'Failed to trace agent lifecycle',
122
+ message: error.message
123
+ });
124
+ }
125
+ });
126
+ // Swarm activity tracing endpoint
127
+ router.post('/trace/swarm', async (req, res)=>{
128
+ try {
129
+ const { swarmId, activity, topology, agentCount, metadata } = req.body;
130
+ if (!swarmId || !activity || !topology) {
131
+ return res.status(400).json({
132
+ error: 'Missing required fields: swarmId, activity, topology'
133
+ });
134
+ }
135
+ apmIntegration.traceSwarmActivity(swarmId, activity, topology, agentCount, metadata);
136
+ res.json({
137
+ success: true,
138
+ message: 'Swarm activity trace recorded successfully',
139
+ swarmId,
140
+ activity,
141
+ topology,
142
+ agentCount,
143
+ metadata
144
+ });
145
+ } catch (error) {
146
+ console.error('Failed to trace swarm activity:', error);
147
+ res.status(500).json({
148
+ error: 'Failed to trace swarm activity',
149
+ message: error.message
150
+ });
151
+ }
152
+ });
153
+ // WebSocket performance endpoint
154
+ router.post('/trace/websocket', async (req, res)=>{
155
+ try {
156
+ const { operation, socketId, duration, success, metadata } = req.body;
157
+ if (!operation || !socketId) {
158
+ return res.status(400).json({
159
+ error: 'Missing required fields: operation, socketId'
160
+ });
161
+ }
162
+ apmIntegration.optimizeWebSocketPerformance(operation, socketId, duration, success, metadata);
163
+ res.json({
164
+ success: true,
165
+ message: 'WebSocket performance trace recorded successfully',
166
+ operation,
167
+ socketId,
168
+ duration,
169
+ success,
170
+ metadata
171
+ });
172
+ } catch (error) {
173
+ console.error('Failed to trace WebSocket performance:', error);
174
+ res.status(500).json({
175
+ error: 'Failed to trace WebSocket performance',
176
+ message: error.message
177
+ });
178
+ }
179
+ });
180
+ // Database performance monitoring endpoint
181
+ router.post('/trace/database', async (req, res)=>{
182
+ try {
183
+ const { operation, query, duration, success, metadata } = req.body;
184
+ if (!operation) {
185
+ return res.status(400).json({
186
+ error: 'Missing required field: operation'
187
+ });
188
+ }
189
+ apmIntegration.monitorDatabasePerformance(operation, query, duration, success, metadata);
190
+ res.json({
191
+ success: true,
192
+ message: 'Database performance trace recorded successfully',
193
+ operation,
194
+ query,
195
+ duration,
196
+ success,
197
+ metadata
198
+ });
199
+ } catch (error) {
200
+ console.error('Failed to monitor database performance:', error);
201
+ res.status(500).json({
202
+ error: 'Failed to monitor database performance',
203
+ message: error.message
204
+ });
205
+ }
206
+ });
207
+ // Integration test endpoint
208
+ router.post('/test/integration', async (req, res)=>{
209
+ try {
210
+ const results = await apmIntegration.runIntegrationTest();
211
+ res.json({
212
+ success: true,
213
+ results
214
+ });
215
+ } catch (error) {
216
+ console.error('Integration test failed:', error);
217
+ res.status(500).json({
218
+ error: 'Integration test failed',
219
+ message: error.message
220
+ });
221
+ }
222
+ });
223
+ // Disaster recovery test endpoint
224
+ router.post('/test/disaster-recovery', async (req, res)=>{
225
+ try {
226
+ const results = await apmIntegration.runDisasterRecoveryTest();
227
+ res.json({
228
+ success: true,
229
+ results
230
+ });
231
+ } catch (error) {
232
+ console.error('Disaster recovery test failed:', error);
233
+ res.status(500).json({
234
+ error: 'Disaster recovery test failed',
235
+ message: error.message
236
+ });
237
+ }
238
+ });
239
+ // Configuration endpoint
240
+ router.get('/config', (req, res)=>{
241
+ try {
242
+ const collectors = apmIntegration.getCollectors();
243
+ res.json({
244
+ dataDog: !!collectors.dataDog,
245
+ newRelic: !!collectors.newRelic,
246
+ distributedTracing: !!collectors.distributedTracer,
247
+ performanceOptimizer: !!collectors.performanceOptimizer,
248
+ timestamp: new Date().toISOString()
249
+ });
250
+ } catch (error) {
251
+ console.error('Failed to get APM config:', error);
252
+ res.status(500).json({
253
+ error: 'Failed to get APM configuration',
254
+ message: error.message
255
+ });
256
+ }
257
+ });
258
+ // Recommendations endpoint
259
+ router.get('/recommendations', (req, res)=>{
260
+ try {
261
+ const analytics = apmIntegration.getPerformanceAnalytics();
262
+ res.json({
263
+ recommendations: analytics.recommendations,
264
+ timestamp: new Date().toISOString()
265
+ });
266
+ } catch (error) {
267
+ console.error('Failed to get recommendations:', error);
268
+ res.status(500).json({
269
+ error: 'Failed to get recommendations',
270
+ message: error.message
271
+ });
272
+ }
273
+ });
274
+ // Slow queries endpoint
275
+ router.get('/slow-queries', (req, res)=>{
276
+ try {
277
+ const collectors = apmIntegration.getCollectors();
278
+ if (!collectors.performanceOptimizer) {
279
+ return res.status(503).json({
280
+ error: 'Performance optimizer not available'
281
+ });
282
+ }
283
+ const slowQueries = collectors.performanceOptimizer.getSlowQueries();
284
+ res.json({
285
+ slowQueries,
286
+ count: slowQueries.length,
287
+ timestamp: new Date().toISOString()
288
+ });
289
+ } catch (error) {
290
+ console.error('Failed to get slow queries:', error);
291
+ res.status(500).json({
292
+ error: 'Failed to get slow queries',
293
+ message: error.message
294
+ });
295
+ }
296
+ });
297
+ // Cache performance endpoint
298
+ router.get('/cache-performance', (req, res)=>{
299
+ try {
300
+ const collectors = apmIntegration.getCollectors();
301
+ if (!collectors.performanceOptimizer) {
302
+ return res.status(503).json({
303
+ error: 'Performance optimizer not available'
304
+ });
305
+ }
306
+ const cacheHitRates = collectors.performanceOptimizer.getCacheHitRates();
307
+ res.json({
308
+ cacheHitRates: Object.fromEntries(cacheHitRates),
309
+ timestamp: new Date().toISOString()
310
+ });
311
+ } catch (error) {
312
+ console.error('Failed to get cache performance:', error);
313
+ res.status(500).json({
314
+ error: 'Failed to get cache performance',
315
+ message: error.message
316
+ });
317
+ }
318
+ });
319
+ // Middleware to add APM tracing to all requests
320
+ router.use((req, res, next)=>{
321
+ const startTime = Date.now();
322
+ // Extract trace context from headers
323
+ const traceContext = {
324
+ traceId: req.headers['x-trace-id'],
325
+ spanId: req.headers['x-span-id'],
326
+ parentSpanId: req.headers['x-parent-span-id']
327
+ };
328
+ // Record the request
329
+ res.on('finish', ()=>{
330
+ const duration = Date.now() - startTime;
331
+ const success = res.statusCode < 400;
332
+ // Record API call metrics
333
+ if (traceContext.traceId) {
334
+ // This is part of an existing trace
335
+ apmIntegration.monitorDatabasePerformance('api_request', undefined, duration, success, {
336
+ method: req.method,
337
+ route: req.route?.path || req.path,
338
+ statusCode: res.statusCode.toString(),
339
+ userAgent: req.headers['user-agent']
340
+ });
341
+ } else {
342
+ // Create a new trace for this request
343
+ apmIntegration.traceAgentLifecycle('api-gateway', 'execute', undefined, {
344
+ method: req.method,
345
+ route: req.route?.path || req.path,
346
+ statusCode: res.statusCode.toString(),
347
+ duration: duration.toString()
348
+ });
349
+ }
350
+ });
351
+ next();
352
+ });
353
+ export default router;
354
+
355
+ //# sourceMappingURL=apm-routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/web/api/apm-routes.ts"],"names":["Router","createAPMIntegration","router","apmIntegration","dataDog","enabled","process","env","DATADOG_ENABLED","apiKey","DATADOG_API_KEY","site","DATADOG_SITE","serviceName","DATADOG_SERVICE_NAME","NODE_ENV","version","npm_package_version","newRelic","NEWRELIC_ENABLED","licenseKey","NEWRELIC_LICENSE_KEY","appName","NEWRELIC_APP_NAME","accountId","NEWRELIC_ACCOUNT_ID","distributedTracing","DISTRIBUTED_TRACING_ENABLED","samplingRate","parseFloat","TRACE_SAMPLING_RATE","performanceOptimization","PERFORMANCE_OPTIMIZATION_ENABLED","monitoringInterval","parseInt","PERFORMANCE_MONITORING_INTERVAL","customMetrics","CUSTOM_METRICS_ENABLED","interval","CUSTOM_METRICS_INTERVAL","alerting","APM_ALERTING_ENABLED","webhookUrl","APM_WEBHOOK_URL","slackChannel","APM_SLACK_CHANNEL","emailRecipients","APM_EMAIL_RECIPIENTS","split","filter","Boolean","get","req","res","health","getHealthStatus","statusCode","overall","status","json","error","console","message","timeRange","query","analytics","getPerformanceAnalytics","timestamp","Date","toISOString","post","metricName","value","tags","type","body","undefined","recordBusinessMetric","success","agentType","lifecycleEvent","agentId","metadata","traceAgentLifecycle","swarmId","activity","topology","agentCount","traceSwarmActivity","operation","socketId","duration","optimizeWebSocketPerformance","monitorDatabasePerformance","results","runIntegrationTest","runDisasterRecoveryTest","collectors","getCollectors","distributedTracer","performanceOptimizer","recommendations","slowQueries","getSlowQueries","count","length","cacheHitRates","getCacheHitRates","Object","fromEntries","use","next","startTime","now","traceContext","traceId","headers","spanId","parentSpanId","on","method","route","path","toString","userAgent"],"mappings":"AAAA;;;CAGC,GAED,SAASA,MAAM,QAAQ,UAAU;AACjC,SAAyBC,oBAAoB,QAAQ,0CAA0C;AAE/F,MAAMC,SAASF;AAEf,4DAA4D;AAC5D,MAAMG,iBAAiBF,qBAAqB;IAC1CG,SAAS;QACPC,SAASC,QAAQC,GAAG,CAACC,eAAe,KAAK;QACzCC,QAAQH,QAAQC,GAAG,CAACG,eAAe;QACnCC,MAAML,QAAQC,GAAG,CAACK,YAAY,IAAI;QAClCC,aAAaP,QAAQC,GAAG,CAACO,oBAAoB,IAAI;QACjDP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