healthcheck
a very simple Django health check app
- easy to use
- no migration
- no extra dependency. only Django and Python 3.6+
install
pip install git+https://github.com/ahmadly/healthcheck/archive/refs/heads/main.zip
usage
- add
healthchecktoINSTALLED_APPSinsettings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'healthcheck',
]
- add
healthcheck.urlstourlpatternsinurls.py
urlpatterns = [
...
path('health/', include('healthcheck.urls')),
...
]
- setting
HEALTHCHECKinsettings.py
HEALTH_CHECK_TOKEN = None
HEALTH_CHECK_VIEW = 'healthcheck.views.HealthCheckView'
HEALTH_CHECK_FAIL_STATUS_CODE = 500
HEALTH_CHECK_SUCCESS_STATUS_CODE = 200
HEALTH_CHECK_FORBIDDEN_STATUS_CODE = 403
HEALTH_CHECK = [
'healthcheck.checks.check_database_connection',
'healthcheck.checks.check_cache_connection',
'healthcheck.checks.check_internet_connection',
]
- run server and go to
http://localhost:8000/health/
{
"uuid": "8f45499108cf4407bd3533d08fe68b26",
"timestamp": "2023-01-20T16:25:51.374452+00:00",
"hostname": "Ahmads-MBP",
"total_checks": 3,
"failed_checks": 0,
"results": [
{
"check": "healthcheck.checks.check_database_connection",
"status": true,
"message": "Database is reachable"
},
{
"check": "healthcheck.checks.check_cache_connection",
"status": true,
"message": "Cache is reachable"
},
{
"check": "healthcheck.checks.check_internet_connection",
"status": true,
"message": "Internet is reachable"
}
]
}
options
-
HEALTH_CHECK_TOKENis optional, if you want to use token for health check, set it to a string. setAuthorizationheader toBearer <HEALTH_CHECK_TOKEN>in request header. -
HEALTH_CHECK_VIEWis optional, if you want to use your own view, set it to a string. inherit fromhealthcheck.views.HealthCheckView -
HEALTH_CHECK_FAIL_STATUS_CODEis optional, if you want to use your own status code for fail, set it to an integer. -
HEALTH_CHECK_SUCCESS_STATUS_CODEis optional, if you want to use your own status code for success, set it to an integer. -
HEALTH_CHECK_FORBIDDEN_STATUS_CODEis optional, if you want to use your own status code for forbidden, set it to an integer. -
HEALTH_CHECKis optional, if you want to use your own checks, set it to a list of strings. each string is a path to a function. the function should return a tuple of two items. the first item is a boolean, the second item is a string. the boolean is the status of the check, the string is the message of the check.
def check_database_connection() -> tuple[bool, str]:
"""
check must return a tuple of (status, message)
check must handle exceptions internally
check must handle timeouts internally
"""
return True, 'Database is reachable'
contribute
if you have any idea, please open an issue or a pull request.
todo
- add more checks
- add more tests
- add documentation
- add badges
- setup release workflow
- setup pypi.org
Release files for easy-health-check 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| easy_health_check-1.0.0.tar.gz | 18.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| easy_health_check-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.0 kB
Release files / easy_health_check-1.0.0.tar.gz
| Download URL | easy_health_check-1.0.0.tar.gz |
|---|---|
| Size | 18.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d75c92184049e027754ab1fef846ebbd05d0e1c00f175dd7299a670082b86e10
|
|
BLAKE2b-256 checksum How to use checksums |
c646cbad6ceee75d17c91d05eb5c6200809b82515beb76e6104b2dbf0b4b3439
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.9
|
Release files / easy_health_check-1.0.0-py3-none-any.whl
| Download URL | easy_health_check-1.0.0-py3-none-any.whl |
|---|---|
| Size | 16.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6fd11c3011c137fe31bcff752f1ab4e50483c97209a705523a4c2b09caa25a2d
|
|
BLAKE2b-256 checksum How to use checksums |
84ce5e1b33242362c13a10c9265a8fe9345a725ae8cde1b83d5fceebb0d4ddfa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.9
|