diff options
author | Christopher Baines <mail@cbaines.net> | 2020-12-10 19:50:02 +0000 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2020-12-10 19:50:02 +0000 |
commit | 35dc26c0ea44c3d70f1819f240d84e2cbb4b7b4c (patch) | |
tree | 83645c80b5f94efb82fdfc126fc245a57ec581ca | |
parent | 0b22a8760cd9ed5f9a0a855a0ef62bab88e46067 (diff) | |
download | prometheus-35dc26c0ea44c3d70f1819f240d84e2cbb4b7b4c.tar prometheus-35dc26c0ea44c3d70f1819f240d84e2cbb4b7b4c.tar.gz |
Add a couple of procedures for generating histogram buckets
-rw-r--r-- | prometheus.scm | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/prometheus.scm b/prometheus.scm index 2a181f8..9d8d7ad 100644 --- a/prometheus.scm +++ b/prometheus.scm @@ -164,6 +164,47 @@ list of label names to be permitted for this metric and ;; 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))) +(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 #:key (buckets %default-histogram-buckets) |