Beaker.Gauge
Beaker.Gauge
is a simple gauge. It’s a metric where a value can be set and retrieved.
It is commonly used for metrics that return a single value.
Examples are:
- Average response time
- Uptime (Availability)
- Latency / Ping
Summary↑
all() | Retrieves all gauges in the form of a map |
clear() | Clears all gauges stored in Beaker |
get(key) | Retrieves the current value of the specified gauge |
set(key, value) | Sets the gauge to the specified value |
time(key, func) | Times the provided function and sets the duration to the gauge with the specified key |
Functions
Retrieves all gauges in the form of a map.
Examples
iex> Beaker.Gauge.clear
:ok
iex> Beaker.Gauge.set("all_gauge1", 10)
:ok
iex> Beaker.Gauge.set("all_gauge2", 1)
:ok
iex> Beaker.Gauge.all
%{"all_gauge1" => 10, "all_gauge2" => 1}
Returns gauges
where gauges is a map of all the gauges currently existing.
Clears all gauges stored in Beaker.
Examples
iex> Beaker.Gauge.clear
:ok
iex> Beaker.Gauge.set("all_gauge1", 10)
:ok
iex> Beaker.Gauge.set("all_gauge2", 1)
:ok
iex> Beaker.Gauge.all
%{"all_gauge1" => 10, "all_gauge2" => 1}
iex> Beaker.Gauge.clear
:ok
iex> Beaker.Gauge.all
%{}
Returns :ok
.
Retrieves the current value of the specified gauge.
Parameters
key
: The name of the gauge to retrieve.
Examples
iex> Beaker.Gauge.set("get_gauge", 50)
:ok
iex> Beaker.Gauge.get("get_gauge")
50
Returns count
where count is an integer if the gauge exists, else nil
.
Sets the gauge to the specified value.
Parameters
key
: The name of the gauge to set the value for.value
: The value to set to the gauge.
Examples
iex> Beaker.Gauge.set("set_gauge", 3.14159)
:ok
iex> Beaker.Gauge.get("set_gauge")
3.14159
Returns :ok
Macros
Times the provided function and sets the duration to the gauge with the specified key.
Parameters
key
: The name of the gauge to set the duration to.func
: The function perform and time.
Examples
iex> Beaker.Gauge.time("time_gauge", fn -> :timer.sleep(50); 2 + 2 end)
4
iex> Beaker.Gauge.get("time_gauge") > 50
true
iex> Beaker.Gauge.time "time_gauge", do: 3 + 3
6
Returns value
where value is the return value of the function that was performed.