Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

dotnet-counters: The Ultimate .NET Counters Tutorial


Real-Time Diagnostics for .NET Runtime, ASP.NET Core, EF Core, Networking & More


1. Introduction to dotnet-counters

dotnet-counters is a cross-platform performance monitoring tool for .NET applications. It provides real-time metrics about the .NET runtime and your application without requiring any code changes or stopping the app.

It is part of the .NET Diagnostic Tools suite.

It enables developers, performance engineers, and SREs to understand:

  • CPU usage
  • Memory allocations
  • GC behavior
  • ThreadPool health
  • ASP.NET Core traffic
  • Kestrel server load
  • System.Net outbound connections
  • EF Core queries & DB activity
  • Lock contention
  • Process working set
  • Request rates
  • Connection counts
  • And MUCH more

2. What is dotnet-counters? (Definition)

dotnet-counters is a lightweight CLI utility that subscribes to runtime performance metrics exposed by:

A. EventCounters (classic counters)

Used by:

  • System.Runtime
  • Microsoft.AspNetCore.Hosting
  • Microsoft-AspNetCore-Server-Kestrel
  • Microsoft.AspNetCore.Http.Connections
  • System.Net.Http
  • Microsoft.EntityFrameworkCore (legacy events)

B. System.Diagnostics.Metrics (new .NET metrics API)

Used by:

  • ASP.NET Core built-in metrics
  • EF Core built-in metrics
  • System.Net
  • .NET Runtime metrics
  • Custom application metrics

The tool displays these counters live or records them to a file.


3. Why dotnet-counters exists (Purpose)

Before dotnet-counters, diagnosing .NET performance issues required:

  • Attaching heavyweight profilers
  • Installing Visual Studio Diagnostics
  • Using Windows-only tools
  • Waiting for dumps or logs

These methods were slow, disruptive, and risky for production.

Modern .NET apps run on:

  • Linux containers
  • Kubernetes
  • Cloud VMs
  • Azure App Service
  • AWS ECS/EKS
  • Docker

What developers need is a safe, fast, cross-platform way to monitor live performance.

dotnet-counters solves this.


4. When to Use dotnet-counters

Use dotnet-counters when you need:

โœ” Live performance monitoring

โœ” Realtime GC insight
โœ” See allocations immediately
โœ” Detect memory leaks
โœ” Detect CPU spikes
โœ” View RPS (requests/sec)
โœ” Investigate latency & saturation
โœ” Observe EF Core query load
โœ” Analyze Kestrel traffic
โœ” Identify contention issues
โœ” Understand warm-up behavior
โœ” Inspect ThreadPool starvation
โœ” Debug production without restarts
โœ” Monitor cloud workloads

You use it in:

  • Local development
  • Performance testing
  • Load testing (JMeter, K6, Locust)
  • Staging / UAT
  • Production (safe)
  • Kubernetes clusters
  • Docker containers
  • Azure/AWS troubleshooting

5. Installing dotnet-counters

It’s included with the .NET SDK.

Check version:

dotnet-counters --version

If not installed:

dotnet tool install -g dotnet-counters

6. dotnet-counters Commands Overview

dotnet-counters

You get:

CommandPurpose
monitorLIVE real-time metrics
collectRecord metrics to a file (offline analysis)
listShow available counter providers
psList running .NET processes

7. Listing .NET Processes

dotnet-counters ps

Shows:

1234  MyApp.Web
5678  WorkerService
Code language: CSS (css)

8. Showing Available Counters

dotnet-counters list
Code language: PHP (php)

Now returns a pointer to documentation:

โžก https://learn.microsoft.com/dotnet/core/diagnostics/available-counters
(This is your main EventCounters reference.)


9. Monitoring an App in Real Time (monitor)

Basic usage:

dotnet-counters monitor -p <PID>
Code language: HTML, XML (xml)

With specific providers:

dotnet-counters monitor -p <PID> System.Runtime Microsoft.AspNetCore.Hosting
Code language: CSS (css)

Your full example:

dotnet-counters monitor -p 30420 System.Runtime Microsoft.AspNetCore.Hosting Microsoft-AspNetCore-Server-Kestrel Microsoft.AspNetCore.Http.Connections System.Net.Http Microsoft.EntityFrameworkCore
Code language: CSS (css)

Press:

  • p โ†’ pause
  • r โ†’ resume
  • q โ†’ quit

10. Recording Metrics to a File (collect)

dotnet-counters collect -p <PID> -o output.json
Code language: HTML, XML (xml)

Useful for:

  • Long-running captures
  • Production debugging
  • Attaching to Jira tickets

11. Providers & Metrics (Deep Dive)

The BIG section โ€” covers EVERY provider you need.


11.1 System.Runtime Counters

Source:
https://learn.microsoft.com/dotnet/core/diagnostics/available-counters

Key Metrics:

MetricMeaning
CPU Usage (%)CPU used by the process
Allocation RateBytes allocated/sec
GC Heap SizeManaged heap usage
GC Committed BytesMemory reserved by GC
% Time in GCHow much the app is paused for GC
Time paused by GCActual GC stop-the-world pause time
Gen 0/1/2 GC CountGarbage collections
Working SetTotal memory consumption
Exception CountThrow rate
ThreadPool Thread CountCurrent pool size
ThreadPool Queue LengthPending work items
Lock Contention CountLocking issues
JIT BytesIL compiled
Methods JittedTotal jitted methods
Active TimersTimers currently alive

This is the heart of your diagnostics.


11.2 ASP.NET Core Hosting Metrics

Source:
https://learn.microsoft.com/en-us/aspnet/core/log-mon/metrics/built-in

Counters include:

  • requests-per-second
  • current-requests
  • failed-requests
  • total-requests
  • request-duration

11.3 Kestrel Server Metrics

Source:
https://learn.microsoft.com/dotnet/core/diagnostics/available-counters

Includes:

  • current-connections
  • tls-handshake-failures
  • connection-queue-length
  • request-queue-length
  • connections-per-second

11.4 ASP.NET Core HTTP Connections (SignalR)

Counters:

  • current-connections
  • connections-started
  • connections-stopped
  • connections-timed-out
  • connection-duration

Useful for:

  • WebSockets
  • SignalR
  • Real-time APIs

11.5 System.Net.Http

Source:
https://learn.microsoft.com/dotnet/core/diagnostics/available-counters

Counters:

  • requests-started
  • requests-started-rate
  • requests-failed
  • http11-connections-current-total
  • http20-streams-current-total
  • http30-connections-established
  • dns-lookups-duration
  • sockets-queued

Great for diagnosing:

  • Slow outbound APIs
  • Connection pooling issues

11.6 EF Core Metrics (Modern + Legacy)

Source:
https://learn.microsoft.com/en-us/ef/core/logging-events-diagnostics/metrics

EF Core Built-in Metrics (New API)

  • microsoft.entityframeworkcore.query.compilation-events
  • microsoft.entityframeworkcore.commands.executed
  • microsoft.entityframeworkcore.active-dbcontexts

Legacy EventCounters compatible with dotnet-counters

  • Query execution count
  • Query execution rate
  • DbContext count
  • Optimistic concurrency failures

12. Interpreting dotnet-counters Output

Example snapshot:

Allocation Rate                50,067,464 B/sec
GC Heap Size                  239 MB
Working Set                   491 MB
ThreadPool Completed/1sec     609
Lock Contention Count/sec     2
Time paused by GC             0
CPU Usage                     5%
Code language: JavaScript (javascript)

Interpretation:

  • High allocation rate โ†’ future GC pressure
  • Large heap โ†’ memory-heavy workload
  • Large working set โ†’ big resident memory footprint
  • Lock contention โ†’ possible bottleneck
  • Nonzero Gen2 size โ†’ long-lived allocations
  • JIT activity โ†’ warm-up in progress
  • High request rate โ†’ check RPS counters in Hosting provider

13. When dotnet-counters is Most Valuable

๐ŸŸข Development

  • Validate memory patterns
  • Analyze LINQ allocations
  • Investigate EF Core inefficiencies

๐ŸŸก Load Testing

  • See RPS
  • See GC stress
  • See thread starvation

๐Ÿ”ต Staging/UAT

  • Compare performance baseline

๐Ÿ”ด Production

  • Safe to use
  • Zero-impact monitoring
  • Perfect for Kubernetes

14. Performance Use Cases (Real World)

โœ” Memory Leak Detection

Watch:

  • GC Heap Size (keeps growing?)
  • Gen 2 Size
  • LOH Size

โœ” High CPU Investigation

Watch:

  • CPU Usage (%)
  • Allocation Rate
  • JIT time
  • Lock contention

โœ” GC Bottleneck

Watch:

  • % Time in GC
  • Time paused by GC
  • Gen 0/1/2 Count
  • Allocation Rate

โœ” ThreadPool Starvation

Watch:

  • ThreadPool Queue Length
  • ThreadPool Completed Work Items
  • Thread Count

โœ” ASP.NET Core Throughput

Watch:

  • RPS
  • Failure rate
  • Current requests
  • Connection count

โœ” EF Core Problem Analysis

Watch:

  • Queries/sec
  • Active DbContexts
  • Command execution count

15. Advantages of dotnet-counters

๐Ÿ’  Cross-platform (Windows, Linux, macOS)

๐Ÿ’  Zero overhead (production-friendly)

๐Ÿ’  Instant insights

๐Ÿ’  No process restart

๐Ÿ’  No profilers needed

๐Ÿ’  No code changes

๐Ÿ’  Works in Docker, Kubernetes, cloud

๐Ÿ’  Works with all .NET apps (5/6/7/8/9+)

๐Ÿ’  Supports both EventCounters and Metrics API


16. Benefits

๐ŸŽฏ Rapid diagnosis

Find issues instantly (CPU, GC, memory, queries).

๐ŸŽฏ Safe for production

Unlike profilers, does not slow down your app.

๐ŸŽฏ Complements logs & APM

Fills the gap between logs, traces, and dumps.

๐ŸŽฏ Helps tune performance

Identify:

  • Excessive allocations
  • Slow queries
  • ThreadPool starvation
  • High RPS behavior

๐ŸŽฏ Helps SREs

Useful for:

  • Incident analysis
  • Postmortems
  • Capacity planning

17. Best Practices

  • Always include System.Runtime first
  • Add more providers only as needed
  • Use collect for long sessions
  • Compare snapshots at:
    • Idle
    • Under load
    • After runaway memory events
  • Capture before & after deployment
  • Combine with:
    • dotnet-trace
    • dotnet-gcdump
    • dotnet-dump
    • Application logs

18. Full Example Command Set

Monitor everything:

dotnet-counters monitor -p <PID> \
  System.Runtime \
  Microsoft.AspNetCore.Hosting \
  Microsoft-AspNetCore-Server-Kestrel \
  Microsoft.AspNetCore.Http.Connections \
  System.Net.Http \
  Microsoft.EntityFrameworkCore
Code language: CSS (css)

Collect to file:

dotnet-counters collect -p <PID> -o metrics.json
Code language: HTML, XML (xml)

List processes:

dotnet-counters ps

List counter providers & documentation:

dotnet-counters list
Code language: PHP (php)

19. Putting It All Together (One-Page Summary)

dotnet-counters = Live Performance Insights for .NET Applications

CategoryWhat You SeeBenefit
RuntimeCPU, GC, memory, threads, locksDiagnose bottlenecks
ASP.NET CoreRPS, requests, failuresWeb performance
Kestrelconnections, TLS, queuesServer-level insight
System.Netoutbound requests, poolsNetworking issues
EF Corequeries, contexts, failuresDB performance
Diagnosticswarm-up, JIT, timersStartup tuning

20. Conclusion

dotnet-counters is the single most powerful, lightweight, cross-platform tool for understanding live .NET performance.

It gives developers, performance engineers, and SREs the ability to see:

  • How much memory is being allocated
  • How often GC is running
  • Whether the app is CPU-bound
  • Whether threads are starving
  • Whether HTTP requests are queuing
  • Whether EF Core is overloaded

Without restarts.
Without downtime.
Without profilers.
Without risk.


Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

OWASP Dependency-Check โ€” 1-Hour Quick Demo Lab

Level: Beginner / Basic DevSecOpsDuration: 60 minutesFormat: Instructor-led hands-on demoFocus: Install โ†’ scan a real project โ†’ read findings โ†’ understand CVE/CVSS โ†’ generate reports โ†’ demonstrate a simple security gate…

Read More

OWASP Dependency-Checkย – Hands-On Lab Manual

OWASP Dependency-Check 13.0.0 Basic-to-Essentials Hands-On Lab Manual Audience: Beginners and engineers with basic DevOps/DevSecOps knowledgeTutorial verified/researched on: 2026-10-03OWASP Dependency-Check version: 13.0.0Minimum Java supported by Dependency-Check: Java 11Recommended lab Java runtime: Java 17…

Read More

Manufacturing automation: Is it worth investing in the field of manufacturing automation?

An investment in manufacturing automation can pay off. (Photo: Generated with the help of AI) Manufacturing automation has developed from a solution mainly associated with large factories…

Read More

How to Choose a Virtual Machine for Development and Production Workloads

Virtual machines remain a practical building block for development, testing, staging, production services, and infrastructure automation. The challenge is not simply choosing the largest instance available. It…

Read More

System Mechanic vs Advanced SystemCare for Small Teams Without an MDM

If you’re keeping a handful of Windows workstations or test machines healthy without a device-management platform, iolo’s System Mechanic is the better choice over IObit’s Advanced SystemCare…

Read More

How to Plan Infrastructure for a Community Project

Every thriving community project sits on top of infrastructure nobody notices, right up until it breaks. The forum. The server. The backups. The dull plumbing that holds…

Read More
Subscribe
Notify of
guest
2 Comments
Newest
Oldest Most Voted
Skylar Bennett
Skylar Bennett
10 months ago

This is a superb, allโ€‘inโ€‘one guide to dotnetโ€‘counters โ€” exactly the kind of resource .NET developers, SREs and performance engineers need. The way it illustrates key realโ€‘time metrics (CPU usage, memory allocations, GC behavior, threadโ€‘pool health, ASP.NET Core requestโ€‘rate, EF Core activity, network/HTTP counters) makes it clear how comprehensive and powerful the tool is. The explanation of why dotnetโ€‘counters matters โ€” especially for modern crossโ€‘platform, containerized or cloudโ€‘based .NET applications โ€” really resonates; zeroโ€‘overhead monitoring with no code changes and safe for production is a huge plus. The โ€œwhen to useโ€ + โ€œwhat to watchโ€ segments are especially useful for anyone trying to catch memory leaks, GC pressure, CPU spikes, request bottlenecks or threadโ€‘starvation early. Thanks for putting together such a practical and productionโ€‘ready tutorial! ๐Ÿ‘

Jason Mitchell
Jason Mitchell
10 months ago

This tutorial is an outstanding goโ€‘to resource for understanding realโ€‘time diagnostic tracing in .NET applications via dotnetโ€‘counters. It does a great job of explaining why youโ€™d pick certain counters (such as GC heap size, threadโ€‘pool queue length, ASPโ€ฏ.NET Core request rates) and how to interpret them in live scenarios. The mix of commandโ€‘walkthroughs, context (runtime health, EFโ€ฏCore activity, networkโ€‘I/O) and interpretation makes it highly valuable for developers, DevOps engineers and SREs alike who want to go beyond โ€œjust capturing metricsโ€ and move toward actionable insights. Itโ€™s especially useful as part of training interns or teams: the piece gives you the tools to link observed metric spikes or patterns back to architectural faults, coding bottlenecks or deployment issues.

2
0
Would love your thoughts, please comment.x
()
x