Container — storage for your own time series data

Storage for time series and other data your application posts under numeric keys.

Essentials

  • A container is a flespi storage item for data your application posts itself: metrics, results of external processing or any other records that do not come from a device.
  • Each container message is a set of parameters stored under a numeric key, usually a UNIX timestamp.
  • The container settings define how messages with the same key are stored, how long they are kept and whether old time series data is compacted automatically.
  • Messages can be read, filtered and aggregated via REST API and received in real time via MQTT.

How containers work

Your application posts messages to a container with POST /storage/containers/{selector}/messages. Each message carries a key, a number that is usually a UNIX timestamp with up to 6 digits (microseconds) in the fraction part, and params, up to 1000 parameters with string, number, boolean, null or JSON values.

Messages are returned sorted by key with GET /storage/containers/{selector}/messages, where you can select a key range, filter messages with flespi expressions and pick the parameters to return.

Messages with the same key

The container flags set what happens when a message is posted under a key that already exists:

FlagsBehavior
0replace the stored message with the new one (default)
1skip the new message
2merge parameters, the new message replaces values of parameters with the same names
3keep both messages, all duplicates under a key are returned on read

A single message may set its own flags to override the container default. Mode 3 cannot be combined with modes 0, 1 and 2 in one container.

Retention

  • ttl: messages with keys older than this number of seconds are deleted automatically. It requires UNIX timestamp keys, and -1 means no ttl.
  • rotate: when the container storage exceeds this size in KiB, messages with the lowest keys are deleted.

When the container exceeds the storage limit, it is blocked for new messages until you delete messages from it.

Automatic generalization

Flag 0x10, added to the duplicates mode (flags 16 to 19), compacts old time series data. It works in containers with UNIX timestamp keys and without ttl or with ttl of at least 7 days. Once a day flespi replaces all messages whose keys fall into one UTC-aligned window with a single message under the window start key. The window depends on the message age:

Message ageWindow
7 to 14 days10 minutes
14 to 30 days30 minutes
30 to 60 days1 hour
60 to 90 days6 hours
over 90 days1 day
  • Numeric parameters get the average of the window values, each stored message counting once, duplicates included. String and JSON parameters keep the first value of the window.
  • A window with a single message stays unchanged.
  • Coarser windows average already generalized messages, so the result is not weighted by the original sample counts.
  • The original messages are deleted, so the container storage size decreases. Enabling the flag applies it to messages already stored as well.

Automatic generalization fits gauges, such as temperatures or loads, whose average is meaningful. Keep counters, states and exact events in a container without this flag.

Aggregation on read

To aggregate messages without changing the stored data:

  • the generalize parameter of GET messages groups messages into intervals of the given number of seconds and returns one message per interval, calculated with the average, minimum, maximum, summary or difference method
  • the calculate method splits container messages into intervals with interval selectors and calculates them with interval counters, the reports engine in its manual mode

How to create a container?

  • Log in to the flespi panel.
  • Navigate to Storage -> Containers and click the "+" button in the bottom right corner to add a new container.
  • Give the container a name, pick the flags with the duplicates mode and, if needed, automatic generalization, set ttl and rotate and click Save:
    create a container
  • Post messages to the container from your application via REST API. The Logs & Messages tab of the container shows the stored messages, and a click on a message shows its parameters:
    container messages

Containers API

To perform any operations with the containers and their messages, use the containers API.

You can receive container data in real time via MQTT topics:

  • flespi/message/storage/containers/{id} - messages posted to the container, one MQTT message per successful POST request;
  • flespi/state/storage/containers/{id}/+ - container fields, such as size in KiB and blocked code;
  • flespi/log/storage/containers/{id}/+ - container log events: created, updated, blocked, unblocked, deleted.

Troubleshooting

In case of any issues, check the Logs of the container in the Logs & Messages tab. They record configuration changes and blocking of the container, and the "blocked" parameter of a block event tells the reason:

container logs

If messages disappear earlier than expected, check the ttl and rotate settings, and the flags for the duplicates mode and automatic generalization.

What's next?


See also
File storage with public links and an own domain for static sites.