Skip to main content

Disk space rules

RequiresEdge2.4.0+upcoming

Older Capture Edge versions ignore disk space rules. They use the Collector's single Min storage available setting and the bucket's Important flag instead.

A disk space rule tells the gateway what to do with one bucket when a drive runs low on free space. You find the rules on Local storage › Disk space.

Each rule has four parts:

PartWhat it is
DriveThe drive whose free space the rule watches. Normally the drive the bucket's data is stored on.
Act belowThe threshold, in MB free. The rule acts while free space on the drive is below it.
Database and BucketWhat the rule acts on: one bucket, All buckets of a database (All queues for a SQLite queue), or Collected files.
ActionDrop oldest data or Stop collecting.
Buckets without a rule are never cleaned up

A rule acts only on the drive and bucket it names. A gateway without rules keeps collecting until the drive is full. New configurations, and databases you add to an existing one, start without rules.


The usual setup​

Give each database two rules on the drive its data is on:

  1. Drop oldest data below 1,000 MB, for the buckets you can afford to lose old data from.
  2. Stop collecting for All buckets below 500 MB.

The first rule keeps the drive from filling up. The oldest data is most likely synced to the cloud already, so it goes first. The second rule is the safety net: if dropping data cannot keep up, the gateway stops writing before the drive is full and the database stops working.

Leave a bucket without a drop rule when its old data must never be removed. A stop rule still protects the drive.


Drive​

The drive as the Collector sees it:

  • Windows: a drive letter, such as D:\. D and D: mean the same. / means the drive Capture Edge runs from.
  • Linux: a mount point, such as / or /mnt/data.
  • Docker: a path inside the Collector container, such as /etc/capture when the Capture data directory is a volume.
  • Balena: /. Capture and its databases share the data partition.

Any absolute folder works too: the rule watches the drive that holds the folder. A relative path is not accepted.

A rule watches a drive and acts on a bucket, so the two have to match. A rule that watches a drive the bucket's data is not on can drop all of that bucket's data and still free nothing.

How free space is measured

Free space is the space Capture Edge can actually use. On Linux that leaves out the blocks the file system reserves for the root user, so it can be lower than what df shows as free.

1 MB is 1,000,000 bytes. df -m and Windows Explorer count in units of 1,048,576 bytes, so they show a slightly lower number for the same amount of space.


Actions​

Drop oldest data​

While free space is below the threshold, the gateway removes the oldest part of the bucket, measures free space again, and repeats. It never removes the part that is being written to.

What one step removes depends on the database:

DatabaseOne step removesNever removed
InfluxDBThe oldest shard of the bucket's retention policyThe newest shard group of the retention policy
TimescaleDB (wide and narrow table)The oldest chunk of the bucket's tablesThe newest chunk of each table
SQLite queueThe oldest 64 MB of rows
CSVThe oldest CSV file of the bucketA file that is still being written to, or was written to in the last minute
Collected filesThe oldest 64 MB of filesFiles younger than a minute
A SQLite queue holds data that is not synced yet

Every row in a queue is waiting to be sent to the cloud. A drop rule on a queue therefore removes data the cloud has never received. Add one only when losing the start of a long outage is better than running out of disk.

The gateway does not check whether old data has been synced before it removes it. In InfluxDB, TimescaleDB and CSV, the oldest data normally has been, unless the gateway has been offline for longer than the data the drive can hold.

Stop collecting​

Below the threshold, nothing new is written to the bucket. Points for a stopped bucket are discarded, and they are not written later. Other buckets keep being written. For Collected files, a file that arrives while collecting is stopped is not stored, and a short message saying so is stored in its place.

Collecting resumes once free space is back at or above the threshold, after at least 1 minute.

While a stop rule is active, the gateway raises an issue, for example Collecting stopped for capture (oneWeek): / has 480 MB free, below 500 MB.


How the gateway applies the rules​

The Collector checks the rules every 30 seconds, drive by drive:

  1. Stop collecting rules apply first, on every drive.
  2. Drop oldest data rules act in order of their threshold, highest first. Each takes one step, after which free space is measured again. Rules with the same threshold take turns.
  3. At most 100 steps are taken per drive per check, so one check never runs for long.

A rule that cannot work does nothing and raises an issue instead. That happens when:

  • the drive is not found, not ready, or could not be measured;
  • the database or bucket no longer exists;
  • the database cannot be cleaned up (see below).

Which databases can have rules​

Database typeRules
InfluxDB, TimescaleDB, SQLite queue, CSVYes
Collected filesYes, one target for all collected files
A database that is Hosted on another machineNo. Capture never cleans up or stops a database it does not manage.
Redis, MQTT, Influx 2, NATS JetStreamNo. These keep no data on the gateway's disk for Capture to drop.

Deleting a bucket or a database also deletes its rules.


The Disk space tab​

The tab shows one row per rule. You can add, duplicate and delete rules there.

  • Warnings flag a rule that is the same as another one, and a bucket whose rules watch different drives. They do not block saving.
  • Test a free-space level lets you pick a drive and a level of free space, and shows what each rule would do at that level.
  • On the Databases tab, the bucket table shows the rules of each bucket in its Disk space rules column.

When you open the configuration in the gateway's local UI, the tab also shows the drives the Collector sees with their free space, and a Status now column with what each saved rule is doing:

StatusMeaning
Not activeFree space is at or above the threshold.
DroppingThe rule is removing old data.
Nothing left to dropFree space is below the threshold, but the bucket has nothing left that may be removed.
Drop failedThe last step could not remove anything, for example because a file was locked.
StoppedCollecting is stopped for the bucket.
Drive not foundThe gateway does not have the drive.
Invalid ruleThe rule points at a database or bucket that does not exist or cannot be cleaned up.

A rule you have changed but not saved shows Changes apply after saving.


Updating from Min storage available​

Before Capture Edge 2.4.0, the Collector's Min storage available setting covered every bucket at once, on the drive Capture runs from, and the Important flag kept a bucket from being cleaned up.

The first time a gateway on 2.4.0 or newer loads a configuration that has no disk space rules yet, it translates that setting. For each InfluxDB and TimescaleDB database on the gateway, with Min storage available set to M:

  • Drop oldest data below 1.5 × M MB on /, for each bucket that is not marked Important;
  • Stop collecting for All buckets below M MB on /.

The Configuration editor makes the same rules when it opens such a configuration.

Check the translated rules
  • SQLite queues, CSV databases and collected files get no translated rules. Add rules for them yourself.
  • The translated rules watch /, the drive Capture runs from. If a database stores its data on another drive, change the rule's drive.
  • A configuration that already has a list of rules, even an empty one, is never translated.

Update the gateway to 2.4.0 or newer first, then add or check the rules and push the configuration. A gateway on an older version ignores the rules and keeps using Min storage available, which stays in the configuration for it.