Overview
The fraud detection system includes Flask-MonitoringDashboard for real-time monitoring of application performance, API usage, and system metrics.Dashboard Setup
Installation and Binding
The monitoring dashboard is integrated inmain.py:
- Creates the monitoring database (
flask_monitoringdashboard.db) - Registers dashboard routes
- Begins tracking all endpoints
- Collects performance metrics
Dependencies
Flask-MonitoringDashboard version 3.0.6 is included inrequirements.txt:
Accessing the Dashboard
Dashboard Endpoint
The monitoring dashboard is accessible at:First-Time Setup
On first access, you’ll be prompted to create an admin account:- Navigate to
/dashboard - Enter a username and password
- Submit to create your admin account
- Login with your credentials
Dashboard Features
Performance Tracking
The dashboard automatically tracks: Request Metrics:- Request duration (min, max, average)
- Request count per endpoint
- Response time distribution
- Slow requests identification
/(Home page)/predict(Fraud prediction)/train(Model training)
API Usage Monitoring
Request Analysis:- Total requests over time
- Requests per endpoint
- Request methods (GET, POST)
- HTTP status codes distribution
- IP address tracking
- Request timestamps
- User sessions
System Metrics
Resource Utilization:- CPU usage
- Memory consumption
- Process information
- Active workers (when using Gunicorn)
- Query performance
- Connection pooling
- Database operations
Error Tracking
Monitor exceptions and errors:- Exception types and counts
- Stack traces
- Error rate over time
- Affected endpoints
Dashboard Views
Overview Page
Provides a high-level summary:- Total requests
- Average response time
- Error rate
- CPU and memory usage graphs
Endpoint Analysis
Detailed view for each endpoint: POST /predict:- Prediction request volume
- Processing time statistics
- Success/error rates
- Recent requests
- Training job frequency
- Training duration
- Success/failure tracking
- Homepage access patterns
- Load times
Outliers Detection
Identify performance issues:- Unusually slow requests
- Timeout events
- Resource spikes
Profiler
Detailed code profiling:- Function execution times
- Call stack analysis
- Performance bottlenecks
Configuration Options
Custom Configuration
Create aconfig.cfg file for custom dashboard settings:
Loading Configuration
Updatemain.py to load custom configuration:
Security Configuration
Enable authentication:Database Management
Monitoring Database
The dashboard uses SQLite by default:- File:
flask_monitoringdashboard.db - Location: Project root directory
- Size: Grows with collected metrics
Database Maintenance
View database size:Performance Optimization
Sampling Rate
Reduce overhead by sampling requests:0: Monitor all requests (default)1: Monitor 10% of requests2: Monitor 1% of requests3: Monitor 0.1% of requests
Disable Profiling
For production with high traffic:Monitoring Best Practices
-
Set up alerts: Monitor for:
- Response time > 5 seconds
- Error rate > 5%
- CPU usage > 80%
-
Regular reviews: Check dashboard weekly for:
- Performance trends
- Unusual patterns
- Error spikes
-
Backup monitoring data: Regular backups of
flask_monitoringdashboard.db - Secure access: Use strong authentication in production
- Resource monitoring: Track dashboard’s own resource usage
Troubleshooting
Dashboard not accessible
Check if dashboard is bound:High database size
- Configure data retention policy
- Archive old metrics
- Consider using PostgreSQL for production
Performance impact
- Reduce monitoring level
- Disable profiling
- Increase sampling interval
Next Steps
- Production setup guide
- Deploy to Heroku
- Configure alerting for critical metrics
- Set up external monitoring (Datadog, New Relic)