Skip to main content

Simple Django app/framework to publish health check for monitoring purposes

Features:

  • Custom checks via Python functions

  • Remote healthchecks

  • Heartbeat monitoring

Status

https://github.com/mvantellingen/django-healthchecks/workflows/Python%20Tests/badge.svg http://codecov.io/github/mvantellingen/django-healthchecks/coverage.svg?branch=master https://img.shields.io/pypi/v/django-healthchecks.svg

Installation

pip install django_healthchecks

Usage

Add the following to your urls.py:

url(r'^healthchecks/', include('django_healthchecks.urls')),

Add a setting with the available healthchecks:

HEALTH_CHECKS = {
    'postgresql': 'django_healthchecks.contrib.check_database',
    'cache_default': 'django_healthchecks.contrib.check_cache_default',
    'solr': 'your_project.lib.healthchecks.check_solr',
}

You can also include healthchecks over http. This is useful when you want to monitor if depending services are up:

HEALTH_CHECKS = {
    ...
    'my_microservice': 'https://my-service.services.internal/healthchecks/',
    ...
}

By default, http health checks will time out after 500ms. You can override this as follows:

HEALTH_CHECKS_HTTP_TIMEOUT = 0.5

By default the status code is always 200, you can change this to something else by using the HEALTH_CHECKS_ERROR_CODE setting:

HEALTH_CHECKS_ERROR_CODE = 503

You can also add some simple protection to your healthchecks via basic auth. This can be specified per check or a wildcard can be used *.

HEALTH_CHECKS_BASIC_AUTH = {
    '*': [('admin', 'pass')],
    'solr': [],
}

Using heartbeats

Heartbeats give a periodic update, to see whether an service was recently active. When the service doesn’t report back within timeout, a healthcheck can be triggered. To use heartbeats, add the application to the INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    "django_healthchecks",
]

Include one of these checks:

HEALTH_CHECKS = {
    ...
    'heartbeats': 'django_healthchecks.contrib.check_heartbeats'
    ...
    'expired_heartbeats': 'django_healthchecks.contrib.check_expired_heartbeats',
    ...
}

Optionally, define an initial timeout:

HEALTHCHECKS_DEFAULT_HEARTBEAT_TIMEOUT = timedelta(days=1)

Let your code track the beats:

from datetime import timedelta
from django_healthchecks.heartbeats import update_heartbeat

update_heartbeat("myservice.name", default_timeout=timedelta(days=2))

Or use the decorator:

from django_healthchecks.heartbeats import update_heartbeat_on_success

@update_heartbeat_on_success("myservice.name", default_timeout=...)
def long_running_task():
    ....

Each time update_heartbeat() is called, the heartbeat is reset. When a heartbeat didn’t receive an update before it’s timeout, the service name be mentioned in the check_expired_heartbeats check.

Updating timeouts

The default_timeout parameter is only assigned upon creation. Any updates happen through the Django admin. To update the timeout automatically on code deployment, use the timeout parameter instead. This will replace the stored timeout value each time the update_heartbeat() function is called, erasing any changes made in the Django admin.

Release files for django-healthchecks 1.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-healthchecks 1.5.0
File Size Uploaded
django-healthchecks-1.5.0.tar.gz 10.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-healthchecks 1.5.0
File Interpreter ABI Platform
django_healthchecks-1.5.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 22.7 kB

Release files / django-healthchecks-1.5.0.tar.gz

Download URL django-healthchecks-1.5.0.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0f167deaa30bde59552796799abf2a97a118bc190e8601eef713379703cf9f64
BLAKE2b-256 checksum
How to use checksums
f9d08cf815b7cadd7ba9cf9ce527c92ba323c45c4060d77d9ae8bc6a357d962d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / django_healthchecks-1.5.0-py2.py3-none-any.whl

Download URL django_healthchecks-1.5.0-py2.py3-none-any.whl
Size 12.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
25eb021a4a94240b28d996e82775ad6c3b392a2b262360b965a24b88fcfad78d
BLAKE2b-256 checksum
How to use checksums
383cc4063946ae0dfc3d16de5615b1e3161b8d88a768d70078b9811977703d80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release history Release notifications | RSS feed

This release

1.5.0 This release

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page