instrument_histogram (instrument v1.0.0)
View SourceHistogram 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:
default_buckets/0- Standard Prometheus bucketslinear_buckets/3- Evenly spaced bucketsexponential_buckets/3- Exponentially growing buckets
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
Release resources owned by this histogram metric (exemplar reservoir). Tolerates non-histogram handles so callers can invoke this on any metric.
Get the bucket boundaries configured for this histogram.
Functions
-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.
-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.