Azure App Service has a built-in health check feature. Through this feature Azure can automatically check the health endpoint of your web app and can take an unhealthy instance out of the load balancer until it's healthy again, or even restart or replace it.
To enable Health check, browse to the Azure portal and select your App Service app.
Under Monitoring, select Health check.
Select Enable and provide a valid URL path on your application, such as /hc
or /api/health
. Click Save.
Remark: Notice the Load balancing slider. Here you can specify the time an app can be unhealthy before being removed from the load balancer.
Azure only looks at the HTTP response the page gives. If the response is in the 2XX range the instance is considered healthy, else it is shown as degraded or unhealthy. It also doesn't follow redirects. If your webapp settings allow http the check by Azure is done over http. If it is set to HTTPS only then Azure used https calls to check the endpoint. In case your health checks return HTTP 307 response make sure you set your webapp to only use https or remove the redirect from your code.
You can further control the Health check behavior through the following appsetings:
WEBSITE_HEALTHCHECK_MAXPINGFAILURES :
The required number of failed requests for an instance to be deemed unhealthy and removed from the load balancer. For example, when set to2
, your instances will be removed after2
failed pings. (Default value is10
)WEBSITE_HEALTHCHECK_MAXUNHEALTHYWORKERPERCENT :
By default, no more than half of the instances will be excluded from the load balancer at one time to avoid overwhelming the remaining healthy instances. For example, if an App Service Plan is scaled to four instances and three are unhealthy, two will be excluded. The other two instances (one healthy and one unhealthy) will continue to receive requests. In the worst-case scenario where all instances are unhealthy, none will be excluded.
More information: Monitor App Services instances using Health Check