如何使用 Asp.Net-Core HealthChecks 设置 Application Insights
How to setup Application Insights with Asp.Net-Core HealthChecks
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
是我的健康检查端点。通过查询 requests
日志,我可以查看健康检查是否失败,但我想查看有关每个健康检查的更多详细信息,而且我认为我不需要为此进行任何扩展,所以我不明白是什么AddApplicationInsightsPublisher()
确实如此。
看起来健康事件是使用 TravkEvent api 作为自定义事件发送到 Application Insights 的。您可以在门户的分析或搜索中看到它们。
发布者 (HealthCheckPublisherHostedService) 的注册目前存在问题,该问题将为 aspnet core 3 修复。
目前的解决方法是手动正确注册 class :
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")));
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
是我的健康检查端点。通过查询 requests
日志,我可以查看健康检查是否失败,但我想查看有关每个健康检查的更多详细信息,而且我认为我不需要为此进行任何扩展,所以我不明白是什么AddApplicationInsightsPublisher()
确实如此。
看起来健康事件是使用 TravkEvent api 作为自定义事件发送到 Application Insights 的。您可以在门户的分析或搜索中看到它们。
发布者 (HealthCheckPublisherHostedService) 的注册目前存在问题,该问题将为 aspnet core 3 修复。 目前的解决方法是手动正确注册 class :
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")));