Skip to main content

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:

  1. 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

  1. Request Way

    1. Add the middleware to django middleware`s:

      MIDDLEWARE = [
          'django_k8s_health_check.middleware.HealthCheckMiddleware',
          ...
      ]
      
    2. Try this request:

      import requests
      requests.get('your-url', headers={'X-Health': 'health-check'})
      
    3. Put this in your yml

      livenessProbe:
          httpGet:
          path: /your-path
          httpHeaders:
          - name: X-Health
              value: health-check
          timeoutSeconds: 5
      
    4. Check de configuration section, and change for security reasons...

  2. Command Way (test database and cache only, this not guarantee application is running):

    1. Add this app to your installed apps:

      INSTALLED_APPS = [
          'django_k8s_health_check',
      ]
      
    2. Try to run this command:

      python manage.py health_check
      
    3. 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
}

Download files

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

Source Distribution

django_k8s_health_check-1.2.1.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_k8s_health_check-1.2.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file django_k8s_health_check-1.2.1.tar.gz.

File metadata

  • Download URL: django_k8s_health_check-1.2.1.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for django_k8s_health_check-1.2.1.tar.gz
Algorithm Hash digest
SHA256 813586181c5189f650d9e1c02d72b10d9ef67226a3eb12fc1b4f0307f91bc007
MD5 8d467d41805095f549a00b9fc12ff181
BLAKE2b-256 37df9dcfa3603e75a3dc6b0f9b3d7c9f4974a463ae90bad2a50b07b6eb82bcaa

See more details on using hashes here.

File details

Details for the file django_k8s_health_check-1.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_k8s_health_check-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c7636415990b5e6d04fba2ec1bff5cd6918b4010452be03f377e12b6d20ace58
MD5 350a5fca1add8fdb2abb49f988e73142
BLAKE2b-256 0e1fea678367f5a2ba6967fee502fe7f1d47095fbbd49f81f157933208f7a007

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 files

1.2.0

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.6

2 files

1.0.5

1 file

Supported by

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