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.DiskHealthCheckerhealth.checkers.database.DatabaseHealthCheckerhealth.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:
- Create a class inheriting the class
HealthCheckerfrom the package health.checkers.base.
from health.checkers.base import HealthChecker
class MyCustomChecker(HealthChecker):
_token: str
- Override (if needed) the
setupmethod.
import typing
from health.checkers.base import HealthChecker
class MyCustomChecker(HealthChecker):
_token: str
def setup(self) -> typing.NoReturn:
self._token = '<token>'
- Override the
checkmethod.
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 []
- Add the custom checker into the
HEALTH_CHECKERSset into thesettings.pyfile.
HEALTH_CHECKERS = {
'health.checkers.disk.DiskHealthChecker',
'health.checkers.database.DatabaseHealthChecker',
'my_package.checkers.MyCustomChecker'
}
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c597d4081d757aa9b8eb0f4e357a9195d3451ee291330cdd848b885f3584f273
|
|
| MD5 |
18ed510b6524a04cea47754fa34ce7af
|
|
| BLAKE2b-256 |
2f876b7ea04455b96ce29930ebea0a7fe224f64e7b7fe2d0b92ddc776452d125
|