pms_md 1.0.4 → 1.0.6
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/.gitignore +158 -0
- package/README.md +69 -1
- package/node-monitor/DESIGN_IMPROVEMENTS.md +286 -0
- package/node-monitor/FILTER_BUTTONS_FIX.md +303 -0
- package/node-monitor/PUBLISHING_GUIDE.md +331 -0
- package/node-monitor/READY_TO_PUBLISH.md +272 -0
- package/node-monitor/examples/views/layout.ejs +1 -1
- package/node-monitor/examples/views/partials/footer.ejs +1 -1
- package/node-monitor/examples/views/status.ejs +1 -1
- package/node-monitor/package-lock.json +4307 -4300
- package/node-monitor/package.json +79 -79
- package/node-monitor/src/index.js +322 -300
- package/node-monitor/src/ui/uiRouter.js +261 -0
- package/node-monitor/src/views/dashboard.html +1 -1
- package/package.json +131 -123
- package/BUILD_SUMMARY.md +0 -257
- package/CHANGELOG.md +0 -190
- package/DATABASE_SUPPORT.md +0 -582
- package/FINAL_CHECKLIST.md +0 -210
- package/PACKAGE_READY.txt +0 -169
- package/PEER_DEPENDENCY_FIX.txt +0 -57
- package/QUICK_DATABASE_REFERENCE.md +0 -247
- package/RELEASE_v1.0.3.md +0 -237
|
@@ -1,300 +1,322 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Node Monitor - Main Entry Point
|
|
3
|
-
* Comprehensive monitoring solution for Node.js applications
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const MonitoringConfig = require('./config/monitoringConfig');
|
|
7
|
-
const ErrorLogger = require('./logger/errorLogger');
|
|
8
|
-
const NotificationManager = require('./notifiers/notificationManager');
|
|
9
|
-
const ApiErrorMonitor = require('./monitors/apiErrorMonitor');
|
|
10
|
-
const ServerHealthMonitor = require('./monitors/serverHealthMonitor');
|
|
11
|
-
const SystemResourceMonitor = require('./monitors/systemResourceMonitor');
|
|
12
|
-
const DbConnectionMonitor = require('./monitors/dbConnectionMonitor');
|
|
13
|
-
|
|
14
|
-
class NodeMonitor {
|
|
15
|
-
constructor(userConfig = {}) {
|
|
16
|
-
// Initialize configuration
|
|
17
|
-
this.config = new MonitoringConfig(userConfig);
|
|
18
|
-
|
|
19
|
-
// Initialize logger
|
|
20
|
-
this.logger = new ErrorLogger(this.config.getAll());
|
|
21
|
-
|
|
22
|
-
// Initialize notification manager
|
|
23
|
-
this.notificationManager = new NotificationManager(this.config.getAll(), this.logger);
|
|
24
|
-
|
|
25
|
-
// Initialize monitors
|
|
26
|
-
this.apiErrorMonitor = new ApiErrorMonitor(
|
|
27
|
-
this.config.getAll(),
|
|
28
|
-
this.logger,
|
|
29
|
-
this.notificationManager
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
this.serverHealthMonitor = new ServerHealthMonitor(
|
|
33
|
-
this.config.getAll(),
|
|
34
|
-
this.logger,
|
|
35
|
-
this.notificationManager
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
this.systemResourceMonitor = new SystemResourceMonitor(
|
|
39
|
-
this.config.getAll(),
|
|
40
|
-
this.logger,
|
|
41
|
-
this.notificationManager
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
this.dbConnectionMonitor = new DbConnectionMonitor(
|
|
45
|
-
this.config.getAll(),
|
|
46
|
-
this.logger,
|
|
47
|
-
this.notificationManager
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
this.isStarted = false;
|
|
51
|
-
|
|
52
|
-
this.logger.logInfo('Node Monitor initialized', {
|
|
53
|
-
app: this.config.get('app.name'),
|
|
54
|
-
version: this.config.get('app.version'),
|
|
55
|
-
environment: this.config.get('app.environment')
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Start all monitoring services
|
|
61
|
-
*/
|
|
62
|
-
start() {
|
|
63
|
-
if (this.isStarted) {
|
|
64
|
-
this.logger.logWarning('monitor_already_started', 'Monitor is already started');
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
this.serverHealthMonitor.start();
|
|
69
|
-
this.systemResourceMonitor.start();
|
|
70
|
-
this.dbConnectionMonitor.start();
|
|
71
|
-
|
|
72
|
-
this.isStarted = true;
|
|
73
|
-
this.logger.logInfo('All monitoring services started');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Stop all monitoring services
|
|
78
|
-
*/
|
|
79
|
-
stop() {
|
|
80
|
-
if (!this.isStarted) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
this.serverHealthMonitor.stop();
|
|
85
|
-
this.systemResourceMonitor.stop();
|
|
86
|
-
this.dbConnectionMonitor.stop();
|
|
87
|
-
|
|
88
|
-
this.isStarted = false;
|
|
89
|
-
this.logger.logInfo('All monitoring services stopped');
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Get Express error handling middleware
|
|
94
|
-
*/
|
|
95
|
-
errorMiddleware() {
|
|
96
|
-
return this.apiErrorMonitor.middleware();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Get Express request logger middleware
|
|
101
|
-
*/
|
|
102
|
-
requestLogger() {
|
|
103
|
-
return this.apiErrorMonitor.requestLogger();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Get 404 handler middleware
|
|
108
|
-
*/
|
|
109
|
-
notFoundHandler() {
|
|
110
|
-
return this.apiErrorMonitor.notFoundHandler();
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Get async error handler wrapper
|
|
115
|
-
*/
|
|
116
|
-
asyncHandler(fn) {
|
|
117
|
-
return this.apiErrorMonitor.asyncHandler(fn);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Get health check endpoint handler
|
|
122
|
-
*/
|
|
123
|
-
healthCheckEndpoint() {
|
|
124
|
-
return this.serverHealthMonitor.healthCheckEndpoint();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Get basic health info endpoint handler
|
|
129
|
-
*/
|
|
130
|
-
healthInfoEndpoint() {
|
|
131
|
-
return this.serverHealthMonitor.healthInfoEndpoint();
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Register a custom health check
|
|
136
|
-
*/
|
|
137
|
-
registerHealthCheck(name, checkFunction) {
|
|
138
|
-
this.serverHealthMonitor.registerHealthCheck(name, checkFunction);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Register a database connection for monitoring
|
|
143
|
-
*/
|
|
144
|
-
registerDatabase(name, type, connection, testQuery = null) {
|
|
145
|
-
this.dbConnectionMonitor.registerConnection(name, type, connection, testQuery);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Setup graceful shutdown handlers
|
|
150
|
-
*/
|
|
151
|
-
setupGracefulShutdown(server) {
|
|
152
|
-
this.serverHealthMonitor.setupGracefulShutdown(server);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Get current monitoring status
|
|
157
|
-
*/
|
|
158
|
-
getStatus() {
|
|
159
|
-
return {
|
|
160
|
-
isRunning: this.isStarted,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
this.
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Node Monitor - Main Entry Point
|
|
3
|
+
* Comprehensive monitoring solution for Node.js applications
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const MonitoringConfig = require('./config/monitoringConfig');
|
|
7
|
+
const ErrorLogger = require('./logger/errorLogger');
|
|
8
|
+
const NotificationManager = require('./notifiers/notificationManager');
|
|
9
|
+
const ApiErrorMonitor = require('./monitors/apiErrorMonitor');
|
|
10
|
+
const ServerHealthMonitor = require('./monitors/serverHealthMonitor');
|
|
11
|
+
const SystemResourceMonitor = require('./monitors/systemResourceMonitor');
|
|
12
|
+
const DbConnectionMonitor = require('./monitors/dbConnectionMonitor');
|
|
13
|
+
|
|
14
|
+
class NodeMonitor {
|
|
15
|
+
constructor(userConfig = {}) {
|
|
16
|
+
// Initialize configuration
|
|
17
|
+
this.config = new MonitoringConfig(userConfig);
|
|
18
|
+
|
|
19
|
+
// Initialize logger
|
|
20
|
+
this.logger = new ErrorLogger(this.config.getAll());
|
|
21
|
+
|
|
22
|
+
// Initialize notification manager
|
|
23
|
+
this.notificationManager = new NotificationManager(this.config.getAll(), this.logger);
|
|
24
|
+
|
|
25
|
+
// Initialize monitors
|
|
26
|
+
this.apiErrorMonitor = new ApiErrorMonitor(
|
|
27
|
+
this.config.getAll(),
|
|
28
|
+
this.logger,
|
|
29
|
+
this.notificationManager
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
this.serverHealthMonitor = new ServerHealthMonitor(
|
|
33
|
+
this.config.getAll(),
|
|
34
|
+
this.logger,
|
|
35
|
+
this.notificationManager
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
this.systemResourceMonitor = new SystemResourceMonitor(
|
|
39
|
+
this.config.getAll(),
|
|
40
|
+
this.logger,
|
|
41
|
+
this.notificationManager
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
this.dbConnectionMonitor = new DbConnectionMonitor(
|
|
45
|
+
this.config.getAll(),
|
|
46
|
+
this.logger,
|
|
47
|
+
this.notificationManager
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
this.isStarted = false;
|
|
51
|
+
|
|
52
|
+
this.logger.logInfo('Node Monitor initialized', {
|
|
53
|
+
app: this.config.get('app.name'),
|
|
54
|
+
version: this.config.get('app.version'),
|
|
55
|
+
environment: this.config.get('app.environment')
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Start all monitoring services
|
|
61
|
+
*/
|
|
62
|
+
start() {
|
|
63
|
+
if (this.isStarted) {
|
|
64
|
+
this.logger.logWarning('monitor_already_started', 'Monitor is already started');
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
this.serverHealthMonitor.start();
|
|
69
|
+
this.systemResourceMonitor.start();
|
|
70
|
+
this.dbConnectionMonitor.start();
|
|
71
|
+
|
|
72
|
+
this.isStarted = true;
|
|
73
|
+
this.logger.logInfo('All monitoring services started');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Stop all monitoring services
|
|
78
|
+
*/
|
|
79
|
+
stop() {
|
|
80
|
+
if (!this.isStarted) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this.serverHealthMonitor.stop();
|
|
85
|
+
this.systemResourceMonitor.stop();
|
|
86
|
+
this.dbConnectionMonitor.stop();
|
|
87
|
+
|
|
88
|
+
this.isStarted = false;
|
|
89
|
+
this.logger.logInfo('All monitoring services stopped');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Get Express error handling middleware
|
|
94
|
+
*/
|
|
95
|
+
errorMiddleware() {
|
|
96
|
+
return this.apiErrorMonitor.middleware();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Get Express request logger middleware
|
|
101
|
+
*/
|
|
102
|
+
requestLogger() {
|
|
103
|
+
return this.apiErrorMonitor.requestLogger();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Get 404 handler middleware
|
|
108
|
+
*/
|
|
109
|
+
notFoundHandler() {
|
|
110
|
+
return this.apiErrorMonitor.notFoundHandler();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Get async error handler wrapper
|
|
115
|
+
*/
|
|
116
|
+
asyncHandler(fn) {
|
|
117
|
+
return this.apiErrorMonitor.asyncHandler(fn);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Get health check endpoint handler
|
|
122
|
+
*/
|
|
123
|
+
healthCheckEndpoint() {
|
|
124
|
+
return this.serverHealthMonitor.healthCheckEndpoint();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Get basic health info endpoint handler
|
|
129
|
+
*/
|
|
130
|
+
healthInfoEndpoint() {
|
|
131
|
+
return this.serverHealthMonitor.healthInfoEndpoint();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Register a custom health check
|
|
136
|
+
*/
|
|
137
|
+
registerHealthCheck(name, checkFunction) {
|
|
138
|
+
this.serverHealthMonitor.registerHealthCheck(name, checkFunction);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Register a database connection for monitoring
|
|
143
|
+
*/
|
|
144
|
+
registerDatabase(name, type, connection, testQuery = null) {
|
|
145
|
+
this.dbConnectionMonitor.registerConnection(name, type, connection, testQuery);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Setup graceful shutdown handlers
|
|
150
|
+
*/
|
|
151
|
+
setupGracefulShutdown(server) {
|
|
152
|
+
this.serverHealthMonitor.setupGracefulShutdown(server);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Get current monitoring status
|
|
157
|
+
*/
|
|
158
|
+
getStatus() {
|
|
159
|
+
return {
|
|
160
|
+
isRunning: this.isStarted,
|
|
161
|
+
environment: this.config.get('app.environment'),
|
|
162
|
+
health: this.serverHealthMonitor.getStatus(),
|
|
163
|
+
system: this.systemResourceMonitor.getCurrentMetrics(),
|
|
164
|
+
databases: this.dbConnectionMonitor.getStatus(),
|
|
165
|
+
errors: this.apiErrorMonitor.getStats()
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Get system information
|
|
171
|
+
*/
|
|
172
|
+
getSystemInfo() {
|
|
173
|
+
return this.systemResourceMonitor.getSystemInfo();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Get metrics history
|
|
178
|
+
*/
|
|
179
|
+
getMetricsHistory() {
|
|
180
|
+
return this.systemResourceMonitor.getMetricsHistory();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Get database statistics
|
|
185
|
+
*/
|
|
186
|
+
async getDatabaseStats(name) {
|
|
187
|
+
return this.dbConnectionMonitor.getStats(name);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Send custom notification
|
|
192
|
+
*/
|
|
193
|
+
async notify(level, subject, message, details = {}) {
|
|
194
|
+
switch (level.toLowerCase()) {
|
|
195
|
+
case 'critical':
|
|
196
|
+
return this.notificationManager.sendCritical(subject, message, details);
|
|
197
|
+
case 'warning':
|
|
198
|
+
return this.notificationManager.sendWarning(subject, message, details);
|
|
199
|
+
case 'info':
|
|
200
|
+
return this.notificationManager.sendInfo(subject, message, details);
|
|
201
|
+
case 'recovery':
|
|
202
|
+
return this.notificationManager.sendRecovery(subject, message, details);
|
|
203
|
+
default:
|
|
204
|
+
return this.notificationManager.sendInfo(subject, message, details);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Log custom error
|
|
210
|
+
*/
|
|
211
|
+
logError(type, message, details = {}) {
|
|
212
|
+
return this.logger.logSystemError(type, message, details);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Log custom warning
|
|
217
|
+
*/
|
|
218
|
+
logWarning(type, message, details = {}) {
|
|
219
|
+
return this.logger.logWarning(type, message, details);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Log custom info
|
|
224
|
+
*/
|
|
225
|
+
logInfo(message, details = {}) {
|
|
226
|
+
return this.logger.logInfo(message, details);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Get Winston logger instance for custom logging
|
|
231
|
+
*/
|
|
232
|
+
getLogger() {
|
|
233
|
+
return this.logger.getLogger();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Get configuration
|
|
238
|
+
*/
|
|
239
|
+
getConfig() {
|
|
240
|
+
return this.config.getSanitized();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Update configuration at runtime
|
|
245
|
+
*/
|
|
246
|
+
updateConfig(path, value) {
|
|
247
|
+
this.config.set(path, value);
|
|
248
|
+
this.logger.logInfo('Configuration updated', { path, value });
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Serve monitoring UI (HTML dashboards)
|
|
253
|
+
* Automatically sets up EJS views and static files from the package
|
|
254
|
+
*
|
|
255
|
+
* @param {Express.Application} app - Express application instance
|
|
256
|
+
* @param {Object} options - UI configuration options
|
|
257
|
+
* @param {string} options.basePath - Base path for UI routes (default: '')
|
|
258
|
+
* @param {boolean} options.enableErrorLogs - Enable error logs page (default: true)
|
|
259
|
+
* @param {string} options.appName - Application name for UI (default: from config)
|
|
260
|
+
* @returns {UIRouter} UI Router instance
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* const monitor = new NodeMonitor({ app: { name: 'My App' } });
|
|
264
|
+
* monitor.serveUI(app);
|
|
265
|
+
* // UI available at: /, /health, /monitor/dashboard, /monitor/metrics
|
|
266
|
+
*/
|
|
267
|
+
serveUI(app, options = {}) {
|
|
268
|
+
const uiRouter = require('./ui/uiRouter');
|
|
269
|
+
return uiRouter.setup(app, this, options);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Create a monitoring dashboard endpoint (returns JSON data)
|
|
274
|
+
*/
|
|
275
|
+
dashboardEndpoint() {
|
|
276
|
+
return async (req, res) => {
|
|
277
|
+
try {
|
|
278
|
+
const status = this.getStatus();
|
|
279
|
+
const systemInfo = this.getSystemInfo();
|
|
280
|
+
const metricsHistory = this.getMetricsHistory();
|
|
281
|
+
|
|
282
|
+
res.json({
|
|
283
|
+
status: 'ok',
|
|
284
|
+
timestamp: new Date().toISOString(),
|
|
285
|
+
application: {
|
|
286
|
+
name: this.config.get('app.name'),
|
|
287
|
+
version: this.config.get('app.version'),
|
|
288
|
+
environment: this.config.get('app.environment')
|
|
289
|
+
},
|
|
290
|
+
monitoring: status,
|
|
291
|
+
system: systemInfo,
|
|
292
|
+
metrics: metricsHistory
|
|
293
|
+
});
|
|
294
|
+
} catch (error) {
|
|
295
|
+
res.status(500).json({
|
|
296
|
+
status: 'error',
|
|
297
|
+
error: error.message
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Static method to create error with status code
|
|
305
|
+
*/
|
|
306
|
+
static createError(message, statusCode = 500, details = {}) {
|
|
307
|
+
return ApiErrorMonitor.createError(message, statusCode, details);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Export the main class
|
|
312
|
+
module.exports = NodeMonitor;
|
|
313
|
+
|
|
314
|
+
// Also export individual components for advanced usage
|
|
315
|
+
module.exports.MonitoringConfig = MonitoringConfig;
|
|
316
|
+
module.exports.ErrorLogger = ErrorLogger;
|
|
317
|
+
module.exports.NotificationManager = NotificationManager;
|
|
318
|
+
module.exports.ApiErrorMonitor = ApiErrorMonitor;
|
|
319
|
+
module.exports.ServerHealthMonitor = ServerHealthMonitor;
|
|
320
|
+
module.exports.SystemResourceMonitor = SystemResourceMonitor;
|
|
321
|
+
module.exports.DbConnectionMonitor = DbConnectionMonitor;
|
|
322
|
+
|