hono-status-monitor 1.0.1 → 1.0.2
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/README.md +56 -2
- package/dist/dashboard.d.ts +13 -0
- package/dist/dashboard.d.ts.map +1 -1
- package/dist/dashboard.js +391 -0
- package/dist/dashboard.js.map +1 -1
- package/dist/index.d.ts +51 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +121 -13
- package/dist/index.js.map +1 -1
- package/dist/monitor-edge.d.ts +21 -0
- package/dist/monitor-edge.d.ts.map +1 -0
- package/dist/monitor-edge.js +376 -0
- package/dist/monitor-edge.js.map +1 -0
- package/dist/platform.d.ts +33 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +80 -0
- package/dist/platform.js.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
// =============================================================================
|
|
2
2
|
// HONO STATUS MONITOR
|
|
3
3
|
// Real-time server monitoring dashboard for Hono.js with WebSocket updates
|
|
4
|
+
// Supports Node.js and Cloudflare Workers/Edge environments
|
|
4
5
|
// =============================================================================
|
|
5
6
|
import { Hono } from 'hono';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { generateDashboard } from './dashboard.js';
|
|
7
|
+
import { detectPlatform } from './platform.js';
|
|
8
|
+
import { createEdgeMonitor } from './monitor-edge.js';
|
|
9
|
+
import { generateDashboard, generateEdgeDashboard } from './dashboard.js';
|
|
9
10
|
// Re-export types
|
|
10
11
|
export * from './types.js';
|
|
12
|
+
export { generateDashboard, generateEdgeDashboard } from './dashboard.js';
|
|
13
|
+
export { createEdgeMonitor } from './monitor-edge.js';
|
|
14
|
+
export { detectPlatform, isNodeEnvironment, isCloudflareEnvironment, isEdgeEnvironment, getPlatformInfo } from './platform.js';
|
|
15
|
+
// Conditionally export Node.js-specific modules
|
|
16
|
+
// These will throw errors if imported in edge environments
|
|
11
17
|
export { createMonitor } from './monitor.js';
|
|
12
18
|
export { createMiddleware } from './middleware.js';
|
|
13
|
-
export { generateDashboard } from './dashboard.js';
|
|
14
19
|
export { isClusterWorker, isClusterMaster, getWorkerId, createClusterAggregator } from './cluster.js';
|
|
15
20
|
/**
|
|
16
21
|
* Create a complete status monitor with routes, middleware, and WebSocket
|
|
22
|
+
* Automatically detects the runtime environment and uses the appropriate implementation
|
|
17
23
|
*
|
|
18
|
-
* @example
|
|
24
|
+
* @example Node.js
|
|
19
25
|
* ```typescript
|
|
20
26
|
* import { Hono } from 'hono';
|
|
21
27
|
* import { serve } from '@hono/node-server';
|
|
@@ -24,23 +30,50 @@ export { isClusterWorker, isClusterMaster, getWorkerId, createClusterAggregator
|
|
|
24
30
|
* const app = new Hono();
|
|
25
31
|
* const monitor = statusMonitor();
|
|
26
32
|
*
|
|
27
|
-
* // Add middleware to track all requests
|
|
28
33
|
* app.use('*', monitor.middleware);
|
|
29
|
-
*
|
|
30
|
-
* // Mount status routes
|
|
31
34
|
* app.route('/status', monitor.routes);
|
|
32
35
|
*
|
|
33
|
-
* // Start server and initialize WebSocket
|
|
34
36
|
* const server = serve({ fetch: app.fetch, port: 3000 });
|
|
35
37
|
* monitor.initSocket(server);
|
|
36
38
|
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example Cloudflare Workers
|
|
41
|
+
* ```typescript
|
|
42
|
+
* import { Hono } from 'hono';
|
|
43
|
+
* import { statusMonitor } from 'hono-status-monitor';
|
|
44
|
+
*
|
|
45
|
+
* const app = new Hono();
|
|
46
|
+
* const monitor = statusMonitor();
|
|
47
|
+
*
|
|
48
|
+
* app.use('*', monitor.middleware);
|
|
49
|
+
* app.route('/status', monitor.routes);
|
|
50
|
+
*
|
|
51
|
+
* export default app;
|
|
52
|
+
* ```
|
|
37
53
|
*/
|
|
38
54
|
export function statusMonitor(config = {}) {
|
|
39
|
-
//
|
|
55
|
+
// Force platform check if specified in config
|
|
56
|
+
const platform = detectPlatform();
|
|
57
|
+
const useNodeVersion = platform === 'node';
|
|
58
|
+
if (useNodeVersion) {
|
|
59
|
+
// Node.js version with full features
|
|
60
|
+
return createNodeStatusMonitor(config);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
// Edge/Cloudflare version with limited features
|
|
64
|
+
return createEdgeStatusMonitor(config);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Create a Node.js status monitor with full features
|
|
69
|
+
* Requires Node.js runtime with os, process, http modules
|
|
70
|
+
*/
|
|
71
|
+
function createNodeStatusMonitor(config = {}) {
|
|
72
|
+
// Dynamic import to avoid loading Node.js modules in edge
|
|
73
|
+
const { createMonitor } = require('./monitor.js');
|
|
74
|
+
const { createMiddleware } = require('./middleware.js');
|
|
40
75
|
const monitor = createMonitor(config);
|
|
41
|
-
// Create middleware
|
|
42
76
|
const middleware = createMiddleware(monitor);
|
|
43
|
-
// Create Hono routes
|
|
44
77
|
const routes = new Hono();
|
|
45
78
|
// Dashboard page
|
|
46
79
|
routes.get('/', async (c) => {
|
|
@@ -78,8 +111,83 @@ export function statusMonitor(config = {}) {
|
|
|
78
111
|
/** Stop metrics collection */
|
|
79
112
|
stop: () => monitor.stop(),
|
|
80
113
|
/** Access to the underlying monitor instance */
|
|
81
|
-
monitor
|
|
114
|
+
monitor,
|
|
115
|
+
/** Whether running in edge mode */
|
|
116
|
+
isEdgeMode: false
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Create an edge-compatible status monitor with limited features
|
|
121
|
+
* Works in Cloudflare Workers, Vercel Edge, and other edge runtimes
|
|
122
|
+
*/
|
|
123
|
+
function createEdgeStatusMonitor(config = {}) {
|
|
124
|
+
const monitor = createEdgeMonitor(config);
|
|
125
|
+
const routes = new Hono();
|
|
126
|
+
// Create middleware for edge
|
|
127
|
+
const middleware = async (c, next) => {
|
|
128
|
+
const path = new URL(c.req.url).pathname;
|
|
129
|
+
const method = c.req.method;
|
|
130
|
+
// Skip status route itself
|
|
131
|
+
if (path.startsWith(config.path || '/status')) {
|
|
132
|
+
return next();
|
|
133
|
+
}
|
|
134
|
+
const start = performance.now();
|
|
135
|
+
monitor.trackRequest(path, method);
|
|
136
|
+
try {
|
|
137
|
+
await next();
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
const duration = performance.now() - start;
|
|
141
|
+
const status = c.res?.status || 200;
|
|
142
|
+
monitor.trackRequestComplete(path, method, duration, status);
|
|
143
|
+
}
|
|
82
144
|
};
|
|
145
|
+
// Dashboard page - uses polling mode
|
|
146
|
+
routes.get('/', async (c) => {
|
|
147
|
+
const snapshot = await monitor.getMetricsSnapshot();
|
|
148
|
+
const html = generateEdgeDashboard({
|
|
149
|
+
hostname: snapshot.hostname,
|
|
150
|
+
uptime: monitor.formatUptime(snapshot.uptime),
|
|
151
|
+
title: monitor.config.title
|
|
152
|
+
});
|
|
153
|
+
return c.html(html);
|
|
154
|
+
});
|
|
155
|
+
// JSON API endpoint
|
|
156
|
+
routes.get('/api/metrics', async (c) => {
|
|
157
|
+
return c.json({
|
|
158
|
+
snapshot: await monitor.getMetricsSnapshot(),
|
|
159
|
+
charts: monitor.getChartData()
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
// Start (no-op in edge mode)
|
|
163
|
+
monitor.start();
|
|
164
|
+
return {
|
|
165
|
+
/** Hono middleware for tracking all requests */
|
|
166
|
+
middleware,
|
|
167
|
+
/** Pre-configured Hono routes for dashboard and API */
|
|
168
|
+
routes,
|
|
169
|
+
/** Initialize Socket.io - not available in edge, returns null */
|
|
170
|
+
initSocket: () => null,
|
|
171
|
+
/** Track rate limit events for the dashboard */
|
|
172
|
+
trackRateLimit: (blocked) => monitor.trackRateLimitEvent(blocked),
|
|
173
|
+
/** Get current metrics snapshot */
|
|
174
|
+
getMetrics: () => monitor.getMetricsSnapshot(),
|
|
175
|
+
/** Get chart data for all metrics */
|
|
176
|
+
getCharts: () => monitor.getChartData(),
|
|
177
|
+
/** Stop metrics collection */
|
|
178
|
+
stop: () => monitor.stop(),
|
|
179
|
+
/** Access to the underlying monitor instance */
|
|
180
|
+
monitor,
|
|
181
|
+
/** Whether running in edge mode */
|
|
182
|
+
isEdgeMode: true
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Explicitly create an edge-compatible status monitor
|
|
187
|
+
* Use this when you want to force edge mode regardless of environment
|
|
188
|
+
*/
|
|
189
|
+
export function statusMonitorEdge(config = {}) {
|
|
190
|
+
return createEdgeStatusMonitor(config);
|
|
83
191
|
}
|
|
84
192
|
// Default export
|
|
85
193
|
export default statusMonitor;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,sBAAsB;AACtB,2EAA2E;AAC3E,gFAAgF;AAEhF,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,sBAAsB;AACtB,2EAA2E;AAC3E,4DAA4D;AAC5D,gFAAgF;AAEhF,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,OAAO,EAAqB,cAAc,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAE1E,kBAAkB;AAClB,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAoB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EACH,cAAc,EAC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type { StatusMonitorConfig, MetricsSnapshot, ChartData } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create an edge-compatible status monitor instance
|
|
4
|
+
* Works without Node.js APIs (os, process, cluster)
|
|
5
|
+
*/
|
|
6
|
+
export declare function createEdgeMonitor(userConfig?: StatusMonitorConfig): {
|
|
7
|
+
config: Required<StatusMonitorConfig>;
|
|
8
|
+
trackRequest: (path: string, method: string) => void;
|
|
9
|
+
trackRequestComplete: (path: string, method: string, durationMs: number, statusCode: number) => void;
|
|
10
|
+
trackRateLimitEvent: (blocked: boolean) => void;
|
|
11
|
+
getMetricsSnapshot: () => Promise<MetricsSnapshot>;
|
|
12
|
+
getChartData: () => ChartData;
|
|
13
|
+
start: () => void;
|
|
14
|
+
stop: () => void;
|
|
15
|
+
initSocket: () => null;
|
|
16
|
+
formatUptime: (seconds: number) => string;
|
|
17
|
+
isEdgeMode: boolean;
|
|
18
|
+
readonly io: null;
|
|
19
|
+
};
|
|
20
|
+
export type EdgeMonitor = ReturnType<typeof createEdgeMonitor>;
|
|
21
|
+
//# sourceMappingURL=monitor-edge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monitor-edge.d.ts","sourceRoot":"","sources":["../src/monitor-edge.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACR,mBAAmB,EAOnB,eAAe,EACf,SAAS,EACZ,MAAM,YAAY,CAAC;AAkCpB;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,GAAE,mBAAwB;;yBAyKtC,MAAM,UAAU,MAAM,KAAG,IAAI;iCA2B/C,MAAM,UACJ,MAAM,cACF,MAAM,cACN,MAAM,KACnB,IAAI;mCAkD+B,OAAO,KAAG,IAAI;8BAQf,OAAO,CAAC,eAAe,CAAC;wBAgEpC,SAAS;iBAgChB,IAAI;gBAKL,IAAI;sBAME,IAAI;4BA3BI,MAAM,KAAG,MAAM;;;EA8CjD;AAED,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// HONO STATUS MONITOR - EDGE-COMPATIBLE MONITOR
|
|
3
|
+
// Lightweight monitor for Cloudflare Workers and Edge environments
|
|
4
|
+
// No Node.js-specific APIs (os, process, cluster, socket.io)
|
|
5
|
+
// =============================================================================
|
|
6
|
+
// Default configuration for edge environments
|
|
7
|
+
const DEFAULT_EDGE_CONFIG = {
|
|
8
|
+
path: '/status',
|
|
9
|
+
title: 'Server Status',
|
|
10
|
+
socketPath: '/status/socket.io', // Not used in edge, included for compatibility
|
|
11
|
+
updateInterval: 5000, // Polling interval (not real-time)
|
|
12
|
+
retentionSeconds: 60,
|
|
13
|
+
maxRecentErrors: 10,
|
|
14
|
+
maxRoutes: 10,
|
|
15
|
+
alerts: {
|
|
16
|
+
cpu: 80, // Not available in edge
|
|
17
|
+
memory: 90, // Not available in edge
|
|
18
|
+
responseTime: 500,
|
|
19
|
+
errorRate: 5,
|
|
20
|
+
eventLoopLag: 100 // Not available in edge
|
|
21
|
+
},
|
|
22
|
+
healthCheck: async () => ({ connected: true, latencyMs: 0 }),
|
|
23
|
+
normalizePath: (path) => path,
|
|
24
|
+
clusterMode: false // Not supported in edge
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Default path normalization function
|
|
28
|
+
*/
|
|
29
|
+
function defaultNormalizePath(path) {
|
|
30
|
+
return path
|
|
31
|
+
.replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi, ':uuid')
|
|
32
|
+
.replace(/[0-9a-f]{24}/gi, ':id')
|
|
33
|
+
.replace(/\/\d+/g, '/:id')
|
|
34
|
+
.split('/').slice(0, 4).join('/');
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create an edge-compatible status monitor instance
|
|
38
|
+
* Works without Node.js APIs (os, process, cluster)
|
|
39
|
+
*/
|
|
40
|
+
export function createEdgeMonitor(userConfig = {}) {
|
|
41
|
+
// Merge configuration
|
|
42
|
+
const config = {
|
|
43
|
+
...DEFAULT_EDGE_CONFIG,
|
|
44
|
+
...userConfig,
|
|
45
|
+
alerts: { ...DEFAULT_EDGE_CONFIG.alerts, ...userConfig.alerts },
|
|
46
|
+
normalizePath: userConfig.normalizePath || defaultNormalizePath,
|
|
47
|
+
clusterMode: false // Never in cluster mode on edge
|
|
48
|
+
};
|
|
49
|
+
// In-memory metrics storage
|
|
50
|
+
let responseTimeHistory = [];
|
|
51
|
+
let rpsHistory = [];
|
|
52
|
+
let errorRateHistory = [];
|
|
53
|
+
// Request tracking
|
|
54
|
+
let requestCount = 0;
|
|
55
|
+
let lastRequestCount = 0;
|
|
56
|
+
let lastUpdateTime = Date.now();
|
|
57
|
+
let totalResponseTime = 0;
|
|
58
|
+
let responseTimeCount = 0;
|
|
59
|
+
let statusCodes = {};
|
|
60
|
+
let totalRequests = 0;
|
|
61
|
+
let activeConnections = 0;
|
|
62
|
+
// Route tracking
|
|
63
|
+
const routeStats = new Map();
|
|
64
|
+
const recentErrors = [];
|
|
65
|
+
// Response time samples for percentiles
|
|
66
|
+
let responseTimeSamples = [];
|
|
67
|
+
// Rate limit tracking
|
|
68
|
+
let rateLimitBlocked = 0;
|
|
69
|
+
let rateLimitTotal = 0;
|
|
70
|
+
// Start time for uptime calculation
|
|
71
|
+
const startTime = Date.now();
|
|
72
|
+
/**
|
|
73
|
+
* Calculate percentiles from samples
|
|
74
|
+
*/
|
|
75
|
+
function calculatePercentiles() {
|
|
76
|
+
if (responseTimeSamples.length === 0) {
|
|
77
|
+
return { p50: 0, p95: 0, p99: 0, avg: 0 };
|
|
78
|
+
}
|
|
79
|
+
const sorted = [...responseTimeSamples].sort((a, b) => a - b);
|
|
80
|
+
const len = sorted.length;
|
|
81
|
+
const p50Index = Math.floor(len * 0.5);
|
|
82
|
+
const p95Index = Math.floor(len * 0.95);
|
|
83
|
+
const p99Index = Math.floor(len * 0.99);
|
|
84
|
+
const avg = sorted.reduce((a, b) => a + b, 0) / len;
|
|
85
|
+
return {
|
|
86
|
+
p50: Math.round(sorted[p50Index] * 100) / 100,
|
|
87
|
+
p95: Math.round(sorted[p95Index] * 100) / 100,
|
|
88
|
+
p99: Math.round(sorted[Math.min(p99Index, len - 1)] * 100) / 100,
|
|
89
|
+
avg: Math.round(avg * 100) / 100
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get top routes by request count
|
|
94
|
+
*/
|
|
95
|
+
function getTopRoutes() {
|
|
96
|
+
return Array.from(routeStats.values())
|
|
97
|
+
.sort((a, b) => b.count - a.count)
|
|
98
|
+
.slice(0, config.maxRoutes);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get slowest routes by average response time
|
|
102
|
+
*/
|
|
103
|
+
function getSlowestRoutes() {
|
|
104
|
+
return Array.from(routeStats.values())
|
|
105
|
+
.filter(r => r.count > 0)
|
|
106
|
+
.sort((a, b) => b.avgTime - a.avgTime)
|
|
107
|
+
.slice(0, config.maxRoutes);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get routes with most errors
|
|
111
|
+
*/
|
|
112
|
+
function getErrorRoutes() {
|
|
113
|
+
return Array.from(routeStats.values())
|
|
114
|
+
.filter(r => r.errors > 0)
|
|
115
|
+
.sort((a, b) => b.errors - a.errors)
|
|
116
|
+
.slice(0, config.maxRoutes);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Calculate current error rate
|
|
120
|
+
*/
|
|
121
|
+
function getErrorRate() {
|
|
122
|
+
const totalErrors = Array.from(routeStats.values()).reduce((sum, r) => sum + r.errors, 0);
|
|
123
|
+
if (totalRequests === 0)
|
|
124
|
+
return 0;
|
|
125
|
+
return Math.round((totalErrors / totalRequests) * 10000) / 100;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Check alert conditions (limited to available metrics)
|
|
129
|
+
*/
|
|
130
|
+
function checkAlerts() {
|
|
131
|
+
const respTime = responseTimeHistory.length > 0
|
|
132
|
+
? responseTimeHistory[responseTimeHistory.length - 1].value
|
|
133
|
+
: 0;
|
|
134
|
+
const errorRate = getErrorRate();
|
|
135
|
+
return {
|
|
136
|
+
cpu: false, // Not available in edge
|
|
137
|
+
memory: false, // Not available in edge
|
|
138
|
+
responseTime: respTime > (config.alerts.responseTime ?? 500),
|
|
139
|
+
errorRate: errorRate > (config.alerts.errorRate ?? 5),
|
|
140
|
+
eventLoopLag: false // Not available in edge
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Add a data point to history
|
|
145
|
+
*/
|
|
146
|
+
function addToHistory(history, value) {
|
|
147
|
+
const now = Date.now();
|
|
148
|
+
history.push({ timestamp: now, value });
|
|
149
|
+
const cutoff = now - (config.retentionSeconds * 1000);
|
|
150
|
+
while (history.length > 0 && history[0].timestamp < cutoff) {
|
|
151
|
+
history.shift();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Update metrics (called on each request in edge mode, not on interval)
|
|
156
|
+
*/
|
|
157
|
+
function updateMetricsIfNeeded() {
|
|
158
|
+
const now = Date.now();
|
|
159
|
+
const elapsed = now - lastUpdateTime;
|
|
160
|
+
// Only update history at configured intervals
|
|
161
|
+
if (elapsed >= config.updateInterval) {
|
|
162
|
+
const intervalSeconds = elapsed / 1000;
|
|
163
|
+
const currentRps = Math.round((requestCount - lastRequestCount) / intervalSeconds);
|
|
164
|
+
lastRequestCount = requestCount;
|
|
165
|
+
lastUpdateTime = now;
|
|
166
|
+
addToHistory(rpsHistory, currentRps);
|
|
167
|
+
const avgResponseTime = responseTimeCount > 0
|
|
168
|
+
? Math.round((totalResponseTime / responseTimeCount) * 100) / 100
|
|
169
|
+
: 0;
|
|
170
|
+
addToHistory(responseTimeHistory, avgResponseTime);
|
|
171
|
+
addToHistory(errorRateHistory, getErrorRate());
|
|
172
|
+
// Reset counters
|
|
173
|
+
totalResponseTime = 0;
|
|
174
|
+
responseTimeCount = 0;
|
|
175
|
+
// Trim samples (keep last 1000)
|
|
176
|
+
if (responseTimeSamples.length > 1000) {
|
|
177
|
+
responseTimeSamples = responseTimeSamples.slice(-500);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Track a request start
|
|
183
|
+
*/
|
|
184
|
+
function trackRequest(path, method) {
|
|
185
|
+
requestCount++;
|
|
186
|
+
totalRequests++;
|
|
187
|
+
activeConnections++;
|
|
188
|
+
const normalizedPath = config.normalizePath(path);
|
|
189
|
+
const key = `${method}:${normalizedPath}`;
|
|
190
|
+
if (!routeStats.has(key)) {
|
|
191
|
+
routeStats.set(key, {
|
|
192
|
+
path: normalizedPath,
|
|
193
|
+
method,
|
|
194
|
+
count: 0,
|
|
195
|
+
totalTime: 0,
|
|
196
|
+
avgTime: 0,
|
|
197
|
+
minTime: Infinity,
|
|
198
|
+
maxTime: 0,
|
|
199
|
+
errors: 0,
|
|
200
|
+
lastAccess: Date.now()
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Track request completion
|
|
206
|
+
*/
|
|
207
|
+
function trackRequestComplete(path, method, durationMs, statusCode) {
|
|
208
|
+
activeConnections = Math.max(0, activeConnections - 1);
|
|
209
|
+
// Track response time
|
|
210
|
+
totalResponseTime += durationMs;
|
|
211
|
+
responseTimeCount++;
|
|
212
|
+
responseTimeSamples.push(durationMs);
|
|
213
|
+
// Track status code
|
|
214
|
+
const codeStr = statusCode.toString();
|
|
215
|
+
statusCodes[codeStr] = (statusCodes[codeStr] || 0) + 1;
|
|
216
|
+
// Update route stats
|
|
217
|
+
const normalizedPath = config.normalizePath(path);
|
|
218
|
+
const key = `${method}:${normalizedPath}`;
|
|
219
|
+
const stats = routeStats.get(key);
|
|
220
|
+
if (stats) {
|
|
221
|
+
stats.count++;
|
|
222
|
+
stats.totalTime += durationMs;
|
|
223
|
+
stats.avgTime = stats.totalTime / stats.count;
|
|
224
|
+
stats.minTime = Math.min(stats.minTime, durationMs);
|
|
225
|
+
stats.maxTime = Math.max(stats.maxTime, durationMs);
|
|
226
|
+
stats.lastAccess = Date.now();
|
|
227
|
+
// Track errors
|
|
228
|
+
if (statusCode >= 400) {
|
|
229
|
+
stats.errors++;
|
|
230
|
+
recentErrors.unshift({
|
|
231
|
+
timestamp: Date.now(),
|
|
232
|
+
path: normalizedPath,
|
|
233
|
+
method,
|
|
234
|
+
status: statusCode,
|
|
235
|
+
message: `${method} ${normalizedPath} returned ${statusCode}`
|
|
236
|
+
});
|
|
237
|
+
while (recentErrors.length > config.maxRecentErrors) {
|
|
238
|
+
recentErrors.pop();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// Update metrics if interval has passed
|
|
243
|
+
updateMetricsIfNeeded();
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Track rate limit event
|
|
247
|
+
*/
|
|
248
|
+
function trackRateLimitEvent(blocked) {
|
|
249
|
+
rateLimitTotal++;
|
|
250
|
+
if (blocked)
|
|
251
|
+
rateLimitBlocked++;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Get current metrics snapshot
|
|
255
|
+
*/
|
|
256
|
+
async function getMetricsSnapshot() {
|
|
257
|
+
// Trigger update check
|
|
258
|
+
updateMetricsIfNeeded();
|
|
259
|
+
const uptimeSeconds = Math.round((Date.now() - startTime) / 1000);
|
|
260
|
+
return {
|
|
261
|
+
timestamp: Date.now(),
|
|
262
|
+
// System metrics - not available in edge
|
|
263
|
+
cpu: 0,
|
|
264
|
+
memoryMB: 0,
|
|
265
|
+
memoryPercent: 0,
|
|
266
|
+
heapUsedMB: 0,
|
|
267
|
+
heapTotalMB: 0,
|
|
268
|
+
loadAvg: 0,
|
|
269
|
+
uptime: uptimeSeconds, // Worker uptime
|
|
270
|
+
processUptime: uptimeSeconds,
|
|
271
|
+
// Request metrics - available
|
|
272
|
+
responseTime: responseTimeHistory.length > 0
|
|
273
|
+
? responseTimeHistory[responseTimeHistory.length - 1].value
|
|
274
|
+
: 0,
|
|
275
|
+
rps: rpsHistory.length > 0
|
|
276
|
+
? rpsHistory[rpsHistory.length - 1].value
|
|
277
|
+
: 0,
|
|
278
|
+
statusCodes: { ...statusCodes },
|
|
279
|
+
totalRequests,
|
|
280
|
+
activeConnections,
|
|
281
|
+
eventLoopLag: 0, // Not available in edge
|
|
282
|
+
// Platform info
|
|
283
|
+
hostname: 'cloudflare-worker',
|
|
284
|
+
platform: 'Cloudflare Workers',
|
|
285
|
+
nodeVersion: 'N/A',
|
|
286
|
+
pid: 0,
|
|
287
|
+
cpuCount: 0,
|
|
288
|
+
// Analytics - available
|
|
289
|
+
percentiles: calculatePercentiles(),
|
|
290
|
+
topRoutes: getTopRoutes(),
|
|
291
|
+
slowestRoutes: getSlowestRoutes(),
|
|
292
|
+
errorRoutes: getErrorRoutes(),
|
|
293
|
+
recentErrors: [...recentErrors],
|
|
294
|
+
alerts: checkAlerts(),
|
|
295
|
+
// Not available metrics
|
|
296
|
+
gc: {
|
|
297
|
+
collections: 0,
|
|
298
|
+
pauseTimeMs: 0,
|
|
299
|
+
heapGrowthRate: 0
|
|
300
|
+
},
|
|
301
|
+
database: {
|
|
302
|
+
connected: false,
|
|
303
|
+
poolSize: 0,
|
|
304
|
+
availableConnections: 0,
|
|
305
|
+
waitQueueSize: 0,
|
|
306
|
+
latencyMs: 0
|
|
307
|
+
},
|
|
308
|
+
rateLimitStats: { blocked: rateLimitBlocked, total: rateLimitTotal },
|
|
309
|
+
errorRate: getErrorRate(),
|
|
310
|
+
// Edge mode indicator
|
|
311
|
+
isEdgeMode: true
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Get chart data
|
|
316
|
+
*/
|
|
317
|
+
function getChartData() {
|
|
318
|
+
return {
|
|
319
|
+
cpu: [], // Not available
|
|
320
|
+
memory: [], // Not available
|
|
321
|
+
heap: [], // Not available
|
|
322
|
+
loadAvg: [], // Not available
|
|
323
|
+
responseTime: [...responseTimeHistory],
|
|
324
|
+
rps: [...rpsHistory],
|
|
325
|
+
eventLoopLag: [], // Not available
|
|
326
|
+
errorRate: [...errorRateHistory]
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Format uptime
|
|
331
|
+
*/
|
|
332
|
+
function formatUptime(seconds) {
|
|
333
|
+
const days = Math.floor(seconds / 86400);
|
|
334
|
+
const hours = Math.floor((seconds % 86400) / 3600);
|
|
335
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
336
|
+
const secs = Math.floor(seconds % 60);
|
|
337
|
+
const parts = [];
|
|
338
|
+
if (days > 0)
|
|
339
|
+
parts.push(`${days}d`);
|
|
340
|
+
if (hours > 0)
|
|
341
|
+
parts.push(`${hours}h`);
|
|
342
|
+
if (minutes > 0)
|
|
343
|
+
parts.push(`${minutes}m`);
|
|
344
|
+
parts.push(`${secs}s`);
|
|
345
|
+
return parts.join(' ');
|
|
346
|
+
}
|
|
347
|
+
// No-op functions for compatibility
|
|
348
|
+
function start() {
|
|
349
|
+
// No interval needed in edge - updates happen on each request
|
|
350
|
+
console.log('📊 Status monitor started (edge mode)');
|
|
351
|
+
}
|
|
352
|
+
function stop() {
|
|
353
|
+
// Nothing to stop in edge mode
|
|
354
|
+
console.log('📊 Status monitor stopped (edge mode)');
|
|
355
|
+
}
|
|
356
|
+
// Socket not available in edge
|
|
357
|
+
function initSocket() {
|
|
358
|
+
console.log('📊 WebSocket not available in edge mode, use polling');
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
return {
|
|
362
|
+
config,
|
|
363
|
+
trackRequest,
|
|
364
|
+
trackRequestComplete,
|
|
365
|
+
trackRateLimitEvent,
|
|
366
|
+
getMetricsSnapshot,
|
|
367
|
+
getChartData,
|
|
368
|
+
start,
|
|
369
|
+
stop,
|
|
370
|
+
initSocket,
|
|
371
|
+
formatUptime,
|
|
372
|
+
isEdgeMode: true,
|
|
373
|
+
get io() { return null; }
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
//# sourceMappingURL=monitor-edge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monitor-edge.js","sourceRoot":"","sources":["../src/monitor-edge.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,gDAAgD;AAChD,mEAAmE;AACnE,6DAA6D;AAC7D,gFAAgF;AAchF,8CAA8C;AAC9C,MAAM,mBAAmB,GAAkC;IACvD,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,eAAe;IACtB,UAAU,EAAE,mBAAmB,EAAE,+CAA+C;IAChF,cAAc,EAAE,IAAI,EAAE,mCAAmC;IACzD,gBAAgB,EAAE,EAAE;IACpB,eAAe,EAAE,EAAE;IACnB,SAAS,EAAE,EAAE;IACb,MAAM,EAAE;QACJ,GAAG,EAAE,EAAE,EAAE,wBAAwB;QACjC,MAAM,EAAE,EAAE,EAAE,wBAAwB;QACpC,YAAY,EAAE,GAAG;QACjB,SAAS,EAAE,CAAC;QACZ,YAAY,EAAE,GAAG,CAAC,wBAAwB;KAC7C;IACD,WAAW,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IAC5D,aAAa,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI;IACrC,WAAW,EAAE,KAAK,CAAC,wBAAwB;CAC9C,CAAC;AAEF;;GAEG;AACH,SAAS,oBAAoB,CAAC,IAAY;IACtC,OAAO,IAAI;SACN,OAAO,CAAC,gEAAgE,EAAE,OAAO,CAAC;SAClF,OAAO,CAAC,gBAAgB,EAAE,KAAK,CAAC;SAChC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC;SACzB,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC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,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,oCAAoC;IACpC,SAAS,KAAK;QACV,8DAA8D;QAC9D,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;IACzD,CAAC;IAED,SAAS,IAAI;QACT,+BAA+B;QAC/B,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;IACzD,CAAC;IAED,+BAA+B;IAC/B,SAAS,UAAU;QACf,OAAO,CAAC,GAAG,CAAC,sDAAsD,CAAC,CAAC;QACpE,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO;QACH,MAAM;QACN,YAAY;QACZ,oBAAoB;QACpB,mBAAmB;QACnB,kBAAkB;QAClB,YAAY;QACZ,KAAK;QACL,IAAI;QACJ,UAAU;QACV,YAAY;QACZ,UAAU,EAAE,IAAI;QAChB,IAAI,EAAE,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC;KAC5B,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported platform types
|
|
3
|
+
*/
|
|
4
|
+
export type Platform = 'node' | 'cloudflare' | 'edge' | 'unknown';
|
|
5
|
+
/**
|
|
6
|
+
* Detect the current runtime platform
|
|
7
|
+
*
|
|
8
|
+
* @returns The detected platform type
|
|
9
|
+
*/
|
|
10
|
+
export declare function detectPlatform(): Platform;
|
|
11
|
+
/**
|
|
12
|
+
* Check if running in a Node.js environment
|
|
13
|
+
*/
|
|
14
|
+
export declare function isNodeEnvironment(): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Check if running in a Cloudflare Workers environment
|
|
17
|
+
*/
|
|
18
|
+
export declare function isCloudflareEnvironment(): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Check if running in any edge environment (Cloudflare, Vercel Edge, etc.)
|
|
21
|
+
*/
|
|
22
|
+
export declare function isEdgeEnvironment(): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Get platform-specific information
|
|
25
|
+
*/
|
|
26
|
+
export declare function getPlatformInfo(): {
|
|
27
|
+
platform: Platform;
|
|
28
|
+
hasOsModule: boolean;
|
|
29
|
+
hasProcessModule: boolean;
|
|
30
|
+
hasWebSocketSupport: boolean;
|
|
31
|
+
hasClusterSupport: boolean;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,YAAY,GAAG,MAAM,GAAG,SAAS,CAAC;AAElE;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,QAAQ,CA0CzC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,OAAO,CAEjD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAG3C;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI;IAC/B,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,EAAE,OAAO,CAAC;IACrB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,iBAAiB,EAAE,OAAO,CAAC;CAC9B,CAWA"}
|