Add a couple of procedures for generating histogram buckets
This commit is contained in:
parent
0b22a8760c
commit
35dc26c0ea
1 changed files with 41 additions and 0 deletions
|
|
@ -164,6 +164,47 @@ list of label names to be permitted for this metric and
|
||||||
;; The default buckets used in other client libraries
|
;; The default buckets used in other client libraries
|
||||||
(list 0.005 0.01 0.025 0.05 0.1 0.25 0.5 1 2.5 5 10 (inf)))
|
(list 0.005 0.01 0.025 0.05 0.1 0.25 0.5 1 2.5 5 10 (inf)))
|
||||||
|
|
||||||
|
(define* (linear-histogram-buckets #:key start step end count)
|
||||||
|
(when (and end count)
|
||||||
|
(raise-exception
|
||||||
|
(make-exception-with-message
|
||||||
|
"you can only specify either end or count to linear-histogram-buckets")))
|
||||||
|
|
||||||
|
(append (if count
|
||||||
|
(map (lambda (index)
|
||||||
|
(+ start
|
||||||
|
(* step index)))
|
||||||
|
(iota count))
|
||||||
|
(let loop ((reverse-result (list start))
|
||||||
|
(current-value start))
|
||||||
|
(let ((next-value (+ current-value step)))
|
||||||
|
(if (>= next-value end)
|
||||||
|
(reverse (cons end reverse-result))
|
||||||
|
(loop (cons next-value reverse-result)
|
||||||
|
next-value)))))
|
||||||
|
(list (inf))))
|
||||||
|
|
||||||
|
(define* (exponential-histogram-buckets #:key start (factor 2) end count)
|
||||||
|
(when (and end count)
|
||||||
|
(raise-exception
|
||||||
|
(make-exception-with-message
|
||||||
|
"you can only specify either end or count to exponential-histogram-buckets")))
|
||||||
|
|
||||||
|
(append (if count
|
||||||
|
(map (lambda (index)
|
||||||
|
(* start
|
||||||
|
(expt factor index)))
|
||||||
|
(iota count))
|
||||||
|
(let loop ((reverse-result (list start)))
|
||||||
|
(let ((next-value
|
||||||
|
(* start
|
||||||
|
(expt factor
|
||||||
|
(+ 1 (length reverse-result))))))
|
||||||
|
(if (>= next-value end)
|
||||||
|
(reverse (cons end reverse-result))
|
||||||
|
(loop (cons next-value reverse-result))))))
|
||||||
|
(list (inf))))
|
||||||
|
|
||||||
(define* (make-histogram-metric registry name
|
(define* (make-histogram-metric registry name
|
||||||
#:key
|
#:key
|
||||||
(buckets %default-histogram-buckets)
|
(buckets %default-histogram-buckets)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue