使用 Application Insights 分析实时 Azure 云服务Profile live Azure Cloud Services with Application Insights

Application Insights Profiler 也可以部署在以下服务上:You can also deploy Application Insights Profiler on these services:

Application Insights Profiler 随 Azure 诊断扩展一同安装。Application Insights Profiler is installed with the Azure Diagnostics extension. 只需将 Azure 诊断配置为安装 Profiler 并将配置文件发送到 Application Insights 资源即可。You just need to configure Azure Diagnostics to install Profiler and send profiles to your Application Insights resource.

对 Azure 云服务启用 ProfilerEnable Profiler for Azure Cloud Services

  1. 请进行检查,确保使用的是 .NET Framework 4.6.1 或更新版本。Check to make sure that you're using .NET Framework 4.6.1 or newer. 如果使用的是 OS 系列 4,则需要使用启动任务安装 .NET Framework 4.6.1 或更新版本。If you are using OS family 4, you'll need to install .NET Framework 4.6.1 or newer with a startup task. 默认情况下,OS 系列 5 包含 .NET Framework 的兼容版本。OS Family 5 includes a compatible version of .NET Framework by default.

  2. 将 Application Insights SDK 添加到 Azure 云服务Add Application Insights SDK to Azure Cloud Services.

    云服务 WAD 中附带的探查器中的 bug 已修复。The bug in the profiler that ships in the WAD for Cloud Services has been fixed. 用于云服务的最新版本的 WAD (1.12.2.0) 适用于所有最新版本的 App Insights SDK。The latest version of WAD (1.12.2.0) for Cloud Services works with all recent versions of the App Insights SDK. 云服务主机将自动升级 WAD,但不会立即升级。Cloud Service hosts will upgrade WAD automatically, but it isn't immediate. 若要强制升级,可以重新部署服务或重新启动节点。To force an upgrade, you can redeploy your service or reboot the node.

  3. 使用 Application Insights 跟踪请求:Track requests with Application Insights:

  4. 配置 Azure 诊断扩展以启用 Profiler:Configure the Azure Diagnostics extension to enable Profiler:

    a.a. 找到应用程序角色的 Azure 诊断 diagnostics.wadcfgx 文件,如下所示:Locate the Azure Diagnostics diagnostics.wadcfgx file for your application role, as shown here:

    诊断配置文件的位置

    如果找不到该文件,请参阅针对 Azure 云服务和虚拟机设置诊断If you can't find the file, see Set up diagnostics for Azure Cloud Services and Virtual Machines.

    b.b. 添加以下 SinksConfig 部分作为 WadCfg 的子元素:Add the following SinksConfig section as a child element of WadCfg:

    <WadCfg>
      <DiagnosticMonitorConfiguration>...</DiagnosticMonitorConfiguration>
      <SinksConfig>
        <Sink name="MyApplicationInsightsProfiler">
          <!-- Replace with your own Application Insights instrumentation key. -->
          <ApplicationInsightsProfiler>00000000-0000-0000-0000-000000000000</ApplicationInsightsProfiler>
        </Sink>
      </SinksConfig>
    </WadCfg>
    

    备注

    如果 diagnostics.wadcfgx 文件中还包含类型为 ApplicationInsights 的其他接收器,则必须匹配以下所有三个检测密钥:If the diagnostics.wadcfgx file also contains another sink of type ApplicationInsights, all three of the following instrumentation keys must match:

    • 应用程序使用的密钥。The key that's used by your application.
    • ApplicationInsights 接收器使用的密钥。The key that's used by the ApplicationInsights sink.
    • ApplicationInsightsProfiler 接收器使用的密钥。The key that's used by the ApplicationInsightsProfiler sink.

    可以在 ServiceConfiguration.*.cscfg 文件中找到 ApplicationInsights 接收器使用的实际检测密钥值。You can find the actual instrumentation key value that's used by the ApplicationInsights sink in the ServiceConfiguration.*.cscfg files. 继 Visual Studio 15.5 Azure SDK 版本之后,只有该应用程序和 ApplicationInsightsProfiler 接收器使用的检测密钥才需相互匹配。After the Visual Studio 15.5 Azure SDK release, only the instrumentation keys that are used by the application and the ApplicationInsightsProfiler sink need to match each other.

  5. 为你的服务部署新的诊断配置,Application Insights Profiler 就可以配置为在该服务上运行了。Deploy your service with the new Diagnostics configuration, and Application Insights Profiler is configured to run on your service.

后续步骤Next steps

  • 生成到应用程序的流量(例如,启动可用性测试)。Generate traffic to your application (for example, launch an availability test). 然后等待 10 到 15 分钟,这样跟踪就会开始发送到 Application Insights 实例。Then, wait 10 to 15 minutes for traces to start to be sent to the Application Insights instance.
  • 请参阅 Azure 门户中的 Profiler 跟踪See Profiler traces in the Azure portal.
  • 若要排查 Profiler 问题,请参阅 Profiler 故障排除To troubleshoot Profiler issues, see Profiler troubleshooting.