Django Health Check
Project description
Django Health Check
If you use or like the project, click Star
and Watch
to generate metrics and i evaluate project continuity.
Install:
pip install django-k8s-health-check
Usage Health only:
- In your urls:
from django_k8s_health_check.views import HealthView ... urlpatterns = [ path('', views.HealthView.as_view()), ]
Usage in kubernetes:
If use health check in kubernetes, you need to add kubernetes ip/host to django allowed_hosts, but is a bad practice, especially if there are multiple ip/hosts... For this, i created a middleware to pass dynamic ip/hosts, using multiples validators
-
Request Way
-
Add the middleware to django middleware`s:
MIDDLEWARE = [ 'django_k8s_health_check.middleware.HealthCheckMiddleware', ... ]
-
Try this request:
import requests requests.get('your-url', headers={'X-Health': 'health-check'})
-
Put this in your yml
livenessProbe: httpGet: path: /your-path httpHeaders: - name: X-Health value: health-check timeoutSeconds: 5
-
Check de configuration section, and change for security reasons...
-
-
Command Way (test database and cache only, this not guarantee application is running):
-
Add this app to your installed apps:
INSTALLED_APPS = [ 'django_k8s_health_check', ]
-
Try to run this command:
python manage.py health_check
-
Put this in your yml
livenessProbe: exec: command: ["python", "manage.py", "health_check"] timeoutSeconds: 5
-
Configuration:
HEALTH_CHECK = {
# View
'SERVICE_NAME': None, # Used only in API
'CHECK_DATABASE': True,
'CHECK_CACHE': True,
# Middleware (All bellow is used only in API)
'HEADER_FIELD': 'X-Health',
'HEADER_VALUE': 'health-check',
'ALLOWED_PATHS': None, # all others urls, use original ALLOWED_HOSTS. Ex: ['api/v1/health', '/health'], None allow all
'ALLOWED_HOSTS': None, # check request host is in a list, Ex: ['127.0.0.1', 'www.domain.com'], None allow all
}
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
Built Distribution
Hashes for django-k8s-health-check-1.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee1129a58cb9b4c1208edeaf89e7fb5db1393986904340926b494d90ffbe7663 |
|
MD5 | 8b43adac17da65803298bda47b821b14 |
|
BLAKE2b-256 | 7c850d60d1eb29b53d85df4aabcb42a7142f03fb78c1bfc0c56af6b77fd74cad |
Hashes for django_k8s_health_check-1.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8a1e63fda3c11b9cd7312cf5695f0272598ba8b7624984483cc16bfdc795bb4 |
|
MD5 | ace387c194b1458b592859d67d1c5a7a |
|
BLAKE2b-256 | c48a0092faf79e0cd465629e799682ee0fe93d851a28a7cb71572945f3859fe1 |