View Source Mobius (mobius v0.3.7)

Localized metrics reporter

Link to this section Summary

Types

Arguments to Mobius

Options for our CSV export

Options to use when filtering time series metric data

The name of the Mobius instance

Options for our plot export

A list of data recorded data points tied to a particular timestamp

Functions

Returns a specification to start this module under a supervisor.

Retrieve the raw metric data from the history store for a given metric.

Function for creating a Mobius.Bundle.t()

Plot the metric name to the screen

Start Mobius

Produces a CSV of currently collected metrics, optionally writing the CSV to file. The CSV looks like: timestamp, name, type, value, tag1, tag2, tag3..., tagN If tags are provided, only the metrics matching the tags are output to the CSV. If a writable file is given via the :file option, the CSV is written to it. Otherwise it is written to the terminal. If the optional :naming option contains :csv_ext, the .csv extension is added to the file name if not already present. If the optional :naming option list :timestamp, the file name is prefixed by a timestamp.

Link to this section Types

Specs

arg() ::
  {:name, name()}
  | {:metrics, [Telemetry.Metrics.t()]}
  | {:persistence_dir, binary()}

Arguments to Mobius

  • :name - the name of the mobius instance (defaults to :mobius)
  • :metrics - list of telemetry metrics for Mobius to track
  • :persistence_dir - the top level directory where mobius will persist
  • :autosave_interval - time in seconds between automatic writes of the persistence data (default disabled) metric information
  • :day_count - number of day-granularity samples to keep
  • :hour_count - number of hour-granularity samples to keep
  • :minute_count - number of minute-granularity samples to keep
  • :second_count - number of second-granularity samples to keep

Specs

csv_opt() :: {:file, String.t()} | {:naming, [naming_opt()]} | filter_opt()

Options for our CSV export

Specs

filter_opt() ::
  {:name, name()}
  | {:last, integer() | {integer(), time_unit()}}
  | {:from, integer()}
  | {:to, integer()}
  | {:type, metric_type()}

Options to use when filtering time series metric data

  • :name - the name of the Mobius instance you are using. Unless you specified this in your configuration you should be safe to allow this option to default, which is :mobius_metrics.
  • :last - display data point that have been captured over the last x amount of time. Where x is either an integer or a tuple of {integer(), time_unit()}. If you only pass an integer the time unit of :seconds is assumed. By default Mobius will plot the last 3 minutes of data.
  • :from - the unix timestamp, in seconds, to start querying from
  • :to - the unix timestamp, in seconds, to stop querying at
  • :type - for metrics that have different types of measurements, you can pass this option to filter which metric type you want to plot

Specs

make_bundle_opt() :: {:name, name()}

Specs

metric() :: %{
  type: metric_type(),
  value: term(),
  tags: map(),
  timestamp: integer()
}

Specs

metric_name() :: [atom()]

Specs

metric_type() :: :counter | :last_value | :sum | :summary

Specs

name() :: atom()

The name of the Mobius instance

This is used to store data for a particular set of mobius metrics.

Specs

naming_opt() :: :csv_ext | :timestamp

Specs

plot_opt() :: filter_opt()

Options for our plot export

Specs

A list of data recorded data points tied to a particular timestamp

Specs

time_unit() :: :second | :minute | :hour | :day

Specs

timestamp() :: integer()

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

filter_metrics(metric_name, tags \\ %{}, opts \\ [])

View Source

Specs

filter_metrics(String.t(), map(), [filter_opt()]) :: [metric()]

Retrieve the raw metric data from the history store for a given metric.

Output will be a list of metric values, which will be in the format, eg: %{type: :last_value, value: 12, tags: %{interface: "eth0"}, timestamp: 1645107424}

If there are tags for the metric you can pass those in the second argument:

Mobius.filter_metrics("vm.memory.total", %{some: :tag})

By default the filter will display the last 3 minutes of metric history.

However, you can pass the :from and :to options to look at a specific range of time.

Mobius.filter_metrics("vm.memory.total", %{}, from: 1630619212, to: 1630619219)

You can also filter data over the last x amount of time. Where x is an integer. When there is no time_unit() provided the unit is assumed to be :second.

Retrieving data over the last 30 seconds:

Mobius.filter_metrics("vm.memory.total", %{}, last: 30)

Retrieving data over the last 2 hours:

Mobius.filter_metrics("vm.memory.total", %{}, last: {2, :hour})
Link to this function

info(name \\ [name: :mobius, persistence_dir: "/data", autosave_interval: nil][:name])

View Source

Specs

info(name() | nil) :: :ok

Get the current metric information

If you configured Mobius to use a different name then you can pass in your custom name to ensure Mobius requests the metrics from the right place.

Link to this function

make_bundle(bundle_target, opts \\ [])

View Source

Specs

Function for creating a Mobius.Bundle.t()

This function makes a bundle that can be used with the functions in Mobius.Bundle

Link to this function

plot(metric_name, tags \\ %{}, opts \\ [])

View Source

Specs

plot(binary(), map(), [plot_opt()]) :: :ok

Plot the metric name to the screen

This takes the same arguments as for filter_metrics, eg:

If there are tags for the metric you can pass those in the second argument:

Mobius.plot("vm.memory.total", %{some: :tag})

By default the plot will display the last 3 minutes of metric history.

However, you can pass the :from and :to options to look at a specific range of time.

Mobius.plot("vm.memory.total", %{}, from: 1630619212, to: 1630619219)

You can also plot data over the last x amount of time. Where x is an integer. When there is no time_unit() provided the unit is assumed to be :second.

Plotting data over the last 30 seconds:

Mobius.plot("vm.memory.total", %{}, last: 30)

Plotting data over the last 2 hours:

Mobius.plot("vm.memory.total", %{}, last: {2, :hour})
Link to this function

save(name \\ [name: :mobius, persistence_dir: "/data", autosave_interval: nil][:name])

View Source

Specs

save(name()) :: :ok | {:error, reason :: term()}

Persist the metrics to disk

Start Mobius

Link to this function

to_csv(metric_name, tags \\ %{}, opts \\ [])

View Source

Specs

to_csv(String.t(), map(), [csv_opt()]) :: :ok

Produces a CSV of currently collected metrics, optionally writing the CSV to file. The CSV looks like: timestamp, name, type, value, tag1, tag2, tag3..., tagN If tags are provided, only the metrics matching the tags are output to the CSV. If a writable file is given via the :file option, the CSV is written to it. Otherwise it is written to the terminal. If the optional :naming option contains :csv_ext, the .csv extension is added to the file name if not already present. If the optional :naming option list :timestamp, the file name is prefixed by a timestamp.

This accepts the same arguments as for filter_metrics to control the metrics, tags, times, etc to be outputted to CSV:

  • :last - metrics captured over the last x amount of time. Where x is either an integer or a tuple of {integer(), time_unit()}. If you only pass an integer the time unit of :seconds is assumed. By default the last 3 minutes of data will be outputted.
  • :from - the unix timestamp, in seconds, to start querying from
  • :to - the unix timestamp, in seconds, to stop querying at

If a metric has multiple types, a CSV can filter on one type with option type: :sum or type: :last_value etc..

Examples:

iex> Mobius.to_csv("vm.memory.total", %{})

-- writes CSV values to the terminal

iex> Mobius.to_csv("vm.memory.total", %{}, file: "/data/csv/vm.memory.total")

-- writes CSV values to file vm.memory.total

iex> Mobius.to_csv("vm.memory.total", %{}, file: "/data/csv/vm.memory.total", naming: [:csv_ext, :timestamp])

-- writes CSV values to a file like 20210830T174954_vm.memory.total.csv

iex> Mobius.to_csv("vm.memory.total", %{})

-- writes CSV values to the terminal

iex> Mobius.to_csv("vintage_net_qmi.connection.end.duration", %{ifname: "wwan0", status: :disconnected}, type: :sum, last: {60, :day})

-- writes CSV values to the terminal