Health Checks

Using DotNet Core comes some responsibilities, one of those is making sure your application is up and running.

Since DotNet Core 2.2 the introductions of health checks have been established.

There are two types of Health Checks

  • Liveness Health Checks
  • Readiness Health Checks

Liveness Health Check has the ability to report that your application is running

Readiness Health Check which can check any additional functionality that your application needs to function.

All the health checks provide an Endpoint which provides a Health Response which can be either Healthy, Degraded or Unhealthy

You can have multiple Health Checks which can be monitored from different systems such as:

  • Monitoring System
  • Load Balancer
  • Container Orchestrators
  • Deployment Tool

And depending on the Health Status each system can react and deal with the results accordingly.

I have created a sample application that formats the Health results and displays a UI for the results.

The example connects to:

  • a database
  • external API
  • file in your file system

I’ve also included two examples of Health Check extensions to show how to create a custom HealthCheck

Taking the application further you can use the following:

  • Rate Limit
  • Authorization
  • Authentication

Limited the rate of calls to the Health Check endpoints, we can do this using AspNetCoreRateLimit is an ASP.NET Core rate limiting solution designed to control the rate of requests that clients can make to a Web API or MVC app based on IP address or client ID.

In the AppSettings you set the IpRateLimiting section for the limiter

For Authorization you just need to add to the end of the EndPoint:

.RequireAuthorization()

For Authentication you just need to add to the end of the EndPoint:

.RequireAuthorization("HealthCheckPolicy")

Hope this helps you understand and build better Health Checks within your DotNet Core application.

The source can be found here:

https://github.com/BryanAvery/HealthChecks