influxdb data/table be downloaded as csv file?

influxdb data/table be downloaded as csv file?

Influxdb is a time series database which stores data and its attributes in the tables, commonly known as measurements.
Can the tables in databases of influxdb be fetched to local system in csv format?

Solutions/Answers:

Solution 1:

In CLI following command can be used to download tables on the local system:

influx -database 'database_name' -execute 'SELECT * FROM table_name' -format csv > test.csv

Solution 2:

Using CLI tool influx you can set csv output format for results:

influx -host your_host -port 8086 -database 'your_db' -execute 'select * from your_metric' -format 'csv'

-host and -port options can be omitted if command is run on local InfluxDB host.
There is also useful -precision option to set format of timestamp.

Solution 3:

Alternatively, you can use jq to convert the JSON output to CSV as follows, which also allows you to get RFC3339 formatted timestamps:

jq -r "(.results[0].series[0].columns), (.results[0].series[0].values[]) | @csv"

which gives the output

"time","ppm","T"
"2019-01-17T19:45:00Z",864.5,18.54
"2019-01-17T19:50:00Z",861.4,18.545
"2019-01-17T19:55:00Z",866.2,18.5
"2019-01-17T20:00:00Z",863.9,18.47

and works because:

Related:  Kapacitor .post() HTTP Post to url not sending data
  • (.results[0].series[0].columns) gets the column names as array
  • , concatenates the output
  • (.results[0].series[0].values[]) gets the data values as array
  • | @csv uses the jq csv formatter
  • -r is used to get raw output

Further resources:

References