Peep.Buckets behaviour (peep v4.2.1)

View Source

A behavior for histogram bucketing strategies.

You can pass a bucketing strategy to a distribution metric in your metrics:

def metrics do
  [
    distribution([:bandit, :request, :stop, :duration],
      tags: [],
      unit: {:native, :millisecond},
      reporter_options: [
        peep_bucket_calculator: Peep.Buckets.PowersOfTen
      ]
    )
  ]
end

If no bucketing strategy is provided is not set in :reporter_options for a %Telemetry.Metrics.Distribution{}, then the default is Peep.Buckets.Exponential.

You can change the default bucket calculator, set :bucket_calculator in your config.

config :peep, bucket_calculator: Peep.Buckets.PowersOfTen

Custom Buckets

If you want custom bucket boundaries, there is Peep.Buckets.Custom, which uses pattern matching to assign sample measurements to buckets.

Example:

defmodule MyApp.MyBucket do
  use Peep.Buckets.Custom,
    buckets: [10, 100, 1_000]
end

Summary

Types

config()

@type config() :: map()

Callbacks

bucket_for(number, config)

@callback bucket_for(number(), config()) :: non_neg_integer()

config(t)

@callback config(Telemetry.Metrics.Distribution.t()) :: config()

number_of_buckets(config)

@callback number_of_buckets(config()) :: pos_integer()

upper_bound(non_neg_integer, config)

@callback upper_bound(non_neg_integer(), config()) :: String.t()

Functions

config(metric)

@spec config(Telemetry.Metrics.Distribution.t()) :: {atom(), config()}