A deep dive into using `MeterListener` from the `System.Diagnostics.Metrics` APIs to consume and aggregate metrics in-process within a .NET application. The post walks through building a `MetricManager` wrapper class that subscribes to specific ASP.NET Core and .NET runtime instruments, handles both standard and observable instrument types, and aggregates measurements using thread-safe primitives like `Interlocked`. A live-updating console table powered by Spectre.Console displays the collected metrics. Key concepts covered include selecting which instruments to listen to, triggering observable instruments via `RecordObservableInstruments()`, handling different measurement types with typed callbacks, and the performance rationale behind the API design.

17m read timeFrom andrewlock.net
Post cover image
Table of contents
Creating the test ASP.NET Core appRecording metrics with MeterListenerCreating a service to display the resultsSummary

Sort: