Documentation

Write data with line protocol

Use line protocol to write data to InfluxDB Cloud. Line protocol is a text-based format that provides the measurement, tag set, field set, and timestamp of a data point. Learn more about line protocol.

Write data using line protocol with the following methods:

Write line protocol using the influx write command

Use the influx write command to write data using line protocol to InfluxDB. Set the path to the line protocol file using the -f flag. Verify that your line protocol follows the correct line protocol format conventions.

Example write command

influx write -b example-bucket -f path/to/example.txt 
  • Copy
  • Fill window

line protocol format

mem,host=host1 used_percent=64.23 1577836800000000000
mem,host=host2 used_percent=72.01 1577836800000000000
mem,host=host1 used_percent=62.61 1577836810000000000
mem,host=host2 used_percent=72.98 1577836810000000000
mem,host=host1 used_percent=63.40 1577836820000000000
mem,host=host2 used_percent=73.77 1577836820000000000
  • Copy
  • Fill window

Line protocol data looks like this:

mem,host=host1 used_percent=23.43234543 1556892576842902000
cpu,host=host1 usage_user=3.8234,usage_system=4.23874 1556892726597397000
mem,host=host1 used_percent=21.83599203 1556892777007291000
  • Copy
  • Fill window

Write line protocol

Write line protocol via stdin

influx write --bucket example-bucket "
m,host=host1 field1=1.2
m,host=host2 field1=2.4
m,host=host1 field2=5i
m,host=host2 field2=3i
"
  • Copy
  • Fill window
Write line protocol from a file
influx write \
  --bucket example-bucket \
  --file path/to/line-protocol.txt
  • Copy
  • Fill window
Write line protocol from multiple files
influx write \
  --bucket example-bucket \
  --file path/to/line-protocol-1.txt \
  --file path/to/line-protocol-2.txt
  • Copy
  • Fill window
Write line protocol from a URL
influx write \
  --bucket example-bucket \
  --url https://example.com/line-protocol.txt
  • Copy
  • Fill window
Write line protocol from multiple URLs
influx write \
  --bucket example-bucket \
  --url https://example.com/line-protocol-1.txt \
  --url https://example.com/line-protocol-2.txt
  • Copy
  • Fill window
Write line protocol from multiple sources
influx write \
  --bucket example-bucket \
  --file path/to/line-protocol-1.txt \
  --url https://example.com/line-protocol-2.txt
  • Copy
  • Fill window
Write line protocol from a compressed file
# The influx CLI assumes files with the .gz extension use gzip compression 
influx write \
  --bucket example-bucket \
  --file path/to/line-protocol.txt.gz

# Specify gzip compression for gzipped files without the .gz extension
influx write \
  --bucket example-bucket \
  --file path/to/line-protocol.txt.comp \
  --compression gzip
  • Copy
  • Fill window

InfluxDB Cloud limits data in an uncompressed write request payload to 250 MB. After 250 MB is uncompressed and written, the remaining lines are not written, and the caller receives a 413 response.  We recommend the caller retry the request with a smaller uncompressed payload.

Timestamp precision

When writing data to InfluxDB, we recommend including a timestamp with each point. 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.

The default precision for timestamps is in nanoseconds. If the precision of the timestamps is anything other than nanoseconds (ns), you must specify the precision in your write request. InfluxDB accepts the following precisions:

  • ns - Nanoseconds
  • us - Microseconds
  • ms - Milliseconds
  • s - Seconds

For more details about line protocol, see the Line protocol reference and Best practices for writing data.


Was this page helpful?

Thank you for your feedback!


The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Read more

InfluxDB 3 Core and Enterprise are now in Beta

InfluxDB 3 Core and Enterprise are now available for beta testing, available under MIT or Apache 2 license.

InfluxDB 3 Core is a high-speed, recent-data engine that collects and processes data in real-time, while persisting it to local disk or object storage. InfluxDB 3 Enterprise is a commercial product that builds on Core’s foundation, adding high availability, read replicas, enhanced security, and data compaction for faster queries. A free tier of InfluxDB 3 Enterprise will also be available for at-home, non-commercial use for hobbyists to get the full historical time series database set of capabilities.

For more information, check out:

InfluxDB Cloud powered by TSM