Overview
Monitoring the MND system ensures reliability, tracks API quota usage, and helps identify issues before they affect users.Health Check Endpoint
The backend exposes a health check endpoint for uptime monitoring.Endpoint
Response
Implementation
Insrc/api/routesController.ts:
Monitoring Services
Use these services to ping/api/health periodically:
UptimeRobot (Free tier):
- Monitor up to 50 endpoints
- 5-minute interval checks
- Email/SMS alerts
- Go to uptimerobot.com
- Add New Monitor
- Type: HTTP(s)
- URL:
https://yourdomain.com/api/health - Interval: 5 minutes
- Add alert contacts
- 3-minute interval
- Incident management
- Status page
- 1-minute interval
- Performance monitoring
- Real user monitoring
API Usage Tracking
The Distance Matrix client includes built-in usage tracking.Usage Statistics
Access stats via the singleton instance:Print Statistics
Usage Limits
Configured insrc/infra/distanceMatrixClient.ts:
Quota Warnings
The client logs warnings when approaching limits:Distance Matrix Quota Management
Google Distance Matrix API has strict quota limits.Free Tier Limits
- $200 free credit/month = ~700 requests
- After that: $5-10 per 1000 requests
Quota Monitoring Endpoint
Create an endpoint to expose quota stats:Quota Alerts
Set up alerts when quota exceeds thresholds:Caching Strategy
The client caches results for 7 days to minimize API calls. Cache configuration:Error Logging
Request Logging
The server logs all requests:Error Handler
Global error handler catches unhandled errors:Structured Logging
For production, use a logging library like Winston:Performance Metrics
Request Duration
Track API response times:Route Planning Performance
Log route calculation times:PM2 Monitoring
PM2 provides built-in monitoring.Real-time Monitoring
- CPU usage
- Memory usage
- Logs (stdout/stderr)
Process List
PM2 Plus (Cloud Monitoring)
Free tier:- Real-time monitoring
- Exception tracking
- Custom metrics
Log Management
View logs:Database Monitoring
The backend uses JSON file-based storage.Monitor Data Files
Track file sizes:User Data
Monitor user database size:Alerting
Email Alerts
Send email alerts for critical events:Slack Alerts
Metrics Dashboard
Create a simple metrics endpoint:Monitoring Checklist
- Health check endpoint configured
- Uptime monitoring service added (UptimeRobot, etc.)
- Distance Matrix quota tracking enabled
- Quota alerts configured (75%, 90%)
- Request logging enabled
- Error logging configured
- PM2 monitoring active
- Log rotation configured
- Performance metrics tracked
- Alert notifications configured (email/Slack)
- Metrics dashboard accessible