Django HealthCheck
Django HealthCheck is a plug-and-play Django application that provides a /healthcheck/ endpoint to monitor the health of your Django app and its connected services like databases, caches, storage, Celery, and more. It returns HTTP 200 for healthy status and HTTP 500 if issues are detected. The current version is 4.2.2, and it maintains a regular release cadence with frequent updates and bug fixes.
Warnings
- breaking Version 4.x introduced significant changes, particularly affecting custom integrations and the overall API. Review the 'Migration to v4.x' guide in the official documentation when upgrading from versions prior to 4.0.
- gotcha Many specific health checks (`health_check.contrib.*`) require additional Python packages to be installed (e.g., `psutil` for disk/memory, `celery` for Celery, `redis` for Redis). Simply adding the contrib app to `INSTALLED_APPS` without the underlying package will cause errors.
- deprecated The `health_check.contrib.migrations` check, which verified applied database migrations, was removed in version 3.23+.
- gotcha For security, it is highly recommended to protect your health check endpoint, especially in production environments. If using a token-based approach, do NOT use Django's `SECRET_KEY`.
- gotcha In high-availability environments with load balancers, be aware that checks like disk and memory usage will return responses specific to the individual node selected by the load balancer, not an aggregated status of the entire cluster.
Install
-
pip install django-health-check -
pip install django-health-check[psutil,celery,redis]
Imports
- health_check
INSTALLED_APPS = [ # ... 'health_check', # required 'health_check.db', # database check 'health_check.cache', # cache check 'health_check.storage', # storage check 'health_check.contrib.celery', # optional, for Celery 'health_check.contrib.psutil', # optional, for disk/memory # ... ] - include
from django.urls import include, path urlpatterns = [ # ... path('health/', include('health_check.urls')), # or any desired path # ... ] - plugin_dir.register
from django.apps import AppConfig from health_check.plugins import plugin_dir from myapp.checks import MyCustomHealthCheck class MyAppConfig(AppConfig): name = 'myapp' def ready(self): plugin_dir.register(MyCustomHealthCheck)
Quickstart
# settings.py
INSTALLED_APPS = [
# ... other Django apps ...
'health_check',
'health_check.db', # Checks database connection
'health_check.cache', # Checks cache backend
'health_check.storage', # Checks default file storage
'health_check.contrib.psutil', # Checks disk/memory usage (requires psutil)
'health_check.contrib.celery', # Checks Celery workers (requires celery)
# Add more health_check.contrib.* apps as needed for your services
]
# urls.py
from django.urls import include, path
urlpatterns = [
# ... other url patterns ...
path('health/', include('health_check.urls')),
]