I am using .NET Core 3.1 to develop a web application. It depends on several other external services (APIs written in Node.js). I would like to monitor the health of external services and use HealthChecks.UI
to show the health on a separate page. I am not interested in health of my own application, I am interested about the health of the dependent external systems. Can this be achieved by health checks package?
This is the code that I have currently:
Startup.cs
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services
.AddHealthChecks()
.AddCheck<ExternalServiceHealthCheck>("External service health check");
services
.AddHealthChecksUI()
.AddInMemoryStorage();
}
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles();
app.UseEndpoints(endpoints =>
{
endpoints.MapHealthChecksUI(setup =>
{
setup.UIPath = "/HealthChecks";
});
});
}
}
ExternalServiceHealthCheck.cs
public class ExternalServiceHealthCheck : IHealthCheck
{
public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
return Task.FromResult(HealthCheckResult.Healthy("External service is healthy"));
}
}
When I go to /HealthChecks
, I get an empty UI even though I registered ExternalServiceHealthCheck
(see image). Why is it not showing on /HealthChecks
page?