Health checking is the process where [load balancers] (https://en.wikipedia.org/wiki/Load_balancing_(computing)) or application delivery controller does periodic check on our applications to make sure that they are up and responding without any problems. If our applications are down for every reason or any of the system that our applications depends on (A database, a distributed cache, web service, ect) are down, the load balancer should detect this and stop sending traffic its way.
AspNetCore.Health enables load balancers to monitor the status of deployed Web applications.
AspNetCore.Health enables you to do the following tasks:
- Monitor the performance of an AspNetCore application to make sure that it is healthy.
- Rapidly diagnose applications or systems that are failing.
You should install AspNetCore.Health with NuGet:
Install-Package AspNetCore.Health
This command from Package Manager Console will download and install AspNetCore.Health and all required dependencies.
By default AspNetCore provides out of the box some health checks providers:
- Check Urls (Http services)
public void ConfigureServices(IServiceCollection app)
{
services.AddHealthChecks(context =>
{
context
.AddUrlCheck("http://www.google.com",true)
g);
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseHealthCheck("/health")
}
You can create your own health check providers in a functional style avoiding inheritance:
Func<Task<HealthCheckResult>>
You can see some examples [here] (https://github.com/lurumad/aspnetcore-health/blob/master/src/AspNetCore.Health/HealthCheckContextExtensions.cs)
Run the HealthSample and open your browser http://localhost:5000/health
[
{
Name: "WebService (Google)",
Status: "Healthy"
}
]
If all services are healthy, returns http 200 OK status code, but if there are any unhealthy service returns http 500 Internal Server Error status code. Added a boolean if you want to exclude that service for unhealthy htpp **500 result. By default is set to true
Try with other services!
Platform | Status |
---|---|
AppVeyor (.NET Core) |
Copyright © 2016 Luis Ruiz (lurumad)