pms_md 1.0.0
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/README.md +93 -0
- package/node-monitor/ARCHITECTURE.md +341 -0
- package/node-monitor/CHANGELOG.md +105 -0
- package/node-monitor/CONTRIBUTING.md +96 -0
- package/node-monitor/DESIGN_IMPROVEMENTS.md +286 -0
- package/node-monitor/FILTER_BUTTONS_FIX.md +303 -0
- package/node-monitor/GETTING_STARTED.md +416 -0
- package/node-monitor/INSTALLATION.md +470 -0
- package/node-monitor/LICENSE +22 -0
- package/node-monitor/PUBLISHING_GUIDE.md +331 -0
- package/node-monitor/QUICK_REFERENCE.md +252 -0
- package/node-monitor/README.md +458 -0
- package/node-monitor/READY_TO_PUBLISH.md +272 -0
- package/node-monitor/SETUP_GUIDE.md +479 -0
- package/node-monitor/examples/EMAIL_SETUP_GUIDE.md +282 -0
- package/node-monitor/examples/ERROR_LOGGING_GUIDE.md +405 -0
- package/node-monitor/examples/GET_APP_PASSWORD.md +145 -0
- package/node-monitor/examples/LOG_FILES_REFERENCE.md +336 -0
- package/node-monitor/examples/QUICK_START_EMAIL.md +126 -0
- package/node-monitor/examples/express-app.js +499 -0
- package/node-monitor/examples/package-lock.json +1295 -0
- package/node-monitor/examples/package.json +18 -0
- package/node-monitor/examples/public/css/style.css +718 -0
- package/node-monitor/examples/public/js/dashboard.js +207 -0
- package/node-monitor/examples/public/js/health.js +114 -0
- package/node-monitor/examples/public/js/main.js +89 -0
- package/node-monitor/examples/public/js/metrics.js +225 -0
- package/node-monitor/examples/public/js/theme.js +138 -0
- package/node-monitor/examples/views/dashboard.ejs +20 -0
- package/node-monitor/examples/views/error-logs.ejs +1129 -0
- package/node-monitor/examples/views/health.ejs +21 -0
- package/node-monitor/examples/views/home.ejs +341 -0
- package/node-monitor/examples/views/layout.ejs +50 -0
- package/node-monitor/examples/views/metrics.ejs +16 -0
- package/node-monitor/examples/views/partials/footer.ejs +16 -0
- package/node-monitor/examples/views/partials/header.ejs +35 -0
- package/node-monitor/examples/views/partials/nav.ejs +23 -0
- package/node-monitor/examples/views/status.ejs +390 -0
- package/node-monitor/package-lock.json +4300 -0
- package/node-monitor/package.json +76 -0
- package/node-monitor/pre-publish-check.js +200 -0
- package/node-monitor/src/config/monitoringConfig.js +255 -0
- package/node-monitor/src/index.js +300 -0
- package/node-monitor/src/logger/errorLogger.js +297 -0
- package/node-monitor/src/monitors/apiErrorMonitor.js +156 -0
- package/node-monitor/src/monitors/dbConnectionMonitor.js +389 -0
- package/node-monitor/src/monitors/serverHealthMonitor.js +320 -0
- package/node-monitor/src/monitors/systemResourceMonitor.js +357 -0
- package/node-monitor/src/notifiers/emailNotifier.js +248 -0
- package/node-monitor/src/notifiers/notificationManager.js +96 -0
- package/node-monitor/src/notifiers/slackNotifier.js +209 -0
- package/node-monitor/src/views/dashboard.html +530 -0
- package/node-monitor/src/views/health.html +399 -0
- package/node-monitor/src/views/metrics.html +406 -0
- package/package.json +22 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
# 📧 Email Notification Setup Guide
|
|
2
|
+
|
|
3
|
+
## 🎯 Overview
|
|
4
|
+
|
|
5
|
+
Your Node Monitor is now configured to send email notifications to **manish.proses@gmail.com** for:
|
|
6
|
+
- ✅ Server errors and crashes
|
|
7
|
+
- ✅ API errors
|
|
8
|
+
- ✅ High CPU usage (>75%)
|
|
9
|
+
- ✅ High memory usage (>85%)
|
|
10
|
+
- ✅ High error rates (>10 errors/minute)
|
|
11
|
+
- ✅ Slow response times (>3 seconds)
|
|
12
|
+
- ✅ Database connection failures
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 🔐 Step 1: Get Gmail App Password
|
|
17
|
+
|
|
18
|
+
Since you're using Gmail, you need to create an **App Password** (not your regular Gmail password).
|
|
19
|
+
|
|
20
|
+
### Instructions:
|
|
21
|
+
|
|
22
|
+
1. **Enable 2-Step Verification** (if not already enabled):
|
|
23
|
+
- Go to: https://myaccount.google.com/security
|
|
24
|
+
- Click on "2-Step Verification"
|
|
25
|
+
- Follow the setup process
|
|
26
|
+
|
|
27
|
+
2. **Create App Password**:
|
|
28
|
+
- Go to: https://myaccount.google.com/apppasswords
|
|
29
|
+
- Select app: **Mail**
|
|
30
|
+
- Select device: **Other (Custom name)**
|
|
31
|
+
- Enter name: **Node Monitor**
|
|
32
|
+
- Click **Generate**
|
|
33
|
+
|
|
34
|
+
3. **Copy the 16-character password**:
|
|
35
|
+
- It will look like: `abcd efgh ijkl mnop`
|
|
36
|
+
- Remove spaces: `abcdefghijklmnop`
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## 📝 Step 2: Update .env File
|
|
41
|
+
|
|
42
|
+
Open the file: `node-monitor/examples/.env`
|
|
43
|
+
|
|
44
|
+
Replace this line:
|
|
45
|
+
```env
|
|
46
|
+
EMAIL_APP_PASSWORD=your-gmail-app-password-here
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
With your actual App Password:
|
|
50
|
+
```env
|
|
51
|
+
EMAIL_APP_PASSWORD=abcdefghijklmnop
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
**IMPORTANT:**
|
|
55
|
+
- ✅ Remove all spaces from the password
|
|
56
|
+
- ✅ Keep the .env file secure (it's already in .gitignore)
|
|
57
|
+
- ❌ Never commit this file to Git
|
|
58
|
+
- ❌ Never share this password
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 🚀 Step 3: Restart the Server
|
|
63
|
+
|
|
64
|
+
After updating the .env file, restart your server:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
cd node-monitor/examples
|
|
68
|
+
node express-app.js
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## 🧪 Step 4: Test Email Notifications
|
|
74
|
+
|
|
75
|
+
### Test 1: Manual Test Notification
|
|
76
|
+
|
|
77
|
+
Open your browser and visit:
|
|
78
|
+
```
|
|
79
|
+
http://localhost:3001/api/notify-test
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Or use curl:
|
|
83
|
+
```bash
|
|
84
|
+
curl http://localhost:3001/api/notify-test
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
You should receive an email with subject: **[Example Express App] Test Notification**
|
|
88
|
+
|
|
89
|
+
### Test 2: Trigger an Error
|
|
90
|
+
|
|
91
|
+
Click the "✗ Error" button on the home page, or visit:
|
|
92
|
+
```
|
|
93
|
+
http://localhost:3001/api/error
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
After 2 consecutive errors, you'll receive an email alert.
|
|
97
|
+
|
|
98
|
+
### Test 3: Trigger High Error Rate
|
|
99
|
+
|
|
100
|
+
Visit the error endpoint multiple times quickly:
|
|
101
|
+
```bash
|
|
102
|
+
# Run this 15 times to trigger high error rate alert
|
|
103
|
+
for i in {1..15}; do curl http://localhost:3001/api/error; done
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
You should receive an email about high error rate.
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## 📧 What Emails Will You Receive?
|
|
111
|
+
|
|
112
|
+
### 1. **Critical Alerts** (Red)
|
|
113
|
+
- Server crashes
|
|
114
|
+
- Database connection failures
|
|
115
|
+
- High error rates (>10 errors/minute)
|
|
116
|
+
- Consecutive health check failures
|
|
117
|
+
|
|
118
|
+
**Example Subject:** `[Example Express App] 🚨 Critical: High Error Rate Detected`
|
|
119
|
+
|
|
120
|
+
### 2. **Warning Alerts** (Yellow)
|
|
121
|
+
- High CPU usage (>75%)
|
|
122
|
+
- High memory usage (>85%)
|
|
123
|
+
- Slow response times (>3 seconds)
|
|
124
|
+
- Individual API errors
|
|
125
|
+
|
|
126
|
+
**Example Subject:** `[Example Express App] ⚠️ Warning: High CPU Usage`
|
|
127
|
+
|
|
128
|
+
### 3. **Info Notifications** (Blue)
|
|
129
|
+
- Server startup
|
|
130
|
+
- Test notifications
|
|
131
|
+
- Manual notifications
|
|
132
|
+
|
|
133
|
+
**Example Subject:** `[Example Express App] ℹ️ Info: Server Started`
|
|
134
|
+
|
|
135
|
+
### 4. **Recovery Notifications** (Green)
|
|
136
|
+
- System recovered from high CPU
|
|
137
|
+
- Error rate back to normal
|
|
138
|
+
- Database connection restored
|
|
139
|
+
|
|
140
|
+
**Example Subject:** `[Example Express App] ✅ Recovery: System Healthy`
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## ⚙️ Customization
|
|
145
|
+
|
|
146
|
+
### Change Alert Thresholds
|
|
147
|
+
|
|
148
|
+
Edit `node-monitor/examples/express-app.js`:
|
|
149
|
+
|
|
150
|
+
```javascript
|
|
151
|
+
thresholds: {
|
|
152
|
+
cpu: 75, // Alert if CPU > 75% (change this)
|
|
153
|
+
memory: 85, // Alert if memory > 85% (change this)
|
|
154
|
+
errorRate: 10, // Alert if > 10 errors per minute (change this)
|
|
155
|
+
responseTime: 3000, // Alert if response time > 3 seconds (change this)
|
|
156
|
+
consecutiveFailures: 2 // Alert after 2 consecutive failures (change this)
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Change Cooldown Period
|
|
161
|
+
|
|
162
|
+
To prevent spam, there's a cooldown between alerts:
|
|
163
|
+
|
|
164
|
+
```javascript
|
|
165
|
+
notifications: {
|
|
166
|
+
enabled: true,
|
|
167
|
+
cooldown: 180000, // 3 minutes (change this)
|
|
168
|
+
// ...
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Add More Recipients
|
|
173
|
+
|
|
174
|
+
Edit `node-monitor/examples/express-app.js`:
|
|
175
|
+
|
|
176
|
+
```javascript
|
|
177
|
+
email: {
|
|
178
|
+
enabled: true,
|
|
179
|
+
// ...
|
|
180
|
+
recipients: [
|
|
181
|
+
'manish.proses@gmail.com',
|
|
182
|
+
'another-email@example.com', // Add more emails here
|
|
183
|
+
'ops-team@example.com'
|
|
184
|
+
]
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## 🔍 Troubleshooting
|
|
191
|
+
|
|
192
|
+
### Problem: Not Receiving Emails
|
|
193
|
+
|
|
194
|
+
**Check 1: Verify App Password**
|
|
195
|
+
- Make sure you copied the entire 16-character password
|
|
196
|
+
- Remove all spaces
|
|
197
|
+
- It should be in the .env file
|
|
198
|
+
|
|
199
|
+
**Check 2: Check Server Logs**
|
|
200
|
+
Look for email-related messages:
|
|
201
|
+
```bash
|
|
202
|
+
# Check if email notifier initialized
|
|
203
|
+
# You should see: "Email notifier initialized successfully"
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
**Check 3: Test Email Configuration**
|
|
207
|
+
Visit: http://localhost:3001/api/notify-test
|
|
208
|
+
|
|
209
|
+
Check the response - it should show:
|
|
210
|
+
```json
|
|
211
|
+
{
|
|
212
|
+
"message": "Test notification sent!",
|
|
213
|
+
"result": {
|
|
214
|
+
"total": 1,
|
|
215
|
+
"successful": 1,
|
|
216
|
+
"failed": 0
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
**Check 4: Gmail Security**
|
|
222
|
+
- Make sure 2-Step Verification is enabled
|
|
223
|
+
- Make sure you're using an App Password (not your regular password)
|
|
224
|
+
- Check Gmail's "Less secure app access" is NOT blocking it
|
|
225
|
+
|
|
226
|
+
### Problem: Emails Going to Spam
|
|
227
|
+
|
|
228
|
+
1. Check your Gmail spam folder
|
|
229
|
+
2. Mark the email as "Not Spam"
|
|
230
|
+
3. Add the sender to your contacts
|
|
231
|
+
|
|
232
|
+
### Problem: Too Many Emails
|
|
233
|
+
|
|
234
|
+
Increase the cooldown period:
|
|
235
|
+
```javascript
|
|
236
|
+
cooldown: 300000, // 5 minutes instead of 3
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Or increase the thresholds:
|
|
240
|
+
```javascript
|
|
241
|
+
thresholds: {
|
|
242
|
+
cpu: 90, // Only alert if CPU > 90%
|
|
243
|
+
memory: 95, // Only alert if memory > 95%
|
|
244
|
+
errorRate: 20, // Only alert if > 20 errors per minute
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## 📊 Email Content
|
|
251
|
+
|
|
252
|
+
Each email includes:
|
|
253
|
+
- **Subject:** Alert type and description
|
|
254
|
+
- **Message:** Detailed explanation
|
|
255
|
+
- **Application:** Name and version
|
|
256
|
+
- **Environment:** development/production
|
|
257
|
+
- **Hostname:** Server hostname
|
|
258
|
+
- **Timestamp:** When the alert occurred
|
|
259
|
+
- **Details:** Specific metrics (CPU %, memory %, error count, etc.)
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## 🔒 Security Best Practices
|
|
264
|
+
|
|
265
|
+
1. ✅ **Never commit .env file** - It's already in .gitignore
|
|
266
|
+
2. ✅ **Use App Passwords** - Never use your main Gmail password
|
|
267
|
+
3. ✅ **Rotate passwords** - Change App Password periodically
|
|
268
|
+
4. ✅ **Limit recipients** - Only send to authorized personnel
|
|
269
|
+
5. ✅ **Use environment variables** - Keep secrets out of code
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## 🎉 You're All Set!
|
|
274
|
+
|
|
275
|
+
Once you complete the setup:
|
|
276
|
+
1. ✅ Update .env with your Gmail App Password
|
|
277
|
+
2. ✅ Restart the server
|
|
278
|
+
3. ✅ Test with http://localhost:3001/api/notify-test
|
|
279
|
+
4. ✅ Check your email inbox
|
|
280
|
+
|
|
281
|
+
**You'll now receive email alerts for all critical issues!** 📧🚀
|
|
282
|
+
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
# 📋 API Error Logging Guide
|
|
2
|
+
|
|
3
|
+
## 🎯 Overview
|
|
4
|
+
|
|
5
|
+
Your Node Monitor now includes a comprehensive error logging system that automatically tracks, stores, and displays all API errors in a beautiful web interface.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## ✅ What's Included
|
|
10
|
+
|
|
11
|
+
### 1. **Automatic Error Logging**
|
|
12
|
+
- ✅ All API errors are automatically logged
|
|
13
|
+
- ✅ Errors saved to JSON files (one per day)
|
|
14
|
+
- ✅ Includes full error details, stack traces, request info
|
|
15
|
+
- ✅ Sensitive data automatically sanitized (passwords, tokens, etc.)
|
|
16
|
+
|
|
17
|
+
### 2. **Web-Based Error Viewer**
|
|
18
|
+
- ✅ Beautiful, interactive error log viewer
|
|
19
|
+
- ✅ View errors by date
|
|
20
|
+
- ✅ Search and filter capabilities
|
|
21
|
+
- ✅ Expandable stack traces
|
|
22
|
+
- ✅ Download logs as JSON
|
|
23
|
+
- ✅ Auto-refresh every 30 seconds
|
|
24
|
+
|
|
25
|
+
### 3. **Error Statistics**
|
|
26
|
+
- ✅ Total error count
|
|
27
|
+
- ✅ Latest error timestamp
|
|
28
|
+
- ✅ Most common error messages
|
|
29
|
+
- ✅ Error rate tracking
|
|
30
|
+
|
|
31
|
+
### 4. **Email Notifications**
|
|
32
|
+
- ✅ Instant alerts for critical errors
|
|
33
|
+
- ✅ High error rate warnings
|
|
34
|
+
- ✅ Sent to: manish.proses@gmail.com
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 🌐 Access Error Logs
|
|
39
|
+
|
|
40
|
+
### **Web Interface:**
|
|
41
|
+
```
|
|
42
|
+
http://localhost:3001/monitor/error-logs
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Or click **"🔴 Error Logs"** in the navigation menu.
|
|
46
|
+
|
|
47
|
+
### **API Endpoints:**
|
|
48
|
+
|
|
49
|
+
**Get list of log files:**
|
|
50
|
+
```
|
|
51
|
+
GET /monitor/error-logs?format=json
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
**Get specific log file:**
|
|
55
|
+
```
|
|
56
|
+
GET /monitor/error-logs/error-2025-11-12.log?format=json&limit=100
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**Download log file:**
|
|
60
|
+
```
|
|
61
|
+
GET /monitor/error-logs/error-2025-11-12.log
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## 📁 Log File Structure
|
|
67
|
+
|
|
68
|
+
### **Location:**
|
|
69
|
+
```
|
|
70
|
+
node-monitor/examples/logs/
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### **Files:**
|
|
74
|
+
- `error-YYYY-MM-DD.log` - Error logs only
|
|
75
|
+
- `application-YYYY-MM-DD.log` - All logs (info, warnings, errors)
|
|
76
|
+
|
|
77
|
+
### **Format:**
|
|
78
|
+
Each line is a JSON object:
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"level": "error",
|
|
83
|
+
"message": "API Error This is a test error",
|
|
84
|
+
"type": "API_ERROR",
|
|
85
|
+
"method": "GET",
|
|
86
|
+
"url": "/api/error",
|
|
87
|
+
"statusCode": 500,
|
|
88
|
+
"timestamp": "2025-11-12T06:00:03.618Z",
|
|
89
|
+
"ip": "::1",
|
|
90
|
+
"userAgent": "Mozilla/5.0...",
|
|
91
|
+
"headers": { ... },
|
|
92
|
+
"query": { ... },
|
|
93
|
+
"body": { ... },
|
|
94
|
+
"stack": "Error: This is a test error\n at ...",
|
|
95
|
+
"app": {
|
|
96
|
+
"name": "Example Express App",
|
|
97
|
+
"version": "1.0.0",
|
|
98
|
+
"environment": "production",
|
|
99
|
+
"hostname": "MD"
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## 🔍 Error Log Details
|
|
107
|
+
|
|
108
|
+
Each error log includes:
|
|
109
|
+
|
|
110
|
+
| Field | Description |
|
|
111
|
+
|-------|-------------|
|
|
112
|
+
| **level** | Log level (error, warn, info) |
|
|
113
|
+
| **message** | Error message |
|
|
114
|
+
| **type** | Error type (API_ERROR, SYSTEM_ERROR, etc.) |
|
|
115
|
+
| **method** | HTTP method (GET, POST, etc.) |
|
|
116
|
+
| **url** | Request URL |
|
|
117
|
+
| **statusCode** | HTTP status code (500, 404, etc.) |
|
|
118
|
+
| **timestamp** | When the error occurred (ISO 8601) |
|
|
119
|
+
| **ip** | Client IP address |
|
|
120
|
+
| **userAgent** | Client browser/app |
|
|
121
|
+
| **headers** | Request headers (sanitized) |
|
|
122
|
+
| **query** | Query parameters (sanitized) |
|
|
123
|
+
| **body** | Request body (sanitized) |
|
|
124
|
+
| **stack** | Full stack trace |
|
|
125
|
+
| **app** | Application metadata |
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## 🛡️ Security Features
|
|
130
|
+
|
|
131
|
+
### **Automatic Data Sanitization:**
|
|
132
|
+
|
|
133
|
+
Sensitive fields are automatically redacted:
|
|
134
|
+
- `password` → `***REDACTED***`
|
|
135
|
+
- `token` → `***REDACTED***`
|
|
136
|
+
- `apiKey` → `***REDACTED***`
|
|
137
|
+
- `secret` → `***REDACTED***`
|
|
138
|
+
- `authorization` → `***REDACTED***`
|
|
139
|
+
|
|
140
|
+
**Example:**
|
|
141
|
+
```json
|
|
142
|
+
{
|
|
143
|
+
"body": {
|
|
144
|
+
"username": "john@example.com",
|
|
145
|
+
"password": "***REDACTED***"
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## 📊 Using the Web Interface
|
|
153
|
+
|
|
154
|
+
### **Features:**
|
|
155
|
+
|
|
156
|
+
1. **Date Selector**
|
|
157
|
+
- Select which day's logs to view
|
|
158
|
+
- Dropdown shows all available log files
|
|
159
|
+
- Most recent logs shown first
|
|
160
|
+
|
|
161
|
+
2. **Statistics Dashboard**
|
|
162
|
+
- Total error count
|
|
163
|
+
- Latest error timestamp
|
|
164
|
+
- Most common error message
|
|
165
|
+
|
|
166
|
+
3. **Error List**
|
|
167
|
+
- Each error shown as a card
|
|
168
|
+
- Click to expand stack trace
|
|
169
|
+
- Color-coded by severity
|
|
170
|
+
|
|
171
|
+
4. **Actions**
|
|
172
|
+
- **🔄 Refresh** - Reload current log file
|
|
173
|
+
- **📥 Download** - Download log as JSON file
|
|
174
|
+
|
|
175
|
+
5. **Auto-Refresh**
|
|
176
|
+
- Automatically refreshes every 30 seconds
|
|
177
|
+
- Always shows latest errors
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## 🔧 Configuration
|
|
182
|
+
|
|
183
|
+
### **Enable/Disable Logging:**
|
|
184
|
+
|
|
185
|
+
Edit `node-monitor/examples/express-app.js`:
|
|
186
|
+
|
|
187
|
+
```javascript
|
|
188
|
+
logging: {
|
|
189
|
+
enabled: true, // Set to false to disable
|
|
190
|
+
level: 'info', // 'error', 'warn', 'info', 'debug'
|
|
191
|
+
directory: './logs', // Where to store logs
|
|
192
|
+
console: true // Also log to console
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### **Log Rotation:**
|
|
197
|
+
|
|
198
|
+
Logs are automatically rotated daily:
|
|
199
|
+
- New file created each day
|
|
200
|
+
- Old files kept for 14 days (configurable)
|
|
201
|
+
- Maximum file size: 20MB (configurable)
|
|
202
|
+
|
|
203
|
+
### **Change Retention:**
|
|
204
|
+
|
|
205
|
+
Edit `node-monitor/src/config/monitoringConfig.js`:
|
|
206
|
+
|
|
207
|
+
```javascript
|
|
208
|
+
logging: {
|
|
209
|
+
maxFiles: '14d', // Keep logs for 14 days
|
|
210
|
+
maxSize: '20m' // Max 20MB per file
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## 📧 Email Notifications
|
|
217
|
+
|
|
218
|
+
Errors trigger email notifications when:
|
|
219
|
+
|
|
220
|
+
| Condition | Threshold | Email Type |
|
|
221
|
+
|-----------|-----------|------------|
|
|
222
|
+
| Single API Error | Any error | Warning ⚠️ |
|
|
223
|
+
| High Error Rate | >10 errors/min | Critical 🚨 |
|
|
224
|
+
| Consecutive Failures | 2+ failures | Critical 🚨 |
|
|
225
|
+
|
|
226
|
+
**Cooldown:** 3 minutes between alerts (prevents spam)
|
|
227
|
+
|
|
228
|
+
**Recipient:** manish.proses@gmail.com
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## 🧪 Testing Error Logging
|
|
233
|
+
|
|
234
|
+
### **Test 1: Trigger a Single Error**
|
|
235
|
+
|
|
236
|
+
Visit: http://localhost:3001/api/error
|
|
237
|
+
|
|
238
|
+
**Expected:**
|
|
239
|
+
- Error logged to `logs/error-YYYY-MM-DD.log`
|
|
240
|
+
- Visible in Error Logs viewer
|
|
241
|
+
- Email sent (if configured)
|
|
242
|
+
|
|
243
|
+
### **Test 2: Trigger High Error Rate**
|
|
244
|
+
|
|
245
|
+
Run this command:
|
|
246
|
+
```bash
|
|
247
|
+
for ($i=1; $i -le 15; $i++) { curl http://localhost:3001/api/error }
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
**Expected:**
|
|
251
|
+
- 15 errors logged
|
|
252
|
+
- High error rate email alert
|
|
253
|
+
- All errors visible in viewer
|
|
254
|
+
|
|
255
|
+
### **Test 3: View Logs**
|
|
256
|
+
|
|
257
|
+
1. Go to: http://localhost:3001/monitor/error-logs
|
|
258
|
+
2. Select today's date
|
|
259
|
+
3. See all errors listed
|
|
260
|
+
4. Click "Show Stack Trace" to expand details
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## 📥 Exporting Logs
|
|
265
|
+
|
|
266
|
+
### **Method 1: Download from Web Interface**
|
|
267
|
+
|
|
268
|
+
1. Go to Error Logs page
|
|
269
|
+
2. Select the date
|
|
270
|
+
3. Click **"📥 Download"** button
|
|
271
|
+
4. JSON file downloads automatically
|
|
272
|
+
|
|
273
|
+
### **Method 2: API Endpoint**
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
curl http://localhost:3001/monitor/error-logs/error-2025-11-12.log -o error-log.json
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### **Method 3: Direct File Access**
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
# Copy log file
|
|
283
|
+
cp node-monitor/examples/logs/error-2025-11-12.log ./my-error-log.json
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## 🔍 Analyzing Logs
|
|
289
|
+
|
|
290
|
+
### **Using Command Line:**
|
|
291
|
+
|
|
292
|
+
**Count total errors:**
|
|
293
|
+
```bash
|
|
294
|
+
wc -l logs/error-2025-11-12.log
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
**Find specific error:**
|
|
298
|
+
```bash
|
|
299
|
+
grep "This is a test error" logs/error-2025-11-12.log
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
**Extract error messages:**
|
|
303
|
+
```bash
|
|
304
|
+
cat logs/error-2025-11-12.log | jq '.message'
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### **Using JavaScript:**
|
|
308
|
+
|
|
309
|
+
```javascript
|
|
310
|
+
const fs = require('fs');
|
|
311
|
+
|
|
312
|
+
// Read log file
|
|
313
|
+
const content = fs.readFileSync('logs/error-2025-11-12.log', 'utf8');
|
|
314
|
+
const errors = content.split('\n')
|
|
315
|
+
.filter(line => line.trim())
|
|
316
|
+
.map(line => JSON.parse(line));
|
|
317
|
+
|
|
318
|
+
// Analyze errors
|
|
319
|
+
console.log('Total errors:', errors.length);
|
|
320
|
+
console.log('Error types:', [...new Set(errors.map(e => e.type))]);
|
|
321
|
+
console.log('Status codes:', [...new Set(errors.map(e => e.statusCode))]);
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
## 🚀 Integration with Your Projects
|
|
327
|
+
|
|
328
|
+
### **Step 1: Copy the Monitoring System**
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
# Copy the entire node-monitor folder to your project
|
|
332
|
+
cp -r node-monitor /path/to/your/project/
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
### **Step 2: Install Dependencies**
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
cd /path/to/your/project
|
|
339
|
+
npm install winston winston-daily-rotate-file nodemailer
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### **Step 3: Initialize in Your App**
|
|
343
|
+
|
|
344
|
+
```javascript
|
|
345
|
+
const NodeMonitor = require('./node-monitor/src/index');
|
|
346
|
+
|
|
347
|
+
const monitor = new NodeMonitor({
|
|
348
|
+
app: {
|
|
349
|
+
name: 'Your App Name',
|
|
350
|
+
version: '1.0.0',
|
|
351
|
+
environment: process.env.NODE_ENV || 'development'
|
|
352
|
+
},
|
|
353
|
+
logging: {
|
|
354
|
+
enabled: true,
|
|
355
|
+
directory: './logs'
|
|
356
|
+
},
|
|
357
|
+
notifications: {
|
|
358
|
+
enabled: true,
|
|
359
|
+
email: {
|
|
360
|
+
enabled: true,
|
|
361
|
+
host: 'smtp.gmail.com',
|
|
362
|
+
port: 587,
|
|
363
|
+
auth: {
|
|
364
|
+
user: 'your-email@gmail.com',
|
|
365
|
+
pass: process.env.EMAIL_APP_PASSWORD
|
|
366
|
+
},
|
|
367
|
+
from: 'your-email@gmail.com',
|
|
368
|
+
recipients: ['admin@example.com']
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
// Add middleware
|
|
374
|
+
app.use(monitor.requestLogger());
|
|
375
|
+
app.use(monitor.errorMiddleware());
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
### **Step 4: Access Error Logs**
|
|
379
|
+
|
|
380
|
+
Add the error logs routes to your Express app (copy from `express-app.js`).
|
|
381
|
+
|
|
382
|
+
---
|
|
383
|
+
|
|
384
|
+
## 📚 Additional Resources
|
|
385
|
+
|
|
386
|
+
- **Quick Start:** `QUICK_START_EMAIL.md`
|
|
387
|
+
- **Email Setup:** `EMAIL_SETUP_GUIDE.md`
|
|
388
|
+
- **App Password:** `GET_APP_PASSWORD.md`
|
|
389
|
+
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
## 🎉 Summary
|
|
393
|
+
|
|
394
|
+
You now have:
|
|
395
|
+
- ✅ Automatic error logging to JSON files
|
|
396
|
+
- ✅ Beautiful web interface to view errors
|
|
397
|
+
- ✅ Email notifications for critical errors
|
|
398
|
+
- ✅ Downloadable error logs
|
|
399
|
+
- ✅ Automatic data sanitization
|
|
400
|
+
- ✅ Daily log rotation
|
|
401
|
+
- ✅ Full stack traces
|
|
402
|
+
- ✅ Error statistics and analytics
|
|
403
|
+
|
|
404
|
+
**All errors are automatically tracked and logged!** 📋🚀
|
|
405
|
+
|