pms_md 1.0.0 → 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.
@@ -0,0 +1,334 @@
1
+ # ✅ MySQL2 & Sequelize Support Added
2
+
3
+ ## 🎉 What's New in v1.0.2
4
+
5
+ Your `pms_md` monitoring package now has **full support** for:
6
+
7
+ - ✅ **MySQL2** (both promise and callback-based)
8
+ - ✅ **Sequelize ORM** (supports MySQL, PostgreSQL, SQLite, MSSQL)
9
+ - ✅ Enhanced database connection monitoring
10
+ - ✅ Automatic health checks for Sequelize instances
11
+ - ✅ Database statistics and pool information
12
+
13
+ ---
14
+
15
+ ## 📦 Installation
16
+
17
+ The package is already installed in your RFID project with version **1.0.2**.
18
+
19
+ ```bash
20
+ # Already installed
21
+ pms_md@1.0.2
22
+ ```
23
+
24
+ ---
25
+
26
+ ## 🚀 How to Use with Your RFID Project
27
+
28
+ ### Option 1: Monitor Sequelize Instance (Recommended)
29
+
30
+ ```javascript
31
+ const { Sequelize } = require('sequelize');
32
+ const NodeMonitor = require('pms_md');
33
+
34
+ // Your existing Sequelize instance
35
+ const sequelize = new Sequelize('asset_tracking', 'root', 'password', {
36
+ host: 'localhost',
37
+ dialect: 'mysql',
38
+ logging: false
39
+ });
40
+
41
+ // Initialize monitor
42
+ const monitor = new NodeMonitor({
43
+ app: {
44
+ name: 'RFID Asset Tracking',
45
+ version: '1.0.0',
46
+ environment: process.env.NODE_ENV || 'development'
47
+ },
48
+ notifications: {
49
+ email: {
50
+ enabled: true,
51
+ host: 'smtp.gmail.com',
52
+ port: 587,
53
+ auth: {
54
+ user: 'manish.proses@gmail.com',
55
+ pass: process.env.EMAIL_APP_PASSWORD
56
+ },
57
+ recipients: ['manish.proses@gmail.com']
58
+ }
59
+ }
60
+ });
61
+
62
+ // Register Sequelize for monitoring
63
+ monitor.registerDatabase('mysql', 'sequelize', sequelize);
64
+
65
+ // Start monitoring
66
+ monitor.start();
67
+ ```
68
+
69
+ ### Option 2: Monitor MySQL2 Pool Directly
70
+
71
+ ```javascript
72
+ const mysql = require('mysql2/promise');
73
+ const NodeMonitor = require('pms_md');
74
+
75
+ // Create MySQL2 pool
76
+ const pool = mysql.createPool({
77
+ host: 'localhost',
78
+ user: 'root',
79
+ password: 'password',
80
+ database: 'asset_tracking',
81
+ waitForConnections: true,
82
+ connectionLimit: 10
83
+ });
84
+
85
+ const monitor = new NodeMonitor({ /* config */ });
86
+
87
+ // Register MySQL2 pool for monitoring
88
+ monitor.registerDatabase('mysql', 'mysql2', pool);
89
+ monitor.start();
90
+ ```
91
+
92
+ ---
93
+
94
+ ## 🔍 Features
95
+
96
+ ### 1. Automatic Connection Monitoring
97
+
98
+ The monitor will automatically:
99
+ - ✅ Check database connection every minute (configurable)
100
+ - ✅ Send email alerts if connection is lost
101
+ - ✅ Send recovery notifications when connection is restored
102
+ - ✅ Track consecutive connection failures
103
+
104
+ ### 2. Database Statistics
105
+
106
+ ```javascript
107
+ // Get database stats
108
+ const stats = await monitor.getDatabaseStats('mysql');
109
+
110
+ // For Sequelize, returns:
111
+ {
112
+ type: 'sequelize',
113
+ dialect: 'mysql',
114
+ database: 'asset_tracking',
115
+ host: 'localhost',
116
+ pool: {
117
+ size: 5,
118
+ available: 3,
119
+ using: 2,
120
+ waiting: 0
121
+ }
122
+ }
123
+
124
+ // For MySQL2, returns:
125
+ {
126
+ type: 'mysql',
127
+ threadsConnected: 5
128
+ }
129
+ ```
130
+
131
+ ### 3. Health Checks
132
+
133
+ ```javascript
134
+ // Add custom database health check
135
+ monitor.registerHealthCheck('database', async () => {
136
+ try {
137
+ await sequelize.authenticate();
138
+ return true;
139
+ } catch {
140
+ return false;
141
+ }
142
+ });
143
+
144
+ // Access via endpoint
145
+ app.get('/health', monitor.healthCheckEndpoint());
146
+ ```
147
+
148
+ ### 4. Connection Status
149
+
150
+ ```javascript
151
+ const status = monitor.getStatus();
152
+ console.log(status.databases);
153
+
154
+ // Output:
155
+ {
156
+ mysql: {
157
+ type: 'sequelize',
158
+ connected: true,
159
+ consecutiveFailures: 0
160
+ }
161
+ }
162
+ ```
163
+
164
+ ---
165
+
166
+ ## 📝 Complete Integration Example
167
+
168
+ ```javascript
169
+ const express = require('express');
170
+ const { Sequelize } = require('sequelize');
171
+ const NodeMonitor = require('pms_md');
172
+
173
+ // Initialize Sequelize
174
+ const sequelize = new Sequelize('asset_tracking', 'root', 'password', {
175
+ host: 'localhost',
176
+ dialect: 'mysql'
177
+ });
178
+
179
+ // Initialize Monitor
180
+ const monitor = new NodeMonitor({
181
+ app: {
182
+ name: 'RFID Asset Tracking',
183
+ version: '1.0.0'
184
+ },
185
+ notifications: {
186
+ email: {
187
+ enabled: true,
188
+ host: 'smtp.gmail.com',
189
+ port: 587,
190
+ auth: {
191
+ user: 'manish.proses@gmail.com',
192
+ pass: process.env.EMAIL_APP_PASSWORD
193
+ },
194
+ recipients: ['manish.proses@gmail.com']
195
+ }
196
+ }
197
+ });
198
+
199
+ const app = express();
200
+ app.use(express.json());
201
+
202
+ // Add monitoring middleware
203
+ app.use(monitor.requestLogger());
204
+
205
+ // Health check endpoint
206
+ app.get('/health', monitor.healthCheckEndpoint());
207
+
208
+ // Dashboard endpoint
209
+ app.get('/admin/dashboard', monitor.dashboardEndpoint());
210
+
211
+ // Your routes
212
+ app.get('/api/assets', monitor.asyncHandler(async (req, res) => {
213
+ const assets = await Asset.findAll();
214
+ res.json(assets);
215
+ }));
216
+
217
+ // Error handling
218
+ app.use(monitor.notFoundHandler());
219
+ app.use(monitor.errorMiddleware());
220
+
221
+ // Start server
222
+ async function start() {
223
+ try {
224
+ // Connect to database
225
+ await sequelize.authenticate();
226
+ console.log('✅ Database connected');
227
+
228
+ // Register for monitoring
229
+ monitor.registerDatabase('mysql', 'sequelize', sequelize);
230
+
231
+ // Start server
232
+ const server = app.listen(9025, () => {
233
+ console.log('✅ Server running on port 9025');
234
+
235
+ // Start monitoring
236
+ monitor.start();
237
+
238
+ // Graceful shutdown
239
+ monitor.setupGracefulShutdown(server, async () => {
240
+ await sequelize.close();
241
+ });
242
+ });
243
+ } catch (error) {
244
+ console.error('❌ Failed to start:', error);
245
+ process.exit(1);
246
+ }
247
+ }
248
+
249
+ start();
250
+ ```
251
+
252
+ ---
253
+
254
+ ## 📊 What You'll Get
255
+
256
+ ### Email Notifications for:
257
+ - ❌ Database connection lost
258
+ - ✅ Database connection restored
259
+ - ⚠️ Multiple consecutive connection failures
260
+ - 🔥 Server errors and API errors
261
+
262
+ ### Monitoring Dashboard:
263
+ - 📈 Real-time database connection status
264
+ - 📊 Connection pool statistics
265
+ - 💾 Database health metrics
266
+ - 🔍 Error logs and tracking
267
+
268
+ ### Log Files:
269
+ - `logs/application-*.log` - All application logs
270
+ - `logs/error-*.log` - Error logs only
271
+ - `logs/combined-*.log` - Combined logs
272
+
273
+ ---
274
+
275
+ ## 🛠️ Configuration Options
276
+
277
+ ```javascript
278
+ const monitor = new NodeMonitor({
279
+ database: {
280
+ enabled: true, // Enable database monitoring
281
+ queryTimeout: 5000 // Query timeout in ms
282
+ },
283
+ intervals: {
284
+ database: 60000 // Check every 60 seconds
285
+ },
286
+ thresholds: {
287
+ consecutiveFailures: 3 // Alert after 3 failures
288
+ }
289
+ });
290
+ ```
291
+
292
+ ---
293
+
294
+ ## 📚 Documentation
295
+
296
+ - **Full Guide**: `node_modules/pms_md/node-monitor/examples/MYSQL_SEQUELIZE_GUIDE.md`
297
+ - **Example Code**: `node_modules/pms_md/node-monitor/examples/sequelize-mysql-example.js`
298
+ - **README**: `node_modules/pms_md/node-monitor/README.md`
299
+ - **Getting Started**: `node_modules/pms_md/node-monitor/GETTING_STARTED.md`
300
+
301
+ ---
302
+
303
+ ## ✅ Verified Working
304
+
305
+ - ✅ Package loads successfully
306
+ - ✅ Sequelize support available
307
+ - ✅ MySQL2 support available
308
+ - ✅ All monitoring features functional
309
+ - ✅ Email notifications configured
310
+
311
+ ---
312
+
313
+ ## 🎯 Next Steps
314
+
315
+ 1. **Integrate into your RFID app** - Add the monitoring code to your server
316
+ 2. **Test email notifications** - Trigger an error to test alerts
317
+ 3. **Access dashboard** - Visit `/admin/dashboard` to see metrics
318
+ 4. **Monitor logs** - Check `logs/` directory for application logs
319
+
320
+ ---
321
+
322
+ ## 💡 Tips
323
+
324
+ - Use environment variables for sensitive data (email passwords, DB credentials)
325
+ - Adjust monitoring intervals based on your needs
326
+ - Set up Slack notifications for team alerts
327
+ - Monitor the logs directory to ensure everything is working
328
+
329
+ ---
330
+
331
+ **Package Version**: 1.0.2
332
+ **Status**: ✅ Ready to use
333
+ **Support**: MySQL2, Sequelize, PostgreSQL, MongoDB, Redis
334
+
package/index.js ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * PMS_MD - Node Monitor Package
3
+ * Main entry point
4
+ *
5
+ * This package provides comprehensive monitoring solution for Node.js applications
6
+ * with error tracking, health checks, and multi-channel notifications.
7
+ *
8
+ * @author Manish Desai
9
+ * @license ISC
10
+ */
11
+
12
+ // Export the main NodeMonitor class and all components
13
+ module.exports = require('./node-monitor/src/index');
14
+
@@ -211,6 +211,41 @@ const pool = new Pool({
211
211
  monitor.registerDatabase('postgres', 'postgresql', pool);
212
212
  ```
213
213
 
214
+ **MySQL2 Example**:
215
+
216
+ ```javascript
217
+ const mysql = require('mysql2/promise');
218
+
219
+ const pool = mysql.createPool({
220
+ host: 'localhost',
221
+ user: 'root',
222
+ password: 'password',
223
+ database: 'myapp',
224
+ waitForConnections: true,
225
+ connectionLimit: 10
226
+ });
227
+
228
+ monitor.registerDatabase('mysql', 'mysql2', pool);
229
+ ```
230
+
231
+ **Sequelize Example** (Works with MySQL, PostgreSQL, SQLite, MSSQL):
232
+
233
+ ```javascript
234
+ const { Sequelize } = require('sequelize');
235
+
236
+ const sequelize = new Sequelize('database', 'username', 'password', {
237
+ host: 'localhost',
238
+ dialect: 'mysql', // or 'postgres', 'sqlite', 'mssql'
239
+ logging: false
240
+ });
241
+
242
+ // Test connection
243
+ await sequelize.authenticate();
244
+
245
+ // Register for monitoring
246
+ monitor.registerDatabase('mydb', 'sequelize', sequelize);
247
+ ```
248
+
214
249
  ### Add Custom Health Checks
215
250
 
216
251
  ```javascript
@@ -230,10 +230,28 @@ const { Pool } = require('pg');
230
230
  const pgPool = new Pool({ connectionString: 'postgresql://...' });
231
231
  monitor.registerDatabase('postgres', 'postgresql', pgPool);
232
232
 
233
- // MySQL
233
+ // MySQL2 (Promise-based)
234
234
  const mysql = require('mysql2/promise');
235
- const mysqlPool = mysql.createPool({ /* config */ });
236
- monitor.registerDatabase('mysql', 'mysql', mysqlPool);
235
+ const mysqlPool = mysql.createPool({
236
+ host: 'localhost',
237
+ user: 'root',
238
+ password: 'password',
239
+ database: 'myapp'
240
+ });
241
+ monitor.registerDatabase('mysql', 'mysql2', mysqlPool);
242
+
243
+ // MySQL2 (Callback-based)
244
+ const mysql2 = require('mysql2');
245
+ const mysqlConnection = mysql2.createConnection({ /* config */ });
246
+ monitor.registerDatabase('mysql', 'mysql2', mysqlConnection);
247
+
248
+ // Sequelize (ORM for MySQL, PostgreSQL, SQLite, MSSQL)
249
+ const { Sequelize } = require('sequelize');
250
+ const sequelize = new Sequelize('database', 'username', 'password', {
251
+ host: 'localhost',
252
+ dialect: 'mysql' // or 'postgres', 'sqlite', 'mssql'
253
+ });
254
+ monitor.registerDatabase('mydb', 'sequelize', sequelize);
237
255
 
238
256
  // Redis
239
257
  const Redis = require('ioredis');