Wobserver v0.1.4 Wobserver.Util.Metrics.Formatter behaviour
Formatter.
Summary
Functions
Formats a keyword list of metrics.
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 valuelist
of tuples with the following format:{value, labels}
, wherelabels
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"
Callbacks
combine_metrics(metrics)
combine_metrics(metrics :: list[<a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>]) :: String.t
merge_metrics(metrics)
merge_metrics(metrics :: list[<a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>]) :: String.t