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,331 @@
1
+ # ๐Ÿ“ฆ Publishing Guide for Node Monitor
2
+
3
+ This guide will help you publish the `@projectmd/node-monitor` package to npm.
4
+
5
+ ## ๐ŸŽฏ Pre-Publishing Checklist
6
+
7
+ Before publishing, make sure:
8
+
9
+ - [x] โœ… `.npmignore` file is created
10
+ - [x] โœ… `package.json` has repository information
11
+ - [x] โœ… `LICENSE` file exists (MIT)
12
+ - [x] โœ… `README.md` is complete
13
+ - [ ] ๐Ÿ“ All documentation is up to date
14
+ - [ ] ๐Ÿงช All tests pass (if applicable)
15
+ - [ ] ๐Ÿ” No sensitive data in code (API keys, passwords)
16
+ - [ ] ๐Ÿ“Š Version number is correct
17
+
18
+ ---
19
+
20
+ ## ๐Ÿš€ Step-by-Step Publishing Process
21
+
22
+ ### Step 1: Create npm Account (If You Don't Have One)
23
+
24
+ 1. Go to: https://www.npmjs.com/signup
25
+ 2. Create an account
26
+ 3. Verify your email
27
+
28
+ ### Step 2: Login to npm
29
+
30
+ ```bash
31
+ # Login to npm
32
+ npm login
33
+
34
+ # Verify you're logged in
35
+ npm whoami
36
+ ```
37
+
38
+ You'll be prompted for:
39
+ - Username
40
+ - Password
41
+ - Email
42
+ - One-time password (if 2FA is enabled)
43
+
44
+ ### Step 3: Test Your Package Locally
45
+
46
+ ```bash
47
+ # Navigate to the package directory
48
+ cd node-monitor
49
+
50
+ # Create a test package (doesn't publish, just creates a .tgz file)
51
+ npm pack
52
+
53
+ # This creates: projectmd-node-monitor-1.0.0.tgz
54
+ ```
55
+
56
+ **Test the package in another project:**
57
+
58
+ ```bash
59
+ # In a test project
60
+ cd ../test-project
61
+ npm install ../node-monitor/projectmd-node-monitor-1.0.0.tgz
62
+
63
+ # Test if it works
64
+ node -e "const monitor = require('@projectmd/node-monitor'); console.log('โœ… Package works!');"
65
+ ```
66
+
67
+ ### Step 4: Dry Run (See What Will Be Published)
68
+
69
+ ```bash
70
+ cd node-monitor
71
+
72
+ # Dry run - shows what will be published without actually publishing
73
+ npm publish --dry-run --access public
74
+ ```
75
+
76
+ This will show:
77
+ - Files that will be included
78
+ - Package size
79
+ - Any warnings or errors
80
+
81
+ ### Step 5: Publish to npm
82
+
83
+ ```bash
84
+ # Publish the package
85
+ npm publish --access public
86
+ ```
87
+
88
+ **Note:** The `--access public` flag is required for scoped packages (@projectmd/...) to make them publicly available.
89
+
90
+ ### Step 6: Verify Publication
91
+
92
+ ```bash
93
+ # Check if the package is published
94
+ npm view @projectmd/node-monitor
95
+
96
+ # Try installing it
97
+ npm install @projectmd/node-monitor
98
+ ```
99
+
100
+ Visit your package page:
101
+ ```
102
+ https://www.npmjs.com/package/@projectmd/node-monitor
103
+ ```
104
+
105
+ ---
106
+
107
+ ## ๐Ÿ”„ Updating the Package (Future Versions)
108
+
109
+ ### Update Version Number
110
+
111
+ Use semantic versioning:
112
+
113
+ ```bash
114
+ # Patch release (1.0.0 โ†’ 1.0.1) - Bug fixes
115
+ npm version patch
116
+
117
+ # Minor release (1.0.0 โ†’ 1.1.0) - New features, backward compatible
118
+ npm version minor
119
+
120
+ # Major release (1.0.0 โ†’ 2.0.0) - Breaking changes
121
+ npm version major
122
+ ```
123
+
124
+ This will:
125
+ 1. Update `package.json` version
126
+ 2. Create a git commit
127
+ 3. Create a git tag
128
+
129
+ ### Publish the New Version
130
+
131
+ ```bash
132
+ # After updating version
133
+ npm publish --access public
134
+
135
+ # Push changes to git
136
+ git push
137
+ git push --tags
138
+ ```
139
+
140
+ ---
141
+
142
+ ## ๐Ÿ“‹ What Gets Published?
143
+
144
+ ### โœ… Included Files:
145
+ - `src/` - All source code
146
+ - `package.json`
147
+ - `package-lock.json`
148
+ - `README.md`
149
+ - `LICENSE`
150
+ - `GETTING_STARTED.md`
151
+ - `INSTALLATION.md`
152
+ - `SETUP_GUIDE.md`
153
+ - `QUICK_REFERENCE.md`
154
+ - `ARCHITECTURE.md`
155
+ - `CHANGELOG.md`
156
+ - `CONTRIBUTING.md`
157
+
158
+ ### โŒ Excluded Files (via .npmignore):
159
+ - `node_modules/`
160
+ - `examples/node_modules/`
161
+ - `examples/logs/`
162
+ - `.env` files
163
+ - `logs/`
164
+ - Test files
165
+ - IDE configuration
166
+ - Development documentation
167
+
168
+ ---
169
+
170
+ ## ๐Ÿ” Verify Package Contents
171
+
172
+ Before publishing, check what will be included:
173
+
174
+ ```bash
175
+ # List all files that will be published
176
+ npm pack --dry-run
177
+
178
+ # Or create the package and inspect it
179
+ npm pack
180
+ tar -tzf projectmd-node-monitor-1.0.0.tgz
181
+ ```
182
+
183
+ ---
184
+
185
+ ## ๐Ÿ› ๏ธ Troubleshooting
186
+
187
+ ### Issue: "You must be logged in to publish packages"
188
+ **Solution:**
189
+ ```bash
190
+ npm login
191
+ npm whoami # Verify login
192
+ ```
193
+
194
+ ### Issue: "Package name already exists"
195
+ **Solution:**
196
+ - Choose a different package name
197
+ - Or use a scope: `@yourusername/node-monitor`
198
+
199
+ ### Issue: "You do not have permission to publish"
200
+ **Solution:**
201
+ - Make sure you're logged in as the correct user
202
+ - For scoped packages, use `--access public`
203
+
204
+ ### Issue: "Package version already exists"
205
+ **Solution:**
206
+ ```bash
207
+ # Update version first
208
+ npm version patch
209
+ npm publish --access public
210
+ ```
211
+
212
+ ### Issue: "Package size too large"
213
+ **Solution:**
214
+ - Check `.npmignore` is working
215
+ - Remove unnecessary files
216
+ - Check with: `npm pack --dry-run`
217
+
218
+ ---
219
+
220
+ ## ๐Ÿ” Security Best Practices
221
+
222
+ ### Enable 2FA (Two-Factor Authentication)
223
+
224
+ ```bash
225
+ # Enable 2FA for your npm account
226
+ npm profile enable-2fa auth-and-writes
227
+ ```
228
+
229
+ ### Use npm Tokens for CI/CD
230
+
231
+ ```bash
232
+ # Create an automation token
233
+ npm token create --read-only
234
+ ```
235
+
236
+ ---
237
+
238
+ ## ๐Ÿ“Š After Publishing
239
+
240
+ ### Monitor Your Package
241
+
242
+ 1. **npm Package Page:**
243
+ - https://www.npmjs.com/package/@projectmd/node-monitor
244
+ - View downloads, versions, dependencies
245
+
246
+ 2. **Check Package Health:**
247
+ ```bash
248
+ npm view @projectmd/node-monitor
249
+ ```
250
+
251
+ 3. **Track Downloads:**
252
+ - https://npm-stat.com/charts.html?package=@projectmd/node-monitor
253
+
254
+ ### Respond to Issues
255
+
256
+ - Monitor GitHub issues
257
+ - Respond to user questions
258
+ - Fix bugs and release patches
259
+
260
+ ### Keep Documentation Updated
261
+
262
+ - Update README.md with new features
263
+ - Maintain CHANGELOG.md
264
+ - Update version in documentation
265
+
266
+ ---
267
+
268
+ ## ๐ŸŽ‰ Success!
269
+
270
+ Once published, users can install your package with:
271
+
272
+ ```bash
273
+ npm install @projectmd/node-monitor
274
+ ```
275
+
276
+ And use it in their projects:
277
+
278
+ ```javascript
279
+ const NodeMonitor = require('@projectmd/node-monitor');
280
+ const monitor = new NodeMonitor();
281
+ ```
282
+
283
+ ---
284
+
285
+ ## ๐Ÿ“ Quick Reference Commands
286
+
287
+ ```bash
288
+ # Login
289
+ npm login
290
+
291
+ # Test package
292
+ npm pack
293
+
294
+ # Dry run
295
+ npm publish --dry-run --access public
296
+
297
+ # Publish
298
+ npm publish --access public
299
+
300
+ # Update version
301
+ npm version patch|minor|major
302
+
303
+ # View package info
304
+ npm view @projectmd/node-monitor
305
+
306
+ # Unpublish (within 72 hours only)
307
+ npm unpublish @projectmd/node-monitor@1.0.0
308
+ ```
309
+
310
+ ---
311
+
312
+ ## ๐Ÿ”— Useful Links
313
+
314
+ - **npm Documentation:** https://docs.npmjs.com/
315
+ - **Semantic Versioning:** https://semver.org/
316
+ - **npm Package Best Practices:** https://docs.npmjs.com/packages-and-modules/contributing-packages-to-the-registry
317
+ - **npm CLI Commands:** https://docs.npmjs.com/cli/v9/commands
318
+
319
+ ---
320
+
321
+ ## โš ๏ธ Important Notes
322
+
323
+ 1. **You cannot unpublish after 72 hours** - Be sure before publishing!
324
+ 2. **You cannot reuse a version number** - Once published, it's permanent
325
+ 3. **Breaking changes require major version bump** - Follow semantic versioning
326
+ 4. **Test thoroughly before publishing** - Your users depend on it!
327
+
328
+ ---
329
+
330
+ **Good luck with your npm package! ๐Ÿš€**
331
+
@@ -0,0 +1,252 @@
1
+ # Node Monitor - Quick Reference
2
+
3
+ ## Installation
4
+
5
+ ```bash
6
+ npm install @projectmd/node-monitor
7
+ ```
8
+
9
+ ## Basic Setup (30 seconds)
10
+
11
+ ```javascript
12
+ const express = require('express');
13
+ const NodeMonitor = require('@projectmd/node-monitor');
14
+
15
+ const monitor = new NodeMonitor();
16
+ const app = express();
17
+
18
+ app.use(monitor.requestLogger());
19
+ app.get('/health', monitor.healthCheckEndpoint());
20
+ app.use(monitor.notFoundHandler());
21
+ app.use(monitor.errorMiddleware());
22
+
23
+ const server = app.listen(3000, () => {
24
+ monitor.start();
25
+ monitor.setupGracefulShutdown(server);
26
+ });
27
+ ```
28
+
29
+ ## Common Tasks
30
+
31
+ ### Enable Email Alerts
32
+
33
+ ```javascript
34
+ const monitor = new NodeMonitor({
35
+ notifications: {
36
+ email: {
37
+ enabled: true,
38
+ host: 'smtp.gmail.com',
39
+ port: 587,
40
+ auth: { user: 'you@gmail.com', pass: 'app-password' },
41
+ recipients: ['admin@example.com']
42
+ }
43
+ }
44
+ });
45
+ ```
46
+
47
+ ### Enable Slack Alerts
48
+
49
+ ```javascript
50
+ const monitor = new NodeMonitor({
51
+ notifications: {
52
+ slack: {
53
+ enabled: true,
54
+ webhook: 'https://hooks.slack.com/services/YOUR/WEBHOOK',
55
+ channel: '#monitoring'
56
+ }
57
+ }
58
+ });
59
+ ```
60
+
61
+ ### Monitor Database
62
+
63
+ ```javascript
64
+ // MongoDB
65
+ monitor.registerDatabase('mongodb', 'mongoose', mongoose.connection);
66
+
67
+ // PostgreSQL
68
+ monitor.registerDatabase('postgres', 'postgresql', pgPool);
69
+
70
+ // MySQL
71
+ monitor.registerDatabase('mysql', 'mysql', mysqlPool);
72
+
73
+ // Redis
74
+ monitor.registerDatabase('redis', 'redis', redisClient);
75
+ ```
76
+
77
+ ### Custom Health Check
78
+
79
+ ```javascript
80
+ monitor.registerHealthCheck('api-check', async () => {
81
+ const response = await fetch('https://api.example.com/health');
82
+ return response.ok;
83
+ });
84
+ ```
85
+
86
+ ### Send Custom Alert
87
+
88
+ ```javascript
89
+ await monitor.notify('critical', 'Payment Failed',
90
+ 'Payment system is down',
91
+ { errorCode: 'PAY_001' }
92
+ );
93
+ ```
94
+
95
+ ### Async Route Handler
96
+
97
+ ```javascript
98
+ app.get('/users', monitor.asyncHandler(async (req, res) => {
99
+ const users = await User.find();
100
+ res.json(users);
101
+ }));
102
+ ```
103
+
104
+ ### Custom Error
105
+
106
+ ```javascript
107
+ const error = NodeMonitor.createError('Not found', 404);
108
+ throw error;
109
+ ```
110
+
111
+ ### Get Status
112
+
113
+ ```javascript
114
+ const status = monitor.getStatus();
115
+ console.log(status.system.cpu);
116
+ console.log(status.databases);
117
+ ```
118
+
119
+ ## Environment Variables (Most Common)
120
+
121
+ ```env
122
+ # App
123
+ MONITOR_APP_NAME=my-app
124
+ NODE_ENV=production
125
+
126
+ # Thresholds
127
+ MONITOR_CPU_THRESHOLD=80
128
+ MONITOR_MEMORY_THRESHOLD=90
129
+ MONITOR_ERROR_RATE_THRESHOLD=50
130
+
131
+ # Email
132
+ MONITOR_EMAIL_ENABLED=true
133
+ MONITOR_EMAIL_HOST=smtp.gmail.com
134
+ MONITOR_EMAIL_USER=you@gmail.com
135
+ MONITOR_EMAIL_PASS=your-password
136
+ MONITOR_EMAIL_RECIPIENTS=admin@example.com
137
+
138
+ # Slack
139
+ MONITOR_SLACK_ENABLED=true
140
+ MONITOR_SLACK_WEBHOOK=https://hooks.slack.com/...
141
+ ```
142
+
143
+ ## Monitoring Endpoints
144
+
145
+ | Endpoint | Description |
146
+ |----------|-------------|
147
+ | `/health` | Full health check |
148
+ | `/health/info` | Basic info |
149
+ | `/monitor/dashboard` | Complete dashboard |
150
+ | `/monitor/status` | Current status |
151
+ | `/monitor/system` | System info |
152
+ | `/monitor/metrics` | Metrics history |
153
+
154
+ ## Alert Levels
155
+
156
+ - **critical** - Server down, DB disconnected
157
+ - **warning** - High CPU/memory, error spike
158
+ - **info** - General information
159
+ - **recovery** - Issue resolved
160
+
161
+ ## Default Thresholds
162
+
163
+ - CPU: 80%
164
+ - Memory: 90%
165
+ - Error Rate: 50 errors/min
166
+ - Response Time: 5000ms
167
+ - Consecutive Failures: 3
168
+
169
+ ## Default Intervals
170
+
171
+ - Health Check: 60 seconds
172
+ - System Check: 5 minutes
173
+ - Database Check: 2 minutes
174
+
175
+ ## Supported Databases
176
+
177
+ - MongoDB (via Mongoose)
178
+ - PostgreSQL
179
+ - MySQL
180
+ - Redis
181
+
182
+ ## Log Levels
183
+
184
+ - error
185
+ - warn
186
+ - info
187
+ - debug
188
+ - verbose
189
+
190
+ ## Tips
191
+
192
+ 1. **Start simple** - Begin with basic error tracking, add features as needed
193
+ 2. **Test notifications** - Send test alerts before going to production
194
+ 3. **Adjust thresholds** - Fine-tune based on your app's normal behavior
195
+ 4. **Use cooldowns** - Prevent alert spam with appropriate cooldown periods
196
+ 5. **Monitor the monitor** - Check logs to ensure monitoring is working
197
+ 6. **Graceful shutdown** - Always call `setupGracefulShutdown(server)`
198
+
199
+ ## Common Patterns
200
+
201
+ ### Full Express Setup
202
+
203
+ ```javascript
204
+ const monitor = new NodeMonitor({
205
+ app: { name: 'My App', version: '1.0.0' },
206
+ thresholds: { cpu: 75, memory: 85 },
207
+ notifications: { email: { /* config */ } }
208
+ });
209
+
210
+ app.use(express.json());
211
+ app.use(monitor.requestLogger());
212
+
213
+ // Routes
214
+ app.get('/health', monitor.healthCheckEndpoint());
215
+ app.get('/', (req, res) => res.json({ ok: true }));
216
+
217
+ // Error handling
218
+ app.use(monitor.notFoundHandler());
219
+ app.use(monitor.errorMiddleware());
220
+
221
+ const server = app.listen(3000, () => {
222
+ monitor.start();
223
+ monitor.setupGracefulShutdown(server);
224
+ });
225
+ ```
226
+
227
+ ### Production Config
228
+
229
+ ```javascript
230
+ const monitor = new NodeMonitor({
231
+ intervals: { health: 30000, system: 60000 },
232
+ thresholds: { cpu: 75, memory: 85, errorRate: 25 },
233
+ notifications: {
234
+ cooldown: 180000,
235
+ email: { enabled: true, /* ... */ },
236
+ slack: { enabled: true, /* ... */ }
237
+ },
238
+ logging: {
239
+ level: 'info',
240
+ format: 'json',
241
+ console: false
242
+ }
243
+ });
244
+ ```
245
+
246
+ ## Need Help?
247
+
248
+ - ๐Ÿ“– Full docs: `README.md`
249
+ - ๐Ÿ”ง Setup guide: `SETUP_GUIDE.md`
250
+ - ๐Ÿ’ก Examples: `examples/express-app.js`
251
+ - ๐Ÿ› Issues: GitHub Issues
252
+