Skip to content

Commit 59883e2

Browse files
committed
New EventCounter doc
1 parent 15f2a19 commit 59883e2

File tree

7 files changed

+138
-56
lines changed

7 files changed

+138
-56
lines changed

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

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ The [Application Insights SDK for ASP.NET Core](https://nuget.org/packages/Micro
6565

6666
```xml
6767
<ItemGroup>
68-
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.7.0" />
68+
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.8.0" />
6969
</ItemGroup>
7070
```
7171

@@ -142,35 +142,7 @@ Support for [performance counters](https://azure.microsoft.com/documentation/art
142142

143143
### EventCounter
144144

145-
[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, ASP.NET Core counters etc.
146-
147-
SDK versions 2.8.0-beta3 and higher supports collection of EventCounters. By default, the SDK collects the following counters, and these counters can be queried either in Metrics Explorer or using Analytics query under the PerformanceCounter table. The name of the counters will be of the form "Category|Counter".
148-
149-
|Category | Counter|
150-
|---------------|-------|
151-
|System.Runtime | cpu-usage |
152-
|System.Runtime | working-set |
153-
|System.Runtime | gc-heap-size |
154-
|System.Runtime | gen-0-gc-count |
155-
|System.Runtime | gen-1-gc-count |
156-
|System.Runtime | gen-2-gc-count |
157-
|System.Runtime | time-in-gc |
158-
|System.Runtime | gen-0-size |
159-
|System.Runtime | gen-1-size |
160-
|System.Runtime | gen-2-size |
161-
|System.Runtime | loh-size |
162-
|System.Runtime | alloc-rate |
163-
|System.Runtime | assembly-count |
164-
|System.Runtime | exception-count |
165-
|System.Runtime | threadpool-thread-count |
166-
|System.Runtime | monitor-lock-contention-count |
167-
|System.Runtime | threadpool-queue-length |
168-
|System.Runtime | threadpool-completed-items-count |
169-
|System.Runtime | active-timer-count |
170-
|Microsoft.AspNetCore.Hosting | requests-per-second |
171-
|Microsoft.AspNetCore.Hosting | total-requests |
172-
|Microsoft.AspNetCore.Hosting | current-requests |
173-
|Microsoft.AspNetCore.Hosting | failed-requests |
145+
`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.
174146

175147
### ILogger logs
176148

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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, and can be thought of as a cross-platform equivalent for the [PerformanceCounters](https://docs.microsoft.com/dotnet/api/system.diagnostics.performancecounter) which is only supported in Windows systems.
19+
20+
While users can publish any custom `EventCounters` to meet their needs, the .NET Core 3.0 ecosystem publishes a set of these counters out-of-the-box. 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) instructions. `EventCounterCollectionModule` collects counters with a non-configurable collection frequency of 60 seconds.
25+
26+
## Default counters collected
27+
28+
For apps running in .NET Core 3.0 or higher, the following lists the default set of counters collected automatically by the SDK. These counters can be queried either in Metrics Explorer or using Analytics query. 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: Counters of category Microsoft.AspNetCore.Hosting are only added in Asp.Net Core Applications.
57+
58+
## Customizing counters to be collected
59+
60+
The following shows how to add/remove counters. This would be done in `ConfigureServices` 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.
61+
62+
```csharp
63+
using Microsoft.ApplicationInsights.Extensibility.EventCounterCollector;
64+
65+
public void ConfigureServices(IServiceCollection services)
66+
{
67+
68+
//... other code...
69+
70+
// The following shows several customizations done to EventCounterCollectionModule.
71+
services.ConfigureTelemetryModule<EventCounterCollectionModule>(
72+
(module, o) =>
73+
{
74+
// The following removes all default counters.
75+
module.Counters.Clear();
76+
77+
// The following adds a user defined counter "MyCounter" from EventSource named "MyEventSource"
78+
module.Counters.Add(new EventCounterCollectionRequest("MyEventSource", "MyCounter"));
79+
80+
// The following 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 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 gets displayed under PerformanceCounter category.
98+
99+
![Event counters reported in Application Insights](./media/event-counters/meticsexplorer-counterlist.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 count(), 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 (eg:) over the recent period:
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 hence 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+
## <a name="next"></a>Next steps
131+
132+
* [Dependency tracking](../../azure-monitor/app/asp-net-dependencies.md)
175 KB
Loading
175 KB
Loading
60.8 KB
Loading

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

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -307,31 +307,7 @@ Dependency collection is enabled by default. [This](asp-net-dependencies.md#auto
307307

308308
### EventCounter
309309

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` |
310+
`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.
335311

336312
### Manually tracking additional telemetry
337313

@@ -555,7 +531,7 @@ Use this sample if you are using a Console Application written in either .NET Co
555531
Use this sample if you are in Asp.Net Core 2.1/2.2, and creating background tasks as per official guidance [here](https://docs.microsoft.com/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-2.2)
556532

557533
[.NET Core 3.0 Worker Service](https://github.com/microsoft/ApplicationInsights-Home/tree/master/Samples/WorkerServiceSDK/WorkerServiceSampleWithApplicationInsights)
558-
Use this sample if you have a .NET Core 3.0 Worker Service application as per official guidance [here](https://docs.microsoft.com/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-3.0&tabs=visual-studio#worker-service-template)
534+
Use this sample if you have a .NET Core 3.0 Worker Service application as per official guidance [here](https://docs.microsoft.com/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-3.0&tabs=visual-studio#worker-service-template)
559535

560536
## Open-source SDK
561537

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)