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.

Classes

Counter<T>

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.

Histogram<T>

Represents a metrics Instrument that can be used to report arbitrary values that are likely to be statistically meaningful. e.g. the request duration. Use CreateHistogram<T>(String, String, String) method to create the Histogram object.

Instrument

Base class of all Metrics Instrument classes

Instrument<T>

The base class for all non-observable instruments.

Meter

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

MeterListener

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

ObservableCounter<T>

ObservableCounter is a metrics observable Instrument which reports monotonically increasing value(s) when the instrument is being observed. e.g. CPU time (for different processes, threads, user mode or kernel mode). Use Meter.CreateObservableCounter methods to create the observable counter object.

ObservableGauge<T>

ObservableGauge is an observable Instrument that reports non-additive value(s) when the instrument is being observed. e.g. the current room temperature Use Meter.CreateObservableGauge methods to create the observable counter object.

ObservableInstrument<T>

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

Structs

Measurement<T>

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.

Delegates

MeasurementCallback<T>

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