EventCounters 소개

EventCounter는 카운터 또는 통계를 게시 및 소비하는 .NET/.NET Core 메커니즘입니다. EventCounters는 모든 OS 플랫폼(Windows, Linux 및 macOS)에서 지원됩니다. 이는 Windows 시스템에서만 지원되는 PerformanceCounters와 달리 플랫폼 간 지원에 해당하는 것으로 볼 수 있습니다.

사용자가 요구 사항을 충족하기 위해 사용자 지정 EventCounters를 게시할 수 있지만 .NET은 기본적으로 이러한 카운터 집합을 게시합니다. 이 문서는 Azure Application Insights에서 EventCounters(시스템 정의 또는 사용자 정의)를 수집하고 확인하는 데 필요한 단계를 안내합니다.

참고 항목

다음 설명서는 Application Insights 클래식 API를 사용합니다. Application Insights에 대한 장기 플랜은 OpenTelemetry를 사용하여 데이터를 수집하는 것입니다. 자세한 내용은 .NET, Node.js, Python 및 Java 애플리케이션에 대해 Azure Monitor OpenTelemetry 사용을 참조하세요.

Application Insights를 사용하여 EventCounters 수집

Application Insights는 새로 릴리스된 NuGet 패키지 Microsoft.ApplicationInsights.EventCounterCollector의 일부인 EventCounterCollectionModule을 사용한 EventCounters 수집을 지원합니다. EventCounterCollectionModuleAspNetCore 또는 WorkerService를 사용하는 경우 자동으로 사용하도록 설정됩니다. EventCounterCollectionModule은 구성 불가능한 수집 빈도(60초)로 카운터를 수집합니다. EventCounters를 수집하는 데 필요한 특별 권한은 없습니다. ASP.NET Core 애플리케이션의 경우 Microsoft.ApplicationInsights.AspNetCore 패키지도 추가하려고 합니다.

dotnet add package Microsoft.ApplicationInsights.EventCounterCollector
dotnet add package Microsoft.ApplicationInsights.AspNetCore

수집된 기본 카운터

AspNetCore SDK 또는 WorkerService SDK의 2.15.0 버전을 사용하여 시작하는 경우 기본적으로 카운터가 수집되지 않습니다. 모듈 자체를 사용할 수 있으므로 사용자가 원하는 카운터를 추가하여 수집합니다.

.NET 런타임에 게시된 잘 알려진 카운터 목록을 가져오려면 사용 가능한 카운터 문서를 참조하세요.

수집할 카운터 사용자 지정

다음 예에서는 카운터를 추가/제거하는 방법을 보여 줍니다. AddApplicationInsightsTelemetry() 또는 AddApplicationInsightsWorkerService()를 사용하여 Application Insights 원격 분석 수집을 사용하도록 설정한 후 애플리케이션 서비스 구성의 일부로 이 사용자 지정을 수행합니다. ASP.NET Core 애플리케이션의 코드 예는 다음과 같습니다. 다른 유형의 애플리케이션에 대해서는 문서를 참조하세요.

using Microsoft.ApplicationInsights.Extensibility.EventCounterCollector;
using Microsoft.Extensions.DependencyInjection;

builder.Services.ConfigureTelemetryModule<EventCounterCollectionModule>(
        (module, o) =>
        {
            // Removes all default counters, if any.
            module.Counters.Clear();

            // Adds a user defined counter "MyCounter" from EventSource named "MyEventSource"
            module.Counters.Add(
                new EventCounterCollectionRequest("MyEventSource", "MyCounter"));

            // Adds the system counter "gen-0-size" from "System.Runtime"
            module.Counters.Add(
                new EventCounterCollectionRequest("System.Runtime", "gen-0-size"));
        }
    );

EventCounter 수집 모듈을 사용하지 않도록 설정

EventCounterCollectionModuleApplicationInsightsServiceOptions를 사용하여 사용하지 않도록 설정할 수 있습니다.

다음 예제에서는 ASP.NET Core SDK를 사용합니다.

using Microsoft.ApplicationInsights.AspNetCore.Extensions;
using Microsoft.Extensions.DependencyInjection;

var applicationInsightsServiceOptions = new ApplicationInsightsServiceOptions();
applicationInsightsServiceOptions.EnableEventCounterCollectionModule = false;
builder.Services.AddApplicationInsightsTelemetry(applicationInsightsServiceOptions);

WorkerService SDK에도 유사한 방법을 사용할 수 있지만, 네임스페이스는 다음 예제에 표시된 것처럼 변경되어야 합니다.

using Microsoft.ApplicationInsights.AspNetCore.Extensions;
using Microsoft.Extensions.DependencyInjection;

var applicationInsightsServiceOptions = new ApplicationInsightsServiceOptions();
applicationInsightsServiceOptions.EnableEventCounterCollectionModule = false;
builder.Services.AddApplicationInsightsTelemetry(applicationInsightsServiceOptions);

메트릭 탐색기의 이벤트 카운터

메트릭 탐색기에서 EventCounter 메트릭을 보려면 Application Insights 리소스를 선택하고 로그 기반 메트릭을 메트릭 네임스페이스로 선택합니다. 그러면 EventCounter 메트릭이 사용자 지정 범주에 표시됩니다.

Event counters reported in Application Insights Metric Explorer

Analytics의 이벤트 카운터

Analytics에서 customMetrics 테이블의 이벤트 카운터 보고서를 검색하고 표시할 수도 있습니다.

예를 들어 다음 쿼리를 실행하여 수집된 카운터 및 쿼리에 사용할 수 있는 카운터를 확인합니다.

customMetrics | summarize avg(value) by name

Event counters reported in Application Insights Analytics

최근 기간 동안 특정 카운터 차트(예: ThreadPool Completed Work Item Count)를 가져오려면 다음 쿼리를 실행합니다.

customMetrics 
| where name contains "System.Runtime|ThreadPool Completed Work Item Count"
| where timestamp >= ago(1h)
| summarize  avg(value) by cloud_RoleInstance, bin(timestamp, 1m)
| render timechart

Chat of a single counter in Application Insights

다른 원격 분석과 마찬가지로 customMetrics에도 앱이 실행되는 호스트 서버 인스턴스의 ID를 나타내는 cloud_RoleInstance 열이 있습니다. 위의 쿼리는 인스턴스당 카운터 값을 표시하며 다른 서버 인스턴스의 성능을 비교하는 데 사용할 수 있습니다.

경고

다른 메트릭과 마찬가지로 이벤트 카운터에서 지정한 제한을 벗어나는 경우 경고 메시지를 표시하도록 경고를 설정할 수 있습니다. 경고 창을 열고 경고 추가를 선택합니다.

자주 묻는 질문

라이브 메트릭의 EventCounters를 볼 수 있나요?

라이브 메트릭은 현재 EventCounters를 표시하지 않습니다. 원격 분석을 보려면 메트릭 탐색기 또는 Analytics를 사용합니다.

Azure Web App 포털에서 Application Insights를 사용하도록 설정했습니다. EventCounters를 볼 수 없는 이유는 무엇인가요?

ASP.NET Core용 Application Insights 확장은 아직 이 기능을 지원하지 않습니다.

다음 단계