Skip to main content
The buckets module provides utility functions to generate bucket configurations for Histogram metrics. Buckets define the upper bounds for grouping observed values.

Types

Buckets

pub type Buckets = List(Float)
A list of floats representing the upper bounds of histogram buckets.

Functions

exponential

Creates count buckets, where the lowest bucket has an upper bound of start and each following bucket’s upper bound is factor times the previous bucket’s upper bound.
pub fn exponential(
  start start: Float,
  factor factor: Int,
  count count: Int,
) -> Result(Buckets, String)
start
Float
required
The upper bound of the lowest bucket
factor
Int
required
The multiplier applied to each subsequent bucket’s upper bound
count
Int
required
The number of buckets to create

Returns

Result(Buckets, String) - A result containing either the list of bucket upper bounds or an error message.

Example

import promgleam/buckets

pub fn main() {
  let assert Ok([1.0, 2.0, 4.0, 8.0]) = buckets.exponential(start: 1.0, factor: 2, count: 4)
}

linear

Creates count buckets, each step wide, where the lowest bucket has an upper bound of start.
pub fn linear(
  start start: Float,
  step step: Float,
  count count: Int,
) -> Result(Buckets, String)
start
Float
required
The upper bound of the lowest bucket
step
Float
required
The width of each bucket (added to each subsequent upper bound)
count
Int
required
The number of buckets to create

Returns

Result(Buckets, String) - A result containing either the list of bucket upper bounds or an error message.

Example

import promgleam/buckets

pub fn main() {
  let assert Ok([1.0, 4.0, 7.0, 10.0]) = buckets.linear(start: 1.0, step: 3.0, count: 4)
}

Build docs developers (and LLMs) love