Oban.Met.Values.Gauge (Oban Met v1.0.3)

View Source

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

t()

@type t() :: %Oban.Met.Values.Gauge{data: [non_neg_integer()]}

Functions

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]

from_map(map)

@spec from_map(%{optional(String.t()) => term()}) :: t()

Initialize a gauge struct from a stringified map, e.g. encoded JSON.

Examples

iex> Gauge.new(2)
...> |> Oban.JSON.encode!()
...> |> Oban.JSON.decode!()
...> |> Gauge.from_map()
...> |> Map.fetch!(:data)
[2]

merge(gauge1, gauge2)

@spec merge(t(), t()) :: t()

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]

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]

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

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

union(gauge1, gauge2)

@spec union(t(), t()) :: t()

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]