File: settings.rst

package info (click to toggle)
python-django-health-check 3.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 428 kB
  • sloc: python: 1,886; makefile: 6
file content (119 lines) | stat: -rw-r--r-- 3,452 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
Settings
========

Settings can be configured via the `HEALTH_CHECK` dictionary.

.. data:: WARNINGS_AS_ERRORS

    Treats :class:`ServiceWarning` as errors, meaning they will cause the views
    to respond with a 500 status code. Default is `True`. If set to
    `False` warnings will be displayed in the template on in the JSON
    response but the status code will remain a 200.

Security
--------

Django health check can be used as a possible DOS attack vector as it can put
your system under a lot of stress. As a default the view is also not cached by
CDNs. Therefore we recommend to use a secure token to protect you application
servers from an attacker.

1.  Setup HTTPS. Seriously...
2.  Add a secure token to your URL.

Create a secure token:

.. code:: shell

    python -c "import secrets; print(secrets.token_urlsafe())"

Add it to your URL:

.. code:: python

    urlpatterns = [
        # ...
        url(r'^ht/super_secret_token/'), include('health_check.urls')),
    ]

You can still use any uptime bot that is URL based while enjoying token protection.

.. warning::
    Do NOT use Django's `SECRET_KEY` setting. This should never be exposed,
    to any third party. Not even your trusted uptime bot.

`cache`
-------

The cache backend uses the following setting:

.. list-table::
   :widths: 25 10 10 55
   :header-rows: 1

   * - Name
     - Type
     - Default
     - Description
   * - `HEALTHCHECK_CACHE_KEY`
     - String
     - `djangohealthcheck_test`
     - Specifies the name of the key to write to and read from to validate that the cache is working.
   * - `HEALTHCHECK_REDIS_URL_OPTIONS`
     - Dict
     - {}
     - Additional arguments which will be passed as keyword arguments to the Redis connection class initialiser.

`psutil`
--------

The following default settings will be used to check for disk and memory
utilization. If you would prefer different thresholds, you can add the dictionary
below to your Django settings file and adjust the values accordingly. If you want
to disable any of these checks, set its value to `None`.

.. code:: python

    HEALTH_CHECK = {
        'DISK_USAGE_MAX': 90,  # percent
        'MEMORY_MIN' = 100,    # in MB
    }

With the above default settings, warnings will be reported when disk utilization
exceeds 90% or available memory drops below 100 MB.

.. data:: DISK_USAGE_MAX

   Specify the desired disk utilization threshold, in percent. When disk usage
   exceeds the specified value, a warning will be reported.

.. data:: MEMORY_MIN

   Specify the desired memory utilization threshold, in megabytes. When available
   memory falls below the specified value, a warning will be reported.

Celery Health Check
-------------------

Using `django.settings` you may exert more fine-grained control over the behavior of the celery health check

.. list-table:: Additional Settings
   :widths: 25 10 10 55
   :header-rows: 1

   * - Name
     - Type
     - Default
     - Description
   * - `HEALTHCHECK_CELERY_QUEUE_TIMEOUT`
     - Number
     - `3`
     - Specifies the maximum amount of time a task may spend in the queue before being automatically revoked with a `TaskRevokedError`.
   * - `HEALTHCHECK_CELERY_RESULT_TIMEOUT`
     - Number
     - `3`
     - Specifies the maximum total time for a task to complete and return a result, including queue time.
   * - `HEALTHCHECK_CELERY_PRIORITY`
     - Number
     - `None`
     - Specifies the healthcheck task priority.