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?


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


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: