The idea with Health checks is that the application is the best one to know about the state of its components, and how critical each one is. By having the application output its own health information, you don’t need to reinvent the wheel in 3rd party scanners and monitors, trying to do the same type of operations your website does just to make sure everything’s running.
Additionally, health endpoints open up a new world of resilience when used in conjunction with orchestration platforms like Kubernetes, allowing you to build a kind of immune system for your application. Check out the concept of Chaos Engineering from Netflix with a system they call Chaos Monkey https://www.gremlin.com/chaos-monkey/
However, they also provide benefits for teams in earlier stages of automation, but allowing health information from applications and their components to be displayed on a dashboard, or changes in state communicated (ex: via Slack.)
A health probe is something that checks the health endpoint of a service.
Docker comes with a simple HEALTHCHECK directive that allows you to turn off a faulty container
HEALTHCHECK CMD curl --fail http://localhost:5000/health || exit
It’s also possible to chain health endpoints with other health endpoint, for example if your microservice depends on another microservice that has a health endpoint.
public class ExampleHealthCheck : IHealthCheck { public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default(CancellationToken)) { var healthCheckResultHealthy = true; if (healthCheckResultHealthy) return Task.FromResult(HealthCheckResult.Healthy("A healthy result.")); return Task.FromResult(HealthCheckResult.Unhealthy("An unhealthy result.")); } }
Source: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-3.0
HealthChecksUI provides a great GUI on top of your health checks, when output in a format it expects.
https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks
https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/blob/master/extensions/README.md
Quick Links
Legal Stuff