Django healthchecks

With our open source django_auto_healthchecks app you can define powerful healthchecks for your Django application directly in your urls.py.

  • Attach healthchecks directly to routes - Healthchecks are defined in your code and attached to the route they monitor.
  • Publish updates automatically - Healthchecks are published to Cronitor automatically when your app is deployed or restarted. Cronitor runs all healthchecks immediately after a deploy.
  • Create in your code, update on your dashboard - Configure health check details directly in your code, or leave things to be managed later from your dashboard.
  • Stateless & fast - All application healthchecks are put to Cronitor with create-or-update logic in a single request. Nothing is ever saved locally.
  • Alerts everywhere - Receive alerts & notifications in PagerDuty, Slack, HipChat, text message and email, or trigger custom actions with webhook callbacks.

How it works

  1. Install the django_auto_healthchecks app in your Django project
  2. Update your urls.py file(s) with inline healthchecks where desired
  3. Every time your Django app starts, defined healthchecks are published to Cronitor in a single batch.
  4. Cronitor bots will monitor your Django routes from North America, Europe, and Asia. You will be alerted if your app is unreachable or if any custom assertions fail.

Getting started

  1. If you haven't created a Cronitor account, do that first. You'll need an API key.
  2. Add the django_auto_healthchecks package to your project.
  3. In your settings.py INSTALLED_APPS, add django_auto_healthchecks to the end of the list
        INSTALLED_APPS = [
            'django.contrib.admin',
            'django.contrib.auth',
            'django.contrib.contenttypes',
            'django.contrib.sessions',
            'django.contrib.messages',
            'django.contrib.staticfiles',
            'example_app',
    
            # Django auto healthchecks should be the final app in your list
            'django_auto_healthchecks'
        ]
  4. Later in your settings.py, add necessary HEALTHCHECKS configuration
        HEALTHCHECKS = {
            # The api key is required
            'API_KEY': '60d12a7093c9465398de00bd75a2b54d',
    
            # These are optional:
            'HTTPS': True,
            'TAGS': ['Demo App', 'Mysite']
        }
  5. Add healthchecks to desired routes directly in urls.py. See our example app for more details.
        from django_auto_healthchecks import url, Healthcheck
    
        url(r'^api/leads/(?P<lead>.+)$',
        views.api,
        name='leads-detail',
        healthcheck=Healthcheck(
            kwargs={'lead': '12345'},
            name='Lead API Update',
            method='PUT',
            body='{"name": "Spacely Sprockets", "contact": "Cosmo Spacely"}',
            assertions=[{
                'rule_type': 'response_body',
                'operator': 'contains',
                'value': 'Cosmo',
            }]))
                
  6. When developing with settings.DEBUG = True healthchecks are published to Cronitor in Development mode.
  7. When your app is deployed or restarted with settings.DEBUG = False, production monitors will be published automatically. Cronitor automatically runs all healthchecks when they are deployed. Cronitor will continue to monitor your Django application and alert you if it becomes unreachable or any of your custom assertions fail.

Advanced usage

If your Django application is deployed to multiple servers or is otherwise high availability, you can choose to control when healthchecks are published to Cronitor by removing django_auto_healthchecks from INSTALLED_APPS.

Call django_auto_healthchecks.put() from a custom admin view or a custom django-admin command to publish healthchecks on demand.

Feedback

The open source django_auto_healthchecks app is currently in beta. We love feedback, bug reports, and contributions.