prometheus_exometer v0.2.0 PrometheusExometer.Metrics View Source
Interface functions to update Exometer metrics with labels.
The underlying Exometer
API
to set values is simple. It doesn't change depending on the type of the
metric, you can call the update/3 function for everything. This function is a simple
wrapper which calls combine_name_labels/2 on its arguments, then calls
:exometer.update_or_create/2. Calling e.g. inc/3 if you are incrementing
a counter makes the intent clearer, though.
There are convenience functions to help with duration calculations as well.
This interface largely implements the recommended public API for Prometheus client libraries
Differences with the Prometheus API recommendations:
Erlang handles times in microseconds internally, so that's what we store, and that's the default output unit instead of seconds.
Link to this section Summary
Functions
Combine base metric name with labels
Decrement counter or gauge metric
Ensure that a metric exists with the specified keyword under the parent metric
Get Exometer metric value
Get Exometer metric value with labels
Increment counter or gauge metric
Observe current value for histogram or summary
Observe time difference in ms between starting time and current time
Set gauge to specified value
Set metric to the difference between the specified timestamp and the current time in ms
Set metric to the current Unix time in seconds
Record duration in ms of a function call, like Erlang :timer.tc/3
Update Exometer metric with labels
Link to this section Types
error()
View Source
error() :: {:error, any()}
error() :: {:error, any()}
labels()
View Source
labels() :: Keyword.t()
labels() :: Keyword.t()
name()
View Source
name() :: :exometer.name()
name() :: :exometer.name()
value()
View Source
value() :: any()
value() :: any()
Link to this section Functions
combine_name_labels(name, labels) View Source
Combine base metric name with labels.
dec(name)
View Source
dec(name()) :: :ok
dec(name()) :: :ok
dec(name, labels) View Source
dec(name, labels, value) View Source
Decrement counter or gauge metric.
Returns :ok.
Examples
iex> PrometheusExometer.Metrics.dec([:active_requests])
:ok
ensure_child(name, labels) View Source
Ensure that a metric exists with the specified keyword under the parent metric
get_value(name) View Source
Get Exometer metric value
get_value(name, labels) View Source
Get Exometer metric value with labels
inc(name)
View Source
inc(name()) :: :ok
inc(name()) :: :ok
inc(name, labels) View Source
inc(name, labels, value) View Source
Increment counter or gauge metric.
Returns :ok.
Examples
Increment simple requests metric by one:
iex> PrometheusExometer.Metrics.inc([:requests])
:ok
observe(name, value) View Source
observe(name, labels, value) View Source
Observe current value for histogram or summary.
observe_duration(name, start_time)
View Source
observe_duration(name(), :erlang.timestamp()) :: :ok | error()
observe_duration(name(), :erlang.timestamp()) :: :ok | error()
Observe time difference in ms between starting time and current time.
observe_duration(name, labels, start_time)
View Source
observe_duration(name(), labels(), :erlang.timestamp()) :: :ok | error()
observe_duration(name(), labels(), :erlang.timestamp()) :: :ok | error()
set(name, value) View Source
set(name, labels, value) View Source
Set gauge to specified value.
Returns :ok.
Examples
iex> PrometheusExometer.Metrics.set([:records], 1000)
:ok
set_duration(name, start_time)
View Source
set_duration(name(), :erlang.timestamp()) :: :ok
set_duration(name(), :erlang.timestamp()) :: :ok
Set metric to the difference between the specified timestamp and the current time in ms.
Returns :ok.
Examples
start_time = :os.timestamp()
do_some_work()
PrometheusExometer.Metrics.set_duration([:duration], start_time)
set_duration(name, labels, start_time)
View Source
set_duration(name(), labels(), :erlang.timestamp()) :: :ok
set_duration(name(), labels(), :erlang.timestamp()) :: :ok
set_to_current_time(name)
View Source
set_to_current_time(name()) :: :ok
set_to_current_time(name()) :: :ok
set_to_current_time(name, labels) View Source
Set metric to the current Unix time in seconds.
tc(name, mod, fun, args) View Source
Record duration in ms of a function call, like Erlang :timer.tc/3
tc(name, labels, mod, fun, args) View Source
update(name, tuple_value) View Source
update(name, labels, value) View Source
Update Exometer metric with labels