pms_md 1.0.2 โ†’ 1.0.4

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,334 +0,0 @@
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/pms_md-1.0.1.tgz DELETED
Binary file
package/pms_md-1.0.2.tgz DELETED
Binary file
@@ -1,102 +0,0 @@
1
- /**
2
- * Test script to verify Sequelize monitoring support
3
- */
4
-
5
- const { Sequelize } = require('sequelize');
6
- const NodeMonitor = require('pms_md');
7
-
8
- console.log('๐Ÿงช Testing Sequelize Monitoring Support\n');
9
-
10
- // Create Sequelize instance (adjust credentials as needed)
11
- const sequelize = new Sequelize('asset_tracking', 'root', 'root', {
12
- host: 'localhost',
13
- dialect: 'mysql',
14
- logging: false,
15
- pool: {
16
- max: 5,
17
- min: 0,
18
- acquire: 30000,
19
- idle: 10000
20
- }
21
- });
22
-
23
- // Initialize monitor
24
- const monitor = new NodeMonitor({
25
- app: {
26
- name: 'Test App',
27
- version: '1.0.0',
28
- environment: 'development'
29
- },
30
- notifications: {
31
- email: {
32
- enabled: false // Disable for testing
33
- }
34
- },
35
- database: {
36
- enabled: true,
37
- queryTimeout: 5000
38
- }
39
- });
40
-
41
- async function testMonitoring() {
42
- try {
43
- console.log('1๏ธโƒฃ Testing database connection...');
44
- await sequelize.authenticate();
45
- console.log(' โœ… Database connected successfully\n');
46
-
47
- console.log('2๏ธโƒฃ Registering Sequelize instance for monitoring...');
48
- monitor.registerDatabase('mysql', 'sequelize', sequelize);
49
- console.log(' โœ… Database registered\n');
50
-
51
- console.log('3๏ธโƒฃ Starting monitoring services...');
52
- monitor.start();
53
- console.log(' โœ… Monitoring started\n');
54
-
55
- console.log('4๏ธโƒฃ Checking database connection status...');
56
- const status = monitor.getStatus();
57
- console.log(' Database Status:', JSON.stringify(status.databases, null, 2));
58
- console.log(' โœ… Status retrieved\n');
59
-
60
- console.log('5๏ธโƒฃ Getting database statistics...');
61
- const stats = await monitor.getDatabaseStats('mysql');
62
- console.log(' Database Stats:', JSON.stringify(stats, null, 2));
63
- console.log(' โœ… Stats retrieved\n');
64
-
65
- console.log('6๏ธโƒฃ Testing connection check...');
66
- await new Promise(resolve => setTimeout(resolve, 2000)); // Wait 2 seconds
67
- const statusAfter = monitor.getStatus();
68
- console.log(' Connection Status:', statusAfter.databases.mysql.connected ? 'โœ… Connected' : 'โŒ Disconnected');
69
- console.log(' Consecutive Failures:', statusAfter.databases.mysql.consecutiveFailures);
70
- console.log(' โœ… Connection check completed\n');
71
-
72
- console.log('7๏ธโƒฃ Stopping monitoring...');
73
- monitor.stop();
74
- console.log(' โœ… Monitoring stopped\n');
75
-
76
- console.log('8๏ธโƒฃ Closing database connection...');
77
- await sequelize.close();
78
- console.log(' โœ… Database connection closed\n');
79
-
80
- console.log('๐ŸŽ‰ All tests passed successfully!\n');
81
- console.log('โœ… MySQL2 and Sequelize support is working correctly!');
82
-
83
- } catch (error) {
84
- console.error('\nโŒ Test failed:', error.message);
85
- console.error('\nFull error:', error);
86
-
87
- if (error.message.includes('Unknown database')) {
88
- console.log('\n๐Ÿ’ก Tip: Make sure the "asset_tracking" database exists in MySQL');
89
- console.log(' You can create it with: CREATE DATABASE asset_tracking;');
90
- } else if (error.message.includes('Access denied')) {
91
- console.log('\n๐Ÿ’ก Tip: Check your MySQL credentials (username/password)');
92
- } else if (error.message.includes('ECONNREFUSED')) {
93
- console.log('\n๐Ÿ’ก Tip: Make sure MySQL server is running on localhost:3306');
94
- }
95
- } finally {
96
- process.exit(0);
97
- }
98
- }
99
-
100
- // Run the test
101
- testMonitoring();
102
-