pms_md 1.0.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.
Files changed (55) hide show
  1. package/README.md +93 -0
  2. package/node-monitor/ARCHITECTURE.md +341 -0
  3. package/node-monitor/CHANGELOG.md +105 -0
  4. package/node-monitor/CONTRIBUTING.md +96 -0
  5. package/node-monitor/DESIGN_IMPROVEMENTS.md +286 -0
  6. package/node-monitor/FILTER_BUTTONS_FIX.md +303 -0
  7. package/node-monitor/GETTING_STARTED.md +416 -0
  8. package/node-monitor/INSTALLATION.md +470 -0
  9. package/node-monitor/LICENSE +22 -0
  10. package/node-monitor/PUBLISHING_GUIDE.md +331 -0
  11. package/node-monitor/QUICK_REFERENCE.md +252 -0
  12. package/node-monitor/README.md +458 -0
  13. package/node-monitor/READY_TO_PUBLISH.md +272 -0
  14. package/node-monitor/SETUP_GUIDE.md +479 -0
  15. package/node-monitor/examples/EMAIL_SETUP_GUIDE.md +282 -0
  16. package/node-monitor/examples/ERROR_LOGGING_GUIDE.md +405 -0
  17. package/node-monitor/examples/GET_APP_PASSWORD.md +145 -0
  18. package/node-monitor/examples/LOG_FILES_REFERENCE.md +336 -0
  19. package/node-monitor/examples/QUICK_START_EMAIL.md +126 -0
  20. package/node-monitor/examples/express-app.js +499 -0
  21. package/node-monitor/examples/package-lock.json +1295 -0
  22. package/node-monitor/examples/package.json +18 -0
  23. package/node-monitor/examples/public/css/style.css +718 -0
  24. package/node-monitor/examples/public/js/dashboard.js +207 -0
  25. package/node-monitor/examples/public/js/health.js +114 -0
  26. package/node-monitor/examples/public/js/main.js +89 -0
  27. package/node-monitor/examples/public/js/metrics.js +225 -0
  28. package/node-monitor/examples/public/js/theme.js +138 -0
  29. package/node-monitor/examples/views/dashboard.ejs +20 -0
  30. package/node-monitor/examples/views/error-logs.ejs +1129 -0
  31. package/node-monitor/examples/views/health.ejs +21 -0
  32. package/node-monitor/examples/views/home.ejs +341 -0
  33. package/node-monitor/examples/views/layout.ejs +50 -0
  34. package/node-monitor/examples/views/metrics.ejs +16 -0
  35. package/node-monitor/examples/views/partials/footer.ejs +16 -0
  36. package/node-monitor/examples/views/partials/header.ejs +35 -0
  37. package/node-monitor/examples/views/partials/nav.ejs +23 -0
  38. package/node-monitor/examples/views/status.ejs +390 -0
  39. package/node-monitor/package-lock.json +4300 -0
  40. package/node-monitor/package.json +76 -0
  41. package/node-monitor/pre-publish-check.js +200 -0
  42. package/node-monitor/src/config/monitoringConfig.js +255 -0
  43. package/node-monitor/src/index.js +300 -0
  44. package/node-monitor/src/logger/errorLogger.js +297 -0
  45. package/node-monitor/src/monitors/apiErrorMonitor.js +156 -0
  46. package/node-monitor/src/monitors/dbConnectionMonitor.js +389 -0
  47. package/node-monitor/src/monitors/serverHealthMonitor.js +320 -0
  48. package/node-monitor/src/monitors/systemResourceMonitor.js +357 -0
  49. package/node-monitor/src/notifiers/emailNotifier.js +248 -0
  50. package/node-monitor/src/notifiers/notificationManager.js +96 -0
  51. package/node-monitor/src/notifiers/slackNotifier.js +209 -0
  52. package/node-monitor/src/views/dashboard.html +530 -0
  53. package/node-monitor/src/views/health.html +399 -0
  54. package/node-monitor/src/views/metrics.html +406 -0
  55. package/package.json +22 -0
@@ -0,0 +1,479 @@
1
+ # 📘 Node Monitor - Complete Setup Guide
2
+
3
+ This guide will walk you through setting up Node Monitor in your application step by step.
4
+
5
+ ## Table of Contents
6
+
7
+ 1. [Installation](#installation)
8
+ 2. [Email Notifications Setup](#email-notifications-setup)
9
+ 3. [Slack Notifications Setup](#slack-notifications-setup)
10
+ 4. [Database Monitoring Setup](#database-monitoring-setup)
11
+ 5. [Production Deployment](#production-deployment)
12
+ 6. [Troubleshooting](#troubleshooting)
13
+
14
+ ---
15
+
16
+ ## Installation
17
+
18
+ ### Step 1: Install the Package
19
+
20
+ ```bash
21
+ npm install @projectmd/node-monitor
22
+ ```
23
+
24
+ ### Step 2: Install Peer Dependencies
25
+
26
+ Install only what you need:
27
+
28
+ ```bash
29
+ # If using Express (required for most features)
30
+ npm install express
31
+
32
+ # If monitoring MongoDB
33
+ npm install mongoose
34
+
35
+ # If monitoring PostgreSQL
36
+ npm install pg
37
+
38
+ # If monitoring MySQL
39
+ npm install mysql2
40
+
41
+ # If monitoring Redis
42
+ npm install ioredis
43
+ ```
44
+
45
+ ### Step 3: Create Configuration File
46
+
47
+ Create a `.env` file in your project root:
48
+
49
+ ```bash
50
+ cp node_modules/@projectmd/node-monitor/.env.example .env
51
+ ```
52
+
53
+ Edit the `.env` file with your settings.
54
+
55
+ ---
56
+
57
+ ## Email Notifications Setup
58
+
59
+ ### Option 1: Gmail
60
+
61
+ 1. **Enable 2-Factor Authentication** on your Gmail account
62
+ 2. **Generate App Password**:
63
+ - Go to Google Account Settings → Security
64
+ - Under "Signing in to Google", select "App passwords"
65
+ - Generate a new app password for "Mail"
66
+ 3. **Configure in .env**:
67
+
68
+ ```env
69
+ MONITOR_EMAIL_ENABLED=true
70
+ MONITOR_EMAIL_HOST=smtp.gmail.com
71
+ MONITOR_EMAIL_PORT=587
72
+ MONITOR_EMAIL_SECURE=false
73
+ MONITOR_EMAIL_USER=your-email@gmail.com
74
+ MONITOR_EMAIL_PASS=your-16-char-app-password
75
+ MONITOR_EMAIL_FROM=your-email@gmail.com
76
+ MONITOR_EMAIL_RECIPIENTS=admin@example.com,ops@example.com
77
+ ```
78
+
79
+ ### Option 2: SendGrid
80
+
81
+ ```env
82
+ MONITOR_EMAIL_ENABLED=true
83
+ MONITOR_EMAIL_HOST=smtp.sendgrid.net
84
+ MONITOR_EMAIL_PORT=587
85
+ MONITOR_EMAIL_USER=apikey
86
+ MONITOR_EMAIL_PASS=your-sendgrid-api-key
87
+ MONITOR_EMAIL_FROM=noreply@yourdomain.com
88
+ MONITOR_EMAIL_RECIPIENTS=admin@example.com
89
+ ```
90
+
91
+ ### Option 3: AWS SES
92
+
93
+ ```env
94
+ MONITOR_EMAIL_ENABLED=true
95
+ MONITOR_EMAIL_HOST=email-smtp.us-east-1.amazonaws.com
96
+ MONITOR_EMAIL_PORT=587
97
+ MONITOR_EMAIL_USER=your-smtp-username
98
+ MONITOR_EMAIL_PASS=your-smtp-password
99
+ MONITOR_EMAIL_FROM=noreply@yourdomain.com
100
+ MONITOR_EMAIL_RECIPIENTS=admin@example.com
101
+ ```
102
+
103
+ ### Test Email Configuration
104
+
105
+ ```javascript
106
+ const monitor = new NodeMonitor();
107
+
108
+ // Send test email
109
+ await monitor.notify('info', 'Test Email', 'This is a test notification');
110
+ ```
111
+
112
+ ---
113
+
114
+ ## Slack Notifications Setup
115
+
116
+ ### Step 1: Create Slack Incoming Webhook
117
+
118
+ 1. Go to https://api.slack.com/apps
119
+ 2. Click "Create New App" → "From scratch"
120
+ 3. Name your app (e.g., "Node Monitor") and select your workspace
121
+ 4. In the app settings, go to "Incoming Webhooks"
122
+ 5. Activate Incoming Webhooks
123
+ 6. Click "Add New Webhook to Workspace"
124
+ 7. Select the channel where you want notifications
125
+ 8. Copy the Webhook URL
126
+
127
+ ### Step 2: Configure in .env
128
+
129
+ ```env
130
+ MONITOR_SLACK_ENABLED=true
131
+ MONITOR_SLACK_WEBHOOK=https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXX
132
+ MONITOR_SLACK_CHANNEL=#monitoring
133
+ MONITOR_SLACK_USERNAME=Node Monitor
134
+ ```
135
+
136
+ ### Step 3: Test Slack Integration
137
+
138
+ ```javascript
139
+ const monitor = new NodeMonitor();
140
+
141
+ // Send test message
142
+ await monitor.notify('info', 'Test Slack', 'Slack integration is working!');
143
+ ```
144
+
145
+ ---
146
+
147
+ ## Database Monitoring Setup
148
+
149
+ ### MongoDB with Mongoose
150
+
151
+ ```javascript
152
+ const mongoose = require('mongoose');
153
+ const NodeMonitor = require('@projectmd/node-monitor');
154
+
155
+ const monitor = new NodeMonitor();
156
+
157
+ // Connect to MongoDB
158
+ await mongoose.connect('mongodb://localhost:27017/myapp', {
159
+ useNewUrlParser: true,
160
+ useUnifiedTopology: true
161
+ });
162
+
163
+ // Register for monitoring
164
+ monitor.registerDatabase('mongodb', 'mongoose', mongoose.connection);
165
+
166
+ // Start monitoring
167
+ monitor.start();
168
+ ```
169
+
170
+ ### PostgreSQL
171
+
172
+ ```javascript
173
+ const { Pool } = require('pg');
174
+ const NodeMonitor = require('@projectmd/node-monitor');
175
+
176
+ const monitor = new NodeMonitor();
177
+
178
+ // Create connection pool
179
+ const pool = new Pool({
180
+ host: 'localhost',
181
+ port: 5432,
182
+ database: 'myapp',
183
+ user: 'postgres',
184
+ password: 'password',
185
+ max: 20
186
+ });
187
+
188
+ // Register for monitoring
189
+ monitor.registerDatabase('postgres', 'postgresql', pool, 'SELECT 1');
190
+
191
+ // Start monitoring
192
+ monitor.start();
193
+ ```
194
+
195
+ ### MySQL
196
+
197
+ ```javascript
198
+ const mysql = require('mysql2/promise');
199
+ const NodeMonitor = require('@projectmd/node-monitor');
200
+
201
+ const monitor = new NodeMonitor();
202
+
203
+ // Create connection pool
204
+ const pool = mysql.createPool({
205
+ host: 'localhost',
206
+ user: 'root',
207
+ password: 'password',
208
+ database: 'myapp',
209
+ waitForConnections: true,
210
+ connectionLimit: 10
211
+ });
212
+
213
+ // Register for monitoring
214
+ monitor.registerDatabase('mysql', 'mysql', pool, 'SELECT 1');
215
+
216
+ // Start monitoring
217
+ monitor.start();
218
+ ```
219
+
220
+ ### Redis
221
+
222
+ ```javascript
223
+ const Redis = require('ioredis');
224
+ const NodeMonitor = require('@projectmd/node-monitor');
225
+
226
+ const monitor = new NodeMonitor();
227
+
228
+ // Create Redis client
229
+ const redis = new Redis({
230
+ host: 'localhost',
231
+ port: 6379,
232
+ password: 'your-password'
233
+ });
234
+
235
+ // Register for monitoring
236
+ monitor.registerDatabase('redis', 'redis', redis);
237
+
238
+ // Start monitoring
239
+ monitor.start();
240
+ ```
241
+
242
+ ---
243
+
244
+ ## Production Deployment
245
+
246
+ ### 1. Environment Configuration
247
+
248
+ Create separate `.env` files for each environment:
249
+
250
+ ```
251
+ .env.development
252
+ .env.staging
253
+ .env.production
254
+ ```
255
+
256
+ Load the appropriate file:
257
+
258
+ ```javascript
259
+ require('dotenv').config({
260
+ path: `.env.${process.env.NODE_ENV || 'development'}`
261
+ });
262
+ ```
263
+
264
+ ### 2. Recommended Production Settings
265
+
266
+ ```env
267
+ NODE_ENV=production
268
+
269
+ # More frequent checks in production
270
+ MONITOR_HEALTH_INTERVAL=30000
271
+ MONITOR_SYSTEM_INTERVAL=60000
272
+ MONITOR_DATABASE_INTERVAL=60000
273
+
274
+ # Stricter thresholds
275
+ MONITOR_CPU_THRESHOLD=75
276
+ MONITOR_MEMORY_THRESHOLD=85
277
+ MONITOR_ERROR_RATE_THRESHOLD=25
278
+
279
+ # Enable all notifications
280
+ MONITOR_EMAIL_ENABLED=true
281
+ MONITOR_SLACK_ENABLED=true
282
+
283
+ # Structured logging
284
+ MONITOR_LOG_FORMAT=json
285
+ MONITOR_LOG_LEVEL=info
286
+ MONITOR_LOG_CONSOLE=false
287
+
288
+ # Shorter cooldown for critical issues
289
+ MONITOR_NOTIFICATION_COOLDOWN=180000
290
+ ```
291
+
292
+ ### 3. Process Manager (PM2)
293
+
294
+ Create `ecosystem.config.js`:
295
+
296
+ ```javascript
297
+ module.exports = {
298
+ apps: [{
299
+ name: 'my-app',
300
+ script: './server.js',
301
+ instances: 'max',
302
+ exec_mode: 'cluster',
303
+ env: {
304
+ NODE_ENV: 'production'
305
+ },
306
+ error_file: './logs/pm2-error.log',
307
+ out_file: './logs/pm2-out.log',
308
+ log_date_format: 'YYYY-MM-DD HH:mm:ss Z'
309
+ }]
310
+ };
311
+ ```
312
+
313
+ Start with PM2:
314
+
315
+ ```bash
316
+ pm2 start ecosystem.config.js
317
+ pm2 save
318
+ pm2 startup
319
+ ```
320
+
321
+ ### 4. Docker Deployment
322
+
323
+ Create `Dockerfile`:
324
+
325
+ ```dockerfile
326
+ FROM node:18-alpine
327
+
328
+ WORKDIR /app
329
+
330
+ COPY package*.json ./
331
+ RUN npm ci --only=production
332
+
333
+ COPY . .
334
+
335
+ EXPOSE 3000
336
+
337
+ CMD ["node", "server.js"]
338
+ ```
339
+
340
+ Create `docker-compose.yml`:
341
+
342
+ ```yaml
343
+ version: '3.8'
344
+
345
+ services:
346
+ app:
347
+ build: .
348
+ ports:
349
+ - "3000:3000"
350
+ environment:
351
+ - NODE_ENV=production
352
+ env_file:
353
+ - .env.production
354
+ volumes:
355
+ - ./logs:/app/logs
356
+ restart: unless-stopped
357
+ ```
358
+
359
+ ### 5. Health Check Integration
360
+
361
+ For Kubernetes:
362
+
363
+ ```yaml
364
+ livenessProbe:
365
+ httpGet:
366
+ path: /health
367
+ port: 3000
368
+ initialDelaySeconds: 30
369
+ periodSeconds: 10
370
+
371
+ readinessProbe:
372
+ httpGet:
373
+ path: /health/info
374
+ port: 3000
375
+ initialDelaySeconds: 5
376
+ periodSeconds: 5
377
+ ```
378
+
379
+ For Docker Compose:
380
+
381
+ ```yaml
382
+ healthcheck:
383
+ test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
384
+ interval: 30s
385
+ timeout: 10s
386
+ retries: 3
387
+ start_period: 40s
388
+ ```
389
+
390
+ ---
391
+
392
+ ## Troubleshooting
393
+
394
+ ### Email Notifications Not Working
395
+
396
+ **Problem**: Emails are not being sent
397
+
398
+ **Solutions**:
399
+ 1. Check SMTP credentials are correct
400
+ 2. Verify firewall allows outbound connections on port 587/465
401
+ 3. Check spam folder
402
+ 4. Enable less secure apps (Gmail) or use app passwords
403
+ 5. Check logs: `tail -f logs/error-*.log`
404
+
405
+ ### Slack Notifications Not Working
406
+
407
+ **Problem**: Slack messages not appearing
408
+
409
+ **Solutions**:
410
+ 1. Verify webhook URL is correct
411
+ 2. Check the webhook hasn't been revoked
412
+ 3. Ensure channel exists and bot has access
413
+ 4. Test webhook with curl:
414
+ ```bash
415
+ curl -X POST -H 'Content-type: application/json' \
416
+ --data '{"text":"Test message"}' \
417
+ YOUR_WEBHOOK_URL
418
+ ```
419
+
420
+ ### High CPU/Memory Alerts
421
+
422
+ **Problem**: Constant alerts about high resource usage
423
+
424
+ **Solutions**:
425
+ 1. Increase thresholds if they're too strict
426
+ 2. Optimize your application code
427
+ 3. Scale horizontally (add more instances)
428
+ 4. Increase cooldown period to reduce alert frequency
429
+
430
+ ### Database Connection Monitoring Issues
431
+
432
+ **Problem**: False positive database disconnection alerts
433
+
434
+ **Solutions**:
435
+ 1. Increase `MONITOR_DB_QUERY_TIMEOUT`
436
+ 2. Check database server is accessible
437
+ 3. Verify connection pool settings
438
+ 4. Increase `MONITOR_CONSECUTIVE_FAILURES` threshold
439
+
440
+ ### Logs Growing Too Large
441
+
442
+ **Problem**: Log files consuming too much disk space
443
+
444
+ **Solutions**:
445
+ 1. Reduce `MONITOR_LOG_MAX_FILES` (e.g., from 14d to 7d)
446
+ 2. Reduce `MONITOR_LOG_MAX_SIZE` (e.g., from 20m to 10m)
447
+ 3. Set up log rotation with logrotate
448
+ 4. Use external logging service (CloudWatch, Datadog, etc.)
449
+
450
+ ### Performance Impact
451
+
452
+ **Problem**: Monitoring affecting application performance
453
+
454
+ **Solutions**:
455
+ 1. Increase monitoring intervals
456
+ 2. Disable `MONITOR_TRACK_EVENT_LOOP` if not needed
457
+ 3. Reduce log level to 'warn' or 'error' in production
458
+ 4. Disable console logging in production
459
+
460
+ ---
461
+
462
+ ## Getting Help
463
+
464
+ - **GitHub Issues**: https://github.com/yourorg/node-monitor/issues
465
+ - **Documentation**: See README.md
466
+ - **Examples**: Check the `examples/` directory
467
+
468
+ ---
469
+
470
+ ## Next Steps
471
+
472
+ 1. ✅ Set up basic monitoring
473
+ 2. ✅ Configure notifications
474
+ 3. ✅ Add database monitoring
475
+ 4. ✅ Test in staging environment
476
+ 5. ✅ Deploy to production
477
+ 6. 📊 Monitor the dashboard regularly
478
+ 7. 🔧 Fine-tune thresholds based on your application's behavior
479
+