How to Monitor Your Django Application with Vigilmon
Django powers everything from Instagram to Disqus to Pinterest. It's battle-tested and reliable — but production Django apps still go down. Database connections fail, Celery workers stop processing, Redis caches become unavailable, and gunicorn workers start dying. Without monitoring, you find out from your users.
This guide shows you how to add production-grade monitoring to your Django application using Vigilmon — a free uptime monitoring platform for developers.
Installing django-health-check (Recommended)
The fastest way to add health endpoints to Django is django-health-check:
pip install django-health-check
Add to INSTALLED_APPS:
# settings.py
INSTALLED_APPS = [
# ... existing apps
'health_check',
'health_check.db', # Checks the default database
'health_check.cache', # Checks the cache backend
'health_check.storage', # Checks file storage
'health_check.contrib.celery', # Checks Celery (if used)
'health_check.contrib.redis', # Checks Redis (if used)
]
Add to urls.py:
from django.urls import include, path
urlpatterns = [
# ... existing URLs
path('health/', include('health_check.urls')),
]
Now GET /health/ returns:
- 200 OK with all checks passing
- 500 if any check fails
{
"DatabaseBackend": "working",
"DefaultFileStorageHealthCheck": "working",
"CacheBackend": "working",
"CeleryHealthCheck": "working",
"RedisHealthCheck": "working"
}
Custom Health Endpoint (Manual Approach)
If you prefer a lightweight custom endpoint:
# views.py
from django.http import JsonResponse
from django.db import connections
from django.db.utils import OperationalError
from django.core.cache import cache
import logging
logger = logging.getLogger(__name__)
def health_check(request):
checks = {}
http_status = 200
# Check database
try:
db_conn = connections['default']
db_conn.cursor().execute('SELECT 1')
checks['db'] = 'ok'
except OperationalError as e:
logger.error(f'DB health check failed: {e}')
checks['db'] = 'error'
http_status = 503
# Check cache (Redis/Memcache)
try:
cache.set('health_check', 'ok', timeout=10)
value = cache.get('health_check')
if value == 'ok':
checks['cache'] = 'ok'
else:
raise Exception('Cache get/set mismatch')
except Exception as e:
logger.error(f'Cache health check failed: {e}')
checks['cache'] = 'error'
http_status = 503
checks['status'] = 'ok' if http_status == 200 else 'degraded'
return JsonResponse(checks, status=http_status)
# urls.py
from . import views
urlpatterns = [
path('health/', views.health_check, name='health_check'),
]
Setting Up Vigilmon for Django
- Sign up at vigilmon.online
-
Add HTTP Monitor →
https://yourapp.com/health/ - Check interval: 1 minute
- Expected status: 200
- Configure alerts: Slack, email, or PagerDuty
Vigilmon checks from multiple global regions — you won't get false alerts from regional network blips.
Monitoring Django + Celery
Celery worker failures are particularly sneaky — your app responds normally but background tasks queue up silently. Monitor Celery health with:
# views.py
from celery.app.control import Inspect
from django.http import JsonResponse
def celery_health(request):
try:
i = Inspect(timeout=3)
active_workers = i.active()
if active_workers is None:
return JsonResponse(
{'status': 'error', 'celery': 'no_workers'},
status=503
)
worker_count = len(active_workers)
return JsonResponse({
'status': 'ok',
'celery': 'healthy',
'workers': worker_count
})
except Exception as e:
return JsonResponse(
{'status': 'error', 'celery': str(e)},
status=503
)
Add this as a separate Vigilmon monitor: https://yourapp.com/health/celery/
Monitoring Gunicorn Workers
Gunicorn worker crashes are another silent failure mode. When workers die faster than Gunicorn restarts them, requests start timing out.
Vigilmon's response time monitoring catches this — if your Django app usually responds in 100ms but starts taking 5+ seconds, your worker count is likely insufficient.
Set a response time alert at 1000ms in Vigilmon for your health endpoint.
Django-Specific Monitoring Configuration
# settings.py — exclude health check from auth middleware
HEALTH_CHECK_EXEMPT_PATHS = ['/health/']
# If using django-allauth or custom auth
LOGIN_URL = '/accounts/login/'
LOGIN_EXEMPT_URLS = [
r'^health/$', # Allow unauthenticated health checks
]
Important: make sure your load balancer and Vigilmon can reach /health/ without authentication.
What to Monitor Beyond Uptime
| Monitor | URL | Alert on |
|---|---|---|
| App health | /health/ |
503 response |
| Database | /health/db/ |
503 response |
| Cache | /health/cache/ |
503 response |
| Celery workers | /health/celery/ |
503 or 0 workers |
| Static files | /static/ |
Not 200 |
| SSL certificate | https://yourapp.com |
30 days before expiry |
Production Checklist
- [ ]
django-health-checkinstalled and configured - [ ] All check backends enabled (DB, cache, Celery, Redis)
- [ ] Health endpoints accessible without authentication
- [ ] Vigilmon HTTP monitors for each endpoint
- [ ] Response time alert at 1000ms
- [ ] SSL certificate monitoring enabled
- [ ] Maintenance windows for Django deployments
Start monitoring your Django app for free →
Vigilmon is an uptime monitoring platform for developers. Free tier includes 10 monitors with 1-minute checks from multiple global regions.
Top comments (0)