Monitoring Dashboard
Fenrir v4.1.2 includes a built-in monitoring dashboard for tracking application health, traffic analysis, and alerts. The dashboard is powered by fenrir.features.init_fenrir_monitoring() and provides both a web UI and REST API endpoints.
Quick Setup
1. Enable Monitoring in Your App
1 2 3 4 5 6 7 | |
2. Configure via Environment Variables
1 2 3 4 5 6 | |
3. Access the Dashboard
Navigate to /monitoring in your browser. You will be redirected to the login page.
Default credentials:
- Username:
admin - Password:
changeme
Important: Change the default password in production using
fenrir monitoring set-passwordor by settingMONITORING_PASSWORDin your.envfile.
CLI Management
Fenrir provides CLI commands to manage the monitoring dashboard:
1 2 3 4 5 6 7 8 9 10 11 | |
Dashboard Features
Health Checks
The dashboard periodically checks the health of configured sites. Health checks run asynchronously using a thread pool to avoid blocking the event loop.
Traffic Analysis
Every incoming request is recorded with:
- Path and HTTP method
- Response status code
- Response time (milliseconds)
- Timestamp
Statistics
The dashboard provides real-time statistics:
- Total requests today vs. yesterday
- Error rate percentage
- Average response time
- Active alerts
Uptime Tracking
Uptime percentage is calculated for each monitored site based on health check history. The dashboard displays uptime status with visual indicators.
Alerts
The system generates alerts at different levels:
- Info: General information messages
- Warning: Potential issues (e.g., high response times)
- Error: Critical failures (e.g., site unreachable)
API Endpoints
All monitoring API endpoints require authentication via the monitoring_token cookie.
GET /monitoring/api/stats
Returns traffic statistics, site counts, and uptime start time.
1 2 3 4 5 6 7 8 | |
GET /monitoring/api/traffic
Returns today vs. yesterday traffic comparison.
1 2 3 4 | |
GET /monitoring/api/alerts?limit=50
Returns recent alerts.
| Parameter | Type | Default | Description |
|---|---|---|---|
limit |
int | 50 | Number of alerts to return (1-500) |
GET /monitoring/api/health
Triggers health checks on all monitored sites and returns results.
GET /monitoring/api/uptime
Returns uptime percentage for each monitored site.
1 2 3 4 5 6 | |
GET /monitoring/api/response-times?url=...&hours=24
Returns response time history for a specific site.
| Parameter | Type | Required | Description |
|---|---|---|---|
url |
string | Yes | The site URL to check |
hours |
int | No | Hours of history (max 168, default 24) |
GET /monitoring/api/hourly?hours=24
Returns hourly traffic breakdown.
| Parameter | Type | Default | Description |
|---|---|---|---|
hours |
int | 24 | Hours of history (max 720) |
GET /monitoring/api/summary
Returns a comprehensive summary with overview, sites, alerts, and hourly traffic data.
POST /monitoring/api/check
Check health of a specific site.
1 2 3 | |
Integration Example
Complete Setup with Custom Configuration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
Using CLI to Enable Monitoring
1 2 3 4 5 6 7 8 9 10 11 | |
Data Persistence
Monitoring data is stored locally in the .fenrir_monitoring/ directory:
1 2 | |
This file contains:
- Traffic logs
- Health check history
- Alert records
- Configuration state
Low-Level Monitoring API
These functions are exported from fenrir for direct use in custom monitoring integrations.
init_monitoring(app, config=None)
Initialize the monitoring system and register all monitoring routes on the app. This is the lower-level function called by init_fenrir_monitoring().
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
| Parameter | Type | Default | Description |
|---|---|---|---|
app |
Fenrir |
required | The Fenrir application instance |
config |
dict \| None |
None |
Configuration dict (falls back to env vars) |
record_request(path, method, status_code, response_time)
Record a request for traffic tracking. Called automatically by the monitoring middleware.
1 2 3 4 5 6 7 8 9 | |
| Parameter | Type | Description |
|---|---|---|
path |
str |
The request path |
method |
str |
HTTP method (GET, POST, etc.) |
status_code |
int |
Response status code |
response_time |
float |
Response time in milliseconds |
check_site_health(url)
Synchronously check the health of a single site. Returns a dict with status information.
1 2 3 4 5 | |
| Parameter | Type | Description |
|---|---|---|
url |
str |
The site URL to check |
Returns: Dict[str, Any] with url, status, response_time, and status_code fields.
check_site_health_async(url)
Asynchronously check the health of a single site using a thread pool. Preferred for use inside async handlers.
1 2 3 4 5 6 | |
| Parameter | Type | Description |
|---|---|---|
url |
str |
The site URL to check |
Returns: Dict[str, Any] — same format as check_site_health().
get_traffic_stats()
Get current traffic statistics comparing today vs. yesterday.
1 2 3 4 5 6 7 8 | |
Returns: Dict[str, Any] with today and yesterday sub-dicts containing total and errors counts.
Security Considerations
- Change default credentials before deploying to production.
- Use HTTPS in production to protect the monitoring token cookie.
- Restrict access to the
/monitoringpath using network rules or middleware. - Set a strong
MONITORING_SECRET_KEYfor secure session management. - Monitor the monitoring endpoint itself — consider adding rate limiting.
Performance Notes
- Health checks run asynchronously using
asyncio.to_thread()to avoid blocking the main event loop. - Traffic data is stored in-memory and periodically flushed to disk.
- The monitoring middleware adds minimal overhead (~0.1ms per request).