Skip to content

Commit 6e678ca

Browse files
authored
Merge pull request #89410 from cijothomas/cithomas/eventcounter1
New EventCounter doc
2 parents 919a1b9 + 758ad96 commit 6e678ca

File tree

8 files changed

+261
-156
lines changed

8 files changed

+261
-156
lines changed

articles/azure-monitor/app/asp-net-core.md

Lines changed: 99 additions & 124 deletions
Large diffs are not rendered by default.

articles/azure-monitor/app/azure-web-apps.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ms.author: mbullwin
1313
---
1414
# Monitor Azure App Service performance
1515

16-
Enabling monitoring on your .NET and .NET Core based web applications running on [Azure App Services](https://docs.microsoft.com/azure/app-service/) is now easier than ever. Whereas previously you needed to manually install a site extension, the latest extension/agent is now built into the app service image by default. This article will walk you through enabling Application Insights monitoring as well as provide preliminary guidance for automating the process for large-scale deployments.
16+
Enabling monitoring on your ASP.NET and ASP.NET Core based web applications running on [Azure App Services](https://docs.microsoft.com/azure/app-service/) is now easier than ever. Whereas previously you needed to manually install a site extension, the latest extension/agent is now built into the app service image by default. This article will walk you through enabling Application Insights monitoring as well as provide preliminary guidance for automating the process for large-scale deployments.
1717

1818
> [!NOTE]
1919
> Manually adding an Application Insights site extension via **Development Tools** > **Extensions** is deprecated. This method of extension installation was dependent on manual updates for each new version. The latest stable release of the extension is now [preinstalled](https://github.com/projectkudu/kudu/wiki/Azure-Site-Extensions) as part of the App Service image. The files are located in `d:\Program Files (x86)\SiteExtensions\ApplicationInsightsAgent` and are automatically updated with each stable release. If you follow the agent based instructions to enable monitoring below, it will automatically remove the deprecated extension for you.
@@ -321,6 +321,9 @@ Below is our step-by-step troubleshooting guide for extension/agent based monito
321321
> [!NOTE]
322322
> Java and Node.js applications are only supported on Azure App Services via manual SDK based instrumentation and therefore the steps below do not apply to these scenarios.
323323
324+
> [!NOTE]
325+
> ASP.NET Core 3.0 applications are not supported. Please follow [Manual instrumentation](https://docs.microsoft.com/azure/azure-monitor/app/asp-net-core) via code for ASP.NET Core 3.0 apps.
326+
324327
1. Check that the application is monitored via `ApplicationInsightsAgent`.
325328
* Check that `ApplicationInsightsAgent_EXTENSION_VERSION` app setting is set to a value of "~2".
326329
2. Ensure that the application meets the requirements to be monitored.
@@ -369,4 +372,4 @@ For the latest information on the Application Insights agent/extension, check ou
369372
* [Monitor service health metrics](../platform/data-platform.md) to make sure your service is available and responsive.
370373
* [Receive alert notifications](../platform/alerts-overview.md) whenever operational events happen or metrics cross a threshold.
371374
* Use [Application Insights for JavaScript apps and web pages](javascript.md) to get client telemetry from the browsers that visit a web page.
372-
* [Set up Availability web tests](monitor-web-app-availability.md) to be alerted if your site is down.
375+
* [Set up Availability web tests](monitor-web-app-availability.md) to be alerted if your site is down.
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
---
2+
title: Event counters in Application Insights | Microsoft Docs
3+
description: Monitor system and custom .NET/.NET Core EventCounters in Application Insights.
4+
services: application-insights
5+
documentationcenter: ''
6+
author: cithomas
7+
manager: carmonm
8+
ms.assetid: 5b816f4c-a77a-4674-ae36-802ee3a2f56d
9+
ms.service: application-insights
10+
ms.workload: tbd
11+
ms.tgt_pltfrm: ibiza
12+
ms.topic: conceptual
13+
ms.date: 09/20/2019
14+
ms.author: cithomas
15+
---
16+
# EventCounters introduction
17+
18+
`EventCounter` is .NET/.NET Core mechanism to publish and consume counters or statistics. [This](https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.Tracing/documentation/EventCounterTutorial.md) document gives an overview of `EventCounters` and examples on how to publish and consume them. EventCounters are supported in all OS platforms - Windows, Linux, and macOS. It can be thought of as a cross-platform equivalent for the [PerformanceCounters](https://docs.microsoft.com/dotnet/api/system.diagnostics.performancecounter) that is only supported in Windows systems.
19+
20+
While users can publish any custom `EventCounters` to meet their needs, the .NET Core 3.0 runtime publishes a set of these counters by default. The document will walk through the steps required to collect and view `EventCounters` (system defined or user defined) in Azure Application Insights.
21+
22+
## Using Application Insights to collect EventCounters
23+
24+
Application Insights supports collecting `EventCounters` with its `EventCounterCollectionModule`, which is part of the newly released nuget package [Microsoft.ApplicationInsights.EventCounterCollector](https://www.nuget.org/packages/Microsoft.ApplicationInsights.EventCounterCollector). `EventCounterCollectionModule` is automatically enabled when using either [AspNetCore](asp-net-core.md) or [WorkerService](worker-service.md). `EventCounterCollectionModule` collects counters with a non-configurable collection frequency of 60 seconds. There are no special permissions required to collect EventCounters.
25+
26+
## Default counters collected
27+
28+
For apps running in .NET Core 3.0, the following counters are collected automatically by the SDK. The name of the counters will be of the form "Category|Counter".
29+
30+
|Category | Counter|
31+
|---------------|-------|
32+
|`System.Runtime` | `cpu-usage` |
33+
|`System.Runtime` | `working-set` |
34+
|`System.Runtime` | `gc-heap-size` |
35+
|`System.Runtime` | `gen-0-gc-count` |
36+
|`System.Runtime` | `gen-1-gc-count` |
37+
|`System.Runtime` | `gen-2-gc-count` |
38+
|`System.Runtime` | `time-in-gc` |
39+
|`System.Runtime` | `gen-0-size` |
40+
|`System.Runtime` | `gen-1-size` |
41+
|`System.Runtime` | `gen-2-size` |
42+
|`System.Runtime` | `loh-size` |
43+
|`System.Runtime` | `alloc-rate` |
44+
|`System.Runtime` | `assembly-count` |
45+
|`System.Runtime` | `exception-count` |
46+
|`System.Runtime` | `threadpool-thread-count` |
47+
|`System.Runtime` | `monitor-lock-contention-count` |
48+
|`System.Runtime` | `threadpool-queue-length` |
49+
|`System.Runtime` | `threadpool-completed-items-count` |
50+
|`System.Runtime` | `active-timer-count` |
51+
|`Microsoft.AspNetCore.Hosting` | `requests-per-second` |
52+
|`Microsoft.AspNetCore.Hosting` | `total-requests` |
53+
|`Microsoft.AspNetCore.Hosting` | `current-requests` |
54+
|`Microsoft.AspNetCore.Hosting` | `failed-requests` |
55+
56+
> [!NOTE]
57+
> Counters of category Microsoft.AspNetCore.Hosting are only added in Asp.Net Core Applications.
58+
59+
## Customizing counters to be collected
60+
61+
The following example shows how to add/remove counters. This customization would be done in the `ConfigureServices` method of your application after Application Insights telemetry collection is enabled using either `AddApplicationInsightsTelemetry()` or `AddApplicationInsightsWorkerService()`. Following is an example code from an ASP.NET Core application. For other type of applications, refer to [this](worker-service.md#configuring-or-removing-default-telemetrymodules) document.
62+
63+
```csharp
64+
using Microsoft.ApplicationInsights.Extensibility.EventCounterCollector;
65+
66+
public void ConfigureServices(IServiceCollection services)
67+
{
68+
//... other code...
69+
70+
// The following code shows several customizations done to EventCounterCollectionModule.
71+
services.ConfigureTelemetryModule<EventCounterCollectionModule>(
72+
(module, o) =>
73+
{
74+
// This removes all default counters.
75+
module.Counters.Clear();
76+
77+
// This adds a user defined counter "MyCounter" from EventSource named "MyEventSource"
78+
module.Counters.Add(new EventCounterCollectionRequest("MyEventSource", "MyCounter"));
79+
80+
// This adds the system counter "gen-0-size" from "System.Runtime"
81+
module.Counters.Add(new EventCounterCollectionRequest("System.Runtime", "gen-0-size"));
82+
}
83+
);
84+
85+
// The following code removes EventCounterCollectionModule to disable the module completely.
86+
var eventCounterModule = services.FirstOrDefault<ServiceDescriptor>
87+
(t => t.ImplementationType == typeof(EventCounterCollectionModule));
88+
if (eventCounterModule != null)
89+
{
90+
services.Remove(eventCounterModule);
91+
}
92+
}
93+
```
94+
95+
## Event counters in Metric Explorer
96+
97+
To view EventCounter metrics in [Metric Explorer](https://docs.microsoft.com/azure/azure-monitor/platform/metrics-charts), select Application Insights resource, and chose Log-based metrics as metric namespace. Then EventCounter metrics get displayed under PerformanceCounter category.
98+
99+
![Event counters reported in Application Insights](./media/event-counters/metrics-explorer-counter-list.png)
100+
101+
## Event counters in Analytics
102+
103+
You can also search and display event counter reports in [Analytics](../../azure-monitor/app/analytics.md), in the **performanceCounters** table.
104+
105+
For example, run the following query to see what counters are collected and available to query:
106+
107+
```Kusto
108+
performanceCounters | summarize avg(value) by name
109+
```
110+
111+
![Event counters reported in Application Insights](./media/event-counters/analytics-event-counters.png)
112+
113+
To get a chart of a specific counter (for example: `ThreadPool Completed Work Item Count`) over the recent period, run the following query.
114+
115+
```Kusto
116+
performanceCounters
117+
| where name contains "System.Runtime|ThreadPool Completed Work Item Count"
118+
| where timestamp >= ago(1h)
119+
| summarize avg(value) by cloud_RoleInstance, bin(timestamp, 1m)
120+
| render timechart
121+
```
122+
123+
![Chat of a single counter in Application Insights](./media/event-counters/analytics-completeditems-counters.png)
124+
125+
Like other telemetry, **performanceCounters** also has a column `cloud_RoleInstance` that indicates the identity of the host server instance on which your app is running. The above query shows the counter value per instance, and can be used to compare performance of different server instances.
126+
127+
## Alerts
128+
Like other metrics, you can [set an alert](../../azure-monitor/app/alerts.md) to warn you if an event counter goes outside a limit you specify. Open the Alerts pane and click Add Alert.
129+
130+
## Frequently asked questions
131+
132+
### Can I see EventCounters in Live Metrics?
133+
134+
Live Metrics do not show EventCounters as of today. Use Metric Explorer or Analytics to see the telemetry.
135+
136+
### Which platforms can I see the default list of .NET Core 3.0 counters?
137+
138+
EventCounter doesn't require any special permissions, and is supported in all platforms .NET Core 3.0 is supported. This includes:
139+
140+
* **Operating system**: Windows, Linux, or macOS.
141+
* **Hosting method**: In process or out of process.
142+
* **Deployment method**: Framework dependent or self-contained.
143+
* **Web server**: IIS (Internet Information Server) or Kestrel.
144+
* **Hosting platform**: The Web Apps feature of Azure App Service, Azure VM, Docker, Azure Kubernetes Service (AKS), and so on.
145+
146+
### I have enabled Application Insights from Azure Web App Portal. But I can't see EventCounters.?
147+
148+
[Application Insights extension](https://docs.microsoft.com/azure/azure-monitor/app/azure-web-apps) for ASP.NET Core doesn't yet support this feature. This document will be updated when this feature is supported.
149+
150+
## <a name="next"></a>Next steps
151+
152+
* [Dependency tracking](../../azure-monitor/app/asp-net-dependencies.md)
89 KB
Loading
108 KB
Loading
60.8 KB
Loading

articles/azure-monitor/app/worker-service.md

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ Application Insights is releasing a new SDK, called `Microsoft.ApplicationInsigh
2020

2121
The new SDK does not do any telemetry collection by itself. Instead, it brings in other well known Application Insights auto collectors like [DependencyCollector](https://www.nuget.org/packages/Microsoft.ApplicationInsights.DependencyCollector/), [PerfCounterCollector](https://www.nuget.org/packages/Microsoft.ApplicationInsights.PerfCounterCollector/), [ApplicationInsightsLoggingProvider](https://www.nuget.org/packages/Microsoft.Extensions.Logging.ApplicationInsights) etc. This SDK exposes extension methods on `IServiceCollection` to enable and configure telemetry collection.
2222

23-
> [!NOTE]
24-
> This article is about a new package from Application Insights SDK for Worker Services. This package is available as a beta package today. This document will be updated when a stable package is available.
25-
2623
## Supported scenarios
2724

2825
The [Application Insights SDK for Worker Service](https://www.nuget.org/packages/Microsoft.ApplicationInsights.WorkerService) is best suited for non-HTTP applications no matter where or how they run. If your application is running and has network connectivity to Azure, telemetry can be collected. Application Insights monitoring is supported everywhere .NET Core is supported. This package can be used in the newly introduced [.NET Core 3.0 Worker Service](https://devblogs.microsoft.com/aspnet/dotnet-core-workers-in-azure-container-instances), [background tasks in Asp.Net Core 2.1/2.2](https://docs.microsoft.com/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-2.2), Console apps (.NET Core/ .NET Framework), etc.
@@ -38,7 +35,7 @@ A valid Application Insights instrumentation key. This key is required to send a
3835

3936
```xml
4037
<ItemGroup>
41-
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.8.0-beta3" />
38+
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.8.0" />
4239
</ItemGroup>
4340
```
4441

@@ -295,7 +292,7 @@ The following lists the full telemetry automatically collected by Application In
295292

296293
### Live Metrics
297294

298-
[Live Metrics](https://docs.microsoft.com/azure/application-insights/app-insights-live-stream) can be used to quickly verify if Application Insights is setup correctly. While it might take a few minutes before telemetry starts appearing in the portal and analytics, Live Metrics would show CPU usage of the running process in near real-time. It can also show other telemetry like Requests, Dependencies, Traces etc.
295+
[Live Metrics](https://docs.microsoft.com/azure/application-insights/app-insights-live-stream) can be used to quickly verify if Application Insights monitoring is configured correctly. While it might take a few minutes before telemetry starts appearing in the portal and analytics, Live Metrics would show CPU usage of the running process in near real-time. It can also show other telemetry like Requests, Dependencies, Traces etc.
299296

300297
### ILogger logs
301298

@@ -307,31 +304,7 @@ Dependency collection is enabled by default. [This](asp-net-dependencies.md#auto
307304

308305
### EventCounter
309306

310-
[EventCounter](https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.Tracing/documentation/EventCounterTutorial.md), is a cross-platform method to publish and consume counters in .NET/.NET Core. Though this feature existed before, there was no built-in providers who published these counters. Starting with .NET Core 3.0, several counters are published out of the box like CLR Counters, CPU etc.
311-
312-
By default, the SDK collects the following counters (available only in .NET Core 3.0 or above), and these counters can be queried either in Metrics Explorer or by using an Analytics query targeting the PerformanceCounter table. The name of the counters will be of the form "Category|Counter".
313-
314-
|Category | Counter|
315-
|---------------|-------|
316-
|`System.Runtime` | `cpu-usage` |
317-
|`System.Runtime` | `working-set` |
318-
|`System.Runtime` | `gc-heap-size` |
319-
|`System.Runtime` | `gen-0-gc-count` |
320-
|`System.Runtime` | `gen-1-gc-count` |
321-
|`System.Runtime` | `gen-2-gc-count` |
322-
|`System.Runtime` | `time-in-gc` |
323-
|`System.Runtime` | `gen-0-size` |
324-
|`System.Runtime` | `gen-1-size` |
325-
|`System.Runtime` | `gen-2-size` |
326-
|`System.Runtime` | `loh-size` |
327-
|`System.Runtime` | `alloc-rate` |
328-
|`System.Runtime` | `assembly-count` |
329-
|`System.Runtime` | `exception-count` |
330-
|`System.Runtime` | `threadpool-thread-count` |
331-
|`System.Runtime` | `monitor-lock-contention-count` |
332-
|`System.Runtime` | `threadpool-queue-length` |
333-
|`System.Runtime` | `threadpool-completed-items-count` |
334-
|`System.Runtime` | `active-timer-count` |
307+
`EventCounterCollectionModule` is enabled by default, and it will collect a default set of counters from .NET Core 3.0 apps. The [EventCounter](eventcounters.md) tutorial lists the default set of counters collected. It also has instructions on customizing the list.
335308

336309
### Manually tracking additional telemetry
337310

articles/azure-monitor/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,8 @@
431431
href: app/asp-net-trace-logs.md
432432
- name: Performance counters
433433
href: app/performance-counters.md
434+
- name: EventCounters
435+
href: app/eventcounters.md
434436
- name: Dependencies
435437
href: app/asp-net-dependencies.md
436438
- name: ApplicationInsights.config

0 commit comments

Comments
 (0)