Wobserver v0.1.3 Wobserver.Util.Metrics.Formatter behaviour

Formatter.

Summary

Functions

format(data, label, type \\ nil, help \\ nil, formatter \\ nil)
format(data :: any, label :: String.t, type :: :gauge | :counter | nil, help :: String.t | nil, formatter :: atom | nil) ::
  String.t |
  :error
format_all(data, formatter \\ nil)
format_all(data :: list, formatter :: atom) :: String.t | :error

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 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"
merge_metrics(metrics, formatter \\ nil)
merge_metrics(metrics :: [String.t], formatter :: atom) ::
  String.t |
  :error

Merges formatted metrics together.

Callbacks

combine_metrics(metrics)
format_data(name, data, type, help)
format_data(name :: String.t, data :: [{integer | float, keyword}], type :: :atom, help :: String.t) :: String.t