Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TimeWindowedStats ¶
type TimeWindowedStats interface {
// Record records a value that occurred at the given timestamp.
Record(value float64, timestamp time.Time)
// RecordToLatestWindow records a value in the current time window.
// This will call time.Now(), don't call this in a tight loop.
RecordToLatestWindow(value float64)
// RecordMulti records a weighted value that occurred at the given timestamp
// with the provided count. Imagine you have 3 counts of 10, and you
// call RecordMulti(20, t, 3). Your new mean will be 15 because you added
// 3 counts of 20.
RecordMulti(value float64, timestamp time.Time, count uint64)
// RecordMultiToLatestWindow records a weighted value in the current time window.
// This will call time.Now(), don't call this in a tight loop.
RecordMultiToLatestWindow(value float64, count uint64)
// Quantile returns the approximate value at quantile q (0 <= q <= 1).
// Aggregates across all active windows.
Quantile(q float64) float64
// TrimmedMean returns the mean of the values within the given quantile range (0 <= q <= 1).
// For example, TrimmedMean(0.9, 0.99) returns the average of all the values between the
// 90th percentile and the 99th percentile.
// Aggregates across all active windows.
TrimmedMean(lowerQuantile, upperQuantile float64) float64
}
TimeWindowedStats collects values into fixed-duration time windows, each backed by a t-digest, enabling approximate quantile queries over a sliding time range. Windows are guaranteed to be non-overlapping.
func NewWindowedTDigest ¶
func NewWindowedTDigest(cfg WindowConfig) (TimeWindowedStats, error)
NewWindowedTDigest creates a new TimeWindowedStats backed by per-window t-digests. Some guidance on sizing the windows/counts: Prefer windows containing about 10,000 datapoints. Insert latency increases by a factor of about 3x from a size of 1k-10k, but the stored size in RAM drops by 7x. So, if you want 300 seconds of history on an event that records 1k counts/sec, 3 10-second windows is fine.
type WindowConfig ¶
type WindowConfig struct {
// windowSize is the duration of each window.
WindowSize time.Duration
// windowCount is the maximum number of windows to retain.
WindowCount int
// FillBlankIntervals controls whether gaps in the windowing should be preserved.
// This matters when windowSize is shorter than the largest gap in the measured data.
FillBlankIntervals bool
}
WindowConfig controls the windowing behavior.