Get CSV data with RFC3339 timestamps from API?

influxdb
#1

Pretty simple question: I’d like to get a CSV export via the Influx query API, and I’d like to have the timestamps be in RFC3339 format rather than Unix epoch.

Is there a way to do that? Currently (per the API docs: https://docs.influxdata.com/influxdb/v1.7/tools/api/), switching the API output format from JSON to CSV automatically switches the timestamp format from RFC3339 to Unix epoch. The precision of the timestamps is still configurable, but that’s about it. I’ve experimented with a few query parameters, to no avail.

What I’m trying to do is of course possible via the CLI, by setting -format csv -precision rfc3339, but the API appears to be more limited. Or am I missing something?

#2

See if the following helps you out.

How can you get CSV instead of JSON from the HTTP API of InfluxDB?

I will add this as a task for our InfluxDB docs.

Steve

#3

Thanks @steve.bang! Using jq to transform the JSON into CSV is a neat idea.

I’m actually running the processing in a Python function in AWS Lambda. And although there are jq packages for python, they all have binary library dependencies that I couldn’t for the life of me get loaded successfully on Lambda.

Anyway, given that it’s a resource-constrained Lambda function my priority is to keep things lean in terms of processing power required to get the CSV. For the time being my best bet appears to be getting the CSV with epoch timestamps from Influx, and converting to RFC3339 in Python. I could try parsing the JSON in pure python (instead of jq) but my gut feeling is that that would be pretty slow.

Thanks again for helping out!