다음을 통해 공유


성능 카운터 조사(dotnet-counters)

이 문서는 버전 3.0.47001 이상 버전에 적용됩니다 ✔️ dotnet-counters .

.NET 5 이상을 실행하는 애플리케이션에서 카운터를 읽을 수 있습니다.

설치

다음 두 가지 방법으로 dotnet-counters를 다운로드하고 설치할 수 있습니다.

참고 항목

x86 앱에서 dotnet-counters를 사용하려면 해당하는 x86 버전의 도구가 필요합니다.

개요

dotnet-counters [-h|--help] [--version] <command>

설명

dotnet-counters는 임시 상태 모니터링 및 1단계 수준 성능 조사를 위한 성능 모니터링 도구입니다. EventCounter API 또는 Meter API를 통해 게시된 성능 카운터 값을 관찰할 수 있습니다. 예를 들어, PerfView 또는 dotnet-trace를 사용하여 보다 심각한 성능 조사를 살펴보기 전에 의심스러운 내용이 있는지 확인하기 위해 .NET Core 애플리케이션에서 throw되는 CPU 사용량 또는 예외 비율과 같은 항목을 신속하게 모니터링할 수 있습니다.

옵션

  • --version

    dotnet-counters 유틸리티의 버전을 표시합니다.

  • -h|--help

    명령줄 도움말을 표시합니다.

명령

명령
dotnet-counters collect
dotnet-counters 목록
dotnet-counters 모니터
dotnet-counters ps

dotnet-counters collect

선택한 카운터 값을 주기적으로 수집하고 후처리를 위해 지정된 파일 형식으로 내보냅니다.

개요

dotnet-counters collect [-h|--help] [-p|--process-id] [-n|--name] [--diagnostic-port] [--refresh-interval] [--counters <COUNTERS>] [--format] [-o|--output] [-- <command>]

옵션

  • -p|--process-id <PID>

    카운터 데이터를 수집할 프로세스의 ID입니다.

  • -n|--name <name>

    카운터 데이터를 수집할 프로세스의 이름입니다.

  • --diagnostic-port

    만들 진단 포트의 이름입니다. 이 옵션을 사용하여 앱 시작부터 카운터 모니터링을 시작하는 방법은 진단 포트 사용을 참조하세요.

  • --refresh-interval <SECONDS>

    표시된 카운터 업데이트 사이의 지연 시간(초)입니다.

  • --counters <COUNTERS>

    쉼표로 구분된 카운터 목록입니다. 카운터는 provider_name[:counter_name]을 지정할 수 있습니다. 적격 카운터 목록 없이 provider_name이 사용되는 경우 공급자의 모든 카운터가 표시됩니다. 공급자 및 카운터 이름을 검색하려면 dotnet-counters 목록 명령을 사용합니다. EventCounters의 경우 provider_name(은)는 EventSource의 이름이고 미터경우 provider_name(은)는 미터의 이름입니다.

  • --format <csv|json>

    내보낼 형식입니다. 현재 csv와 json을 사용할 수 있습니다.

  • -o|--output <output>

    출력 파일의 이름입니다.

  • -- <command>

    컬렉션 구성 매개 변수 후에 사용자는 명령을 추가하여 -- .NET 애플리케이션을 시작할 수 있습니다. dotnet-counters는 제공된 명령을 사용하여 프로세스를 시작하고 요청된 메트릭을 수집합니다. 이 옵션은 애플리케이션의 시작 경로에 대한 메트릭을 수집하는 데 유용하며, 주요 진입점 이전이나 바로 다음에 발생하는 문제를 진단하거나 모니터링하는 데 사용할 수 있습니다.

    참고 항목

    이 옵션을 사용하면 도구와 다시 통신하는 첫 번째 .NET 프로세스를 모니터링합니다. 즉, 명령이 여러 .NET 애플리케이션을 시작하는 경우 첫 번째 앱만 수집합니다. 따라서 자체 포함 애플리케이션에서 이 옵션을 사용하거나 dotnet exec <app.dll> 옵션을 사용하는 것이 좋습니다.

    참고 항목

    dotnet-counters를 통해 .NET 실행 파일을 시작하면 해당 입력/출력이 리디렉션되며 해당 stdin/stdout과 상호 작용할 수 없습니다. Ctrl+C 또는 SIGTERM을 통해 도구를 종료하면 도구와 자식 프로세스가 모두 안전하게 종료됩니다. 자식 프로세스가 도구보다 먼저 종료되면 도구도 종료됩니다. Stdin/stdout을 사용해야 하는 경우 --diagnostic-port 옵션을 사용할 수 있습니다. 자세한 내용은 진단 포트 사용을 참조하세요.

참고 항목

Linux 및 macOS에서 해당 명령은 대상 애플리케이션 및 dotnet-counters가 동일한 TMPDIR 환경 변수를 공유할 것으로 예상합니다. 그러지 않으면 명령 시간이 초과됩니다.

참고 항목

dotnet-counters를 사용하여 메트릭을 수집하려면 대상 프로세스를 실행하는 사용자와 동일한 사용자 또는 루트로 실행해야 합니다. 그러지 않으면 도구는 대상 프로세스와 연결을 설정하지 못합니다.

예제

  • 3초의 새로 고침 간격으로 모든 카운터를 수집하고 csv를 출력으로 생성합니다.

    > dotnet-counters collect --process-id 1902 --refresh-interval 3 --format csv
    
    --counters is unspecified. Monitoring System.Runtime counters by default.
    Starting a counter session. Press Q to quit.
    
  • dotnet mvc.dll을 자식 프로세스로 시작하고 시작에서 런타임 카운터 및 ASP.NET Core 호스팅 카운터 수집을 시작하여 JSON 출력으로 저장합니다.

    > dotnet-counters collect --format json --counters System.Runtime,Microsoft.AspNetCore.Hosting -- dotnet mvc.dll
    Starting a counter session. Press Q to quit.
    File saved to counter.json
    

dotnet-counters 목록

공급자별로 그룹화된 카운터 이름 및 설명 목록을 표시합니다.

개요

dotnet-counters list [-h|--help]

예시

> dotnet-counters list
Showing well-known counters only. Specific processes may support additional counters.

System.Runtime
    cpu-usage                                    Amount of time the process has utilized the CPU (ms)
    working-set                                  Amount of working set used by the process (MB)
    gc-heap-size                                 Total heap size reported by the GC (MB)
    gen-0-gc-count                               Number of Gen 0 GCs per interval
    gen-1-gc-count                               Number of Gen 1 GCs per interval
    gen-2-gc-count                               Number of Gen 2 GCs per interval
    time-in-gc                                   % time in GC since the last GC
    gen-0-size                                   Gen 0 Heap Size
    gen-1-size                                   Gen 1 Heap Size
    gen-2-size                                   Gen 2 Heap Size
    loh-size                                     LOH Heap Size
    alloc-rate                                   Allocation Rate
    assembly-count                               Number of Assemblies Loaded
    exception-count                              Number of Exceptions per interval
    threadpool-thread-count                      Number of ThreadPool Threads
    monitor-lock-contention-count                Monitor Lock Contention Count
    threadpool-queue-length                      ThreadPool Work Items Queue Length
    threadpool-completed-items-count             ThreadPool Completed Work Items Count
    active-timer-count                           Active Timers Count

Microsoft.AspNetCore.Hosting
    requests-per-second                  Request rate
    total-requests                       Total number of requests
    current-requests                     Current number of requests
    failed-requests                      Failed number of requests

참고 항목

이러한 카운터를 지원하는 프로세스를 식별한 경우, 예를 들어 호스트 머신에서 ASP.NET Core 애플리케이션이 실행되고 있는 경우 Microsoft.AspNetCore.Hosting 카운터가 표시됩니다.

dotnet-counters 모니터

선택한 카운터의 값을 주기적으로 새로 고치는 방법을 표시합니다.

개요

dotnet-counters monitor [-h|--help] [-p|--process-id] [-n|--name] [--diagnostic-port] [--refresh-interval] [--counters] [-- <command>]

옵션

  • -p|--process-id <PID>

    모니터링할 프로세스의 ID입니다.

  • -n|--name <name>

    모니터링할 프로세스의 이름입니다.

  • --diagnostic-port

    만들 진단 포트의 이름입니다. 이 옵션을 사용하여 앱 시작부터 카운터 모니터링을 시작하는 방법은 진단 포트 사용을 참조하세요.

  • --refresh-interval <SECONDS>

    표시된 카운터 업데이트 사이의 지연 시간(초)입니다.

  • --counters <COUNTERS>

    쉼표로 구분된 카운터 목록입니다. 카운터는 provider_name[:counter_name]을 지정할 수 있습니다. 적격 카운터 목록 없이 provider_name이 사용되는 경우 공급자의 모든 카운터가 표시됩니다. 공급자 및 카운터 이름을 검색하려면 dotnet-counters 목록 명령을 사용합니다. EventCounters의 경우 provider_name(은)는 EventSource의 이름이고 미터경우 provider_name(은)는 미터의 이름입니다.

-- <command>

컬렉션 구성 매개 변수 후에 사용자는 명령을 추가하여 -- .NET 애플리케이션을 시작할 수 있습니다. dotnet-counters는 제공된 명령을 사용하여 프로세스를 시작하고 요청된 메트릭을 모니터링합니다. 이 옵션은 애플리케이션의 시작 경로에 대한 메트릭을 수집하는 데 유용하며, 주요 진입점 이전이나 바로 다음에 발생하는 문제를 진단하거나 모니터링하는 데 사용할 수 있습니다.

참고 항목

이 옵션을 사용하면 도구와 다시 통신하는 첫 번째 .NET 프로세스를 모니터링합니다. 즉, 명령이 여러 .NET 애플리케이션을 시작하는 경우 첫 번째 앱만 수집합니다. 따라서 자체 포함 애플리케이션에서 이 옵션을 사용하거나 dotnet exec <app.dll> 옵션을 사용하는 것이 좋습니다.

참고 항목

dotnet-counters를 통해 .NET 실행 파일을 시작하면 해당 입력/출력이 리디렉션되며 해당 stdin/stdout과 상호 작용할 수 없습니다. Ctrl+C 또는 SIGTERM을 통해 도구를 종료하면 도구와 자식 프로세스가 모두 안전하게 종료됩니다. 자식 프로세스가 도구보다 먼저 종료되면 도구도 종료됩니다. Stdin/stdout을 사용해야 하는 경우 --diagnostic-port 옵션을 사용할 수 있습니다. 자세한 내용은 진단 포트 사용을 참조하세요.

참고 항목

Linux 및 macOS에서 해당 명령은 대상 애플리케이션 및 dotnet-counters가 동일한 TMPDIR 환경 변수를 공유할 것으로 예상합니다.

참고 항목

dotnet-counters를 사용하여 메트릭을 모니터링하려면 대상 프로세스를 실행하는 사용자와 동일한 사용자 또는 루트로 실행해야 합니다.

참고 항목

[ERROR] System.ComponentModel.Win32Exception (299): A 32 bit processes cannot access modules of a 64 bit process.와 유사한 오류 메시지가 표시되는 경우, 대상 프로세스와 비트 수가 일치하지 않는 dotnet-counters를 사용하려고 합니다. 설치 링크에서 도구의 올바른 비트 수를 다운로드해야 합니다.

예제

  • 3초의 새로 고침 간격으로 System.Runtime의 모든 카운터를 모니터링합니다.

    > dotnet-counters monitor --process-id 1902  --refresh-interval 3 --counters System.Runtime
    Press p to pause, r to resume, q to quit.
        Status: Running
    
    [System.Runtime]
        % Time in GC since last GC (%)                                 0
        Allocation Rate (B / 1 sec)                                5,376
        CPU Usage (%)                                                  0
        Exception Count (Count / 1 sec)                                0
        GC Fragmentation (%)                                          48.467
        GC Heap Size (MB)                                              0
        Gen 0 GC Count (Count / 1 sec)                                 1
        Gen 0 Size (B)                                                24
        Gen 1 GC Count (Count / 1 sec)                                 1
        Gen 1 Size (B)                                                24
        Gen 2 GC Count (Count / 1 sec)                                 1
        Gen 2 Size (B)                                           272,000
        IL Bytes Jitted (B)                                       19,449
        LOH Size (B)                                              19,640
        Monitor Lock Contention Count (Count / 1 sec)                  0
        Number of Active Timers                                        0
        Number of Assemblies Loaded                                    7
        Number of Methods Jitted                                     166
        POH (Pinned Object Heap) Size (B)                             24
        ThreadPool Completed Work Item Count (Count / 1 sec)           0
        ThreadPool Queue Length                                        0
        ThreadPool Thread Count                                        2
        Working Set (MB)                                              19
    
  • System.Runtime에서 CPU 사용량 및 GC 힙 크기만 모니터링합니다.

    > dotnet-counters monitor --process-id 1902 --counters System.Runtime[cpu-usage,gc-heap-size]
    
    Press p to pause, r to resume, q to quit.
      Status: Running
    
    [System.Runtime]
        CPU Usage (%)                                 24
        GC Heap Size (MB)                            811
    
  • 사용자 정의 EventSource에서 EventCounter 값을 모니터링합니다. 자세한 내용은 자습서: .NET Core에서 EventCounters를 사용하여 성능 측정을 참조하세요.

    > dotnet-counters monitor --process-id 1902 --counters Samples-EventCounterDemos-Minimal
    
    Press p to pause, r to resume, q to quit.
        request                                      100
    
  • dotnet-counters에서 사용할 수 있는 잘 알려진 카운터를 모두 봅니다.

    > dotnet-counters list
    
    Showing well-known counters for .NET (Core) version 3.1 only. Specific processes may support additional counters.
    System.Runtime
        cpu-usage                          The percent of process' CPU usage relative to all of the system CPU resources [0-100]
        working-set                        Amount of working set used by the process (MB)
        gc-heap-size                       Total heap size reported by the GC (MB)
        gen-0-gc-count                     Number of Gen 0 GCs between update intervals
        gen-1-gc-count                     Number of Gen 1 GCs between update intervals
        gen-2-gc-count                     Number of Gen 2 GCs between update intervals
        time-in-gc                         % time in GC since the last GC
        gen-0-size                         Gen 0 Heap Size
        gen-1-size                         Gen 1 Heap Size
        gen-2-size                         Gen 2 Heap Size
        loh-size                           LOH Size
        alloc-rate                         Number of bytes allocated in the managed heap between update intervals
        assembly-count                     Number of Assemblies Loaded
        exception-count                    Number of Exceptions / sec
        threadpool-thread-count            Number of ThreadPool Threads
        monitor-lock-contention-count      Number of times there were contention when trying to take the monitor lock between update intervals
        threadpool-queue-length            ThreadPool Work Items Queue Length
        threadpool-completed-items-count   ThreadPool Completed Work Items Count
        active-timer-count                 Number of timers that are currently active
    
    Microsoft.AspNetCore.Hosting
        requests-per-second                Number of requests between update intervals
        total-requests                     Total number of requests
        current-requests                   Current number of requests
        failed-requests                    Failed number of requests
    
  • .NET 5 앱용 dotnet-counters 에서 사용할 수 있는 잘 알려진 카운터를 모두 봅니다.

    > dotnet-counters list --runtime-version 5.0
    
    Showing well-known counters for .NET (Core) version 5.0 only. Specific processes may support additional counters.
    System.Runtime
        cpu-usage                          The percent of process' CPU usage relative to all of the system CPU resources [0-100]
        working-set                        Amount of working set used by the process (MB)
        gc-heap-size                       Total heap size reported by the GC (MB)
        gen-0-gc-count                     Number of Gen 0 GCs between update intervals
        gen-1-gc-count                     Number of Gen 1 GCs between update intervals
        gen-2-gc-count                     Number of Gen 2 GCs between update intervals
        time-in-gc                         % time in GC since the last GC
        gen-0-size                         Gen 0 Heap Size
        gen-1-size                         Gen 1 Heap Size
        gen-2-size                         Gen 2 Heap Size
        loh-size                           LOH Size
        poh-size                           POH (Pinned Object Heap) Size
        alloc-rate                         Number of bytes allocated in the managed heap between update intervals
        gc-fragmentation                   GC Heap Fragmentation
        assembly-count                     Number of Assemblies Loaded
        exception-count                    Number of Exceptions / sec
        threadpool-thread-count            Number of ThreadPool Threads
        monitor-lock-contention-count      Number of times there were contention when trying to take the monitor lock between update intervals
        threadpool-queue-length            ThreadPool Work Items Queue Length
        threadpool-completed-items-count   ThreadPool Completed Work Items Count
        active-timer-count                 Number of timers that are currently active
        il-bytes-jitted                    Total IL bytes jitted
        methods-jitted-count               Number of methods jitted
    
    Microsoft.AspNetCore.Hosting
        requests-per-second   Number of requests between update intervals
        total-requests        Total number of requests
        current-requests      Current number of requests
        failed-requests       Failed number of requests
    
    Microsoft-AspNetCore-Server-Kestrel
        connections-per-second      Number of connections between update intervals
        total-connections           Total Connections
        tls-handshakes-per-second   Number of TLS Handshakes made between update intervals
        total-tls-handshakes        Total number of TLS handshakes made
        current-tls-handshakes      Number of currently active TLS handshakes
        failed-tls-handshakes       Total number of failed TLS handshakes
        current-connections         Number of current connections
        connection-queue-length     Length of Kestrel Connection Queue
        request-queue-length        Length total HTTP request queue
    
    System.Net.Http
        requests-started        Total Requests Started
        requests-started-rate   Number of Requests Started between update intervals
        requests-aborted        Total Requests Aborted
        requests-aborted-rate   Number of Requests Aborted between update intervals
        current-requests        Current Requests
    
  • 시작 시 로드된 어셈블리의 #을 시작하고 my-aspnet-server.exe 모니터링합니다.

    > dotnet-counters monitor --counters System.Runtime[assembly-count] -- my-aspnet-server.exe
    
    Press p to pause, r to resume, q to quit.
      Status: Running
    
    [System.Runtime]
        Number of Assemblies Loaded                   24
    
  • 명령줄 인수로 arg1 arg2 시작하고 my-aspnet-server.exe 시작부터 작업 집합 및 GC 힙 크기를 모니터링합니다.

    > dotnet-counters monitor --counters System.Runtime[working-set,gc-heap-size] -- my-aspnet-server.exe arg1 arg2
    
    Press p to pause, r to resume, q to quit.
      Status: Running
    
    [System.Runtime]
        GC Heap Size (MB)                                 39
        Working Set (MB)                                  59
    

dotnet-counters ps

dotnet-counters에서 모니터링할 수 있는 dotnet 프로세스를 나열합니다. dotnet-counters 버전 6.0.320703 이상에서는 사용 가능한 경우 각 프로세스가 시작된 명령줄 인수도 표시합니다.

개요

dotnet-counters ps [-h|--help]

예시

dotnet run --configuration Release 명령을 사용하여 장기 실행 앱을 시작한다고 가정해 보겠습니다. 다른 창에서 dotnet-counters ps 명령을 실행합니다. 표시되는 출력은 다음과 같습니다. 명령줄 인수가 있는 경우 dotnet-counters 버전 6.0.320703 이상에서 표시됩니다.

> dotnet-counters ps
  
  21932 dotnet     C:\Program Files\dotnet\dotnet.exe   run --configuration Release
  36656 dotnet     C:\Program Files\dotnet\dotnet.exe

진단 포트 사용

진단 포트 는 앱 시작에서 카운터 모니터링 또는 수집을 시작할 수 있는 런타임 기능입니다. dotnet-counters를 사용하여 이렇게 하려면 위의 예제에 설명된 대로 dotnet-counters <collect|monitor> -- <command>를 사용하거나 --diagnostic-port 옵션을 사용할 수 있습니다.

dotnet-counters <collect|monitor> -- <command>를 사용하여 애플리케이션을 자식 프로세스로 실행하는 것이 시작부터 빠르게 모니터링하는 가장 간단한 방법입니다.

하지만 모니터링되는 앱의 수명을 더 세부적으로 제어하거나(예: 처음 10분간만 앱을 모니터링하고 실행 계속) CLI를 사용하여 앱을 조작해야 하는 경우에는 --diagnostic-port 옵션을 사용하여 모니터링되는 대상 앱과 dotnet-counters를 모두 제어할 수 있습니다.

  1. 아래 명령은 dotnet-counters에서 myport.sock라는 진단 소켓을 만들고 연결을 대기하게 합니다.

    dotnet-counters collect --diagnostic-port myport.sock
    

    출력

    Waiting for connection on myport.sock
    Start an application with the following environment variable: DOTNET_DiagnosticPorts=/home/user/myport.sock
    
  2. 별도의 콘솔에서 DOTNET_DiagnosticPorts 환경 변수를 dotnet-counters 출력의 값으로 설정하고 대상 애플리케이션을 시작합니다.

    export DOTNET_DiagnosticPorts=/home/user/myport.sock
    ./my-dotnet-app arg1 arg2
    

    그러면 dotnet-countersmy-dotnet-app에서 카운터 수집을 시작할 수 있습니다.

    Waiting for connection on myport.sock
    Start an application with the following environment variable: DOTNET_DiagnosticPorts=myport.sock
    Starting a counter session. Press Q to quit.
    

    Important

    dotnet run을 사용하여 앱을 시작하면 문제가 될 수 있는데, dotnet CLI가 앱이 아닌 여러 자식 프로세스를 생성할 수 있고 해당 프로세스가 앱보다 먼저 dotnet-counters에 연결하여 앱이 런타임에 일시 중단될 수 있기 때문입니다. 앱의 자체 포함 버전을 직접 사용하거나 dotnet exec를 사용하여 애플리케이션을 시작하는 것이 좋습니다.