-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
160 lines (142 loc) · 3.87 KB
/
Copy pathindex.d.ts
File metadata and controls
160 lines (142 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import { RequestHandler } from 'express';
export interface Percentiles {
p50: number;
p90: number;
p95: number;
p99: number;
}
export interface RouteMetric {
count: number;
avgDuration: number;
minDuration: number;
maxDuration: number;
percentiles: Percentiles;
}
export interface RequestEntry {
id: string;
timestamp: string;
method: string;
url: string;
status: number;
durationMs: number;
headers: Record<string, string | string[]>;
ip?: string;
curl?: string;
slowThresholdMs?: number;
}
export interface AlertTrigger {
type: 'ERROR_RATE_EXCEEDED' | 'MEMORY_LIMIT_EXCEEDED' | 'LATENCY_THRESHOLD_EXCEEDED';
message: string;
metric: string;
value: number;
threshold: number;
timestamp: string;
}
export interface AlertOptions {
/** Error rate percentage threshold (0-100) to trigger alert */
errorRateThreshold?: number;
/** RSS memory threshold in MB to trigger alert */
memoryThresholdMb?: number;
/** Average response latency threshold in ms to trigger alert */
avgDurationThresholdMs?: number;
/** Alert callback function */
onAlert?: (alert: AlertTrigger) => void;
}
export interface ExpressLensOptions {
/** Enable/disable console analytics logging (default: true) */
logAnalytics?: boolean;
/** Batched logging interval in milliseconds (default: 0 for real-time logging) */
logInterval?: number;
/** Enable ANSI colors in console log output (default: true) */
colorize?: boolean;
/** Array of string prefixes or RegExps to exclude from metric collection */
ignoreRoutes?: (string | RegExp)[];
/** Slow request threshold in ms to log/buffer slow endpoints (default: 500ms) */
slowThresholdMs?: number;
/** Custom header names to redact in logs and dashboard */
redactHeaders?: string[];
/** Threshold alert configuration */
alerts?: AlertOptions;
}
export interface ExpressLensMetrics {
totalRequests: number;
totalErrors: number;
errorRate: string;
avgDurationMs: number;
percentiles: Percentiles;
statusCodes: Record<number, number>;
methods: Record<string, number>;
routes: Record<string, RouteMetric>;
recentErrors: RequestEntry[];
slowRequests: RequestEntry[];
system: {
uptime: number;
memory: {
heapTotal: number;
heapUsed: number;
rss: number;
external: number;
};
system: {
totalMem: number;
freeMem: number;
cpus: number;
loadavg: number[];
};
};
}
/**
* Express Lens Middleware Factory
*/
export default function monitor(options?: ExpressLensOptions): RequestHandler;
/**
* Get a JSON snapshot of all current metrics.
*/
export function getMetrics(): ExpressLensMetrics;
/**
* Calculate percentiles (p50, p90, p95, p99) from latency samples.
*/
export function getPercentiles(samples?: number[]): Percentiles;
/**
* Reset all stored metrics to initial state.
*/
export function resetMetrics(): void;
/**
* Express handler to serve metrics JSON over HTTP.
*/
export function metricsHandler(): RequestHandler;
/**
* Get metrics in Prometheus exposition text format.
*/
export function getPrometheusMetrics(): string;
/**
* Express handler to serve Prometheus format metrics at /metrics.
*/
export function prometheusHandler(): RequestHandler;
/**
* Express handler to serve embedded real-time web dashboard & SSE events stream.
*/
export function dashboardHandler(): RequestHandler;
/**
* Export captured requests as standard HAR 1.2 JSON object.
*/
export function exportHAR(title?: string): object;
/**
* Replay a captured request by ID.
*/
export function replayRequest(requestId: string, fetchFn?: typeof fetch): Promise<{
success: boolean;
status?: number;
durationMs?: number;
error?: string;
originalRequestId: string;
}>;
/**
* Generate cURL command string for a request.
*/
export function generateCurl(req: {
method?: string;
url?: string;
headers?: Record<string, any>;
body?: any;
}): string;