A simple healthcheck server
Project description
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
healthcheck
toINSTALLED_APPS
insettings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'healthcheck',
]
- add
healthcheck.urls
tourlpatterns
inurls.py
urlpatterns = [
...
path('health/', include('healthcheck.urls')),
...
]
- setting
HEALTHCHECK
insettings.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_TOKEN
is optional, if you want to use token for health check, set it to a string. setAuthorization
header toBearer <HEALTH_CHECK_TOKEN>
in request header. -
HEALTH_CHECK_VIEW
is optional, if you want to use your own view, set it to a string. inherit fromhealthcheck.views.HealthCheckView
-
HEALTH_CHECK_FAIL_STATUS_CODE
is optional, if you want to use your own status code for fail, set it to an integer. -
HEALTH_CHECK_SUCCESS_STATUS_CODE
is optional, if you want to use your own status code for success, set it to an integer. -
HEALTH_CHECK_FORBIDDEN_STATUS_CODE
is optional, if you want to use your own status code for forbidden, set it to an integer. -
HEALTH_CHECK
is 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
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
Built Distribution
File details
Details for the file easy_health_check-1.0.0.tar.gz
.
File metadata
- Download URL: easy_health_check-1.0.0.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d75c92184049e027754ab1fef846ebbd05d0e1c00f175dd7299a670082b86e10 |
|
MD5 | 5808430fc71a53530763b259f94d57ad |
|
BLAKE2b-256 | c646cbad6ceee75d17c91d05eb5c6200809b82515beb76e6104b2dbf0b4b3439 |
File details
Details for the file easy_health_check-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: easy_health_check-1.0.0-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fd11c3011c137fe31bcff752f1ab4e50483c97209a705523a4c2b09caa25a2d |
|
MD5 | c588536cbe21096ec8f4e7e22440df02 |
|
BLAKE2b-256 | 84ce5e1b33242362c13a10c9265a8fe9345a725ae8cde1b83d5fceebb0d4ddfa |