pms_md 1.0.4 → 1.0.5

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.
@@ -1,582 +0,0 @@
1
- # 🗄️ Complete Database Support Guide
2
-
3
- ## ✅ Supported Databases (v1.0.3)
4
-
5
- The `pms_md` package now supports **15+ database types** with automatic health monitoring, connection checks, and statistics tracking.
6
-
7
- ---
8
-
9
- ## 📊 Database Support Matrix
10
-
11
- | Database | Type | Package | Status | Stats Support |
12
- |----------|------|---------|--------|---------------|
13
- | **MongoDB** | NoSQL | `mongoose` or `mongodb` | ✅ Full | ✅ Yes |
14
- | **PostgreSQL** | SQL | `pg` | ✅ Full | ✅ Yes |
15
- | **MySQL** | SQL | `mysql2` | ✅ Full | ✅ Yes |
16
- | **MariaDB** | SQL | `mariadb` | ✅ Full | ✅ Yes |
17
- | **MSSQL** | SQL | `mssql` or `tedious` | ✅ Full | ✅ Yes |
18
- | **SQLite** | SQL | `sqlite3` or `better-sqlite3` | ✅ Full | ✅ Yes |
19
- | **Sequelize** | ORM | `sequelize` | ✅ Full | ✅ Yes |
20
- | **Redis** | Cache | `ioredis` | ✅ Full | ✅ Yes |
21
- | **CouchDB** | NoSQL | `nano` | ✅ Full | ✅ Yes |
22
- | **Cassandra** | NoSQL | `cassandra-driver` | ✅ Full | ✅ Yes |
23
- | **Elasticsearch** | Search | `@elastic/elasticsearch` | ✅ Full | ✅ Yes |
24
- | **DynamoDB** | NoSQL | `@aws-sdk/client-dynamodb` or `aws-sdk` | ✅ Full | ✅ Yes |
25
- | **Neo4j** | Graph | `neo4j-driver` | ✅ Full | ✅ Yes |
26
-
27
- ---
28
-
29
- ## 🚀 Quick Start Examples
30
-
31
- ### 1. MongoDB / Mongoose
32
-
33
- ```javascript
34
- const mongoose = require('mongoose');
35
- const NodeMonitor = require('pms_md');
36
-
37
- await mongoose.connect('mongodb://localhost:27017/mydb');
38
-
39
- const monitor = new NodeMonitor();
40
- monitor.registerDatabase('mongodb', 'mongoose', mongoose.connection);
41
- monitor.start();
42
- ```
43
-
44
- ### 2. PostgreSQL
45
-
46
- ```javascript
47
- const { Pool } = require('pg');
48
- const NodeMonitor = require('pms_md');
49
-
50
- const pool = new Pool({
51
- host: 'localhost',
52
- database: 'mydb',
53
- user: 'postgres',
54
- password: 'password'
55
- });
56
-
57
- const monitor = new NodeMonitor();
58
- monitor.registerDatabase('postgres', 'postgresql', pool);
59
- monitor.start();
60
- ```
61
-
62
- ### 3. MySQL / MySQL2
63
-
64
- ```javascript
65
- const mysql = require('mysql2/promise');
66
- const NodeMonitor = require('pms_md');
67
-
68
- const pool = mysql.createPool({
69
- host: 'localhost',
70
- user: 'root',
71
- password: 'password',
72
- database: 'mydb'
73
- });
74
-
75
- const monitor = new NodeMonitor();
76
- monitor.registerDatabase('mysql', 'mysql2', pool);
77
- monitor.start();
78
- ```
79
-
80
- ### 4. MariaDB
81
-
82
- ```javascript
83
- const mariadb = require('mariadb');
84
- const NodeMonitor = require('pms_md');
85
-
86
- const pool = mariadb.createPool({
87
- host: 'localhost',
88
- user: 'root',
89
- password: 'password',
90
- database: 'mydb'
91
- });
92
-
93
- const monitor = new NodeMonitor();
94
- monitor.registerDatabase('mariadb', 'mariadb', pool);
95
- monitor.start();
96
- ```
97
-
98
- ### 5. MSSQL (Microsoft SQL Server)
99
-
100
- ```javascript
101
- const sql = require('mssql');
102
- const NodeMonitor = require('pms_md');
103
-
104
- const pool = await sql.connect({
105
- server: 'localhost',
106
- database: 'mydb',
107
- user: 'sa',
108
- password: 'YourPassword123',
109
- options: {
110
- encrypt: true,
111
- trustServerCertificate: true
112
- }
113
- });
114
-
115
- const monitor = new NodeMonitor();
116
- monitor.registerDatabase('mssql', 'mssql', pool);
117
- monitor.start();
118
- ```
119
-
120
- ### 6. SQLite
121
-
122
- ```javascript
123
- // Option A: sqlite3
124
- const sqlite3 = require('sqlite3').verbose();
125
- const NodeMonitor = require('pms_md');
126
-
127
- const db = new sqlite3.Database('./mydb.sqlite');
128
-
129
- const monitor = new NodeMonitor();
130
- monitor.registerDatabase('sqlite', 'sqlite3', db);
131
- monitor.start();
132
-
133
- // Option B: better-sqlite3
134
- const Database = require('better-sqlite3');
135
- const db = new Database('./mydb.sqlite');
136
-
137
- monitor.registerDatabase('sqlite', 'sqlite3', db);
138
- ```
139
-
140
- ### 7. Sequelize (Multi-Database ORM)
141
-
142
- ```javascript
143
- const { Sequelize } = require('sequelize');
144
- const NodeMonitor = require('pms_md');
145
-
146
- // Works with MySQL, PostgreSQL, SQLite, MSSQL
147
- const sequelize = new Sequelize('database', 'username', 'password', {
148
- host: 'localhost',
149
- dialect: 'mysql' // or 'postgres', 'sqlite', 'mssql'
150
- });
151
-
152
- const monitor = new NodeMonitor();
153
- monitor.registerDatabase('mydb', 'sequelize', sequelize);
154
- monitor.start();
155
- ```
156
-
157
- ### 8. Redis
158
-
159
- ```javascript
160
- const Redis = require('ioredis');
161
- const NodeMonitor = require('pms_md');
162
-
163
- const redis = new Redis({
164
- host: 'localhost',
165
- port: 6379,
166
- password: 'your-password'
167
- });
168
-
169
- const monitor = new NodeMonitor();
170
- monitor.registerDatabase('redis', 'redis', redis);
171
- monitor.start();
172
- ```
173
-
174
- ### 9. CouchDB
175
-
176
- ```javascript
177
- const nano = require('nano');
178
- const NodeMonitor = require('pms_md');
179
-
180
- const couch = nano('http://admin:password@localhost:5984');
181
-
182
- const monitor = new NodeMonitor();
183
- monitor.registerDatabase('couchdb', 'nano', couch);
184
- monitor.start();
185
- ```
186
-
187
- ### 10. Cassandra
188
-
189
- ```javascript
190
- const cassandra = require('cassandra-driver');
191
- const NodeMonitor = require('pms_md');
192
-
193
- const client = new cassandra.Client({
194
- contactPoints: ['localhost'],
195
- localDataCenter: 'datacenter1',
196
- keyspace: 'mykeyspace'
197
- });
198
-
199
- await client.connect();
200
-
201
- const monitor = new NodeMonitor();
202
- monitor.registerDatabase('cassandra', 'cassandra', client);
203
- monitor.start();
204
- ```
205
-
206
- ### 11. Elasticsearch
207
-
208
- ```javascript
209
- const { Client } = require('@elastic/elasticsearch');
210
- const NodeMonitor = require('pms_md');
211
-
212
- const client = new Client({
213
- node: 'http://localhost:9200',
214
- auth: {
215
- username: 'elastic',
216
- password: 'password'
217
- }
218
- });
219
-
220
- const monitor = new NodeMonitor();
221
- monitor.registerDatabase('elasticsearch', 'elasticsearch', client);
222
- monitor.start();
223
- ```
224
-
225
- ### 12. DynamoDB
226
-
227
- ```javascript
228
- // AWS SDK v3 (Recommended)
229
- const { DynamoDBClient } = require('@aws-sdk/client-dynamodb');
230
- const NodeMonitor = require('pms_md');
231
-
232
- const client = new DynamoDBClient({
233
- region: 'us-east-1',
234
- credentials: {
235
- accessKeyId: 'YOUR_ACCESS_KEY',
236
- secretAccessKey: 'YOUR_SECRET_KEY'
237
- }
238
- });
239
-
240
- const monitor = new NodeMonitor();
241
- monitor.registerDatabase('dynamodb', 'dynamodb', client);
242
- monitor.start();
243
-
244
- // AWS SDK v2
245
- const AWS = require('aws-sdk');
246
- const dynamodb = new AWS.DynamoDB({ region: 'us-east-1' });
247
- monitor.registerDatabase('dynamodb', 'dynamodb', dynamodb);
248
- ```
249
-
250
- ### 13. Neo4j
251
-
252
- ```javascript
253
- const neo4j = require('neo4j-driver');
254
- const NodeMonitor = require('pms_md');
255
-
256
- const driver = neo4j.driver(
257
- 'bolt://localhost:7687',
258
- neo4j.auth.basic('neo4j', 'password')
259
- );
260
-
261
- const monitor = new NodeMonitor();
262
- monitor.registerDatabase('neo4j', 'neo4j', driver);
263
- monitor.start();
264
-
265
- // Don't forget to close the driver when done
266
- // await driver.close();
267
- ```
268
-
269
- ---
270
-
271
- ## 📊 Getting Database Statistics
272
-
273
- ```javascript
274
- // Get stats for any registered database
275
- const stats = await monitor.getDatabaseStats('database-name');
276
-
277
- // MongoDB stats
278
- {
279
- type: 'mongodb',
280
- collections: 10,
281
- dataSize: 1048576,
282
- indexes: 15,
283
- indexSize: 204800
284
- }
285
-
286
- // PostgreSQL stats
287
- {
288
- type: 'postgresql',
289
- activeConnections: 5
290
- }
291
-
292
- // MySQL/MariaDB stats
293
- {
294
- type: 'mysql',
295
- threadsConnected: 3
296
- }
297
-
298
- // MSSQL stats
299
- {
300
- type: 'mssql',
301
- version: 'Microsoft SQL Server 2019...',
302
- connections: 10,
303
- connected: true
304
- }
305
-
306
- // SQLite stats
307
- {
308
- type: 'sqlite',
309
- database: '/path/to/mydb.sqlite',
310
- inTransaction: false
311
- }
312
-
313
- // Redis stats
314
- {
315
- type: 'redis',
316
- connectedClients: '2',
317
- usedMemory: '1.5M',
318
- uptime: '86400'
319
- }
320
-
321
- // Cassandra stats
322
- {
323
- type: 'cassandra',
324
- connectedHosts: 3,
325
- hosts: ['192.168.1.1', '192.168.1.2', '192.168.1.3'],
326
- keyspaces: 5
327
- }
328
-
329
- // Elasticsearch stats
330
- {
331
- type: 'elasticsearch',
332
- clusterName: 'my-cluster',
333
- status: 'green',
334
- numberOfNodes: 3,
335
- activeShards: 10,
336
- version: '8.5.0'
337
- }
338
-
339
- // DynamoDB stats
340
- {
341
- type: 'dynamodb',
342
- tableCount: 15
343
- }
344
-
345
- // Neo4j stats
346
- {
347
- type: 'neo4j',
348
- version: '5.0.0',
349
- address: 'localhost:7687',
350
- edition: 'community'
351
- }
352
- ```
353
-
354
- ---
355
-
356
- ## 🔔 Automatic Monitoring Features
357
-
358
- All registered databases get:
359
-
360
- ### ✅ Connection Health Checks
361
- - Automatic periodic connection checks (every 1 minute by default)
362
- - Configurable check intervals
363
-
364
- ### ✅ Email Notifications
365
- - **Connection Lost**: Critical alert when database connection fails
366
- - **Connection Restored**: Recovery notification when connection is back
367
- - Consecutive failure tracking
368
-
369
- ### ✅ Logging
370
- - All connection checks logged with Winston
371
- - Error details captured and logged
372
- - System-wide monitoring integration
373
-
374
- ### ✅ Health Endpoints
375
- ```javascript
376
- // Check all database statuses
377
- app.get('/health', monitor.healthCheckEndpoint());
378
-
379
- // Get detailed health info
380
- app.get('/health/info', monitor.healthInfoEndpoint());
381
-
382
- // Get monitoring status
383
- const status = monitor.getStatus();
384
- console.log(status.databases);
385
- // {
386
- // mongodb: { type: 'mongoose', connected: true, consecutiveFailures: 0 },
387
- // postgres: { type: 'postgresql', connected: true, consecutiveFailures: 0 },
388
- // mssql: { type: 'mssql', connected: true, consecutiveFailures: 0 }
389
- // }
390
- ```
391
-
392
- ---
393
-
394
- ## 📦 Installation
395
-
396
- Install only the database drivers you need:
397
-
398
- ```bash
399
- # Core package
400
- npm install pms_md
401
-
402
- # MongoDB
403
- npm install mongoose
404
-
405
- # PostgreSQL
406
- npm install pg
407
-
408
- # MySQL
409
- npm install mysql2
410
-
411
- # MariaDB
412
- npm install mariadb
413
-
414
- # MSSQL
415
- npm install mssql
416
- # or
417
- npm install tedious
418
-
419
- # SQLite
420
- npm install sqlite3
421
- # or
422
- npm install better-sqlite3
423
-
424
- # Sequelize (ORM)
425
- npm install sequelize
426
-
427
- # Redis
428
- npm install ioredis
429
-
430
- # CouchDB
431
- npm install nano
432
-
433
- # Cassandra
434
- npm install cassandra-driver
435
-
436
- # Elasticsearch
437
- npm install @elastic/elasticsearch
438
-
439
- # DynamoDB
440
- npm install @aws-sdk/client-dynamodb
441
- # or
442
- npm install aws-sdk
443
-
444
- # Neo4j
445
- npm install neo4j-driver
446
- ```
447
-
448
- ---
449
-
450
- ## ⚙️ Configuration
451
-
452
- ```javascript
453
- const monitor = new NodeMonitor({
454
- database: {
455
- enabled: true,
456
- queryTimeout: 5000 // 5 seconds timeout for health checks
457
- },
458
- intervals: {
459
- database: 60000 // Check every 60 seconds (1 minute)
460
- },
461
- thresholds: {
462
- consecutiveFailures: 3 // Send alert after 3 consecutive failures
463
- },
464
- notifications: {
465
- email: {
466
- enabled: true,
467
- recipients: ['admin@example.com']
468
- }
469
- }
470
- });
471
- ```
472
-
473
- ---
474
-
475
- ## 🎯 Best Practices
476
-
477
- 1. **Register databases after connection**: Always register databases after they're successfully connected
478
- 2. **Use connection pools**: For SQL databases, use connection pools for better performance
479
- 3. **Handle errors**: Wrap database connections in try-catch blocks
480
- 4. **Monitor in production**: Enable monitoring in production environments
481
- 5. **Set appropriate timeouts**: Configure query timeouts based on your database performance
482
- 6. **Use health endpoints**: Integrate health endpoints with load balancers and orchestrators
483
-
484
- ---
485
-
486
- ## 📝 Example: Multi-Database Application
487
-
488
- ```javascript
489
- const NodeMonitor = require('pms_md');
490
- const mongoose = require('mongoose');
491
- const { Pool } = require('pg');
492
- const Redis = require('ioredis');
493
- const sql = require('mssql');
494
-
495
- // Initialize monitor
496
- const monitor = new NodeMonitor({
497
- notifications: {
498
- email: {
499
- enabled: true,
500
- recipients: ['admin@example.com']
501
- }
502
- }
503
- });
504
-
505
- // Connect to MongoDB
506
- await mongoose.connect('mongodb://localhost:27017/myapp');
507
- monitor.registerDatabase('mongodb', 'mongoose', mongoose.connection);
508
-
509
- // Connect to PostgreSQL
510
- const pgPool = new Pool({ connectionString: 'postgresql://...' });
511
- monitor.registerDatabase('postgres', 'postgresql', pgPool);
512
-
513
- // Connect to Redis
514
- const redis = new Redis();
515
- monitor.registerDatabase('redis', 'redis', redis);
516
-
517
- // Connect to MSSQL
518
- const mssqlPool = await sql.connect({ server: 'localhost', database: 'mydb' });
519
- monitor.registerDatabase('mssql', 'mssql', mssqlPool);
520
-
521
- // Start monitoring all databases
522
- monitor.start();
523
-
524
- // Express app
525
- const app = express();
526
- app.use(monitor.requestLogger());
527
- app.get('/health', monitor.healthCheckEndpoint());
528
-
529
- // Graceful shutdown
530
- const server = app.listen(3000);
531
- monitor.setupGracefulShutdown(server);
532
- ```
533
-
534
- ---
535
-
536
- ## 🆘 Troubleshooting
537
-
538
- ### Database not connecting?
539
- - Check connection credentials
540
- - Verify database server is running
541
- - Check firewall rules
542
- - Review connection timeout settings
543
-
544
- ### Not receiving alerts?
545
- - Verify email configuration in `.env`
546
- - Check `consecutiveFailures` threshold
547
- - Review notification settings
548
- - Check email logs
549
-
550
- ### Stats not working?
551
- - Ensure database user has proper permissions
552
- - Some stats require admin/elevated privileges
553
- - Check database-specific documentation
554
-
555
- ---
556
-
557
- ## 📚 Additional Resources
558
-
559
- - [Main README](README.md)
560
- - [MySQL2 & Sequelize Guide](MYSQL2_SEQUELIZE_SUPPORT.md)
561
- - [Package Analysis](PACKAGE_ANALYSIS.md)
562
- - [Setup Guide](node-monitor/SETUP_GUIDE.md)
563
-
564
- ---
565
-
566
- ## 🎉 Summary
567
-
568
- **Version 1.0.3** adds support for:
569
- - ✅ MSSQL (Microsoft SQL Server)
570
- - ✅ MariaDB
571
- - ✅ SQLite
572
- - ✅ CouchDB
573
- - ✅ Cassandra
574
- - ✅ Elasticsearch
575
- - ✅ DynamoDB
576
- - ✅ Neo4j
577
-
578
- **Total: 13+ database types supported!**
579
-
580
- All with automatic health monitoring, email notifications, and statistics tracking! 🚀
581
-
582
-