Skip to content

InfluxDB To Victoria Metrics

In august 2021, Brewblox switched its history database from InfluxDB to Victoria Metrics. For the reasoning behind this change, see the decision document.

To migrate existing history data, we added the brewblox-ctl database from-influxdb command. This command creates an InfluxDB Docker container, reads all data, and writes it either to file, or to the new history database.

While the migration is in progress, you can use the system as normal.

If you have relatively little history data, migration is done in a matter of minutes. If you have multiple years worth of history data for multiple Spark controllers, the migration can take a few hours.

Safety

To avoid accidental data corruption, we've made sure that:

  • No InfluxDB data is removed.
  • The migration command can safely be restarted.
  • The migration command can safely be run multiple times.

Output

During the migration, progress is printed to the console

sh
INFO       Starting InfluxDB container...
INFO       Exporting services: spark-one
INFO       spark-one: exported 5000/18521 lines
INFO       spark-one: exported 10000/18521 lines
INFO       spark-one: exported 15000/18521 lines
INFO       spark-one: exported 18521/18521 lines

A "line" is a set of values with the same timestamp. There is one line for every time history data was published.

Arguments

Services

If you only want to migrate data for some of your services, you can list those you want to migrate.

If you do not specify any, all services will be migrated.

Examples
sh
brewblox-ctl database from-influxdb
brewblox-ctl database from-influxdb spark-one
brewblox-ctl database from-influxdb spark-one spark-two tilt

Duration

You can use the --duration option to set from how far back data will be migrated. If you for example use --duration 30d, then only history data for the last month will be copied.

If this argument is not set, the command will prompt you to set a value. If you leave it empty, there is no limit, and all history data will be migrated.

Examples
sh
brewblox-ctl database from-influxdb --duration 1h
brewblox-ctl database from-influxdb --duration 30d
brewblox-ctl database from-influxdb --duration 1y

Offset

To support resuming a lengthy migration, use the --offset option. This option has two values: the service name, and the offset value.

The offset value matches the number of lines printed during the command.

If this was the last line printed by the migrate command before it was interrupted:

txt
INFO       spark-one: exported 10000/18521 lines

Then you can resume the migration by using

sh
brewblox-ctl database from-influxdb --offset spark-one 10000

Again: it is perfectly safe to restart the migration from 0. The --offset argument is there to save time.

The --offset argument can be used multiple times, and can be combined with explicitly listed services.

Examples

For all examples, we'll assume there are three services in InfluxDB: spark-one, spark-two, and tilt

To resume after the migration stopped halfway through spark-one

sh
brewblox-ctl database from-influxdb --offset spark-one 10000

To resume after spark-one was fully migrated, and spark-two was in progress:

sh
brewblox-ctl database from-influxdb --offset spark-two 10000 spark-two tilt

To skip the first 5000 lines for all three services:

sh
brewblox-ctl database from-influxdb --offset spark-one 5000 --offset spark-two 5000 --offset tilt 50000

Target

By default, data is immediately inserted into the Victoria Metrics database. If you'd rather save the data to file, you can use --target file.

If this is set, data will be saved to one or more files in the ~/brewblox/influxdb-export/ directory. Data is formatted using the InfluxDB line protocol, and files are batched with 50 000 lines per file.

File names are formatted as {SERVICE}__{DATE}__{DURATION}__{IDX}.lines, and will be in the correct order when sorted alphabetically.

  • {SERVICE} is the service name
  • {DATE} is a %Y%m%d_%H%M (eg. 20210730_1542) formatted timestamp, and will be the same for all files generated by a single command.
  • {DURATION} is the value for the --duration option, or "all" if it was left blank.
  • {IDX} is a 3-digit index (001, 002, ...) incremented by one per batch.
Examples
sh
brewblox-ctl database from-influxdb --target file