File tree Expand file tree Collapse file tree 4 files changed +24
-5
lines changed
Expand file tree Collapse file tree 4 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,13 @@ on django.conf.settings with the required format to connect to your redis server
111111 REDIS_URL = redis:// localhost:6370
112112```
113113
114+ The cache healthcheck tries to write and read a specific key within the cache backend.
115+ It can be customized by setting ` HEALTHCHECK_CACHE_KEY ` to another value:
116+
117+ ``` python
118+ HEALTHCHECK_CACHE_KEY = custom_healthcheck_key
119+ ```
120+
114121## Setting up monitoring
115122
116123You can use tools like Pingdom, StatusCake or other uptime robots to monitor service status.
Original file line number Diff line number Diff line change @@ -56,3 +56,9 @@ all the time.
5656
5757You may also use both of them. To use these checks add them to `INSTALLED_APPS ` in your
5858Django settings module.
59+
60+ ``cache ``
61+ ---------
62+
63+ The key `djangohealtcheck_test ` will be written to the cache backend to validate that the cache is working.
64+ The name of the key can be customized by setting `HEALTHCHECK_CACHE_KEY ` to another value.
Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ exceeds 90% or available memory drops below 100 MB.
7171 memory falls below the specified value, a warning will be reported.
7272
7373Celery Health Check
74- ----------------------
74+ -------------------
7575Using `django.settings ` you may exert more fine-grained control over the behavior of the celery health check
7676
7777.. list-table :: Additional Settings
@@ -82,6 +82,10 @@ Using `django.settings` you may exert more fine-grained control over the behavio
8282 - Type
8383 - Default
8484 - Description
85+ * - `HEALTHCHECK_CACHE_KEY `
86+ - String
87+ - djangohealtcheck_test
88+ - Specifies the name of the key to write to and read from to validate that the cache is working.
8589 * - `HEALTHCHECK_CELERY_QUEUE_TIMEOUT `
8690 - Number
8791 - 3
Original file line number Diff line number Diff line change 11from django .core .cache import CacheKeyWarning , caches
2+ from django .conf import settings
23
34from health_check .backends import BaseHealthCheckBackend
45from health_check .exceptions import ServiceReturnedUnexpectedResult , ServiceUnavailable
56
6-
77class CacheBackend (BaseHealthCheckBackend ):
8+
89 def __init__ (self , backend = "default" ):
910 super ().__init__ ()
1011 self .backend = backend
12+ self .cache_key = getattr (settings , "HEALTHCHECK_CACHE_KEY" , "djangohealtcheck_test" )
1113
1214 def identifier (self ):
1315 return f"Cache backend: { self .backend } "
@@ -16,9 +18,9 @@ def check_status(self):
1618 cache = caches [self .backend ]
1719
1820 try :
19- cache .set ("djangohealtcheck_test" , "itworks" )
20- if not cache .get ("djangohealtcheck_test" ) == "itworks" :
21- raise ServiceUnavailable ("Cache key does not match" )
21+ cache .set (self . cache_key , "itworks" )
22+ if not cache .get (self . cache_key ) == "itworks" :
23+ raise ServiceUnavailable (f "Cache key { self . cache_key } does not match" )
2224 except CacheKeyWarning as e :
2325 self .add_error (ServiceReturnedUnexpectedResult ("Cache key warning" ), e )
2426 except ValueError as e :
You can’t perform that action at this time.
0 commit comments