instrument_histogram (instrument v1.0.0)

View Source

Histogram metric for measuring distributions of values.

A histogram samples observations (usually things like request durations or response sizes) and counts them in configurable buckets. It also provides a sum of all observed values and a count of observations.

Bucket Configuration

Histograms use upper-bound exclusive buckets. Values are counted in the first bucket where value <= boundary. Default buckets follow Prometheus conventions: [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10]

Custom buckets can be created with:

Example

   %% Create histogram with default buckets
   Hist = instrument_histogram:new_histogram(latency, <<"Request latency">>),
  
   %% Create histogram with custom buckets
   Buckets = instrument_histogram:linear_buckets(0.1, 0.1, 10),
   Hist2 = instrument_histogram:new_histogram(size, <<"Response size">>, Buckets),
  
   %% Record observations
   instrument_histogram:observe_histogram(Hist, 0.042),
   instrument_histogram:observe_histogram(Hist, 0.156).

Summary

Functions

cleanup(Metric)

-spec cleanup(#metric{name :: term(),
                      handle :: term(),
                      collect :: tuple(),
                      description :: binary() | undefined,
                      unit :: binary() | undefined,
                      meter :: binary() | undefined,
                      attributes :: map()} |
              term()) ->
                 ok.

Release resources owned by this histogram metric (exemplar reservoir). Tolerates non-histogram handles so callers can invoke this on any metric.

collect(Info, Hist)

default_buckets()

exponential_buckets(Start, Factor, Count)

get_bucket_boundaries(Metric)

-spec get_bucket_boundaries(#metric{name :: term(),
                                    handle :: term(),
                                    collect :: tuple(),
                                    description :: binary() | undefined,
                                    unit :: binary() | undefined,
                                    meter :: binary() | undefined,
                                    attributes :: map()}) ->
                               [number()].

Get the bucket boundaries configured for this histogram.

get_histogram(Metric)

linear_buckets(Start, Width, Count)

new_histogram(Name, Help)

new_histogram(Name, Help, Buckets)

observe_histogram(Metric, Value)

validate_buckets(Rest)

with_histogram(Hist, F)

with_histogram(Hist, F, V)