View Source prometheus_histogram (prometheus v5.0.0)
A Histogram tracks the size and number of events in buckets. You can use Histograms for aggregatable calculation of quantiles.
Example use cases for Histograms:
- Response latency
- Request size
Histogram expects buckets
key in a metric spec. Buckets can be:
- a list of numbers in increasing order;
default
;{linear, Start, Step, Count
;{exponential, Start, Step, Count}
Example:
-module(example_instrumenter).
setup() ->
prometheus_histogram:declare([{name, http_request_duration_milliseconds},
{labels, [method]},
{buckets, [100, 300, 500, 750, 1000]},
{help, \"Http Request execution time.\"}]).
instrument(Time, Method) ->
%% Time must be in native units, otherwise duration_unit must be false
prometheus_histogram:observe(http_request_duration_milliseconds, [Method], Time).
The prometheus_histogram:observe_n/3,4,5
adds limited support for the \"weighted\" histograms.
It accepts the extra integer argument \"Count\" to update the number of observations in the bucket
by adding that number. This allows for better accuracy in the case of irregular measurements,
assuming that the \"Count\" conveys the observation time interval (for example,
the number of time ticks when the recent value was observed).
Summary
Functions
Equivalent to buckets(default, Name, [])
.
Equivalent to buckets(default, Name, LabelValues)
.
Returns buckets of the histogram identified by Registry
, Name
and LabelValues
.
Creates a histogram using Spec
. If a histogram with the same Spec
exists returns false
.
Equivalent to deregister(default, Name)
.
Removes all histogram series with name Name
and removes Metric Family from Registry
.
Creates a histogram using Spec
.
Equivalent to observe(default, Name, [], Value)
.
Observes the given Value
.
Equivalent to observe_duration(default, Name, LabelValues, Fun)
.
Tracks the amount of time spent executing Fun
.
Equivalent to observe_n(default, Name, LabelValues, Value, Count)
.
Observes the given Value
, Count
times.
Observes the given Value
, Count
times, in the bucket position of the bucket list.
Equivalent to remove(default, Name, [])
.
Equivalent to remove(default, Name, LabelValues)
.
Removes histogram series identified by Registry
, Name
and LabelValues
.
Equivalent to reset(default, Name, [])
.
Equivalent to reset(default, Name, LabelValues)
.
Resets the value of the histogram identified by Registry
, Name
and LabelValues
.
Equivalent to value(default, Name, [])
.
Equivalent to value(default, Name, LabelValues)
.
Returns the value of the histogram identified by Registry
, Name
and LabelValues
.
If there is no histogram for LabelValues
, returns undefined
.
Functions
-spec buckets(prometheus_metric:name()) -> [number()].
Equivalent to buckets(default, Name, [])
.
-spec buckets(prometheus_metric:name(), prometheus_metric:labels()) -> [number()].
Equivalent to buckets(default, Name, LabelValues)
.
-spec buckets(Registry, Name, LabelValues) -> [number()] when Registry :: prometheus_registry:registry(), Name :: prometheus_metric:name(), LabelValues :: prometheus_metric:labels().
Returns buckets of the histogram identified by Registry
, Name
and LabelValues
.
-spec declare(prometheus_metric:spec()) -> boolean().
Creates a histogram using Spec
. If a histogram with the same Spec
exists returns false
.
Raises:
{missing_metric_spec_key, Key, Spec}
error if requiredSpec
key is missing.{invalid_metric_name, Name, Message}
error if metricName
is invalid.{invalid_metric_help, Help, Message}
error if metricHelp
is invalid.{invalid_metric_labels, Labels, Message}
error ifLabels
isn't a list.{invalid_label_name, Name, Message}
error ifName
isn't a valid label name.{invalid_value_error, Value, MessagE}
error ifduration_unit
is unknown or doesn't match metric name.
Histogram-specific errors:
Raises:
{no_buckets, Buckets}
error ifBuckets
are missing, not a list, empty list or not known buckets spec.{invalid_buckets, Buckets, Message}
error ifBuckets
aren't in increasing order.{invalid_bound, Bound}
error ifBound
isn't a number.
-spec deregister(prometheus_metric:name()) -> {boolean(), boolean()}.
Equivalent to deregister(default, Name)
.
-spec deregister(prometheus_registry:registry(), prometheus_metric:name()) -> {boolean(), boolean()}.
Removes all histogram series with name Name
and removes Metric Family from Registry
.
After this call new/1 for Name
and Registry
will succeed.
Returns {true, _}
if Name
was a registered histogram. Otherwise returns {false, _}
.
-spec new(prometheus_metric:spec()) -> ok.
Creates a histogram using Spec
.
Raises:
{missing_metric_spec_key, Key, Spec}
error if requiredSpec
key is missing.{invalid_metric_name, Name, Message}
error if metricName
is invalid.{invalid_metric_help, Help, Message}
error if metricHelp
is invalid.{invalid_metric_labels, Labels, Message}
error ifLabels
isn't a list.{invalid_label_name, Name, Message}
error ifName
isn't a valid label name.{invalid_value_error, Value, Message}
error ifduration_unit
is unknown or doesn't match metric name.{mf_already_exists, {Registry, Name}, Message}
error if a histogram with the sameSpec
already exists.
Histogram-specific errors:
Raises:
{no_buckets, Buckets}
error ifBuckets
are missing, not a list, empty list or not known buckets spec.{invalid_buckets, Buckets, Message}
error ifBuckets
aren't in increasing order.{invalid_bound, Bound}
error ifBound
isn't a number.
-spec observe(prometheus_metric:name(), number()) -> ok.
Equivalent to observe(default, Name, [], Value)
.
-spec observe(prometheus_metric:name(), prometheus_metric:labels(), number()) -> ok.
Equivalent to observe(default, Name, LabelValues, Value)
.
-spec observe(Registry, Name, LabelValues, Value) -> ok when Registry :: prometheus_registry:registry(), Name :: prometheus_metric:name(), LabelValues :: prometheus_metric:labels(), Value :: number().
Observes the given Value
.
Raises:
{invalid_value, Value, Message}
ifValue
isn't a number.{unknown_metric, Registry, Name}
error if histogram with namedName
can't be found inRegistry
.{invalid_metric_arity, Present, Expected}
error if labels count mismatch.
-spec observe_duration(prometheus_metric:name(), fun(() -> term())) -> term().
Equivalent to observe_duration(default, Name, [], Fun)
.
-spec observe_duration(prometheus_metric:name(), prometheus_metric:labels(), fun(() -> term())) -> term().
Equivalent to observe_duration(default, Name, LabelValues, Fun)
.
-spec observe_duration(Registry, Name, LabelValues, Fun) -> any() when Registry :: prometheus_registry:registry(), Name :: prometheus_metric:name(), LabelValues :: prometheus_metric:labels(), Fun :: fun(() -> any()).
Tracks the amount of time spent executing Fun
.
Raises:
{unknown_metric, Registry, Name}
error if histogram with namedName
can't be found inRegistry
.{invalid_metric_arity, Present, Expected}
error if labels count mismatch.{invalid_value, Value, Message}
ifFun
isn't a function.
-spec observe_n(prometheus_metric:name(), number(), integer()) -> ok.
Equivalent to observe_n(default, Name, [], Value, Count)
.
-spec observe_n(prometheus_metric:name(), prometheus_metric:labels(), number(), integer()) -> ok.
Equivalent to observe_n(default, Name, LabelValues, Value, Count)
.
-spec observe_n(Registry, Name, LabelValues, Value, Count) -> ok when Registry :: prometheus_registry:registry(), Name :: prometheus_metric:name(), LabelValues :: prometheus_metric:labels(), Value :: number(), Count :: integer().
Observes the given Value
, Count
times.
Raises:
{invalid_value, Value, Message}
ifValue
isn't a number.{invalid_count, Count, Message}
ifCount
isn't integer.{unknown_metric, Registry, Name}
error if histogram with namedName
can't be found inRegistry
.{invalid_metric_arity, Present, Expected}
error if labels count mismatch.
-spec pobserve(Registry, Name, LabelValues, Buckets, BucketPos, Value) -> ok when Registry :: prometheus_registry:registry(), Name :: prometheus_metric:name(), LabelValues :: prometheus_metric:labels(), Buckets :: prometheus_buckets:buckets(), BucketPos :: integer(), Value :: number().
Observes the given Value
, Count
times, in the bucket position of the bucket list.
Useful when the bucket position is known in advance, as it avoids having to compute such value during the observation.
-spec remove(prometheus_metric:name()) -> boolean().
Equivalent to remove(default, Name, [])
.
-spec remove(prometheus_metric:name(), prometheus_metric:labels()) -> boolean().
Equivalent to remove(default, Name, LabelValues)
.
-spec remove(prometheus_registry:registry(), prometheus_metric:name(), prometheus_metric:labels()) -> boolean().
Removes histogram series identified by Registry
, Name
and LabelValues
.
Raises:
{unknown_metric, Registry, Name}
error if histogram with nameName
can't be found inRegistry
.{invalid_metric_arity, Present, Expected}
error if labels count mismatch.
-spec reset(prometheus_metric:name()) -> boolean().
Equivalent to reset(default, Name, [])
.
-spec reset(prometheus_metric:name(), prometheus_metric:labels()) -> boolean().
Equivalent to reset(default, Name, LabelValues)
.
-spec reset(prometheus_registry:registry(), prometheus_metric:name(), prometheus_metric:labels()) -> boolean().
Resets the value of the histogram identified by Registry
, Name
and LabelValues
.
Raises:
{unknown_metric, Registry, Name}
error if histogram with nameName
can't be found inRegistry
.{invalid_metric_arity, Present, Expected}
error if labels count mismatch.
-spec value(prometheus_metric:name()) -> {number(), infinity | number()} | undefined.
Equivalent to value(default, Name, [])
.
-spec value(prometheus_metric:name(), prometheus_metric:labels()) -> {number(), infinity | number()} | undefined.
Equivalent to value(default, Name, LabelValues)
.
-spec value(prometheus_registry:registry(), prometheus_metric:name(), prometheus_metric:labels()) -> {number(), infinity | number()} | undefined.
Returns the value of the histogram identified by Registry
, Name
and LabelValues
.
If there is no histogram for LabelValues
, returns undefined
.
If duration unit set, sum will be converted to the duration unit. Read more here.
Raises:
{unknown_metric, Registry, Name}
error if histogram namedName
can't be found inRegistry
.{invalid_metric_arity, Present, Expected}
error if labels count mismatch.
-spec values(prometheus_registry:registry(), prometheus_metric:name()) -> [{list(), number()}].