Creating a Load Balancer Custom Health Check Page

Develop a custom health check page for a load balancer.

In many scenarios, you might want to expose your own custom health check page to do a more thorough check. One example scenario is to use the flask application, as in the following example, rather than relying on your existing application.https://pypi.org/project/py-healthcheck/

import tornado.web
from healthcheck import TornadoHandler, HealthCheck, EnvironmentDump
# add your own check function to the healthcheck
def redis_available():
client = _redis_client()
info = client.info()
return True, "Redis Test Pass"
health = HealthCheck(checkers=[redis_available])
app = tornado.web.Application([
("/healthcheck", TornadoHandler, dict(checker=health)),
])
In the preceding example, the test page is doing more than just ensuring the HTTP application is listening. This example checks for a redis client and waits for a response to ensure that the full application is healthy before returning a 200 status code. Some other command examples would be to check for disk space or the availability of an upstream dependency. In your health check configuration, specify the following:
  • /healthcheck as your path

  • flask default 5000 as port

  • 200 as status code