pms_md 1.0.0 → 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.
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Example: Using Node Monitor with Sequelize and MySQL2
3
+ *
4
+ * This example demonstrates how to integrate the monitoring package
5
+ * with Sequelize ORM and MySQL2 database.
6
+ */
7
+
8
+ const express = require('express');
9
+ const { Sequelize } = require('sequelize');
10
+ const NodeMonitor = require('../src/index');
11
+
12
+ // Initialize Sequelize with MySQL2
13
+ const sequelize = new Sequelize('asset_tracking', 'root', 'password', {
14
+ host: 'localhost',
15
+ dialect: 'mysql',
16
+ logging: false, // Disable SQL logging
17
+ pool: {
18
+ max: 5,
19
+ min: 0,
20
+ acquire: 30000,
21
+ idle: 10000
22
+ }
23
+ });
24
+
25
+ // Initialize Node Monitor
26
+ const monitor = new NodeMonitor({
27
+ app: {
28
+ name: 'Sequelize MySQL App',
29
+ version: '1.0.0',
30
+ environment: process.env.NODE_ENV || 'development'
31
+ },
32
+ notifications: {
33
+ email: {
34
+ enabled: true,
35
+ host: 'smtp.gmail.com',
36
+ port: 587,
37
+ auth: {
38
+ user: process.env.EMAIL_USER || 'your-email@gmail.com',
39
+ pass: process.env.EMAIL_PASS || 'your-app-password'
40
+ },
41
+ from: process.env.EMAIL_USER || 'your-email@gmail.com',
42
+ recipients: [process.env.EMAIL_RECIPIENTS || 'admin@example.com']
43
+ }
44
+ },
45
+ database: {
46
+ enabled: true,
47
+ queryTimeout: 5000
48
+ }
49
+ });
50
+
51
+ // Create Express app
52
+ const app = express();
53
+ app.use(express.json());
54
+
55
+ // Add monitoring middleware
56
+ app.use(monitor.requestLogger());
57
+
58
+ // Health check endpoint
59
+ app.get('/health', monitor.healthCheckEndpoint());
60
+
61
+ // Dashboard endpoint
62
+ app.get('/dashboard', monitor.dashboardEndpoint());
63
+
64
+ // Example routes
65
+ app.get('/', (req, res) => {
66
+ res.json({
67
+ message: 'Sequelize MySQL Monitoring Example',
68
+ status: 'running'
69
+ });
70
+ });
71
+
72
+ // Example database query endpoint
73
+ app.get('/db-test', monitor.asyncHandler(async (req, res) => {
74
+ // Test database connection
75
+ await sequelize.authenticate();
76
+
77
+ // Execute a simple query
78
+ const [results] = await sequelize.query('SELECT 1 + 1 AS result');
79
+
80
+ res.json({
81
+ message: 'Database connection successful',
82
+ result: results
83
+ });
84
+ }));
85
+
86
+ // Get database stats
87
+ app.get('/db-stats', monitor.asyncHandler(async (req, res) => {
88
+ const stats = await monitor.getDatabaseStats('mysql');
89
+ res.json(stats);
90
+ }));
91
+
92
+ // Error handling middleware (must be last)
93
+ app.use(monitor.notFoundHandler());
94
+ app.use(monitor.errorMiddleware());
95
+
96
+ // Start server
97
+ async function startServer() {
98
+ try {
99
+ // Test database connection
100
+ console.log('Testing database connection...');
101
+ await sequelize.authenticate();
102
+ console.log('✅ Database connection established successfully.');
103
+
104
+ // Register database for monitoring
105
+ monitor.registerDatabase('mysql', 'sequelize', sequelize);
106
+ console.log('✅ Database registered for monitoring.');
107
+
108
+ // Register custom health check for database
109
+ monitor.registerHealthCheck('database', async () => {
110
+ try {
111
+ await sequelize.authenticate();
112
+ return true;
113
+ } catch {
114
+ return false;
115
+ }
116
+ });
117
+
118
+ // Start the server
119
+ const PORT = process.env.PORT || 3000;
120
+ const server = app.listen(PORT, () => {
121
+ console.log(`\n🚀 Server running on http://localhost:${PORT}`);
122
+ console.log(`📊 Health check: http://localhost:${PORT}/health`);
123
+ console.log(`📈 Dashboard: http://localhost:${PORT}/dashboard`);
124
+ console.log(`🔍 DB Test: http://localhost:${PORT}/db-test`);
125
+ console.log(`📊 DB Stats: http://localhost:${PORT}/db-stats\n`);
126
+
127
+ // Start monitoring
128
+ monitor.start();
129
+ console.log('✅ Monitoring started\n');
130
+
131
+ // Setup graceful shutdown
132
+ monitor.setupGracefulShutdown(server, async () => {
133
+ console.log('Closing database connection...');
134
+ await sequelize.close();
135
+ console.log('Database connection closed.');
136
+ });
137
+ });
138
+
139
+ } catch (error) {
140
+ console.error('❌ Unable to start server:', error);
141
+ process.exit(1);
142
+ }
143
+ }
144
+
145
+ // Start the application
146
+ startServer();
147
+
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectmd/node-monitor",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Comprehensive monitoring solution for Node.js applications with error tracking, health checks, and multi-channel notifications",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -47,7 +47,8 @@
47
47
  "express": "^4.18.0 || ^5.0.0",
48
48
  "mongoose": "^7.0.0 || ^8.0.0",
49
49
  "pg": "^8.11.0",
50
- "mysql2": "^3.6.0",
50
+ "mysql2": "^2.0.0 || ^3.0.0",
51
+ "sequelize": "^6.0.0",
51
52
  "ioredis": "^5.3.0"
52
53
  },
53
54
  "peerDependenciesMeta": {
@@ -63,6 +64,9 @@
63
64
  "mysql2": {
64
65
  "optional": true
65
66
  },
67
+ "sequelize": {
68
+ "optional": true
69
+ },
66
70
  "ioredis": {
67
71
  "optional": true
68
72
  }