2023-01-04 06:19:18 +00:00
|
|
|
package streamaggr
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/VictoriaMetrics/metrics"
|
|
|
|
)
|
|
|
|
|
2024-09-24 20:03:04 +00:00
|
|
|
// histogramBucketAggrValue calculates output=histogram_bucket, e.g. VictoriaMetrics histogram over input samples.
|
|
|
|
type histogramBucketAggrValue struct {
|
|
|
|
h metrics.Histogram
|
|
|
|
state metrics.Histogram
|
2023-01-04 06:19:18 +00:00
|
|
|
}
|
|
|
|
|
2024-09-24 20:03:04 +00:00
|
|
|
func (sv *histogramBucketAggrValue) pushSample(ctx *pushSampleCtx) {
|
|
|
|
sv.h.Update(ctx.sample.value)
|
2023-01-04 06:19:18 +00:00
|
|
|
}
|
|
|
|
|
2024-09-24 20:03:04 +00:00
|
|
|
func (sv *histogramBucketAggrValue) flush(ctx *flushCtx, key string) {
|
|
|
|
total := &sv.state
|
|
|
|
total.Merge(&sv.h)
|
|
|
|
total.VisitNonZeroBuckets(func(vmrange string, count uint64) {
|
|
|
|
ctx.appendSeriesWithExtraLabel(key, "histogram_bucket", float64(count), "vmrange", vmrange)
|
2023-01-04 06:19:18 +00:00
|
|
|
})
|
2024-09-24 20:03:04 +00:00
|
|
|
total.Reset()
|
2023-01-04 06:19:18 +00:00
|
|
|
}
|