Skip to main content

Health checkers for Django apps

Project description

Health Checkers

For django applications.

Installation

pip install py-django-health

Usage

In settings.py file:

INSTALLED_APPS = [
    'health',
    ...
]

Using checkers

By default, you have 3 checkers set (which are the built-in defined by the library):

  • health.checkers.disk.DiskHealthChecker
  • health.checkers.database.DatabaseHealthChecker
  • health.checkers.cache.CacheHealthChecker

If you want to replace them or use another, just modify this property in the settings.py file:

HEALTH_CHECKERS = {
    'health.checkers.disk.DiskHealthChecker',
    ...
}

Remember: HEALTH_CHECKERS is a set of strings.

Exposing endpoints

Health Checkers has endpoints to be consumed by others apps or metrics counters.
To enabled them, just add them into your urls.py file:

url('', include('health.urls'))

Configuring the application

HEALTH_CHECKERS_ENABLED

Type Required Default
bool No True

Enable or disabled all health checker features.

HEALTH_CHECKERS

Type Required Default
set No {'health.checkers.disk.DiskHealthChecker', 'health.checkers.database.DatabaseHealthChecker', 'health.checkers.cache.CacheHealthChecker'}

Set of checkers to execute

HEALTH_CHECKERS_CONTEXT_PATH

Type Required Default
str No /infra

Context path for exposed endpoint

Adding custom checkers

You can create and add custom checkers.
Just follow these steps:

  1. Create a class inheriting the class HealthChecker from the package health.checkers.base.
from health.checkers.base import HealthChecker

class MyCustomChecker(HealthChecker):
    _token: str
  1. Override (if needed) the setup method.
import typing

from health.checkers.base import HealthChecker

class MyCustomChecker(HealthChecker):
    _token: str
    
    def setup(self) -> typing.NoReturn:
        self._token = '<token>'
  1. Override the check method.
import typing

from health.checkers.base import HealthChecker
from health.models import ComponentHealth

class MyCustomChecker(HealthChecker):
    _token: str
    
    def setup(self) -> typing.NoReturn:         
        self._token = '<token>'
        
    def check(self) -> typing.List[ComponentHealth]:       
       # Logic goes here 
       return []
  1. Add the custom checker into the HEALTH_CHECKERS set into the settings.py file.
HEALTH_CHECKERS = {
   'health.checkers.disk.DiskHealthChecker',
   'health.checkers.database.DatabaseHealthChecker',
   'my_package.checkers.MyCustomChecker'
}
  1. You can also create a new ComponentHealth.
from health.models import ComponentHealth

class MyCustomHealthComponent(ComponentHealth):
    token: str

Consuming endpoint

Get Health information

Retrieve health information from the application.

Method Path
GET /{HEALTH_CHECKERS_CONTEXT_PATH}/health

Response (JSON):

{
   "status": "ALIVE",
   "components": [
      {
         "type": "DISK",
         "status": "ALIVE",
         "total": 50699194432,
         "free": 5131434234,
         "used": 4551234 
      }
   ]
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-django-health-0.0.4.tar.gz (20.0 kB view details)

Uploaded Source

File details

Details for the file py-django-health-0.0.4.tar.gz.

File metadata

  • Download URL: py-django-health-0.0.4.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.2

File hashes

Hashes for py-django-health-0.0.4.tar.gz
Algorithm Hash digest
SHA256 c597d4081d757aa9b8eb0f4e357a9195d3451ee291330cdd848b885f3584f273
MD5 18ed510b6524a04cea47754fa34ce7af
BLAKE2b-256 2f876b7ea04455b96ce29930ebea0a7fe224f64e7b7fe2d0b92ddc776452d125

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page