View Source PrometheusExometer.Metrics (prometheus_exometer v0.3.1)
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.
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
Types
@type error() :: {:error, any()}
@type labels() :: Keyword.t()
@type name() :: :exometer.name()
@type value() :: any()
Functions
Combine base metric name with labels.
@spec dec(name()) :: :ok
Decrement counter or gauge metric.
Returns :ok
.
Examples
iex> PrometheusExometer.Metrics.dec([:active_requests])
:ok
Ensure that a metric exists with the specified keyword under the parent metric
Get Exometer metric value
Get Exometer metric value with labels
@spec inc(name()) :: :ok
Increment counter or gauge metric.
Returns :ok
.
Examples
Increment simple requests
metric by one:
iex> PrometheusExometer.Metrics.inc([:requests])
:ok
Observe current value for histogram or summary.
@spec observe_duration(name(), :erlang.timestamp()) :: :ok | error()
Observe time difference in ms between starting time and current time.
@spec observe_duration(name(), labels(), :erlang.timestamp()) :: :ok | error()
Set gauge to specified value.
Returns :ok
.
Examples
iex> PrometheusExometer.Metrics.set([:records], 1000)
:ok
@spec 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)
@spec set_duration(name(), labels(), :erlang.timestamp()) :: :ok
@spec set_to_current_time(name()) :: :ok
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