Chat Support
Loupe - Log - Monitor - Resolve
Loupe / Developer's Guide / For .NET Core / 6 / 8 / Metrics / Developer's Guide - Metrics - Designing Sampled Metrics
In This Topic
    Developer's Guide - Metrics - Designing Sampled Metrics
    In This Topic

    Sampled metrics are designed for situations when either the raw event data isn't available or the cost of collecting it is too high compared to the value of the information.  To record a sampled metric, you need to periodically sample the source data in a consistent format. 

    Sampled metrics all share the characteristic that they track a value related to time.  The time distance between samples is automatically used to calculate the effective rate when necessary to represent  metrics like bytes / second. 

    Sampling Formats 

    Depending on how your application can conveniently aggregate data, select the matching sampling type.  For example, consider a metric designed to record disk utilization in bytes / second.  This can be done by:

    1. Recording with each sample the total number of bytes written from the start of the process to the current point.  This would use the TotalCount Sample Type.
    2. Recording with each sample the number of bytes written since the last sample.  This would use the IncrementalCount Sample Type.
    3. Recording with each sample the bytes per second since the last sample.  This would use the RawCount sample type.

    Fraction Sampling Formats 

    When you want to record a metric that represents a percentage, such as percent utilization, it's often easiest to record the individual metric samples with both parts of the fraction used to derive the percentage.  For example, consider a metric designed to record percent disk utilization (as a percentage of working time).  This can be done by:

    1. Recording with each sample the total number of ticks spent writing to disk as the value and the total number of ticks spent servicing requests as the base value.  This would use the TotalFraction Sample Type.
    2. Recording with each sample the number of ticks spent writing to disk since the last sample as the value and the number of ticks spent servicing client requests since the last sample as the base value.  This would use the IncrementalFraction sample type.
    3. Recording with each sample the number of ticks spent writing per second as the value and the number of ticks spent servicing client requests per second as the base value.  This would use the RawFraction Sample Type.

    The advantage of the fractional sampling types over simply doing the division yourself is primarily the additional safety aspects built into Loupe (such as division by zero protection) and automatic, accurate extrapolation to different sampling intervals (such as when samples are recorded once per second but you want to view them on a longer interval)

    See Also