TL;DR Tech Tips — How to Construct a Table with Flux

  • Generate line protocol and write it manually to InfluxDB through the UI. Writing line protocol data to InfluxDB through the UI is easy, if you don’t need to include a specific timestamp. If a data point does not include a timestamp when it is received by the database, InfluxDB uses the current system time (UTC) of its host machine. However, if you need to add data with timestamps, you need to include Unix timestamps based on epoch time. This makes generating line protocol data a little difficult — you’ll most likely rely on a timestamp converter.
  • Copy and edit an Annotated CSV and use the csv.from() function to write the data to a bucket. This approach isn’t recommended because editing a CSV can be difficult and invites human error. However, using the CSV export UI functionality in conjunction with the csv.from() is a great way to share data with colleagues and community. Community members with Flux questions frequently share their Annotated CSV data with me. Then I’m able to use the csv.from() function to help answer their Flux questions.
  • Use the influx write command to write any CSV to InfluxDB. This is a great tool, but it assumes that you already have the data in a CSV format. The influx write command is great for writing large volumes of existing CSV data to InfluxDB.
  • We’ve recently introduced a new method, the array.from() function is a Flux function that allows you to construct tables on the fly.
  • Allowing you to write data with timestamps in a human readable RFC3339 timestamp format (as opposed to epoch time).
  • Reliably construct data through a list of objects rather than manually editing an annotated CSV.
  • Saving you time. You don’t need to collect authentication parameters to use array.from() like you do with influx write.
import "experimental/array"

|> array.from(rows: [{_time: 2020-01-01T00:00:00Z, _value: "foo"},{_time: 2020-01-02T00:00:00Z, _value: "bar"}])
compilation failed: error at @3:3-3:5: invalid statement: |>
  • _measurement: this key corresponds to the measurement column; the value must be a string.
  • _field: this key corresponds to the field column; the value must be string.
  • _value: this key corresponds to the field value column; the value can be a string, float, or integer.
  • _time: this key corresponds to the timestamp column; the value is in the RFC3339 timestamp format.
  • Tag set column can be given any key name; the value must be a string.
import "experimental/array"
array.from(rows: [{_measurement: "m0", mytag: "t0", _field: "f0", _value: "foo", _time: 2020-01-01T00:00:00Z,},
{_measurement: "m0", mytag: "t0", _field: "f0", _value: "bar", _time: 2020-01-02T00:00:00Z}])




Developer Advocate at InfluxData

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

No-code and Low-code: an Engineering tale from modern times

Is It Really Necessary to Defrag a Mac Drive?

Chapter 7 Attorney

chapter 7 attorney

Google’s Android Studio IDE gets live edits to speed up development cycles : Tech Big News

Day 4: Creating the Spawn Manager

Streamline Your Electronic Music Studio

Publishing and consuming debugging symbols for .net core library

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Anais Dotis

Anais Dotis

Developer Advocate at InfluxData

More from Medium

Using AWS Macie to Identify and Protect Sensitive Data at Scale

Installing APEX+ORDS on On-Prem Oracle Database

The future of the data center is cloud native

Create and Browse Reusable Datasets in Your Private S3 Buckets with quilt3