Skip to content

Commit 4dbc8b5

Browse files
authored
Merge pull request #202485 from hhunter-ms/hh-1945406
[Profiler] Enable on VM freshness
2 parents 210c779 + a7ff4ed commit 4dbc8b5

File tree

5 files changed

+170
-66
lines changed

5 files changed

+170
-66
lines changed
-10 KB
Loading
-9.08 KB
Loading
-16 KB
Loading
-10.2 KB
Loading
Lines changed: 170 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,219 @@
11
---
2-
title: Profile web apps on an Azure VM - Application Insights Profiler
3-
description: Profile web apps on an Azure VM by using Application Insights Profiler.
2+
title: Enable Profiler for web apps on an Azure virtual machine
3+
description: Profile web apps running on an Azure virtual machine or a virtual machine scale set by using Application Insights Profiler
44
ms.topic: conceptual
5-
ms.date: 11/08/2019
6-
ms.reviewer: jogrima
5+
ms.date: 07/18/2022
6+
ms.reviewer: charles.weininger
77
---
88

9-
# Profile web apps running on an Azure virtual machine or a virtual machine scale set by using Application Insights Profiler
9+
# Enable Profiler for web apps on an Azure virtual machine
1010

1111
[!INCLUDE [updated-for-az](../../../includes/updated-for-az.md)]
1212

13-
You can also deploy Azure Application Insights Profiler on these services:
14-
* [Azure App Service](./profiler.md?toc=%2fazure%2fazure-monitor%2ftoc.json)
15-
* [Azure Cloud Services](profiler-cloudservice.md?toc=/azure/azure-monitor/toc.json)
16-
* [Azure Service Fabric](?toc=%2fazure%2fazure-monitor%2ftoc.json)
13+
In this article, you learn how to run Application Insights Profiler on your Azure virtual machine (VM) or Azure virtual machine scale set via three different methods. Using any of these methods, you will:
1714

18-
## Deploy Profiler on a virtual machine or a virtual machine scale set
19-
This article shows you how to get Application Insights Profiler running on your Azure virtual machine (VM) or Azure virtual machine scale set. Profiler is installed with the Azure Diagnostics extension for VMs. Configure the extension to run Profiler, and build the Application Insights SDK into your application.
15+
- Configure the Azure Diagnostics extension to run Profiler.
16+
- Install the Application Insights SDK onto a VM.
17+
- Deploy your application.
18+
- View Profiler traces via the Application Insights instance on Azure portal.
2019

21-
1. Add the Application Insights SDK to your [ASP.NET application](../app/asp-net.md).
20+
## Pre-requisites
2221

23-
To view profiles for your requests, you must send request telemetry to Application Insights.
22+
- A functioning [ASP.NET Core application](https://docs.microsoft.com/aspnet/core/getting-started)
23+
- An [Application Insights resource](../app/create-workspace-resource.md).
24+
- Review the Azure Resource Manager templates for the Azure Diagnostics extension:
25+
- [VM](https://github.com/Azure/azure-docs-json-samples/blob/master/application-insights/WindowsVirtualMachine.json)
26+
- [Virtual machine scale set](https://github.com/Azure/azure-docs-json-samples/blob/master/application-insights/WindowsVirtualMachineScaleSet.json)
2427

25-
1. Install Azure Diagnostics extension on your VM. For full Resource Manager template examples, see:
26-
* [Virtual machine](https://github.com/Azure/azure-docs-json-samples/blob/master/application-insights/WindowsVirtualMachine.json)
27-
* [Virtual machine scale set](https://github.com/Azure/azure-docs-json-samples/blob/master/application-insights/WindowsVirtualMachineScaleSet.json)
28-
29-
The key part is the ApplicationInsightsProfilerSink in the WadCfg. To have Azure Diagnostics enable Profiler to send data to your iKey, add another sink to this section.
28+
## Add Application Insights SDK to your application
29+
30+
1. Open your ASP.NET core project in Visual Studio.
31+
32+
1. Select **Project** > **Add Application Insights Telemetry**.
33+
34+
1. Select **Azure Application Insights**, then click **Next**.
35+
36+
1. Select the subscription where your Application Insights resource lives, then click **Next**.
37+
38+
1. Select where to save connection string, then click **Next**.
39+
40+
1. Select **Finish**.
41+
42+
> [!NOTE]
43+
> For full instructions, including enabling Application Insights on your ASP.NET Core application without Visual Studio, see the [Application Insights for ASP.NET Core applications](../app/asp-net-core.md).
44+
45+
## Confirm the latest stable release of the Application Insights SDK
46+
47+
1. Go to **Project** > **Manage NuGet Packages**.
48+
49+
1. Select **Microsoft.ApplicationInsights.AspNetCore**.
50+
51+
1. In the side pane, select the latest version of the SDK from the dropdown.
52+
53+
1. Select **Update**.
54+
55+
:::image type="content" source="../app/media/asp-net-core/update-nuget-package.png" alt-text="Screenshot of where to select the Application Insights package for update.":::
56+
57+
## Enable Profiler
58+
59+
You can enable Profiler by any of the following three ways:
60+
61+
- Within your ASP.NET Core application using an Azure Resource Manager template and Visual Studio (recommended).
62+
- Using a PowerShell command via the Azure CLI.
63+
- Using Azure Resource Explorer.
64+
65+
# [Visual Studio and ARM template](#tab/vs-arm)
66+
67+
### Install the Azure Diagnostics extension
68+
69+
1. Choose which Azure Resource Manager template to use:
70+
- [VM](https://github.com/Azure/azure-docs-json-samples/blob/master/application-insights/WindowsVirtualMachine.json)
71+
- [Virtual machine scale set](https://github.com/Azure/azure-docs-json-samples/blob/master/application-insights/WindowsVirtualMachineScaleSet.json).
72+
73+
1. In the template, locate the resource of type `extension`.
74+
75+
1. In Visual Studio, navigate to the `arm.json` file in your ASP.NET Core application that was added when you installed the Application Insights SDK.
76+
77+
1. Add the resource type `extension` from the template to the `arm.json` file to set up a VM or virtual machine scale set with Azure Diagnostics.
78+
79+
1. Within the `WadCfg` tag, add your Application Insights instrumentation key to the `MyApplicationInsightsProfilerSink`.
3080

31-
```json
81+
```json
82+
"WadCfg": {
83+
"SinksConfig": {
84+
"Sink": [
85+
{
86+
"name": "MyApplicationInsightsProfilerSink",
87+
"ApplicationInsightsProfiler": "YOUR_APPLICATION_INSIGHTS_INSTRUMENTATION_KEY"
88+
}
89+
]
90+
}
91+
}
92+
```
93+
94+
1. Deploy your application.
95+
96+
# [PowerShell](#tab/powershell)
97+
98+
The following PowerShell commands are an approach for existing VMs that touch only the Azure Diagnostics extension.
99+
100+
> [!NOTE]
101+
> If you deploy the VM again, the sink will be lost. You'll need to update the config you use when deploying the VM to preserve this setting.
102+
103+
### Install Application Insights via Azure Diagnostics config
104+
105+
1. Export the currently deployed Azure Diagnostics config to a file:
106+
107+
```powershell
108+
$ConfigFilePath = [IO.Path]::GetTempFileName()
109+
```
110+
111+
1. Add the Application Insights Profiler sink to the config returned by the following command:
112+
113+
```powershell
114+
(Get-AzVMDiagnosticsExtension -ResourceGroupName "YOUR_RESOURCE_GROUP" -VMName "YOUR_VM").PublicSettings | Out-File -Verbose $ConfigFilePath
115+
```
116+
117+
Application Insights Profiler `WadCfg`:
118+
119+
```json
120+
"WadCfg": {
32121
"SinksConfig": {
33122
"Sink": [
34-
{
35-
"name": "ApplicationInsightsSink",
36-
"ApplicationInsights": "85f73556-b1ba-46de-9534-606e08c6120f"
37-
},
38123
{
39124
"name": "MyApplicationInsightsProfilerSink",
40-
"ApplicationInsightsProfiler": "85f73556-b1ba-46de-9534-606e08c6120f"
125+
"ApplicationInsightsProfiler": "YOUR_APPLICATION_INSIGHTS_INSTRUMENTATION_KEY"
41126
}
42127
]
43-
},
44-
```
128+
}
129+
}
130+
```
131+
132+
1. Run the following command to pass the updated config to the `Set-AzVMDiagnosticsExtension` command.
133+
134+
```powershell
135+
Set-AzVMDiagnosticsExtension -ResourceGroupName "YOUR_RESOURCE_GROUP" -VMName "YOUR_VM" -DiagnosticsConfigurationPath $ConfigFilePath
136+
```
137+
138+
> [!NOTE]
139+
> `Set-AzVMDiagnosticsExtension` might require the `-StorageAccountName` argument. If your original diagnostics configuration had the `storageAccountName` property in the `protectedSettings` section (which isn't downloadable), be sure to pass the same original value you had in this cmdlet call.
140+
141+
### IIS Http Tracing feature
45142

46-
1. Deploy the modified environment deployment definition.
143+
If the intended application is running through [IIS](https://www.microsoft.com/web/downloads/platform.aspx), enable the `IIS Http Tracing` Windows feature:
47144

48-
Applying the modifications usually involves a full template deployment or a cloud service-based publish through PowerShell cmdlets or Visual Studio.
145+
1. Establish remote access to the environment.
49146

50-
The following PowerShell commands are an alternate approach for existing virtual machines that touch only the Azure Diagnostics extension. Add the previously mentioned ProfilerSink to the config that's returned by the Get-AzVMDiagnosticsExtension command. Then pass the updated config to the Set-AzVMDiagnosticsExtension command.
147+
1. Use the [Add Windows features](/iis/configuration/system.webserver/tracing/) window, or run the following command in PowerShell (as administrator):
51148

52149
```powershell
53-
$ConfigFilePath = [IO.Path]::GetTempFileName()
54-
# After you export the currently deployed Diagnostics config to a file, edit it to include the ApplicationInsightsProfiler sink.
55-
(Get-AzVMDiagnosticsExtension -ResourceGroupName "MyRG" -VMName "MyVM").PublicSettings | Out-File -Verbose $ConfigFilePath
56-
# Set-AzVMDiagnosticsExtension might require the -StorageAccountName argument
57-
# If your original diagnostics configuration had the storageAccountName property in the protectedSettings section (which is not downloadable), be sure to pass the same original value you had in this cmdlet call.
58-
Set-AzVMDiagnosticsExtension -ResourceGroupName "MyRG" -VMName "MyVM" -DiagnosticsConfigurationPath $ConfigFilePath
150+
Enable-WindowsOptionalFeature -FeatureName IIS-HttpTracing -Online -All
59151
```
60152
61-
1. If the intended application is running through [IIS](https://www.microsoft.com/web/downloads/platform.aspx), enable the `IIS Http Tracing` Windows feature.
153+
If establishing remote access is a problem, you can use the [Azure CLI](/cli/azure/get-started-with-azure-cli) to run the following command:
62154
63-
1. Establish remote access to the environment, and then use the [Add Windows features](/iis/configuration/system.webserver/tracing/) window. Or run the following command in PowerShell (as administrator):
155+
```cli
156+
az vm run-command invoke -g MyResourceGroupName -n MyVirtualMachineName --command-id RunPowerShellScript --scripts "Enable-WindowsOptionalFeature -FeatureName IIS-HttpTracing -Online -All"
157+
```
64158
65-
```powershell
66-
Enable-WindowsOptionalFeature -FeatureName IIS-HttpTracing -Online -All
67-
```
68-
69-
1. If establishing remote access is a problem, you can use the [Azure CLI](/cli/azure/get-started-with-azure-cli) to run the following command:
159+
1. Deploy your application.
70160
71-
```azurecli
72-
az vm run-command invoke -g MyResourceGroupName -n MyVirtualMachineName --command-id RunPowerShellScript --scripts "Enable-WindowsOptionalFeature -FeatureName IIS-HttpTracing -Online -All"
73-
```
161+
# [Azure Resource Explorer](#tab/azure-resource-explorer)
74162
75-
1. Deploy your application.
163+
### Set Profiler sink using Azure Resource Explorer
76164
77-
## Set Profiler Sink using Azure Resource Explorer
165+
Since the Azure portal doesn't provide a way to set the Application Insights Profiler sink, you can use [Azure Resource Explorer](https://resources.azure.com) to set the sink.
78166
79-
We don't yet have a way to set the Application Insights Profiler sink from the portal. Instead of using PowerShell as described above, you can use Azure Resource Explorer to set the sink. But note, if you deploy the VM again, the sink will be lost. You'll need to update the config you use when deploying the VM to preserve this setting.
167+
> [!NOTE]
168+
> If you deploy the VM again, the sink will be lost. You'll need to update the config you use when deploying the VM to preserve this setting.
80169
81-
1. Check that the Windows Azure Diagnostics extension is installed by viewing the extensions installed for your virtual machine.
170+
1. Verify the Microsoft Azure Diagnostics extension is installed by viewing the extensions installed for your virtual machine.
82171
83-
![Check if WAD extension is installed][wadextension]
172+
:::image type="content" source="./media/profiler-vm/wad-extension.png" alt-text="Screenshot of checking if WAD extension is installed.":::
84173
85-
2. Find the VM Diagnostics extension for your VM. Go to [https://resources.azure.com](https://resources.azure.com). Expand your resource group, Microsoft.Compute virtualMachines, virtual machine name, and extensions.
174+
1. Find the VM Diagnostics extension for your VM:
175+
1. Go to [https://resources.azure.com](https://resources.azure.com).
176+
1. Expand **subscriptions** and find the subscription holding the resource group with your VM.
177+
1. Drill down to your VM extensions by selecting your resource group, followed by **Microsoft.Compute** > **virtualMachines** > **[your virtual machine]** > **extensions**.
86178
87-
![Navigate to WAD config in Azure Resource Explorer][azureresourceexplorer]
179+
:::image type="content" source="./media/profiler-vm/azure-resource-explorer.png" alt-text="Screenshot of navigating to WAD config in Azure Resource Explorer.":::
88180
89-
3. Add the Application Insights Profiler sink to the SinksConfig node under WadCfg. If you don't already have a SinksConfig section, you may need to add one. Be sure to specify the proper Application Insights iKey in your settings. You'll need to switch the explorers mode to Read/Write in the upper right corner and Press the blue 'Edit' button.
181+
1. Add the Application Insights Profiler sink to the `SinksConfig` node under WadCfg. If you don't already have a `SinksConfig` section, you may need to add one. To add the sink:
90182
91-
![Add Application Insights Profiler Sink][resourceexplorersinksconfig]
183+
- Specify the proper Application Insights iKey in your settings.
184+
- Switch the explorers mode to Read/Write in the upper right corner.
185+
- Press the blue **Edit** button.
92186
93-
4. When you're done editing the config, press 'Put'. If the put is successful, a green check will appear in the middle of the screen.
187+
:::image type="content" source="./media/profiler-vm/resource-explorer-sinks-config.png" alt-text="Screenshot of adding Application Insights Profiler sink.":::
94188
95-
![Send put request to apply changes][resourceexplorerput]
189+
```json
190+
"WadCfg": {
191+
"SinksConfig": {
192+
"Sink": [
193+
{
194+
"name": "MyApplicationInsightsProfilerSink",
195+
"ApplicationInsightsProfiler": "YOUR_APPLICATION_INSIGHTS_INSTRUMENTATION_KEY"
196+
}
197+
]
198+
}
199+
}
200+
```
96201

97202

203+
1. When you're done editing the config, press **PUT**.
98204

205+
1. If the `put` is successful, a green check will appear in the middle of the screen.
99206

207+
:::image type="content" source="./media/profiler-vm/resource-explorer-put.png" alt-text="Screenshot of sending the put request to apply changes.":::
100208

209+
---
101210

102211
## Can Profiler run on on-premises servers?
103-
We have no plan to support Application Insights Profiler for on-premises servers.
104212

105-
## Next steps
106-
107-
- Generate traffic to your application (for example, launch an [availability test](../app/monitor-web-app-availability.md)). Then, wait 10 to 15 minutes for traces to start to be sent to the Application Insights instance.
108-
- See [Profiler traces](profiler-overview.md?toc=/azure/azure-monitor/toc.json) in the Azure portal.
109-
- For help with troubleshooting Profiler issues, see [Profiler troubleshooting](profiler-troubleshooting.md?toc=/azure/azure-monitor/toc.json).
213+
Currently, Application Insights Profiler is not supported for on-premises servers.
110214

111-
[azureresourceexplorer]: ./media/profiler-vm/azure-resource-explorer.png
112-
[resourceexplorerput]: ./media/profiler-vm/resource-explorer-put.png
113-
[resourceexplorersinksconfig]: ./media/profiler-vm/resource-explorer-sinks-config.png
114-
[wadextension]: ./media/profiler-vm/wad-extension.png
215+
## Next steps
115216

217+
Learn how to...
218+
> [!div class="nextstepaction"]
219+
> [Generate load and view Profiler traces](./profiler-data.md)

0 commit comments

Comments
 (0)