Django¶
This documents the code that allows Django integration.
Checks¶
The provided checks hook into Django’s system check framework to enable
the heartbeat view
to diagnose
the current health of the Django project.
- dockerflow.django.checks.check_database_connected(app_configs, **kwargs)[source]¶
A Django check to see if connecting to the configured default database backend succeeds.
Signals¶
During the rendering of the /__heartbeat__
Django view two signals are
being sent to hook into the result of the checks:
- dockerflow.django.signals.heartbeat_passed¶
The signal that is sent when the heartbeat checks pass successfully.
- dockerflow.django.signals.heartbeat_failed¶
The signal that is sent when the heartbeat checks raise either a warning or worse (error, critical)
Both signals receive an additional level
parameter that indicates the
maximum check level that failed during the rendering.
E.g. to hook into those signals to send data to statsd, do this:
from django.dispatch import receiver
from dockerflow.django.signals import heartbeat_passed, heartbeat_failed
from statsd.defaults.django import statsd
@receiver(heartbeat_passed)
def heartbeat_passed_handler(sender, level, **kwargs):
statsd.incr('heartbeat.pass')
@receiver(heartbeat_failed)
def heartbeat_failed_handler(sender, level, **kwargs):
statsd.incr('heartbeat.fail')
Views¶
dockerflow.django
implements various views so the automatic application
monitoring can happen. They are mounted by including them in the root of a
URL configration:
urlpatterns = [
url(r'^', include('dockerflow.django.urls', namespace='dockerflow')),
# ...
]
- dockerflow.django.views.heartbeat(request)[source]¶
Runs all the Django checks and returns a JsonResponse with either a status code of 200 or 500 depending on the results of the checks.
Any check that returns a warning or worse (error, critical) will return a 500 response.
- dockerflow.django.views.lbheartbeat(request)[source]¶
Let the load balancer know the application is running and available must return 200 (not 204) for ELB http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/elb-healthchecks.html