Using histograms
System.Diagnostics.Metrics.Histogram
represents a distribution of values – for example, the operation duration or payload size. Histograms can only be reported synchronously as each measurement is important. As we saw in Chapter 2, Native Monitoring in .NET, they allow us to calculate percentiles at query time.
We’ll use a histogram to record the processing duration in our example:
Processor.cs
_processingDurationHistogram = _meter .CreateHistogram<double>( "processor.processing.duration", "ms", "Item processing duration");
Every time we process an item from the queue, we should measure and record the time it took:
Processor.cs
Stopwatch? duration = _processingDurationHistogram .Enabled ? Stopwatch...