View Source Wobserver.Util.Metrics.Formatter behaviour (Wobserver NG v1.14.0)

Formatter.

Link to this section Summary

Callbacks

Combines formatted metrics together.

Format a set of data with a label.

Merges formatted sets of metrics from different nodes together.

Functions

Format a set of data with a label for a metric parser/aggregater.

Formats a keyword list of metrics using a given formatter.

Merges formatted sets of metrics from different nodes together using a given formatter.

Link to this section Callbacks

Link to this callback

combine_metrics(metrics)

View Source
@callback combine_metrics(metrics :: list()[String.t()]) :: String.t()

Combines formatted metrics together.

Arguments:

  • metrics, a list of formatted metrics for one node.
Link to this callback

format_data(name, data, type, help)

View Source
@callback format_data(
  name :: String.t(),
  data :: [{integer() | float(), keyword()}],
  type :: :atom,
  help :: String.t()
) :: String.t()

Format a set of data with a label.

The data must be given as a list of tuples with the following format: {value, labels}, where labels is a keyword list with labels and their values.

The following options can also be given:

  • type, the type of the metric. The following values are currently supported: :gauge, :counter.
  • help, a single line text description of the metric.
@callback merge_metrics(metrics :: list()[String.t()]) :: String.t()

Merges formatted sets of metrics from different nodes together.

The merge should prevent double declarations of help and type.

Arguments:

  • metrics, a list of formatted sets metrics for multiple node.

Link to this section Functions

Link to this function

format(data, label, type \\ nil, help \\ nil, formatter \\ nil)

View Source
@spec format(
  data :: any(),
  label :: String.t(),
  type :: :gauge | :counter | nil,
  help :: String.t() | nil,
  formatter :: atom() | nil
) :: String.t() | :error

Format a set of data with a label for a metric parser/aggregater.

The following options can also be given:

  • type, the type of the metric. The following values are currently supported: :gauge, :counter.
  • help, a single line text description of the metric.
  • formatter, a module implementing the Formatter behaviour to format metrics.
Link to this function

format_all(data, formatter \\ nil)

View Source
@spec format_all(data :: list(), formatter :: atom()) :: String.t() | :error

Formats a keyword list of metrics using a given formatter.

Metrics

The key is the name of the metric and the value can be given in the following formats:

  • data
  • {data, type}
  • {data, type, help}

The different fields are:

  • data, the actual metrics information.
  • type, the type of the metric.
        Possible values: `:gauge`, `:counter`.
  • help, a one line text description of the metric.

The data can be given in the following formats:

  • integer | float, just a single value.

  • map, where every key will be turned into a type value.
  • keyword list, where every key will be turned into a type value
  • list of tuples with the following format: {value, labels}, where labels is a keyword list with labels and their values.
  • function | string, a function or String that can be evaluated to a function, which, when called, returns one of the above data-types.

Example:

iex> Wobserver.Util.Metrics.Formatter.format_all [simple: 5]
"simple{node=\"10.74.181.35\"} 5\n"
iex> Wobserver.Util.Metrics.Formatter.format_all [simple: {5, :gauge}]
"# TYPE simple gauge\nsimple{node=\"10.74.181.35\"} 5\n"
iex> Wobserver.Util.Metrics.Formatter.format_all [simple: {5, :gauge, "Example desc."}]
"# HELP simple Example desc.\n
# TYPE simple gauge\n
simple{node=\"10.74.181.35\"} 5\n"
iex> Wobserver.Util.Metrics.Formatter.format_all [simple: %{floor: 5, wall: 8}]
"simple{node=\"10.74.181.35\",type=\"floor\"} 5\n
simple{node=\"10.74.181.35\",type=\"wall\"} 8\n"
iex> Wobserver.Util.Metrics.Formatter.format_all [simple: [floor: 5, wall: 8]]
"simple{node=\"10.74.181.35\",type=\"floor\"} 5\n
simple{node=\"10.74.181.35\",type=\"wall\"} 8\n"
iex> Wobserver.Util.Metrics.Formatter.format_all [simple: [{5, [location: :floor]}, {8, [location: :wall]}]]
"simple{node=\"10.74.181.35\",location=\"floor\"} 5\n
simple{node=\"10.74.181.35\",location=\"wall\"} 8\n"
Link to this function

merge_metrics(metrics, formatter \\ nil)

View Source
@spec merge_metrics(metrics :: [String.t()], formatter :: atom()) ::
  String.t() | :error

Merges formatted sets of metrics from different nodes together using a given formatter.

The merge should prevent double declarations of help and type.

Arguments:

  • metrics, a list of formatted sets metrics for multiple node.