pms_md 1.0.2 โ 1.0.3
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.
- package/BUILD_SUMMARY.md +257 -0
- package/CHANGELOG.md +176 -0
- package/DATABASE_SUPPORT.md +582 -0
- package/FINAL_CHECKLIST.md +210 -0
- package/PACKAGE_READY.txt +169 -0
- package/QUICK_DATABASE_REFERENCE.md +247 -0
- package/README.md +582 -57
- package/RELEASE_v1.0.3.md +237 -0
- package/node-monitor/src/monitors/dbConnectionMonitor.js +536 -4
- package/package.json +47 -3
- package/MYSQL2_SEQUELIZE_SUPPORT.md +0 -334
- package/pms_md-1.0.1.tgz +0 -0
- package/pms_md-1.0.2.tgz +0 -0
- package/test-sequelize-monitor.js +0 -102
|
@@ -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
|
-
|