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

Link to this section Functions

Link to this function

combine_name_labels(name, labels) View Source
combine_name_labels(name(), labels()) :: name()

Combine base metric name with labels.

Link to this function

dec(name, labels) View Source
dec(name(), labels() | value()) :: :ok

Link to this function

dec(name, labels, value) View Source
dec(name(), labels(), value()) :: :ok

Decrement counter or gauge metric.

Returns :ok.

Examples

iex> PrometheusExometer.Metrics.dec([:active_requests])
:ok
Link to this function

ensure_child(name, labels) View Source
ensure_child(name(), labels()) :: :ok | error()

Ensure that a metric exists with the specified keyword under the parent metric

Link to this function

get_value(name) View Source
get_value(name()) :: {:ok, any()} | {:error, :not_found}

Get Exometer metric value

Link to this function

get_value(name, labels) View Source
get_value(name(), labels()) :: {:ok, any()} | {:error, :not_found}

Get Exometer metric value with labels

Link to this function

inc(name, labels) View Source
inc(name(), labels() | value()) :: :ok

Link to this function

inc(name, labels, value) View Source
inc(name(), labels(), value()) :: :ok

Increment counter or gauge metric.

Returns :ok.

Examples

Increment simple requests metric by one:

iex> PrometheusExometer.Metrics.inc([:requests])
:ok
Link to this function

observe(name, value) View Source
observe(name(), value()) :: :ok | error()

Link to this function

observe(name, labels, value) View Source
observe(name(), labels(), float() | integer()) :: :ok | error()

Observe current value for histogram or summary.

Link to this function

observe_duration(name, start_time) View Source
observe_duration(name(), :erlang.timestamp()) :: :ok | error()

Observe time difference in ms between starting time and current time.

Link to this function

observe_duration(name, labels, start_time) View Source
observe_duration(name(), labels(), :erlang.timestamp()) :: :ok | error()

Link to this function

set(name, value) View Source
set(name(), float()) :: :ok

Link to this function

set(name, labels, value) View Source
set(list(), labels(), float()) :: :ok

Set gauge to specified value.

Returns :ok.

Examples

iex> PrometheusExometer.Metrics.set([:records], 1000)
:ok
Link to this function

set_duration(name, start_time) View Source
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)
Link to this function

set_duration(name, labels, start_time) View Source
set_duration(name(), labels(), :erlang.timestamp()) :: :ok

Link to this function

set_to_current_time(name) View Source
set_to_current_time(name()) :: :ok

Link to this function

set_to_current_time(name, labels) View Source
set_to_current_time(name(), labels()) :: :ok

Set metric to the current Unix time in seconds.

Link to this function

tc(name, mod, fun, args) View Source
tc(name(), module(), atom(), list()) :: any()

Record duration in ms of a function call, like Erlang :timer.tc/3

Link to this function

tc(name, labels, mod, fun, args) View Source
tc(name(), labels(), module(), atom(), list()) :: any()

Link to this function

update(name, tuple_value) View Source
update(name(), value()) :: :ok | error()

Link to this function

update(name, labels, value) View Source
update(name(), labels(), value()) :: :ok | error()

Update Exometer metric with labels