Skip to content

Conversation

@nsgocev
Copy link

@nsgocev nsgocev commented Jan 13, 2026

Summary of changes

This PR extends the runtime metrics collection to include 13 new high-value metrics that were previously missing:

JIT Metrics (.NET 6+):

  • runtime.dotnet.jit.compiled_il_bytes - Total IL bytes compiled by JIT
  • runtime.dotnet.jit.compiled_methods - Total methods compiled by JIT
  • runtime.dotnet.jit.compilation_time - Total JIT compilation time (milliseconds)

ThreadPool Metrics:

  • runtime.dotnet.threads.queue_length - ThreadPool work item queue length (.NET Core 3.0+)
  • runtime.dotnet.threads.available_worker_threads - Available ThreadPool worker threads
  • runtime.dotnet.threads.available_completion_port_threads - Available ThreadPool I/O completion port threads
  • runtime.dotnet.threads.completed_work_items - Completed ThreadPool work items (.NET 5+)
  • runtime.dotnet.threads.active_timers - Active timer count (.NET 6+)

GC Metrics:

  • runtime.dotnet.gc.allocated_bytes - Total allocated bytes (.NET Core 3.0+)
  • runtime.dotnet.gc.fragmentation_percent - Heap fragmentation percentage
  • runtime.dotnet.gc.total_available_memory - Container-aware total available memory
  • runtime.dotnet.gc.high_memory_load_threshold - GC high memory pressure trigger threshold
  • runtime.dotnet.gc.size.poh - Pinned Object Heap size (.NET 5+)

Reason for change

The existing runtime metrics implementation was missing several important metrics that are essential for:

  1. JIT Diagnostics: Understanding startup performance and code generation costs - critical for containerized applications and serverless scenarios where cold starts matter
  2. ThreadPool Saturation Detection: Identifying async bottlenecks and ThreadPool starvation - the most common cause of performance issues in .NET applications
  3. Advanced GC Diagnostics: Container-aware memory tracking, heap fragmentation analysis, and POH size monitoring - essential for memory-constrained environments

Implementation details

Architecture

Extended both existing runtime metrics listeners to maintain compatibility across all supported platforms:

  1. DiagnosticsMetricsRuntimeMetricsListener (.NET 6+)

    • Uses System.Diagnostics.Metrics APIs where available
    • Leverages System.Runtime.JitInfo APIs for JIT metrics
  2. RuntimeEventListener (.NET Core 3.1+, also runs on .NET 6+)

    • Added metrics collection using EventSource-based approach

Platform Support Matrix

Metric .NET Framework .NET Core 3.1 .NET 5 .NET 6+
JIT metrics
ThreadPool queue length
ThreadPool available threads
ThreadPool completed items
ThreadPool active timers
GC allocated bytes
GC fragmentation
GC total available memory
GC high memory load threshold
POH size

Other details

Performance Impact

  • Collection overhead: < 1ms per 10s collection cycle (all metrics use fast BCL APIs)
  • Memory overhead: Negligible (no allocations in hot paths, no new background threads)

@nsgocev nsgocev requested a review from a team as a code owner January 13, 2026 11:33
@andrewlock
Copy link
Member

Hi @nsgocev, thanks for the contribution, but adding additional built-in runtime metrics requires some work in the backend too, and we're not looking to add new built-in metrics right now, but it's on our radar. You're obviously free to send these as custom metrics in the meantime though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants