为 Azure Service Fabric 应用程序启用 .NET Profiler

适用于 .NET 的 Application Insights Profiler 会采集跟踪,这些跟踪显示在应用程序处理实际生产流量时,哪些代码行的执行耗时最长。 作为服务Fabric开发人员,可以使用这些跟踪来查明在生产环境中减缓应用程序的性能瓶颈,而无需在测试环境中重现问题。

Azure 诊断包含分析器。 若要从Azure Service Fabric群集收集跟踪,请使用 Azure 资源管理器 模板(ARM 模板)安装Azure 诊断扩展。

本指南介绍如何:

  • 将适用于 .NET 的 Application Insights Profiler 属性添加到 ARM 模板。
  • 使用适用于 .NET 连接字符串的 Application Insights Profiler 部署 Service Fabric 群集。
  • 在 Service Fabric 应用程序上启用 Application Insights。
  • 重新部署 Service Fabric 群集以启用 .NET Profiler。

先决条件

创建部署模板

  1. 在你的 Service Fabric 托管群集中,转到实现 ARM 模板的位置。

  2. 在部署模板文件中找到 WadCfgAzure 诊断扩展中的 标记。

  3. 添加以下 SinksConfig 部分作为 WadCfg 的子元素。 将 ApplicationInsightsProfiler 属性值替换为自己的 Application Insights 连接字符串:

    "settings": {
        "WadCfg": {
            "SinksConfig": {
                "Sink": [
                    {
                        "name": "MyApplicationInsightsProfilerSinkVMSS",
                        "ApplicationInsightsProfiler": "YOUR_APPLICATION_INSIGHTS_CONNECTION_STRING"
                    }
                ]
            }
        }
    }
    

    有关如何将诊断扩展添加到部署模板的信息,请参阅 将监视和诊断与 Windows VM 配合使用

部署 Service Fabric 群集

使用你的 Application Insights 连接字符串更新 WadCfg 配置后,部署 Service Fabric 群集。

在群集上安装 Azure 诊断 扩展时,会自动安装并启用适用于.NET的 Application Insights Profiler。

在 Service Fabric 应用程序上启用 Application Insights

若要使 .NET Profiler 能够收集针对你的请求的性能分析数据,Service Fabric 应用程序必须使用 Application Insights 跟踪操作。 选择与应用程序类型匹配的选项:

启用 Application Insights 后,重新部署应用程序。

生成流量并查看 .NET Profiler 踪迹

  1. 启动可用性测试以生成到应用程序的流量。
  2. 等待 10 到 15 分钟,让跟踪数据传送到 Application Insights 实例。
  3. 在 Azure 门户中使用 Application Insights 实例查看 探查器跟踪

后续步骤