Django package for system monitoring and alerting
Project description
Django Alert & Monitoring
A comprehensive Django package for monitoring system health, API performance, and sending automated alerts via email when issues occur.
Features
- API Error Monitoring: Automatically detect and alert on API errors (4xx, 5xx status codes)
- System Health Monitoring: Monitor CPU, memory, disk usage with configurable thresholds
- Redis Monitoring: Track Redis connection health and performance
- Log Monitoring: Parse and analyze Django application logs for errors and warnings
- Email Alerts: Send configurable email notifications to administrators
- Prometheus Integration: Export metrics for external monitoring systems
- Celery Integration: Background task monitoring and health checks
- Web Dashboard: Built-in web interface for viewing alerts and system metrics
Installation
pip install django-alert-monitoring
Or install from source:
git clone https://github.com/yourusername/django-alert-monitoring.git
cd django-alert-monitoring
pip install -e .
Quick Start
- Add to your Django
INSTALLED_APPS:
INSTALLED_APPS = [
# ... other apps
'alert_monitoring',
]
- Add the middleware to monitor API requests:
MIDDLEWARE = [
# ... other middleware
'alert_monitoring.middleware.APIMonitoringMiddleware',
]
- Configure email settings for alerts:
# settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'your-email@gmail.com'
EMAIL_HOST_PASSWORD = 'your-app-password'
# Alert monitoring settings
ALERT_MONITORING = {
'ADMIN_EMAILS': ['admin@example.com', 'dev@example.com'],
'EMAIL_SUBJECT_PREFIX': '[ALERT] ',
'API_ERROR_THRESHOLD': 10, # Alert if more than 10 errors in 5 minutes
'SYSTEM_THRESHOLDS': {
'CPU_WARNING': 80,
'CPU_CRITICAL': 95,
'MEMORY_WARNING': 85,
'MEMORY_CRITICAL': 95,
'DISK_WARNING': 90,
'DISK_CRITICAL': 98,
},
'REDIS_CHECK_INTERVAL': 60, # seconds
'LOG_CHECK_INTERVAL': 300, # seconds
}
- Run migrations:
python manage.py migrate
- Start the monitoring tasks:
python manage.py start_monitoring
Usage
API Monitoring
The middleware automatically monitors all API requests and creates alerts for:
- 4xx client errors
- 5xx server errors
- Slow response times (>5 seconds)
System Monitoring
Monitor system resources with automatic alerts:
- High CPU usage
- High memory usage
- Low disk space
Redis Monitoring
Track Redis connection health and performance metrics.
Log Monitoring
Parse Django logs for:
- ERROR level messages
- WARNING level messages
- Custom patterns
Email Alerts
Receive email notifications when:
- API errors exceed threshold
- System resources are critical
- Redis connection fails
- Log errors are detected
Web Dashboard
Access the monitoring dashboard at /monitoring/ to view:
- Current system health
- Recent alerts
- System metrics history
- Alert statistics
Management Commands
start_monitoring: Start all monitoring taskscheck_health: Run manual health checkclear_old_alerts: Remove alerts older than specified days
API Endpoints
GET /monitoring/health/: Basic health checkGET /monitoring/health/detailed/: Detailed system healthGET /monitoring/metrics/: Prometheus metricsGET /monitoring/alerts/: View alerts (requires authentication)
Configuration
Full configuration options:
ALERT_MONITORING = {
'ADMIN_EMAILS': ['admin@example.com'],
'EMAIL_SUBJECT_PREFIX': '[ALERT] ',
'API_ERROR_THRESHOLD': 10,
'API_ERROR_WINDOW': 300, # 5 minutes
'SYSTEM_THRESHOLDS': {
'CPU_WARNING': 80,
'CPU_CRITICAL': 95,
'MEMORY_WARNING': 85,
'MEMORY_CRITICAL': 95,
'DISK_WARNING': 90,
'DISK_CRITICAL': 98,
},
'REDIS_CHECK_INTERVAL': 60,
'LOG_CHECK_INTERVAL': 300,
'LOG_FILE_PATH': '/path/to/django.log',
'LOG_ERROR_PATTERNS': [
r'ERROR',
r'CRITICAL',
r'Exception',
],
'ENABLE_PROMETHEUS': True,
'PROMETHEUS_PORT': 8001,
}
Dependencies
- Django >= 3.2
- psutil >= 5.8.0
- redis >= 4.0.0
- celery >= 5.0.0
- prometheus-client >= 0.16.0
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
MIT License - see LICENSE file for details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_alert_monitoring-1.0.0.tar.gz.
File metadata
- Download URL: django_alert_monitoring-1.0.0.tar.gz
- Upload date:
- Size: 27.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d83a11a708450189bfdfbd5bb1094fa475a62d139aed9d3fbd0a4b4202aec81
|
|
| MD5 |
0d8fff4b7c12331612c149927b07b737
|
|
| BLAKE2b-256 |
a2a24cf0bf89b6a76b17540239a81ac1437fff7fb58506d23e64e1729314c985
|
File details
Details for the file django_alert_monitoring-1.0.0-py3-none-any.whl.
File metadata
- Download URL: django_alert_monitoring-1.0.0-py3-none-any.whl
- Upload date:
- Size: 29.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2531449d3da067181876dfe9a9e1cdfcb613c53998ac8439a8ecbdb82ee3d53d
|
|
| MD5 |
293a1bf2fcf183d71d121cc40be43f9e
|
|
| BLAKE2b-256 |
6c3ba647a50753ab6e851748c04cb398e99c324bdf84d4b8130f78e0e5669bca
|