3.1 What to Check
Problem
You need to check your application for health but don’t know what
to check.
问题
你想对服务器进行有效检测,但不止如何去检测服务器健康状况。
Solution
Use a simple but direct indication of the application health. For
example, a handler that simply returns an HTTP 200 response tells
the load balancer that the application process is running.
解决方案
使用一个简单粗暴的检测方案实现应用健康检测。如,负载均衡器通过获取被负载
服务器的响应状态码是否为 200 判断应用服务器进程是否正常。
Discussion
It’s important to check the core of the service you’re load balancing
for. A single comprehensive health check that ensures all of the sys‐
tems are available can be problematic. Health checks should check
that the application directly behind the load balancer is available
over the network and that the application itself is running. With
application-aware health checks, you want to pick an endpoint that
simply ensures that the processes on that machine are running. It
may be tempting to make sure that the database connection strings
are correct or that the application can contact its resources. How‐
ever, this can cause a cascading effect if any particular service fails.
结论
实际项目中,对被负载的提供核心功能的应用服务器进行健康检测非常重要。
仅仅通过一种健康检测方案,确保核心服务是否可用,通常并不完全可靠。
健康检测应该通过网络直接检测被负载的应用服务器和应用本身是否运行正常,
来确保服务可用,这比仅使用负载均衡器来检测服务是否可用要可靠。
一般,可以选择一个功能来进行健康检测,来确保整个服务是否可用。比如,
确认数据库连接是否正常或应用是否能够正常获取它的资源。任何一个服务失效,
都可能引发蝴蝶效应导致整个服务不可用。