【问题标题】:How to setup Application Insights with Asp.Net-Core HealthChecks如何使用 Asp.Net-Core HealthChecks 设置 Application Insights
【发布时间】:2019-06-11 21:43:17
【问题描述】:

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 日志,我可以查看健康检查是否失败,但我想查看有关每个健康检查的更多详细信息,而且我认为我不需要对此进行任何扩展,所以我不明白@987654333 是什么@ 确实如此。

【问题讨论】:

  • AddApplicationInsightsPublisher() 在哪里定义,它有什么作用?我不知道有任何自动方式将结果发布到应用程序见解 - Application Insights 继续照常收集请求。
  • 更多信息请看这里:github.com/Xabaril/… 它被定义为AddHealthChecks 服务的扩展方法,它应该将健康检查结果推送到应用洞察
  • 发布到 Application Insights 后,您可以使用 Analytics (customEvents) 或 Metrics (Custom) 在相关资源中查询它们。
  • @StefanPrugg 我没有收到任何带有健康检查信息的自定义事件。我唯一能看到它的地方是在requests 日志中,但我只能知道请求是成功还是失败,我想看看健康检查的哪一部分失败了。

标签: azure-application-insights asp.net-core-2.2


【解决方案1】:

目前发布者 (HealthCheckPublisherHostedService) 的注册存在问题,该问题将在 aspnet core 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")));

见:https://github.com/aspnet/Extensions/issues/639

【讨论】:

    【解决方案2】:

    它看起来使用 TravkEvent api 将运行状况事件作为自定义事件发送到 Application Insights。您可以在门户的分析或搜索中看到它们。

    【讨论】:

      猜你喜欢
      • 2022-01-14
      • 2017-11-01
      • 2019-12-21
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多