Oban.Met.Values.Gauge (Oban Met v0.1.5)
One or more non-negative integers captured over time.
Summary
Functions
Add to the gauge.
Initialize a gauge struct from a stringified map, e.g. encoded JSON.
Merges two gauges into a one.
Initialize a new gauge.
Compute the quantile for a gauge.
Compute the sum for a gauge.
Union two gauges into a single value.
Types
@type t() :: %Oban.Met.Values.Gauge{data: [non_neg_integer()]}
Functions
Link to this function
add(gauge, value)
@spec add(t(), pos_integer()) :: t()
Add to the gauge.
Examples
iex> 1
...> |> Gauge.new()
...> |> Gauge.add(1)
...> |> Gauge.add(1)
...> |> Map.fetch!(:data)
[3]
Link to this function
from_map(map)
Initialize a gauge struct from a stringified map, e.g. encoded JSON.
Examples
iex> Gauge.new(2)
...> |> Jason.encode!()
...> |> Jason.decode!()
...> |> Gauge.from_map()
...> |> Map.fetch!(:data)
[2]
Link to this function
merge(gauge1, gauge2)
Merges two gauges into a one.
Examples
Merging two gauge retains all values:
iex> gauge_1 = Gauge.new([1, 2])
...> gauge_2 = Gauge.new([2, 3])
...> Gauge.merge(gauge_1, gauge_2).data
[1, 2, 2, 3]
Link to this function
new(data)
@spec new(non_neg_integer() | [non_neg_integer()]) :: t()
Initialize a new gauge.
Examples
iex> Gauge.new(1).data
[1]
iex> Gauge.new([1, 2]).data
[1, 2]
Link to this function
quantile(gauge, ntile)
@spec quantile(t(), float()) :: non_neg_integer()
Compute the quantile for a gauge.
Examples
With single values:
iex> Gauge.quantile(Gauge.new([1, 2, 3]), 1.0)
3
iex> Gauge.quantile(Gauge.new([1, 2, 3]), 0.5)
2
Link to this function
sum(gauge)
@spec sum(t()) :: non_neg_integer()
Compute the sum for a gauge.
Examples
iex> Gauge.sum(Gauge.new(3))
3
iex> Gauge.sum(Gauge.new([1, 2, 3]))
6
Link to this function
union(gauge1, gauge2)
Union two gauges into a single value.
Examples
Merging two gauge results in a single value:
iex> gauge_1 = Gauge.new([1, 2])
...> gauge_2 = Gauge.new([2, 3])
...> Gauge.union(gauge_1, gauge_2).data
[8]