View Source prometheus_buckets (prometheus v4.13.0)

Summary

Types

Histogram buckets configuration.

Functions

Default histogram buckets.

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. The returned list is meant to be used for the buckets key of histogram constructors options.

Creates Count buckets, each Width wide, where the lowest bucket has an upper bound of Start.

Histogram buckets constructor, returns default/0 plus infinity

Histogram buckets constructor

Types

bucket_bound()

-type bucket_bound() :: number() | infinity.

buckets()

-type buckets() :: [bucket_bound(), ...].

config()

-type config() ::
          undefined | default |
          {linear, number(), number(), pos_integer()} |
          {exponential, number(), number(), pos_integer()} |
          buckets().

Histogram buckets configuration.

Setting the buckets key of a histogram to

  • default: will use the default buckets
  • linear: will use Start, Step, and Count to generate the buckets as in linear/3
  • exponential: will use Start, Factor, and Count to generate the buckets as in exponential/3

You can also specify your own buckets if desired instead.

Functions

default()

-spec default() -> buckets().

Default histogram buckets.

1> prometheus_buckets:default().
[0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10]

Please note these buckets are floats and represent seconds so you'll have to use prometheus_histogramdobserve/3 or configure duration_unit as seconds.

exponential/3

-spec exponential(number(), number(), pos_integer()) -> buckets().

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. The returned list is meant to be used for the buckets key of histogram constructors options.

3> prometheus_buckets:exponential(100, 1.2, 3).
[100, 120, 144]

The function raises {invalid_value, Value, Message} error if Count isn't positive, if Start isn't positive, or if Factor is less than or equals to 1.

linear/3

-spec linear(number(), number(), pos_integer()) -> buckets().

Creates Count buckets, each Width wide, where the lowest bucket has an upper bound of Start.

The returned list is meant to be used for the buckets key of histogram constructors options.

2> prometheus_buckets:linear(10, 5, 6).
[10, 15, 20, 25, 30, 35]

The function raises {invalid_value, Value, Message} error if Count is zero or negative.

new()

-spec new() -> buckets().

Histogram buckets constructor, returns default/0 plus infinity

new/1

-spec new(config()) -> buckets().

Histogram buckets constructor

position(Buckets, Value)

-spec position(buckets(), number()) -> pos_integer().