Behaviours: prometheus_collector, prometheus_metric.
Counter is a Metric that represents a single numerical value that only ever
goes up. That implies that it cannot be used to count items whose number can
also go down, e.g. the number of currently running processes. Those
"counters" are represented by prometheus_gauge.
A Counter is typically used to count requests served, tasks completed, errors occurred, etc.
Examople use cases for Counters:Use the
rate()/irate()
functions in Prometheus to calculate the rate of increase of a Counter.
By convention, the names of Counters are suffixed by _total.
To create a counter use either new/1 or declare/1,
the difference is that new/1 will raise
{:mf_already_exists, {Registry, Name}, Message} error if counter with
the same Registry, Name and Labels combination already exists.
Both accept Spec [proplist](http://erlang.org/doc/man/proplists.html)
with the same set of keys:
- Registry - optional, default is default;
- Name - required, can be an atom or a string;
- Help - required, must be a string;
- Labels - optional, default is [].
-module(my_service_instrumenter).
-export([setup/0,
inc/1]).
setup() ->
prometheus_counter:declare([{name, my_service_requests_total},
{help, "Requests count"},
{labels, caller}]).
inc(Caller) ->
prometheus_counter:inc(my_service_requests_total, [Caller]).
| declare/1 | Creates a counter using Spec, if a counter with the same Spec exists
returns false. |
| deregister/1 | Equivalent to deregister(default, Name).
|
| deregister/2 |
Removes all counter series with name Name and
removes Metric Family from Registry. |
| inc/1 | Equivalent to inc(default, Name, [], 1).
|
| inc/2 | If the second argument is a list, equivalent to inc(default, Name, LabelValues, 1) otherwise equivalent to inc(default, Name, [], Value). |
| inc/3 | Equivalent to inc(default, Name, LabelValues, Value).
|
| inc/4 | Increments the counter identified by Registry, Name
and LabelValues by Value. |
| new/1 | Creates a counter using Spec. |
| remove/1 | Equivalent to remove(default, Name, []).
|
| remove/2 | Equivalent to remove(default, Name, LabelValues).
|
| remove/3 | Removes counter series identified by Registry, Name
and LabelValues. |
| reset/1 | Equivalent to reset(default, Name, []).
|
| reset/2 | Equivalent to reset(default, Name, LabelValues).
|
| reset/3 | Resets the value of the counter identified by Registry, Name
and LabelValues. |
| value/1 | Equivalent to value(default, Name, []).
|
| value/2 | Equivalent to value(default, Name, LabelValues).
|
| value/3 | Returns the value of the counter identified by Registry, Name
and LabelValues. |
| values/2 |
declare(Spec) -> any()
Creates a counter using Spec, if a counter with the same Spec exists
returns false.
{missing_metric_spec_key, Key, Spec} error if required Soec key
is missing.{invalid_metric_name, Name, Message} error if metric Name
is invalid.{invalid_metric_help, Help, Message} error if metric Help
is invalid.{invalid_metric_labels, Labels, Message} error if Labels
isn't a list.{invalid_label_name, Name, Message} error if Name isn't a valid
label name.
deregister(Name) -> any()
Equivalent to deregister(default, Name).
deregister(Registry, Name) -> any()
Removes all counter series with name Name and
removes Metric Family from Registry.
After this call new/1 for Name and Registry will succeed.
{true, _} if Name was a registered counter.
Otherwise returns {true, _}.
inc(Name) -> any()
Equivalent to inc(default, Name, [], 1).
inc(Name, LabelValues) -> any()
If the second argument is a list, equivalent to inc(default, Name, LabelValues, 1) otherwise equivalent to inc(default, Name, [], Value).
inc(Name, LabelValues, Value) -> any()
Equivalent to inc(default, Name, LabelValues, Value).
inc(Registry, Name, LabelValues, Value) -> any()
Increments the counter identified by Registry, Name
and LabelValues by Value.
{invalid_value, Value, Message} if Value
isn't a positive number.{unknown_metric, Registry, Name} error if counter with named Name
can't be found in Registry.{invalid_metric_arity, Present, Expected} error if labels count
mismatch.
new(Spec) -> any()
Creates a counter using Spec.
{missing_metric_spec_key, Key, Spec} error if required Soec key
is missing.{invalid_metric_name, Name, Message} error if metric Name
is invalid.{invalid_metric_help, Help, Message} error if metric Help
is invalid.{invalid_metric_labels, Labels, Message} error if Labels
isn't a list.{invalid_label_name, Name, Message} error if Name isn't a valid
label name.{mf_already_exists, {Registry, Name}, Message} error if a counter
with the same Spec already exists.
remove(Name) -> any()
Equivalent to remove(default, Name, []).
remove(Name, LabelValues) -> any()
Equivalent to remove(default, Name, LabelValues).
remove(Registry, Name, LabelValues) -> any()
Removes counter series identified by Registry, Name
and LabelValues.
{unknown_metric, Registry, Name} error if counter with name Name
can't be found in Registry.{invalid_metric_arity, Present, Expected} error if labels count
mismatch.
reset(Name) -> any()
Equivalent to reset(default, Name, []).
reset(Name, LabelValues) -> any()
Equivalent to reset(default, Name, LabelValues).
reset(Registry, Name, LabelValues) -> any()
Resets the value of the counter identified by Registry, Name
and LabelValues.
{unknown_metric, Registry, Name} error if counter with name Name
can't be found in Registry.{invalid_metric_arity, Present, Expected} error if labels count
mismatch.
value(Name) -> any()
Equivalent to value(default, Name, []).
value(Name, LabelValues) -> any()
Equivalent to value(default, Name, LabelValues).
value(Registry, Name, LabelValues) -> any()
Returns the value of the counter identified by Registry, Name
and LabelValues. If there is no counter for LabelValues,
returns undefined.
{unknown_metric, Registry, Name} error if counter named Name
can't be found in Registry.{invalid_metric_arity, Present, Expected} error if labels count
mismatch.
values(Registry, Name) -> any()
Generated by EDoc