CrowdStrike Go Metrics Sliding Window

Sliding Window Sampling for go-metrics


This project contains a simple implementation of a sliding window sampling approach implementing the rcrowley/go-metrics Sample interface. The user can define a reservoir size, much like the default sampling approach, but also define a window size that is used to phase out sample values once they fall outside the window.


The problem with the default exponential decay sampling approach is that it only expires old data as new data comes in. While this approach works perfectly fine for high-volume metrics, it is problematic for low-volume metrics and can lead to misleading graphs where the data is stale, but looks like it is recent. This issue is particularly troublesome when measuring metrics with a histogram (e.g., endpoint latency).

Ideally this contribution would be made to the go-metrics project itself, but the author has made it clear he would rather have others implement this themselves and leverage the exported interfaces.


package main

import (

func main() {
	// Creates a histogram using the sliding window sampling approach with a reservoir size of 1024 and a sampling window of 2 minutes.
	sample := slidingwindow.NewSample(1024, time.Minute*2)
	histogram := metrics.GetOrRegisterHistogram("histogram.latency", metrics.DefaultRegistry, sample)

	// Uses the histogram with the sliding window sampling to create a timer.
	timer := metrics.NewCustomTimer(histogram, metrics.NewMeter())


View Github