适用于 .NET 的 Application Insights Profiler 是作为 Azure 应用服务运行时的一部分预先安装的。 通过使用基本服务层或更高服务层,可以在运行在应用服务上的 ASP.NET 和 ASP.NET Core 应用上运行 Profiler。
适用于 .NET 的 Application Insights Profiler 的无代码安装遵循 .NET Core 支持策略。 Azure 仅支持 基于 Windows 的 Web 应用。
若要在 Linux 上启用 .NET Profiler,请参阅在 Linux 中为 Azure 应用服务应用启用 .NET Profiler。
先决条件
验证是否已启用“始终可用”设置
在 Azure 门户中,转到应用服务实例。
在左侧菜单中选择设置>配置。
选择“常规设置”。
验证 Always On 是否已设置为 On。
注意
如果 禁用 Always on ,请升级应用服务 Web 应用以在基本层或更高版本上运行。
如果进行了更改,请选择“保存”。
启用 Application Insights 和 .NET Profiler
在以下情况下,可以启用 Profiler:
对于同一订阅中的 Application Insights 和应用服务
如果 Application Insights 资源与您的 App Service 实例处于同一订阅中:
在应用服务实例的左侧菜单中,选择“ 监视>Application Insights”。
选择 “打开 Application Insights”。
在 Application Insights 设置页的 Application Insights 下,选择“ 启用”。
验证是否已将 Application Insights 资源连接到应用。
向下滚动并选择“.NET”或“.NET Core”选项卡,具体取决于应用。
对于 集合级别,请选择建议。
在“探查器和代码优化”下,选择“开启”。 如果之前选择了“基本”收集级别,则会禁用 Profiler 设置。
选择 “应用”,然后选择 “是 ”以确认。
对于不同订阅中的 Application Insights 和应用服务
如果 Application Insights 资源与应用服务实例位于不同的订阅中,则需要手动为 .NET 环境启用 Profiler。 通过为应用服务实例创建应用设置来启用它。 可以使用模板或其他方式自动创建这些设置。 以下是启用 Profiler 所需的设置。
| 应用设置 | 值 |
|---|---|
| APPLICATIONINSIGHTS_CONNECTION_STRING | 从 Application Insights 资源的 “概述 ”页获取此值。 |
| APPINSIGHTS_PROFILERFEATURE_VERSION | 1.0.0 |
| DiagnosticServices_EXTENSION_VERSION | ~3 |
使用以下方法设置这些值:
为区域云启用 .NET Profiler
目前,由世纪互联运营的 Azure 区域需要进行终结点修改。
| 应用设置 | 由世纪互联运营的 Azure |
|---|---|
| ApplicationInsightsProfilerEndpoint | https://profiler.monitor.azure.cn |
| ApplicationInsightsEndpoint | https://dc.applicationinsights.azure.cn |
禁用 .NET Profiler
为单个应用实例停止或重启 Profiler:
在左侧菜单中的 “设置” 下,选择 “Web 作业”。
选择名为
ApplicationInsightsProfiler3的 WebJob。选择 “停止 ”图标。
选择 “停止 ”进行确认。
建议在所有应用上都启用 Profiler,以便尽早发现任何性能问题。
使用 WebDeploy 将更改部署到 Web 应用程序时,可以删除 Profiler 的文件。 可以通过在部署期间从要删除的内容中排除 App_Data 文件夹来防止删除该文件夹。