Wobserver v0.1.8 Wobserver.Util.Metrics.Formatter behaviour View Source
Formatter.
Link to this section Summary
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
Callbacks
Combines formatted metrics together
Format a set of data with a label
Merges formatted sets of metrics from different nodes together
Link to this section Functions
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 theFormatterbehaviour to format metrics.
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.keywordlist, where every key will be turned into a type valuelistof tuples with the following format:{value, labels}, wherelabelsis 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"
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.
Link to this section Callbacks
combine_metrics(metrics :: list[<a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>]) :: String.t
Combines formatted metrics together.
Arguments:
metrics, a list of formatted metrics for one node.
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.
merge_metrics(metrics :: list[<a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>]) :: 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.