Write data from InfluxDB OSS to InfluxDB Cloud

To write data from InfluxDB OSS to InfluxDB Cloud, use the Flux to() or experimental.to() functions. Write data once with a single query execution or use InfluxDB tasks to routinely write data to InfluxDB Cloud.

InfluxDB Cloud rate limits

Write requests to InfluxDB Cloud are subject to the rate limits associated with your InfluxDB Cloud pricing plan.

  1. Query data from InfluxDB OSS.

  2. (Optional) Filter or process data to write to InfluxDB Cloud.

  3. Use to or experimental.to to write data to InfluxDB Cloud. For most use cases, to() is the correct function to use, but depending on the structure of the data you’re writing, experimental.to may be required.

    Use the following guidelines:

    • to(): Use to write data in field keys to the _field column and field values to the _value column.

    • experimental.to(): Use to write data in column names to corresponding field keys and column values to field values.

    See input and output examples for to() functions.

  4. Provide the following parameters to either function:

    • bucket: InfluxDB Cloud bucket to write to
    • host: InfluxDB Cloud region URL
    • org: InfluxDB Cloud organization
    • token: InfluxDB Cloud API Token
  5. (Recommended) To keep your raw API token out of queries, store your InfluxDB Cloud API token as an InfluxDB secret in your InfluxDB OSS instance and use secrets.get() to retrieve the secret value as shown in the following example (select the function you’re using to see the correct format):

to() experimental.to()

  1. import "influxdata/influxdb/secrets"
  2. cloudToken = secrets.get(key: "INFLUX_CLOUD_API_TOKEN")
  3. from(bucket: "example-oss-bucket")
  4. |> range(start: -10m)
  5. |> filter(fn: (r) => r._measurement == "example-measurement")
  6. |> to(
  7. bucket: "example-cloud-bucket",
  8. host: "https://cloud2.influxdata.com",
  9. org: "example-org",
  10. token: cloudToken,
  11. )
  1. import "experimental"
  2. import "influxdata/influxdb/secrets"
  3. cloudToken = secrets.get(key: "INFLUX_CLOUD_API_TOKEN")
  4. from(bucket: "example-oss-bucket")
  5. |> range(start: -10m)
  6. |> filter(fn: (r) => r._measurement == "example-measurement")
  7. |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
  8. |> experimental.to(
  9. bucket: "example-cloud-bucket",
  10. host: "https://cloud2.influxdata.com",
  11. org: "example-org",
  12. token: cloudToken,
  13. )

Input and output data for to() functions

to() experimental.to()

  • to() requires _time, _measurement, _field, and _value columns.
  • to() writes all other columns as tags where the column name is the tag key and the column value is the tag value.

Input data

_time_measurementexampleTag_field_value
2021-01-01T00:00:00Zexample-mAtemp80.0
2021-01-01T00:01:00Zexample-mAtemp80.3
2021-01-01T00:02:00Zexample-mAtemp81.1
_time_measurementexampleTag_field_value
2021-01-01T00:00:00Zexample-mArpm4023
2021-01-01T00:01:00Zexample-mArpm4542
2021-01-01T00:02:00Zexample-mArpm4901

Output line protocol

  1. example-m,exampleTag=A temp=80.0,rpm=4023i 1609459200000000000
  2. example-m,exampleTag=A temp=80.3,rpm=4542i 1609459260000000000
  3. example-m,exampleTag=A temp=81.1,rpm=4901i 1609459320000000000
  • experimental.to() requires _time and _measurement columns.
  • Columns in the group key (other than _measurement) are parsed as tags where the column name is the tag key and the column value is the tag value.
  • Columns not in the group key (other than _time_) are parsed as fields where the column name is the field key and the column value is the field value.

Input data

Group key = [_measurement, exampleTag]

_time_measurementexampleTagtemprpm
2021-01-01T00:00:00Zexample-mA80.04023
2021-01-01T00:01:00Zexample-mA80.34542
2021-01-01T00:02:00Zexample-mA81.14901

Output line protocol

  1. example-m,exampleTag=A temp=80.0,rpm=4023i 1609459200000000000
  2. example-m,exampleTag=A temp=80.3,rpm=4542i 1609459260000000000
  3. example-m,exampleTag=A temp=81.1,rpm=4901i 1609459320000000000

Examples

Downsample and write data to InfluxDB Cloud

  1. import "influxdata/influxdb/secrets"
  2. cloudToken = secrets.get(key: "INFLUX_CLOUD_API_TOKEN")
  3. from(bucket: "example-oss-bucket")
  4. |> range(start: -10m)
  5. |> filter(fn: (r) => r._measurement == "example-measurement")
  6. |> aggregateWindow(every: 1m, fn: last)
  7. |> to(
  8. bucket: "example-cloud-bucket",
  9. host: "https://cloud2.influxdata.com",
  10. org: "example-org",
  11. token: cloudToken,
  12. )

Write min, max, and mean values to InfluxDB Cloud

  1. import "influxdata/influxdb/secrets"
  2. cloudToken = secrets.get(key: "INFLUX_CLOUD_API_TOKEN")
  3. data = from(bucket: "example-oss-bucket")
  4. |> range(start: -30m)
  5. |> filter(fn: (r) => r._measurement == "example-measurement")
  6. min = data |> aggregateWindow(every: 10m, fn: min) |> map(fn: (r) => ({ r with _field: "{$r._field}_min" }))
  7. max = data |> aggregateWindow(every: 10m, fn: max) |> map(fn: (r) => ({ r with _field: "{$r._field}_max" }))
  8. mean = data |> aggregateWindow(every: 10m, fn: mean) |> map(fn: (r) => ({ r with _field: "{$r._field}_mean" }))
  9. union(tables: [min, max, mean])
  10. |> to(
  11. bucket: "example-cloud-bucket",
  12. host: "https://cloud2.influxdata.com",
  13. org: "example-org",
  14. token: cloudToken,
  15. )

Automate writing data from InfluxDB OSS to InfluxDB Cloud

To automatically and routinely write data from InfluxDB OSS to InfluxDB Cloud, create a task in your InfluxDB OSS instance that regularly queries, processes, and writes data to InfluxDB Cloud.

  1. import "influxdata/influxdb/tasks"
  2. option task = {
  3. name: "Downsample to InfluxDB Cloud",
  4. every: 1h,
  5. }
  6. from(bucket: "example-oss-bucket")
  7. |> range(start: -10m)
  8. |> filter(fn: (r) => r._measurement == "example-measurement")
  9. |> aggregateWindow(every: 1m, fn: last)
  10. |> to(
  11. bucket: "example-cloud-bucket",
  12. host: "https://cloud2.influxdata.com",
  13. org: "example-org",
  14. token: cloudToken,
  15. )

write