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 can be inconsistent: You don't need to worry about sampling on a fixed interval such as every second or every minute. You can sample as often or as infrequently as you wish. That said, if you find it convenient to sample more often than several times a minute it may be more appropriate to use Event metrics instead.
- Samples have to represent all activity: If you have a multithreaded application, you need to consider the contribution of all threads to the sample being recorded.
- The sampled format doesn't have to be the final format: While the sampling format has to be consistent, it doesn't have to be in the final form. There are several forms supported for recording samples to make it convenient.
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:
- 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.
- Recording with each sample the number of bytes written since the last sample. This would use the IncrementalCount Sample Type.
- 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:
- 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.
- 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.
- 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