node-runtime-guardian 0.1.0
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.
- package/LICENSE +22 -0
- package/README.md +423 -0
- package/dist/core/EventLoopMonitor.d.ts +32 -0
- package/dist/core/EventLoopMonitor.d.ts.map +1 -0
- package/dist/core/EventLoopMonitor.js +131 -0
- package/dist/core/EventLoopMonitor.js.map +1 -0
- package/dist/core/GCMonitor.d.ts +32 -0
- package/dist/core/GCMonitor.d.ts.map +1 -0
- package/dist/core/GCMonitor.js +151 -0
- package/dist/core/GCMonitor.js.map +1 -0
- package/dist/core/Guardian.d.ts +76 -0
- package/dist/core/Guardian.d.ts.map +1 -0
- package/dist/core/Guardian.js +196 -0
- package/dist/core/Guardian.js.map +1 -0
- package/dist/core/HeuristicEngine.d.ts +27 -0
- package/dist/core/HeuristicEngine.d.ts.map +1 -0
- package/dist/core/HeuristicEngine.js +150 -0
- package/dist/core/HeuristicEngine.js.map +1 -0
- package/dist/core/MemoryMonitor.d.ts +33 -0
- package/dist/core/MemoryMonitor.d.ts.map +1 -0
- package/dist/core/MemoryMonitor.js +193 -0
- package/dist/core/MemoryMonitor.js.map +1 -0
- package/dist/core/ProtectionLayer.d.ts +42 -0
- package/dist/core/ProtectionLayer.d.ts.map +1 -0
- package/dist/core/ProtectionLayer.js +105 -0
- package/dist/core/ProtectionLayer.js.map +1 -0
- package/dist/core/ThreadPoolMonitor.d.ts +29 -0
- package/dist/core/ThreadPoolMonitor.d.ts.map +1 -0
- package/dist/core/ThreadPoolMonitor.js +144 -0
- package/dist/core/ThreadPoolMonitor.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/Plugin.d.ts +53 -0
- package/dist/plugins/Plugin.d.ts.map +1 -0
- package/dist/plugins/Plugin.js +74 -0
- package/dist/plugins/Plugin.js.map +1 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +18 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/server/MetricsServer.d.ts +26 -0
- package/dist/server/MetricsServer.d.ts.map +1 -0
- package/dist/server/MetricsServer.js +86 -0
- package/dist/server/MetricsServer.js.map +1 -0
- package/dist/types/index.d.ts +104 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/metrics.d.ts +67 -0
- package/dist/types/metrics.d.ts.map +1 -0
- package/dist/types/metrics.js +3 -0
- package/dist/types/metrics.js.map +1 -0
- package/dist/worker/WorkerPool.d.ts +44 -0
- package/dist/worker/WorkerPool.d.ts.map +1 -0
- package/dist/worker/WorkerPool.js +214 -0
- package/dist/worker/WorkerPool.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GCMonitor = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
/**
|
|
6
|
+
* Monitors GC pressure by observing heap drop patterns
|
|
7
|
+
*/
|
|
8
|
+
class GCMonitor extends events_1.EventEmitter {
|
|
9
|
+
constructor(config = {}) {
|
|
10
|
+
super();
|
|
11
|
+
this.interval = null;
|
|
12
|
+
this.isRunning = false;
|
|
13
|
+
this.heapHistory = [];
|
|
14
|
+
this.maxHistorySize = 100;
|
|
15
|
+
this.minorGCCount = 0;
|
|
16
|
+
this.majorGCCount = 0;
|
|
17
|
+
this.lastHeapSize = 0;
|
|
18
|
+
this.config = {
|
|
19
|
+
enabled: config.enabled ?? true,
|
|
20
|
+
pressureThreshold: config.pressureThreshold ?? 0.7, // 70% pressure
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Start monitoring GC
|
|
25
|
+
*/
|
|
26
|
+
start() {
|
|
27
|
+
if (!this.config.enabled || this.isRunning) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
this.lastHeapSize = process.memoryUsage().heapUsed;
|
|
31
|
+
this.interval = setInterval(() => {
|
|
32
|
+
this.collectMetrics();
|
|
33
|
+
}, 100);
|
|
34
|
+
this.isRunning = true;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Stop monitoring
|
|
38
|
+
*/
|
|
39
|
+
stop() {
|
|
40
|
+
if (this.interval) {
|
|
41
|
+
clearInterval(this.interval);
|
|
42
|
+
this.interval = null;
|
|
43
|
+
}
|
|
44
|
+
this.isRunning = false;
|
|
45
|
+
this.heapHistory = [];
|
|
46
|
+
this.minorGCCount = 0;
|
|
47
|
+
this.majorGCCount = 0;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get current GC metrics
|
|
51
|
+
*/
|
|
52
|
+
getMetrics() {
|
|
53
|
+
// Estimate GC cycles by detecting significant heap drops
|
|
54
|
+
// Minor GC: small drops (< 10% of heap)
|
|
55
|
+
// Major GC: large drops (> 10% of heap)
|
|
56
|
+
const estimatedCycles = this.minorGCCount + this.majorGCCount;
|
|
57
|
+
// Calculate GC pressure based on frequency and heap volatility
|
|
58
|
+
const pressure = this.calculatePressure();
|
|
59
|
+
return {
|
|
60
|
+
estimatedCycles,
|
|
61
|
+
minorGCCount: this.minorGCCount,
|
|
62
|
+
majorGCCount: this.majorGCCount,
|
|
63
|
+
gcPressure: pressure,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
collectMetrics() {
|
|
67
|
+
const currentHeap = process.memoryUsage().heapUsed;
|
|
68
|
+
// Detect GC by observing heap drops
|
|
69
|
+
if (this.lastHeapSize > 0 && currentHeap < this.lastHeapSize) {
|
|
70
|
+
const dropSize = this.lastHeapSize - currentHeap;
|
|
71
|
+
const dropPercentage = dropSize / this.lastHeapSize;
|
|
72
|
+
// Minor GC: small drops (typically < 5% of heap)
|
|
73
|
+
if (dropPercentage < 0.05) {
|
|
74
|
+
this.minorGCCount++;
|
|
75
|
+
}
|
|
76
|
+
// Major GC: larger drops (typically > 5% of heap)
|
|
77
|
+
else if (dropPercentage >= 0.05) {
|
|
78
|
+
this.majorGCCount++;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
this.heapHistory.push(currentHeap);
|
|
82
|
+
if (this.heapHistory.length > this.maxHistorySize) {
|
|
83
|
+
this.heapHistory.shift();
|
|
84
|
+
}
|
|
85
|
+
this.lastHeapSize = currentHeap;
|
|
86
|
+
const metrics = this.getMetrics();
|
|
87
|
+
if (metrics.gcPressure > this.config.pressureThreshold) {
|
|
88
|
+
const emptyEventLoop = {
|
|
89
|
+
mean: 0,
|
|
90
|
+
max: 0,
|
|
91
|
+
min: 0,
|
|
92
|
+
p50: 0,
|
|
93
|
+
p95: 0,
|
|
94
|
+
p99: 0,
|
|
95
|
+
};
|
|
96
|
+
const emptyMemory = {
|
|
97
|
+
heapUsed: 0,
|
|
98
|
+
heapTotal: 0,
|
|
99
|
+
rss: 0,
|
|
100
|
+
external: 0,
|
|
101
|
+
arrayBuffers: 0,
|
|
102
|
+
};
|
|
103
|
+
const emptyThreadPool = {
|
|
104
|
+
saturationLevel: 0,
|
|
105
|
+
estimatedQueueSize: 0,
|
|
106
|
+
avgLatency: 0,
|
|
107
|
+
};
|
|
108
|
+
const emptyCPU = {
|
|
109
|
+
user: 0,
|
|
110
|
+
system: 0,
|
|
111
|
+
};
|
|
112
|
+
const warning = {
|
|
113
|
+
type: 'gcPressure',
|
|
114
|
+
message: `GC pressure detected: ${(metrics.gcPressure * 100).toFixed(2)}% (minor: ${metrics.minorGCCount}, major: ${metrics.majorGCCount})`,
|
|
115
|
+
severity: metrics.gcPressure > 0.9 ? 'high' : 'medium',
|
|
116
|
+
metrics: {
|
|
117
|
+
eventLoopDelay: emptyEventLoop,
|
|
118
|
+
memory: emptyMemory,
|
|
119
|
+
gc: metrics,
|
|
120
|
+
threadPool: emptyThreadPool,
|
|
121
|
+
cpu: emptyCPU,
|
|
122
|
+
activeRequests: 0,
|
|
123
|
+
timestamp: Date.now(),
|
|
124
|
+
},
|
|
125
|
+
timestamp: Date.now(),
|
|
126
|
+
};
|
|
127
|
+
this.emit('warning', warning);
|
|
128
|
+
this.emit('gcPressure', metrics);
|
|
129
|
+
}
|
|
130
|
+
this.emit('metric', metrics);
|
|
131
|
+
}
|
|
132
|
+
calculatePressure() {
|
|
133
|
+
if (this.heapHistory.length < 10) {
|
|
134
|
+
return 0;
|
|
135
|
+
}
|
|
136
|
+
// Calculate volatility (standard deviation of heap size)
|
|
137
|
+
const mean = this.heapHistory.reduce((a, b) => a + b, 0) / this.heapHistory.length;
|
|
138
|
+
const variance = this.heapHistory.reduce((sum, val) => sum + Math.pow(val - mean, 2), 0) /
|
|
139
|
+
this.heapHistory.length;
|
|
140
|
+
const volatility = Math.sqrt(variance) / mean; // Normalized volatility
|
|
141
|
+
// Calculate frequency of GC events
|
|
142
|
+
const recentGCs = this.minorGCCount + this.majorGCCount;
|
|
143
|
+
const frequency = Math.min(recentGCs / this.heapHistory.length, 1);
|
|
144
|
+
// Combine volatility and frequency to estimate pressure
|
|
145
|
+
// Higher volatility + higher frequency = higher pressure
|
|
146
|
+
const pressure = Math.min(volatility * 0.5 + frequency * 0.5, 1);
|
|
147
|
+
return pressure;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.GCMonitor = GCMonitor;
|
|
151
|
+
//# sourceMappingURL=GCMonitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GCMonitor.js","sourceRoot":"","sources":["../../src/core/GCMonitor.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AAWtC;;GAEG;AACH,MAAa,SAAU,SAAQ,qBAAY;IAUzC,YAAY,SAAmB,EAAE;QAC/B,KAAK,EAAE,CAAC;QAVF,aAAQ,GAA0B,IAAI,CAAC;QAEvC,cAAS,GAAG,KAAK,CAAC;QAClB,gBAAW,GAAa,EAAE,CAA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AG,EAAE,EAAE,CAAC;YACjC,OAAO,CAAC,CAAC;QACX,CAAC;QAED,yDAAyD;QACzD,MAAM,IAAI,GACR,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;QACxE,MAAM,QAAQ,GACZ,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;YACvE,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;QAC1B,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC,wBAAwB;QAEvE,mCAAmC;QACnC,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;QACxD,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAEnE,wDAAwD;QACxD,yDAAyD;QACzD,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,GAAG,GAAG,GAAG,SAAS,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC;QAEjE,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AA5KD,8BA4KC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { GuardianConfig, RuntimeMetrics } from '../types';
|
|
4
|
+
import { HeuristicEngine } from './HeuristicEngine';
|
|
5
|
+
import { ProtectionLayer } from './ProtectionLayer';
|
|
6
|
+
/**
|
|
7
|
+
* Main Guardian class that orchestrates all monitoring and protection
|
|
8
|
+
*/
|
|
9
|
+
export declare class Guardian extends EventEmitter {
|
|
10
|
+
private config;
|
|
11
|
+
private eventLoopMonitor;
|
|
12
|
+
private memoryMonitor;
|
|
13
|
+
private threadPoolMonitor;
|
|
14
|
+
private gcMonitor;
|
|
15
|
+
private heuristicEngine;
|
|
16
|
+
private protectionLayer;
|
|
17
|
+
private isRunning;
|
|
18
|
+
private metricsInterval;
|
|
19
|
+
private lastCPUTime;
|
|
20
|
+
constructor(config?: GuardianConfig);
|
|
21
|
+
/**
|
|
22
|
+
* Initialize and start monitoring
|
|
23
|
+
*/
|
|
24
|
+
init(config?: GuardianConfig): void;
|
|
25
|
+
/**
|
|
26
|
+
* Start all monitors
|
|
27
|
+
*/
|
|
28
|
+
start(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Stop all monitors
|
|
31
|
+
*/
|
|
32
|
+
stop(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Get current aggregated metrics
|
|
35
|
+
*/
|
|
36
|
+
getMetrics(): RuntimeMetrics;
|
|
37
|
+
/**
|
|
38
|
+
* Get health score from heuristic engine
|
|
39
|
+
*/
|
|
40
|
+
getHealthScore(): number;
|
|
41
|
+
/**
|
|
42
|
+
* Check if protection is active
|
|
43
|
+
*/
|
|
44
|
+
isProtectionActive(): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Check if a request should be rejected
|
|
47
|
+
*/
|
|
48
|
+
shouldRejectRequest(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Get rejection response details
|
|
51
|
+
*/
|
|
52
|
+
getRejectionResponse(): {
|
|
53
|
+
statusCode: number;
|
|
54
|
+
message: string;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Track incoming request
|
|
58
|
+
*/
|
|
59
|
+
trackRequest(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Track completed request
|
|
62
|
+
*/
|
|
63
|
+
trackRequestComplete(): void;
|
|
64
|
+
/**
|
|
65
|
+
* Get protection layer instance
|
|
66
|
+
*/
|
|
67
|
+
getProtectionLayer(): ProtectionLayer;
|
|
68
|
+
/**
|
|
69
|
+
* Get heuristic engine instance
|
|
70
|
+
*/
|
|
71
|
+
getHeuristicEngine(): HeuristicEngine;
|
|
72
|
+
private setupMonitorEvents;
|
|
73
|
+
private collectAggregatedMetrics;
|
|
74
|
+
private getCPUMetrics;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=Guardian.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Guardian.d.ts","sourceRoot":"","sources":["../../src/core/Guardian.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,cAAc,EAAgB,MAAM,UAAU,CAAC;AAKxE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;GAEG;AACH,qBAAa,QAAS,SAAQ,YAAY;IACxC,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,eAAe,CAA+B;IACtD,OAAO,CAAC,WAAW,CAAsB;gBAE7B,MAAM,GAAE,cAAmB;IAgBvC;;OAEG;IACH,IAAI,CAAC,MAAM,CAAC,EAAE,cAAc,GAAG,IAAI;IAQnC;;OAEG;IACH,KAAK,IAAI,IAAI;IAmBb;;OAEG;IACH,IAAI,IAAI,IAAI;IAmBZ;;OAEG;IACH,UAAU,IAAI,cAAc;IAc5B;;OAEG;IACH,cAAc,IAAI,MAAM;IAIxB;;OAEG;IACH,kBAAkB,IAAI,OAAO;IAI7B;;OAEG;IACH,mBAAmB,IAAI,OAAO;IAI9B;;OAEG;IACH,oBAAoB,IAAI;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;IAI/D;;OAEG;IACH,YAAY,IAAI,IAAI;IAIpB;;OAEG;IACH,oBAAoB,IAAI,IAAI;IAI5B;;OAEG;IACH,kBAAkB,IAAI,eAAe;IAIrC;;OAEG;IACH,kBAAkB,IAAI,eAAe;IAIrC,OAAO,CAAC,kBAAkB;IA2C1B,OAAO,CAAC,wBAAwB;IAahC,OAAO,CAAC,aAAa;CAYtB"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Guardian = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
const EventLoopMonitor_1 = require("./EventLoopMonitor");
|
|
6
|
+
const MemoryMonitor_1 = require("./MemoryMonitor");
|
|
7
|
+
const ThreadPoolMonitor_1 = require("./ThreadPoolMonitor");
|
|
8
|
+
const GCMonitor_1 = require("./GCMonitor");
|
|
9
|
+
const HeuristicEngine_1 = require("./HeuristicEngine");
|
|
10
|
+
const ProtectionLayer_1 = require("./ProtectionLayer");
|
|
11
|
+
/**
|
|
12
|
+
* Main Guardian class that orchestrates all monitoring and protection
|
|
13
|
+
*/
|
|
14
|
+
class Guardian extends events_1.EventEmitter {
|
|
15
|
+
constructor(config = {}) {
|
|
16
|
+
super();
|
|
17
|
+
this.isRunning = false;
|
|
18
|
+
this.metricsInterval = null;
|
|
19
|
+
this.lastCPUTime = process.cpuUsage();
|
|
20
|
+
this.config = config;
|
|
21
|
+
// Initialize monitors
|
|
22
|
+
this.eventLoopMonitor = new EventLoopMonitor_1.EventLoopMonitor(config.eventLoop);
|
|
23
|
+
this.memoryMonitor = new MemoryMonitor_1.MemoryMonitor(config.memory);
|
|
24
|
+
this.threadPoolMonitor = new ThreadPoolMonitor_1.ThreadPoolMonitor(config.threadPool);
|
|
25
|
+
this.gcMonitor = new GCMonitor_1.GCMonitor(config.gc);
|
|
26
|
+
this.heuristicEngine = new HeuristicEngine_1.HeuristicEngine();
|
|
27
|
+
this.protectionLayer = new ProtectionLayer_1.ProtectionLayer(config.protection);
|
|
28
|
+
// Wire up monitor events
|
|
29
|
+
this.setupMonitorEvents();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Initialize and start monitoring
|
|
33
|
+
*/
|
|
34
|
+
init(config) {
|
|
35
|
+
if (config) {
|
|
36
|
+
this.config = { ...this.config, ...config };
|
|
37
|
+
}
|
|
38
|
+
this.start();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Start all monitors
|
|
42
|
+
*/
|
|
43
|
+
start() {
|
|
44
|
+
if (this.isRunning) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
this.eventLoopMonitor.start();
|
|
48
|
+
this.memoryMonitor.start();
|
|
49
|
+
this.threadPoolMonitor.start();
|
|
50
|
+
this.gcMonitor.start();
|
|
51
|
+
// Collect aggregated metrics periodically
|
|
52
|
+
this.metricsInterval = setInterval(() => {
|
|
53
|
+
this.collectAggregatedMetrics();
|
|
54
|
+
}, 1000);
|
|
55
|
+
this.isRunning = true;
|
|
56
|
+
this.emit('started');
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Stop all monitors
|
|
60
|
+
*/
|
|
61
|
+
stop() {
|
|
62
|
+
if (!this.isRunning) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
this.eventLoopMonitor.stop();
|
|
66
|
+
this.memoryMonitor.stop();
|
|
67
|
+
this.threadPoolMonitor.stop();
|
|
68
|
+
this.gcMonitor.stop();
|
|
69
|
+
if (this.metricsInterval) {
|
|
70
|
+
clearInterval(this.metricsInterval);
|
|
71
|
+
this.metricsInterval = null;
|
|
72
|
+
}
|
|
73
|
+
this.isRunning = false;
|
|
74
|
+
this.emit('stopped');
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get current aggregated metrics
|
|
78
|
+
*/
|
|
79
|
+
getMetrics() {
|
|
80
|
+
const cpu = this.getCPUMetrics();
|
|
81
|
+
return {
|
|
82
|
+
eventLoopDelay: this.eventLoopMonitor.getMetrics(),
|
|
83
|
+
memory: this.memoryMonitor.getMetrics(),
|
|
84
|
+
gc: this.gcMonitor.getMetrics(),
|
|
85
|
+
threadPool: this.threadPoolMonitor.getMetrics(),
|
|
86
|
+
cpu,
|
|
87
|
+
activeRequests: this.protectionLayer.getActiveRequests(),
|
|
88
|
+
timestamp: Date.now(),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get health score from heuristic engine
|
|
93
|
+
*/
|
|
94
|
+
getHealthScore() {
|
|
95
|
+
return this.heuristicEngine.getHealthScore();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Check if protection is active
|
|
99
|
+
*/
|
|
100
|
+
isProtectionActive() {
|
|
101
|
+
return this.protectionLayer.isActive();
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Check if a request should be rejected
|
|
105
|
+
*/
|
|
106
|
+
shouldRejectRequest() {
|
|
107
|
+
return this.protectionLayer.shouldRejectRequest(this.getMetrics());
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get rejection response details
|
|
111
|
+
*/
|
|
112
|
+
getRejectionResponse() {
|
|
113
|
+
return this.protectionLayer.getRejectionResponse();
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Track incoming request
|
|
117
|
+
*/
|
|
118
|
+
trackRequest() {
|
|
119
|
+
this.protectionLayer.incrementRequest();
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Track completed request
|
|
123
|
+
*/
|
|
124
|
+
trackRequestComplete() {
|
|
125
|
+
this.protectionLayer.decrementRequest();
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get protection layer instance
|
|
129
|
+
*/
|
|
130
|
+
getProtectionLayer() {
|
|
131
|
+
return this.protectionLayer;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get heuristic engine instance
|
|
135
|
+
*/
|
|
136
|
+
getHeuristicEngine() {
|
|
137
|
+
return this.heuristicEngine;
|
|
138
|
+
}
|
|
139
|
+
setupMonitorEvents() {
|
|
140
|
+
// Forward warnings from monitors
|
|
141
|
+
this.eventLoopMonitor.on('warning', (warning) => {
|
|
142
|
+
this.emit('warning', warning);
|
|
143
|
+
this.emit('eventLoopBlocked', warning);
|
|
144
|
+
});
|
|
145
|
+
this.memoryMonitor.on('warning', (warning) => {
|
|
146
|
+
this.emit('warning', warning);
|
|
147
|
+
if (warning.type === 'memoryDrift') {
|
|
148
|
+
this.emit('memoryDrift', warning);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
this.threadPoolMonitor.on('warning', (warning) => {
|
|
152
|
+
this.emit('warning', warning);
|
|
153
|
+
this.emit('threadPoolSaturated', warning);
|
|
154
|
+
});
|
|
155
|
+
this.gcMonitor.on('warning', (warning) => {
|
|
156
|
+
this.emit('warning', warning);
|
|
157
|
+
this.emit('gcPressure', warning);
|
|
158
|
+
});
|
|
159
|
+
// Forward heuristic engine events
|
|
160
|
+
this.heuristicEngine.on('anomaly', (data) => {
|
|
161
|
+
this.emit('anomaly', data);
|
|
162
|
+
});
|
|
163
|
+
this.heuristicEngine.on('trend', (data) => {
|
|
164
|
+
this.emit('trend', data);
|
|
165
|
+
});
|
|
166
|
+
// Forward protection layer events
|
|
167
|
+
this.protectionLayer.on('protectionActivated', (data) => {
|
|
168
|
+
this.emit('protectionActivated', data);
|
|
169
|
+
});
|
|
170
|
+
this.protectionLayer.on('protectionDeactivated', (data) => {
|
|
171
|
+
this.emit('protectionDeactivated', data);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
collectAggregatedMetrics() {
|
|
175
|
+
const metrics = this.getMetrics();
|
|
176
|
+
// Process metrics through heuristic engine
|
|
177
|
+
this.heuristicEngine.processMetrics(metrics);
|
|
178
|
+
// Evaluate protection
|
|
179
|
+
this.protectionLayer.evaluateProtection(metrics);
|
|
180
|
+
// Emit aggregated metrics
|
|
181
|
+
this.emit('metric', metrics);
|
|
182
|
+
}
|
|
183
|
+
getCPUMetrics() {
|
|
184
|
+
const currentCPU = process.cpuUsage();
|
|
185
|
+
const userDelta = currentCPU.user - this.lastCPUTime.user;
|
|
186
|
+
const systemDelta = currentCPU.system - this.lastCPUTime.system;
|
|
187
|
+
this.lastCPUTime = currentCPU;
|
|
188
|
+
// Convert from microseconds to milliseconds
|
|
189
|
+
return {
|
|
190
|
+
user: userDelta / 1000,
|
|
191
|
+
system: systemDelta / 1000,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exports.Guardian = Guardian;
|
|
196
|
+
//# sourceMappingURL=Guardian.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Guardian.js","sourceRoot":"","sources":["../../src/core/Guardian.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AAEtC,yDAAsD;AACtD,mDAAgD;AAChD,2DAAwD;AACxD,2CAAwC;AACxC,uDAAoD;AACpD,uDAAoD;AAEpD;;GAEG;AACH,MAAa,QAAS,SAAQ,qBAAY;IAYxC,YAAY,SAAyB,EAAE;QACrC,KAAK,EAAE,CAAC;QALF,cAAS,GAAG,KAAK,CAAC;QAClB,oBAAe,GAA0B,IAAI,CAAC;QAC9C,gBAAW,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;QAIvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,sBAAsB;QACtB,IAAI,CAAC,gBAAgB,GAAG,IAAI,mCAAgB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC/D,IAAI,CAAC,aAAa,GAAG,IAAI,6BAAa,CAAC,MAAM,CAAC,MAAM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AAC;QACtC,MAAM,SAAS,GAAG,UAAU,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAC1D,MAAM,WAAW,GAAG,UAAU,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;QAChE,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAE9B,4CAA4C;QAC5C,OAAO;YACL,IAAI,EAAE,SAAS,GAAG,IAAI;YACtB,MAAM,EAAE,WAAW,GAAG,IAAI;SAC3B,CAAC;IACJ,CAAC;CACF;AAhOD,4BAgOC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { RuntimeMetrics } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Heuristic engine for pattern detection and anomaly detection
|
|
6
|
+
*/
|
|
7
|
+
export declare class HeuristicEngine extends EventEmitter {
|
|
8
|
+
private metricsHistory;
|
|
9
|
+
private readonly maxHistorySize;
|
|
10
|
+
/**
|
|
11
|
+
* Process new metrics and detect patterns
|
|
12
|
+
*/
|
|
13
|
+
processMetrics(metrics: RuntimeMetrics): void;
|
|
14
|
+
/**
|
|
15
|
+
* Detect anomalies in current metrics
|
|
16
|
+
*/
|
|
17
|
+
private detectAnomalies;
|
|
18
|
+
/**
|
|
19
|
+
* Detect trends across metrics
|
|
20
|
+
*/
|
|
21
|
+
private detectTrends;
|
|
22
|
+
/**
|
|
23
|
+
* Get current health score (0-1, where 1 is healthy)
|
|
24
|
+
*/
|
|
25
|
+
getHealthScore(): number;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=HeuristicEngine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HeuristicEngine.d.ts","sourceRoot":"","sources":["../../src/core/HeuristicEngine.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C;;GAEG;AACH,qBAAa,eAAgB,SAAQ,YAAY;IAC/C,OAAO,CAAC,cAAc,CAAwB;IAC9C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAO;IAEtC;;OAEG;IACH,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IAa7C;;OAEG;IACH,OAAO,CAAC,eAAe;IA0CvB;;OAEG;IACH,OAAO,CAAC,YAAY;IA0DpB;;OAEG;IACH,cAAc,IAAI,MAAM;CAyCzB"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HeuristicEngine = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
/**
|
|
6
|
+
* Heuristic engine for pattern detection and anomaly detection
|
|
7
|
+
*/
|
|
8
|
+
class HeuristicEngine extends events_1.EventEmitter {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.metricsHistory = [];
|
|
12
|
+
this.maxHistorySize = 100;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Process new metrics and detect patterns
|
|
16
|
+
*/
|
|
17
|
+
processMetrics(metrics) {
|
|
18
|
+
this.metricsHistory.push(metrics);
|
|
19
|
+
if (this.metricsHistory.length > this.maxHistorySize) {
|
|
20
|
+
this.metricsHistory.shift();
|
|
21
|
+
}
|
|
22
|
+
// Detect anomalies
|
|
23
|
+
this.detectAnomalies(metrics);
|
|
24
|
+
// Detect trends
|
|
25
|
+
this.detectTrends();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Detect anomalies in current metrics
|
|
29
|
+
*/
|
|
30
|
+
detectAnomalies(metrics) {
|
|
31
|
+
if (this.metricsHistory.length < 5) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// Anomaly: Sudden spike in event loop delay
|
|
35
|
+
const recentDelays = this.metricsHistory
|
|
36
|
+
.slice(-5)
|
|
37
|
+
.map((m) => m.eventLoopDelay.mean);
|
|
38
|
+
const avgDelay = recentDelays.reduce((a, b) => a + b, 0) / recentDelays.length;
|
|
39
|
+
const currentDelay = metrics.eventLoopDelay.mean;
|
|
40
|
+
if (currentDelay > avgDelay * 3 && currentDelay > 50) {
|
|
41
|
+
this.emit('anomaly', {
|
|
42
|
+
type: 'eventLoopSpike',
|
|
43
|
+
message: `Sudden event loop delay spike: ${currentDelay.toFixed(2)}ms (avg: ${avgDelay.toFixed(2)}ms)`,
|
|
44
|
+
metrics,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
// Anomaly: Sudden memory increase
|
|
48
|
+
const recentMemory = this.metricsHistory
|
|
49
|
+
.slice(-5)
|
|
50
|
+
.map((m) => m.memory.heapUsed);
|
|
51
|
+
const avgMemory = recentMemory.reduce((a, b) => a + b, 0) / recentMemory.length;
|
|
52
|
+
const currentMemory = metrics.memory.heapUsed;
|
|
53
|
+
if (currentMemory > avgMemory * 1.5 &&
|
|
54
|
+
currentMemory - avgMemory > 50 * 1024 * 1024) {
|
|
55
|
+
// 50MB increase
|
|
56
|
+
this.emit('anomaly', {
|
|
57
|
+
type: 'memorySpike',
|
|
58
|
+
message: `Sudden memory increase: ${(currentMemory / 1024 / 1024).toFixed(2)}MB (avg: ${(avgMemory / 1024 / 1024).toFixed(2)}MB)`,
|
|
59
|
+
metrics,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Detect trends across metrics
|
|
65
|
+
*/
|
|
66
|
+
detectTrends() {
|
|
67
|
+
if (this.metricsHistory.length < 20) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const recent = this.metricsHistory.slice(-10);
|
|
71
|
+
const older = this.metricsHistory.slice(-20, -10);
|
|
72
|
+
if (older.length === 0) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
// Trend: Increasing event loop delay
|
|
76
|
+
const recentAvgDelay = recent.reduce((sum, m) => sum + m.eventLoopDelay.mean, 0) / recent.length;
|
|
77
|
+
const olderAvgDelay = older.reduce((sum, m) => sum + m.eventLoopDelay.mean, 0) / older.length;
|
|
78
|
+
if (recentAvgDelay > olderAvgDelay * 1.5 && recentAvgDelay > 10) {
|
|
79
|
+
this.emit('trend', {
|
|
80
|
+
type: 'increasingEventLoopDelay',
|
|
81
|
+
message: `Event loop delay trending upward: ${recentAvgDelay.toFixed(2)}ms (was: ${olderAvgDelay.toFixed(2)}ms)`,
|
|
82
|
+
severity: 'medium',
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
// Trend: Increasing memory usage
|
|
86
|
+
const recentAvgMemory = recent.reduce((sum, m) => sum + m.memory.heapUsed, 0) / recent.length;
|
|
87
|
+
const olderAvgMemory = older.reduce((sum, m) => sum + m.memory.heapUsed, 0) / older.length;
|
|
88
|
+
if (recentAvgMemory > olderAvgMemory * 1.2) {
|
|
89
|
+
this.emit('trend', {
|
|
90
|
+
type: 'increasingMemory',
|
|
91
|
+
message: `Memory usage trending upward: ${(recentAvgMemory / 1024 / 1024).toFixed(2)}MB (was: ${(olderAvgMemory / 1024 / 1024).toFixed(2)}MB)`,
|
|
92
|
+
severity: 'medium',
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
// Trend: Increasing GC pressure
|
|
96
|
+
const recentAvgGCPressure = recent.reduce((sum, m) => sum + m.gc.gcPressure, 0) / recent.length;
|
|
97
|
+
const olderAvgGCPressure = older.reduce((sum, m) => sum + m.gc.gcPressure, 0) / older.length;
|
|
98
|
+
if (recentAvgGCPressure > olderAvgGCPressure * 1.3 &&
|
|
99
|
+
recentAvgGCPressure > 0.5) {
|
|
100
|
+
this.emit('trend', {
|
|
101
|
+
type: 'increasingGCPressure',
|
|
102
|
+
message: `GC pressure trending upward: ${(recentAvgGCPressure * 100).toFixed(2)}% (was: ${(olderAvgGCPressure * 100).toFixed(2)}%)`,
|
|
103
|
+
severity: 'high',
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get current health score (0-1, where 1 is healthy)
|
|
109
|
+
*/
|
|
110
|
+
getHealthScore() {
|
|
111
|
+
if (this.metricsHistory.length === 0) {
|
|
112
|
+
return 1;
|
|
113
|
+
}
|
|
114
|
+
const latest = this.metricsHistory[this.metricsHistory.length - 1];
|
|
115
|
+
// Calculate health based on various factors
|
|
116
|
+
let score = 1.0;
|
|
117
|
+
// Event loop delay penalty
|
|
118
|
+
if (latest.eventLoopDelay.mean > 100) {
|
|
119
|
+
score -= 0.3;
|
|
120
|
+
}
|
|
121
|
+
else if (latest.eventLoopDelay.mean > 50) {
|
|
122
|
+
score -= 0.15;
|
|
123
|
+
}
|
|
124
|
+
// Memory pressure penalty
|
|
125
|
+
const memoryUsageRatio = latest.memory.heapUsed / latest.memory.heapTotal;
|
|
126
|
+
if (memoryUsageRatio > 0.9) {
|
|
127
|
+
score -= 0.3;
|
|
128
|
+
}
|
|
129
|
+
else if (memoryUsageRatio > 0.8) {
|
|
130
|
+
score -= 0.15;
|
|
131
|
+
}
|
|
132
|
+
// GC pressure penalty
|
|
133
|
+
if (latest.gc.gcPressure > 0.8) {
|
|
134
|
+
score -= 0.2;
|
|
135
|
+
}
|
|
136
|
+
else if (latest.gc.gcPressure > 0.6) {
|
|
137
|
+
score -= 0.1;
|
|
138
|
+
}
|
|
139
|
+
// Thread pool saturation penalty
|
|
140
|
+
if (latest.threadPool.saturationLevel > 0.9) {
|
|
141
|
+
score -= 0.2;
|
|
142
|
+
}
|
|
143
|
+
else if (latest.threadPool.saturationLevel > 0.7) {
|
|
144
|
+
score -= 0.1;
|
|
145
|
+
}
|
|
146
|
+
return Math.max(0, Math.min(1, score));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.HeuristicEngine = HeuristicEngine;
|
|
150
|
+
//# sourceMappingURL=HeuristicEngine.js.map
|
|
@@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AAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IACzC,CAAC;CACF;AA1KD,0CA0KC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { MemoryConfig, MemoryMetrics, MemoryDrift } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Monitors memory usage and detects drift patterns
|
|
6
|
+
*/
|
|
7
|
+
export declare class MemoryMonitor extends EventEmitter {
|
|
8
|
+
private interval;
|
|
9
|
+
private config;
|
|
10
|
+
private isRunning;
|
|
11
|
+
private history;
|
|
12
|
+
private readonly maxHistorySize;
|
|
13
|
+
constructor(config?: MemoryConfig);
|
|
14
|
+
/**
|
|
15
|
+
* Start monitoring memory
|
|
16
|
+
*/
|
|
17
|
+
start(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Stop monitoring
|
|
20
|
+
*/
|
|
21
|
+
stop(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Get current memory metrics
|
|
24
|
+
*/
|
|
25
|
+
getMetrics(): MemoryMetrics;
|
|
26
|
+
/**
|
|
27
|
+
* Detect memory drift patterns
|
|
28
|
+
*/
|
|
29
|
+
detectDrift(): MemoryDrift | null;
|
|
30
|
+
private collectMetrics;
|
|
31
|
+
private emitWarning;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=MemoryMonitor.d.ts.map
|