System.Diagnostics.Metrics Namespace

Metrics are numerical measurements reported over time, most often used to monitor the health of an application and generate alerts. For example, a web service might track how many requests it receives each second, how many milliseconds it took to respond, and how many of the responses sent an error back to the user. These metrics can be reported to a monitoring system at frequent, regular intervals. The System.Diagnostics.Metrics namespace can be used to add metrics to an application. The APIs work on all platforms supported by .NET and are designed to integrate well with OpenTelemetry's growing ecosystem of tools. They also integrate with .NET SDK tools, such as dotnet-counters. A listener API is available for developers that want to create custom tooling or adapters to other systems.



Represents an instrument that supports adding non-negative values. For example, you might call counter.Add(1) each time a request is processed to track the total number of requests. Most metric viewers display counters using a rate (requests/sec), by default, but can also display a cumulative total.


Represents a metrics instrument that can be used to report arbitrary values that are likely to be statistically meaningful, for example, the request duration. Call CreateHistogram<T>(String, String, String) to create a Histogram object.


Base class of all Metrics Instrument classes


The base class for all non-observable instruments.


Meter is the class responsible for creating and tracking the Instruments.


MeterListener is class used to listen to the metrics instrument measurements recording.


Represents a metrics-observable instrument that reports monotonically increasing values when the instrument is being observed, for example, CPU time (for different processes, threads, user mode, or kernel mode). Call CreateObservableCounter to create the observable counter object.


Represents an observable instrument that reports non-additive values when the instrument is being observed, for example, the current room temperature. Call CreateObservableGauge to create the observable counter object.


ObservableInstrument{T} is the base class from which all metrics observable instruments will inherit from.


A metrics-observable instrument that reports increasing or decreasing values when the instrument is being observed. Use this instrument to monitor the process heap size or the approximate number of items in a lock-free circular buffer, for example. To create an ObservableUpDownCounter object, use the CreateObservableUpDownCounter methods.


An instrument that supports reporting positive or negative metric values. UpDownCounter may be used in scenarios like reporting the change in active requests or queue size.



Stores one observed metrics value and its associated tags. This type is used by an Observable instrument's Observe() method when reporting current measurements. with the associated tags.



A delegate to represent the Meterlistener callbacks used in measurements recording operation.