View Source Mobius.RRD (mobius v0.4.0)

A round robin database for Mobius

This is RRD is used by Mobius to store historical metric data.

A round robin database (RRD) is a data store that a circular buffer to store information. As time moves forward the older data points get overwritten by newer data points. This type of data storage is useful for a consistent memory footprint for time series data.

The Mobius.RRD implementation provides four resolutions. These are: seconds, minutes, hours, and days. Each resolution can be configured to allow for as many single data points as you see fit. For example, if you want to store three days of data at an hour resolution you can configure the RRD like so:

RRD.new(hours: 72)

The above will configure the hour resolution to store 72 hours worth of data points in the hour archive.

The default resolutions are:

  • 60 days (each day for about 2 months)
  • 48 hours (each hour for 2 days)
  • 120 minutes (each minute for 2 hours)
  • 120 seconds (each second for 2 minutes)

For more information about round robin databases, RRD tool is a great resource to study.

Link to this section Summary

Types

Options for the RRD

Resolution name

Options for saving RRD into a binary

t()

Functions

Return all items in order

Insert an item for the specified time

Load persisted data back into a TimeLayerBuffer

Create a new RRD

Return all items with timestamps equal to or after the specified one

Return all items within the specified range

Serialize to an iolist

Link to this section Types

Specs

create_opt() :: {resolution(), non_neg_integer()}

Options for the RRD

For resolution options you specify which resolution and the max number of metric data to keep for that resolution.

For example, if the RRD were to track seconds up to five minutes it would need to track 300 seconds. Also, if the same RRD wanted to track day resolution for a year, it would need to be contain 365 days.

Mobius.RRD.new(seconds: 300, days: 365)

Specs

resolution() :: :seconds | :minutes | :hours | :days

Resolution name

Specs

save_opt() :: {:serialization_version, 1 | 2}

Options for saving RRD into a binary

  • :serialization_version - the version of serialization format, defaults to most recent

Specs

t()

Link to this section Functions

Specs

all(t()) :: [{Mobius.timestamp(), [Mobius.metric()]}]

Return all items in order

Specs

insert(t(), integer(), [Mobius.metric()]) :: t()

Insert an item for the specified time

Specs

load(t(), binary()) :: {:ok, t()} | {:error, Mobius.DataLoadError.t()}

Load persisted data back into a TimeLayerBuffer

The rrd that's passed in is expected to be a new one without any entries.

Specs

new([create_opt()]) :: t()

Create a new RRD

The default resolution values are:

  • 60 days (each day for about 2 months)
  • 48 hours (each hour for 2 days)
  • 120 minutes (each minute for 2 hours)
  • 120 seconds (each second for 2 minutes)

Specs

query(t(), from :: integer()) :: [{integer(), any()}]

Return all items with timestamps equal to or after the specified one

Specs

query(t(), from :: integer(), to :: integer()) :: [{integer(), any()}]

Return all items within the specified range

Specs

save(t(), [save_opt()]) :: iolist()

Serialize to an iolist