Performance and exception monitoring with Application Insights
Application Insights is in preview.
Caution
|
|---|
|
This is about the older version of Application Insights in Visual Studio Online. There’s a new version in Microsoft Azure. How do I know which I’m using, and how do I choose? |
Performance monitoring with Application Insights lets you know if your web application is throwing exceptions, running slow, suffering memory leaks or running out of resources. If any of these events happens, Application Insights shows you tables and charts that help you diagnose the problem. You can be notified by email if things get really bad. You can drill into the stack trace in Visual Studio to pinpoint the problem in the code.
You can monitor any web application, whether it’s an ordinary website or, for example, the server component of a phone application. The agent collects data with very little overhead. You don’t have to change your code.
You might not need to do anything to start getting performance data. Open the Performance pages in Application Insights, and select your application. If you see setup instructions, follow them.
To explain a little more: To get performance data, you have to:
-
Have a copy of ApplicationInsights.config in the root folder of your web application or website. If you already added Application Insights to your application project, then you already have it.
-
Have an agent running on the server. The details depend on the platform you are using:
-
Microsoft Azure web role: Azure provides the agent and you only need a couple of other files. If you already added Application Insights to your application project, then you have those and don’t need anything else. (Learn more.)
-
IIS server or Java server (on your own machine or a VM): You have to install the appropriate agent. But you only need to install one on each server. If you install extra applications, it discovers them automatically. (Learn more: IIS; Java.)
-
After 20 minutes, in Application Insights, look for the performance counters and metrics that will show up in the Server Performance and Diagnostics pages.
-
Select the name of your application component to see the results.
If you want to have results appear under a different application component name, update the ComponentName property in ApplicationInsights.config.
-
To adjust the scale of the chart, set the date range.
-
Zoom in and out by dragging the pointer across part of the smaller summary chart.
Notice that the smaller charts also use the same date range.
Performance events are logged whenever a performance counter crosses a threshold. Detailed results appear under Diagnostics.
-
Edit the set of metrics that appears on the chart.
-
Get an email whenever a metric crosses a threshold.
-
Drill into listings of events
-
Expand an event count to see instances of the event.
-
Open an instance of the event to see the stack trace. Get the IntelliTrace log.
The stack trace omits methods that run for less than a specified minimum time.
You can open the IntelliTrace log in Visual Studio Ultimate.
Does your web application periodically run out of memory? Typically the symptom is a gradual slowdown, followed by a sudden recovery when IIS restarts your application.
Now that you’re using Application Insights, this problem will show up as a memory event under Diagnostics, Events. The event is generated when your application is using 90% of the maximum memory allocated to it by IIS, or when the application is occupying more than 50% of the machine’s physical memory. You can adjust these parameters to refine the data you get.
Open the event and then download the memory dump. Open the dump file in Visual Studio Ultimate 2013. There are actually two dumps: one taken when the event was generated, and another a while earlier. By comparing the two, you should be able to see which objects are not being properly disposed.
Anecdotal advice is that event handlers are a typical source of problems.
See Customizing Application Insights in ApplicationInsights.config to find out what you can adjust by editing ApplicationInsights.config.
Microsoft Monitoring Agent reconfigures automatically when you update ApplicationInsights.config in your web application on your web server. If you’re using the Application Insights SDK to monitor how people use your application, then you’ll typically update the file in your web app project, and then redeploy it to your web server. Otherwise, you can update the file directly in the web server.
-
On the Overview/Servers page, check that your server is listed with a green indicator. If so, then communications are being received from the agent.
-
Make sure your web app is running.
-
Make sure you’re looking at the right application component. Try selecting another component from the drop-down list near the top left of the page.
-
Is there more than one web app running on your server? If so, open ApplicationInsights.config in the root folder of each web app, and check that:
-
<ComponentName> is different in each one.
-
<AccountID> and <LicenseKey> are the same in each one. Microsoft Monitoring Agent can only send data to Application Insights in a single Visual Studio Online account. It sets the first account as its default, and won’t monitor web apps for other accounts. To reset it, use its control panel, or set-DefaultMonitoringCredentials.
-
The agent reports only a limited number of diagnostic events of each group, in a given interval. This throttling behavior prevents telemetry from affecting your server’s performance, but allows you to see a representative set of events from which you can diagnose the problem. Typically the statistical distribution of reported events is proportionate to the real distribution, so that you can assess the relative importance of different issues.
The throttling limits are:
|
Maximum |
per minute |
per hour |
per day |
|---|---|---|---|
|
Total performance events |
60 |
600 |
1200 |
|
Performance events per group |
3 |
30 |
60 |
|
Total exception events |
15 |
60 |
300 |
|
Exception events per group |
3 |
15 |
30 |
For example, if four uncaught SQL exceptions occur in a minute, only three will be reported. But if an arithmetic exception is thrown in the same minute, it will be reported.
OK. If you’re running on a machine with Microsoft Monitoring Agent, you can use it in local mode. That dumps all the information to a local file on the server. You can pick up the file when you want to, and open it in Visual Studio Ultimate. You won’t get the nice reports, but you’ll see IntelliTrace logs of every event.
Use PowerShell in administrator mode:
Start-WebApplicationMonitoring -Local "Default Web Site" –OutputPath outputfolder –Mode Trace
When you’re ready to look at the log, use checkpoint-webApplicationMonitoring to save the log and continue, or
Stop-WebApplicationMonitoring –Local -All
-
Set an alert to let you know as soon as a performance issue occurs.
-
Log and search diagnostic events to help fix any issues in your live application.
-
Detect and diagnose performance issues – Some practical experience in using Application Insights.
-
Track usage to find out how people are using your app, so that you can make it serve them better.
-
Set up deployment markers on your charts, so that you can see how changes you make affect performance and usage.
Caution