View Source Mobius.RRD (mobius v0.6.1)

A round robin database for Mobius

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

A round robin database (RRD) is a data store that has 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 time 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.

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

Types

@type 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 contain 365 days.

Mobius.RRD.new(seconds: 300, days: 365)
@type resolution() :: :seconds | :minutes | :hours | :days

Resolution name

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

Options for saving RRD into a binary

  • :serialization_version - the version of serialization format, defaults to most recent
@opaque t()

Functions

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

Return all items in order

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

Insert an item for the specified time

@spec 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.

@spec 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)
@spec query(t(), from :: integer()) :: [{integer(), any()}]

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

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

Return all items within the specified range

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

Serialize to an iolist