I want to configure healthcheckers to work with HealthChecksUI. But the HealthChecksUI page display a empty list of configured HealthChecks.
Here is code from ConfigureServices Method:
services.AddHealthChecksUI();
services.AddHealthChecks()
//.AddAzureTableStorage(Configuration["AzureTableStorage"])
.AddAzureServiceBusQueue(Configuration["NServiceBusParameters"], "CAPIMSPurchaseAPI")
.AddAzureServiceBusTopic(Configuration["NServiceBusParameters"], "CAPIMSPurchaseAPI")
.AddCheck("self", c => { return HealthCheckResult.Healthy(); })
.AddCheck<MailerHealthCheck>("mailer")
.AddDocumentDb(c =>
{
c.UriEndpoint = Configuration["xxxxx"];
c.PrimaryKey = Configuration["yyyyy"];
});
here is the code from Configure Method:
app.UseHealthChecks("/health", new Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckOptions
{
Predicate = registration => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
}
);
app.UseHealthChecksUI();
Here is the json configuration for HealthChecks-UI:
"HealthChecks-UI": {
"HealthChecks": [
{
"Name": "HTTP-Api-Basic",
"Uri": "http://localhost:4020/health"
}
],
"Webhooks": [
{
"Name": "",
"Uri": "",
"Payload": "",
"RestoredPayload": ""
}
],
"EvaluationTimeOnSeconds": 10,
"MinimumSecondsBetweenFailureNotifications": 60
}
When I access the link /health, it show the following result:
{"status":"Healthy",
"totalDuration":"00:00:02.1671415",
"entries":{
"azurequeue":{
"data":{
},
"duration":"00:00:01.0486138",
"status":"Healthy"
},
"azuretopic":{
"data":{
},
"duration":"00:00:00.1572862",
"status":"Healthy"
},
"self":{
"data":{
},
"duration":"00:00:00.0001244",
"status":"Healthy"
},
"mailer":{
"data":{
},
"duration":"00:00:00.1451047",
"status":"Healthy"
},
"documentdb":{
"data":{
},
"duration":"00:00:00.8158108",
"status":"Healthy"
}
}
}
Anyway, the healthcheckers-ui link show an empty list:
What I observed as well is that the healthchecksdb tables are empty. So it can be that there is a problem with configurations of healthcheckers
Do you have any configuration inside "launchSettings.json" in Properties Folder? Something like this? Solved my empty result list.
"HealthChecks": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "healthchecks-ui",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
I don't know if you manage to solve this but for me what worked was to call AddHealthChecksUI like this
public void ConfigureServices(IServiceCollection services)
{
services.AddHealthChecksUI("healthchecksdb", settings => settings.AddHealthCheckEndpoint("My health checks", "http://localhost:58811/healthz"));
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime applicationLifetime)
{
app.UseHealthChecks("/healthz",
new HealthCheckOptions()
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
}
I had the config set in the appsettings.json but it seems like that HealthCheckUI is not reading from there. I am not sure where I should put the config but setting it explictly in ConfigureServices did the trick
I think that you may be missing the UIPath
app.UseHealthChecksUI(config =>
{
config.UIPath = "/hc-ui";
})