Asp.Net Core发布了2.2版,并附带了HealthChecks功能。 (Read more)。其中一项功能是将运行状况检查结果推送到Azure Application Insights。但我还没有找到任何方法如何在Azure门户中看到这些结果。要发送结果,我使用以下扩展名:
services.AddHealthChecks()
.AddSqlServer("...")
.AddApplicationInsightsPublisher();
有没有办法在Application Insights中查看这些运行状况检查报告?
编辑1:我从官方github docs举了例子。
编辑2:如果我转到Azure门户查询分析,我会看到以下结果:
查询requests
:
查询customEvents
这里:GET /health
是我的healthCheck端点。通过查询requests
日志我可以看到健康检查是否失败,但我想看到有关每个健康检查的更多细节,我也不认为我需要任何扩展,所以我不明白AddApplicationInsightsPublisher()
实际上做了什么。
目前存在注册发布者(HealthCheckPublisherHostedService)的问题,该问题将针对aspnet核心3进行修复。目前解决方法是手动正确注册该类:
services.AddHealthChecks()
.AddApplicationInsightsPublisher();
// This is a hack to fix an issue with the AddApplicationInsightsPublisher() call above
services.TryAddEnumerable(ServiceDescriptor.Singleton(typeof(IHostedService), typeof(HealthCheckPublisherOptions).Assembly.GetType("Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckPublisherHostedService")));
它看起来健康事件使用TravkEvent api作为自定义事件发送到Application Insights。您可以在门户网站的分析或搜索中查看它们。