2023-01-04 06:19:18 +00:00
|
|
|
package streamaggr
|
|
|
|
|
2024-09-24 20:03:04 +00:00
|
|
|
// stdvarAggrValue calculates output=stdvar, e.g. the average value over input samples.
|
|
|
|
type stdvarAggrValue struct {
|
2024-07-03 10:42:45 +00:00
|
|
|
count float64
|
|
|
|
avg float64
|
|
|
|
q float64
|
2023-01-04 06:19:18 +00:00
|
|
|
}
|
|
|
|
|
2024-09-24 20:03:04 +00:00
|
|
|
func (av *stdvarAggrValue) pushSample(ctx *pushSampleCtx) {
|
|
|
|
av.count++
|
|
|
|
avg := av.avg + (ctx.sample.value-av.avg)/av.count
|
|
|
|
av.q += (ctx.sample.value - av.avg) * (ctx.sample.value - avg)
|
|
|
|
av.avg = avg
|
2023-01-04 06:19:18 +00:00
|
|
|
}
|
|
|
|
|
2024-09-24 20:03:04 +00:00
|
|
|
func (av *stdvarAggrValue) flush(ctx *flushCtx, key string) {
|
|
|
|
if av.count > 0 {
|
|
|
|
ctx.appendSeries(key, "stdvar", av.q/av.count)
|
|
|
|
av.count = 0
|
|
|
|
av.avg = 0
|
|
|
|
av.q = 0
|
2023-01-04 06:19:18 +00:00
|
|
|
}
|
|
|
|
}
|