beaker v1.3.0 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
Functions
Retrieves all gauges in the form of a map
Clears all gauges stored in Beaker
Clears the specified gauge from Beaker
Retrieves the current value of the specified gauge
DEPRECATED
Sets gauge with min max values
Macros
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, 0, 100)
:ok
iex> Beaker.Gauge.set("all_gauge2", 1, 0, 100)
:ok
iex> Beaker.Gauge.all
%{"all_gauge1" => %{max: 100, min: 0, name: "all_gauge1", value: 10},
"all_gauge2" => %{max: 100, min: 0, name: "all_gauge2", value: 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, 0, 100)
:ok
iex> Beaker.Gauge.set("all_gauge2", 1, 0, 100)
:ok
iex> Beaker.Gauge.all
%{"all_gauge1" => %{max: 100, min: 0, name: "all_gauge1", value: 10},
"all_gauge2" => %{max: 100, min: 0, name: "all_gauge2", value: 1}}
iex> Beaker.Gauge.clear
:ok
iex> Beaker.Gauge.all
%{}
Returns :ok
.
Clears the specified gauge from Beaker.
Parameters
key
: The name of the gauge to clear.
Examples
iex> Beaker.Gauge.clear
:ok
iex> Beaker.Gauge.set("all_gauge1", 10, 0, 100)
:ok
iex> Beaker.Gauge.set("all_gauge2", 1, 0, 100)
:ok
iex> Beaker.Gauge.all
%{"all_gauge1" => %{max: 100, min: 0, name: "all_gauge1", value: 10},
"all_gauge2" => %{max: 100, min: 0, name: "all_gauge2", value: 1}}
iex> Beaker.Gauge.clear("all_gauge1")
:ok
iex> Beaker.Gauge.all
%{"all_gauge2" => %{max: 100, min: 0, name: "all_gauge2", value: 1}}
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, 0, 100)
:ok
iex> Beaker.Gauge.get("get_gauge")
%{max: 100, min: 0, name: "get_gauge", value: 50}
Returns count
where count is an integer if the gauge exists, else nil
.
DEPRECATED
It is now expected that you set a min and max value for a gauge, rather than just a value. Please use set/4 instead.
Sets gauge with min max values
Parameters
key
: The name of the gauges to set the value for.value
: The value to set for the gaugemin
: The lowest value for the gaugemax
: The highest value for the gauge
Examples
iex> Beaker.Gauge.set(“latency”, 70, 0, 1000) :ok iex> Beaker.Gauge.get(“latency”) %{name: “latency”, value: 70, min: 0, max: 1000}
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.